fix showing key icons, where available
This commit is contained in:
parent
718cd41d8a
commit
6281d4e205
|
@ -209,6 +209,16 @@ class MyKeyboard {
|
|||
* @attr ref android.R.styleable#Keyboard_Key_keyEdgeFlags
|
||||
*/
|
||||
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. */
|
||||
var codes = ArrayList<Int>()
|
||||
|
||||
|
@ -414,8 +424,7 @@ class MyKeyboard {
|
|||
* @return the drawable state of the key.
|
||||
* @see android.graphics.drawable.StateListDrawable.setState
|
||||
*/
|
||||
val currentDrawableState: IntArray
|
||||
get() {
|
||||
fun getCurrentDrawableState(): IntArray {
|
||||
var states: IntArray = KEY_STATE_NORMAL
|
||||
if (on) {
|
||||
states = if (pressed) {
|
||||
|
@ -438,15 +447,6 @@ class MyKeyboard {
|
|||
}
|
||||
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)
|
||||
mDefaultHorizontalGap = getDimensionOrFraction(a, R.styleable.Keyboard_horizontalGap, mDisplayWidth, 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
|
||||
a.recycle()
|
||||
}
|
||||
|
|
|
@ -566,7 +566,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
continue
|
||||
}
|
||||
|
||||
val drawableState = key.currentDrawableState
|
||||
val drawableState = key.getCurrentDrawableState()
|
||||
keyBackground!!.state = drawableState
|
||||
|
||||
// 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())
|
||||
keyBackground.draw(canvas)
|
||||
if (label != null) {
|
||||
if (label?.isNotEmpty() == true) {
|
||||
// For characters, use large font. For labels like "Done", use small font.
|
||||
if (label.length > 1 && key.codes.size < 2) {
|
||||
paint.textSize = mLabelTextSize.toFloat()
|
||||
|
|
Loading…
Reference in New Issue