Getting to a stable version...

This commit is contained in:
Nehemiah of Zebulun 2023-09-05 11:03:45 +02:00
parent fa02792649
commit 980aa88381
9 changed files with 104 additions and 284 deletions

View File

@ -100,7 +100,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
private var spellCheckerSession: SpellCheckerSession? = null private var spellCheckerSession: SpellCheckerSession? = null
// UI // UI
private lateinit var inputView: View private var inputView: View? = null
private var toast: Toast? = null private var toast: Toast? = null
// Whisper // Whisper
@ -138,7 +138,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
} }
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
override fun onCreateInputView(): View { override fun onCreateInputView(): View? {
inputView = layoutInflater.inflate(R.layout.suggestions, null) inputView = layoutInflater.inflate(R.layout.suggestions, null)
return inputView return inputView
@ -290,7 +290,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
} }
private fun clearCandidateUI() { private fun clearCandidateUI() {
val candidatesView = inputView.findViewById<LinearLayout>(R.id.suggestions) val candidatesView = inputView?.findViewById<LinearLayout>(R.id.suggestions) ?: return
candidatesView.removeAllViews() candidatesView.removeAllViews()
} }
@ -420,7 +420,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
if (res.updateWordStatus) onUpdateWordStatus() if (res.updateWordStatus) onUpdateWordStatus()
if (res.focus) onFocus() if (res.focus) onFocus()
if (res.switchInputMode != null) onSwitchInputMode(res.switchInputMode) if (res.switchInputMode != null) onSwitchInputMode(res.switchInputMode)
if (res.functionMode) onFunctionMode() if (res.toggleFunctionMode) onToggleFunctionMode()
if (res.increaseVolume) onIncreaseVolume() if (res.increaseVolume) onIncreaseVolume()
if (res.decreaseVolume) onDecreaseVolume() if (res.decreaseVolume) onDecreaseVolume()
if (res.increaseBrightness) onIncreaseBrightness() if (res.increaseBrightness) onIncreaseBrightness()
@ -442,7 +442,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
} }
private fun loadCandidates(highLight: Int? = null) { private fun loadCandidates(highLight: Int? = null) {
val candidatesView = inputView.findViewById<LinearLayout>(R.id.suggestions) val candidatesView = inputView?.findViewById<LinearLayout>(R.id.suggestions) ?: return
candidates.forEachIndexed { index, candidate -> candidates.forEachIndexed { index, candidate ->
val layout = if (index == highLight) R.layout.current_suggestion else R.layout.suggestion val layout = if (index == highLight) R.layout.current_suggestion else R.layout.suggestion
@ -532,8 +532,10 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
requestShowSelf(InputMethodManager.SHOW_IMPLICIT) requestShowSelf(InputMethodManager.SHOW_IMPLICIT)
} }
private fun onFunctionMode() { private fun onToggleFunctionMode() {
enableInputMode(WKT9InputMode.FN) if (inputMode is FNInputMode) enableInputMode(lastInputMode)
else enableInputMode(WKT9InputMode.FN)
updateInputStatus() updateInputStatus()
} }

View File

@ -3,29 +3,20 @@ package net.mezimmah.wkt9.inputmode
import android.util.Log import android.util.Log
import net.mezimmah.wkt9.keypad.Command import net.mezimmah.wkt9.keypad.Command
import net.mezimmah.wkt9.keypad.Key import net.mezimmah.wkt9.keypad.Key
import net.mezimmah.wkt9.keypad.KeyCommandResolver
import net.mezimmah.wkt9.keypad.KeyEventResult import net.mezimmah.wkt9.keypad.KeyEventResult
import net.mezimmah.wkt9.keypad.KeyLayout
import java.lang.StringBuilder
class AlphaInputMode: InputMode { class AlphaInputMode: BaseInputMode() {
private val tag = "WKT9" private val tag = "WKT9"
private val keyCommandResolver: KeyCommandResolver = KeyCommandResolver.getBasic()
private var newKey = true
private var keyIndex = 0
private var lastKey: Key? = null
override val mode: String = "alpha"
override var status: Status = Status.CAP
private set
init { init {
Log.d(tag, "Started alpha input mode.") mode = "alpha"
status = Status.CAP
Log.d(tag, "Started $mode input mode.")
} }
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult { override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
keyStats(key) super.onKeyDown(key, composing)
return when(keyCommandResolver.getCommand(key)) { return when(keyCommandResolver.getCommand(key)) {
Command.BACK -> KeyEventResult(consumed = false) Command.BACK -> KeyEventResult(consumed = false)
@ -41,7 +32,7 @@ class AlphaInputMode: InputMode {
return when(keyCommandResolver.getCommand(key, true)) { return when(keyCommandResolver.getCommand(key, true)) {
Command.RECORD -> record(composing) Command.RECORD -> record(composing)
Command.NUMBER -> commitNumber(key, composing) Command.NUMBER -> commitNumber(key, composing)
Command.SWITCH_MODE -> switchMode(composing) Command.SWITCH_MODE -> switchMode(WKT9InputMode.NUMERIC, composing)
else -> KeyEventResult(true) else -> KeyEventResult(true)
} }
} }
@ -58,6 +49,7 @@ class AlphaInputMode: InputMode {
return when(keyCommandResolver.getCommand(key, after = true)) { return when(keyCommandResolver.getCommand(key, after = true)) {
Command.BACK -> goBack(composing) Command.BACK -> goBack(composing)
Command.CHARACTER -> composeCharacter(key, composing) Command.CHARACTER -> composeCharacter(key, composing)
Command.FN -> functionMode()
Command.SHIFT_MODE -> shiftMode() Command.SHIFT_MODE -> shiftMode()
Command.SPACE -> finalizeWordOrSentence(composing) Command.SPACE -> finalizeWordOrSentence(composing)
else -> KeyEventResult() else -> KeyEventResult()
@ -71,102 +63,10 @@ class AlphaInputMode: InputMode {
} }
} }
private fun deleteCharacter(composing: Boolean): KeyEventResult { override fun composeCharacter(key: Key, composing: Boolean): KeyEventResult {
return KeyEventResult(
finishComposing = composing,
deleteBeforeCursor = 1
)
}
private fun commitNumber(key: Key, composing: Boolean): KeyEventResult {
val code = KeyLayout.numeric[key] ?: return KeyEventResult(true)
return KeyEventResult(
consumed = true,
finishComposing = composing,
commit = code.toString()
)
}
private fun composeCharacter(key: Key, composing: Boolean): KeyEventResult {
if (composing && !newKey) return navigateRight() if (composing && !newKey) return navigateRight()
val layout = KeyLayout.en_US[key] ?: return KeyEventResult(true) return super.composeCharacter(key, composing)
val candidates = layout.map { it.toString() }
return KeyEventResult(
consumed = true,
finishComposing = composing,
startComposing = true,
candidates = candidates,
timeout = 400
)
}
private fun finalizeWordOrSentence(composing: Boolean): KeyEventResult {
if (composing && !newKey) return navigateRight()
return KeyEventResult(
finishComposing = composing,
startComposing = true,
candidates = listOf(" ", ". ", "? ", "! ", ", ", ": ", "; "),
timeout = 700
)
}
private fun focus(): KeyEventResult {
return KeyEventResult(
consumed = true,
focus = true
)
}
private fun goBack(composing: Boolean): KeyEventResult {
return KeyEventResult(
consumed = false,
finishComposing = composing
)
}
private fun goHome(repeat: Int, composing: Boolean): KeyEventResult {
if (repeat > 1) return KeyEventResult(true)
return KeyEventResult(
consumed = true,
finishComposing = composing,
goHome = true
)
}
private fun keyStats(key: Key) {
when (key != lastKey) {
true -> {
newKey = true
keyIndex = 0
}
false -> {
newKey = false
keyIndex++
}
}
lastKey = key
}
private fun navigateLeft(): KeyEventResult {
return KeyEventResult(left = true)
}
private fun navigateRight(): KeyEventResult {
return KeyEventResult(right = true)
}
private fun record(composing: Boolean): KeyEventResult {
return KeyEventResult(
consumed = true,
finishComposing = composing,
record = true
)
} }
private fun shiftMode(): KeyEventResult { private fun shiftMode(): KeyEventResult {
@ -181,20 +81,4 @@ class AlphaInputMode: InputMode {
updateInputStatus = true updateInputStatus = true
) )
} }
private fun switchMode(composing: Boolean): KeyEventResult {
return KeyEventResult(
consumed = true,
finishComposing = composing,
switchInputMode = WKT9InputMode.NUMERIC
)
}
private fun transcribe(composing: Boolean): KeyEventResult {
return KeyEventResult(
consumed = true,
finishComposing = composing,
transcribe = true
)
}
} }

View File

@ -6,11 +6,12 @@ import net.mezimmah.wkt9.keypad.KeyEventResult
import net.mezimmah.wkt9.keypad.KeyLayout import net.mezimmah.wkt9.keypad.KeyLayout
open class BaseInputMode: InputMode { open class BaseInputMode: InputMode {
protected val keyCommandResolver: KeyCommandResolver = KeyCommandResolver.getBasic()
protected var newKey = true protected var newKey = true
protected var keyIndex = 0 protected var keyIndex = 0
protected var lastKey: Key? = null protected var lastKey: Key? = null
protected open val keyCommandResolver: KeyCommandResolver = KeyCommandResolver.getBasic()
override lateinit var mode: String override lateinit var mode: String
protected set protected set
@ -49,7 +50,30 @@ open class BaseInputMode: InputMode {
) )
} }
protected open fun deleteCharacter(repeat: Int = 0, composing: Boolean): KeyEventResult { protected open fun composeCharacter(key: Key, composing: Boolean): KeyEventResult {
val layout = KeyLayout.en_US[key] ?: return KeyEventResult(true)
val candidates = layout.map { it.toString() }
return KeyEventResult(
consumed = true,
finishComposing = composing,
startComposing = true,
candidates = candidates,
timeout = 1200
)
}
protected fun composeNumber(key: Key, composing: Boolean): KeyEventResult {
val code = KeyLayout.numeric[key] ?: return KeyEventResult(true)
return KeyEventResult(
consumed = true,
finishComposing = composing,
commit = code.toString()
)
}
protected open fun deleteCharacter(composing: Boolean): KeyEventResult {
return KeyEventResult( return KeyEventResult(
finishComposing = composing, finishComposing = composing,
deleteBeforeCursor = 1 deleteBeforeCursor = 1
@ -77,7 +101,7 @@ open class BaseInputMode: InputMode {
protected fun functionMode(): KeyEventResult { protected fun functionMode(): KeyEventResult {
return KeyEventResult( return KeyEventResult(
consumed = true, consumed = true,
functionMode = true toggleFunctionMode = true
) )
} }
@ -120,11 +144,11 @@ open class BaseInputMode: InputMode {
) )
} }
protected open fun switchMode(composing: Boolean): KeyEventResult { protected open fun switchMode(mode: WKT9InputMode, composing: Boolean): KeyEventResult {
return KeyEventResult( return KeyEventResult(
consumed = true, consumed = true,
finishComposing = composing, finishComposing = composing,
switchInputMode = WKT9InputMode.ALPHA switchInputMode = mode
) )
} }

View File

@ -6,11 +6,10 @@ import net.mezimmah.wkt9.keypad.Key
import net.mezimmah.wkt9.keypad.KeyCommandResolver import net.mezimmah.wkt9.keypad.KeyCommandResolver
import net.mezimmah.wkt9.keypad.KeyEventResult import net.mezimmah.wkt9.keypad.KeyEventResult
class FNInputMode: InputMode { class FNInputMode: BaseInputMode() {
private val tag = "WKT9" private val tag = "WKT9"
private val parentKeyCommandResolver: KeyCommandResolver = KeyCommandResolver.getBasic() override val keyCommandResolver: KeyCommandResolver = KeyCommandResolver(
private val keyCommandResolver: KeyCommandResolver = KeyCommandResolver( parent = super.keyCommandResolver,
parent = parentKeyCommandResolver,
onShort = HashMap(mapOf( onShort = HashMap(mapOf(
Key.UP to Command.VOL_UP, Key.UP to Command.VOL_UP,
@ -23,49 +22,55 @@ class FNInputMode: InputMode {
Key.UP to Command.VOL_UP, Key.UP to Command.VOL_UP,
Key.DOWN to Command.VOL_DOWN, Key.DOWN to Command.VOL_DOWN,
Key.LEFT to Command.BRIGHTNESS_DOWN, Key.LEFT to Command.BRIGHTNESS_DOWN,
Key.RIGHT to Command.BRIGHTNESS_UP Key.RIGHT to Command.BRIGHTNESS_UP,
Key.BACK to Command.HOME
)) ))
) )
override val mode: String = "fn"
override var status: Status = Status.NA
private set
init { init {
mode = "fn"
status = Status.NA
Log.d(tag, "Started $mode input mode.") Log.d(tag, "Started $mode input mode.")
} }
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult { override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key)) { return when(keyCommandResolver.getCommand(key)) {
Command.BACK -> KeyEventResult(false)
Command.VOL_UP -> volumeUp() Command.VOL_UP -> volumeUp()
Command.VOL_DOWN -> volumeDown() Command.VOL_DOWN -> volumeDown()
Command.BRIGHTNESS_DOWN -> brightnessDown() Command.BRIGHTNESS_DOWN -> brightnessDown()
Command.BRIGHTNESS_UP -> brightnessUp() Command.BRIGHTNESS_UP -> brightnessUp()
else -> KeyEventResult(false) else -> KeyEventResult(true)
} }
} }
override fun onKeyLongDown(key: Key, composing: Boolean): KeyEventResult { override fun onKeyLongDown(key: Key, composing: Boolean): KeyEventResult {
return KeyEventResult(false) return KeyEventResult(true)
} }
override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult { override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key, repeat = repeat)) { return when(keyCommandResolver.getCommand(key, repeat = repeat)) {
Command.HOME -> goHome(repeat, composing)
Command.VOL_UP -> volumeUp() Command.VOL_UP -> volumeUp()
Command.VOL_DOWN -> volumeDown() Command.VOL_DOWN -> volumeDown()
Command.BRIGHTNESS_DOWN -> brightnessDown() Command.BRIGHTNESS_DOWN -> brightnessDown()
Command.BRIGHTNESS_UP -> brightnessUp() Command.BRIGHTNESS_UP -> brightnessUp()
else -> KeyEventResult(false) else -> KeyEventResult(true)
} }
} }
override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult { override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult {
return KeyEventResult(false) return when(keyCommandResolver.getCommand(key, after = true)) {
Command.BACK -> goBack(composing)
Command.FN -> functionMode()
else -> KeyEventResult(true)
}
} }
override fun afterKeyLongDown(key: Key, keyDownMS: Long, composing: Boolean): KeyEventResult { override fun afterKeyLongDown(key: Key, keyDownMS: Long, composing: Boolean): KeyEventResult {
return KeyEventResult(false) return KeyEventResult(true)
} }
private fun brightnessDown(): KeyEventResult { private fun brightnessDown(): KeyEventResult {

View File

@ -3,24 +3,21 @@ package net.mezimmah.wkt9.inputmode
import android.util.Log import android.util.Log
import net.mezimmah.wkt9.keypad.Command import net.mezimmah.wkt9.keypad.Command
import net.mezimmah.wkt9.keypad.Key import net.mezimmah.wkt9.keypad.Key
import net.mezimmah.wkt9.keypad.KeyCommandResolver
import net.mezimmah.wkt9.keypad.KeyEventResult import net.mezimmah.wkt9.keypad.KeyEventResult
class IdleInputMode : InputMode { class IdleInputMode : BaseInputMode() {
override val mode: String = "idle"
override var status: Status = Status.NA
private set
private val tag = "WKT9" private val tag = "WKT9"
private val keyCommandResolver: KeyCommandResolver = KeyCommandResolver.getBasic()
init { init {
mode = "idle"
status = Status.NA
Log.d(tag, "Started $mode input mode.") Log.d(tag, "Started $mode input mode.")
} }
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult { override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key)) { return when(keyCommandResolver.getCommand(key)) {
Command.FN -> KeyEventResult(true)
else -> KeyEventResult(false) else -> KeyEventResult(false)
} }
} }
@ -33,14 +30,15 @@ class IdleInputMode : InputMode {
override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult { override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key, repeat = repeat)) { return when(keyCommandResolver.getCommand(key, repeat = repeat)) {
Command.HOME -> goHome(repeat) Command.HOME -> goHome(repeat, composing)
else -> KeyEventResult(false) else -> KeyEventResult(false)
} }
} }
override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult { override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key, after = true)) { return when(keyCommandResolver.getCommand(key, after = true)) {
Command.BACK -> goBack() Command.BACK -> goBack(composing)
Command.FN -> functionMode()
else -> KeyEventResult(false) else -> KeyEventResult(false)
} }
} }
@ -50,19 +48,4 @@ class IdleInputMode : InputMode {
else -> KeyEventResult(false) 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
)
}
} }

View File

@ -5,13 +5,11 @@ import net.mezimmah.wkt9.keypad.Command
import net.mezimmah.wkt9.keypad.Key import net.mezimmah.wkt9.keypad.Key
import net.mezimmah.wkt9.keypad.KeyCommandResolver import net.mezimmah.wkt9.keypad.KeyCommandResolver
import net.mezimmah.wkt9.keypad.KeyEventResult import net.mezimmah.wkt9.keypad.KeyEventResult
import net.mezimmah.wkt9.keypad.KeyLayout
class NumericInputMode: InputMode { class NumericInputMode: BaseInputMode() {
private val tag = "WKT9" private val tag = "WKT9"
private val parentKeyCommandResolver: KeyCommandResolver = KeyCommandResolver.getBasic() override val keyCommandResolver: KeyCommandResolver = KeyCommandResolver(
private val keyCommandResolver: KeyCommandResolver = KeyCommandResolver( parent = super.keyCommandResolver,
parent = parentKeyCommandResolver,
onLong = HashMap(mapOf( onLong = HashMap(mapOf(
Key.N0 to Command.SPACE, Key.N0 to Command.SPACE,
@ -37,23 +35,22 @@ class NumericInputMode: InputMode {
Key.N7 to Command.NUMBER, Key.N7 to Command.NUMBER,
Key.N8 to Command.NUMBER, Key.N8 to Command.NUMBER,
Key.N9 to Command.NUMBER Key.N9 to Command.NUMBER
)),
onRepeat = HashMap(mapOf(
Key.BACK to Command.HOME
)) ))
) )
private var newKey = true
private var keyIndex = 0
private var lastKey: Key? = null
override val mode: String = "numeric"
override var status: Status = Status.NUM
private set
init { init {
Log.d(tag, "Started numeric input mode.") mode = "numeric"
status = Status.NUM
Log.d(tag, "Started $mode input mode.")
} }
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult { override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
keyStats(key) super.onKeyDown(key, composing)
return when(keyCommandResolver.getCommand(key)) { return when(keyCommandResolver.getCommand(key)) {
Command.BACK -> KeyEventResult(consumed = false) Command.BACK -> KeyEventResult(consumed = false)
@ -68,13 +65,13 @@ class NumericInputMode: InputMode {
return when(keyCommandResolver.getCommand(key, true)) { return when(keyCommandResolver.getCommand(key, true)) {
Command.CHARACTER -> composeCharacter(key, composing) Command.CHARACTER -> composeCharacter(key, composing)
Command.SPACE -> insertSpace(composing) Command.SPACE -> insertSpace(composing)
Command.SWITCH_MODE -> switchMode(composing) Command.SWITCH_MODE -> switchMode(WKT9InputMode.WORD, composing)
else -> KeyEventResult(true) else -> KeyEventResult(true)
} }
} }
override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult { override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key, repeat = repeat)) { return when(keyCommandResolver.getCommand(key, repeat = repeat)) {
Command.HOME -> goHome(repeat, composing) Command.HOME -> goHome(repeat, composing)
Command.DELETE -> deleteCharacter(composing) Command.DELETE -> deleteCharacter(composing)
else -> KeyEventResult() else -> KeyEventResult()
@ -84,6 +81,7 @@ class NumericInputMode: InputMode {
override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult { override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key, after = true)) { return when(keyCommandResolver.getCommand(key, after = true)) {
Command.BACK -> goBack(composing) Command.BACK -> goBack(composing)
Command.FN -> functionMode()
Command.NUMBER -> composeNumber(key, composing) Command.NUMBER -> composeNumber(key, composing)
else -> KeyEventResult() else -> KeyEventResult()
} }
@ -95,53 +93,6 @@ class NumericInputMode: InputMode {
} }
} }
private fun deleteCharacter(composing: Boolean): KeyEventResult {
return KeyEventResult(
finishComposing = composing,
deleteBeforeCursor = 1
)
}
private fun composeCharacter(key: Key, composing: Boolean): KeyEventResult {
val layout = KeyLayout.en_US[key] ?: return KeyEventResult(true)
val candidates = layout.map { it.toString() }
return KeyEventResult(
consumed = true,
finishComposing = composing,
startComposing = true,
candidates = candidates,
timeout = 1200
)
}
private fun composeNumber(key: Key, composing: Boolean): KeyEventResult {
val code = KeyLayout.numeric[key] ?: return KeyEventResult(true)
return KeyEventResult(
consumed = true,
finishComposing = composing,
commit = code.toString()
)
}
private fun goBack(composing: Boolean): KeyEventResult {
return KeyEventResult(
consumed = false,
finishComposing = composing
)
}
private fun goHome(repeat: Int, composing: Boolean): KeyEventResult {
if (repeat > 1) return KeyEventResult(true)
return KeyEventResult(
consumed = true,
finishComposing = composing,
goHome = true
)
}
private fun insertSpace(composing: Boolean): KeyEventResult { private fun insertSpace(composing: Boolean): KeyEventResult {
return KeyEventResult( return KeyEventResult(
consumed = true, consumed = true,
@ -149,35 +100,4 @@ class NumericInputMode: InputMode {
commit = " " commit = " "
) )
} }
private fun keyStats(key: Key) {
when (key != lastKey) {
true -> {
newKey = true
keyIndex = 0
}
false -> {
newKey = false
keyIndex++
}
}
lastKey = key
}
private fun navigateLeft(): KeyEventResult {
return KeyEventResult(left = true)
}
private fun navigateRight(): KeyEventResult {
return KeyEventResult(right = true)
}
private fun switchMode(composing: Boolean): KeyEventResult {
return KeyEventResult(
consumed = true,
finishComposing = composing,
switchInputMode = WKT9InputMode.WORD
)
}
} }

View File

@ -23,8 +23,7 @@ class WordInputMode: BaseInputMode() {
return when(keyCommandResolver.getCommand(key)) { return when(keyCommandResolver.getCommand(key)) {
Command.BACK -> KeyEventResult(consumed = false) Command.BACK -> KeyEventResult(consumed = false)
Command.DELETE -> deleteCharacter(0, composing) Command.DELETE -> deleteCharacter(composing)
Command.FN -> functionMode()
Command.LEFT -> navigateLeft() Command.LEFT -> navigateLeft()
Command.RIGHT -> navigateRight() Command.RIGHT -> navigateRight()
Command.SELECT -> focus() Command.SELECT -> focus()
@ -35,7 +34,7 @@ class WordInputMode: BaseInputMode() {
override fun onKeyLongDown(key: Key, composing: Boolean): KeyEventResult { override fun onKeyLongDown(key: Key, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key, true)) { return when(keyCommandResolver.getCommand(key, true)) {
Command.RECORD -> record(composing) Command.RECORD -> record(composing)
Command.SWITCH_MODE -> switchMode(composing) Command.SWITCH_MODE -> switchMode(WKT9InputMode.ALPHA, composing)
Command.NUMBER -> commitNumber(key, composing) Command.NUMBER -> commitNumber(key, composing)
else -> KeyEventResult(true) else -> KeyEventResult(true)
} }
@ -44,7 +43,7 @@ class WordInputMode: BaseInputMode() {
override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult { override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key, repeat = repeat)) { return when(keyCommandResolver.getCommand(key, repeat = repeat)) {
Command.HOME -> goHome(repeat, composing) Command.HOME -> goHome(repeat, composing)
Command.DELETE -> deleteCharacter(repeat, composing) Command.DELETE -> deleteCharacter(composing)
else -> KeyEventResult() else -> KeyEventResult()
} }
} }
@ -53,6 +52,7 @@ class WordInputMode: BaseInputMode() {
return when(keyCommandResolver.getCommand(key, after = true)) { return when(keyCommandResolver.getCommand(key, after = true)) {
Command.BACK -> goBack(composing) Command.BACK -> goBack(composing)
Command.CHARACTER -> buildCodeWord(key, composing) Command.CHARACTER -> buildCodeWord(key, composing)
Command.FN -> functionMode()
Command.SHIFT_MODE -> shiftMode(composing) Command.SHIFT_MODE -> shiftMode(composing)
Command.SPACE -> finalizeWordOrSentence(composing) Command.SPACE -> finalizeWordOrSentence(composing)
else -> KeyEventResult() else -> KeyEventResult()
@ -66,10 +66,10 @@ class WordInputMode: BaseInputMode() {
} }
} }
override fun deleteCharacter(repeat: Int, composing: Boolean): KeyEventResult { override fun deleteCharacter(composing: Boolean): KeyEventResult {
if (repeat == 0) codeWord.clear() codeWord.clear()
return super.deleteCharacter(repeat, composing) return super.deleteCharacter(composing)
} }
override fun finalizeWordOrSentence(composing: Boolean): KeyEventResult { override fun finalizeWordOrSentence(composing: Boolean): KeyEventResult {
@ -96,10 +96,10 @@ class WordInputMode: BaseInputMode() {
return super.record(composing) return super.record(composing)
} }
override fun switchMode(composing: Boolean): KeyEventResult { override fun switchMode(mode: WKT9InputMode, composing: Boolean): KeyEventResult {
reset() reset()
return super.switchMode(composing) return super.switchMode(mode, composing)
} }
private fun buildCodeWord(key: Key, composing: Boolean): KeyEventResult { private fun buildCodeWord(key: Key, composing: Boolean): KeyEventResult {

View File

@ -71,6 +71,8 @@ class KeyCommandResolver (
Key.BACK to Command.BACK, Key.BACK to Command.BACK,
Key.POUND to Command.SHIFT_MODE, Key.POUND to Command.SHIFT_MODE,
Key.FN to Command.FN
)), )),
afterLong = HashMap(mapOf( afterLong = HashMap(mapOf(

View File

@ -23,7 +23,7 @@ data class KeyEventResult(
val updateWordStatus: Boolean = false, val updateWordStatus: Boolean = false,
val focus: Boolean = false, val focus: Boolean = false,
val switchInputMode: WKT9InputMode? = null, val switchInputMode: WKT9InputMode? = null,
val functionMode: Boolean = false, val toggleFunctionMode: Boolean = false,
val increaseVolume: Boolean = false, val increaseVolume: Boolean = false,
val decreaseVolume: Boolean = false, val decreaseVolume: Boolean = false,
val increaseBrightness: Boolean = false, val increaseBrightness: Boolean = false,