diff --git a/res/values/cherish_arrays.xml b/res/values/cherish_arrays.xml index 8da8b6f..2ada6e0 100644 --- a/res/values/cherish_arrays.xml +++ b/res/values/cherish_arrays.xml @@ -74,44 +74,56 @@ 2 - - - @string/am_pm_clock_none - @string/am_pm_clock_small - @string/am_pm_clock_normal + + + @string/status_bar_clock_style_left + @string/status_bar_clock_style_center + @string/status_bar_clock_style_right - + 0 1 2 - + + @string/status_bar_am_pm_hidden + @string/status_bar_am_pm_small + @string/status_bar_am_pm_normal + + + + 0 + 1 + 2 + + + @string/clock_date_display_none @string/clock_date_display_small @string/clock_date_display_normal - + 0 1 2 - + @string/clock_date_style_normal @string/clock_date_style_lowercase @string/clock_date_style_uppercase - + 0 1 2 - + dd/MM/yy MM/dd/yy yyyy-MM-dd @@ -129,6 +141,8 @@ EEE MMM dd EEE MMMM dd EEEE dd/MM + EEEE MM/dd + @string/clock_date_format_custom @@ -369,5 +383,4 @@ 7 5 - diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml index de11984..e9c0ef6 100644 --- a/res/values/cherish_strings.xml +++ b/res/values/cherish_strings.xml @@ -234,35 +234,36 @@ Pulldown statusbar from left side + Clock and date + Customize the statusbar clock and date Clock settings - Clock & Date - Enabled - Disabled - Reset color - Show clock & date - AM/PM + Show clock and date + Clock style + Right + Center + Left + AM/PM style 24-hour clock is enabled - Day of the week - Abbreviated day of the week before the time - Don\'t show + Normal + Small + Hidden (default) + Show seconds + Date settings Date - Display custom date before the clock - Date style - Date format - Must be in DateFormat eg. MM/dd/yy - Enter string - Normal font size - Small font size - Don\'t show Don\'t show Small font size Normal font size + Date style Normal Lowercase Uppercase + Custom java format + Date format + Must be in DateFormat eg. MM/dd/yy + Enter string + Date position Right of time Left of time - Date position Auto-hide clock Hide and show clock at regular intervals of time Hide duration diff --git a/res/xml/cherish_settings_statusbar.xml b/res/xml/cherish_settings_statusbar.xml index afefa4b..5c203a6 100644 --- a/res/xml/cherish_settings_statusbar.xml +++ b/res/xml/cherish_settings_statusbar.xml @@ -31,9 +31,9 @@ android:title="@string/sb_icons"> + android:title="@string/status_bar_clock_date_title" + android:summary="@string/status_bar_clock_date_summary" + android:fragment="com.cherish.settings.fragments.ClockDateSettings" /> - + + - + - - + + + + - + - + + + + android:dependency="statusbar_clock_date_display" /> + + + + + + diff --git a/src/com/cherish/settings/fragments/ClockDateSettings.java b/src/com/cherish/settings/fragments/ClockDateSettings.java index 81b7c08..04f4437 100644 --- a/src/com/cherish/settings/fragments/ClockDateSettings.java +++ b/src/com/cherish/settings/fragments/ClockDateSettings.java @@ -38,7 +38,8 @@ import android.view.View; import android.widget.EditText; import com.android.internal.logging.nano.MetricsProto; - +import com.cherish.settings.preferences.SystemSettingSwitchPreference; +import com.cherish.settings.preferences.CustomSeekBarPreference; import com.android.settings.R; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.SettingsPreferenceFragment; @@ -53,112 +54,147 @@ import java.util.List; public class ClockDateSettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener, Indexable { - private static final String PREF_AM_PM_STYLE = "status_bar_am_pm"; - private static final String PREF_CLOCK_DATE_DISPLAY = "clock_date_display"; - private static final String PREF_CLOCK_DATE_STYLE = "clock_date_style"; - private static final String PREF_CLOCK_DATE_FORMAT = "clock_date_format"; - private static final String PREF_STATUS_BAR_CLOCK = "status_bar_show_clock"; - private static final String PREF_CLOCK_DATE_POSITION = "clock_date_position"; + private static final String STATUS_BAR_CLOCK = "status_bar_clock"; + private static final String STATUS_BAR_CLOCK_SECONDS = "status_bar_clock_seconds"; + private static final String STATUS_BAR_CLOCK_STYLE = "statusbar_clock_style"; + private static final String STATUS_BAR_AM_PM = "statusbar_clock_am_pm_style"; + private static final String STATUS_BAR_CLOCK_DATE_DISPLAY = "statusbar_clock_date_display"; + private static final String STATUS_BAR_CLOCK_DATE_STYLE = "statusbar_clock_date_style"; + private static final String STATUS_BAR_CLOCK_DATE_FORMAT = "statusbar_clock_date_format"; 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; + private static final String STATUS_BAR_CLOCK_DATE_POSITION = "statusbar_clock_date_position"; - private ListPreference mClockAmPmStyle; + private SystemSettingSwitchPreference mStatusBarClockShow; + private SystemSettingSwitchPreference mStatusBarSecondsShow; + private ListPreference mStatusBarClock; + private ListPreference mStatusBarAmPm; private ListPreference mClockDateDisplay; private ListPreference mClockDateStyle; private ListPreference mClockDateFormat; private ListPreference mClockDatePosition; - private SwitchPreference mStatusBarClock; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.clock_date_settings); + PreferenceScreen prefSet = getPreferenceScreen(); + ContentResolver resolver = getActivity().getContentResolver(); - mClockAmPmStyle = (ListPreference) findPreference(PREF_AM_PM_STYLE); - mClockAmPmStyle.setOnPreferenceChangeListener(this); - mClockAmPmStyle.setValue(Integer.toString(Settings.System.getInt(getActivity() - .getContentResolver(), Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE, - 0))); - boolean is24hour = DateFormat.is24HourFormat(getActivity()); - if (is24hour) { - mClockAmPmStyle.setSummary(R.string.status_bar_am_pm_info); + // clock settings + mStatusBarClockShow = (SystemSettingSwitchPreference) findPreference(STATUS_BAR_CLOCK); + mStatusBarSecondsShow = (SystemSettingSwitchPreference) findPreference(STATUS_BAR_CLOCK_SECONDS); + mStatusBarClock = (ListPreference) findPreference(STATUS_BAR_CLOCK_STYLE); + mStatusBarAmPm = (ListPreference) findPreference(STATUS_BAR_AM_PM); + mClockDateDisplay = (ListPreference) findPreference(STATUS_BAR_CLOCK_DATE_DISPLAY); + mClockDateStyle = (ListPreference) findPreference(STATUS_BAR_CLOCK_DATE_STYLE); + mClockDatePosition = (ListPreference) findPreference(STATUS_BAR_CLOCK_DATE_POSITION); + + mStatusBarClockShow.setChecked((Settings.System.getInt(resolver, + Settings.System.STATUSBAR_CLOCK, 1) == 1)); + mStatusBarClockShow.setOnPreferenceChangeListener(this); + + mStatusBarSecondsShow.setChecked((Settings.System.getInt(resolver, + Settings.System.STATUSBAR_CLOCK_SECONDS, 0) == 1)); + mStatusBarSecondsShow.setOnPreferenceChangeListener(this); + + int clockStyle = Settings.System.getInt(resolver, + Settings.System.STATUSBAR_CLOCK_STYLE, 0); + mStatusBarClock.setValue(String.valueOf(clockStyle)); + mStatusBarClock.setSummary(mStatusBarClock.getEntry()); + mStatusBarClock.setOnPreferenceChangeListener(this); + + if (DateFormat.is24HourFormat(getActivity())) { + mStatusBarAmPm.setEnabled(false); + mStatusBarAmPm.setSummary(R.string.status_bar_am_pm_info); } else { - mClockAmPmStyle.setSummary(mClockAmPmStyle.getEntry()); + int statusBarAmPm = Settings.System.getInt(resolver, + Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE, 2); + mStatusBarAmPm.setValue(String.valueOf(statusBarAmPm)); + mStatusBarAmPm.setSummary(mStatusBarAmPm.getEntry()); + mStatusBarAmPm.setOnPreferenceChangeListener(this); } - mClockAmPmStyle.setEnabled(!is24hour); - mClockDateDisplay = (ListPreference) findPreference(PREF_CLOCK_DATE_DISPLAY); - mClockDateDisplay.setOnPreferenceChangeListener(this); - mClockDateDisplay.setValue(Integer.toString(Settings.System.getInt(getActivity() - .getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, - 0))); + // date settings + int clockDateDisplay = Settings.System.getInt(resolver, + Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, 0); + mClockDateDisplay.setValue(String.valueOf(clockDateDisplay)); mClockDateDisplay.setSummary(mClockDateDisplay.getEntry()); + mClockDateDisplay.setOnPreferenceChangeListener(this); - mClockDateStyle = (ListPreference) findPreference(PREF_CLOCK_DATE_STYLE); - mClockDateStyle.setOnPreferenceChangeListener(this); - mClockDateStyle.setValue(Integer.toString(Settings.System.getInt(getActivity() - .getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_STYLE, - 0))); + int clockDateStyle = Settings.System.getInt(resolver, + Settings.System.STATUSBAR_CLOCK_DATE_STYLE, 0); + mClockDateStyle.setValue(String.valueOf(clockDateStyle)); mClockDateStyle.setSummary(mClockDateStyle.getEntry()); + mClockDateStyle.setOnPreferenceChangeListener(this); - mClockDateFormat = (ListPreference) findPreference(PREF_CLOCK_DATE_FORMAT); + mClockDateFormat = (ListPreference) findPreference(STATUS_BAR_CLOCK_DATE_FORMAT); mClockDateFormat.setOnPreferenceChangeListener(this); String value = Settings.System.getString(getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_FORMAT); + if (value == null || value.isEmpty()) { value = "EEE"; } + int index = mClockDateFormat.findIndexOfValue((String) value); if (index == -1) { mClockDateFormat.setValueIndex(CUSTOM_CLOCK_DATE_FORMAT_INDEX); } else { mClockDateFormat.setValue(value); } - parseClockDateFormats(); - mStatusBarClock = (SwitchPreference) findPreference(PREF_STATUS_BAR_CLOCK); - mStatusBarClock.setChecked((Settings.System.getInt( - getActivity().getApplicationContext().getContentResolver(), - Settings.System.STATUSBAR_CLOCK, 1) == 1)); - mStatusBarClock.setOnPreferenceChangeListener(this); - - mClockDatePosition = (ListPreference) findPreference(PREF_CLOCK_DATE_POSITION); - mClockDatePosition.setOnPreferenceChangeListener(this); mClockDatePosition.setValue(Integer.toString(Settings.System.getInt(getActivity() .getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_POSITION, 0))); mClockDatePosition.setSummary(mClockDatePosition.getEntry()); + mClockDatePosition.setOnPreferenceChangeListener(this); - boolean mClockDateToggle = Settings.System.getInt(getActivity().getContentResolver(), - Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, 0) != 0; - if (!mClockDateToggle) { - mClockDateStyle.setEnabled(false); - mClockDateFormat.setEnabled(false); - mClockDatePosition.setEnabled(false); - } + int clockDatePosition = Settings.System.getInt(resolver, + Settings.System.STATUSBAR_CLOCK_DATE_POSITION, 0); + mClockDatePosition.setValue(String.valueOf(clockDatePosition)); + mClockDatePosition.setSummary(mClockDatePosition.getEntry()); + mClockDatePosition.setOnPreferenceChangeListener(this); } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { AlertDialog dialog; - if (preference == mClockAmPmStyle) { - int val = Integer.parseInt((String) newValue); - int index = mClockAmPmStyle.findIndexOfValue((String) newValue); + if (preference == mStatusBarClockShow) { + boolean value = (Boolean) newValue; Settings.System.putInt(getActivity().getContentResolver(), - Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE, val); - mClockAmPmStyle.setSummary(mClockAmPmStyle.getEntries()[index]); + Settings.System.STATUSBAR_CLOCK, value ? 1 : 0); + return true; + } else if (preference == mStatusBarSecondsShow) { + boolean value = (Boolean) newValue; + Settings.System.putInt(getActivity().getContentResolver(), + Settings.System.STATUSBAR_CLOCK_SECONDS, value ? 1 : 0); + return true; + } else if (preference == mStatusBarClock) { + int clockStyle = Integer.parseInt((String) newValue); + int index = mStatusBarClock.findIndexOfValue((String) newValue); + Settings.System.putInt(getActivity().getContentResolver(), + Settings.System.STATUSBAR_CLOCK_STYLE, clockStyle); + mStatusBarClock.setSummary(mStatusBarClock.getEntries()[index]); + return true; + } else if (preference == mStatusBarAmPm) { + int statusBarAmPm = Integer.valueOf((String) newValue); + int index = mStatusBarAmPm.findIndexOfValue((String) newValue); + Settings.System.putInt(getActivity().getContentResolver(), + Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE, statusBarAmPm); + mStatusBarAmPm.setSummary(mStatusBarAmPm.getEntries()[index]); return true; } else if (preference == mClockDateDisplay) { - int val = Integer.parseInt((String) newValue); + int clockDateDisplay = Integer.valueOf((String) newValue); int index = mClockDateDisplay.findIndexOfValue((String) newValue); Settings.System.putInt(getActivity().getContentResolver(), - Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, val); + Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, clockDateDisplay); mClockDateDisplay.setSummary(mClockDateDisplay.getEntries()[index]); - if (val == 0) { + if (clockDateDisplay == 0) { mClockDateStyle.setEnabled(false); mClockDateFormat.setEnabled(false); mClockDatePosition.setEnabled(false); @@ -169,22 +205,17 @@ public class ClockDateSettings extends SettingsPreferenceFragment } return true; } else if (preference == mClockDateStyle) { - int val = Integer.parseInt((String) newValue); + int clockDateStyle = Integer.valueOf((String) newValue); int index = mClockDateStyle.findIndexOfValue((String) newValue); Settings.System.putInt(getActivity().getContentResolver(), - Settings.System.STATUSBAR_CLOCK_DATE_STYLE, val); + Settings.System.STATUSBAR_CLOCK_DATE_STYLE, clockDateStyle); mClockDateStyle.setSummary(mClockDateStyle.getEntries()[index]); parseClockDateFormats(); return true; - } else if (preference == mStatusBarClock) { - Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(), - Settings.System.STATUSBAR_CLOCK, - (Boolean) newValue ? 1 : 0); - return true; } else if (preference == mClockDateFormat) { int index = mClockDateFormat.findIndexOfValue((String) newValue); - if (index == CUSTOM_CLOCK_DATE_FORMAT_INDEX) { + if (index == CUSTOM_CLOCK_DATE_FORMAT_INDEX) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle(R.string.clock_date_string_edittext_title); alert.setMessage(R.string.clock_date_string_edittext_summary); @@ -206,7 +237,8 @@ public class ClockDateSettings extends SettingsPreferenceFragment } Settings.System.putString(getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_FORMAT, value); - return; + + return; } }); @@ -233,8 +265,8 @@ public class ClockDateSettings extends SettingsPreferenceFragment mClockDatePosition.setSummary(mClockDatePosition.getEntries()[index]); parseClockDateFormats(); return true; - } - return false; + } + return false; } private void parseClockDateFormats() {