Allow disabling dynamic color theme

This commit is contained in:
Suphon Thanakornpakapong committed 2021-10-19 20:37:07 +07:00
1 parent 0483324bfa
commit 526c4ad329
8 files changed
+86 -14

No files matched your search

+1
View File
@@ -160,4 +160,5 @@
<string name="app_title_label">Title</string>
<string name="hide_from_drawer">Hide from Drawer</string>
<string name="action_lens">Lens</string>
<string name="enable_colorful_theme">Also Apply to Background</string>
</resources>
@@ -95,6 +95,7 @@ class PreferenceManager private constructor(private val context: Context) : Base
ColorOption::fromString,
ColorOption::toString
)
val enableColorfulTheme = BoolPref("pref_enableColorfulTheme", true, recreate)
val wallpaperScrolling = BoolPref("pref_wallpaperScrolling", true)
val showSysUiScrim = BoolPref("pref_showSysUiScrim", true)
val showStatusBar = BoolPref("pref_showStatusBar", true, recreate)
@@ -27,11 +27,13 @@ import dev.kdrag0n.colorkt.tristimulus.CieXyzAbs.Companion.toAbs
import dev.kdrag0n.colorkt.ucs.lab.CieLab
import dev.kdrag0n.monet.theme.ColorScheme
import dev.kdrag0n.monet.theme.DynamicColorScheme
import dev.kdrag0n.monet.theme.GrayColorScheme
import dev.kdrag0n.monet.theme.MaterialYouTargets
class ThemeProvider(private val context: Context) {
private val prefs = PreferenceManager.getInstance(context)
private val accentColor by prefs.accentColor
private val enableColorfulTheme by prefs.enableColorfulTheme
private val targets = MaterialYouTargets(1.0, false, viewingCondition)
private val colorSchemeMap = SparseArray<ColorScheme>()
@@ -67,7 +69,7 @@ class ThemeProvider(private val context: Context) {
getColorScheme(wallpaperPrimary ?: ColorOption.LawnchairBlue.color)
}
is ColorOption.CustomColor -> getColorScheme(accentColor.color)
}
}.let { if (!enableColorfulTheme) GrayColorScheme(it) else it }
private val systemColorScheme get() = when {
Utilities.ATLEAST_S -> getColorScheme(0)
@@ -34,12 +34,20 @@ private val customOptions = customOptionsValues.map(ColorOption::preferenceOptio
@ExperimentalMaterialApi
@ExperimentalAnimationApi
fun AccentColorPreference() {
val prefs = preferenceManager()
ColorPreference(
previewColor = MaterialTheme.colors.primary,
colorAdapter = preferenceManager().accentColor.getAdapter(),
lastCustomColorAdapter = preferenceManager().lastCustomAccent.getAdapter(),
colorAdapter = prefs.accentColor.getAdapter(),
lastCustomColorAdapter = prefs.lastCustomAccent.getAdapter(),
label = stringResource(id = R.string.accent_color),
options = options,
customOptions = customOptions
)
) {
PreferenceGroup {
SwitchPreference(
adapter = prefs.enableColorfulTheme.getAdapter(),
label = stringResource(id = R.string.enable_colorful_theme)
)
}
}
}
@@ -36,7 +36,7 @@ fun <T> ColorPreference(
label: String,
options: List<ColorPreferenceOption<T>>,
customOptions: List<ColorPreferenceOption<T>>,
showDivider: Boolean = false
widget: @Composable () -> Unit = {}
) {
val bottomSheetState = rememberBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
val coroutineScope = rememberCoroutineScope()
@@ -55,7 +55,6 @@ fun <T> ColorPreference(
.background(previewColor)
)
},
showDivider = showDivider,
verticalPadding = 12.dp
)
@@ -100,6 +99,7 @@ fun <T> ColorPreference(
option = lastCustomColorOption,
onEditClick = { selectingCustomColor = true }
)
widget()
Spacer(modifier = Modifier.requiredHeight(16.dp))
}
Row(
@@ -260,11 +260,12 @@ fun <T> ColorSwatch(
val color = if (darkTheme) option.darkColor() else option.lightColor()
val elevationOverlay = LocalElevationOverlay.current
val absoluteElevation = LocalAbsoluteElevation.current + elevation
val ringColorWithOverlay = if (ringColor == MaterialTheme.colors.surface && elevationOverlay != null) {
elevationOverlay.apply(ringColor, absoluteElevation)
} else {
ringColor
}
val ringColorWithOverlay =
if (ringColor == MaterialTheme.colors.surface && elevationOverlay != null) {
elevationOverlay.apply(ringColor, absoluteElevation)
} else {
ringColor
}
Box(
modifier = modifier
@@ -51,7 +51,8 @@ fun getColors(darkTheme: Boolean): Colors {
val context = LocalContext.current
val prefs = PreferenceManager.getInstance(context)
val accentColor = prefs.accentColor.observeAsState().value
val colorScheme = remember(accentColor) {
val enableColorfulTheme = prefs.enableColorfulTheme.observeAsState().value
val colorScheme = remember(accentColor, enableColorfulTheme) {
ThemeProvider.INSTANCE.get(context).colorScheme
}
@@ -10,11 +10,12 @@ import dev.kdrag0n.colorkt.gamut.LchGamut.clipToLinearSrgb
import dev.kdrag0n.colorkt.rgb.Srgb
import dev.kdrag0n.colorkt.tristimulus.CieXyz
import dev.kdrag0n.colorkt.tristimulus.CieXyzAbs.Companion.toAbs
import java.util.*
class DynamicColorScheme(
targets: ColorScheme,
seedColor: Color,
chromaFactor: Double = 1.0,
private val seedColor: Color,
private val chromaFactor: Double = 1.0,
private val cond: Zcam.ViewingConditions,
private val accurateShades: Boolean = true,
) : ColorScheme() {
@@ -90,6 +91,16 @@ class DynamicColorScheme(
}
}
override fun equals(other: Any?): Boolean {
return other is DynamicColorScheme
&& other.seedColor == seedColor
&& other.chromaFactor == chromaFactor
&& other.cond == cond
&& other.accurateShades == accurateShades
}
override fun hashCode() = Objects.hash(seedColor, chromaFactor, cond, accurateShades)
companion object {
private const val TAG = "DynamicColorScheme"
@@ -0,0 +1,47 @@
package dev.kdrag0n.monet.theme
import dev.kdrag0n.colorkt.rgb.Srgb
import java.util.*
class GrayColorScheme(private val accentColorScheme: ColorScheme) : ColorScheme() {
override val neutral1 = mapOf(
0 to Srgb(0xffffff),
10 to Srgb(0xfbfbfb),
50 to Srgb(0xf0f0f0),
100 to Srgb(0xe2e2e2),
200 to Srgb(0xc6c6c6),
300 to Srgb(0xababab),
400 to Srgb(0x909090),
500 to Srgb(0x757575),
600 to Srgb(0x5e5e5e),
700 to Srgb(0x464646),
800 to Srgb(0x303030),
900 to Srgb(0x1b1b1b),
1000 to Srgb(0x000000),
)
override val neutral2 = mapOf(
0 to Srgb(0xffffff),
10 to Srgb(0xfbfbfb),
50 to Srgb(0xf0f0f0),
100 to Srgb(0xe2e2e2),
200 to Srgb(0xc6c6c6),
300 to Srgb(0xababab),
400 to Srgb(0x909090),
500 to Srgb(0x757575),
600 to Srgb(0x5e5e5e),
700 to Srgb(0x464646),
800 to Srgb(0x303030),
900 to Srgb(0x1b1b1b),
1000 to Srgb(0x000000),
)
override val accent1 = accentColorScheme.accent1
override val accent2 = accentColorScheme.accent2
override val accent3 = accentColorScheme.accent3
override fun equals(other: Any?) = other is GrayColorScheme && other.accentColorScheme == accentColorScheme
override fun hashCode() = Objects.hash(accentColorScheme)
}