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
This commit is contained in:
Aleksandras Kostarevas 2024-05-26 16:43:20 +03:00
parent fd3a4297ec
commit e0ddb4462c
4 changed files with 111 additions and 27 deletions

View File

@ -167,6 +167,26 @@
android:label="@string/payment"
android:clearTaskOnLaunch="false"
android:launchMode="singleInstance" />
<activity
android:name=".uix.TextEditPopupActivity"
android:exported="true"
android:label="Testing Popup"
android:clearTaskOnLaunch="true"
android:launchMode="singleInstance"
android:visibleToInstantApps="true"
android:configChanges="orientation|screenLayout|screenSize|keyboardHidden|keyboard|uiMode|density"
android:process=":texteditpopup"
android:theme="@style/Theme.TextEditPopup">
<intent-filter>
<action android:name="android.speech.action.RECOGNIZE_SPEECH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<!-- To query enabled input methods for voice IME detection -->

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.TextEditPopup" parent="Theme.AppCompat.DayNight.Dialog">
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">@null</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
</resources>

View File

@ -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()
}
}
}
}

View File

@ -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())
}
}
}