diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c0fe91f..c95d834 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,14 +1,15 @@ - + + , timeout: Int?) { clearCandidates() @@ -500,6 +517,25 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene commitText(text, cursorPosition, cursorPosition) } + private fun onDecreaseBrightness() { + if (!Settings.System.canWrite(this)) requestWriteSettings() + else { + var brightness = Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS) + + brightness -= 5 + + if (brightness < 0) brightness = 0 + + Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS, brightness) + } + } + + private fun onDecreaseVolume() { + val audioManager = getSystemService(AUDIO_SERVICE) as AudioManager + + audioManager.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI) + } + private fun onDelete(beforeCursor: Int, afterCursor: Int) { clearCandidates() deleteText(beforeCursor, afterCursor) @@ -514,6 +550,25 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene updateInputStatus() } + private fun onIncreaseBrightness() { + if (!Settings.System.canWrite(this)) requestWriteSettings() + else { + var brightness = Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS) + + brightness += 5 + + if (brightness > 255) brightness = 255 + + Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS, brightness) + } + } + + private fun onIncreaseVolume() { + val audioManager = getSystemService(AUDIO_SERVICE) as AudioManager + + audioManager.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI) + } + private fun onIncreaseWeight() { val word = commitHistory.last() @@ -655,6 +710,15 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene composeText(candidates[candidateIndex]) } + private fun requestWriteSettings() { + val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS) + + intent.data = Uri.parse("package:$packageName") + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + + startActivity(intent) + } + private fun updateInputStatus() { inputStatus = inputMode?.status ?: Status.CAP diff --git a/app/src/main/java/net/mezimmah/wkt9/inputmode/FNInputMode.kt b/app/src/main/java/net/mezimmah/wkt9/inputmode/FNInputMode.kt index c63febc..6bcfaca 100644 --- a/app/src/main/java/net/mezimmah/wkt9/inputmode/FNInputMode.kt +++ b/app/src/main/java/net/mezimmah/wkt9/inputmode/FNInputMode.kt @@ -1,11 +1,31 @@ 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 FNInputMode: InputMode { private val tag = "WKT9" + private val parentKeyCommandResolver: KeyCommandResolver = KeyCommandResolver.getBasic() + private val keyCommandResolver: KeyCommandResolver = KeyCommandResolver( + parent = parentKeyCommandResolver, + + onShort = HashMap(mapOf( + Key.UP to Command.VOL_UP, + Key.DOWN to Command.VOL_DOWN, + Key.LEFT to Command.BRIGHTNESS_DOWN, + Key.RIGHT to Command.BRIGHTNESS_UP + )), + + onRepeat = HashMap(mapOf( + Key.UP to Command.VOL_UP, + Key.DOWN to Command.VOL_DOWN, + Key.LEFT to Command.BRIGHTNESS_DOWN, + Key.RIGHT to Command.BRIGHTNESS_UP + )) + ) override val mode: String = "fn" @@ -17,23 +37,62 @@ class FNInputMode: InputMode { } override fun onKeyDown(key: Key, composing: Boolean): KeyEventResult { - return KeyEventResult() + return when(keyCommandResolver.getCommand(key)) { + Command.VOL_UP -> volumeUp() + Command.VOL_DOWN -> volumeDown() + Command.BRIGHTNESS_DOWN -> brightnessDown() + Command.BRIGHTNESS_UP -> brightnessUp() + else -> KeyEventResult(false) + } } override fun onKeyLongDown(key: Key, composing: Boolean): KeyEventResult { - return KeyEventResult() + return KeyEventResult(false) } override fun onKeyDownRepeatedly(key: Key, repeat: Int, composing: Boolean): KeyEventResult { - return KeyEventResult() + return when(keyCommandResolver.getCommand(key, repeat = repeat)) { + Command.VOL_UP -> volumeUp() + Command.VOL_DOWN -> volumeDown() + Command.BRIGHTNESS_DOWN -> brightnessDown() + Command.BRIGHTNESS_UP -> brightnessUp() + else -> KeyEventResult(false) + } } override fun afterKeyDown(key: Key, composing: Boolean): KeyEventResult { - return KeyEventResult() + return KeyEventResult(false) } override fun afterKeyLongDown(key: Key, keyDownMS: Long, composing: Boolean): KeyEventResult { - return KeyEventResult() + return KeyEventResult(false) } + private fun brightnessDown(): KeyEventResult { + return KeyEventResult( + consumed = true, + decreaseBrightness = true + ) + } + + private fun brightnessUp(): KeyEventResult { + return KeyEventResult( + consumed = true, + increaseBrightness = true + ) + } + + private fun volumeUp(): KeyEventResult { + return KeyEventResult( + consumed = true, + increaseVolume = true + ) + } + + private fun volumeDown(): KeyEventResult { + return KeyEventResult( + consumed = true, + decreaseVolume = true + ) + } } \ No newline at end of file diff --git a/app/src/main/java/net/mezimmah/wkt9/keypad/Command.kt b/app/src/main/java/net/mezimmah/wkt9/keypad/Command.kt index ca4b4aa..935eb65 100644 --- a/app/src/main/java/net/mezimmah/wkt9/keypad/Command.kt +++ b/app/src/main/java/net/mezimmah/wkt9/keypad/Command.kt @@ -12,6 +12,10 @@ enum class Command { NAVIGATE, RIGHT, LEFT, + VOL_UP, + VOL_DOWN, + BRIGHTNESS_DOWN, + BRIGHTNESS_UP, RECORD, TRANSCRIBE, BACK, diff --git a/app/src/main/java/net/mezimmah/wkt9/keypad/KeyEventResult.kt b/app/src/main/java/net/mezimmah/wkt9/keypad/KeyEventResult.kt index bd325e8..e188ca4 100644 --- a/app/src/main/java/net/mezimmah/wkt9/keypad/KeyEventResult.kt +++ b/app/src/main/java/net/mezimmah/wkt9/keypad/KeyEventResult.kt @@ -23,5 +23,9 @@ data class KeyEventResult( val updateWordStatus: Boolean = false, val focus: Boolean = false, val switchInputMode: WKT9InputMode? = null, - val functionMode: Boolean = false + val functionMode: Boolean = false, + val increaseVolume: Boolean = false, + val decreaseVolume: Boolean = false, + val increaseBrightness: Boolean = false, + val decreaseBrightness: Boolean = false )