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

@@ -384,7 +384,7 @@
<activity-alias android:name=".ManageApplications" <activity-alias android:name=".ManageApplications"
android:targetActivity=".applications.ManageApplications" android:targetActivity=".applications.ManageApplications"
android:exported="true" /> android:exported="true" />
<activity android:name=".applications.InstalledAppDetails" <activity android:name=".applications.InstalledAppDetails"
android:theme="@android:style/Theme.NoTitleBar" android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/application_info_label"> android:label="@string/application_info_label">
@@ -407,7 +407,7 @@
<category android:name="com.android.settings.SHORTCUT" /> <category android:name="com.android.settings.SHORTCUT" />
</intent-filter> </intent-filter>
</activity-alias> </activity-alias>
<!-- Provide direct entry into manage apps showing running services. --> <!-- Provide direct entry into manage apps showing running services. -->
<activity-alias android:name=".applications.StorageUse" <activity-alias android:name=".applications.StorageUse"
android:label="@string/storageuse_settings_title" android:label="@string/storageuse_settings_title"
@@ -420,7 +420,7 @@
<category android:name="com.android.settings.SHORTCUT" /> <category android:name="com.android.settings.SHORTCUT" />
</intent-filter> </intent-filter>
</activity-alias> </activity-alias>
<activity android:name=".applications.RunningServiceDetails" <activity android:name=".applications.RunningServiceDetails"
android:theme="@android:style/Theme.NoTitleBar" android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/runningservicedetails_settings_title"> android:label="@string/runningservicedetails_settings_title">

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 -->
@@ -525,7 +535,7 @@
<string name="lock_after_timeout">Lock device after timeout</string> <string name="lock_after_timeout">Lock device after timeout</string>
<!-- Security settings screen, setting option summary to change screen timeout --> <!-- Security settings screen, setting option summary to change screen timeout -->
<string name="lock_after_timeout_summary">Adjust the delay before the device automatically locks</string> <string name="lock_after_timeout_summary">Adjust the delay before the device automatically locks</string>
<!-- Main Settings screen setting option title for the item to take you the security and location screen --> <!-- Main Settings screen setting option title for the item to take you the security and location screen -->
<string name="security_settings_title">Location &amp; security</string> <string name="security_settings_title">Location &amp; security</string>
<!-- Location & security settings screen title --> <!-- Location & security settings screen title -->
@@ -1927,7 +1937,7 @@ found in the list of installed applications.</string>
<!-- Message that a process's provider is in use. --> <!-- Message that a process's provider is in use. -->
<string name="process_provider_in_use_description">Provider <xliff:g id="comp_name">%1$s</xliff:g> <string name="process_provider_in_use_description">Provider <xliff:g id="comp_name">%1$s</xliff:g>
is in use.</string> is in use.</string>
<!-- Language Settings --> <skip /> <!-- Language Settings --> <skip />
<!-- Title of setting on main settings screen. This item will take the user to the screen to tweak settings realted to locale and text --> <!-- Title of setting on main settings screen. This item will take the user to the screen to tweak settings realted to locale and text -->
<string name="language_settings">Language &amp; keyboard</string> <string name="language_settings">Language &amp; keyboard</string>
@@ -2077,7 +2087,7 @@ found in the list of installed applications.</string>
<!-- Used to show an amount of time in the form "s seconds" in BatteryHistory --> <!-- Used to show an amount of time in the form "s seconds" in BatteryHistory -->
<string name="battery_history_seconds"><xliff:g id="seconds">%1$d</xliff:g>s</string> <string name="battery_history_seconds"><xliff:g id="seconds">%1$d</xliff:g>s</string>
<!-- XXX remove? Strings used for displaying usage statistics --> <!-- XXX remove? Strings used for displaying usage statistics -->
<string name="usage_stats_label">Usage statistics</string> <string name="usage_stats_label">Usage statistics</string>

View File

@@ -4,9 +4,9 @@
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,31 +16,36 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/date_and_time"> android:title="@string/date_and_time">
<CheckBoxPreference android:key="auto_time" <CheckBoxPreference android:key="auto_time"
android:title="@string/date_time_auto" android:title="@string/date_time_auto"
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"
/> />
<Preference android:key="date" <CheckBoxPreference android:key="auto_zone"
android:title="@string/date_time_set_date" 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" 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" <CheckBoxPreference android:key="24 hour"
android:title="@string/date_time_set_time"
android:summary="12:00am"
/>
<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"
android:summaryOff="@string/date_time_12_hour_sample"/> android:summaryOff="@string/date_time_12_hour_sample"/>
<ListPreference <ListPreference
android:key="date_format" android:key="date_format"
android:title="@string/date_time_date_format" android:title="@string/date_time_date_format"
android:summary="mm/dd/yyyy"/> android:summary="mm/dd/yyyy"/>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -48,47 +48,50 @@ public class DateTimeSettings extends SettingsPreferenceFragment
private static final String HOURS_12 = "12"; private static final String HOURS_12 = "12";
private static final String HOURS_24 = "24"; private static final String HOURS_24 = "24";
// Used for showing the current date format, which looks like "12/31/2010", "2010/12/13", etc. // Used for showing the current date format, which looks like "12/31/2010", "2010/12/13", etc.
// The date value is dummy (independent of actual date). // The date value is dummy (independent of actual date).
private Calendar mDummyDate; private Calendar mDummyDate;
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;
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
addPreferencesFromResource(R.xml.date_time_prefs); addPreferencesFromResource(R.xml.date_time_prefs);
initUI(); initUI();
} }
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");
mDatePref = findPreference("date"); mDatePref = findPreference("date");
mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT); mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT);
String [] dateFormats = getResources().getStringArray(R.array.date_format_values); String [] dateFormats = getResources().getStringArray(R.array.date_format_values);
String [] formattedDates = new String[dateFormats.length]; String [] formattedDates = new String[dateFormats.length];
String currentFormat = getDateFormat(); String currentFormat = getDateFormat();
@@ -109,22 +112,23 @@ public class DateTimeSettings extends SettingsPreferenceFragment
formattedDates[i] = formatted; formattedDates[i] = formatted;
} }
} }
mDateFormat.setEntries(formattedDates); mDateFormat.setEntries(formattedDates);
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);
} }
@Override @Override
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());
@@ -138,13 +142,14 @@ public class DateTimeSettings extends SettingsPreferenceFragment
updateTimeAndDateDisplay(getActivity()); updateTimeAndDateDisplay(getActivity());
} }
@Override @Override
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) {
java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(context); java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(context);
final Calendar now = Calendar.getInstance(); final Calendar now = Calendar.getInstance();
@@ -180,19 +185,22 @@ public class DateTimeSettings extends SettingsPreferenceFragment
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (key.equals(KEY_DATE_FORMAT)) { if (key.equals(KEY_DATE_FORMAT)) {
String format = preferences.getString(key, String format = preferences.getString(key,
getResources().getString(R.string.default_date_format)); getResources().getString(R.string.default_date_format));
Settings.System.putString(getContentResolver(), Settings.System.putString(getContentResolver(),
Settings.System.DATE_FORMAT, format); Settings.System.DATE_FORMAT, format);
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);
} }
} }
@@ -272,39 +280,38 @@ public class DateTimeSettings extends SettingsPreferenceFragment
} }
return super.onPreferenceTreeClick(preferenceScreen, preference); return super.onPreferenceTreeClick(preferenceScreen, preference);
} }
@Override @Override
public void onActivityResult(int requestCode, int resultCode, public void onActivityResult(int requestCode, int resultCode,
Intent data) { Intent data) {
updateTimeAndDateDisplay(getActivity()); updateTimeAndDateDisplay(getActivity());
} }
private void timeUpdated() { private void timeUpdated() {
Intent timeChanged = new Intent(Intent.ACTION_TIME_CHANGED); Intent timeChanged = new Intent(Intent.ACTION_TIME_CHANGED);
getActivity().sendBroadcast(timeChanged); getActivity().sendBroadcast(timeChanged);
} }
/* Get & Set values from the system settings */ /* Get & Set values from the system settings */
private boolean is24Hour() { private boolean is24Hour() {
return DateFormat.is24HourFormat(getActivity()); return DateFormat.is24HourFormat(getActivity());
} }
private void set24Hour(boolean is24Hour) { private void set24Hour(boolean is24Hour) {
Settings.System.putString(getContentResolver(), Settings.System.putString(getContentResolver(),
Settings.System.TIME_12_24, Settings.System.TIME_12_24,
is24Hour? HOURS_24 : HOURS_12); is24Hour? HOURS_24 : HOURS_12);
} }
private String getDateFormat() { private String getDateFormat() {
return Settings.System.getString(getContentResolver(), return Settings.System.getString(getContentResolver(),
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;
} }
@@ -346,7 +353,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment
append(", "). append(", ").
append(tz.getDisplayName(daylight, TimeZone.LONG)); append(tz.getDisplayName(daylight, TimeZone.LONG));
return sb.toString(); return sb.toString();
} }
private static char[] formatOffset(int off) { private static char[] formatOffset(int off) {
@@ -364,7 +371,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment
buf[3] = '+'; buf[3] = '+';
} }
int hours = off / 60; int hours = off / 60;
int minutes = off % 60; int minutes = off % 60;
buf[4] = (char) ('0' + hours / 10); buf[4] = (char) ('0' + hours / 10);
@@ -377,7 +384,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment
return buf; return buf;
} }
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {