Accent colors follow desaturation preference

pull/935/head
Alex Baker 6 years ago
parent 0e967c0889
commit f413b37058

@ -83,9 +83,7 @@ class ColorPalettePicker : InjectingDialogFragment() {
palette = arguments!!.getSerializable(EXTRA_PALETTE) as Palette
colors = when (palette) {
Palette.COLORS -> colorProvider.getThemeColors()
Palette.ACCENTS -> ThemeAccent.ACCENTS.mapIndexed { index, _ ->
ThemeAccent(context, index)
}
Palette.ACCENTS -> colorProvider.getAccentColors()
Palette.LAUNCHERS -> ThemeColor.LAUNCHER_COLORS.map { color ->
ThemeColor(context, ContextCompat.getColor(context!!, color))
}

@ -48,8 +48,8 @@ public class ActivityModule {
@Provides
@ActivityScope
public ThemeAccent getThemeAccent(Preferences preferences) {
return new ThemeAccent(activity, preferences.getInt(R.string.p_theme_accent, 1));
public ThemeAccent getThemeAccent(ColorProvider colorProvider, Preferences preferences) {
return colorProvider.getThemeAccent(preferences.getInt(R.string.p_theme_accent, 1));
}
@Provides

@ -90,9 +90,17 @@ class ColorProvider @Inject constructor(@ForActivity private val context: Contex
else -> GREY
}
fun getThemeAccent(index: Int) = ThemeAccent(context, if (isDark && desaturate) {
ThemeAccent.ACCENTS_DESATURATED[index]
} else {
ThemeAccent.ACCENTS[index]
})
fun getThemeColors(adjust: Boolean = true) = ThemeColor.COLORS.map { c ->
getThemeColor(ContextCompat.getColor(context, c), adjust)
}
fun getWidgetColors() = getThemeColors(true)
fun getWidgetColors() = getThemeColors(false)
fun getAccentColors() = ThemeAccent.ACCENTS.indices.map(this@ColorProvider::getThemeAccent)
}

@ -31,6 +31,27 @@ public class ThemeAccent implements Pickable {
R.style.OrangeAccent,
R.style.DeepOrangeAccent
};
public static final int[] ACCENTS_DESATURATED =
new int[] {
R.style.BlueGreyAccentDesaturated,
R.style.RedAccentDesaturated,
R.style.PinkAccentDesaturated,
R.style.PurpleAccentDesaturated,
R.style.DeepPurpleAccentDesaturated,
R.style.IndigoAccentDesaturated,
R.style.BlueAccentDesaturated,
R.style.LightBlueAccentDesaturated,
R.style.CyanAccentDesaturated,
R.style.TealAccentDesaturated,
R.style.GreenAccentDesaturated,
R.style.LightGreenAccentDesaturated,
R.style.LimeAccentDesaturated,
R.style.YellowAccentDesaturated,
R.style.AmberAccentDesaturated,
R.style.OrangeAccentDesaturated,
R.style.DeepOrangeAccentDesaturated
};
public static final Parcelable.Creator<ThemeAccent> CREATOR =
new Parcelable.Creator<ThemeAccent>() {
@Override
@ -46,9 +67,9 @@ public class ThemeAccent implements Pickable {
private final int style;
@Deprecated private final int accentColor;
public ThemeAccent(Context context, int index) {
this.style = ACCENTS[index];
Resources.Theme theme = new ContextThemeWrapper(context, ThemeAccent.ACCENTS[index]).getTheme();
public ThemeAccent(Context context, int style) {
this.style = style;
Resources.Theme theme = new ContextThemeWrapper(context, style).getTheme();
this.accentColor = resolveAttribute(theme, R.attr.colorSecondary);
}
@ -77,6 +98,8 @@ public class ThemeAccent implements Pickable {
switch (style) {
case R.style.BlueGreyAccent:
case R.style.RedAccent:
case R.style.BlueGreyAccentDesaturated:
case R.style.RedAccentDesaturated:
return true;
default:
return false;

@ -1,72 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AmberAccent" parent="BlackTint">
<item name="colorSecondary">@color/amber_a100</item>
</style>
<style name="BlueAccent" parent="BlackTint">
<item name="colorSecondary">@color/blue_a100</item>
</style>
<style name="BlueGreyAccent" parent="BlackTint">
<item name="colorSecondary">@color/blue_grey_100</item>
</style>
<style name="CyanAccent" parent="BlackTint">
<item name="colorSecondary">@color/cyan_a100</item>
</style>
<style name="DeepOrangeAccent" parent="BlackTint">
<item name="colorSecondary">@color/deep_orange_a100</item>
</style>
<style name="DeepPurpleAccent" parent="BlackTint">
<item name="colorSecondary">@color/deep_purple_a100</item>
</style>
<style name="GreenAccent" parent="BlackTint">
<item name="colorSecondary">@color/green_a100</item>
</style>
<style name="IndigoAccent" parent="BlackTint">
<item name="colorSecondary">@color/indigo_a100</item>
</style>
<style name="LightBlueAccent" parent="BlackTint">
<item name="colorSecondary">@color/light_blue_a100</item>
</style>
<style name="LightGreenAccent" parent="BlackTint">
<item name="colorSecondary">@color/light_green_a100</item>
</style>
<style name="LimeAccent" parent="BlackTint">
<item name="colorSecondary">@color/lime_a100</item>
</style>
<style name="OrangeAccent" parent="BlackTint">
<item name="colorSecondary">@color/orange_a100</item>
</style>
<style name="PinkAccent" parent="BlackTint">
<item name="colorSecondary">@color/pink_a100</item>
</style>
<style name="PurpleAccent" parent="BlackTint">
<item name="colorSecondary">@color/purple_a100</item>
</style>
<style name="RedAccent" parent="BlackTint">
<item name="colorSecondary">@color/red_a100</item>
</style>
<style name="TealAccent" parent="BlackTint">
<item name="colorSecondary">@color/teal_a100</item>
</style>
<style name="YellowAccent" parent="BlackTint">
<item name="colorSecondary">@color/yellow_a100</item>
</style>
</resources>

@ -69,4 +69,72 @@
<item name="colorSecondary">@color/yellow_a400</item>
</style>
<style name="AmberAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/amber_a100</item>
</style>
<style name="BlueAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/blue_a100</item>
</style>
<style name="BlueGreyAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/blue_grey_100</item>
</style>
<style name="CyanAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/cyan_a100</item>
</style>
<style name="DeepOrangeAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/deep_orange_a100</item>
</style>
<style name="DeepPurpleAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/deep_purple_a100</item>
</style>
<style name="GreenAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/green_a100</item>
</style>
<style name="IndigoAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/indigo_a100</item>
</style>
<style name="LightBlueAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/light_blue_a100</item>
</style>
<style name="LightGreenAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/light_green_a100</item>
</style>
<style name="LimeAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/lime_a100</item>
</style>
<style name="OrangeAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/orange_a100</item>
</style>
<style name="PinkAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/pink_a100</item>
</style>
<style name="PurpleAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/purple_a100</item>
</style>
<style name="RedAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/red_a100</item>
</style>
<style name="TealAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/teal_a100</item>
</style>
<style name="YellowAccentDesaturated" parent="BlackTint">
<item name="colorSecondary">@color/yellow_a100</item>
</style>
</resources>
Loading…
Cancel
Save