summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVeeti Paananen <veeti.paananen@rojekti.fi>2013-07-23 16:55:31 +0300
committerVeeti Paananen <veeti.paananen@rojekti.fi>2013-07-23 18:47:58 +0300
commitd1f1fb4064bfcef528a12a4c5176df7b44ffd48c (patch)
tree876387fc274a430cb2cd4ffcaa63575007195ce8
parent2413c2418c1d55e5fd3b765428aa6616be00babd (diff)
downloadpackages_apps_settings-d1f1fb4064bfcef528a12a4c5176df7b44ffd48c.zip
packages_apps_settings-d1f1fb4064bfcef528a12a4c5176df7b44ffd48c.tar.gz
packages_apps_settings-d1f1fb4064bfcef528a12a4c5176df7b44ffd48c.tar.bz2
Hide the AM/PM preference completely if using a 24-hour clock
In addition, this commit also fixes a bug where the switch would not be disabled on a fresh 24-hour clock install, as the preference value would be null. This is avoided by using a higher-level method from DateFormat to check the clock mode. Patch Set 2: improve code styling Patch Set 3: remove pointless application context retrieval Change-Id: I80de938df61803649688723843439905e9909b07
-rw-r--r--res/xml/status_bar.xml1
-rw-r--r--src/com/android/settings/cyanogenmod/StatusBar.java33
2 files changed, 18 insertions, 16 deletions
diff --git a/res/xml/status_bar.xml b/res/xml/status_bar.xml
index b996c6f..9dc45e4 100644
--- a/res/xml/status_bar.xml
+++ b/res/xml/status_bar.xml
@@ -20,6 +20,7 @@
<!-- Status bar tweaks -->
<PreferenceCategory
+ android:key="status_bar_clock"
android:title="@string/status_bar_clock_title">
<CheckBoxPreference
diff --git a/src/com/android/settings/cyanogenmod/StatusBar.java b/src/com/android/settings/cyanogenmod/StatusBar.java
index 6c10d13..f9e911a 100644
--- a/src/com/android/settings/cyanogenmod/StatusBar.java
+++ b/src/com/android/settings/cyanogenmod/StatusBar.java
@@ -25,6 +25,7 @@ import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
+import android.text.format.DateFormat;
import android.util.Log;
import com.android.settings.R;
@@ -33,6 +34,7 @@ import com.android.settings.Utils;
public class StatusBar extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
+ private static final String STATUS_BAR_CLOCK_CATEGORY = "status_bar_clock";
private static final String STATUS_BAR_AM_PM = "status_bar_am_pm";
private static final String STATUS_BAR_BATTERY = "status_bar_battery";
private static final String STATUS_BAR_CLOCK = "status_bar_show_clock";
@@ -65,6 +67,20 @@ public class StatusBar extends SettingsPreferenceFragment implements OnPreferenc
mStatusBarClock.setChecked((Settings.System.getInt(getActivity().getApplicationContext().getContentResolver(),
Settings.System.STATUS_BAR_CLOCK, 1) == 1));
+
+ if (DateFormat.is24HourFormat(getActivity())) {
+ ((PreferenceCategory) prefSet.findPreference(STATUS_BAR_CLOCK_CATEGORY))
+ .removePreference(prefSet.findPreference(STATUS_BAR_AM_PM));
+ } else {
+ mStatusBarAmPm = (ListPreference) prefSet.findPreference(STATUS_BAR_AM_PM);
+ int statusBarAmPm = Settings.System.getInt(getActivity().getContentResolver(),
+ Settings.System.STATUS_BAR_AM_PM, 2);
+
+ mStatusBarAmPm.setValue(String.valueOf(statusBarAmPm));
+ mStatusBarAmPm.setSummary(mStatusBarAmPm.getEntry());
+ mStatusBarAmPm.setOnPreferenceChangeListener(this);
+ }
+
mStatusBarBrightnessControl.setChecked((Settings.System.getInt(getActivity().getApplicationContext().getContentResolver(),
Settings.System.STATUS_BAR_BRIGHTNESS_CONTROL, 0) == 1));
@@ -77,21 +93,6 @@ public class StatusBar extends SettingsPreferenceFragment implements OnPreferenc
} catch (SettingNotFoundException e) {
}
- try {
- if (Settings.System.getInt(getActivity().getApplicationContext().getContentResolver(),
- Settings.System.TIME_12_24) == 24) {
- mStatusBarAmPm.setEnabled(false);
- mStatusBarAmPm.setSummary(R.string.status_bar_am_pm_info);
- }
- } catch (SettingNotFoundException e ) {
- }
-
- int statusBarAmPm = Settings.System.getInt(getActivity().getApplicationContext().getContentResolver(),
- Settings.System.STATUS_BAR_AM_PM, 2);
- mStatusBarAmPm.setValue(String.valueOf(statusBarAmPm));
- mStatusBarAmPm.setSummary(mStatusBarAmPm.getEntry());
- mStatusBarAmPm.setOnPreferenceChangeListener(this);
-
int statusBarBattery = Settings.System.getInt(getActivity().getApplicationContext().getContentResolver(),
Settings.System.STATUS_BAR_BATTERY, 0);
mStatusBarBattery.setValue(String.valueOf(statusBarBattery));
@@ -121,7 +122,7 @@ public class StatusBar extends SettingsPreferenceFragment implements OnPreferenc
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (preference == mStatusBarAmPm) {
+ if (mStatusBarAmPm != null && preference == mStatusBarAmPm) {
int statusBarAmPm = Integer.valueOf((String) newValue);
int index = mStatusBarAmPm.findIndexOfValue((String) newValue);
Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),