OSDN Git Service

Flag all the locales of the default region as suggested
authorMihai Nita <mnita@google.com>
Fri, 5 Feb 2016 22:27:55 +0000 (14:27 -0800)
committerRoozbeh Pournader <roozbeh@google.com>
Thu, 11 Feb 2016 00:34:45 +0000 (00:34 +0000)
This was done by the SetupWizard to suggest the default locale
before the SIM was detected.
It is also handy for devices without SIM (tablets).

Bug: 26784450
Bug: 26882058
Bug: 26939651
Change-Id: Ia1d3b2ef4756121cf6ca13d5d7280215df060a8f

core/java/com/android/internal/app/LocaleStore.java

index 210adce..465c4d8 100644 (file)
@@ -104,6 +104,9 @@ public class LocaleStore {
         }
 
         private boolean isSuggestionOfType(int suggestionMask) {
+            if (!mIsTranslated) { // Never suggest an untranslated locale
+                return false;
+            }
             return (mSuggestionFlags & suggestionMask) == suggestionMask;
         }
 
@@ -207,6 +210,27 @@ public class LocaleStore {
         }
     }
 
+    /*
+     * Show all the languages supported for a country in the suggested list.
+     * This is also handy for devices without SIM (tablets).
+     */
+    private static void addSuggestedLocalesForRegion(Locale locale) {
+        if (locale == null) {
+            return;
+        }
+        final String country = locale.getCountry();
+        if (country.isEmpty()) {
+            return;
+        }
+
+        for (LocaleInfo li : sLocaleCache.values()) {
+            if (country.equals(li.getLocale().getCountry())) {
+                // We don't need to differentiate between manual and SIM suggestions
+                li.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM;
+            }
+        }
+    }
+
     public static void fillCache(Context context) {
         if (sFullyInitialized) {
             return;
@@ -256,6 +280,8 @@ public class LocaleStore {
             li.setTranslated(localizedLocales.contains(li.getLangScriptKey()));
         }
 
+        addSuggestedLocalesForRegion(Locale.getDefault());
+
         sFullyInitialized = true;
     }