Press on
This commit is contained in:
parent
aee8243bf6
commit
3dbd18e867
@ -1,14 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
|
@ -3,7 +3,10 @@ package net.mezimmah.wkt9
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.inputmethodservice.InputMethodService
|
||||
import android.media.AudioManager
|
||||
import android.media.MediaRecorder
|
||||
import android.net.Uri
|
||||
import android.provider.Settings
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
@ -26,14 +29,14 @@ import kotlinx.coroutines.launch
|
||||
import net.mezimmah.wkt9.dao.SettingDao
|
||||
import net.mezimmah.wkt9.dao.WordDao
|
||||
import net.mezimmah.wkt9.db.AppDatabase
|
||||
import net.mezimmah.wkt9.inputmode.InputMode
|
||||
import net.mezimmah.wkt9.inputmode.AlphaInputMode
|
||||
import net.mezimmah.wkt9.inputmode.FNInputMode
|
||||
import net.mezimmah.wkt9.inputmode.IdleInputMode
|
||||
import net.mezimmah.wkt9.inputmode.InputMode
|
||||
import net.mezimmah.wkt9.inputmode.NumericInputMode
|
||||
import net.mezimmah.wkt9.inputmode.Status
|
||||
import net.mezimmah.wkt9.inputmode.WordInputMode
|
||||
import net.mezimmah.wkt9.inputmode.WKT9InputMode
|
||||
import net.mezimmah.wkt9.inputmode.WordInputMode
|
||||
import net.mezimmah.wkt9.keypad.KeyCodeMapping
|
||||
import net.mezimmah.wkt9.keypad.KeyEventResult
|
||||
import net.mezimmah.wkt9.keypad.KeyLayout
|
||||
@ -42,8 +45,9 @@ import net.mezimmah.wkt9.t9.T9
|
||||
import net.mezimmah.wkt9.voice.Whisper
|
||||
import okio.IOException
|
||||
import java.io.File
|
||||
import java.lang.StringBuilder
|
||||
import java.util.Locale
|
||||
import kotlin.math.floor
|
||||
|
||||
|
||||
//val info = arrayOf(TextInfo("banan#", 0, 6, 0, 0))
|
||||
//
|
||||
@ -310,7 +314,6 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
||||
updateInputStatus()
|
||||
}
|
||||
|
||||
// Todo: inputType
|
||||
private fun enableInputMode(mode: WKT9InputMode) {
|
||||
if (mode != WKT9InputMode.FN) lastInputMode = mode
|
||||
|
||||
@ -375,8 +378,6 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
||||
.replace('-', '_')
|
||||
.lowercase()
|
||||
|
||||
Log.d(tag, name)
|
||||
|
||||
return resources.getIdentifier(name, "drawable", packageName)
|
||||
}
|
||||
|
||||
@ -421,6 +422,10 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
||||
if (res.focus) onFocus()
|
||||
if (res.switchInputMode != null) onSwitchInputMode(res.switchInputMode)
|
||||
if (res.functionMode) onFunctionMode()
|
||||
if (res.increaseVolume) onIncreaseVolume()
|
||||
if (res.decreaseVolume) onDecreaseVolume()
|
||||
if (res.increaseBrightness) onIncreaseBrightness()
|
||||
if (res.decreaseBrightness) onDecreaseBrightness()
|
||||
|
||||
return res.consumed
|
||||
}
|
||||
@ -462,6 +467,18 @@ class WKT9: InputMethodService(), SpellCheckerSession.SpellCheckerSessionListene
|
||||
return composing
|
||||
}
|
||||
|
||||
private fun normalize(
|
||||
x: Float,
|
||||
inMin: Float,
|
||||
inMax: Float,
|
||||
outMin: Float,
|
||||
outMax: Float
|
||||
): Float {
|
||||
val outRange = outMax - outMin
|
||||
val inRange = inMax - inMin
|
||||
return (x - inMin) * outRange / inRange + outMin
|
||||
}
|
||||
|
||||
private fun onCandidates(candidates: List<String>, 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
|
||||
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
@ -12,6 +12,10 @@ enum class Command {
|
||||
NAVIGATE,
|
||||
RIGHT,
|
||||
LEFT,
|
||||
VOL_UP,
|
||||
VOL_DOWN,
|
||||
BRIGHTNESS_DOWN,
|
||||
BRIGHTNESS_UP,
|
||||
RECORD,
|
||||
TRANSCRIBE,
|
||||
BACK,
|
||||
|
@ -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
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user