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>
<!-- 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>
<!-- Date & time setting screen setting check box title if the date and time should be determined automatically -->
<string name="date_time_auto">Automatic</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) -->
<string name="date_time_auto_summaryOn">Use network-provided values</string>
<!-- Date & time setting screen setting option summary text when Automatic check box is clear -->
<string name="date_time_auto_summaryOff">Use network-provided values</string>
<!-- 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 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) [CHAR LIMIT=100] -->
<string name="date_time_auto_summaryOn">Use network-provided time</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 -->
<string name="date_time_24hour">Use 24-hour format</string>
<!-- Date & time setting screen setting option title -->

View File

@@ -21,20 +21,25 @@
android:summaryOn="@string/date_time_auto_summaryOn"
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"
android:title="@string/date_time_set_date"
android:summary="03/10/2008"
/>
<Preference android:key="time"
android:title="@string/date_time_set_time"
android:summary="12:00am"
/>
<PreferenceScreen
android:fragment="com.android.settings.ZonePicker"
android:key="timezone"
android:title="@string/date_time_set_timezone"
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"
android:title="@string/date_time_24hour"
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_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_TIMEPICKER = 1;
private CheckBoxPreference mAutoPref;
private CheckBoxPreference mAutoTimePref;
private Preference mTimePref;
private Preference mTime24Pref;
private CheckBoxPreference mAutoTimeZonePref;
private Preference mTimeZone;
private Preference mDatePref;
private ListPreference mDateFormat;
@@ -76,13 +78,14 @@ public class DateTimeSettings extends SettingsPreferenceFragment
}
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.set(mDummyDate.get(Calendar.YEAR), 11, 31, 13, 0, 0);
mAutoPref = (CheckBoxPreference) findPreference(KEY_AUTO_TIME);
mAutoPref.setChecked(autoEnabled);
mAutoTimePref = (CheckBoxPreference) findPreference(KEY_AUTO_TIME);
mAutoTimePref.setChecked(autoTimeEnabled);
mTimePref = findPreference("time");
mTime24Pref = findPreference("24 hour");
mTimeZone = findPreference("timezone");
@@ -114,9 +117,9 @@ public class DateTimeSettings extends SettingsPreferenceFragment
mDateFormat.setEntryValues(R.array.date_format_values);
mDateFormat.setValue(currentFormat);
mTimePref.setEnabled(!autoEnabled);
mDatePref.setEnabled(!autoEnabled);
mTimeZone.setEnabled(!autoEnabled);
mTimePref.setEnabled(!autoTimeEnabled);
mDatePref.setEnabled(!autoTimeEnabled);
mTimeZone.setEnabled(!autoTimeZoneEnabled);
}
@@ -124,7 +127,8 @@ public class DateTimeSettings extends SettingsPreferenceFragment
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
((CheckBoxPreference)mTime24Pref).setChecked(is24Hour());
@@ -142,7 +146,8 @@ public class DateTimeSettings extends SettingsPreferenceFragment
public void onPause() {
super.onPause();
getActivity().unregisterReceiver(mIntentReceiver);
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
private void updateTimeAndDateDisplay(Context context) {
@@ -187,12 +192,15 @@ public class DateTimeSettings extends SettingsPreferenceFragment
updateTimeAndDateDisplay(getActivity());
} else if (key.equals(KEY_AUTO_TIME)) {
boolean autoEnabled = preferences.getBoolean(key, true);
Settings.System.putInt(getContentResolver(),
Settings.System.AUTO_TIME,
Settings.System.putInt(getContentResolver(), Settings.System.AUTO_TIME,
autoEnabled ? 1 : 0);
mTimePref.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);
}
private boolean getAutoState() {
private boolean getAutoState(String name) {
try {
return Settings.System.getInt(getContentResolver(),
Settings.System.AUTO_TIME) > 0;
return Settings.System.getInt(getContentResolver(), name) > 0;
} catch (SettingNotFoundException snfe) {
return true;
}