@@ -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