From: Elliott Hughes Date: Tue, 9 Sep 2014 21:33:11 +0000 (-0700) Subject: Always use the LocalePicker's preferred locale names. X-Git-Tag: android-x86-6.0-r1~860^2~400^2^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=81395c8f3d908e2f41a147b33ca02fd1963af7ea;p=android-x86%2Fpackages-apps-Settings.git Always use the LocalePicker's preferred locale names. Without this change we have the odd situation where LocalePicker goes out of its way to avoid saying certain things but then -- as long as there's more than one locale for a given language -- Settings would happily report the name we'd been avoiding. (Either because it's too specific or because it's too sensitive.) Also remove the unused bit-rotted duplicate of the blacklist; even if we needed to access that list directly, we should use LocalePicker's copy. Bug: 17150708 Change-Id: I9bfa0bf9a82bebd29ba45f4cbeaabb4e78570779 --- diff --git a/res/values/arrays.xml b/res/values/arrays.xml index e586e29c93..c7c0020a24 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -489,19 +489,6 @@ Proxy Auto-Config - - - zh_CN - zh_TW - - - - 中文 (简体) - 中文 (繁體) - - None diff --git a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java index e1bcac5968..f0f73074de 100644 --- a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java +++ b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java @@ -55,6 +55,7 @@ import android.view.inputmethod.InputMethodSubtype; import android.view.textservice.SpellCheckerInfo; import android.view.textservice.TextServicesManager; +import com.android.internal.app.LocalePicker; import com.android.settings.R; import com.android.settings.Settings.KeyboardLayoutPickerActivity; import com.android.settings.SettingsActivity; @@ -74,6 +75,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.TreeSet; public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment @@ -252,7 +254,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment if (!mShowsOnlyFullImeAndKeyboardList) { if (mLanguagePref != null) { - String localeName = getLocaleName(getResources()); + String localeName = getLocaleName(getActivity()); mLanguagePref.setSummary(localeName); } @@ -326,42 +328,19 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment return super.onPreferenceTreeClick(preferenceScreen, preference); } - private static String getLocaleName(Resources resources) { - Configuration conf = resources.getConfiguration(); - String language = conf.locale.getLanguage(); - String localeName; - // TODO: This is not an accurate way to display the locale, as it is - // just working around the fact that we support limited dialects - // and want to pretend that the language is valid for all locales. - // We need a way to support languages that aren't tied to a particular - // locale instead of hiding the locale qualifier. - if (hasOnlyOneLanguageInstance(language, - Resources.getSystem().getAssets().getLocales())) { - localeName = conf.locale.getDisplayLanguage(conf.locale); - } else { - localeName = conf.locale.getDisplayName(conf.locale); - } - - if (localeName.length() > 1) { - localeName = Character.toUpperCase(localeName.charAt(0)) - + localeName.substring(1); - } - - return localeName; - } - - private static boolean hasOnlyOneLanguageInstance(String languageCode, String[] locales) { - int count = 0; - for (String localeCode : locales) { - if (localeCode.length() > 2 - && localeCode.startsWith(languageCode)) { - count++; - if (count > 1) { - return false; - } + private static String getLocaleName(Context context) { + // We want to show the same string that the LocalePicker used. + // TODO: should this method be in LocalePicker instead? + Locale currentLocale = context.getResources().getConfiguration().locale; + List locales = LocalePicker.getAllAssetLocales(context, true); + for (LocalePicker.LocaleInfo locale : locales) { + if (locale.getLocale().equals(currentLocale)) { + return locale.getLabel(); } } - return count == 1; + // This can't happen as long as the locale was one set by Settings. + // Fall back in case a developer is testing an unsupported locale. + return currentLocale.getDisplayName(currentLocale); } private void saveInputMethodSelectorVisibility(String value) { @@ -664,12 +643,11 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment public List getRawDataToIndex(Context context, boolean enabled) { List indexables = new ArrayList<>(); - final Resources resources = context.getResources(); final String screenTitle = context.getString(R.string.language_keyboard_settings_title); // Locale picker. if (context.getAssets().getLocales().length > 1) { - String localeName = getLocaleName(resources); + String localeName = getLocaleName(context); SearchIndexableRaw indexable = new SearchIndexableRaw(context); indexable.key = KEY_PHONE_LANGUAGE; indexable.title = context.getString(R.string.phone_language);