insert the proper character at releasing a key after long pressing

This commit is contained in:
tibbi 2022-01-14 21:35:14 +01:00
parent b5a97813ca
commit 916a64774c
2 changed files with 11 additions and 11 deletions

View File

@ -1099,6 +1099,16 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
if (mMiniKeyboard != null) {
val coords = intArrayOf(0, 0)
mMiniKeyboard!!.getLocationOnScreen(coords)
val keys = mMiniKeyboard!!.mKeys
val widthPerKey = mMiniKeyboard!!.width / keys.size
var selectedKeyIndex = Math.floor((me.x - coords[0]) / widthPerKey.toDouble()).toInt()
selectedKeyIndex = Math.max(0, Math.min(selectedKeyIndex, keys.size - 1))
val selectedKeyCodes = keys[selectedKeyIndex].codes
onKeyboardActionListener!!.onKey(selectedKeyCodes[0], selectedKeyCodes.toIntArray())
}
dismissPopupKeyboard()
}
}

View File

@ -1,14 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_keyboard_key_pressed_on" android:state_checkable="true" android:state_checked="true" android:state_pressed="true" />