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()

View File

@ -14,8 +14,8 @@
</declare-styleable>
<declare-styleable name="MyKeyboard_Key">
<!-- The unicode value or comma-separated values that this key outputs. -->
<attr name="codes" format="integer" />
<!-- The unicode value that this key outputs. -->
<attr name="code" format="integer" />
<!-- The XML keyboard layout of any popup keyboard. -->
<attr name="popupKeyboard" format="reference" />
<!-- The characters to display in the popup keyboard. -->

View File

@ -2,62 +2,62 @@
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto">
<Row>
<Key
app:codes="113"
app:code="113"
app:keyEdgeFlags="left"
app:keyLabel="q"
app:popupCharacters="1"
app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="1" />
<Key
app:codes="119"
app:code="119"
app:keyLabel="w"
app:popupCharacters="2"
app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="2" />
<Key
app:codes="101"
app:code="101"
app:keyLabel="e"
app:popupCharacters="3é"
app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="3" />
<Key
app:codes="114"
app:code="114"
app:keyLabel="r"
app:popupCharacters="ř4ŕ"
app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="4" />
<Key
app:codes="116"
app:code="116"
app:keyLabel="t"
app:popupCharacters="5ť"
app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="5" />
<Key
app:codes="121"
app:code="121"
app:keyLabel="y"
app:popupCharacters="6ý"
app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="6" />
<Key
app:codes="117"
app:code="117"
app:keyLabel="u"
app:popupCharacters="ű7üú"
app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="7" />
<Key
app:codes="105"
app:code="105"
app:keyLabel="i"
app:popupCharacters="8í"
app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="8" />
<Key
app:codes="111"
app:code="111"
app:keyLabel="o"
app:popupCharacters="őöó9ô"
app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="9" />
<Key
app:codes="112"
app:code="112"
app:keyEdgeFlags="right"
app:keyLabel="p"
app:popupCharacters="0"
@ -66,39 +66,39 @@
</Row>
<Row>
<Key
app:codes="97"
app:code="97"
app:horizontalGap="5%"
app:keyEdgeFlags="left"
app:keyLabel="a"
app:popupCharacters="á"
app:popupKeyboard="@xml/keyboard_popup_template" />
<Key
app:codes="115"
app:code="115"
app:keyLabel="s"
app:popupCharacters="š"
app:popupKeyboard="@xml/keyboard_popup_template" />
<Key
app:codes="100"
app:code="100"
app:keyLabel="d"
app:popupCharacters="ď"
app:popupKeyboard="@xml/keyboard_popup_template" />
<Key
app:codes="102"
app:code="102"
app:keyLabel="f" />
<Key
app:codes="103"
app:code="103"
app:keyLabel="g" />
<Key
app:codes="104"
app:code="104"
app:keyLabel="h" />
<Key
app:codes="106"
app:code="106"
app:keyLabel="j" />
<Key
app:codes="107"
app:code="107"
app:keyLabel="k" />
<Key
app:codes="108"
app:code="108"
app:keyEdgeFlags="right"
app:keyLabel="l"
app:popupCharacters="ĺľ"
@ -106,39 +106,39 @@
</Row>
<Row>
<Key
app:codes="-1"
app:code="-1"
app:keyEdgeFlags="left"
app:keyIcon="@drawable/ic_caps_outline_vector"
app:keyWidth="15%p" />
<Key
app:codes="122"
app:code="122"
app:keyLabel="z"
app:popupCharacters="ž"
app:popupKeyboard="@xml/keyboard_popup_template" />
<Key
app:codes="120"
app:code="120"
app:keyLabel="x" />
<Key
app:codes="99"
app:code="99"
app:keyLabel="c"
app:popupCharacters="č"
app:popupKeyboard="@xml/keyboard_popup_template" />
<Key
app:codes="118"
app:code="118"
app:keyLabel="v" />
<Key
app:codes="98"
app:code="98"
app:keyLabel="b" />
<Key
app:codes="110"
app:code="110"
app:keyLabel="n"
app:popupCharacters="ňń"
app:popupKeyboard="@xml/keyboard_popup_template" />
<Key
app:codes="109"
app:code="109"
app:keyLabel="m" />
<Key
app:codes="-5"
app:code="-5"
app:isRepeatable="true"
app:keyEdgeFlags="right"
app:keyIcon="@drawable/ic_clear_vector"
@ -146,23 +146,23 @@
</Row>
<Row>
<Key
app:codes="-2"
app:code="-2"
app:keyEdgeFlags="left"
app:keyLabel="123"
app:keyWidth="15%p" />
<Key
app:codes="44"
app:code="44"
app:keyLabel=","
app:keyWidth="10%p" />
<Key
app:codes="32"
app:code="32"
app:isRepeatable="true"
app:keyWidth="45%p" />
<Key
app:codes="46"
app:code="46"
app:keyLabel="." />
<Key
app:codes="-4"
app:code="-4"
app:keyEdgeFlags="right"
app:keyIcon="@drawable/ic_enter_vector"
app:keyWidth="20%p" />

View File

@ -2,101 +2,101 @@
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto">
<Row>
<Key
app:codes="49"
app:code="49"
app:keyEdgeFlags="left"
app:keyLabel="1" />
<Key
app:codes="50"
app:code="50"
app:keyLabel="2" />
<Key
app:codes="51"
app:code="51"
app:keyLabel="3" />
<Key
app:codes="52"
app:code="52"
app:keyLabel="4" />
<Key
app:codes="53"
app:code="53"
app:keyLabel="5" />
<Key
app:codes="54"
app:code="54"
app:keyLabel="6" />
<Key
app:codes="55"
app:code="55"
app:keyLabel="7" />
<Key
app:codes="56"
app:code="56"
app:keyLabel="8" />
<Key
app:codes="57"
app:code="57"
app:keyLabel="9" />
<Key
app:codes="48"
app:code="48"
app:keyEdgeFlags="right"
app:keyLabel="0" />
</Row>
<Row>
<Key
app:codes="64"
app:code="64"
app:keyEdgeFlags="left"
app:keyLabel="\@" />
<Key
app:codes="35"
app:code="35"
app:keyLabel="\#" />
<Key
app:codes="36"
app:code="36"
app:keyLabel="$" />
<Key
app:codes="37"
app:code="37"
app:keyLabel="%" />
<Key
app:codes="38"
app:code="38"
app:keyLabel="&amp;" />
<Key
app:codes="42"
app:code="42"
app:keyLabel="*" />
<Key
app:codes="45"
app:code="45"
app:keyLabel="-" />
<Key
app:codes="61"
app:code="61"
app:keyLabel="=" />
<Key
app:codes="40"
app:code="40"
app:keyLabel="(" />
<Key
app:codes="41"
app:code="41"
app:keyEdgeFlags="right"
app:keyLabel=")" />
</Row>
<Row>
<Key
app:codes="-1"
app:code="-1"
app:keyEdgeFlags="left"
app:keyLabel="=\\&lt;"
app:keyWidth="15%p" />
<Key
app:codes="33"
app:code="33"
app:keyLabel="!" />
<Key
app:codes="34"
app:code="34"
app:keyLabel="&quot;" />
<Key
app:codes="39"
app:code="39"
app:keyLabel="\'" />
<Key
app:codes="58"
app:code="58"
app:keyLabel=":" />
<Key
app:codes="59"
app:code="59"
app:keyLabel=";" />
<Key
app:codes="47"
app:code="47"
app:keyLabel="/" />
<Key
app:codes="63"
app:code="63"
app:keyLabel="\?" />
<Key
app:codes="-5"
app:code="-5"
app:isRepeatable="true"
app:keyEdgeFlags="right"
app:keyIcon="@drawable/ic_clear_vector"
@ -104,23 +104,23 @@
</Row>
<Row>
<Key
app:codes="-2"
app:code="-2"
app:keyEdgeFlags="left"
app:keyLabel="abc"
app:keyWidth="15%p" />
<Key
app:codes="44"
app:code="44"
app:keyLabel=","
app:keyWidth="10%p" />
<Key
app:codes="32"
app:code="32"
app:isRepeatable="true"
app:keyWidth="45%p" />
<Key
app:codes="46"
app:code="46"
app:keyLabel="." />
<Key
app:codes="-4"
app:code="-4"
app:keyEdgeFlags="right"
app:keyIcon="@drawable/ic_enter_vector"
app:keyWidth="20%p" />

View File

@ -2,101 +2,101 @@
<Keyboard xmlns:app="http://schemas.android.com/apk/res-auto">
<Row>
<Key
app:codes="126"
app:code="126"
app:keyEdgeFlags="left"
app:keyLabel="~" />
<Key
app:codes="177"
app:code="177"
app:keyLabel="±" />
<Key
app:codes="215"
app:code="215"
app:keyLabel="×" />
<Key
app:codes="247"
app:code="247"
app:keyLabel="÷" />
<Key
app:codes="8226"
app:code="8226"
app:keyLabel="•" />
<Key
app:codes="176"
app:code="176"
app:keyLabel="°" />
<Key
app:codes="96"
app:code="96"
app:keyLabel="`" />
<Key
app:codes="180"
app:code="180"
app:keyLabel="´" />
<Key
app:codes="123"
app:code="123"
app:keyLabel="{" />
<Key
app:codes="125"
app:code="125"
app:keyEdgeFlags="right"
app:keyLabel="}" />
</Row>
<Row>
<Key
app:codes="169"
app:code="169"
app:keyEdgeFlags="left"
app:keyLabel="©" />
<Key
app:codes="163"
app:code="163"
app:keyLabel="£" />
<Key
app:codes="8364"
app:code="8364"
app:keyLabel="€" />
<Key
app:codes="94"
app:code="94"
app:keyLabel="^" />
<Key
app:codes="174"
app:code="174"
app:keyLabel="®" />
<Key
app:codes="165"
app:code="165"
app:keyLabel="¥" />
<Key
app:codes="95"
app:code="95"
app:keyLabel="_" />
<Key
app:codes="43"
app:code="43"
app:keyLabel="+" />
<Key
app:codes="91"
app:code="91"
app:keyLabel="[" />
<Key
app:codes="93"
app:code="93"
app:keyEdgeFlags="right"
app:keyLabel="]" />
</Row>
<Row>
<Key
app:codes="-1"
app:code="-1"
app:keyEdgeFlags="left"
app:keyLabel="\?123"
app:keyWidth="15%p" />
<Key
app:codes="161"
app:code="161"
app:keyLabel="¡" />
<Key
app:codes="60"
app:code="60"
app:keyLabel="&lt;" />
<Key
app:codes="62"
app:code="62"
app:keyLabel="&gt;" />
<Key
app:codes="162"
app:code="162"
app:keyLabel="¢" />
<Key
app:codes="124"
app:code="124"
app:keyLabel="|" />
<Key
app:codes="92"
app:code="92"
app:keyLabel="\\" />
<Key
app:codes="191"
app:code="191"
app:keyLabel="¿" />
<Key
app:codes="-5"
app:code="-5"
app:isRepeatable="true"
app:keyEdgeFlags="right"
app:keyIcon="@drawable/ic_clear_vector"
@ -104,23 +104,23 @@
</Row>
<Row>
<Key
app:codes="-2"
app:code="-2"
app:keyEdgeFlags="left"
app:keyLabel="abc"
app:keyWidth="15%p" />
<Key
app:codes="44"
app:code="44"
app:keyLabel=","
app:keyWidth="10%p" />
<Key
app:codes="32"
app:code="32"
app:isRepeatable="true"
app:keyWidth="45%p" />
<Key
app:codes="46"
app:code="46"
app:keyLabel="." />
<Key
app:codes="-4"
app:code="-4"
app:keyEdgeFlags="right"
app:keyIcon="@drawable/ic_enter_vector"
app:keyWidth="20%p" />