fix showing key icons, where available

This commit is contained in:
tibbi 2022-01-08 23:30:07 +01:00
parent 718cd41d8a
commit 6281d4e205
2 changed files with 28 additions and 28 deletions

View File

@ -209,6 +209,16 @@ class MyKeyboard {
* @attr ref android.R.styleable#Keyboard_Key_keyEdgeFlags * @attr ref android.R.styleable#Keyboard_Key_keyEdgeFlags
*/ */
class Key(parent: Row) { class Key(parent: Row) {
companion object {
private val KEY_STATE_NORMAL = intArrayOf()
private val KEY_STATE_NORMAL_ON = intArrayOf(android.R.attr.state_checkable, android.R.attr.state_checked)
private val KEY_STATE_NORMAL_OFF = intArrayOf(android.R.attr.state_checkable)
private val KEY_STATE_PRESSED = intArrayOf(android.R.attr.state_pressed)
private val KEY_STATE_PRESSED_ON = intArrayOf(android.R.attr.state_pressed, android.R.attr.state_checkable, android.R.attr.state_checked)
private val KEY_STATE_PRESSED_OFF = intArrayOf(android.R.attr.state_pressed, android.R.attr.state_checkable)
}
/** All the key codes (unicode or custom code) that this key could generate, zero'th being the most important. */ /** All the key codes (unicode or custom code) that this key could generate, zero'th being the most important. */
var codes = ArrayList<Int>() var codes = ArrayList<Int>()
@ -414,38 +424,28 @@ class MyKeyboard {
* @return the drawable state of the key. * @return the drawable state of the key.
* @see android.graphics.drawable.StateListDrawable.setState * @see android.graphics.drawable.StateListDrawable.setState
*/ */
val currentDrawableState: IntArray fun getCurrentDrawableState(): IntArray {
get() { var states: IntArray = KEY_STATE_NORMAL
var states: IntArray = KEY_STATE_NORMAL if (on) {
if (on) { states = if (pressed) {
KEY_STATE_PRESSED_ON
} else {
KEY_STATE_NORMAL_ON
}
} else {
if (sticky) {
states = if (pressed) { states = if (pressed) {
KEY_STATE_PRESSED_ON KEY_STATE_PRESSED_OFF
} else { } else {
KEY_STATE_NORMAL_ON KEY_STATE_NORMAL_OFF
} }
} else { } else {
if (sticky) { if (pressed) {
states = if (pressed) { states = KEY_STATE_PRESSED
KEY_STATE_PRESSED_OFF
} else {
KEY_STATE_NORMAL_OFF
}
} else {
if (pressed) {
states = KEY_STATE_PRESSED
}
} }
} }
return states
} }
return states
companion object {
private val KEY_STATE_NORMAL_ON = intArrayOf(android.R.attr.state_checkable, android.R.attr.state_checked)
private val KEY_STATE_PRESSED_ON = intArrayOf(android.R.attr.state_pressed, android.R.attr.state_checkable, android.R.attr.state_checked)
private val KEY_STATE_NORMAL_OFF = intArrayOf(android.R.attr.state_checkable)
private val KEY_STATE_PRESSED_OFF = intArrayOf(android.R.attr.state_pressed, android.R.attr.state_checkable)
private val KEY_STATE_NORMAL = intArrayOf()
private val KEY_STATE_PRESSED = intArrayOf(android.R.attr.state_pressed)
} }
} }
@ -712,7 +712,7 @@ class MyKeyboard {
mDefaultHeight = getDimensionOrFraction(a, R.styleable.Keyboard_keyHeight, mDisplayHeight, 50) mDefaultHeight = getDimensionOrFraction(a, R.styleable.Keyboard_keyHeight, mDisplayHeight, 50)
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.Keyboard_horizontalGap, mDisplayWidth, 0) mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.Keyboard_horizontalGap, mDisplayWidth, 0)
mDefaultVerticalGap = getDimensionOrFraction(a, R.styleable.Keyboard_verticalGap, mDisplayHeight, 0) mDefaultVerticalGap = getDimensionOrFraction(a, R.styleable.Keyboard_verticalGap, mDisplayHeight, 0)
mProximityThreshold = (mDefaultWidth * SEARCH_DISTANCE) as Int mProximityThreshold = (mDefaultWidth * SEARCH_DISTANCE).toInt()
mProximityThreshold *= mProximityThreshold // Square it for comparison mProximityThreshold *= mProximityThreshold // Square it for comparison
a.recycle() a.recycle()
} }

View File

@ -566,7 +566,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
continue continue
} }
val drawableState = key.currentDrawableState val drawableState = key.getCurrentDrawableState()
keyBackground!!.state = drawableState keyBackground!!.state = drawableState
// Switch the character to uppercase if shift is pressed // Switch the character to uppercase if shift is pressed
@ -579,7 +579,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
canvas.translate((key.x + kbdPaddingLeft).toFloat(), (key.y + kbdPaddingTop).toFloat()) canvas.translate((key.x + kbdPaddingLeft).toFloat(), (key.y + kbdPaddingTop).toFloat())
keyBackground.draw(canvas) keyBackground.draw(canvas)
if (label != null) { if (label?.isNotEmpty() == true) {
// For characters, use large font. For labels like "Done", use small font. // For characters, use large font. For labels like "Done", use small font.
if (label.length > 1 && key.codes.size < 2) { if (label.length > 1 && key.codes.size < 2) {
paint.textSize = mLabelTextSize.toFloat() paint.textSize = mLabelTextSize.toFloat()