This commit is contained in:
Nehemiah of Zebulun 2023-09-03 11:30:50 +02:00
parent 50cb0d6d9b
commit aee8243bf6
10 changed files with 85 additions and 13 deletions

View File

@ -14,8 +14,6 @@ import android.view.inputmethod.InputMethodManager
import android.view.textservice.SentenceSuggestionsInfo import android.view.textservice.SentenceSuggestionsInfo
import android.view.textservice.SpellCheckerSession import android.view.textservice.SpellCheckerSession
import android.view.textservice.SuggestionsInfo import android.view.textservice.SuggestionsInfo
import android.view.textservice.TextInfo
import android.view.textservice.TextServicesManager
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
@ -30,6 +28,7 @@ import net.mezimmah.wkt9.dao.WordDao
import net.mezimmah.wkt9.db.AppDatabase import net.mezimmah.wkt9.db.AppDatabase
import net.mezimmah.wkt9.inputmode.InputMode import net.mezimmah.wkt9.inputmode.InputMode
import net.mezimmah.wkt9.inputmode.AlphaInputMode import net.mezimmah.wkt9.inputmode.AlphaInputMode
import net.mezimmah.wkt9.inputmode.FNInputMode
import net.mezimmah.wkt9.inputmode.IdleInputMode import net.mezimmah.wkt9.inputmode.IdleInputMode
import net.mezimmah.wkt9.inputmode.NumericInputMode import net.mezimmah.wkt9.inputmode.NumericInputMode
import net.mezimmah.wkt9.inputmode.Status import net.mezimmah.wkt9.inputmode.Status
@ -80,6 +79,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
private var lastInputMode: WKT9InputMode = WKT9InputMode.WORD private var lastInputMode: WKT9InputMode = WKT9InputMode.WORD
private var inputMode: InputMode? = null private var inputMode: InputMode? = null
private lateinit var alphaInputMode: AlphaInputMode private lateinit var alphaInputMode: AlphaInputMode
private lateinit var fnInputMode: FNInputMode
private lateinit var numericInputMode: NumericInputMode private lateinit var numericInputMode: NumericInputMode
private lateinit var wordInputMode: WordInputMode private lateinit var wordInputMode: WordInputMode
private lateinit var idleInputMode: IdleInputMode private lateinit var idleInputMode: IdleInputMode
@ -121,6 +121,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
keypad = Keypad(KeyCodeMapping(KeyCodeMapping.basic), KeyLayout.en_US, KeyLayout.numeric) keypad = Keypad(KeyCodeMapping(KeyCodeMapping.basic), KeyLayout.en_US, KeyLayout.numeric)
t9 = T9(this, keypad, settingDao, wordDao) t9 = T9(this, keypad, settingDao, wordDao)
alphaInputMode = AlphaInputMode() alphaInputMode = AlphaInputMode()
fnInputMode = FNInputMode()
numericInputMode = NumericInputMode() numericInputMode = NumericInputMode()
wordInputMode = WordInputMode() wordInputMode = WordInputMode()
idleInputMode = IdleInputMode() idleInputMode = IdleInputMode()
@ -311,13 +312,14 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
// Todo: inputType // Todo: inputType
private fun enableInputMode(mode: WKT9InputMode) { private fun enableInputMode(mode: WKT9InputMode) {
lastInputMode = mode if (mode != WKT9InputMode.FN) lastInputMode = mode
inputMode = when(mode) { inputMode = when(mode) {
WKT9InputMode.ALPHA -> alphaInputMode WKT9InputMode.ALPHA -> alphaInputMode
WKT9InputMode.NUMERIC -> numericInputMode WKT9InputMode.NUMERIC -> numericInputMode
WKT9InputMode.WORD -> wordInputMode WKT9InputMode.WORD -> wordInputMode
WKT9InputMode.IDLE -> idleInputMode WKT9InputMode.FN -> fnInputMode
else -> idleInputMode
} }
} }
@ -373,6 +375,8 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
.replace('-', '_') .replace('-', '_')
.lowercase() .lowercase()
Log.d(tag, name)
return resources.getIdentifier(name, "drawable", packageName) return resources.getIdentifier(name, "drawable", packageName)
} }
@ -416,6 +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()
return res.consumed return res.consumed
} }
@ -504,6 +509,11 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
requestShowSelf(InputMethodManager.SHOW_IMPLICIT) requestShowSelf(InputMethodManager.SHOW_IMPLICIT)
} }
private fun onFunctionMode() {
enableInputMode(WKT9InputMode.FN)
updateInputStatus()
}
private fun onIncreaseWeight() { private fun onIncreaseWeight() {
val word = commitHistory.last() val word = commitHistory.last()

View File

@ -0,0 +1,39 @@
package net.mezimmah.wkt9.inputmode
import android.util.Log
import net.mezimmah.wkt9.keypad.Key
import net.mezimmah.wkt9.keypad.KeyEventResult
class FNInputMode: InputMode {
private val tag = "WKT9"
override val mode: String = "fn"
override var status: Status = Status.NA
private set
init {
Log.d(tag, "Started $mode input mode.")
}
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
return KeyEventResult()
}
override fun onKeyLongDown(key: Key, composing: Boolean): KeyEventResult {
return KeyEventResult()
}
override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult {
return KeyEventResult()
}
override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult {
return KeyEventResult()
}
override fun afterKeyLongDown(key: Key, keyDownMS: Long, composing: Boolean): KeyEventResult {
return KeyEventResult()
}
}

View File

@ -9,7 +9,7 @@ import net.mezimmah.wkt9.keypad.KeyEventResult
class IdleInputMode : InputMode { class IdleInputMode : InputMode {
override val mode: String = "idle" override val mode: String = "idle"
override var status: Status = Status.LOWER override var status: Status = Status.NA
private set private set
private val tag = "WKT9" private val tag = "WKT9"

View File

@ -4,5 +4,6 @@ enum class Status {
CAP, CAP,
UPPER, UPPER,
LOWER, LOWER,
NUM NUM,
NA
} }

View File

@ -1,8 +1,9 @@
package net.mezimmah.wkt9.inputmode package net.mezimmah.wkt9.inputmode
enum class WKT9InputMode(val idx: Int) { enum class WKT9InputMode {
WORD(0), WORD,
ALPHA(1), ALPHA,
NUMERIC(2), NUMERIC,
IDLE(3) IDLE,
FN
} }

View File

@ -31,6 +31,7 @@ class WordInputMode: InputMode {
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(0, composing)
Command.FN -> functionMode()
Command.LEFT -> navigateLeft() Command.LEFT -> navigateLeft()
Command.RIGHT -> navigateRight() Command.RIGHT -> navigateRight()
Command.SELECT -> focus() Command.SELECT -> focus()
@ -127,6 +128,13 @@ class WordInputMode: InputMode {
) )
} }
private fun functionMode(): KeyEventResult {
return KeyEventResult(
consumed = true,
functionMode = true
)
}
private fun goBack(composing: Boolean): KeyEventResult { private fun goBack(composing: Boolean): KeyEventResult {
reset() reset()

View File

@ -35,7 +35,9 @@ class KeyCommandResolver (
Key.DOWN to Command.NAVIGATE, Key.DOWN to Command.NAVIGATE,
Key.STAR to Command.DELETE, Key.STAR to Command.DELETE,
Key.SELECT to Command.SELECT Key.SELECT to Command.SELECT,
Key.FN to Command.FN
)), )),
onLong = HashMap(mapOf( onLong = HashMap(mapOf(

View File

@ -22,5 +22,6 @@ data class KeyEventResult(
val updateInputStatus: Boolean = false, val updateInputStatus: Boolean = false,
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
) )

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.884,30.784V1.216H14.153V4.501H4.724v9.301h8.363v3.2H4.724V30.784ZM16.951,9.024q1.579,-0.469 3.413,-0.768 1.835,-0.341 3.371,-0.341 1.664,0 3.029,0.469 1.365,0.427 2.304,1.493 0.981,1.067 1.493,2.901 0.555,1.792 0.555,4.48V30.784H27.447V17.557q0,-3.328 -0.853,-4.864 -0.853,-1.536 -3.2,-1.536 -1.237,0 -2.773,0.427V30.784H16.951Z"
android:strokeWidth="0.815"/>
</vector>