Progress
This commit is contained in:
parent
f805d8dcf3
commit
43f2679374
@ -30,6 +30,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.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
|
||||||
import net.mezimmah.wkt9.inputmode.WordInputMode
|
import net.mezimmah.wkt9.inputmode.WordInputMode
|
||||||
@ -81,6 +82,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
private lateinit var alphaInputMode: AlphaInputMode
|
private lateinit var alphaInputMode: AlphaInputMode
|
||||||
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 var composing = false
|
private var composing = false
|
||||||
private val candidates: MutableList<String> = mutableListOf()
|
private val candidates: MutableList<String> = mutableListOf()
|
||||||
private var candidateIndex = 0
|
private var candidateIndex = 0
|
||||||
@ -91,6 +93,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
|
|
||||||
// Spell checker
|
// Spell checker
|
||||||
private lateinit var locale: Locale
|
private lateinit var locale: Locale
|
||||||
|
private var allowSuggestions = false
|
||||||
private var spellCheckerSession: SpellCheckerSession? = null
|
private var spellCheckerSession: SpellCheckerSession? = null
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
@ -118,6 +121,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
alphaInputMode = AlphaInputMode()
|
alphaInputMode = AlphaInputMode()
|
||||||
numericInputMode = NumericInputMode()
|
numericInputMode = NumericInputMode()
|
||||||
wordInputMode = WordInputMode()
|
wordInputMode = WordInputMode()
|
||||||
|
idleInputMode = IdleInputMode()
|
||||||
longPressTimeout = ViewConfiguration.getLongPressTimeout()
|
longPressTimeout = ViewConfiguration.getLongPressTimeout()
|
||||||
lastComposedString = null
|
lastComposedString = null
|
||||||
commitHistory.clear()
|
commitHistory.clear()
|
||||||
@ -199,6 +203,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
val inputType = attribute?.inputType
|
val inputType = attribute?.inputType
|
||||||
val inputClass = inputType?.and(InputType.TYPE_MASK_CLASS) ?: 0
|
val inputClass = inputType?.and(InputType.TYPE_MASK_CLASS) ?: 0
|
||||||
val typeVariation = inputType?.and(InputType.TYPE_MASK_VARIATION) ?: 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
|
// val textServiceManager = getSystemService(TEXT_SERVICES_MANAGER_SERVICE) as TextServicesManager
|
||||||
|
|
||||||
cursorPosition = attribute?.initialSelEnd ?: 0
|
cursorPosition = attribute?.initialSelEnd ?: 0
|
||||||
@ -208,15 +213,8 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
InputType.TYPE_CLASS_DATETIME,
|
InputType.TYPE_CLASS_DATETIME,
|
||||||
InputType.TYPE_CLASS_NUMBER,
|
InputType.TYPE_CLASS_NUMBER,
|
||||||
InputType.TYPE_CLASS_PHONE -> enableInputMode(WKT9InputMode.NUMERIC)
|
InputType.TYPE_CLASS_PHONE -> enableInputMode(WKT9InputMode.NUMERIC)
|
||||||
InputType.TYPE_CLASS_TEXT -> {
|
InputType.TYPE_CLASS_TEXT -> enableTextInputMode(typeVariation, typeFlags)
|
||||||
if (typeVariation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS) {
|
else -> enableInputMode(WKT9InputMode.IDLE)
|
||||||
Log.d(tag, "Heja")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastInputMode == WKT9InputMode.ALPHA) enableInputMode(WKT9InputMode.ALPHA)
|
|
||||||
else enableInputMode(WKT9InputMode.WORD)
|
|
||||||
}
|
|
||||||
else -> Log.d(tag, "Mode without input...")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateInputStatus()
|
updateInputStatus()
|
||||||
@ -317,9 +315,34 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
WKT9InputMode.ALPHA -> alphaInputMode
|
WKT9InputMode.ALPHA -> alphaInputMode
|
||||||
WKT9InputMode.NUMERIC -> numericInputMode
|
WKT9InputMode.NUMERIC -> numericInputMode
|
||||||
WKT9InputMode.WORD -> wordInputMode
|
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 {
|
private fun finishComposingText(): Boolean {
|
||||||
return if (composing) {
|
return if (composing) {
|
||||||
composing = false
|
composing = false
|
||||||
@ -330,6 +353,8 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
lastComposedString = null
|
lastComposedString = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (allowSuggestions) Log.d(tag, "History: ${commitHistory.toString()}")
|
||||||
|
|
||||||
updateInputStatus()
|
updateInputStatus()
|
||||||
|
|
||||||
currentInputConnection?.finishComposingText() ?: false
|
currentInputConnection?.finishComposingText() ?: false
|
||||||
@ -553,7 +578,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
when (mode) {
|
when (mode) {
|
||||||
WKT9InputMode.ALPHA -> enableInputMode(WKT9InputMode.ALPHA)
|
WKT9InputMode.ALPHA -> enableInputMode(WKT9InputMode.ALPHA)
|
||||||
WKT9InputMode.NUMERIC -> enableInputMode(WKT9InputMode.NUMERIC)
|
WKT9InputMode.NUMERIC -> enableInputMode(WKT9InputMode.NUMERIC)
|
||||||
WKT9InputMode.WORD -> enableInputMode(WKT9InputMode.WORD)
|
else -> enableInputMode(WKT9InputMode.WORD)
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCandidates()
|
clearCandidates()
|
||||||
|
@ -6,6 +6,7 @@ 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
|
||||||
import net.mezimmah.wkt9.keypad.KeyLayout
|
import net.mezimmah.wkt9.keypad.KeyLayout
|
||||||
|
import java.lang.StringBuilder
|
||||||
|
|
||||||
class AlphaInputMode: InputMode {
|
class AlphaInputMode: InputMode {
|
||||||
private val tag = "WKT9"
|
private val tag = "WKT9"
|
||||||
|
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -3,5 +3,6 @@ package net.mezimmah.wkt9.inputmode
|
|||||||
enum class WKT9InputMode(val idx: Int) {
|
enum class WKT9InputMode(val idx: Int) {
|
||||||
WORD(0),
|
WORD(0),
|
||||||
ALPHA(1),
|
ALPHA(1),
|
||||||
NUMERIC(2)
|
NUMERIC(2),
|
||||||
|
IDLE(3)
|
||||||
}
|
}
|
14
app/src/main/res/drawable/idle_en_us_lower.xml
Normal file
14
app/src/main/res/drawable/idle_en_us_lower.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<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="M6.728,15.126 L4.496,15.344Q4.002,14.054 3.521,12.499 3.064,10.919 2.585,9.21 2.135,7.498 1.699,5.696 1.262,3.895 0.858,2.113L3.177,1.886 5.469,13.01 7.001,6.669 9.088,6.465 12.831,12.289 11.177,1.102 13.496,0.874q0.234,1.821 0.409,3.648 0.205,1.824 0.336,3.567 0.128,1.722 0.203,3.317 0.076,1.595 0.08,2.956L12.322,14.577 8.335,8.207ZM28.171,0.869q-1.142,1.714 -2.577,3.436 -1.406,1.718 -3.103,3.465 1.031,0.492 2.211,1.166 1.181,0.675 2.33,1.506 1.175,0.807 2.227,1.757 1.082,0.948 1.881,1.967l-2.696,0.264Q27.546,13.508 26.537,12.641 25.529,11.774 24.427,11.048 23.355,10.319 22.222,9.749 21.115,9.156 20.012,8.759l1.129,6.387 -2.377,0.233 -2.362,-13.357 2.377,-0.233 1.053,5.955Q21.461,6.114 22.893,4.371 24.353,2.626 25.417,1.139Z"
|
||||||
|
android:strokeWidth="0.996"/>
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M14.253,17.249 L14.543,18.724 9.183,19.195 11.462,30.764 8.877,30.991 6.598,19.423 1.238,19.894 0.948,18.419ZM30.741,22.513q0.768,3.898 -1.679,6.129 -2.452,2.209 -8.154,2.733l-0.385,-1.467q3.531,-0.311 5.492,-1.427 1.989,-1.14 2.23,-3.498 -0.711,0.298 -1.596,0.526 -0.889,0.207 -1.898,0.296 -1.671,0.147 -2.868,-0.069 -1.201,-0.237 -2.003,-0.724 -0.806,-0.508 -1.262,-1.197 -0.456,-0.689 -0.614,-1.489 -0.141,-0.716 0.06,-1.485 0.197,-0.789 0.802,-1.464 0.605,-0.675 1.661,-1.175 1.056,-0.5 2.633,-0.639 3.216,-0.283 5.146,1.048 1.93,1.331 2.436,3.902zM24.751,24.348q1.009,-0.089 1.835,-0.29 0.858,-0.204 1.632,-0.508 -0.01,-0.213 -0.047,-0.403 -0.037,-0.19 -0.079,-0.4 -0.162,-0.822 -0.496,-1.543 -0.303,-0.724 -0.852,-1.233 -0.518,-0.512 -1.337,-0.761 -0.792,-0.273 -1.927,-0.173 -0.946,0.083 -1.522,0.413 -0.581,0.308 -0.912,0.745 -0.335,0.415 -0.429,0.917 -0.062,0.499 0.025,0.941 0.253,1.285 1.237,1.885 1.011,0.576 2.872,0.412z"
|
||||||
|
android:strokeWidth="1.026"/>
|
||||||
|
</vector>
|
Loading…
x
Reference in New Issue
Block a user