From ed819c8cb3257ff7de8cf8a82037567d8252b823 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Tue, 15 Jun 2021 21:02:55 +0700 Subject: [PATCH] Use monet colors in settings ui --- .../lawnchair/ui/preferences/Preferences.kt | 2 +- .../ui/preferences/components/TopBar.kt | 3 +- lawnchair/src/app/lawnchair/ui/theme/Theme.kt | 46 +++++++++++++++---- .../src/app/lawnchair/util/ResourceUtils.kt | 16 +++++++ src/com/android/launcher3/Utilities.java | 2 + 5 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 lawnchair/src/app/lawnchair/util/ResourceUtils.kt diff --git a/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt index d596fdf17e..64ceb5ef41 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt @@ -65,7 +65,7 @@ fun Preferences(interactor: PreferenceInteractor = viewModel Unit) { @Composable fun topBarColors(): Pair { val elevationOverlay = LocalElevationOverlay.current + val backgroundColor = MaterialTheme.colors.background val surfaceColor = MaterialTheme.colors.surface val floatingColor = elevationOverlay?.apply(surfaceColor, 4.dp) ?: surfaceColor - return Pair(surfaceColor.copy(alpha = 0.9f), floatingColor.copy(alpha = 0.9f)) + return Pair(backgroundColor.copy(alpha = 0.9f), floatingColor.copy(alpha = 0.9f)) } @Composable diff --git a/lawnchair/src/app/lawnchair/ui/theme/Theme.kt b/lawnchair/src/app/lawnchair/ui/theme/Theme.kt index efab825d09..2e35516a6a 100644 --- a/lawnchair/src/app/lawnchair/ui/theme/Theme.kt +++ b/lawnchair/src/app/lawnchair/ui/theme/Theme.kt @@ -17,22 +17,23 @@ package app.lawnchair.ui.theme import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material.Colors import androidx.compose.material.MaterialTheme import androidx.compose.material.darkColors import androidx.compose.material.lightColors import androidx.compose.runtime.* -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.colorResource import app.lawnchair.preferences.observeAsState import app.lawnchair.preferences.preferenceManager import app.lawnchair.ui.preferences.components.ThemeChoice +import app.lawnchair.util.androidColorId import com.android.launcher3.Utilities import com.android.launcher3.uioverrides.WallpaperColorInfo private val DarkColorPalette = darkColors( primary = Blue600, - secondary = Blue600, - background = Color.Black + secondary = Blue600 ) private val LightColorPalette = lightColors( @@ -45,11 +46,7 @@ fun LawnchairTheme( darkTheme: Boolean = isSelectedThemeDark(), content: @Composable () -> Unit ) { - val colors = if (darkTheme) { - DarkColorPalette - } else { - LightColorPalette - } + val colors = getColors(darkTheme) MaterialTheme( colors = colors, @@ -59,6 +56,39 @@ fun LawnchairTheme( ) } +@Composable +fun getColors(darkTheme: Boolean): Colors { + if (Utilities.ATLEAST_S) { + if (darkTheme) { + val accent = colorResource(id = androidColorId(name = "system_accent1_100")) + val surface = colorResource(id = androidColorId(name = "system_neutral1_800")) + val background = colorResource(id = androidColorId(name = "system_neutral1_900")) + return darkColors( + primary = accent, + secondary = accent, + background = background, + surface = surface + ) + } else { + val accent = colorResource(id = androidColorId(name = "system_accent1_600")) + val surface = colorResource(id = androidColorId(name = "system_neutral1_100")) + val background = colorResource(id = androidColorId(name = "system_neutral1_50")) + return lightColors( + primary = accent, + secondary = accent, + background = background, + surface = surface + ) + } + } else { + return if (darkTheme) { + DarkColorPalette + } else { + LightColorPalette + } + } +} + @Composable fun isSelectedThemeDark(): Boolean { val themeChoice by preferenceManager().launcherTheme.observeAsState() diff --git a/lawnchair/src/app/lawnchair/util/ResourceUtils.kt b/lawnchair/src/app/lawnchair/util/ResourceUtils.kt new file mode 100644 index 0000000000..0f6af53664 --- /dev/null +++ b/lawnchair/src/app/lawnchair/util/ResourceUtils.kt @@ -0,0 +1,16 @@ +package app.lawnchair.util + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.platform.LocalContext + +@Composable +fun androidColorId(name: String) = androidResId(name = name, defType = "color") + +@Composable +fun androidResId(name: String, defType: String): Int { + val resources = LocalContext.current.resources + return remember(name, defType) { + resources.getIdentifier(name, defType, "android") + } +} diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 618649f161..8c56fac40e 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -106,6 +106,8 @@ public final class Utilities { public static final String[] EMPTY_STRING_ARRAY = new String[0]; public static final Person[] EMPTY_PERSON_ARRAY = new Person[0]; + public static final boolean ATLEAST_S = BuildCompat.isAtLeastS(); + public static final boolean ATLEAST_R = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R; public static final boolean ATLEAST_Q = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;