Fast progress
This commit is contained in:
parent
40a21c6588
commit
0a39862571
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
|
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
|
@ -96,6 +96,8 @@ class WKT9: InputMethodService() {
|
||||
|
||||
inputMode = null
|
||||
cursorPosition = 0
|
||||
|
||||
clearCandidates()
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
@ -209,10 +211,8 @@ class WKT9: InputMethodService() {
|
||||
return currentInputConnection?.setComposingText(text, cursorPosition) ?: false
|
||||
}
|
||||
|
||||
private fun deleteText(beforeCursor: Int, afterCursor: Int): Boolean {
|
||||
val cursorPosition = currentInputEditorInfo?.initialSelEnd ?: 0
|
||||
|
||||
return commitText("", cursorPosition - beforeCursor, cursorPosition + afterCursor, 1)
|
||||
private fun deleteText(beforeCursor: Int, afterCursor: Int) {
|
||||
currentInputConnection?.deleteSurroundingText(beforeCursor, afterCursor)
|
||||
}
|
||||
|
||||
// Todo: inputType
|
||||
@ -238,6 +238,8 @@ class WKT9: InputMethodService() {
|
||||
if (res.startComposing) markComposingRegion()
|
||||
if (!res.codeWord.isNullOrEmpty()) onCodeWordUpdate(res.codeWord)
|
||||
if (!res.candidates.isNullOrEmpty()) onCandidates(res.candidates)
|
||||
if (res.deleteBeforeCursor > 0 || res.deleteAfterCursor > 0) onDelete(res.deleteBeforeCursor, res.deleteAfterCursor)
|
||||
if (res.left) onLeft()
|
||||
if (res.right) onRight()
|
||||
|
||||
return res.consumed
|
||||
@ -292,10 +294,33 @@ class WKT9: InputMethodService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDelete(beforeCursor: Int, afterCursor: Int) {
|
||||
clearCandidates()
|
||||
deleteText(beforeCursor, afterCursor)
|
||||
}
|
||||
|
||||
private fun onLeft() {
|
||||
if (candidates.isEmpty()) return
|
||||
|
||||
candidateIndex--
|
||||
|
||||
if (candidateIndex < 0) candidateIndex = candidates.count() - 1
|
||||
|
||||
clearCandidateUI()
|
||||
loadCandidates(candidateIndex)
|
||||
composeText(candidates[candidateIndex])
|
||||
}
|
||||
|
||||
private fun onRight() {
|
||||
if (candidates.isEmpty()) return
|
||||
|
||||
Log.d(tag, "Let's have some fun!!")
|
||||
candidateIndex++
|
||||
|
||||
if (candidateIndex >= candidates.count()) candidateIndex = 0
|
||||
|
||||
clearCandidateUI()
|
||||
loadCandidates(candidateIndex)
|
||||
composeText(candidates[candidateIndex])
|
||||
}
|
||||
|
||||
private suspend fun queryT9Candidates(codeWord: StringBuilder, limit: Int = 10): Boolean {
|
||||
|
@ -6,6 +6,7 @@ import net.mezimmah.wkt9.keypad.Key
|
||||
import net.mezimmah.wkt9.keypad.KeyCommandResolver
|
||||
import net.mezimmah.wkt9.keypad.KeyEventResult
|
||||
import java.lang.StringBuilder
|
||||
import java.lang.annotation.Native
|
||||
|
||||
class WordInputMode: InputMode {
|
||||
private val tag = "WKT9"
|
||||
@ -21,8 +22,10 @@ class WordInputMode: InputMode {
|
||||
return when(keyCommandResolver.getCommand(key)) {
|
||||
Command.CHARACTER -> buildCodeWord(key)
|
||||
// Command.SELECT -> true
|
||||
// Command.DELETE -> delete()
|
||||
Command.DELETE -> deleteCharacter()
|
||||
Command.SPACE -> finalizeWordOrSentence()
|
||||
Command.LEFT -> navigateLeft()
|
||||
Command.RIGHT -> navigateRight()
|
||||
// Command.CYCLE_CANDIDATES -> cycleCandidates()
|
||||
else -> KeyEventResult()
|
||||
}
|
||||
@ -35,9 +38,10 @@ class WordInputMode: InputMode {
|
||||
}
|
||||
|
||||
override fun onKeyDownRepeatedly(key: Key, repeat: Int): KeyEventResult {
|
||||
// Log.d(tag, "onKeyDownRepeatedly")
|
||||
|
||||
return KeyEventResult()
|
||||
return when(keyCommandResolver.getCommand(key, repeat = repeat)) {
|
||||
Command.DELETE -> deleteCharacter(repeat)
|
||||
else -> KeyEventResult()
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterKeyDown(key: Key): KeyEventResult {
|
||||
@ -64,8 +68,19 @@ class WordInputMode: InputMode {
|
||||
)
|
||||
}
|
||||
|
||||
private fun deleteCharacter(repeat: Int = 0): KeyEventResult {
|
||||
if (repeat % 2 != 0) return KeyEventResult()
|
||||
|
||||
codeWord.clear()
|
||||
|
||||
return KeyEventResult(
|
||||
finishComposing = true,
|
||||
deleteBeforeCursor = 1
|
||||
)
|
||||
}
|
||||
|
||||
private fun finalizeWordOrSentence(): KeyEventResult {
|
||||
if (!newKey) return KeyEventResult(right = true)
|
||||
if (!newKey) return navigateRight()
|
||||
|
||||
val finishComposing = codeWord.isNotEmpty()
|
||||
|
||||
@ -92,4 +107,12 @@ class WordInputMode: InputMode {
|
||||
|
||||
lastKey = key
|
||||
}
|
||||
|
||||
private fun navigateLeft(): KeyEventResult {
|
||||
return KeyEventResult(left = true)
|
||||
}
|
||||
|
||||
private fun navigateRight(): KeyEventResult {
|
||||
return KeyEventResult(right = true)
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ enum class Command {
|
||||
SHIFT_MODE,
|
||||
SWITCH_MODE,
|
||||
NAVIGATE,
|
||||
RIGHT,
|
||||
LEFT,
|
||||
RECORD,
|
||||
TRANSCRIBE
|
||||
}
|
@ -39,12 +39,12 @@ class KeyCommandResolver (
|
||||
Key.N8 to Command.CHARACTER,
|
||||
Key.N9 to Command.CHARACTER,
|
||||
|
||||
Key.LEFT to Command.NAVIGATE,
|
||||
Key.RIGHT to Command.NAVIGATE,
|
||||
Key.LEFT to Command.LEFT,
|
||||
Key.RIGHT to Command.RIGHT,
|
||||
Key.UP to Command.NAVIGATE,
|
||||
Key.DOWN to Command.NAVIGATE,
|
||||
|
||||
Key.STAR to Command.CYCLE_CANDIDATES,
|
||||
Key.STAR to Command.DELETE,
|
||||
Key.DELETE to Command.DELETE,
|
||||
Key.SELECT to Command.SELECT
|
||||
)),
|
||||
@ -70,12 +70,11 @@ class KeyCommandResolver (
|
||||
)),
|
||||
|
||||
afterLong = HashMap(mapOf(
|
||||
Key.DELETE to Command.DELETE,
|
||||
Key.SELECT to Command.TRANSCRIBE,
|
||||
)),
|
||||
|
||||
onRepeat = HashMap(mapOf(
|
||||
Key.DELETE to Command.DELETE,
|
||||
Key.STAR to Command.DELETE,
|
||||
))
|
||||
)
|
||||
}
|
||||
|
@ -8,5 +8,8 @@ data class KeyEventResult(
|
||||
val startComposing: Boolean = false,
|
||||
val codeWord: StringBuilder? = null,
|
||||
val candidates: List<String>? = null,
|
||||
val deleteBeforeCursor: Int = 0,
|
||||
val deleteAfterCursor: Int = 0,
|
||||
val left: Boolean = false,
|
||||
val right: Boolean = false
|
||||
)
|
||||
|
@ -1,12 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/current_suggestion"
|
||||
android:id="@+id/suggestion"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginRight="2dp"
|
||||
android:padding="8dp"
|
||||
android:background="@drawable/suggestion_current_border"
|
||||
android:textFontWeight="600"
|
||||
android:textSize="20dp"
|
||||
android:textSize="20sp"
|
||||
android:minWidth="40dp"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/current_suggestion" />
|
Loading…
x
Reference in New Issue
Block a user