diff options
author | Luis Vidal <lvidal@cyngn.com> | 2016-05-16 16:35:35 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-05-17 14:30:09 -0700 |
commit | d67600a4f39917e47d5009bf4f9f8ce3be362af9 (patch) | |
tree | ae566d2947713ab2a97436ea56dfb2f9e972a7dc | |
parent | d6709e61c125cdc636944c16efe3303f9ffbb9e1 (diff) | |
download | packages_apps_Settings-d67600a4f39917e47d5009bf4f9f8ce3be362af9.tar.gz packages_apps_Settings-d67600a4f39917e47d5009bf4f9f8ce3be362af9.tar.bz2 packages_apps_Settings-d67600a4f39917e47d5009bf4f9f8ce3be362af9.zip |
Settings: update time zone strings on date change
If the user changes the date, most obvious case being from 1970, to a
current date, and the user's selected Locale's country time zones have
been changed (according to ICU), we must update the time zone strings in
the system.
Ref: CYNGNOS-453
Signed-off-by: Roman Birg <roman@cyngn.com>
(cherry picked from commit 926c3b0a50e521368628ef0d9975c99fa4cd3480)
Change-Id: I487c54cd4f933286c5004d24a3f8730ee2d4e4f6
-rwxr-xr-x | AndroidManifest.xml | 7 | ||||
-rw-r--r-- | src/com/android/settings/DateChangeReceiver.java | 28 | ||||
-rw-r--r-- | src/com/android/settings/DateTimeSettings.java | 13 |
3 files changed, 48 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 451f3708c..349bca7f9 100755 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -529,6 +529,13 @@ android:value="true" /> </activity> + <receiver android:name=".DateChangeReceiver"> + <intent-filter> + <action android:name="android.intent.action.DATE_CHANGED"/> + <action android:name="android.intent.action.LOCALE_CHANGED"/> + </intent-filter> + </receiver> + <activity android:name="DateTimeSettingsSetupWizard" android:label="@string/date_and_time" android:theme="@style/Theme.DateTimeSettingsSetupWizard" diff --git a/src/com/android/settings/DateChangeReceiver.java b/src/com/android/settings/DateChangeReceiver.java new file mode 100644 index 000000000..6a3ec882e --- /dev/null +++ b/src/com/android/settings/DateChangeReceiver.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class DateChangeReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + DateTimeSettings.updateLocaleStrings(); + } +} diff --git a/src/com/android/settings/DateTimeSettings.java b/src/com/android/settings/DateTimeSettings.java index 8a9e2ad84..34753ef04 100644 --- a/src/com/android/settings/DateTimeSettings.java +++ b/src/com/android/settings/DateTimeSettings.java @@ -40,9 +40,12 @@ import android.widget.TimePicker; import com.android.internal.logging.MetricsLogger; import com.android.settingslib.datetime.ZoneGetter; +import libcore.icu.TimeZoneNames; +import java.text.DateFormatSymbols; import java.util.Calendar; import java.util.Date; +import java.util.Locale; public class DateTimeSettings extends SettingsPreferenceFragment implements OnSharedPreferenceChangeListener, @@ -329,6 +332,16 @@ public class DateTimeSettings extends SettingsPreferenceFragment if (when / 1000 < Integer.MAX_VALUE) { ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).setTime(when); } + updateLocaleStrings(); + } + + static void updateLocaleStrings() { + // If a device was boot up with date 1970 and then date changes to some later time, + // the wrong string might be cached if the country's zones have changed. + // See external/icu/icu4c/source/data/misc/metaZones.txt for complete mapping + TimeZoneNames.clearLocaleCache(); + Locale locale = Locale.getDefault(); + DateFormatSymbols.getInstance(locale).setZoneStrings(TimeZoneNames.getZoneStrings(locale)); } /* package */ static void setTime(Context context, int hourOfDay, int minute) { |