diff options
author | Michael Chan <mchan@android.com> | 2013-04-11 17:08:11 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-04-11 17:08:11 +0000 |
commit | fa1c198c60768f9beeb5694502b3dcd3b9528e0c (patch) | |
tree | 12a77ac6a745491be20932abbd7c3d844c2f8bac /src/com/android | |
parent | 10084999817064f79d4f79531385088c2b335caf (diff) | |
parent | b506b1dddd4007997bbe6773cb0ebced27ba96df (diff) | |
download | android_frameworks_opt_timezonepicker-fa1c198c60768f9beeb5694502b3dcd3b9528e0c.tar.gz android_frameworks_opt_timezonepicker-fa1c198c60768f9beeb5694502b3dcd3b9528e0c.tar.bz2 android_frameworks_opt_timezonepicker-fa1c198c60768f9beeb5694502b3dcd3b9528e0c.zip |
Merge "Embedded country names in the app for ones not in framework" into jb-mr2-dev
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/timezonepicker/TimeZoneData.java | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/com/android/timezonepicker/TimeZoneData.java b/src/com/android/timezonepicker/TimeZoneData.java index c8e9355..c6eeeaa 100644 --- a/src/com/android/timezonepicker/TimeZoneData.java +++ b/src/com/android/timezonepicker/TimeZoneData.java @@ -394,8 +394,7 @@ public class TimeZoneData { // name String country = mCountryCodeToNameMap.get(countryCode); if (country == null) { - country = new Locale(lang, countryCode) - .getDisplayCountry(Locale.getDefault()); + country = getCountryNames(lang, countryCode); mCountryCodeToNameMap.put(countryCode, country); } @@ -465,6 +464,38 @@ public class TimeZoneData { return processedTimeZones; } + @SuppressWarnings("unused") + private static Locale mBackupCountryLocale; + private static String[] mBackupCountryCodes; + private static String[] mBackupCountryNames; + + private String getCountryNames(String lang, String countryCode) { + final Locale defaultLocale = Locale.getDefault(); + String countryDisplayName = new Locale(lang, countryCode).getDisplayCountry(defaultLocale); + + if (!countryCode.equals(countryDisplayName)) { + return countryDisplayName; + } + + if (mBackupCountryCodes == null || !defaultLocale.equals(mBackupCountryLocale)) { + mBackupCountryLocale = defaultLocale; + mBackupCountryCodes = mContext.getResources().getStringArray( + R.array.backup_country_codes); + mBackupCountryNames = mContext.getResources().getStringArray( + R.array.backup_country_names); + } + + int length = Math.min(mBackupCountryCodes.length, mBackupCountryNames.length); + + for (int i = 0; i < length; i++) { + if (mBackupCountryCodes[i].equals(countryCode)) { + return mBackupCountryNames[i]; + } + } + + return countryCode; + } + private int getIdenticalTimeZoneInTheCountry(TimeZoneInfo timeZoneInfo) { int idx = 0; for (TimeZoneInfo tzi : mTimeZones) { |