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:
@@ -384,7 +384,7 @@
|
||||
<activity-alias android:name=".ManageApplications"
|
||||
android:targetActivity=".applications.ManageApplications"
|
||||
android:exported="true" />
|
||||
|
||||
|
||||
<activity android:name=".applications.InstalledAppDetails"
|
||||
android:theme="@android:style/Theme.NoTitleBar"
|
||||
android:label="@string/application_info_label">
|
||||
@@ -407,7 +407,7 @@
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
</activity-alias>
|
||||
|
||||
|
||||
<!-- Provide direct entry into manage apps showing running services. -->
|
||||
<activity-alias android:name=".applications.StorageUse"
|
||||
android:label="@string/storageuse_settings_title"
|
||||
@@ -420,7 +420,7 @@
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
</activity-alias>
|
||||
|
||||
|
||||
<activity android:name=".applications.RunningServiceDetails"
|
||||
android:theme="@android:style/Theme.NoTitleBar"
|
||||
android:label="@string/runningservicedetails_settings_title">
|
||||
|
@@ -498,12 +498,22 @@
|
||||
<string name="date_and_time_settings_title">Date & 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 & 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 & 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 -->
|
||||
@@ -525,7 +535,7 @@
|
||||
<string name="lock_after_timeout">Lock device after timeout</string>
|
||||
<!-- 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>
|
||||
|
||||
|
||||
<!-- Main Settings screen setting option title for the item to take you the security and location screen -->
|
||||
<string name="security_settings_title">Location & security</string>
|
||||
<!-- 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. -->
|
||||
<string name="process_provider_in_use_description">Provider <xliff:g id="comp_name">%1$s</xliff:g>
|
||||
is in use.</string>
|
||||
|
||||
|
||||
<!-- 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 -->
|
||||
<string name="language_settings">Language & 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 -->
|
||||
<string name="battery_history_seconds"><xliff:g id="seconds">%1$d</xliff:g>s</string>
|
||||
|
||||
|
||||
<!-- XXX remove? Strings used for displaying usage statistics -->
|
||||
<string name="usage_stats_label">Usage statistics</string>
|
||||
|
||||
|
@@ -4,9 +4,9 @@
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
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"
|
||||
android:title="@string/date_and_time">
|
||||
<CheckBoxPreference android:key="auto_time"
|
||||
<CheckBoxPreference android:key="auto_time"
|
||||
android:title="@string/date_time_auto"
|
||||
android:summaryOn="@string/date_time_auto_summaryOn"
|
||||
android:summaryOff="@string/date_time_auto_summaryOff"
|
||||
/>
|
||||
<Preference android:key="date"
|
||||
android:title="@string/date_time_set_date"
|
||||
<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"
|
||||
<CheckBoxPreference android:key="24 hour"
|
||||
android:title="@string/date_time_24hour"
|
||||
android:summaryOn="@string/date_time_24_hour_sample"
|
||||
android:summaryOff="@string/date_time_12_hour_sample"/>
|
||||
<ListPreference
|
||||
android:key="date_format"
|
||||
android:title="@string/date_time_date_format"
|
||||
android:title="@string/date_time_date_format"
|
||||
android:summary="mm/dd/yyyy"/>
|
||||
</PreferenceScreen>
|
||||
|
@@ -48,47 +48,50 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
|
||||
private static final String HOURS_12 = "12";
|
||||
private static final String HOURS_24 = "24";
|
||||
|
||||
|
||||
// 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).
|
||||
private Calendar mDummyDate;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
|
||||
addPreferencesFromResource(R.xml.date_time_prefs);
|
||||
|
||||
initUI();
|
||||
|
||||
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.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");
|
||||
mDatePref = findPreference("date");
|
||||
mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT);
|
||||
|
||||
|
||||
String [] dateFormats = getResources().getStringArray(R.array.date_format_values);
|
||||
String [] formattedDates = new String[dateFormats.length];
|
||||
String currentFormat = getDateFormat();
|
||||
@@ -109,22 +112,23 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
formattedDates[i] = formatted;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mDateFormat.setEntries(formattedDates);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
getPreferenceScreen().getSharedPreferences()
|
||||
.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
((CheckBoxPreference)mTime24Pref).setChecked(is24Hour());
|
||||
|
||||
@@ -138,13 +142,14 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
updateTimeAndDateDisplay(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getActivity().unregisterReceiver(mIntentReceiver);
|
||||
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
getPreferenceScreen().getSharedPreferences()
|
||||
.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
|
||||
private void updateTimeAndDateDisplay(Context context) {
|
||||
java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(context);
|
||||
final Calendar now = Calendar.getInstance();
|
||||
@@ -180,19 +185,22 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (key.equals(KEY_DATE_FORMAT)) {
|
||||
String format = preferences.getString(key,
|
||||
String format = preferences.getString(key,
|
||||
getResources().getString(R.string.default_date_format));
|
||||
Settings.System.putString(getContentResolver(),
|
||||
Settings.System.putString(getContentResolver(),
|
||||
Settings.System.DATE_FORMAT, format);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,39 +280,38 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode,
|
||||
Intent data) {
|
||||
updateTimeAndDateDisplay(getActivity());
|
||||
}
|
||||
|
||||
|
||||
private void timeUpdated() {
|
||||
Intent timeChanged = new Intent(Intent.ACTION_TIME_CHANGED);
|
||||
getActivity().sendBroadcast(timeChanged);
|
||||
}
|
||||
|
||||
|
||||
/* Get & Set values from the system settings */
|
||||
|
||||
|
||||
private boolean is24Hour() {
|
||||
return DateFormat.is24HourFormat(getActivity());
|
||||
}
|
||||
|
||||
|
||||
private void set24Hour(boolean is24Hour) {
|
||||
Settings.System.putString(getContentResolver(),
|
||||
Settings.System.TIME_12_24,
|
||||
is24Hour? HOURS_24 : HOURS_12);
|
||||
}
|
||||
|
||||
|
||||
private String getDateFormat() {
|
||||
return Settings.System.getString(getContentResolver(),
|
||||
return Settings.System.getString(getContentResolver(),
|
||||
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;
|
||||
}
|
||||
@@ -346,7 +353,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
append(", ").
|
||||
append(tz.getDisplayName(daylight, TimeZone.LONG));
|
||||
|
||||
return sb.toString();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static char[] formatOffset(int off) {
|
||||
@@ -364,7 +371,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
buf[3] = '+';
|
||||
}
|
||||
|
||||
int hours = off / 60;
|
||||
int hours = off / 60;
|
||||
int minutes = off % 60;
|
||||
|
||||
buf[4] = (char) ('0' + hours / 10);
|
||||
@@ -377,7 +384,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
Reference in New Issue
Block a user