From 20f897aa5675bc855a4c33c2ccf7d95ee0d1a9ab Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Thu, 21 Mar 2024 19:34:35 -0500 Subject: [PATCH] Keep screen awake during voice input --- java/src/org/futo/inputmethod/latin/uix/Action.kt | 1 + java/src/org/futo/inputmethod/latin/uix/UixManager.kt | 7 +++++++ .../futo/inputmethod/latin/uix/actions/VoiceInputAction.kt | 1 + 3 files changed, 9 insertions(+) diff --git a/java/src/org/futo/inputmethod/latin/uix/Action.kt b/java/src/org/futo/inputmethod/latin/uix/Action.kt index 825ffd9fe..78863baad 100644 --- a/java/src/org/futo/inputmethod/latin/uix/Action.kt +++ b/java/src/org/futo/inputmethod/latin/uix/Action.kt @@ -64,6 +64,7 @@ data class Action( @DrawableRes val icon: Int, @StringRes val name: Int, val canShowKeyboard: Boolean = false, + val keepScreenAwake: Boolean = false, val windowImpl: ((KeyboardManagerForAction, PersistentActionState?) -> ActionWindow)?, val simplePressImpl: ((KeyboardManagerForAction, PersistentActionState?) -> Unit)?, diff --git a/java/src/org/futo/inputmethod/latin/uix/UixManager.kt b/java/src/org/futo/inputmethod/latin/uix/UixManager.kt index 4be518de5..9048e21dd 100644 --- a/java/src/org/futo/inputmethod/latin/uix/UixManager.kt +++ b/java/src/org/futo/inputmethod/latin/uix/UixManager.kt @@ -7,6 +7,7 @@ import android.os.Build import android.os.VibrationEffect import android.os.Vibrator import android.view.View +import android.view.WindowManager import android.view.inputmethod.InlineSuggestionsResponse import androidx.annotation.RequiresApi import androidx.compose.animation.AnimatedVisibility @@ -230,6 +231,10 @@ class UixManager(private val latinIME: LatinIME) { currWindowActionWindow = action.windowImpl?.let { it(keyboardManagerForAction, persistentStates[action]) } + if(action.keepScreenAwake) { + latinIME.window.window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + setContent() } @@ -245,6 +250,8 @@ class UixManager(private val latinIME: LatinIME) { latinIME.onKeyboardShown() + latinIME.window.window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + setContent() } diff --git a/java/src/org/futo/inputmethod/latin/uix/actions/VoiceInputAction.kt b/java/src/org/futo/inputmethod/latin/uix/actions/VoiceInputAction.kt index 299232c72..7767b41eb 100644 --- a/java/src/org/futo/inputmethod/latin/uix/actions/VoiceInputAction.kt +++ b/java/src/org/futo/inputmethod/latin/uix/actions/VoiceInputAction.kt @@ -244,6 +244,7 @@ private class VoiceInputActionWindow( val VoiceInputAction = Action(icon = R.drawable.mic_fill, name = R.string.voice_input_action_title, simplePressImpl = null, + keepScreenAwake = true, persistentState = { VoiceInputPersistentState(it) }, windowImpl = { manager, persistentState -> VoiceInputActionWindow(