SystemUI: monet: Allow a more granular control over shades [2/2]
Do that by letting the user control the luminance and chroma factors of accent / background colors Use Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES as an existing medium to store choices Also refactor the code here Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -888,5 +888,11 @@
|
|||||||
<string name="color_source_preset">Preset</string>
|
<string name="color_source_preset">Preset</string>
|
||||||
<string name="accent_color_title">Accent Color</string>
|
<string name="accent_color_title">Accent Color</string>
|
||||||
<string name="accent_color_summary">Override default accent color</string>
|
<string name="accent_color_summary">Override default 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>
|
||||||
|
<string name="chroma_factor_summary">Higher values produce stronger colors</string>
|
||||||
|
<string name="tint_background_title">Tint Background</string>
|
||||||
|
<string name="tint_background_summary">Make Luminance and Chroma selection affect background colors as well</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -37,4 +37,32 @@
|
|||||||
android:title="@string/accent_color_title"
|
android:title="@string/accent_color_title"
|
||||||
android:summary="@string/accent_color_summary" />
|
android:summary="@string/accent_color_summary" />
|
||||||
|
|
||||||
|
<com.cherish.settings.preferences.CustomSeekBarPreference
|
||||||
|
android:key="luminance_factor"
|
||||||
|
android:title="@string/luminance_factor_title"
|
||||||
|
android:summary="@string/luminance_factor_summary"
|
||||||
|
android:max="100"
|
||||||
|
settings:min="-95"
|
||||||
|
settings:interval="5"
|
||||||
|
settings:defaultValue="0"
|
||||||
|
settings:units="%"
|
||||||
|
settings:showSign="true" />
|
||||||
|
|
||||||
|
<com.cherish.settings.preferences.CustomSeekBarPreference
|
||||||
|
android:key="chroma_factor"
|
||||||
|
android:title="@string/chroma_factor_title"
|
||||||
|
android:summary="@string/chroma_factor_summary"
|
||||||
|
android:max="100"
|
||||||
|
settings:min="-95"
|
||||||
|
settings:interval="5"
|
||||||
|
settings:defaultValue="0"
|
||||||
|
settings:units="%"
|
||||||
|
settings:showSign="true" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="tint_background"
|
||||||
|
android:title="@string/tint_background_title"
|
||||||
|
android:summary="@string/tint_background_summary"
|
||||||
|
android:defaultValue="false" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import androidx.preference.ListPreference;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
@@ -32,6 +33,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
||||||
|
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||||
|
|
||||||
import java.lang.CharSequence;
|
import java.lang.CharSequence;
|
||||||
|
|
||||||
@@ -52,6 +54,12 @@ public class MonetSettings extends SettingsPreferenceFragment implements
|
|||||||
"android.theme.customization.color_source";
|
"android.theme.customization.color_source";
|
||||||
private static final String OVERLAY_COLOR_BOTH =
|
private static final String OVERLAY_COLOR_BOTH =
|
||||||
"android.theme.customization.color_both";
|
"android.theme.customization.color_both";
|
||||||
|
private static final String OVERLAY_LUMINANCE_FACTOR =
|
||||||
|
"android.theme.customization.luminance_factor";
|
||||||
|
private static final String OVERLAY_CHROMA_FACTOR =
|
||||||
|
"android.theme.customization.chroma_factor";
|
||||||
|
private static final String OVERLAY_TINT_BACKGROUND =
|
||||||
|
"android.theme.customization.tint_background";
|
||||||
private static final String COLOR_SOURCE_PRESET = "preset";
|
private static final String COLOR_SOURCE_PRESET = "preset";
|
||||||
private static final String COLOR_SOURCE_HOME = "home_wallpaper";
|
private static final String COLOR_SOURCE_HOME = "home_wallpaper";
|
||||||
private static final String COLOR_SOURCE_LOCK = "lock_wallpaper";
|
private static final String COLOR_SOURCE_LOCK = "lock_wallpaper";
|
||||||
@@ -59,10 +67,16 @@ public class MonetSettings extends SettingsPreferenceFragment implements
|
|||||||
private static final String PREF_THEME_STYLE = "theme_style";
|
private static final String PREF_THEME_STYLE = "theme_style";
|
||||||
private static final String PREF_COLOR_SOURCE = "color_source";
|
private static final String PREF_COLOR_SOURCE = "color_source";
|
||||||
private static final String PREF_ACCENT_COLOR = "accent_color";
|
private static final String PREF_ACCENT_COLOR = "accent_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";
|
||||||
|
|
||||||
private ListPreference mThemeStylePref;
|
private ListPreference mThemeStylePref;
|
||||||
private ListPreference mColorSourcePref;
|
private ListPreference mColorSourcePref;
|
||||||
private ColorPickerPreference mAccentColorPref;
|
private ColorPickerPreference mAccentColorPref;
|
||||||
|
private CustomSeekBarPreference mLuminancePref;
|
||||||
|
private CustomSeekBarPreference mChromaPref;
|
||||||
|
private SwitchPreference mTintBackgroundPref;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
@@ -72,7 +86,27 @@ public class MonetSettings extends SettingsPreferenceFragment implements
|
|||||||
mThemeStylePref = findPreference(PREF_THEME_STYLE);
|
mThemeStylePref = findPreference(PREF_THEME_STYLE);
|
||||||
mColorSourcePref = findPreference(PREF_COLOR_SOURCE);
|
mColorSourcePref = findPreference(PREF_COLOR_SOURCE);
|
||||||
mAccentColorPref = findPreference(PREF_ACCENT_COLOR);
|
mAccentColorPref = findPreference(PREF_ACCENT_COLOR);
|
||||||
|
mLuminancePref = findPreference(PREF_LUMINANCE_FACTOR);
|
||||||
|
mChromaPref = findPreference(PREF_CHROMA_FACTOR);
|
||||||
|
mTintBackgroundPref = findPreference(PREF_TINT_BACKGROUND);
|
||||||
|
|
||||||
|
updatePreferences();
|
||||||
|
|
||||||
|
mThemeStylePref.setOnPreferenceChangeListener(this);
|
||||||
|
mColorSourcePref.setOnPreferenceChangeListener(this);
|
||||||
|
mAccentColorPref.setOnPreferenceChangeListener(this);
|
||||||
|
mLuminancePref.setOnPreferenceChangeListener(this);
|
||||||
|
mChromaPref.setOnPreferenceChangeListener(this);
|
||||||
|
mTintBackgroundPref.setOnPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
updatePreferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePreferences() {
|
||||||
final String overlayPackageJson = Settings.Secure.getStringForUser(
|
final String overlayPackageJson = Settings.Secure.getStringForUser(
|
||||||
getActivity().getContentResolver(),
|
getActivity().getContentResolver(),
|
||||||
Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
|
Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
|
||||||
@@ -82,8 +116,11 @@ public class MonetSettings extends SettingsPreferenceFragment implements
|
|||||||
final JSONObject object = new JSONObject(overlayPackageJson);
|
final JSONObject object = new JSONObject(overlayPackageJson);
|
||||||
final String style = object.optString(OVERLAY_CATEGORY_THEME_STYLE, null);
|
final String style = object.optString(OVERLAY_CATEGORY_THEME_STYLE, null);
|
||||||
final String source = object.optString(OVERLAY_COLOR_SOURCE, null);
|
final String source = object.optString(OVERLAY_COLOR_SOURCE, null);
|
||||||
final boolean both = object.optInt(OVERLAY_COLOR_BOTH, 0) == 1;
|
|
||||||
final String color = object.optString(OVERLAY_CATEGORY_SYSTEM_PALETTE, null);
|
final String color = object.optString(OVERLAY_CATEGORY_SYSTEM_PALETTE, null);
|
||||||
|
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);
|
||||||
|
final float chroma = (float) object.optDouble(OVERLAY_CHROMA_FACTOR, 1d);
|
||||||
// style handling
|
// style handling
|
||||||
boolean styleUpdated = false;
|
boolean styleUpdated = false;
|
||||||
if (style != null && !style.isEmpty()) {
|
if (style != null && !style.isEmpty()) {
|
||||||
@@ -110,12 +147,18 @@ public class MonetSettings extends SettingsPreferenceFragment implements
|
|||||||
mAccentColorPref.setNewPreviewColor(
|
mAccentColorPref.setNewPreviewColor(
|
||||||
ColorPickerPreference.convertToColorInt(color));
|
ColorPickerPreference.convertToColorInt(color));
|
||||||
}
|
}
|
||||||
|
// etc
|
||||||
|
int luminV = 0;
|
||||||
|
if (lumin > 1d) luminV = Math.round((lumin - 1f) * 100f);
|
||||||
|
else if (lumin < 1d) luminV = -1 * Math.round((1f - lumin) * 100f);
|
||||||
|
mLuminancePref.setValue(luminV);
|
||||||
|
int chromaV = 0;
|
||||||
|
if (chroma > 1d) chromaV = Math.round((chroma - 1f) * 100f);
|
||||||
|
else if (chroma < 1d) chromaV = -1 * Math.round((1f - chroma) * 100f);
|
||||||
|
mChromaPref.setValue(chromaV);
|
||||||
|
mTintBackgroundPref.setChecked(tintBG);
|
||||||
} catch (JSONException | IllegalArgumentException ignored) {}
|
} catch (JSONException | IllegalArgumentException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
mThemeStylePref.setOnPreferenceChangeListener(this);
|
|
||||||
mColorSourcePref.setOnPreferenceChangeListener(this);
|
|
||||||
mAccentColorPref.setOnPreferenceChangeListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -123,18 +166,30 @@ public class MonetSettings extends SettingsPreferenceFragment implements
|
|||||||
final ContentResolver resolver = getActivity().getContentResolver();
|
final ContentResolver resolver = getActivity().getContentResolver();
|
||||||
if (preference == mThemeStylePref) {
|
if (preference == mThemeStylePref) {
|
||||||
String value = (String) newValue;
|
String value = (String) newValue;
|
||||||
setSettingsValues(value, null, null);
|
setStyleValue(value);
|
||||||
updateListByValue(mThemeStylePref, value, false);
|
updateListByValue(mThemeStylePref, value, false);
|
||||||
return true;
|
return true;
|
||||||
} else if (preference == mColorSourcePref) {
|
} else if (preference == mColorSourcePref) {
|
||||||
String value = (String) newValue;
|
String value = (String) newValue;
|
||||||
setSettingsValues(null, value, null);
|
setSourceValue(value);
|
||||||
updateListByValue(mColorSourcePref, value, false);
|
updateListByValue(mColorSourcePref, value, false);
|
||||||
updateAccentEnablement(value);
|
updateAccentEnablement(value);
|
||||||
return true;
|
return true;
|
||||||
} else if (preference == mAccentColorPref) {
|
} else if (preference == mAccentColorPref) {
|
||||||
int value = (Integer) newValue;
|
int value = (Integer) newValue;
|
||||||
setSettingsValues(null, null, value);
|
setColorValue(value);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mLuminancePref) {
|
||||||
|
int value = (Integer) newValue;
|
||||||
|
setLuminanceValue(value);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mChromaPref) {
|
||||||
|
int value = (Integer) newValue;
|
||||||
|
setChromaValue(value);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mTintBackgroundPref) {
|
||||||
|
boolean value = (Boolean) newValue;
|
||||||
|
setTintBackgroundValue(value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -156,23 +211,35 @@ public class MonetSettings extends SettingsPreferenceFragment implements
|
|||||||
return shouldEnable;
|
return shouldEnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSettingsValues(String style, String source, Integer color) {
|
private JSONObject getSettingsJson() throws JSONException {
|
||||||
final ContentResolver resolver = getActivity().getContentResolver();
|
|
||||||
final String overlayPackageJson = Settings.Secure.getStringForUser(
|
final String overlayPackageJson = Settings.Secure.getStringForUser(
|
||||||
resolver, Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
|
getActivity().getContentResolver(),
|
||||||
|
Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
|
||||||
UserHandle.USER_CURRENT);
|
UserHandle.USER_CURRENT);
|
||||||
|
|
||||||
try {
|
|
||||||
JSONObject object;
|
JSONObject object;
|
||||||
if (overlayPackageJson == null || overlayPackageJson.isEmpty())
|
if (overlayPackageJson == null || overlayPackageJson.isEmpty())
|
||||||
object = new JSONObject();
|
return new JSONObject();
|
||||||
else
|
return new JSONObject(overlayPackageJson);
|
||||||
object = new JSONObject(overlayPackageJson);
|
|
||||||
|
|
||||||
if (style != null) {
|
|
||||||
object.putOpt(OVERLAY_CATEGORY_THEME_STYLE, style);
|
|
||||||
}
|
}
|
||||||
if (source != null) {
|
|
||||||
|
private void putSettingsJson(JSONObject object) {
|
||||||
|
Settings.Secure.putStringForUser(
|
||||||
|
getActivity().getContentResolver(),
|
||||||
|
Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
|
||||||
|
object.toString(), UserHandle.USER_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setStyleValue(String style) {
|
||||||
|
try {
|
||||||
|
JSONObject object = getSettingsJson();
|
||||||
|
object.putOpt(OVERLAY_CATEGORY_THEME_STYLE, style);
|
||||||
|
putSettingsJson(object);
|
||||||
|
} catch (JSONException | IllegalArgumentException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSourceValue(String source) {
|
||||||
|
try {
|
||||||
|
JSONObject object = getSettingsJson();
|
||||||
if (source.equals("both")) {
|
if (source.equals("both")) {
|
||||||
object.putOpt(OVERLAY_COLOR_BOTH, 1);
|
object.putOpt(OVERLAY_COLOR_BOTH, 1);
|
||||||
object.putOpt(OVERLAY_COLOR_SOURCE, COLOR_SOURCE_HOME);
|
object.putOpt(OVERLAY_COLOR_SOURCE, COLOR_SOURCE_HOME);
|
||||||
@@ -184,17 +251,49 @@ public class MonetSettings extends SettingsPreferenceFragment implements
|
|||||||
object.remove(OVERLAY_CATEGORY_ACCENT_COLOR);
|
object.remove(OVERLAY_CATEGORY_ACCENT_COLOR);
|
||||||
object.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE);
|
object.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE);
|
||||||
}
|
}
|
||||||
|
putSettingsJson(object);
|
||||||
|
} catch (JSONException | IllegalArgumentException ignored) {}
|
||||||
}
|
}
|
||||||
if (color != null) {
|
|
||||||
|
private void setColorValue(int color) {
|
||||||
|
try {
|
||||||
|
JSONObject object = getSettingsJson();
|
||||||
final String rgbColor = ColorPickerPreference.convertToRGB(color).replace("#", "");
|
final String rgbColor = ColorPickerPreference.convertToRGB(color).replace("#", "");
|
||||||
object.putOpt(OVERLAY_CATEGORY_ACCENT_COLOR, rgbColor);
|
object.putOpt(OVERLAY_CATEGORY_ACCENT_COLOR, rgbColor);
|
||||||
object.putOpt(OVERLAY_CATEGORY_SYSTEM_PALETTE, rgbColor);
|
object.putOpt(OVERLAY_CATEGORY_SYSTEM_PALETTE, rgbColor);
|
||||||
object.putOpt(OVERLAY_COLOR_SOURCE, COLOR_SOURCE_PRESET);
|
object.putOpt(OVERLAY_COLOR_SOURCE, COLOR_SOURCE_PRESET);
|
||||||
|
putSettingsJson(object);
|
||||||
|
} catch (JSONException | IllegalArgumentException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.Secure.putStringForUser(
|
private void setLuminanceValue(int lumin) {
|
||||||
resolver, Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
|
try {
|
||||||
object.toString(), UserHandle.USER_CURRENT);
|
JSONObject object = getSettingsJson();
|
||||||
|
if (lumin == 0)
|
||||||
|
object.remove(OVERLAY_LUMINANCE_FACTOR);
|
||||||
|
else
|
||||||
|
object.putOpt(OVERLAY_LUMINANCE_FACTOR, 1d + ((double) lumin / 100d));
|
||||||
|
putSettingsJson(object);
|
||||||
|
} catch (JSONException | IllegalArgumentException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChromaValue(int chroma) {
|
||||||
|
try {
|
||||||
|
JSONObject object = getSettingsJson();
|
||||||
|
if (chroma == 0)
|
||||||
|
object.remove(OVERLAY_CHROMA_FACTOR);
|
||||||
|
else
|
||||||
|
object.putOpt(OVERLAY_CHROMA_FACTOR, 1d + ((double) chroma / 100d));
|
||||||
|
putSettingsJson(object);
|
||||||
|
} catch (JSONException | IllegalArgumentException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTintBackgroundValue(boolean tint) {
|
||||||
|
try {
|
||||||
|
JSONObject object = getSettingsJson();
|
||||||
|
if (!tint) object.remove(OVERLAY_TINT_BACKGROUND);
|
||||||
|
else object.putOpt(OVERLAY_TINT_BACKGROUND, 1);
|
||||||
|
putSettingsJson(object);
|
||||||
} catch (JSONException | IllegalArgumentException ignored) {}
|
} catch (JSONException | IllegalArgumentException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user