Added delay for fast typing

This commit is contained in:
merkost 2023-06-28 13:32:53 +10:00
parent 7b80307abd
commit dc1972a096
2 changed files with 11 additions and 8 deletions

View file

@ -179,7 +179,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
}
} else {
when {
originalText != null && originalText.isNotEmpty() && cachedVNTelexData.isNotEmpty() -> {
!originalText.isNullOrEmpty() && cachedVNTelexData.isNotEmpty() -> {
val fullText = originalText.toString() + codeChar.toString()
val lastIndexEmpty = if (fullText.contains(" ")) {
fullText.lastIndexOf(" ")

View file

@ -224,7 +224,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
override fun onAttachedToWindow() {
super.onAttachedToWindow()
if (mHandler == null) {
mHandler = object : Handler() {
mHandler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message) {
when (msg.what) {
MSG_REMOVE_PREVIEW -> mPreviewText!!.visibility = INVISIBLE
@ -800,7 +800,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}
private fun detectAndSendKey(index: Int, x: Int, y: Int, eventTime: Long) {
if (index != NOT_A_KEY && index < mKeys.size) {
if (index != NOT_A_KEY && index in mKeys.indices) {
val key = mKeys[index]
getPressedKeyIndex(x, y)
mOnKeyboardActionListener!!.onKey(key.code)
@ -1194,12 +1194,15 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
val newPointerY = me.getY(1).toInt()
val secondKeyIndex = getPressedKeyIndex(newPointerX, newPointerY)
showPreview(secondKeyIndex)
detectAndSendKey(secondKeyIndex, newPointerX, newPointerY, eventTime)
val secondKeyCode = mKeys.getOrNull(secondKeyIndex)?.code
if (secondKeyCode != null) {
mOnKeyboardActionListener!!.onPress(secondKeyCode)
}
mHandler!!.postDelayed({
detectAndSendKey(secondKeyIndex, newPointerX, newPointerY, eventTime)
val secondKeyCode = mKeys.getOrNull(secondKeyIndex)?.code
if (secondKeyCode != null) {
mOnKeyboardActionListener!!.onPress(secondKeyCode)
}
}, REPEAT_INTERVAL.toLong())
showPreview(NOT_A_KEY)
invalidateKey(mCurrentKey)