103 lines
3.4 KiB
Kotlin
103 lines
3.4 KiB
Kotlin
package net.mezimmah.wkt9.inputmode
|
|
|
|
import android.util.Log
|
|
import net.mezimmah.wkt9.keypad.Command
|
|
import net.mezimmah.wkt9.keypad.Key
|
|
import net.mezimmah.wkt9.keypad.KeyCommandResolver
|
|
import net.mezimmah.wkt9.keypad.KeyEventResult
|
|
|
|
class NumericInputMode: BaseInputMode() {
|
|
private val tag = "WKT9"
|
|
override val keyCommandResolver: KeyCommandResolver = KeyCommandResolver(
|
|
parent = super.keyCommandResolver,
|
|
|
|
onLong = 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
|
|
)),
|
|
|
|
afterShort = 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
|
|
)),
|
|
|
|
onRepeat = HashMap(mapOf(
|
|
Key.BACK to Command.HOME
|
|
))
|
|
)
|
|
|
|
init {
|
|
mode = "numeric"
|
|
status = Status.NUM
|
|
|
|
Log.d(tag, "Started $mode input mode.")
|
|
}
|
|
|
|
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
|
|
super.onKeyDown(key, composing)
|
|
|
|
return when(keyCommandResolver.getCommand(key)) {
|
|
Command.BACK -> KeyEventResult(consumed = false)
|
|
Command.DELETE -> deleteCharacter(composing)
|
|
Command.LEFT -> navigateLeft()
|
|
Command.RIGHT -> navigateRight()
|
|
else -> KeyEventResult()
|
|
}
|
|
}
|
|
|
|
override fun onKeyLongDown(key: Key, composing: Boolean): KeyEventResult {
|
|
return when(keyCommandResolver.getCommand(key, true)) {
|
|
Command.CHARACTER -> composeCharacter(key, composing)
|
|
Command.SPACE -> insertSpace(composing)
|
|
Command.SWITCH_MODE -> switchMode(WKT9InputMode.WORD, composing)
|
|
else -> KeyEventResult(true)
|
|
}
|
|
}
|
|
|
|
override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult {
|
|
return when(keyCommandResolver.getCommand(key, repeat = repeat)) {
|
|
Command.HOME -> goHome(repeat, composing)
|
|
Command.DELETE -> deleteCharacter(composing)
|
|
else -> KeyEventResult()
|
|
}
|
|
}
|
|
|
|
override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult {
|
|
return when(keyCommandResolver.getCommand(key, after = true)) {
|
|
Command.BACK -> goBack(composing)
|
|
Command.FN -> functionMode()
|
|
Command.NUMBER -> composeNumber(key, composing)
|
|
else -> KeyEventResult()
|
|
}
|
|
}
|
|
|
|
override fun afterKeyLongDown(key: Key, keyDownMS: Long, composing: Boolean): KeyEventResult {
|
|
return when(keyCommandResolver.getCommand(key, after = true, longPress = true)) {
|
|
else -> KeyEventResult()
|
|
}
|
|
}
|
|
|
|
private fun insertSpace(composing: Boolean): KeyEventResult {
|
|
return KeyEventResult(
|
|
consumed = true,
|
|
finishComposing = composing,
|
|
commit = " "
|
|
)
|
|
}
|
|
} |