Support for restarting input
This commit is contained in:
parent
cbaa339c37
commit
e86ff3b3b2
@ -204,28 +204,8 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartInput(attribute: EditorInfo?, restarting: Boolean) {
|
override fun onStartInput(attribute: EditorInfo?, restarting: Boolean) {
|
||||||
val inputType = attribute?.inputType
|
if (restarting) restartInput()
|
||||||
val inputClass = inputType?.and(InputType.TYPE_MASK_CLASS) ?: 0
|
else startInput(attribute)
|
||||||
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()
|
|
||||||
|
|
||||||
super.onStartInput(attribute, restarting)
|
super.onStartInput(attribute, restarting)
|
||||||
}
|
}
|
||||||
@ -749,6 +729,12 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
composeText(candidates[candidateIndex])
|
composeText(candidates[candidateIndex])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun restartInput() {
|
||||||
|
inputMode?.restart()
|
||||||
|
|
||||||
|
clearCandidates()
|
||||||
|
}
|
||||||
|
|
||||||
private fun requestWriteSettings() {
|
private fun requestWriteSettings() {
|
||||||
val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
|
val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
|
||||||
|
|
||||||
@ -758,6 +744,31 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
startActivity(intent)
|
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() {
|
private fun updateInputStatus() {
|
||||||
inputStatus = inputMode?.status ?: Status.CAP
|
inputStatus = inputMode?.status ?: Status.CAP
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.mezimmah.wkt9.inputmode
|
package net.mezimmah.wkt9.inputmode
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
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
|
||||||
@ -42,6 +43,10 @@ open class BaseInputMode: InputMode {
|
|||||||
return KeyEventResult()
|
return KeyEventResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun restart() {
|
||||||
|
Log.d(tag, "Restart should be handled by individual input modes")
|
||||||
|
}
|
||||||
|
|
||||||
protected fun commit(text: String, composing: Boolean): KeyEventResult {
|
protected fun commit(text: String, composing: Boolean): KeyEventResult {
|
||||||
return KeyEventResult(
|
return KeyEventResult(
|
||||||
consumed = true,
|
consumed = true,
|
||||||
|
@ -16,4 +16,6 @@ interface InputMode {
|
|||||||
fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult
|
fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult
|
||||||
|
|
||||||
fun afterKeyLongDown(key: Key, keyDownMS: Long, composing: Boolean): KeyEventResult
|
fun afterKeyLongDown(key: Key, keyDownMS: Long, composing: Boolean): KeyEventResult
|
||||||
|
|
||||||
|
fun restart()
|
||||||
}
|
}
|
@ -65,6 +65,10 @@ class WordInputMode: BaseInputMode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun restart() {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
|
||||||
override fun commitNumber(key: Key, composing: Boolean): KeyEventResult {
|
override fun commitNumber(key: Key, composing: Boolean): KeyEventResult {
|
||||||
codeWord.clear()
|
codeWord.clear()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user