Progress
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
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 IdleInputMode : InputMode {
|
||||
override val mode: String = "idle"
|
||||
|
||||
override var status: Status = Status.LOWER
|
||||
private set
|
||||
|
||||
private val tag = "WKT9"
|
||||
private val keyCommandResolver: KeyCommandResolver = KeyCommandResolver.getBasic()
|
||||
|
||||
init {
|
||||
Log.d(tag, "Started $mode input mode.")
|
||||
}
|
||||
|
||||
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
|
||||
return when(keyCommandResolver.getCommand(key)) {
|
||||
else -> KeyEventResult(false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKeyLongDown(key: Key, composing: Boolean): KeyEventResult {
|
||||
return when(keyCommandResolver.getCommand(key, true)) {
|
||||
else -> KeyEventResult(false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult {
|
||||
return when(keyCommandResolver.getCommand(key, repeat = repeat)) {
|
||||
Command.HOME -> goHome(repeat)
|
||||
else -> KeyEventResult(false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult {
|
||||
return when(keyCommandResolver.getCommand(key, after = true)) {
|
||||
Command.BACK -> goBack()
|
||||
else -> KeyEventResult(false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterKeyLongDown(key: Key, keyDownMS: Long, composing: Boolean): KeyEventResult {
|
||||
return when(keyCommandResolver.getCommand(key, after = true, longPress = true)) {
|
||||
else -> KeyEventResult(false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun goBack(): KeyEventResult {
|
||||
return KeyEventResult(
|
||||
consumed = false,
|
||||
)
|
||||
}
|
||||
|
||||
private fun goHome(repeat: Int): KeyEventResult {
|
||||
if (repeat > 1) return KeyEventResult(true)
|
||||
|
||||
return KeyEventResult(
|
||||
consumed = true,
|
||||
goHome = true
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user