Set status bar color in settings

This commit is contained in:
Aleksandras Kostarevas 2023-09-04 14:13:17 +03:00
parent 263165b596
commit 0a7ab52e8b
3 changed files with 24 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.futo.inputmethod.latin.uix.THEME_KEY
import org.futo.inputmethod.latin.uix.deferGetSetting
import org.futo.inputmethod.latin.uix.theme.StatusBarColorSetter
import org.futo.inputmethod.latin.uix.theme.ThemeOption
import org.futo.inputmethod.latin.uix.theme.ThemeOptions
import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper
@ -109,6 +110,7 @@ class SettingsActivity : ComponentActivity() {
val themeIdx = useDataStore(key = THEME_KEY.key, default = themeOption.key)
val theme: ThemeOption = ThemeOptions[themeIdx.value] ?: themeOption
UixThemeWrapper(theme.obtainColors(LocalContext.current)) {
StatusBarColorSetter()
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background

View File

@ -1,9 +1,13 @@
package org.futo.inputmethod.latin.uix.settings.pages
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import org.futo.inputmethod.latin.R
@ -18,6 +22,7 @@ import org.futo.inputmethod.latin.uix.settings.openLanguageSettings
fun HomeScreen(navController: NavHostController = rememberNavController()) {
val context = LocalContext.current
ScrollableList {
Spacer(modifier = Modifier.height(24.dp))
ScreenTitle("FUTO Keyboard Settings")
NavigationItem(
title = "Languages",

View File

@ -2,12 +2,14 @@ package org.futo.inputmethod.latin.uix.theme
import android.app.Activity
import android.os.Build
import android.view.WindowManager
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
@ -45,6 +47,21 @@ val DarkColorScheme = darkColorScheme(
onSurfaceVariant = Slate300
)
@Composable
fun StatusBarColorSetter() {
val backgroundColor = MaterialTheme.colorScheme.background
val context = LocalContext.current
LaunchedEffect(backgroundColor) {
val window = (context as Activity).window
val color = backgroundColor.copy(alpha = 0.75f).toArgb()
window.statusBarColor = color
window.navigationBarColor = color
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
}
}
@Composable
fun UixThemeWrapper(colorScheme: ColorScheme, content: @Composable () -> Unit) {
MaterialTheme(