Compare commits
No commits in common. "3b5b77c540bd0ac0f7ee3ebca92d8d2eb742ed40" and "cbaa339c376ff9d3a34e1f0a49de26857c08cc93" have entirely different histories.
3b5b77c540
...
cbaa339c37
@ -37,7 +37,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("androidx.core:core-ktx:1.12.0")
|
implementation("androidx.core:core-ktx:1.10.1")
|
||||||
implementation("androidx.appcompat:appcompat:1.6.1")
|
implementation("androidx.appcompat:appcompat:1.6.1")
|
||||||
implementation("com.google.android.material:material:1.9.0")
|
implementation("com.google.android.material:material:1.9.0")
|
||||||
implementation("androidx.room:room-common:2.5.2")
|
implementation("androidx.room:room-common:2.5.2")
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package net.mezimmah.wkt9
|
package net.mezimmah.wkt9
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.inputmethodservice.InputMethodService
|
import android.inputmethodservice.InputMethodService
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.media.MediaRecorder
|
import android.media.MediaRecorder
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.text.InputType
|
import android.text.InputType
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@ -14,8 +14,6 @@ import android.view.KeyEvent
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewConfiguration
|
import android.view.ViewConfiguration
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.view.inputmethod.ExtractedTextRequest
|
|
||||||
import android.view.inputmethod.InlineSuggestionsRequest
|
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.view.textservice.SentenceSuggestionsInfo
|
import android.view.textservice.SentenceSuggestionsInfo
|
||||||
import android.view.textservice.SpellCheckerSession
|
import android.view.textservice.SpellCheckerSession
|
||||||
@ -25,7 +23,6 @@ import android.view.textservice.TextServicesManager
|
|||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import android.widget.inline.InlinePresentationSpec
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@ -53,7 +50,6 @@ import okio.IOException
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
|
|
||||||
class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListener {
|
class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListener {
|
||||||
private val tag = "WKT9"
|
private val tag = "WKT9"
|
||||||
|
|
||||||
@ -139,14 +135,6 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
super.onCreate()
|
super.onCreate()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateInlineSuggestionsRequest(uiExtras: Bundle): InlineSuggestionsRequest? {
|
|
||||||
Log.d(tag, "Here we are")
|
|
||||||
|
|
||||||
return InlineSuggestionsRequest.Builder(ArrayList<InlinePresentationSpec>())
|
|
||||||
.setMaxSuggestionCount(InlineSuggestionsRequest.SUGGESTION_COUNT_UNLIMITED)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
override fun onCreateInputView(): View? {
|
override fun onCreateInputView(): View? {
|
||||||
inputView = layoutInflater.inflate(R.layout.suggestions, null)
|
inputView = layoutInflater.inflate(R.layout.suggestions, null)
|
||||||
@ -216,8 +204,28 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartInput(attribute: EditorInfo?, restarting: Boolean) {
|
override fun onStartInput(attribute: EditorInfo?, restarting: Boolean) {
|
||||||
if (restarting) restartInput()
|
val inputType = attribute?.inputType
|
||||||
else startInput(attribute)
|
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()
|
||||||
|
|
||||||
super.onStartInput(attribute, restarting)
|
super.onStartInput(attribute, restarting)
|
||||||
}
|
}
|
||||||
@ -467,7 +475,6 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
if (res.decreaseVolume) onDecreaseVolume()
|
if (res.decreaseVolume) onDecreaseVolume()
|
||||||
if (res.increaseBrightness) onIncreaseBrightness()
|
if (res.increaseBrightness) onIncreaseBrightness()
|
||||||
if (res.decreaseBrightness) onDecreaseBrightness()
|
if (res.decreaseBrightness) onDecreaseBrightness()
|
||||||
if (res.keyEvent != null) onKeyEvent(res.keyEvent)
|
|
||||||
|
|
||||||
return res.consumed
|
return res.consumed
|
||||||
}
|
}
|
||||||
@ -567,32 +574,14 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onDelete(beforeCursor: Int, afterCursor: Int) {
|
private fun onDelete(beforeCursor: Int, afterCursor: Int) {
|
||||||
val newCursorPosition = cursorPosition - beforeCursor
|
|
||||||
|
|
||||||
clearCandidates()
|
clearCandidates()
|
||||||
deleteText(beforeCursor, afterCursor)
|
deleteText(beforeCursor, afterCursor)
|
||||||
|
|
||||||
if (newCursorPosition < 1) return
|
|
||||||
|
|
||||||
val extractedTextRequest = ExtractedTextRequest()
|
|
||||||
val request = currentInputConnection?.getExtractedText(extractedTextRequest, 0)
|
|
||||||
val text = request?.text
|
|
||||||
|
|
||||||
text?.let {
|
|
||||||
Log.d(tag, "Last char before cursor = ${it[newCursorPosition - 1]}")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log.d(tag, "Text: $sub, ${text?.length}, $cursorPosition")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onFocus() {
|
private fun onFocus() {
|
||||||
requestShowSelf(InputMethodManager.SHOW_IMPLICIT)
|
requestShowSelf(InputMethodManager.SHOW_IMPLICIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onKeyEvent(keyEvent: KeyEvent) {
|
|
||||||
currentInputConnection?.sendKeyEvent(keyEvent)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onToggleFunctionMode() {
|
private fun onToggleFunctionMode() {
|
||||||
if (inputMode is FNInputMode) enableInputMode(lastInputMode)
|
if (inputMode is FNInputMode) enableInputMode(lastInputMode)
|
||||||
else enableInputMode(WKT9InputMode.FN)
|
else enableInputMode(WKT9InputMode.FN)
|
||||||
@ -760,12 +749,6 @@ 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)
|
||||||
|
|
||||||
@ -775,35 +758,6 @@ 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
attribute?.packageName?.let {
|
|
||||||
inputMode?.packageName(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
updateInputStatus()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateInputStatus() {
|
private fun updateInputStatus() {
|
||||||
inputStatus = inputMode?.status ?: Status.CAP
|
inputStatus = inputMode?.status ?: Status.CAP
|
||||||
|
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
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
|
||||||
import net.mezimmah.wkt9.keypad.KeyLayout
|
import net.mezimmah.wkt9.keypad.KeyLayout
|
||||||
|
|
||||||
open class BaseInputMode: InputMode {
|
open class BaseInputMode: InputMode {
|
||||||
protected var packageName: String? = null
|
|
||||||
|
|
||||||
protected val tag = "WKT9"
|
protected val tag = "WKT9"
|
||||||
|
|
||||||
protected var newKey = true
|
protected var newKey = true
|
||||||
@ -45,14 +42,6 @@ open class BaseInputMode: InputMode {
|
|||||||
return KeyEventResult()
|
return KeyEventResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun packageName(packageName: String) {
|
|
||||||
this.packageName = packageName
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.mezimmah.wkt9.inputmode
|
package net.mezimmah.wkt9.inputmode
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.KeyEvent
|
|
||||||
import net.mezimmah.wkt9.keypad.Command
|
import net.mezimmah.wkt9.keypad.Command
|
||||||
import net.mezimmah.wkt9.keypad.Key
|
import net.mezimmah.wkt9.keypad.Key
|
||||||
import net.mezimmah.wkt9.keypad.KeyEventResult
|
import net.mezimmah.wkt9.keypad.KeyEventResult
|
||||||
@ -17,7 +16,6 @@ class IdleInputMode : BaseInputMode() {
|
|||||||
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
|
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
|
||||||
return when(keyCommandResolver.getCommand(key)) {
|
return when(keyCommandResolver.getCommand(key)) {
|
||||||
Command.FN -> KeyEventResult(true)
|
Command.FN -> KeyEventResult(true)
|
||||||
Command.SELECT -> conditionalSelect()
|
|
||||||
else -> KeyEventResult(false)
|
else -> KeyEventResult(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,17 +46,4 @@ class IdleInputMode : BaseInputMode() {
|
|||||||
else -> KeyEventResult(false)
|
else -> KeyEventResult(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun conditionalSelect(): KeyEventResult {
|
|
||||||
return when (packageName) {
|
|
||||||
"com.android.camera2" -> {
|
|
||||||
KeyEventResult(
|
|
||||||
consumed = true,
|
|
||||||
keyEvent = KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_CAMERA)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> KeyEventResult(consumed = false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -16,8 +16,4 @@ 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 packageName(packageName: String)
|
|
||||||
|
|
||||||
fun restart()
|
|
||||||
}
|
}
|
@ -65,10 +65,6 @@ 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()
|
||||||
|
|
||||||
@ -76,17 +72,9 @@ class WordInputMode: BaseInputMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun deleteCharacter(composing: Boolean): KeyEventResult {
|
override fun deleteCharacter(composing: Boolean): KeyEventResult {
|
||||||
return if (codeWord.length > 1) {
|
codeWord.clear()
|
||||||
codeWord.deleteAt(codeWord.length - 1)
|
|
||||||
|
|
||||||
KeyEventResult(
|
return super.deleteCharacter(composing)
|
||||||
codeWord = codeWord
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
codeWord.clear()
|
|
||||||
|
|
||||||
super.deleteCharacter(composing)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun finalizeWordOrSentence(composing: Boolean): KeyEventResult {
|
override fun finalizeWordOrSentence(composing: Boolean): KeyEventResult {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.mezimmah.wkt9.keypad
|
package net.mezimmah.wkt9.keypad
|
||||||
|
|
||||||
import android.view.KeyEvent
|
|
||||||
import net.mezimmah.wkt9.inputmode.WKT9InputMode
|
import net.mezimmah.wkt9.inputmode.WKT9InputMode
|
||||||
import java.lang.StringBuilder
|
import java.lang.StringBuilder
|
||||||
|
|
||||||
@ -28,6 +27,5 @@ data class KeyEventResult(
|
|||||||
val increaseVolume: Boolean = false,
|
val increaseVolume: Boolean = false,
|
||||||
val decreaseVolume: Boolean = false,
|
val decreaseVolume: Boolean = false,
|
||||||
val increaseBrightness: Boolean = false,
|
val increaseBrightness: Boolean = false,
|
||||||
val decreaseBrightness: Boolean = false,
|
val decreaseBrightness: Boolean = false
|
||||||
val keyEvent: KeyEvent? = null
|
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
|
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:settingsActivity="net.mezimmah.wkt9.preferences.PreferencesActivity"
|
android:settingsActivity="net.mezimmah.wkt9.preferences.PreferencesActivity">
|
||||||
android:supportsInlineSuggestions="true">
|
|
||||||
|
|
||||||
<subtype
|
<subtype
|
||||||
android:label="English US"
|
android:label="English US"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user