Skip to content

Commit dc1972a

Browse files
committed
Added delay for fast typing
1 parent 7b80307 commit dc1972a

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
179179
}
180180
} else {
181181
when {
182-
originalText != null && originalText.isNotEmpty() && cachedVNTelexData.isNotEmpty() -> {
182+
!originalText.isNullOrEmpty() && cachedVNTelexData.isNotEmpty() -> {
183183
val fullText = originalText.toString() + codeChar.toString()
184184
val lastIndexEmpty = if (fullText.contains(" ")) {
185185
fullText.lastIndexOf(" ")

app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
224224
override fun onAttachedToWindow() {
225225
super.onAttachedToWindow()
226226
if (mHandler == null) {
227-
mHandler = object : Handler() {
227+
mHandler = object : Handler(Looper.getMainLooper()) {
228228
override fun handleMessage(msg: Message) {
229229
when (msg.what) {
230230
MSG_REMOVE_PREVIEW -> mPreviewText!!.visibility = INVISIBLE
@@ -800,7 +800,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
800800
}
801801

802802
private fun detectAndSendKey(index: Int, x: Int, y: Int, eventTime: Long) {
803-
if (index != NOT_A_KEY && index < mKeys.size) {
803+
if (index != NOT_A_KEY && index in mKeys.indices) {
804804
val key = mKeys[index]
805805
getPressedKeyIndex(x, y)
806806
mOnKeyboardActionListener!!.onKey(key.code)
@@ -1194,12 +1194,15 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
11941194
val newPointerY = me.getY(1).toInt()
11951195
val secondKeyIndex = getPressedKeyIndex(newPointerX, newPointerY)
11961196
showPreview(secondKeyIndex)
1197-
detectAndSendKey(secondKeyIndex, newPointerX, newPointerY, eventTime)
11981197

1199-
val secondKeyCode = mKeys.getOrNull(secondKeyIndex)?.code
1200-
if (secondKeyCode != null) {
1201-
mOnKeyboardActionListener!!.onPress(secondKeyCode)
1202-
}
1198+
mHandler!!.postDelayed({
1199+
detectAndSendKey(secondKeyIndex, newPointerX, newPointerY, eventTime)
1200+
1201+
val secondKeyCode = mKeys.getOrNull(secondKeyIndex)?.code
1202+
if (secondKeyCode != null) {
1203+
mOnKeyboardActionListener!!.onPress(secondKeyCode)
1204+
}
1205+
}, REPEAT_INTERVAL.toLong())
12031206

12041207
showPreview(NOT_A_KEY)
12051208
invalidateKey(mCurrentKey)

0 commit comments

Comments
 (0)