mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Set SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR when necessary
This commit is contained in:
parent
f261de9fab
commit
645c7d6e49
@ -1,6 +1,7 @@
|
|||||||
package org.futo.inputmethod.latin
|
package org.futo.inputmethod.latin
|
||||||
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
import android.graphics.Color
|
||||||
import android.inputmethodservice.InputMethodService
|
import android.inputmethodservice.InputMethodService
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -66,6 +67,7 @@ import org.futo.inputmethod.latin.uix.setSetting
|
|||||||
import org.futo.inputmethod.latin.uix.theme.DarkColorScheme
|
import org.futo.inputmethod.latin.uix.theme.DarkColorScheme
|
||||||
import org.futo.inputmethod.latin.uix.theme.ThemeOption
|
import org.futo.inputmethod.latin.uix.theme.ThemeOption
|
||||||
import org.futo.inputmethod.latin.uix.theme.ThemeOptions
|
import org.futo.inputmethod.latin.uix.theme.ThemeOptions
|
||||||
|
import org.futo.inputmethod.latin.uix.theme.applyWindowColors
|
||||||
import org.futo.inputmethod.latin.uix.theme.presets.VoiceInputTheme
|
import org.futo.inputmethod.latin.uix.theme.presets.VoiceInputTheme
|
||||||
import org.futo.inputmethod.latin.xlm.LanguageModelFacilitator
|
import org.futo.inputmethod.latin.xlm.LanguageModelFacilitator
|
||||||
import org.futo.inputmethod.updates.scheduleUpdateCheckingJob
|
import org.futo.inputmethod.updates.scheduleUpdateCheckingJob
|
||||||
@ -132,11 +134,26 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
|||||||
Log.w("LatinIME", "Recreating keyboard")
|
Log.w("LatinIME", "Recreating keyboard")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var isNavigationBarVisible = false
|
||||||
|
fun updateNavigationBarVisibility(visible: Boolean? = null) {
|
||||||
|
if(visible != null) isNavigationBarVisible = visible
|
||||||
|
|
||||||
|
val color = drawableProvider?.primaryKeyboardColor
|
||||||
|
|
||||||
|
window.window?.let { window ->
|
||||||
|
if(color == null || !isNavigationBarVisible) {
|
||||||
|
applyWindowColors(window, Color.TRANSPARENT, statusBar = false)
|
||||||
|
} else {
|
||||||
|
applyWindowColors(window, color, statusBar = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateDrawableProvider(colorScheme: ColorScheme) {
|
private fun updateDrawableProvider(colorScheme: ColorScheme) {
|
||||||
activeColorScheme = colorScheme
|
activeColorScheme = colorScheme
|
||||||
drawableProvider = BasicThemeProvider(this, overrideColorScheme = colorScheme)
|
drawableProvider = BasicThemeProvider(this, overrideColorScheme = colorScheme)
|
||||||
|
|
||||||
window.window?.navigationBarColor = drawableProvider!!.primaryKeyboardColor
|
updateNavigationBarVisibility()
|
||||||
uixManager.onColorSchemeChanged()
|
uixManager.onColorSchemeChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2040,13 +2040,7 @@ public class LatinIMELegacy implements KeyboardActionListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setNavigationBarVisibility(final boolean visible) {
|
private void setNavigationBarVisibility(final boolean visible) {
|
||||||
int color = ((DynamicThemeProviderOwner)getInputMethodService()).getDrawableProvider().getPrimaryKeyboardColor();
|
((LatinIME)mInputMethodService).updateNavigationBarVisibility(visible);
|
||||||
if (BuildCompatUtils.EFFECTIVE_SDK_INT > Build.VERSION_CODES.M) {
|
|
||||||
// For N and later, IMEs can specify Color.TRANSPARENT to make the navigation bar
|
|
||||||
// transparent. For other colors the system uses the default color.
|
|
||||||
mInputMethodService.getWindow().getWindow().setNavigationBarColor(
|
|
||||||
visible ? color : Color.TRANSPARENT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputMethodService getInputMethodService() {
|
public InputMethodService getInputMethodService() {
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
package org.futo.inputmethod.latin.uix.theme
|
package org.futo.inputmethod.latin.uix.theme
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.view.WindowManager
|
import android.view.View
|
||||||
|
import android.view.Window
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
import androidx.compose.material3.ColorScheme
|
import androidx.compose.material3.ColorScheme
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.darkColorScheme
|
import androidx.compose.material3.darkColorScheme
|
||||||
import androidx.compose.material3.dynamicDarkColorScheme
|
|
||||||
import androidx.compose.material3.dynamicLightColorScheme
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.SideEffect
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalView
|
import kotlin.math.sqrt
|
||||||
import androidx.core.view.WindowCompat
|
|
||||||
|
|
||||||
val DarkColorScheme = darkColorScheme(
|
val DarkColorScheme = darkColorScheme(
|
||||||
primary = Slate600,
|
primary = Slate600,
|
||||||
@ -49,14 +45,28 @@ val DarkColorScheme = darkColorScheme(
|
|||||||
onSurfaceVariant = Slate300
|
onSurfaceVariant = Slate300
|
||||||
)
|
)
|
||||||
|
|
||||||
fun applyWindowColors(context: Context, backgroundColor: Color) {
|
fun applyWindowColors(window: Window, @ColorInt color: Int, statusBar: Boolean) {
|
||||||
val window = (context as Activity).window
|
if(statusBar) {
|
||||||
val color = backgroundColor.copy(alpha = 0.75f).toArgb()
|
window.statusBarColor = color
|
||||||
|
}
|
||||||
window.statusBarColor = color
|
|
||||||
window.navigationBarColor = color
|
window.navigationBarColor = color
|
||||||
|
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
val view = window.decorView
|
||||||
|
val uiFlags = view.systemUiVisibility
|
||||||
|
|
||||||
|
val luminance = sqrt(
|
||||||
|
0.299 * android.graphics.Color.red(color) / 255.0
|
||||||
|
+ 0.587 * android.graphics.Color.green(color) / 255.0
|
||||||
|
+ 0.114 * android.graphics.Color.blue(color) / 255.0
|
||||||
|
)
|
||||||
|
|
||||||
|
if (luminance > 0.5 && color != android.graphics.Color.TRANSPARENT) {
|
||||||
|
view.systemUiVisibility = uiFlags or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||||
|
} else {
|
||||||
|
view.systemUiVisibility = uiFlags and (View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -64,7 +74,7 @@ fun StatusBarColorSetter() {
|
|||||||
val backgroundColor = MaterialTheme.colorScheme.background
|
val backgroundColor = MaterialTheme.colorScheme.background
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
LaunchedEffect(backgroundColor) {
|
LaunchedEffect(backgroundColor) {
|
||||||
applyWindowColors(context, backgroundColor)
|
applyWindowColors((context as Activity).window, backgroundColor.toArgb(), statusBar = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user