diff --git a/app/src/main/java/net/mezimmah/wkt9/WKT9.kt b/app/src/main/java/net/mezimmah/wkt9/WKT9.kt index c36f3f1..c9fd36b 100644 --- a/app/src/main/java/net/mezimmah/wkt9/WKT9.kt +++ b/app/src/main/java/net/mezimmah/wkt9/WKT9.kt @@ -204,28 +204,8 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene } override fun onStartInput(attribute: EditorInfo?, restarting: Boolean) { - 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 - - cursorPosition = attribute?.initialSelEnd ?: 0 - - val forceNumeric = resources.getStringArray(R.array.input_mode_numeric) - - if (forceNumeric.contains(attribute?.packageName)) enableInputMode(WKT9InputMode.NUMERIC) - else { - when (inputClass) { - InputType.TYPE_CLASS_DATETIME, - InputType.TYPE_CLASS_NUMBER, - InputType.TYPE_CLASS_PHONE -> enableInputMode(WKT9InputMode.NUMERIC) - - InputType.TYPE_CLASS_TEXT -> enableTextInputMode(typeVariation, typeFlags) - else -> enableInputMode(WKT9InputMode.IDLE) - } - } - - updateInputStatus() + if (restarting) restartInput() + else startInput(attribute) super.onStartInput(attribute, restarting) } @@ -749,6 +729,12 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene composeText(candidates[candidateIndex]) } + private fun restartInput() { + inputMode?.restart() + + clearCandidates() + } + private fun requestWriteSettings() { val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS) @@ -758,6 +744,31 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene startActivity(intent) } + private fun startInput(attribute: EditorInfo?) { + 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 + + cursorPosition = attribute?.initialSelEnd ?: 0 + + val forceNumeric = resources.getStringArray(R.array.input_mode_numeric) + + if (forceNumeric.contains(attribute?.packageName)) enableInputMode(WKT9InputMode.NUMERIC) + else { + when (inputClass) { + InputType.TYPE_CLASS_DATETIME, + InputType.TYPE_CLASS_NUMBER, + InputType.TYPE_CLASS_PHONE -> enableInputMode(WKT9InputMode.NUMERIC) + + InputType.TYPE_CLASS_TEXT -> enableTextInputMode(typeVariation, typeFlags) + else -> enableInputMode(WKT9InputMode.IDLE) + } + } + + updateInputStatus() + } + private fun updateInputStatus() { inputStatus = inputMode?.status ?: Status.CAP diff --git a/app/src/main/java/net/mezimmah/wkt9/inputmode/BaseInputMode.kt b/app/src/main/java/net/mezimmah/wkt9/inputmode/BaseInputMode.kt index 8b46ac3..a236dc0 100644 --- a/app/src/main/java/net/mezimmah/wkt9/inputmode/BaseInputMode.kt +++ b/app/src/main/java/net/mezimmah/wkt9/inputmode/BaseInputMode.kt @@ -1,5 +1,6 @@ package net.mezimmah.wkt9.inputmode +import android.util.Log import net.mezimmah.wkt9.keypad.Key import net.mezimmah.wkt9.keypad.KeyCommandResolver import net.mezimmah.wkt9.keypad.KeyEventResult @@ -42,6 +43,10 @@ open class BaseInputMode: InputMode { return KeyEventResult() } + override fun restart() { + Log.d(tag, "Restart should be handled by individual input modes") + } + protected fun commit(text: String, composing: Boolean): KeyEventResult { return KeyEventResult( consumed = true, diff --git a/app/src/main/java/net/mezimmah/wkt9/inputmode/InputMode.kt b/app/src/main/java/net/mezimmah/wkt9/inputmode/InputMode.kt index 219f758..015aaa0 100644 --- a/app/src/main/java/net/mezimmah/wkt9/inputmode/InputMode.kt +++ b/app/src/main/java/net/mezimmah/wkt9/inputmode/InputMode.kt @@ -16,4 +16,6 @@ interface InputMode { fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult fun afterKeyLongDown(key: Key, keyDownMS: Long, composing: Boolean): KeyEventResult + + fun restart() } \ No newline at end of file diff --git a/app/src/main/java/net/mezimmah/wkt9/inputmode/WordInputMode.kt b/app/src/main/java/net/mezimmah/wkt9/inputmode/WordInputMode.kt index 731848d..b9a704a 100644 --- a/app/src/main/java/net/mezimmah/wkt9/inputmode/WordInputMode.kt +++ b/app/src/main/java/net/mezimmah/wkt9/inputmode/WordInputMode.kt @@ -65,6 +65,10 @@ class WordInputMode: BaseInputMode() { } } + override fun restart() { + reset() + } + override fun commitNumber(key: Key, composing: Boolean): KeyEventResult { codeWord.clear()