removing keycodes array in multiple other places

This commit is contained in:
tibbi
2022-01-22 09:53:24 +01:00
parent f671f2653c
commit be30b19380
7 changed files with 119 additions and 122 deletions

View File

@ -211,7 +211,7 @@ class MyKeyboard {
a.recycle()
a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.MyKeyboard_Key)
code = a.getInt(R.styleable.MyKeyboard_Key_codes, 0)
code = a.getInt(R.styleable.MyKeyboard_Key_code, 0)
popupCharacters = a.getText(R.styleable.MyKeyboard_Key_popupCharacters)
popupResId = a.getResourceId(R.styleable.MyKeyboard_Key_popupKeyboard, 0)

View File

@ -82,13 +82,13 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
}
}
override fun onKey(primaryCode: Int, keyCodes: IntArray?) {
override fun onKey(code: Int) {
val inputConnection = currentInputConnection
if (keyboard == null || inputConnection == null) {
return
}
when (primaryCode) {
when (code) {
MyKeyboard.KEYCODE_DELETE -> {
if (keyboard!!.mShiftState == SHIFT_ON_ONE_CHAR) {
keyboard!!.mShiftState = SHIFT_OFF
@ -141,21 +141,21 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
keyboardView!!.setKeyboard(keyboard!!)
}
else -> {
var code = primaryCode.toChar()
if (Character.isLetter(code) && keyboard!!.mShiftState > SHIFT_OFF) {
code = Character.toUpperCase(code)
var codeChar = code.toChar()
if (Character.isLetter(codeChar) && keyboard!!.mShiftState > SHIFT_OFF) {
codeChar = Character.toUpperCase(codeChar)
}
// If the keyboard is set to symbols and the user presses space, we usually should switch back to the letters keyboard.
// However, avoid doing that in cases when the EditText for example requires numbers as the input.
// We can detect that by the text not changing on pressing Space.
if (keyboardMode != KEYBOARD_LETTERS && primaryCode == MyKeyboard.KEYCODE_SPACE) {
if (keyboardMode != KEYBOARD_LETTERS && code == MyKeyboard.KEYCODE_SPACE) {
val originalText = inputConnection.getExtractedText(ExtractedTextRequest(), 0).text
inputConnection.commitText(code.toString(), 1)
inputConnection.commitText(codeChar.toString(), 1)
val newText = inputConnection.getExtractedText(ExtractedTextRequest(), 0).text
switchToLetters = originalText != newText
} else {
inputConnection.commitText(code.toString(), 1)
inputConnection.commitText(codeChar.toString(), 1)
}
if (keyboard!!.mShiftState == SHIFT_ON_ONE_CHAR && keyboardMode == KEYBOARD_LETTERS) {
@ -165,7 +165,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
}
}
if (primaryCode != MyKeyboard.KEYCODE_SHIFT) {
if (code != MyKeyboard.KEYCODE_SHIFT) {
updateShiftKeyState()
}
}

View File

@ -39,12 +39,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
/**
* Send a key press to the listener.
* @param primaryCode this is the key that was pressed
* @param keyCodes the codes for all the possible alternative keys with the primary code being the first. If the primary key code is a single character
* such as an alphabet or number or symbol, the alternatives will include other characters that may be on the same key or adjacent keys. These codes
* are useful to correct for accidental presses of a key adjacent to the intended key.
* @param code this is the key that was pressed
*/
fun onKey(primaryCode: Int, keyCodes: IntArray?)
fun onKey(code: Int)
/**
* Called when the finger has been lifted after pressing a key
@ -555,7 +552,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
val codes = IntArray(MAX_NEARBY_KEYS)
Arrays.fill(codes, NOT_A_KEY)
getKeyIndices(x, y, codes)
mOnKeyboardActionListener!!.onKey(key.code, codes)
mOnKeyboardActionListener!!.onKey(key.code)
mLastTapTime = eventTime
}
}
@ -785,8 +782,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
mMiniKeyboard = mMiniKeyboardContainer!!.findViewById<View>(R.id.mini_keyboard_view) as MyKeyboardView
mMiniKeyboard!!.mOnKeyboardActionListener = object : OnKeyboardActionListener {
override fun onKey(primaryCode: Int, keyCodes: IntArray?) {
mOnKeyboardActionListener!!.onKey(primaryCode, keyCodes)
override fun onKey(primaryCode: Int) {
mOnKeyboardActionListener!!.onKey(primaryCode)
dismissPopupKeyboard()
}
@ -962,7 +959,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
mMiniKeyboard?.mKeys?.firstOrNull { it.focused }?.apply {
mOnKeyboardActionListener!!.onKey(code, intArrayOf(code))
mOnKeyboardActionListener!!.onKey(code)
}
mMiniKeyboardSelectedKeyIndex = -1
dismissPopupKeyboard()