Search in sources :

Example 11 with IllformedLocaleException

use of java.util.IllformedLocaleException in project android_frameworks_base by DirtyUnicorns.

the class LocaleStore method fillCache.

public static void fillCache(Context context) {
    if (sFullyInitialized) {
        return;
    }
    Set<String> simCountries = getSimCountries(context);
    for (String localeId : LocalePicker.getSupportedLocales(context)) {
        if (localeId.isEmpty()) {
            throw new IllformedLocaleException("Bad locale entry in locale_config.xml");
        }
        LocaleInfo li = new LocaleInfo(localeId);
        if (simCountries.contains(li.getLocale().getCountry())) {
            li.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM;
        }
        sLocaleCache.put(li.getId(), li);
        final Locale parent = li.getParent();
        if (parent != null) {
            String parentId = parent.toLanguageTag();
            if (!sLocaleCache.containsKey(parentId)) {
                sLocaleCache.put(parentId, new LocaleInfo(parent));
            }
        }
    }
    boolean isInDeveloperMode = Settings.Global.getInt(context.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
    for (String localeId : LocalePicker.getPseudoLocales()) {
        LocaleInfo li = getLocaleInfo(Locale.forLanguageTag(localeId));
        if (isInDeveloperMode) {
            li.setTranslated(true);
            li.mIsPseudo = true;
            li.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM;
        } else {
            sLocaleCache.remove(li.getId());
        }
    }
    // TODO: See if we can reuse what LocaleList.matchScore does
    final HashSet<String> localizedLocales = new HashSet<>();
    for (String localeId : LocalePicker.getSystemAssetLocales()) {
        LocaleInfo li = new LocaleInfo(localeId);
        final String country = li.getLocale().getCountry();
        // All this is to figure out if we should suggest a country
        if (!country.isEmpty()) {
            LocaleInfo cachedLocale = null;
            if (sLocaleCache.containsKey(li.getId())) {
                // the simple case, e.g. fr-CH
                cachedLocale = sLocaleCache.get(li.getId());
            } else {
                // e.g. zh-TW localized, zh-Hant-TW in cache
                final String langScriptCtry = li.getLangScriptKey() + "-" + country;
                if (sLocaleCache.containsKey(langScriptCtry)) {
                    cachedLocale = sLocaleCache.get(langScriptCtry);
                }
            }
            if (cachedLocale != null) {
                cachedLocale.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_CFG;
            }
        }
        localizedLocales.add(li.getLangScriptKey());
    }
    // Serbian in Latin script is only partially localized in N.
    localizedLocales.remove("sr-Latn");
    for (LocaleInfo li : sLocaleCache.values()) {
        li.setTranslated(localizedLocales.contains(li.getLangScriptKey()));
    }
    addSuggestedLocalesForRegion(Locale.getDefault());
    sFullyInitialized = true;
}
Also used : Locale(java.util.Locale) IllformedLocaleException(java.util.IllformedLocaleException) HashSet(java.util.HashSet)

Example 12 with IllformedLocaleException

use of java.util.IllformedLocaleException in project android_frameworks_base by crdroidandroid.

the class LocaleStore method fillCache.

public static void fillCache(Context context) {
    if (sFullyInitialized) {
        return;
    }
    Set<String> simCountries = getSimCountries(context);
    for (String localeId : LocalePicker.getSupportedLocales(context)) {
        if (localeId.isEmpty()) {
            throw new IllformedLocaleException("Bad locale entry in locale_config.xml");
        }
        LocaleInfo li = new LocaleInfo(localeId);
        if (simCountries.contains(li.getLocale().getCountry())) {
            li.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM;
        }
        sLocaleCache.put(li.getId(), li);
        final Locale parent = li.getParent();
        if (parent != null) {
            String parentId = parent.toLanguageTag();
            if (!sLocaleCache.containsKey(parentId)) {
                sLocaleCache.put(parentId, new LocaleInfo(parent));
            }
        }
    }
    boolean isInDeveloperMode = Settings.Global.getInt(context.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
    for (String localeId : LocalePicker.getPseudoLocales()) {
        LocaleInfo li = getLocaleInfo(Locale.forLanguageTag(localeId));
        if (isInDeveloperMode) {
            li.setTranslated(true);
            li.mIsPseudo = true;
            li.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM;
        } else {
            sLocaleCache.remove(li.getId());
        }
    }
    // TODO: See if we can reuse what LocaleList.matchScore does
    final HashSet<String> localizedLocales = new HashSet<>();
    for (String localeId : LocalePicker.getSystemAssetLocales()) {
        LocaleInfo li = new LocaleInfo(localeId);
        final String country = li.getLocale().getCountry();
        // All this is to figure out if we should suggest a country
        if (!country.isEmpty()) {
            LocaleInfo cachedLocale = null;
            if (sLocaleCache.containsKey(li.getId())) {
                // the simple case, e.g. fr-CH
                cachedLocale = sLocaleCache.get(li.getId());
            } else {
                // e.g. zh-TW localized, zh-Hant-TW in cache
                final String langScriptCtry = li.getLangScriptKey() + "-" + country;
                if (sLocaleCache.containsKey(langScriptCtry)) {
                    cachedLocale = sLocaleCache.get(langScriptCtry);
                }
            }
            if (cachedLocale != null) {
                cachedLocale.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_CFG;
            }
        }
        localizedLocales.add(li.getLangScriptKey());
    }
    // Serbian in Latin script is only partially localized in N.
    localizedLocales.remove("sr-Latn");
    for (LocaleInfo li : sLocaleCache.values()) {
        li.setTranslated(localizedLocales.contains(li.getLangScriptKey()));
    }
    addSuggestedLocalesForRegion(Locale.getDefault());
    sFullyInitialized = true;
}
Also used : Locale(java.util.Locale) IllformedLocaleException(java.util.IllformedLocaleException) HashSet(java.util.HashSet)

Aggregations

IllformedLocaleException (java.util.IllformedLocaleException)12 Locale (java.util.Locale)12 HashSet (java.util.HashSet)5 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Builder (java.util.Locale.Builder)1 TimeZone (java.util.TimeZone)1