From 767f65c5e900b02d4a851e068ac837994e1f4a47 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 17 Jan 2022 20:58:14 +0100 Subject: [PATCH] adding some more styling --- .../keyboard/helpers/MyKeyboard.kt | 11 ++++++++ .../keyboard/views/MyKeyboardView.kt | 26 ++++++++++++------- .../res/drawable/keyboard_key_selector.xml | 8 ++++++ .../drawable/minikeyboard_key_selector.xml | 4 --- app/src/main/res/values/colors.xml | 2 +- app/src/main/res/values/styles.xml | 2 +- 6 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/drawable/keyboard_key_selector.xml delete mode 100644 app/src/main/res/drawable/minikeyboard_key_selector.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt index ab4640a..a0b7485 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt @@ -247,6 +247,9 @@ class MyKeyboard { /** The current pressed state of this key */ var pressed = false + /** Focused state, used after long pressing a key and swiping to alternative keys */ + var focused = false + /** Text to output when pressed. This can be multiple characters, like ".com" */ var text: CharSequence? = null @@ -331,6 +334,14 @@ class MyKeyboard { edgeFlags = parent.rowEdgeFlags } + fun onPressed() { + pressed = true + } + + fun onReleased() { + pressed = false + } + fun parseCSV(value: String): ArrayList { var count = 0 var lastIndex = 0 diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt index e8f217c..553ae02 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -587,10 +587,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut keyBackground.setBounds(0, 0, key.width, key.height) } - keyBackground.state = if (key.pressed) { - intArrayOf(android.R.attr.state_pressed) - } else { - intArrayOf() + keyBackground.state = when { + key.pressed -> intArrayOf(android.R.attr.state_pressed) + key.focused -> intArrayOf(android.R.attr.state_focused) + else -> intArrayOf() } canvas.translate((key.x + kbdPaddingLeft).toFloat(), (key.y + kbdPaddingTop).toFloat()) @@ -605,8 +605,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut paint.typeface = Typeface.DEFAULT } - // Draw a drop shadow for the text - paint.setShadowLayer(mShadowRadius, 0f, 0f, mShadowColor) // Draw the text canvas.drawText( label, ((key.width - padding.left - padding.right) / 2 + padding.left).toFloat(), @@ -769,6 +767,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut if (oldKeyIndex != mCurrentKeyIndex) { if (oldKeyIndex != NOT_A_KEY && keys.size > oldKeyIndex) { val oldKey = keys[oldKeyIndex] + oldKey.onReleased() invalidateKey(oldKeyIndex) val keyCode = oldKey.codes[0] sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT, keyCode) @@ -777,6 +776,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut if (mCurrentKeyIndex != NOT_A_KEY && keys.size > mCurrentKeyIndex) { val newKey = keys[mCurrentKeyIndex] + + val code = newKey.codes.firstOrNull() ?: -100 + if (code == MyKeyboard.KEYCODE_SHIFT || code == MyKeyboard.KEYCODE_MODE_CHANGE || code == MyKeyboard.KEYCODE_DELETE || + code == MyKeyboard.KEYCODE_ENTER || code == MyKeyboard.KEYCODE_SPACE + ) { + newKey.onPressed() + } + invalidateKey(mCurrentKeyIndex) val keyCode = newKey.codes[0] sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER, keyCode) @@ -1057,8 +1064,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut selectedKeyIndex = Math.max(0, Math.min(selectedKeyIndex, keysCnt - 1)) for (i in 0 until keysCnt) { - mMiniKeyboard!!.mKeys[i].pressed = i == selectedKeyIndex + mMiniKeyboard!!.mKeys[i].focused = i == selectedKeyIndex } + mMiniKeyboardSelectedKeyIndex = selectedKeyIndex mMiniKeyboard!!.invalidateAllKeys() @@ -1153,7 +1161,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut selectedKeyIndex = Math.max(0, Math.min(selectedKeyIndex, keysCnt - 1)) if (selectedKeyIndex != mMiniKeyboardSelectedKeyIndex) { for (i in 0 until keysCnt) { - mMiniKeyboard!!.mKeys[i].pressed = i == selectedKeyIndex + mMiniKeyboard!!.mKeys[i].focused = i == selectedKeyIndex } mMiniKeyboardSelectedKeyIndex = selectedKeyIndex mMiniKeyboard!!.invalidateAllKeys() @@ -1167,7 +1175,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { - mMiniKeyboard?.mKeys?.firstOrNull { it.pressed }?.apply { + mMiniKeyboard?.mKeys?.firstOrNull { it.focused }?.apply { onKeyboardActionListener!!.onKey(codes[0], codes.toIntArray()) } mMiniKeyboardSelectedKeyIndex = -1 diff --git a/app/src/main/res/drawable/keyboard_key_selector.xml b/app/src/main/res/drawable/keyboard_key_selector.xml new file mode 100644 index 0000000..ceb6c03 --- /dev/null +++ b/app/src/main/res/drawable/keyboard_key_selector.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/minikeyboard_key_selector.xml b/app/src/main/res/drawable/minikeyboard_key_selector.xml deleted file mode 100644 index e081682..0000000 --- a/app/src/main/res/drawable/minikeyboard_key_selector.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index d781ec5..c4a92ef 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,4 +1,4 @@ - + #11ffffff diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 65e0497..48fb2eb 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -7,7 +7,7 @@