From e0ddb4462c741cb8f905a378d63b5484e78d7c3e Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Sun, 26 May 2024 16:43:20 +0300 Subject: [PATCH] Move the test text field to a separate activity and process Fixes some jank exhibited by the fact that the keyboard and the EditText are running in the same process --- java/AndroidManifest.xml | 20 ++++++ java/res/values/themes.xml | 10 +++ .../latin/uix/TextEditPopupActivity.kt | 68 +++++++++++++++++++ .../latin/uix/settings/pages/Home.kt | 40 ++++------- 4 files changed, 111 insertions(+), 27 deletions(-) create mode 100644 java/res/values/themes.xml create mode 100644 java/src/org/futo/inputmethod/latin/uix/TextEditPopupActivity.kt diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml index 5f17cb6e2..ad68afe02 100644 --- a/java/AndroidManifest.xml +++ b/java/AndroidManifest.xml @@ -167,6 +167,26 @@ android:label="@string/payment" android:clearTaskOnLaunch="false" android:launchMode="singleInstance" /> + + + + + + + + + + + diff --git a/java/res/values/themes.xml b/java/res/values/themes.xml new file mode 100644 index 000000000..0355d9ae9 --- /dev/null +++ b/java/res/values/themes.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/java/src/org/futo/inputmethod/latin/uix/TextEditPopupActivity.kt b/java/src/org/futo/inputmethod/latin/uix/TextEditPopupActivity.kt new file mode 100644 index 000000000..b9af94da5 --- /dev/null +++ b/java/src/org/futo/inputmethod/latin/uix/TextEditPopupActivity.kt @@ -0,0 +1,68 @@ +package org.futo.inputmethod.latin.uix + +import android.os.Bundle +import android.view.inputmethod.EditorInfo +import android.widget.EditText +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalInspectionMode +import androidx.compose.ui.unit.dp +import androidx.compose.ui.viewinterop.AndroidView +import org.futo.inputmethod.latin.R + +@Composable +fun AndroidTextInput() { + val context = LocalContext.current + val bgColor = MaterialTheme.colorScheme.background + val fgColor = MaterialTheme.colorScheme.onBackground + + if(!LocalInspectionMode.current) { + val editText = remember { + EditText(context).apply { + inputType = EditorInfo.TYPE_CLASS_TEXT + isSingleLine = false + this. + + setHint(R.string.try_typing) + setBackgroundColor(bgColor.toArgb()) + setTextColor(fgColor.toArgb()) + setHintTextColor(fgColor.copy(alpha = 0.7f).toArgb()) + } + } + + LaunchedEffect(bgColor, fgColor) { + editText.setBackgroundColor(bgColor.toArgb()) + editText.setTextColor(fgColor.toArgb()) + editText.setHintTextColor(fgColor.copy(alpha = 0.7f).toArgb()) + } + + AndroidView({ editText }, modifier = Modifier + .fillMaxWidth() + .padding(16.dp), update = { editText.requestFocus() }) + } +} + + +class TextEditPopupActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContent { + Surface(modifier = Modifier.padding(8.dp), shape = RoundedCornerShape(16.dp)) { + AndroidTextInput() + } + } + } + +} diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Home.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Home.kt index c3ff62dcb..33f4c8e00 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Home.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Home.kt @@ -1,19 +1,17 @@ package org.futo.inputmethod.latin.uix.settings.pages -import android.widget.EditText +import android.content.Intent import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalInspectionMode import androidx.compose.ui.res.painterResource @@ -21,11 +19,11 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import androidx.compose.ui.viewinterop.AndroidView import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import org.futo.inputmethod.latin.BuildConfig import org.futo.inputmethod.latin.R +import org.futo.inputmethod.latin.uix.TextEditPopupActivity import org.futo.inputmethod.latin.uix.USE_SYSTEM_VOICE_INPUT import org.futo.inputmethod.latin.uix.settings.NavigationItem import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle @@ -34,27 +32,6 @@ import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking import org.futo.inputmethod.latin.uix.theme.Typography import org.futo.inputmethod.updates.ConditionalUpdate -@Composable -fun AndroidTextInput() { - val context = LocalContext.current - val bgColor = MaterialTheme.colorScheme.background - val fgColor = MaterialTheme.colorScheme.onBackground - - if(!LocalInspectionMode.current) { - val editText = remember { - EditText(context).apply { - setHint(R.string.try_typing) - setBackgroundColor(bgColor.toArgb()) - setTextColor(fgColor.toArgb()) - setHintTextColor(fgColor.copy(alpha = 0.7f).toArgb()) - } - } - AndroidView({ editText }, modifier = Modifier - .fillMaxWidth() - .padding(8.dp)) - } -} - @Preview(showBackground = true) @Composable fun HomeScreen(navController: NavHostController = rememberNavController()) { @@ -166,6 +143,15 @@ fun HomeScreen(navController: NavHostController = rememberNavController()) { ) Spacer(modifier = Modifier.height(32.dp)) } - AndroidTextInput() + TextButton(onClick = { + val intent = Intent() + intent.setClass(context, TextEditPopupActivity::class.java) + intent.setFlags( + Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP + ) + context.startActivity(intent) + }, modifier = Modifier.fillMaxWidth()) { + Text(stringResource(R.string.try_typing), color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.7f), modifier = Modifier.fillMaxWidth()) + } } } \ No newline at end of file