Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f59a969a authored by Luis Vidal's avatar Luis Vidal Committed by Roman Birg
Browse files

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
parent 22a2eff7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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>
+32 −13
Original line number Diff line number Diff line
@@ -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;
        }
    }
}