This commit is contained in:
zb
2023-08-24 21:09:06 +02:00
commit 40a21c6588
67 changed files with 81748 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
package net.mezimmah.wkt9.keypad
class KeyCommandResolver (
private val onShort: HashMap<Key, Command> = HashMap(mapOf()),
private val onLong: HashMap<Key, Command> = HashMap(mapOf()),
private val afterShort: HashMap<Key, Command> = HashMap(mapOf()),
private val afterLong: HashMap<Key, Command> = HashMap(mapOf()),
private val onRepeat: HashMap<Key, Command> = HashMap(mapOf()),
private val parent: KeyCommandResolver? = null
) {
fun getCommand(key: Key, longPress: Boolean = false, after: Boolean = false, repeat: Int = 0): Command? {
val command = when {
repeat > 0 -> onRepeat[key]
(longPress && after) -> afterLong[key]
(longPress) -> onLong[key]
(after) -> afterShort[key]
else -> onShort[key]
}
return when (command) {
null -> parent?.getCommand(key, longPress, after)
else -> command
}
}
companion object {
fun getBasic(): KeyCommandResolver {
return KeyCommandResolver(
onShort = HashMap(mapOf(
Key.N0 to Command.SPACE,
Key.N1 to Command.CHARACTER,
Key.N2 to Command.CHARACTER,
Key.N3 to Command.CHARACTER,
Key.N4 to Command.CHARACTER,
Key.N5 to Command.CHARACTER,
Key.N6 to Command.CHARACTER,
Key.N7 to Command.CHARACTER,
Key.N8 to Command.CHARACTER,
Key.N9 to Command.CHARACTER,
Key.LEFT to Command.NAVIGATE,
Key.RIGHT to Command.NAVIGATE,
Key.UP to Command.NAVIGATE,
Key.DOWN to Command.NAVIGATE,
Key.STAR to Command.CYCLE_CANDIDATES,
Key.DELETE to Command.DELETE,
Key.SELECT to Command.SELECT
)),
onLong = HashMap(mapOf(
Key.N0 to Command.NUMBER,
Key.N1 to Command.NUMBER,
Key.N2 to Command.NUMBER,
Key.N3 to Command.NUMBER,
Key.N4 to Command.NUMBER,
Key.N5 to Command.NUMBER,
Key.N6 to Command.NUMBER,
Key.N7 to Command.NUMBER,
Key.N8 to Command.NUMBER,
Key.N9 to Command.NUMBER,
Key.POUND to Command.SWITCH_MODE,
Key.SELECT to Command.RECORD
)),
afterShort = HashMap(mapOf(
Key.POUND to Command.SHIFT_MODE,
)),
afterLong = HashMap(mapOf(
Key.DELETE to Command.DELETE,
Key.SELECT to Command.TRANSCRIBE,
)),
onRepeat = HashMap(mapOf(
Key.DELETE to Command.DELETE,
))
)
}
}
}