This commit is contained in:
Nehemiah of Zebulun 2023-08-30 11:26:55 +02:00
parent 65d278d907
commit a356774001
5 changed files with 152 additions and 36 deletions

View File

@ -386,7 +386,7 @@ class WKT9: InputMethodService() {
}
loadCandidates(candidateIndex)
composeText(candidates[candidateIndex])
composeText(this.candidates[candidateIndex])
handleComposeTimeout(timeout)
}

View File

@ -174,7 +174,7 @@ class AlphaInputMode: InputMode {
return KeyEventResult(
consumed = true,
finishComposing = composing,
switchInputMode = WKT9InputMode.WORD
switchInputMode = WKT9InputMode.NUMERIC
)
}

View File

@ -2,51 +2,157 @@ package net.mezimmah.wkt9.inputmode
import android.util.Log
import net.mezimmah.wkt9.keypad.Command
import net.mezimmah.wkt9.keypad.KeyCommandResolver
import net.mezimmah.wkt9.keypad.Key
import net.mezimmah.wkt9.keypad.KeyCommandResolver
import net.mezimmah.wkt9.keypad.KeyEventResult
import java.lang.StringBuilder
import net.mezimmah.wkt9.keypad.KeyLayout
class NumericInputMode: InputMode {
override val mode: String = "numeric"
private val tag = "WKT9"
private val keyCommandResolver: KeyCommandResolver = KeyCommandResolver.getBasic()
private val codeWord = StringBuilder()
private val parentKeyCommandResolver: KeyCommandResolver = KeyCommandResolver.getBasic()
private val keyCommandResolver: KeyCommandResolver = KeyCommandResolver(
parent = parentKeyCommandResolver,
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
))
)
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
override fun onKeyDown(key: Key, sentenceStart: Boolean): KeyEventResult {
init {
Log.d(tag, "Started numeric input mode.")
}
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
keyStats(key)
return when(keyCommandResolver.getCommand(key)) {
Command.CHARACTER -> buildCodeWord(key)
// Command.SELECT -> true
// Command.DELETE -> delete()
// Command.SPACE -> finalizeWordOrSentence()
// Command.CYCLE_CANDIDATES -> cycleCandidates()
else -> KeyEventResult(consumed = true)
Command.BACK -> KeyEventResult(consumed = false)
Command.DELETE -> deleteCharacter(composing)
Command.LEFT -> navigateLeft()
Command.RIGHT -> navigateRight()
else -> KeyEventResult()
}
}
override fun onKeyLongDown(key: Key, sentenceStart: Boolean): KeyEventResult {
return KeyEventResult(consumed = false)
override fun onKeyLongDown(key: Key, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key, true)) {
Command.SWITCH_MODE -> switchMode(composing)
else -> KeyEventResult(true)
}
}
override fun onKeyDownRepeatedly(key: Key, repeat: Int, sentenceStart: Boolean): KeyEventResult {
return KeyEventResult(consumed = false)
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, sentenceStart: Boolean): KeyEventResult {
return KeyEventResult(consumed = false)
override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key, after = true)) {
Command.BACK -> goBack(composing)
Command.NUMBER -> composeNumber(key, composing)
else -> KeyEventResult()
}
}
override fun afterKeyLongDown(key: Key, keyDownMS: Long, sentenceStart: Boolean): KeyEventResult {
return KeyEventResult(consumed = false)
override fun afterKeyLongDown(key: Key, keyDownMS: Long, composing: Boolean): KeyEventResult {
return when(keyCommandResolver.getCommand(key, after = true, longPress = true)) {
else -> KeyEventResult()
}
}
private fun buildCodeWord(key: Key): KeyEventResult {
Log.d(tag, "GR8!")
private fun deleteCharacter(composing: Boolean): KeyEventResult {
return KeyEventResult(
finishComposing = composing,
deleteBeforeCursor = 1
)
}
return KeyEventResult(consumed = true)
private fun composeNumber(key: Key, composing: Boolean): KeyEventResult {
if (composing && !newKey) return navigateRight()
val layout = KeyLayout.numeric[key] ?: return KeyEventResult(true)
val candidates = layout.map { it.toString() }
return KeyEventResult(
consumed = true,
finishComposing = composing,
startComposing = true,
candidates = candidates,
timeout = 400
)
}
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 switchMode(composing: Boolean): KeyEventResult {
return KeyEventResult(
consumed = true,
finishComposing = composing,
switchInputMode = WKT9InputMode.WORD
)
}
}

View File

@ -3,16 +3,16 @@ package net.mezimmah.wkt9.keypad
object KeyLayout {
// Map for number input mode
val numeric = mapOf(
Key.N0 to '0',
Key.N1 to '1',
Key.N2 to '2',
Key.N3 to '3',
Key.N4 to '4',
Key.N5 to '5',
Key.N6 to '6',
Key.N7 to '7',
Key.N8 to '8',
Key.N9 to '9',
Key.N0 to listOf('0'),
Key.N1 to listOf('1'),
Key.N2 to listOf('2'),
Key.N3 to listOf('3'),
Key.N4 to listOf('4'),
Key.N5 to listOf('5'),
Key.N6 to listOf('6'),
Key.N7 to listOf('7'),
Key.N8 to listOf('8'),
Key.N9 to listOf('9'),
)
val en_US = mapOf(

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:fillColor="#FF000000"
android:pathData="M0.948,7.445Q1.759,6.976 2.612,6.293 3.508,5.611 4.319,4.843 5.129,4.032 5.812,3.221 6.537,2.368 7.007,1.557H9.823V31.125H6.153V7.36Q5.428,8.128 4.447,8.811 3.508,9.493 2.441,10.091ZM17.185,3.392q2.517,-2.517 6.144,-2.517 3.456,0 5.291,1.835 1.835,1.792 1.835,5.632 0,1.792 -0.597,3.413 -0.597,1.621 -1.493,3.157 -0.896,1.493 -1.963,2.987 -1.067,1.493 -2.048,3.072 -0.981,1.536 -1.707,3.243 -0.725,1.664 -0.896,3.584h9.301v3.328H17.825v-0.811q0,-2.859 0.64,-5.077 0.683,-2.219 1.621,-4.011 0.981,-1.792 2.133,-3.328 1.152,-1.536 2.091,-2.987 0.981,-1.493 1.621,-3.029 0.683,-1.579 0.683,-3.456 0,-2.261 -0.896,-3.243 -0.896,-1.024 -2.688,-1.024 -1.237,0 -2.261,0.512 -0.981,0.469 -1.792,1.237z"
android:strokeWidth="0.815"/>
</vector>