Cherish: Allow choosing a custom background color seed [2/2]

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Ido Ben-Hur
2022-12-08 03:15:17 +02:00
committed by Hưng Phan
parent c811849ab5
commit e0f2441316
3 changed files with 58 additions and 0 deletions

View File

@@ -888,6 +888,10 @@
<string name="color_source_preset">Preset</string>
<string name="accent_color_title">Accent Color</string>
<string name="accent_color_summary">Override default accent color</string>
<string name="accent_background_title">Accent background</string>
<string name="accent_background_summary">Choose a different accent color for background</string>
<string name="bg_color_title">Background Color</string>
<string name="bg_color_summary">Override default background accent color</string>
<string name="luminance_factor_title">Luminance</string>
<string name="luminance_factor_summary">Higher values produce brighter colors</string>
<string name="chroma_factor_title">Chroma</string>

View File

@@ -37,6 +37,17 @@
android:title="@string/accent_color_title"
android:summary="@string/accent_color_summary" />
<SwitchPreference
android:key="accent_background"
android:title="@string/accent_background_title"
android:summary="@string/accent_background_summary"
android:defaultValue="false" />
<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="bg_color"
android:title="@string/bg_color_title"
android:summary="@string/bg_color_summary" />
<com.cherish.settings.preferences.CustomSeekBarPreference
android:key="luminance_factor"
android:title="@string/luminance_factor_title"

View File

@@ -50,6 +50,8 @@ public class MonetSettings extends SettingsPreferenceFragment implements
"android.theme.customization.system_palette";
private static final String OVERLAY_CATEGORY_THEME_STYLE =
"android.theme.customization.theme_style";
private static final String OVERLAY_CATEGORY_BG_COLOR =
"android.theme.customization.bg_color";
private static final String OVERLAY_COLOR_SOURCE =
"android.theme.customization.color_source";
private static final String OVERLAY_COLOR_BOTH =
@@ -67,6 +69,8 @@ public class MonetSettings extends SettingsPreferenceFragment implements
private static final String PREF_THEME_STYLE = "theme_style";
private static final String PREF_COLOR_SOURCE = "color_source";
private static final String PREF_ACCENT_COLOR = "accent_color";
private static final String PREF_ACCENT_BACKGROUND = "accent_background";
private static final String PREF_BG_COLOR = "bg_color";
private static final String PREF_LUMINANCE_FACTOR = "luminance_factor";
private static final String PREF_CHROMA_FACTOR = "chroma_factor";
private static final String PREF_TINT_BACKGROUND = "tint_background";
@@ -74,6 +78,8 @@ public class MonetSettings extends SettingsPreferenceFragment implements
private ListPreference mThemeStylePref;
private ListPreference mColorSourcePref;
private ColorPickerPreference mAccentColorPref;
private SwitchPreference mAccentBackgroundPref;
private ColorPickerPreference mBgColorPref;
private CustomSeekBarPreference mLuminancePref;
private CustomSeekBarPreference mChromaPref;
private SwitchPreference mTintBackgroundPref;
@@ -86,6 +92,8 @@ public class MonetSettings extends SettingsPreferenceFragment implements
mThemeStylePref = findPreference(PREF_THEME_STYLE);
mColorSourcePref = findPreference(PREF_COLOR_SOURCE);
mAccentColorPref = findPreference(PREF_ACCENT_COLOR);
mAccentBackgroundPref = findPreference(PREF_ACCENT_BACKGROUND);
mBgColorPref = findPreference(PREF_BG_COLOR);
mLuminancePref = findPreference(PREF_LUMINANCE_FACTOR);
mChromaPref = findPreference(PREF_CHROMA_FACTOR);
mTintBackgroundPref = findPreference(PREF_TINT_BACKGROUND);
@@ -95,6 +103,8 @@ public class MonetSettings extends SettingsPreferenceFragment implements
mThemeStylePref.setOnPreferenceChangeListener(this);
mColorSourcePref.setOnPreferenceChangeListener(this);
mAccentColorPref.setOnPreferenceChangeListener(this);
mAccentBackgroundPref.setOnPreferenceChangeListener(this);
mBgColorPref.setOnPreferenceChangeListener(this);
mLuminancePref.setOnPreferenceChangeListener(this);
mChromaPref.setOnPreferenceChangeListener(this);
mTintBackgroundPref.setOnPreferenceChangeListener(this);
@@ -117,6 +127,7 @@ public class MonetSettings extends SettingsPreferenceFragment implements
final String style = object.optString(OVERLAY_CATEGORY_THEME_STYLE, null);
final String source = object.optString(OVERLAY_COLOR_SOURCE, null);
final String color = object.optString(OVERLAY_CATEGORY_SYSTEM_PALETTE, null);
final int bgColor = object.optInt(OVERLAY_CATEGORY_BG_COLOR);
final boolean both = object.optInt(OVERLAY_COLOR_BOTH, 0) == 1;
final boolean tintBG = object.optInt(OVERLAY_TINT_BACKGROUND, 0) == 1;
final float lumin = (float) object.optDouble(OVERLAY_LUMINANCE_FACTOR, 1d);
@@ -147,6 +158,14 @@ public class MonetSettings extends SettingsPreferenceFragment implements
mAccentColorPref.setNewPreviewColor(
ColorPickerPreference.convertToColorInt(color));
}
final boolean bgEnabled = enabled && bgColor != 0;
if (bgEnabled) {
mBgColorPref.setNewPreviewColor(bgColor);
} else if (!enabled) {
mAccentBackgroundPref.setEnabled(false);
}
mAccentBackgroundPref.setChecked(bgEnabled);
mBgColorPref.setEnabled(bgEnabled);
// etc
int luminV = 0;
if (lumin > 1d) luminV = Math.round((lumin - 1f) * 100f);
@@ -179,6 +198,15 @@ public class MonetSettings extends SettingsPreferenceFragment implements
int value = (Integer) newValue;
setColorValue(value);
return true;
} else if (preference == mAccentBackgroundPref) {
boolean value = (Boolean) newValue;
if (!value) setBgColorValue(0);
mBgColorPref.setEnabled(value);
return true;
} else if (preference == mBgColorPref) {
int value = (Integer) newValue;
setBgColorValue(value);
return true;
} else if (preference == mLuminancePref) {
int value = (Integer) newValue;
setLuminanceValue(value);
@@ -208,6 +236,12 @@ public class MonetSettings extends SettingsPreferenceFragment implements
private boolean updateAccentEnablement(String source) {
final boolean shouldEnable = source != null && source.equals(COLOR_SOURCE_PRESET);
mAccentColorPref.setEnabled(shouldEnable);
mAccentBackgroundPref.setEnabled(shouldEnable);
if (!shouldEnable) {
mBgColorPref.setEnabled(false);
mAccentBackgroundPref.setEnabled(false);
mAccentBackgroundPref.setChecked(false);
}
return shouldEnable;
}
@@ -266,6 +300,15 @@ public class MonetSettings extends SettingsPreferenceFragment implements
} catch (JSONException | IllegalArgumentException ignored) {}
}
private void setBgColorValue(int color) {
try {
JSONObject object = getSettingsJson();
if (color != 0) object.putOpt(OVERLAY_CATEGORY_BG_COLOR, color);
else object.remove(OVERLAY_CATEGORY_BG_COLOR);
putSettingsJson(object);
} catch (JSONException | IllegalArgumentException ignored) {}
}
private void setLuminanceValue(int lumin) {
try {
JSONObject object = getSettingsJson();