Add an Automatic Time Zone setting to Date & Time settings.

User can now enable auto-time but disable auto-timezone, especially
if we don't have NITZ time from the cell network (or wifi only)
and only have NTP time that gives us date and time.
This commit is contained in:
Amith Yamasani
2010-09-17 13:34:47 -07:00
parent 653abb13d8
commit 1bb6db5267
4 changed files with 88 additions and 66 deletions

View File

@@ -498,12 +498,22 @@
<string name="date_and_time_settings_title">Date &amp; time</string> <string name="date_and_time_settings_title">Date &amp; time</string>
<!-- Main Settings screen setting option summary text for the item to go into the date and time settings. --> <!-- Main Settings screen setting option summary text for the item to go into the date and time settings. -->
<string name="date_and_time_settings_summary">Set date, time, time zone &amp; formats</string> <string name="date_and_time_settings_summary">Set date, time, time zone &amp; formats</string>
<!-- Date & time setting screen setting check box title if the date and time should be determined automatically --> <!-- Date & time setting screen setting check box title if the date and time should be determined automatically [CHAR LIMIT=25] -->
<string name="date_time_auto">Automatic</string> <string name="date_time_auto">Automatic date &amp; time</string>
<!-- Date & time setting screen setting option summary text when Automatic check box is selected (that is, when date and time should be determined automatically) --> <!-- Date & time setting screen setting option summary text when Automatic check box is selected
<string name="date_time_auto_summaryOn">Use network-provided values</string> (that is, when date and time should be determined automatically) [CHAR LIMIT=100] -->
<!-- Date & time setting screen setting option summary text when Automatic check box is clear --> <string name="date_time_auto_summaryOn">Use network-provided time</string>
<string name="date_time_auto_summaryOff">Use network-provided values</string> <!-- Date & time setting screen setting option summary text when Automatic check box is clear
[CHAR LIMIT=100] -->
<string name="date_time_auto_summaryOff">Use network-provided time</string>
<!-- Date & time setting screen setting check box title if the time zone should be determined automatically [CHAR LIMIT=25] -->
<string name="zone_auto">Automatic time zone</string>
<!-- Date & time setting screen setting option summary text when Automatic time zone check box is selected (that is, when date and time should be determined automatically)
[CHAR LIMIT=100] -->
<string name="zone_auto_summaryOn">Use network-provided time zone</string>
<!-- Date & time setting screen setting option summary text when Automatic time zone check box is clear
[CHAR LIMIT=100] -->
<string name="zone_auto_summaryOff">Use network-provided time zone</string>
<!-- Date & time setting screen setting check box title --> <!-- Date & time setting screen setting check box title -->
<string name="date_time_24hour">Use 24-hour format</string> <string name="date_time_24hour">Use 24-hour format</string>
<!-- Date & time setting screen setting option title --> <!-- Date & time setting screen setting option title -->

View File

@@ -21,20 +21,25 @@
android:summaryOn="@string/date_time_auto_summaryOn" android:summaryOn="@string/date_time_auto_summaryOn"
android:summaryOff="@string/date_time_auto_summaryOff" android:summaryOff="@string/date_time_auto_summaryOff"
/> />
<CheckBoxPreference android:key="auto_zone"
android:title="@string/zone_auto"
android:summaryOn="@string/zone_auto_summaryOn"
android:summaryOff="@string/zone_auto_summaryOff"
/>
<Preference android:key="date" <Preference android:key="date"
android:title="@string/date_time_set_date" android:title="@string/date_time_set_date"
android:summary="03/10/2008" android:summary="03/10/2008"
/> />
<Preference android:key="time"
android:title="@string/date_time_set_time"
android:summary="12:00am"
/>
<PreferenceScreen <PreferenceScreen
android:fragment="com.android.settings.ZonePicker" android:fragment="com.android.settings.ZonePicker"
android:key="timezone" android:key="timezone"
android:title="@string/date_time_set_timezone" android:title="@string/date_time_set_timezone"
android:summary="GMT-8:00" android:summary="GMT-8:00"
/> />
<Preference android:key="time"
android:title="@string/date_time_set_time"
android:summary="12:00am"
/>
<CheckBoxPreference android:key="24 hour" <CheckBoxPreference android:key="24 hour"
android:title="@string/date_time_24hour" android:title="@string/date_time_24hour"
android:summaryOn="@string/date_time_24_hour_sample" android:summaryOn="@string/date_time_24_hour_sample"

View File

@@ -55,13 +55,15 @@ public class DateTimeSettings extends SettingsPreferenceFragment
private static final String KEY_DATE_FORMAT = "date_format"; private static final String KEY_DATE_FORMAT = "date_format";
private static final String KEY_AUTO_TIME = "auto_time"; private static final String KEY_AUTO_TIME = "auto_time";
private static final String KEY_AUTO_TIME_ZONE = "auto_zone";
private static final int DIALOG_DATEPICKER = 0; private static final int DIALOG_DATEPICKER = 0;
private static final int DIALOG_TIMEPICKER = 1; private static final int DIALOG_TIMEPICKER = 1;
private CheckBoxPreference mAutoPref; private CheckBoxPreference mAutoTimePref;
private Preference mTimePref; private Preference mTimePref;
private Preference mTime24Pref; private Preference mTime24Pref;
private CheckBoxPreference mAutoTimeZonePref;
private Preference mTimeZone; private Preference mTimeZone;
private Preference mDatePref; private Preference mDatePref;
private ListPreference mDateFormat; private ListPreference mDateFormat;
@@ -76,13 +78,14 @@ public class DateTimeSettings extends SettingsPreferenceFragment
} }
private void initUI() { private void initUI() {
boolean autoEnabled = getAutoState(); boolean autoTimeEnabled = getAutoState(Settings.System.AUTO_TIME);
boolean autoTimeZoneEnabled = getAutoState(Settings.System.AUTO_TIME_ZONE);
mDummyDate = Calendar.getInstance(); mDummyDate = Calendar.getInstance();
mDummyDate.set(mDummyDate.get(Calendar.YEAR), 11, 31, 13, 0, 0); mDummyDate.set(mDummyDate.get(Calendar.YEAR), 11, 31, 13, 0, 0);
mAutoPref = (CheckBoxPreference) findPreference(KEY_AUTO_TIME); mAutoTimePref = (CheckBoxPreference) findPreference(KEY_AUTO_TIME);
mAutoPref.setChecked(autoEnabled); mAutoTimePref.setChecked(autoTimeEnabled);
mTimePref = findPreference("time"); mTimePref = findPreference("time");
mTime24Pref = findPreference("24 hour"); mTime24Pref = findPreference("24 hour");
mTimeZone = findPreference("timezone"); mTimeZone = findPreference("timezone");
@@ -114,9 +117,9 @@ public class DateTimeSettings extends SettingsPreferenceFragment
mDateFormat.setEntryValues(R.array.date_format_values); mDateFormat.setEntryValues(R.array.date_format_values);
mDateFormat.setValue(currentFormat); mDateFormat.setValue(currentFormat);
mTimePref.setEnabled(!autoEnabled); mTimePref.setEnabled(!autoTimeEnabled);
mDatePref.setEnabled(!autoEnabled); mDatePref.setEnabled(!autoTimeEnabled);
mTimeZone.setEnabled(!autoEnabled); mTimeZone.setEnabled(!autoTimeZoneEnabled);
} }
@@ -124,7 +127,8 @@ public class DateTimeSettings extends SettingsPreferenceFragment
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
((CheckBoxPreference)mTime24Pref).setChecked(is24Hour()); ((CheckBoxPreference)mTime24Pref).setChecked(is24Hour());
@@ -142,7 +146,8 @@ public class DateTimeSettings extends SettingsPreferenceFragment
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
getActivity().unregisterReceiver(mIntentReceiver); getActivity().unregisterReceiver(mIntentReceiver);
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
} }
private void updateTimeAndDateDisplay(Context context) { private void updateTimeAndDateDisplay(Context context) {
@@ -187,12 +192,15 @@ public class DateTimeSettings extends SettingsPreferenceFragment
updateTimeAndDateDisplay(getActivity()); updateTimeAndDateDisplay(getActivity());
} else if (key.equals(KEY_AUTO_TIME)) { } else if (key.equals(KEY_AUTO_TIME)) {
boolean autoEnabled = preferences.getBoolean(key, true); boolean autoEnabled = preferences.getBoolean(key, true);
Settings.System.putInt(getContentResolver(), Settings.System.putInt(getContentResolver(), Settings.System.AUTO_TIME,
Settings.System.AUTO_TIME,
autoEnabled ? 1 : 0); autoEnabled ? 1 : 0);
mTimePref.setEnabled(!autoEnabled); mTimePref.setEnabled(!autoEnabled);
mDatePref.setEnabled(!autoEnabled); mDatePref.setEnabled(!autoEnabled);
mTimeZone.setEnabled(!autoEnabled); } else if (key.equals(KEY_AUTO_TIME_ZONE)) {
boolean autoZoneEnabled = preferences.getBoolean(key, true);
Settings.System.putInt(
getContentResolver(), Settings.System.AUTO_TIME_ZONE, autoZoneEnabled ? 1 : 0);
mTimeZone.setEnabled(!autoZoneEnabled);
} }
} }
@@ -301,10 +309,9 @@ public class DateTimeSettings extends SettingsPreferenceFragment
Settings.System.DATE_FORMAT); Settings.System.DATE_FORMAT);
} }
private boolean getAutoState() { private boolean getAutoState(String name) {
try { try {
return Settings.System.getInt(getContentResolver(), return Settings.System.getInt(getContentResolver(), name) > 0;
Settings.System.AUTO_TIME) > 0;
} catch (SettingNotFoundException snfe) { } catch (SettingNotFoundException snfe) {
return true; return true;
} }