mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-11 06:44:00 +00:00
Use system colors on S
This commit is contained in:
@@ -24,16 +24,10 @@ fun lightenColor(@ColorInt color: Int): Int {
|
||||
return ColorUtils.HSLToColor(outHsl)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION") // use Resources.getColor(int) directly because we don't need the theme
|
||||
fun Context.getDefaultAccentColor(darkTheme: Boolean): Int {
|
||||
val res = resources
|
||||
val colorScheme = ColorSchemeCache.INSTANCE.get(this).defaultColorScheme
|
||||
return when {
|
||||
Utilities.ATLEAST_S -> {
|
||||
val colorName = if (darkTheme) "system_accent1_100" else "system_accent1_600"
|
||||
val colorId = res.getIdentifier(colorName, "color", "android")
|
||||
res.getColor(colorId)
|
||||
}
|
||||
darkTheme -> res.getColor(R.color.primary_200)
|
||||
else -> res.getColor(R.color.primary_500)
|
||||
darkTheme -> colorScheme.primaryDark.toSrgb().quantize8()
|
||||
else -> colorScheme.primary.toSrgb().quantize8()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.content.Context
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import app.lawnchair.preferences.PreferenceManager
|
||||
import app.lawnchair.ui.theme.color.DefaultColorScheme
|
||||
import app.lawnchair.ui.theme.color.SystemColorScheme
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.launcher3.util.MainThreadInitializedObject
|
||||
import dev.kdrag0n.android12ext.monet.theme.ColorScheme
|
||||
import dev.kdrag0n.android12ext.monet.theme.DynamicColorScheme
|
||||
@@ -12,6 +14,7 @@ import dev.kdrag0n.android12ext.monet.theme.TargetColors
|
||||
class ColorSchemeCache(private val context: Context) {
|
||||
private val prefs = PreferenceManager.getInstance(context)
|
||||
private val targetColors by lazy { TargetColors() }
|
||||
val defaultColorScheme = loadDefaultColorScheme()
|
||||
private val currentColorScheme = mutableStateOf(loadColorScheme())
|
||||
val current get() = currentColorScheme.value
|
||||
|
||||
@@ -19,12 +22,20 @@ class ColorSchemeCache(private val context: Context) {
|
||||
currentColorScheme.value = loadColorScheme()
|
||||
}
|
||||
|
||||
private fun loadDefaultColorScheme(): ColorScheme {
|
||||
return if (Utilities.ATLEAST_S) {
|
||||
SystemColorScheme(context)
|
||||
} else {
|
||||
DefaultColorScheme(context, targetColors)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadColorScheme(): ColorScheme {
|
||||
val accentColor = prefs.accentColor.get()
|
||||
if (accentColor != 0) {
|
||||
return DynamicColorScheme(targetColors, accentColor)
|
||||
}
|
||||
return DefaultColorScheme(context, targetColors)
|
||||
return defaultColorScheme
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package app.lawnchair.ui.theme.color
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import dev.kdrag0n.android12ext.monet.colors.Color
|
||||
import dev.kdrag0n.android12ext.monet.colors.Srgb
|
||||
import dev.kdrag0n.android12ext.monet.theme.ColorScheme
|
||||
|
||||
class SystemColorScheme(private val context: Context) : ColorScheme() {
|
||||
override val neutral1 = systemPaletteMap("neutral1")
|
||||
override val neutral2 = systemPaletteMap("neutral2")
|
||||
|
||||
override val accent1 = systemPaletteMap("accent1")
|
||||
override val accent2 = systemPaletteMap("accent2")
|
||||
override val accent3 = systemPaletteMap("accent3")
|
||||
|
||||
private fun systemPaletteMap(paletteName: String): Map<Int, Color> {
|
||||
val lums = listOf(0, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000)
|
||||
return lums.associateWith { SystemColor(context.resources, paletteName, it) }
|
||||
}
|
||||
}
|
||||
|
||||
class SystemColor(resources: Resources, paletteName: String, it: Int) : Color {
|
||||
@Suppress("DEPRECATION") // use Resources.getColor(int) directly because we don't need the theme
|
||||
private val srgb by lazy {
|
||||
val colorName = "system_${paletteName}_$it"
|
||||
val colorId = resources.getIdentifier(colorName, "color", "android")
|
||||
Srgb(resources.getColor(colorId))
|
||||
}
|
||||
|
||||
override fun toLinearSrgb() = srgb.toLinearSrgb()
|
||||
override fun toSrgb() = srgb
|
||||
}
|
||||
Reference in New Issue
Block a user