Laid the foundation for conditional key press events
This commit is contained in:
parent
bf7adcbb3a
commit
3b5b77c540
@ -14,6 +14,7 @@ import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.ViewConfiguration
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.ExtractedTextRequest
|
||||
import android.view.inputmethod.InlineSuggestionsRequest
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.view.textservice.SentenceSuggestionsInfo
|
||||
@ -466,6 +467,7 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
||||
if (res.decreaseVolume) onDecreaseVolume()
|
||||
if (res.increaseBrightness) onIncreaseBrightness()
|
||||
if (res.decreaseBrightness) onDecreaseBrightness()
|
||||
if (res.keyEvent != null) onKeyEvent(res.keyEvent)
|
||||
|
||||
return res.consumed
|
||||
}
|
||||
@ -565,16 +567,32 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
||||
}
|
||||
|
||||
private fun onDelete(beforeCursor: Int, afterCursor: Int) {
|
||||
val newCursorPosition = cursorPosition - beforeCursor
|
||||
|
||||
clearCandidates()
|
||||
deleteText(beforeCursor, afterCursor)
|
||||
|
||||
Log.d(tag, "Do we connect now????")
|
||||
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() {
|
||||
requestShowSelf(InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
|
||||
private fun onKeyEvent(keyEvent: KeyEvent) {
|
||||
currentInputConnection?.sendKeyEvent(keyEvent)
|
||||
}
|
||||
|
||||
private fun onToggleFunctionMode() {
|
||||
if (inputMode is FNInputMode) enableInputMode(lastInputMode)
|
||||
else enableInputMode(WKT9InputMode.FN)
|
||||
|
@ -7,7 +7,7 @@ import net.mezimmah.wkt9.keypad.KeyEventResult
|
||||
import net.mezimmah.wkt9.keypad.KeyLayout
|
||||
|
||||
open class BaseInputMode: InputMode {
|
||||
private var packageName: String? = null
|
||||
protected var packageName: String? = null
|
||||
|
||||
protected val tag = "WKT9"
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.mezimmah.wkt9.inputmode
|
||||
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import net.mezimmah.wkt9.keypad.Command
|
||||
import net.mezimmah.wkt9.keypad.Key
|
||||
import net.mezimmah.wkt9.keypad.KeyEventResult
|
||||
@ -16,6 +17,7 @@ class IdleInputMode : BaseInputMode() {
|
||||
override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult {
|
||||
return when(keyCommandResolver.getCommand(key)) {
|
||||
Command.FN -> KeyEventResult(true)
|
||||
Command.SELECT -> conditionalSelect()
|
||||
else -> KeyEventResult(false)
|
||||
}
|
||||
}
|
||||
@ -46,4 +48,17 @@ class IdleInputMode : BaseInputMode() {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package net.mezimmah.wkt9.keypad
|
||||
|
||||
import android.view.KeyEvent
|
||||
import net.mezimmah.wkt9.inputmode.WKT9InputMode
|
||||
import java.lang.StringBuilder
|
||||
|
||||
@ -27,5 +28,6 @@ data class KeyEventResult(
|
||||
val increaseVolume: Boolean = false,
|
||||
val decreaseVolume: Boolean = false,
|
||||
val increaseBrightness: Boolean = false,
|
||||
val decreaseBrightness: Boolean = false
|
||||
val decreaseBrightness: Boolean = false,
|
||||
val keyEvent: KeyEvent? = null
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user