diff options
author | Luis Vidal <lvidal@cyngn.com> | 2016-05-16 16:00:49 -0700 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2016-05-17 14:30:17 -0700 |
commit | f59a969ae6385cd376c07f2bfadd9373c7a4e7fc (patch) | |
tree | dba72334f5a39d665507ad29ec6c8716b1105de4 /packages | |
parent | 22a2eff7aaea5e00f8c93add3b2dc8a99ddc6604 (diff) | |
download | frameworks_base-f59a969ae6385cd376c07f2bfadd9373c7a4e7fc.zip frameworks_base-f59a969ae6385cd376c07f2bfadd9373c7a4e7fc.tar.gz frameworks_base-f59a969ae6385cd376c07f2bfadd9373c7a4e7fc.tar.bz2 |
Port "Settings: add a way to not localize zone selections" to cm-13
In specific cases we may not want to display the localized time zone
name in the time zone picker.
For instance, when the system language is set to English (US), going
into the time zone picker, we can find "London." After we set the
system language to English (United Kingdom), London becomes localized to
"British Summer Time."
To avoid this behavior and to always display the unlocalized version
of the time zone name, we can now set localizeInPicker="false" on the
time zone entry desired to not be localized. Note that if a translation
is available for the selected time zone, it will still be applied.
In this patch we add this attribute to the Kiev time zone. In English
this patch has no effect. However if the system language is changed to
Ukranian and we select Kiev from the time zone picker:
Without this patch: in the time zone picker it would use local time
zone translations, e.g. "за схдноевропейським літнім часом"
(Eastern European Summer Time).
With this patch: it displays "Київ" in the time zone picker. But
still displays the localized time zone in the Date & Time settings.
Ref: CYNGNOS-453
(ported from commit c5aecaab60d353fcedd4579b9d94808be9838de2)
Change-Id: I6302e5beb981786500f73629baa0751ac9e43e73
Diffstat (limited to 'packages')
-rw-r--r-- | packages/SettingsLib/res/xml/timezones.xml | 2 | ||||
-rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java | 45 |
2 files changed, 33 insertions, 14 deletions
diff --git a/packages/SettingsLib/res/xml/timezones.xml b/packages/SettingsLib/res/xml/timezones.xml index 47e84c8..147f263 100644 --- a/packages/SettingsLib/res/xml/timezones.xml +++ b/packages/SettingsLib/res/xml/timezones.xml @@ -47,7 +47,7 @@ <timezone id="Africa/Harare"></timezone> <timezone id="Asia/Baghdad"></timezone> <timezone id="Europe/Moscow"></timezone> - <timezone id="Europe/Kiev"></timezone> + <timezone id="Europe/Kiev" localizeInPicker="false"></timezone> <timezone id="Asia/Kuwait"></timezone> <timezone id="Africa/Nairobi"></timezone> <timezone id="Asia/Tehran"></timezone> diff --git a/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java b/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java index 7b5bfb5..d4e09ca 100644 --- a/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java +++ b/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java @@ -50,7 +50,8 @@ public class ZoneGetter { public static final String KEY_DISPLAYNAME = "name"; // value: String public static final String KEY_GMT = "gmt"; // value: String public static final String KEY_OFFSET = "offset"; // value: int (Integer) - + private static final String XML_ATTR_ID = "id"; + private static final String XML_ATTR_LOCALIZE_IN_PICKER = "localizeInPicker"; private ZoneGetter() {} public static String getTimeZoneOffsetAndName(TimeZone tz, Date now) { @@ -85,7 +86,7 @@ public class ZoneGetter { // selecting the wrong olson ids. // Get the list of olson ids to display to the user. - List<String> olsonIdsToDisplay = readTimezonesToDisplay(context); + List<ZoneInfo> olsonIdsToDisplay = readTimezonesToDisplay(context); // Create a lookup of local zone IDs. Set<String> localZoneIds = new TreeSet<String>(); @@ -97,9 +98,9 @@ public class ZoneGetter { // be ambiguous. Set<String> localZoneNames = new TreeSet<String>(); boolean localLongNamesAreAmbiguous = false; - for (String olsonId : olsonIdsToDisplay) { - if (localZoneIds.contains(olsonId)) { - TimeZone tz = TimeZone.getTimeZone(olsonId); + for (ZoneInfo zoneInfo : olsonIdsToDisplay) { + if (localZoneIds.contains(zoneInfo.mOlsonId) && zoneInfo.mLocalizeInPicker) { + TimeZone tz = TimeZone.getTimeZone(zoneInfo.mOlsonId); String zoneLongName = getZoneLongName(locale, tz, now); boolean longNameIsUnique = localZoneNames.add(zoneLongName); if (!longNameIsUnique) { @@ -111,12 +112,13 @@ public class ZoneGetter { // Generate the list of zone entries to return. List<Map<String, Object>> zones = new ArrayList<Map<String, Object>>(); - for (String olsonId : olsonIdsToDisplay) { - final TimeZone tz = TimeZone.getTimeZone(olsonId); + for (ZoneInfo zoneInfo: olsonIdsToDisplay) { + final TimeZone tz = TimeZone.getTimeZone(zoneInfo.mOlsonId); // Exemplar location display is the default. The only time we intend to display the long // name is when the olsonId is local AND long names are not ambiguous. - boolean isLocalZoneId = localZoneIds.contains(olsonId); - boolean preferLongName = isLocalZoneId && !localLongNamesAreAmbiguous; + boolean isLocalZoneId = localZoneIds.contains(zoneInfo.mOlsonId); + boolean preferLongName = isLocalZoneId && !localLongNamesAreAmbiguous + && zoneInfo.mLocalizeInPicker; String displayName = getZoneDisplayName(locale, tz, now, preferLongName); String gmtOffsetString = getGmtOffsetString(locale, tz, now); @@ -162,8 +164,8 @@ public class ZoneGetter { return TimeZoneNames.getExemplarLocation(locale.toString(), tz.getID()); } - private static List<String> readTimezonesToDisplay(Context context) { - List<String> olsonIds = new ArrayList<String>(); + private static List<ZoneInfo> readTimezonesToDisplay(Context context) { + List<ZoneInfo> olsonIds = new ArrayList<>(); try (XmlResourceParser xrp = context.getResources().getXml(R.xml.timezones)) { while (xrp.next() != XmlResourceParser.START_TAG) { continue; @@ -177,8 +179,10 @@ public class ZoneGetter { xrp.next(); } if (xrp.getName().equals(XMLTAG_TIMEZONE)) { - String olsonId = xrp.getAttributeValue(0); - olsonIds.add(olsonId); + String olsonId = xrp.getAttributeValue(null, XML_ATTR_ID); + boolean localize = xrp.getAttributeBooleanValue(null, + XML_ATTR_LOCALIZE_IN_PICKER, true); + olsonIds.add(new ZoneInfo(olsonId, localize)); } while (xrp.getEventType() != XmlResourceParser.END_TAG) { xrp.next(); @@ -212,4 +216,19 @@ public class ZoneGetter { isRtl ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR); return gmtString; } + + private static class ZoneInfo { + String mOlsonId; + boolean mLocalizeInPicker; + + public ZoneInfo(String olsonId) { + mOlsonId = olsonId; + mLocalizeInPicker = false; + } + + public ZoneInfo(String olsonId, boolean localizeInPicker) { + mOlsonId = olsonId; + mLocalizeInPicker = localizeInPicker; + } + } } |