Skip to content

Commit f59a969

Browse files
greniazromanbb
authored andcommitted
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
1 parent 22a2eff commit f59a969

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

packages/SettingsLib/res/xml/timezones.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<timezone id="Africa/Harare"></timezone>
4848
<timezone id="Asia/Baghdad"></timezone>
4949
<timezone id="Europe/Moscow"></timezone>
50-
<timezone id="Europe/Kiev"></timezone>
50+
<timezone id="Europe/Kiev" localizeInPicker="false"></timezone>
5151
<timezone id="Asia/Kuwait"></timezone>
5252
<timezone id="Africa/Nairobi"></timezone>
5353
<timezone id="Asia/Tehran"></timezone>

packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public class ZoneGetter {
5050
public static final String KEY_DISPLAYNAME = "name"; // value: String
5151
public static final String KEY_GMT = "gmt"; // value: String
5252
public static final String KEY_OFFSET = "offset"; // value: int (Integer)
53-
53+
private static final String XML_ATTR_ID = "id";
54+
private static final String XML_ATTR_LOCALIZE_IN_PICKER = "localizeInPicker";
5455
private ZoneGetter() {}
5556

5657
public static String getTimeZoneOffsetAndName(TimeZone tz, Date now) {
@@ -85,7 +86,7 @@ public static List<Map<String, Object>> getZonesList(Context context) {
8586
// selecting the wrong olson ids.
8687

8788
// Get the list of olson ids to display to the user.
88-
List<String> olsonIdsToDisplay = readTimezonesToDisplay(context);
89+
List<ZoneInfo> olsonIdsToDisplay = readTimezonesToDisplay(context);
8990

9091
// Create a lookup of local zone IDs.
9192
Set<String> localZoneIds = new TreeSet<String>();
@@ -97,9 +98,9 @@ public static List<Map<String, Object>> getZonesList(Context context) {
9798
// be ambiguous.
9899
Set<String> localZoneNames = new TreeSet<String>();
99100
boolean localLongNamesAreAmbiguous = false;
100-
for (String olsonId : olsonIdsToDisplay) {
101-
if (localZoneIds.contains(olsonId)) {
102-
TimeZone tz = TimeZone.getTimeZone(olsonId);
101+
for (ZoneInfo zoneInfo : olsonIdsToDisplay) {
102+
if (localZoneIds.contains(zoneInfo.mOlsonId) && zoneInfo.mLocalizeInPicker) {
103+
TimeZone tz = TimeZone.getTimeZone(zoneInfo.mOlsonId);
103104
String zoneLongName = getZoneLongName(locale, tz, now);
104105
boolean longNameIsUnique = localZoneNames.add(zoneLongName);
105106
if (!longNameIsUnique) {
@@ -111,12 +112,13 @@ public static List<Map<String, Object>> getZonesList(Context context) {
111112

112113
// Generate the list of zone entries to return.
113114
List<Map<String, Object>> zones = new ArrayList<Map<String, Object>>();
114-
for (String olsonId : olsonIdsToDisplay) {
115-
final TimeZone tz = TimeZone.getTimeZone(olsonId);
115+
for (ZoneInfo zoneInfo: olsonIdsToDisplay) {
116+
final TimeZone tz = TimeZone.getTimeZone(zoneInfo.mOlsonId);
116117
// Exemplar location display is the default. The only time we intend to display the long
117118
// name is when the olsonId is local AND long names are not ambiguous.
118-
boolean isLocalZoneId = localZoneIds.contains(olsonId);
119-
boolean preferLongName = isLocalZoneId && !localLongNamesAreAmbiguous;
119+
boolean isLocalZoneId = localZoneIds.contains(zoneInfo.mOlsonId);
120+
boolean preferLongName = isLocalZoneId && !localLongNamesAreAmbiguous
121+
&& zoneInfo.mLocalizeInPicker;
120122
String displayName = getZoneDisplayName(locale, tz, now, preferLongName);
121123

122124
String gmtOffsetString = getGmtOffsetString(locale, tz, now);
@@ -162,8 +164,8 @@ private static String getZoneExemplarLocation(Locale locale, TimeZone tz) {
162164
return TimeZoneNames.getExemplarLocation(locale.toString(), tz.getID());
163165
}
164166

165-
private static List<String> readTimezonesToDisplay(Context context) {
166-
List<String> olsonIds = new ArrayList<String>();
167+
private static List<ZoneInfo> readTimezonesToDisplay(Context context) {
168+
List<ZoneInfo> olsonIds = new ArrayList<>();
167169
try (XmlResourceParser xrp = context.getResources().getXml(R.xml.timezones)) {
168170
while (xrp.next() != XmlResourceParser.START_TAG) {
169171
continue;
@@ -177,8 +179,10 @@ private static List<String> readTimezonesToDisplay(Context context) {
177179
xrp.next();
178180
}
179181
if (xrp.getName().equals(XMLTAG_TIMEZONE)) {
180-
String olsonId = xrp.getAttributeValue(0);
181-
olsonIds.add(olsonId);
182+
String olsonId = xrp.getAttributeValue(null, XML_ATTR_ID);
183+
boolean localize = xrp.getAttributeBooleanValue(null,
184+
XML_ATTR_LOCALIZE_IN_PICKER, true);
185+
olsonIds.add(new ZoneInfo(olsonId, localize));
182186
}
183187
while (xrp.getEventType() != XmlResourceParser.END_TAG) {
184188
xrp.next();
@@ -212,4 +216,19 @@ private static String getGmtOffsetString(Locale locale, TimeZone tz, Date now) {
212216
isRtl ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR);
213217
return gmtString;
214218
}
219+
220+
private static class ZoneInfo {
221+
String mOlsonId;
222+
boolean mLocalizeInPicker;
223+
224+
public ZoneInfo(String olsonId) {
225+
mOlsonId = olsonId;
226+
mLocalizeInPicker = false;
227+
}
228+
229+
public ZoneInfo(String olsonId, boolean localizeInPicker) {
230+
mOlsonId = olsonId;
231+
mLocalizeInPicker = localizeInPicker;
232+
}
233+
}
215234
}

0 commit comments

Comments
 (0)