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
This commit is contained in:
@@ -489,19 +489,6 @@
|
|||||||
<item>Proxy Auto-Config</item>
|
<item>Proxy Auto-Config</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<!-- Locales in this list are displayed with the corresponding
|
|
||||||
name from special_locale_names instead of using the name
|
|
||||||
from Locale.getDisplayName(). -->
|
|
||||||
<string-array translatable="false" name="special_locale_codes">
|
|
||||||
<item>zh_CN</item>
|
|
||||||
<item>zh_TW</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array translatable="false" name="special_locale_names">
|
|
||||||
<item>中文 (简体)</item>
|
|
||||||
<item>中文 (繁體)</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<!-- Authentication Types used in APN editor -->
|
<!-- Authentication Types used in APN editor -->
|
||||||
<string-array name="apn_auth_entries">
|
<string-array name="apn_auth_entries">
|
||||||
<item>None</item>
|
<item>None</item>
|
||||||
|
@@ -55,6 +55,7 @@ import android.view.inputmethod.InputMethodSubtype;
|
|||||||
import android.view.textservice.SpellCheckerInfo;
|
import android.view.textservice.SpellCheckerInfo;
|
||||||
import android.view.textservice.TextServicesManager;
|
import android.view.textservice.TextServicesManager;
|
||||||
|
|
||||||
|
import com.android.internal.app.LocalePicker;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Settings.KeyboardLayoutPickerActivity;
|
import com.android.settings.Settings.KeyboardLayoutPickerActivity;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
@@ -74,6 +75,7 @@ import java.util.Comparator;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||||
@@ -252,7 +254,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
if (!mShowsOnlyFullImeAndKeyboardList) {
|
if (!mShowsOnlyFullImeAndKeyboardList) {
|
||||||
if (mLanguagePref != null) {
|
if (mLanguagePref != null) {
|
||||||
String localeName = getLocaleName(getResources());
|
String localeName = getLocaleName(getActivity());
|
||||||
mLanguagePref.setSummary(localeName);
|
mLanguagePref.setSummary(localeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,42 +328,19 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
|||||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getLocaleName(Resources resources) {
|
private static String getLocaleName(Context context) {
|
||||||
Configuration conf = resources.getConfiguration();
|
// We want to show the same string that the LocalePicker used.
|
||||||
String language = conf.locale.getLanguage();
|
// TODO: should this method be in LocalePicker instead?
|
||||||
String localeName;
|
Locale currentLocale = context.getResources().getConfiguration().locale;
|
||||||
// TODO: This is not an accurate way to display the locale, as it is
|
List<LocalePicker.LocaleInfo> locales = LocalePicker.getAllAssetLocales(context, true);
|
||||||
// just working around the fact that we support limited dialects
|
for (LocalePicker.LocaleInfo locale : locales) {
|
||||||
// and want to pretend that the language is valid for all locales.
|
if (locale.getLocale().equals(currentLocale)) {
|
||||||
// We need a way to support languages that aren't tied to a particular
|
return locale.getLabel();
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// This can't happen as long as the locale was one set by Settings.
|
||||||
return count == 1;
|
// Fall back in case a developer is testing an unsupported locale.
|
||||||
|
return currentLocale.getDisplayName(currentLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveInputMethodSelectorVisibility(String value) {
|
private void saveInputMethodSelectorVisibility(String value) {
|
||||||
@@ -664,12 +643,11 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
|||||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
|
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
|
||||||
List<SearchIndexableRaw> indexables = new ArrayList<>();
|
List<SearchIndexableRaw> indexables = new ArrayList<>();
|
||||||
|
|
||||||
final Resources resources = context.getResources();
|
|
||||||
final String screenTitle = context.getString(R.string.language_keyboard_settings_title);
|
final String screenTitle = context.getString(R.string.language_keyboard_settings_title);
|
||||||
|
|
||||||
// Locale picker.
|
// Locale picker.
|
||||||
if (context.getAssets().getLocales().length > 1) {
|
if (context.getAssets().getLocales().length > 1) {
|
||||||
String localeName = getLocaleName(resources);
|
String localeName = getLocaleName(context);
|
||||||
SearchIndexableRaw indexable = new SearchIndexableRaw(context);
|
SearchIndexableRaw indexable = new SearchIndexableRaw(context);
|
||||||
indexable.key = KEY_PHONE_LANGUAGE;
|
indexable.key = KEY_PHONE_LANGUAGE;
|
||||||
indexable.title = context.getString(R.string.phone_language);
|
indexable.title = context.getString(R.string.phone_language);
|
||||||
|
Reference in New Issue
Block a user