From 43f26793744879a58e9cdcc03d32881fb5197284 Mon Sep 17 00:00:00 2001 From: Nehemiah of Zebulun Date: Thu, 31 Aug 2023 16:30:47 +0200 Subject: [PATCH] Progress --- app/src/main/java/net/mezimmah/wkt9/WKT9.kt | 45 +++++++++--- .../mezimmah/wkt9/inputmode/AlphaInputMode.kt | 1 + .../mezimmah/wkt9/inputmode/IdleInputMode.kt | 68 +++++++++++++++++++ .../mezimmah/wkt9/inputmode/WKT9InputMode.kt | 3 +- .../main/res/drawable/idle_en_us_lower.xml | 14 ++++ 5 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/net/mezimmah/wkt9/inputmode/IdleInputMode.kt create mode 100644 app/src/main/res/drawable/idle_en_us_lower.xml diff --git a/app/src/main/java/net/mezimmah/wkt9/WKT9.kt b/app/src/main/java/net/mezimmah/wkt9/WKT9.kt index 54ce866..a66aeda 100644 --- a/app/src/main/java/net/mezimmah/wkt9/WKT9.kt +++ b/app/src/main/java/net/mezimmah/wkt9/WKT9.kt @@ -30,6 +30,7 @@ import net.mezimmah.wkt9.dao.WordDao import net.mezimmah.wkt9.db.AppDatabase import net.mezimmah.wkt9.inputmode.InputMode import net.mezimmah.wkt9.inputmode.AlphaInputMode +import net.mezimmah.wkt9.inputmode.IdleInputMode import net.mezimmah.wkt9.inputmode.NumericInputMode import net.mezimmah.wkt9.inputmode.Status import net.mezimmah.wkt9.inputmode.WordInputMode @@ -81,6 +82,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene private lateinit var alphaInputMode: AlphaInputMode private lateinit var numericInputMode: NumericInputMode private lateinit var wordInputMode: WordInputMode + private lateinit var idleInputMode: IdleInputMode private var composing = false private val candidates: MutableList = mutableListOf() private var candidateIndex = 0 @@ -91,6 +93,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene // Spell checker private lateinit var locale: Locale + private var allowSuggestions = false private var spellCheckerSession: SpellCheckerSession? = null // UI @@ -118,6 +121,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene alphaInputMode = AlphaInputMode() numericInputMode = NumericInputMode() wordInputMode = WordInputMode() + idleInputMode = IdleInputMode() longPressTimeout = ViewConfiguration.getLongPressTimeout() lastComposedString = null commitHistory.clear() @@ -199,6 +203,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene val inputType = attribute?.inputType val inputClass = inputType?.and(InputType.TYPE_MASK_CLASS) ?: 0 val typeVariation = inputType?.and(InputType.TYPE_MASK_VARIATION) ?: 0 + val typeFlags = inputType?.and(InputType.TYPE_MASK_FLAGS) ?: 0 // val textServiceManager = getSystemService(TEXT_SERVICES_MANAGER_SERVICE) as TextServicesManager cursorPosition = attribute?.initialSelEnd ?: 0 @@ -208,15 +213,8 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene InputType.TYPE_CLASS_DATETIME, InputType.TYPE_CLASS_NUMBER, InputType.TYPE_CLASS_PHONE -> enableInputMode(WKT9InputMode.NUMERIC) - InputType.TYPE_CLASS_TEXT -> { - if (typeVariation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS) { - Log.d(tag, "Heja") - } - - if (lastInputMode == WKT9InputMode.ALPHA) enableInputMode(WKT9InputMode.ALPHA) - else enableInputMode(WKT9InputMode.WORD) - } - else -> Log.d(tag, "Mode without input...") + InputType.TYPE_CLASS_TEXT -> enableTextInputMode(typeVariation, typeFlags) + else -> enableInputMode(WKT9InputMode.IDLE) } updateInputStatus() @@ -317,9 +315,34 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene WKT9InputMode.ALPHA -> alphaInputMode WKT9InputMode.NUMERIC -> numericInputMode WKT9InputMode.WORD -> wordInputMode + WKT9InputMode.IDLE -> idleInputMode } } + private fun enableTextInputMode(variation: Int, flags: Int) { + val letterVariations = listOf( + InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS, + InputType.TYPE_TEXT_VARIATION_URI, + InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS, + InputType.TYPE_TEXT_VARIATION_PASSWORD, + InputType.TYPE_TEXT_VARIATION_FILTER, + InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD, + InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD, + InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS, + InputType.TYPE_TEXT_VARIATION_PERSON_NAME + ) + + if (letterVariations.contains(variation)) { + allowSuggestions = false + + enableInputMode(WKT9InputMode.ALPHA) + } else if (lastInputMode == WKT9InputMode.ALPHA) { + allowSuggestions = flags != InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS + + enableInputMode(WKT9InputMode.ALPHA) + } else enableInputMode(WKT9InputMode.WORD) + } + private fun finishComposingText(): Boolean { return if (composing) { composing = false @@ -330,6 +353,8 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene lastComposedString = null } + if (allowSuggestions) Log.d(tag, "History: ${commitHistory.toString()}") + updateInputStatus() currentInputConnection?.finishComposingText() ?: false @@ -553,7 +578,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene when (mode) { WKT9InputMode.ALPHA -> enableInputMode(WKT9InputMode.ALPHA) WKT9InputMode.NUMERIC -> enableInputMode(WKT9InputMode.NUMERIC) - WKT9InputMode.WORD -> enableInputMode(WKT9InputMode.WORD) + else -> enableInputMode(WKT9InputMode.WORD) } clearCandidates() diff --git a/app/src/main/java/net/mezimmah/wkt9/inputmode/AlphaInputMode.kt b/app/src/main/java/net/mezimmah/wkt9/inputmode/AlphaInputMode.kt index 589f5b2..b38827d 100644 --- a/app/src/main/java/net/mezimmah/wkt9/inputmode/AlphaInputMode.kt +++ b/app/src/main/java/net/mezimmah/wkt9/inputmode/AlphaInputMode.kt @@ -6,6 +6,7 @@ import net.mezimmah.wkt9.keypad.Key import net.mezimmah.wkt9.keypad.KeyCommandResolver import net.mezimmah.wkt9.keypad.KeyEventResult import net.mezimmah.wkt9.keypad.KeyLayout +import java.lang.StringBuilder class AlphaInputMode: InputMode { private val tag = "WKT9" diff --git a/app/src/main/java/net/mezimmah/wkt9/inputmode/IdleInputMode.kt b/app/src/main/java/net/mezimmah/wkt9/inputmode/IdleInputMode.kt new file mode 100644 index 0000000..86106d7 --- /dev/null +++ b/app/src/main/java/net/mezimmah/wkt9/inputmode/IdleInputMode.kt @@ -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 + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/net/mezimmah/wkt9/inputmode/WKT9InputMode.kt b/app/src/main/java/net/mezimmah/wkt9/inputmode/WKT9InputMode.kt index 3bb0f19..15eec32 100644 --- a/app/src/main/java/net/mezimmah/wkt9/inputmode/WKT9InputMode.kt +++ b/app/src/main/java/net/mezimmah/wkt9/inputmode/WKT9InputMode.kt @@ -3,5 +3,6 @@ package net.mezimmah.wkt9.inputmode enum class WKT9InputMode(val idx: Int) { WORD(0), ALPHA(1), - NUMERIC(2) + NUMERIC(2), + IDLE(3) } \ No newline at end of file diff --git a/app/src/main/res/drawable/idle_en_us_lower.xml b/app/src/main/res/drawable/idle_en_us_lower.xml new file mode 100644 index 0000000..cd5f4b0 --- /dev/null +++ b/app/src/main/res/drawable/idle_en_us_lower.xml @@ -0,0 +1,14 @@ + + + +