Skip to content
Snippets Groups Projects
Commit e0ddb446 authored by Aleksandras Kostarevas's avatar Aleksandras Kostarevas
Browse files

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
parent fd3a4297
No related branches found
No related tags found
No related merge requests found
...@@ -167,6 +167,26 @@ ...@@ -167,6 +167,26 @@
android:label="@string/payment" android:label="@string/payment"
android:clearTaskOnLaunch="false" android:clearTaskOnLaunch="false"
android:launchMode="singleInstance" /> 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> </application>
<!-- To query enabled input methods for voice IME detection --> <!-- To query enabled input methods for voice IME detection -->
......
<?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>
\ No newline at end of file
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()
}
}
}
}
package org.futo.inputmethod.latin.uix.settings.pages 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.Column
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
...@@ -21,11 +19,11 @@ import androidx.compose.ui.res.stringResource ...@@ -21,11 +19,11 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import org.futo.inputmethod.latin.BuildConfig import org.futo.inputmethod.latin.BuildConfig
import org.futo.inputmethod.latin.R 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.USE_SYSTEM_VOICE_INPUT
import org.futo.inputmethod.latin.uix.settings.NavigationItem import org.futo.inputmethod.latin.uix.settings.NavigationItem
import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle
...@@ -34,27 +32,6 @@ import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking ...@@ -34,27 +32,6 @@ import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking
import org.futo.inputmethod.latin.uix.theme.Typography import org.futo.inputmethod.latin.uix.theme.Typography
import org.futo.inputmethod.updates.ConditionalUpdate 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) @Preview(showBackground = true)
@Composable @Composable
fun HomeScreen(navController: NavHostController = rememberNavController()) { fun HomeScreen(navController: NavHostController = rememberNavController()) {
...@@ -166,6 +143,15 @@ fun HomeScreen(navController: NavHostController = rememberNavController()) { ...@@ -166,6 +143,15 @@ fun HomeScreen(navController: NavHostController = rememberNavController()) {
) )
Spacer(modifier = Modifier.height(32.dp)) 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment