diff options
author | Michael Chan <mchan@android.com> | 2013-04-04 17:32:02 -0700 |
---|---|---|
committer | Michael Chan <mchan@android.com> | 2013-04-05 17:39:06 -0700 |
commit | 1989c63ae3f98b5088e27564cd397ef5e8affaea (patch) | |
tree | 88fcd49f17d596c174c1a1c02cd72c69323938c0 /src/com/android | |
parent | cc955106e2889ec351593b913cb7af4328dca153 (diff) | |
download | android_frameworks_opt_timezonepicker-1989c63ae3f98b5088e27564cd397ef5e8affaea.tar.gz android_frameworks_opt_timezonepicker-1989c63ae3f98b5088e27564cd397ef5e8affaea.tar.bz2 android_frameworks_opt_timezonepicker-1989c63ae3f98b5088e27564cd397ef5e8affaea.zip |
Added code to allow for time zone name substitution in the app.
Disabled search by time zone
Sort by actual offset (respects DST) then country, then name
Dropped TZs without country. They are usually dups and since we don't search by tz name, they are hard to find.
Move Sydney above Hobart, Australia
Moved Adelaide above Broken Hill, Australia
Moved Dawson_Creek above Creston, Canada
Updated string descriptions
Bug: 7157738
Change-Id: I0320a002d5267633fe581dfc8cd636ba6e689bc0
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/timezonepicker/TimeZoneData.java | 89 | ||||
-rw-r--r-- | src/com/android/timezonepicker/TimeZoneFilterTypeAdapter.java | 28 | ||||
-rw-r--r-- | src/com/android/timezonepicker/TimeZoneInfo.java | 15 |
3 files changed, 100 insertions, 32 deletions
diff --git a/src/com/android/timezonepicker/TimeZoneData.java b/src/com/android/timezonepicker/TimeZoneData.java index 115a8b8..a0cfa4b 100644 --- a/src/com/android/timezonepicker/TimeZoneData.java +++ b/src/com/android/timezonepicker/TimeZoneData.java @@ -18,6 +18,7 @@ package com.android.timezonepicker; import android.content.Context; import android.content.res.AssetManager; +import android.content.res.Resources; import android.text.format.DateFormat; import android.text.format.DateUtils; import android.util.Log; @@ -53,8 +54,13 @@ public class TimeZoneData { private TimeZoneInfo mDefaultTimeZoneInfo; private String mAlternateDefaultTimeZoneId; private String mDefaultTimeZoneCountry; + private HashMap<String, TimeZoneInfo> mTimeZonesById; + private boolean[] mHasTimeZonesInHrOffset = new boolean[40]; + SparseArray<ArrayList<Integer>> mTimeZonesByOffsets; + private Context mContext; public TimeZoneData(Context context, String defaultTimeZoneId, long timeMillis) { + mContext = context; is24HourFormat = TimeZoneInfo.is24HourFormat = DateFormat.is24HourFormat(context); mDefaultTimeZoneId = mAlternateDefaultTimeZoneId = defaultTimeZoneId; long now = System.currentTimeMillis(); @@ -65,6 +71,7 @@ public class TimeZoneData { mTimeMillis = timeMillis; } loadTzs(context); + Log.i(TAG, "Time to load time zones (ms): " + (System.currentTimeMillis() - now)); // now = System.currentTimeMillis(); @@ -115,6 +122,16 @@ public class TimeZoneData { continue; } + /* + * Dropping non-GMT tzs without a country code. They are not + * really needed and they are dups but missing proper + * country codes. e.g. WET CET MST7MDT PST8PDT Asia/Khandyga + * Asia/Ust-Nera EST + */ + if (!tzId.startsWith("Etc/GMT")) { + continue; + } + final TimeZone tz = TimeZone.getTimeZone(tzId); if (tz == null) { Log.e(TAG, "Timezone not found: " + tzId); @@ -153,17 +170,54 @@ public class TimeZoneData { // Don't change the order of mTimeZones after this sort Collections.sort(mTimeZones); + // TimeZoneInfo last = null; + // boolean first = true; + // for (TimeZoneInfo tz : mTimeZones) { + // // All + // Log.e("ALL", tz.toString()); + // + // // GMT + // String name = tz.mTz.getDisplayName(); + // if (name.startsWith("GMT") && !tz.mTzId.startsWith("Etc/GMT")) { + // Log.e("GMT", tz.toString()); + // } + // + // // Dups + // if (last != null) { + // if (last.compareTo(tz) == 0) { + // if (first) { + // Log.e("SAME", last.toString()); + // first = false; + // } + // Log.e("SAME", tz.toString()); + // } else { + // first = true; + // } + // } + // last = tz; + // } mTimeZonesByCountry = new LinkedHashMap<String, ArrayList<Integer>>(); mTimeZonesByOffsets = new SparseArray<ArrayList<Integer>>(mHasTimeZonesInHrOffset.length); + mTimeZonesById = new HashMap<String, TimeZoneInfo>(mTimeZones.size()); + for (TimeZoneInfo tz : mTimeZones) { + // ///////////////////// + // Lookup map for id -> tz + mTimeZonesById.put(tz.mTzId, tz); + } + populateDisplayNameOverrides(mContext.getResources()); Date date = new Date(mTimeMillis); Locale defaultLocal = Locale.getDefault(); int idx = 0; for (TimeZoneInfo tz : mTimeZones) { - tz.mDisplayName = tz.mTz.getDisplayName(tz.mTz.inDaylightTime(date), - TimeZone.LONG, defaultLocal); + // ///////////////////// + // Populate display name + if (tz.mDisplayName == null) { + tz.mDisplayName = tz.mTz.getDisplayName(tz.mTz.inDaylightTime(date), + TimeZone.LONG, defaultLocal); + } // ///////////////////// // Grouping tz's by country for search by country @@ -191,8 +245,22 @@ public class TimeZoneData { } } - private boolean[] mHasTimeZonesInHrOffset = new boolean[40]; - SparseArray<ArrayList<Integer>> mTimeZonesByOffsets; + private void populateDisplayNameOverrides(Resources resources) { + String[] ids = resources.getStringArray(R.array.timezone_rename_ids); + String[] labels = resources.getStringArray(R.array.timezone_rename_labels); + + int length = ids.length; + if (ids.length != labels.length) { + Log.e(TAG, "timezone_rename_ids len=" + ids.length + " timezone_rename_labels len=" + + labels.length); + length = Math.min(ids.length, labels.length); + } + + for (int i = 0; i < length; i++) { + TimeZoneInfo tzi = mTimeZonesById.get(ids[i]); + tzi.mDisplayName = labels[i]; + } + } public boolean hasTimeZonesInHrOffset(int offsetHr) { int index = OFFSET_ARRAY_OFFSET + offsetHr; @@ -302,9 +370,20 @@ public class TimeZoneData { continue; } + /* + * Dropping non-GMT tzs without a country code. They are not + * really needed and they are dups but missing proper + * country codes. e.g. WET CET MST7MDT PST8PDT Asia/Khandyga + * Asia/Ust-Nera EST + */ + if (countryCode == null && !timeZoneId.startsWith("Etc/GMT")) { + processedTimeZones.add(timeZoneId); + continue; + } + // Remember the mapping between the country code and display // name - String country = mCountryCodeToNameMap.get(fields[0]); + String country = mCountryCodeToNameMap.get(countryCode); if (country == null) { country = new Locale(lang, countryCode) .getDisplayCountry(Locale.getDefault()); diff --git a/src/com/android/timezonepicker/TimeZoneFilterTypeAdapter.java b/src/com/android/timezonepicker/TimeZoneFilterTypeAdapter.java index b5557cb..0c8d420 100644 --- a/src/com/android/timezonepicker/TimeZoneFilterTypeAdapter.java +++ b/src/com/android/timezonepicker/TimeZoneFilterTypeAdapter.java @@ -266,20 +266,20 @@ public class TimeZoneFilterTypeAdapter extends BaseAdapter implements Filterable // //////////////////////////////////////// // Search by time zone name // //////////////////////////////////////// - first = true; - for (String timeZoneName : mTimeZoneData.mTimeZoneNames) { - // TODO Perf - cache toLowerCase()? - if (timeZoneName.toLowerCase().startsWith(prefixString)) { - FilterTypeResult r; - if (first) { - r = new FilterTypeResult(true, FILTER_TYPE_TIME_ZONE, null, 0); - filtered.add(r); - first = false; - } - r = new FilterTypeResult(false, FILTER_TYPE_TIME_ZONE, timeZoneName, 0); - filtered.add(r); - } - } +// first = true; +// for (String timeZoneName : mTimeZoneData.mTimeZoneNames) { +// // TODO Perf - cache toLowerCase()? +// if (timeZoneName.toLowerCase().startsWith(prefixString)) { +// FilterTypeResult r; +// if (first) { +// r = new FilterTypeResult(true, FILTER_TYPE_TIME_ZONE, null, 0); +// filtered.add(r); +// first = false; +// } +// r = new FilterTypeResult(false, FILTER_TYPE_TIME_ZONE, timeZoneName, 0); +// filtered.add(r); +// } +// } // //////////////////////////////////////// // TODO Search by state diff --git a/src/com/android/timezonepicker/TimeZoneInfo.java b/src/com/android/timezonepicker/TimeZoneInfo.java index 7fdc472..3cc2f92 100644 --- a/src/com/android/timezonepicker/TimeZoneInfo.java +++ b/src/com/android/timezonepicker/TimeZoneInfo.java @@ -308,19 +308,8 @@ public class TimeZoneInfo implements Comparable<TimeZoneInfo> { */ @Override public int compareTo(TimeZoneInfo other) { - - // TODO !!! Should compare the clock time instead of raw offset - - // Higher raw offset comes before i.e. if the offset is bigger, return - // positive number. - if (this.mRawoffset != other.mRawoffset) { - return other.mRawoffset - this.mRawoffset; - } - - // TZ with DST comes first because the offset is bigger during DST - // compared to a tz without DST - if (this.hasDst != other.hasDst) { - return this.hasDst ? -1 : 1; + if (this.getNowOffsetMillis() != other.getNowOffsetMillis()) { + return other.getNowOffsetMillis() - this.getNowOffsetMillis(); } // By country |