Loading src/com/android/settings/datetime/timezone/RegionSearchPicker.java +2 −2 Original line number Diff line number Diff line Loading @@ -71,14 +71,14 @@ public class RegionSearchPicker extends BaseTimeZonePicker { final FilteredCountryTimeZones countryTimeZones = mTimeZoneData.lookupCountryTimeZones( regionId); final Activity activity = getActivity(); if (countryTimeZones == null || countryTimeZones.getTimeZoneIds().isEmpty()) { if (countryTimeZones == null || countryTimeZones.getPreferredTimeZoneIds().isEmpty()) { Log.e(TAG, "Region has no time zones: " + regionId); activity.setResult(Activity.RESULT_CANCELED); activity.finish(); return; } List<String> timeZoneIds = countryTimeZones.getTimeZoneIds(); List<String> timeZoneIds = countryTimeZones.getPreferredTimeZoneIds(); // Choose the time zone associated the region if there is only one time zone in that region if (timeZoneIds.size() == 1) { final Intent resultData = new Intent() Loading src/com/android/settings/datetime/timezone/RegionZonePicker.java +1 −1 Original line number Diff line number Diff line Loading @@ -103,7 +103,7 @@ public class RegionZonePicker extends BaseTimeZoneInfoPicker { // It could be a timely operations if there are many time zones. A region in time zone data // contains a maximum of 29 time zones currently. It may change in the future, but it's // unlikely to be changed drastically. return getRegionTimeZoneInfo(filteredCountryTimeZones.getTimeZoneIds()); return getRegionTimeZoneInfo(filteredCountryTimeZones.getPreferredTimeZoneIds()); } /** Loading src/com/android/settings/datetime/timezone/TimeZoneSettings.java +5 −3 Original line number Diff line number Diff line Loading @@ -214,10 +214,11 @@ public class TimeZoneSettings extends DashboardFragment { mTimeZoneData.lookupCountryTimeZones(regionId); use(RegionZonePreferenceController.class).setTimeZoneInfo(tzInfo); // Only clickable when the region has more than 1 time zones or no time zone is selected. // Only clickable when the region has more than 1 time zones or no time zone is selected. use(RegionZonePreferenceController.class).setClickable(tzInfo == null || (countryTimeZones != null && countryTimeZones.getTimeZoneIds().size() > 1)); (countryTimeZones != null && countryTimeZones.getPreferredTimeZoneIds().size() > 1)); use(TimeZoneInfoPreferenceController.class).setTimeZoneInfo(tzInfo); updatePreferenceStates(); Loading @@ -244,7 +245,8 @@ public class TimeZoneSettings extends DashboardFragment { FilteredCountryTimeZones countryTimeZones = timeZoneData.lookupCountryTimeZones(regionId); if (countryTimeZones == null || !countryTimeZones.getTimeZoneIds().contains(tzId)) { if (countryTimeZones == null || !countryTimeZones.getPreferredTimeZoneIds().contains(tzId)) { Log.e(TAG, "Unknown time zone id is selected: " + tzId); return; } Loading src/com/android/settings/datetime/timezone/model/FilteredCountryTimeZones.java +32 −13 Original line number Diff line number Diff line Loading @@ -16,11 +16,15 @@ package com.android.settings.datetime.timezone.model; import android.util.ArraySet; import com.android.i18n.timezone.CountryTimeZones; import java.time.Instant; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.Set; /** * Wrap {@class CountryTimeZones} to filter time zone that are shown in the picker. Loading @@ -39,31 +43,46 @@ public class FilteredCountryTimeZones { * a timestamp known to be in the recent past is used. This should be updated occasionally but * it doesn't have to be very often. */ private static final long MIN_USE_DATE_OF_TIMEZONE = 1546300800000L; // 1/1/2019 00:00 UTC private static final Instant MIN_USE_DATE_OF_TIMEZONE = Instant.ofEpochMilli(1546300800000L); // 1/1/2019 00:00 UTC private final CountryTimeZones mCountryTimeZones; private final List<String> mTimeZoneIds; private final List<String> mPreferredTimeZoneIds; private final Set<String> mAlternativeTimeZoneIds; public FilteredCountryTimeZones(CountryTimeZones countryTimeZones) { mCountryTimeZones = countryTimeZones; List<String> timeZoneIds = countryTimeZones.getTimeZoneMappings().stream() .filter(timeZoneMapping -> timeZoneMapping.isShownInPicker() && (timeZoneMapping.getNotUsedAfter() == null || timeZoneMapping.getNotUsedAfter() >= MIN_USE_DATE_OF_TIMEZONE)) .map(timeZoneMapping -> timeZoneMapping.getTimeZoneId()) .collect(Collectors.toList()); mTimeZoneIds = Collections.unmodifiableList(timeZoneIds); List<String> timeZoneIds = new ArrayList<>(); Set<String> alternativeTimeZoneIds = new ArraySet<>(); for (CountryTimeZones.TimeZoneMapping timeZoneMapping : countryTimeZones.getTimeZoneMappings()) { if (timeZoneMapping.isShownInPickerAt(MIN_USE_DATE_OF_TIMEZONE)) { String timeZoneId = timeZoneMapping.getTimeZoneId(); timeZoneIds.add(timeZoneId); alternativeTimeZoneIds.addAll(timeZoneMapping.getAlternativeIds()); } } mPreferredTimeZoneIds = Collections.unmodifiableList(timeZoneIds); mAlternativeTimeZoneIds = Collections.unmodifiableSet(alternativeTimeZoneIds); } public List<String> getTimeZoneIds() { return mTimeZoneIds; public List<String> getPreferredTimeZoneIds() { return mPreferredTimeZoneIds; } public CountryTimeZones getCountryTimeZones() { return mCountryTimeZones; } /** * Returns whether {@code timeZoneId} is currently used in the country or is an alternative * name of a currently used time zone. */ public boolean matches(String timeZoneId) { return mPreferredTimeZoneIds.contains(timeZoneId) || mAlternativeTimeZoneIds.contains(timeZoneId); } public String getRegionId() { return TimeZoneData.normalizeRegionId(mCountryTimeZones.getCountryIso()); } Loading src/com/android/settings/datetime/timezone/model/TimeZoneData.java +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ public class TimeZoneData { Set<String> regionIds = new ArraySet<>(); for (CountryTimeZones countryTimeZone : countryTimeZones) { FilteredCountryTimeZones filteredZones = new FilteredCountryTimeZones(countryTimeZone); if (filteredZones.getTimeZoneIds().contains(tzId)) { if (filteredZones.matches(tzId)) { regionIds.add(filteredZones.getRegionId()); } } Loading Loading
src/com/android/settings/datetime/timezone/RegionSearchPicker.java +2 −2 Original line number Diff line number Diff line Loading @@ -71,14 +71,14 @@ public class RegionSearchPicker extends BaseTimeZonePicker { final FilteredCountryTimeZones countryTimeZones = mTimeZoneData.lookupCountryTimeZones( regionId); final Activity activity = getActivity(); if (countryTimeZones == null || countryTimeZones.getTimeZoneIds().isEmpty()) { if (countryTimeZones == null || countryTimeZones.getPreferredTimeZoneIds().isEmpty()) { Log.e(TAG, "Region has no time zones: " + regionId); activity.setResult(Activity.RESULT_CANCELED); activity.finish(); return; } List<String> timeZoneIds = countryTimeZones.getTimeZoneIds(); List<String> timeZoneIds = countryTimeZones.getPreferredTimeZoneIds(); // Choose the time zone associated the region if there is only one time zone in that region if (timeZoneIds.size() == 1) { final Intent resultData = new Intent() Loading
src/com/android/settings/datetime/timezone/RegionZonePicker.java +1 −1 Original line number Diff line number Diff line Loading @@ -103,7 +103,7 @@ public class RegionZonePicker extends BaseTimeZoneInfoPicker { // It could be a timely operations if there are many time zones. A region in time zone data // contains a maximum of 29 time zones currently. It may change in the future, but it's // unlikely to be changed drastically. return getRegionTimeZoneInfo(filteredCountryTimeZones.getTimeZoneIds()); return getRegionTimeZoneInfo(filteredCountryTimeZones.getPreferredTimeZoneIds()); } /** Loading
src/com/android/settings/datetime/timezone/TimeZoneSettings.java +5 −3 Original line number Diff line number Diff line Loading @@ -214,10 +214,11 @@ public class TimeZoneSettings extends DashboardFragment { mTimeZoneData.lookupCountryTimeZones(regionId); use(RegionZonePreferenceController.class).setTimeZoneInfo(tzInfo); // Only clickable when the region has more than 1 time zones or no time zone is selected. // Only clickable when the region has more than 1 time zones or no time zone is selected. use(RegionZonePreferenceController.class).setClickable(tzInfo == null || (countryTimeZones != null && countryTimeZones.getTimeZoneIds().size() > 1)); (countryTimeZones != null && countryTimeZones.getPreferredTimeZoneIds().size() > 1)); use(TimeZoneInfoPreferenceController.class).setTimeZoneInfo(tzInfo); updatePreferenceStates(); Loading @@ -244,7 +245,8 @@ public class TimeZoneSettings extends DashboardFragment { FilteredCountryTimeZones countryTimeZones = timeZoneData.lookupCountryTimeZones(regionId); if (countryTimeZones == null || !countryTimeZones.getTimeZoneIds().contains(tzId)) { if (countryTimeZones == null || !countryTimeZones.getPreferredTimeZoneIds().contains(tzId)) { Log.e(TAG, "Unknown time zone id is selected: " + tzId); return; } Loading
src/com/android/settings/datetime/timezone/model/FilteredCountryTimeZones.java +32 −13 Original line number Diff line number Diff line Loading @@ -16,11 +16,15 @@ package com.android.settings.datetime.timezone.model; import android.util.ArraySet; import com.android.i18n.timezone.CountryTimeZones; import java.time.Instant; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.Set; /** * Wrap {@class CountryTimeZones} to filter time zone that are shown in the picker. Loading @@ -39,31 +43,46 @@ public class FilteredCountryTimeZones { * a timestamp known to be in the recent past is used. This should be updated occasionally but * it doesn't have to be very often. */ private static final long MIN_USE_DATE_OF_TIMEZONE = 1546300800000L; // 1/1/2019 00:00 UTC private static final Instant MIN_USE_DATE_OF_TIMEZONE = Instant.ofEpochMilli(1546300800000L); // 1/1/2019 00:00 UTC private final CountryTimeZones mCountryTimeZones; private final List<String> mTimeZoneIds; private final List<String> mPreferredTimeZoneIds; private final Set<String> mAlternativeTimeZoneIds; public FilteredCountryTimeZones(CountryTimeZones countryTimeZones) { mCountryTimeZones = countryTimeZones; List<String> timeZoneIds = countryTimeZones.getTimeZoneMappings().stream() .filter(timeZoneMapping -> timeZoneMapping.isShownInPicker() && (timeZoneMapping.getNotUsedAfter() == null || timeZoneMapping.getNotUsedAfter() >= MIN_USE_DATE_OF_TIMEZONE)) .map(timeZoneMapping -> timeZoneMapping.getTimeZoneId()) .collect(Collectors.toList()); mTimeZoneIds = Collections.unmodifiableList(timeZoneIds); List<String> timeZoneIds = new ArrayList<>(); Set<String> alternativeTimeZoneIds = new ArraySet<>(); for (CountryTimeZones.TimeZoneMapping timeZoneMapping : countryTimeZones.getTimeZoneMappings()) { if (timeZoneMapping.isShownInPickerAt(MIN_USE_DATE_OF_TIMEZONE)) { String timeZoneId = timeZoneMapping.getTimeZoneId(); timeZoneIds.add(timeZoneId); alternativeTimeZoneIds.addAll(timeZoneMapping.getAlternativeIds()); } } mPreferredTimeZoneIds = Collections.unmodifiableList(timeZoneIds); mAlternativeTimeZoneIds = Collections.unmodifiableSet(alternativeTimeZoneIds); } public List<String> getTimeZoneIds() { return mTimeZoneIds; public List<String> getPreferredTimeZoneIds() { return mPreferredTimeZoneIds; } public CountryTimeZones getCountryTimeZones() { return mCountryTimeZones; } /** * Returns whether {@code timeZoneId} is currently used in the country or is an alternative * name of a currently used time zone. */ public boolean matches(String timeZoneId) { return mPreferredTimeZoneIds.contains(timeZoneId) || mAlternativeTimeZoneIds.contains(timeZoneId); } public String getRegionId() { return TimeZoneData.normalizeRegionId(mCountryTimeZones.getCountryIso()); } Loading
src/com/android/settings/datetime/timezone/model/TimeZoneData.java +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ public class TimeZoneData { Set<String> regionIds = new ArraySet<>(); for (CountryTimeZones countryTimeZone : countryTimeZones) { FilteredCountryTimeZones filteredZones = new FilteredCountryTimeZones(countryTimeZone); if (filteredZones.getTimeZoneIds().contains(tzId)) { if (filteredZones.matches(tzId)) { regionIds.add(filteredZones.getRegionId()); } } Loading