From 1b0dd25244f81fdb1664a335d0d58e838aae7c60 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Sat, 26 Aug 2023 21:31:31 +0300 Subject: [PATCH] Separate actions into its own files --- .../futo/inputmethod/latin/uix/ActionBar.kt | 2 + .../futo/inputmethod/latin/uix/BaseActions.kt | 93 ------------------- .../latin/uix/InlineSuggestionView.kt | 2 + .../latin/uix/actions/ThemeAction.kt | 52 +++++++++++ .../latin/uix/actions/VoiceInputAction.kt | 44 +++++++++ 5 files changed, 100 insertions(+), 93 deletions(-) create mode 100644 java/src/org/futo/inputmethod/latin/uix/actions/ThemeAction.kt create mode 100644 java/src/org/futo/inputmethod/latin/uix/actions/VoiceInputAction.kt diff --git a/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt b/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt index e7ea69710..aa7f361f1 100644 --- a/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt +++ b/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt @@ -63,6 +63,8 @@ import org.futo.inputmethod.latin.SuggestedWords import org.futo.inputmethod.latin.SuggestedWords.SuggestedWordInfo import org.futo.inputmethod.latin.SuggestedWords.SuggestedWordInfo.KIND_TYPED import org.futo.inputmethod.latin.suggestions.SuggestionStripView +import org.futo.inputmethod.latin.uix.actions.ThemeAction +import org.futo.inputmethod.latin.uix.actions.VoiceInputAction import org.futo.inputmethod.latin.uix.theme.DarkColorScheme import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper import java.lang.Integer.min diff --git a/java/src/org/futo/inputmethod/latin/uix/BaseActions.kt b/java/src/org/futo/inputmethod/latin/uix/BaseActions.kt index 71dd8ccfb..e7cdaabbd 100644 --- a/java/src/org/futo/inputmethod/latin/uix/BaseActions.kt +++ b/java/src/org/futo/inputmethod/latin/uix/BaseActions.kt @@ -2,97 +2,4 @@ package org.futo.inputmethod.latin.uix -import android.os.Build -import androidx.compose.foundation.gestures.Orientation -import androidx.compose.foundation.gestures.scrollable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.rememberScrollState -import androidx.compose.material3.Button -import androidx.compose.material3.Icon -import androidx.compose.material3.Text -import androidx.compose.material3.darkColorScheme -import androidx.compose.material3.dynamicDarkColorScheme -import androidx.compose.material3.dynamicLightColorScheme -import androidx.compose.material3.lightColorScheme -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocal -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.unit.dp -import org.futo.inputmethod.latin.R -import org.futo.inputmethod.latin.uix.theme.DarkColorScheme -import org.futo.inputmethod.latin.uix.theme.ThemeOptionKeys -import org.futo.inputmethod.latin.uix.theme.ThemeOptions - -// TODO: For now, this calls CODE_SHORTCUT. In the future, we will want to -// make this a window -val VoiceInputAction = Action( - icon = R.drawable.mic_fill, - name = "Voice Input", - //simplePressImpl = { - // it.triggerSystemVoiceInput() - //}, - simplePressImpl = null, - windowImpl = object : ActionWindow { - @Composable - override fun windowName(): String { - return "Voice Input" - } - - @Composable - override fun WindowContents(manager: KeyboardManagerForAction) { - Box(modifier = Modifier.fillMaxSize()) { - Icon( - painter = painterResource(id = R.drawable.mic_fill), - contentDescription = null, - modifier = Modifier.align(Alignment.Center).size(48.dp) - ) - } - } - } -) - -val ThemeAction = Action( - icon = R.drawable.eye, - name = "Theme Switcher", - simplePressImpl = null, - windowImpl = object : ActionWindow { - @Composable - override fun windowName(): String { - return "Theme Switcher" - } - - @Composable - override fun WindowContents(manager: KeyboardManagerForAction) { - val context = LocalContext.current - LazyColumn(modifier = Modifier - .padding(8.dp, 0.dp) - .fillMaxWidth()) - { - items(ThemeOptionKeys.count()) { - val key = ThemeOptionKeys[it] - val themeOption = ThemeOptions[key] - if(themeOption != null && themeOption.available(context)) { - Button(onClick = { - manager.updateTheme( - themeOption - ) - }) { - Text(themeOption.name) - } - } - } - } - } - } -) diff --git a/java/src/org/futo/inputmethod/latin/uix/InlineSuggestionView.kt b/java/src/org/futo/inputmethod/latin/uix/InlineSuggestionView.kt index 154d1aec5..1f3865335 100644 --- a/java/src/org/futo/inputmethod/latin/uix/InlineSuggestionView.kt +++ b/java/src/org/futo/inputmethod/latin/uix/InlineSuggestionView.kt @@ -127,6 +127,8 @@ fun Context.inflateInlineSuggestion(inlineSuggestion: InlineSuggestion): Mutable @Composable fun InlineSuggestionView(inlineSuggestion: MutableState) { if (inlineSuggestion.value != null) { + // TODO: For some reason this appears over top of keyboard key previews + // We should also make it animate in and round corners AndroidView( factory = { inlineSuggestion.value!! }, modifier = Modifier.padding(4.dp, 0.dp) diff --git a/java/src/org/futo/inputmethod/latin/uix/actions/ThemeAction.kt b/java/src/org/futo/inputmethod/latin/uix/actions/ThemeAction.kt new file mode 100644 index 000000000..707769e98 --- /dev/null +++ b/java/src/org/futo/inputmethod/latin/uix/actions/ThemeAction.kt @@ -0,0 +1,52 @@ +package org.futo.inputmethod.latin.uix.actions + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.unit.dp +import org.futo.inputmethod.latin.R +import org.futo.inputmethod.latin.uix.Action +import org.futo.inputmethod.latin.uix.ActionWindow +import org.futo.inputmethod.latin.uix.KeyboardManagerForAction +import org.futo.inputmethod.latin.uix.theme.ThemeOptionKeys +import org.futo.inputmethod.latin.uix.theme.ThemeOptions + +val ThemeAction = Action( + icon = R.drawable.eye, + name = "Theme Switcher", + simplePressImpl = null, + windowImpl = object : ActionWindow { + @Composable + override fun windowName(): String { + return "Theme Switcher" + } + + @Composable + override fun WindowContents(manager: KeyboardManagerForAction) { + val context = LocalContext.current + LazyColumn(modifier = Modifier + .padding(8.dp, 0.dp) + .fillMaxWidth()) + { + items(ThemeOptionKeys.count()) { + val key = ThemeOptionKeys[it] + val themeOption = ThemeOptions[key] + if(themeOption != null && themeOption.available(context)) { + Button(onClick = { + manager.updateTheme( + themeOption + ) + }) { + Text(themeOption.name) + } + } + } + } + } + } +) \ No newline at end of file diff --git a/java/src/org/futo/inputmethod/latin/uix/actions/VoiceInputAction.kt b/java/src/org/futo/inputmethod/latin/uix/actions/VoiceInputAction.kt new file mode 100644 index 000000000..7045c2466 --- /dev/null +++ b/java/src/org/futo/inputmethod/latin/uix/actions/VoiceInputAction.kt @@ -0,0 +1,44 @@ +package org.futo.inputmethod.latin.uix.actions + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.size +import androidx.compose.material3.Icon +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import org.futo.inputmethod.latin.R +import org.futo.inputmethod.latin.uix.Action +import org.futo.inputmethod.latin.uix.ActionWindow +import org.futo.inputmethod.latin.uix.KeyboardManagerForAction + + +// TODO: For now, this calls CODE_SHORTCUT. In the future, we will want to +// make this a window +val VoiceInputAction = Action( + icon = R.drawable.mic_fill, + name = "Voice Input", + //simplePressImpl = { + // it.triggerSystemVoiceInput() + //}, + simplePressImpl = null, + windowImpl = object : ActionWindow { + @Composable + override fun windowName(): String { + return "Voice Input" + } + + @Composable + override fun WindowContents(manager: KeyboardManagerForAction) { + Box(modifier = Modifier.fillMaxSize()) { + Icon( + painter = painterResource(id = R.drawable.mic_fill), + contentDescription = null, + modifier = Modifier.align(Alignment.Center).size(48.dp) + ) + } + } + } +) \ No newline at end of file