adding some more styling

This commit is contained in:
tibbi 2022-01-17 20:58:14 +01:00
parent 6bd6d128b9
commit 767f65c5e9
6 changed files with 38 additions and 15 deletions

View file

@ -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<Int> {
var count = 0
var lastIndex = 0

View file

@ -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

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- used after long pressing a key to highlight the currently selected key alternative on minikeyboard-->
<item android:drawable="@drawable/minikeyboard_selected_background" android:state_focused="true" />
<!-- used at clicking some keys on the main keyboard -->
<item android:drawable="@color/key_press_color" android:state_pressed="true" />
</selector>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/minikeyboard_selected_background" android:state_pressed="true" />
</selector>

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="key_press_color">#11ffffff</color>
</resources>

View file

@ -7,7 +7,7 @@
</style>
<style name="Widget.KeyboardView" parent="Widget">
<item name="keyBackground">@drawable/minikeyboard_key_selector</item>
<item name="keyBackground">@drawable/keyboard_key_selector</item>
<item name="keyTextSize">22sp</item>
<item name="keyTextColor">#FFFFFFFF</item>
<item name="keyPreviewLayout">@layout/keyboard_key_preview</item>