Cherish:Xtended Statusbar Clock Customization [2/2]

Add Clock size, color & font style.

Port to Pie + Added Color for Clocks - SuperDroidBond
Clock fonts and size - @temasek
Port to Oreo by @varund7726

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
SuperDroidBond
2018-09-20 15:22:10 +05:30
committed by Hưng Phan
parent 19f919964c
commit 561a6531a0
3 changed files with 83 additions and 0 deletions

View File

@@ -779,4 +779,9 @@
<string name="clock_date_string_edittext_title">Must be in DateFormat eg. MM/dd/yy</string>
<string name="clock_date_string_edittext_summary">Enter string</string>
<!-- Statusbar Clock Font Style, Size & Color -->
<string name="status_bar_clock_font_style_title">Clock font style</string>
<string name="status_bar_clock_font_size_title">Clock font size</string>
<string name="status_bar_clock_color_title">Clock font color</string>
</resources>

View File

@@ -74,6 +74,29 @@
android:entryValues="@array/clock_date_format_entries_values"
android:dependency="clock_date_display" />
<com.cherish.settings.preferences.CustomSeekBarPreference
android:key="status_bar_clock_size"
android:title="@string/status_bar_clock_font_size_title"
android:max="23"
settings:min="4"
android:defaultValue="14"
settings:units="dp"/>
<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="status_bar_clock_color"
android:icon="@drawable/ic_color"
android:title="@string/status_bar_clock_color_title"
android:defaultValue="0xffffffff" />
<ListPreference
android:key="status_bar_clock_font_style"
android:dialogTitle="@string/status_bar_clock_font_style_title"
android:title="@string/status_bar_clock_font_style_title"
android:entries="@array/lock_clock_fonts_entries"
android:entryValues="@array/lock_clock_fonts_values"
android:summary="%s"
android:defaultValue="0" />
</PreferenceScreen>

View File

@@ -42,6 +42,8 @@ import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
import com.cherish.settings.preferences.CustomSeekBarPreference;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
import com.android.internal.logging.nano.MetricsProto;
import java.util.Date;
@@ -56,10 +58,15 @@ public class ClockSettings extends SettingsPreferenceFragment implements
private static final String STATUS_BAR_CLOCK_DATE_DISPLAY = "clock_date_display";
private static final String STATUS_BAR_CLOCK_DATE_STYLE = "clock_date_style";
private static final String STATUS_BAR_CLOCK_DATE_FORMAT = "clock_date_format";
private static final String STATUS_BAR_CLOCK_COLOR = "status_bar_clock_color";
private static final String STATUS_BAR_CLOCK_SIZE = "status_bar_clock_size";
private static final String STATUS_BAR_CLOCK_FONT_STYLE = "status_bar_clock_font_style";
public static final int CLOCK_DATE_STYLE_LOWERCASE = 1;
public static final int CLOCK_DATE_STYLE_UPPERCASE = 2;
private static final int CUSTOM_CLOCK_DATE_FORMAT_INDEX = 18;
static final int DEFAULT_STATUS_CLOCK_COLOR = 0xffffffff;
private SystemSettingSwitchPreference mStatusBarClockShow;
private SystemSettingSwitchPreference mStatusBarSecondsShow;
private ListPreference mStatusBarClock;
@@ -67,6 +74,9 @@ public class ClockSettings extends SettingsPreferenceFragment implements
private ListPreference mClockDateDisplay;
private ListPreference mClockDateStyle;
private ListPreference mClockDateFormat;
private ColorPickerPreference mClockColor;
private CustomSeekBarPreference mClockSize;
private ListPreference mClockFontStyle;
@Override
public void onCreate(Bundle icicle) {
@@ -75,6 +85,9 @@ public class ClockSettings extends SettingsPreferenceFragment implements
PreferenceScreen prefSet = getPreferenceScreen();
ContentResolver resolver = getActivity().getContentResolver();
int intColor;
String hexColor;
// clock settings
mStatusBarClockShow = (SystemSettingSwitchPreference) findPreference(STATUS_BAR_CLOCK);
mStatusBarSecondsShow = (SystemSettingSwitchPreference) findPreference(STATUS_BAR_CLOCK_SECONDS);
@@ -97,6 +110,26 @@ public class ClockSettings extends SettingsPreferenceFragment implements
mStatusBarClock.setSummary(mStatusBarClock.getEntry());
mStatusBarClock.setOnPreferenceChangeListener(this);
mClockColor = (ColorPickerPreference) findPreference(STATUS_BAR_CLOCK_COLOR);
mClockColor.setOnPreferenceChangeListener(this);
intColor = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CLOCK_COLOR, DEFAULT_STATUS_CLOCK_COLOR);
hexColor = String.format("#%08x", (0xffffffff & intColor));
mClockColor.setSummary(hexColor);
mClockColor.setNewPreviewColor(intColor);
mClockSize = (CustomSeekBarPreference) findPreference(STATUS_BAR_CLOCK_SIZE);
int clockSize = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CLOCK_SIZE, 14);
mClockSize.setValue(clockSize / 1);
mClockSize.setOnPreferenceChangeListener(this);
mClockFontStyle = (ListPreference) findPreference(STATUS_BAR_CLOCK_FONT_STYLE);
int showClockFont = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CLOCK_FONT_STYLE, 0);
mClockFontStyle.setValue(String.valueOf(showClockFont));
mClockFontStyle.setOnPreferenceChangeListener(this);
if (DateFormat.is24HourFormat(getActivity())) {
mStatusBarAmPm.setEnabled(false);
mStatusBarAmPm.setSummary(R.string.status_bar_am_pm_info);
@@ -149,6 +182,8 @@ public class ClockSettings extends SettingsPreferenceFragment implements
public boolean onPreferenceChange(Preference preference, Object newValue) {
AlertDialog dialog;
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mStatusBarClockShow) {
boolean value = (Boolean) newValue;
Settings.System.putInt(getActivity().getContentResolver(),
@@ -173,6 +208,26 @@ public class ClockSettings extends SettingsPreferenceFragment implements
Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE, statusBarAmPm);
mStatusBarAmPm.setSummary(mStatusBarAmPm.getEntries()[index]);
return true;
} else if (preference == mClockColor) {
String hex = ColorPickerPreference.convertToARGB(
Integer.valueOf(String.valueOf(newValue)));
preference.setSummary(hex);
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_CLOCK_COLOR, intHex);
return true;
} else if (preference == mClockSize) {
int width = ((Integer)newValue).intValue();
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_CLOCK_SIZE, width);
return true;
} else if (preference == mClockFontStyle) {
int showClockFont = Integer.valueOf((String) newValue);
int index = mClockFontStyle.findIndexOfValue((String) newValue);
Settings.System.putInt(resolver, Settings.System.
STATUS_BAR_CLOCK_FONT_STYLE, showClockFont);
mClockFontStyle.setSummary(mClockFontStyle.getEntries()[index]);
return true;
} else if (preference == mClockDateDisplay) {
int clockDateDisplay = Integer.valueOf((String) newValue);
int index = mClockDateDisplay.findIndexOfValue((String) newValue);