Show only the language if there's only one locale for the language.
If the system has only one instance of that language, then only show the language without the country name. Bug: 6522572 Change-Id: I1e99182b1c669b200090f6c360bb902376b63ab0
This commit is contained in:
@@ -29,6 +29,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.hardware.input.InputManager;
|
import android.hardware.input.InputManager;
|
||||||
import android.hardware.input.KeyboardLayout;
|
import android.hardware.input.KeyboardLayout;
|
||||||
@@ -229,10 +230,23 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
|||||||
if (!mIsOnlyImeSettings) {
|
if (!mIsOnlyImeSettings) {
|
||||||
if (mLanguagePref != null) {
|
if (mLanguagePref != null) {
|
||||||
Configuration conf = getResources().getConfiguration();
|
Configuration conf = getResources().getConfiguration();
|
||||||
String locale = conf.locale.getDisplayName(conf.locale);
|
String language = conf.locale.getLanguage();
|
||||||
if (locale != null && locale.length() > 1) {
|
String localeString;
|
||||||
locale = Character.toUpperCase(locale.charAt(0)) + locale.substring(1);
|
// TODO: This is not an accurate way to display the locale, as it is
|
||||||
mLanguagePref.setSummary(locale);
|
// 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())) {
|
||||||
|
localeString = conf.locale.getDisplayLanguage(conf.locale);
|
||||||
|
} else {
|
||||||
|
localeString = conf.locale.getDisplayName(conf.locale);
|
||||||
|
}
|
||||||
|
if (localeString.length() > 1) {
|
||||||
|
localeString = Character.toUpperCase(localeString.charAt(0))
|
||||||
|
+ localeString.substring(1);
|
||||||
|
mLanguagePref.setSummary(localeString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,6 +336,20 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
|||||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count == 1;
|
||||||
|
}
|
||||||
|
|
||||||
private void saveInputMethodSelectorVisibility(String value) {
|
private void saveInputMethodSelectorVisibility(String value) {
|
||||||
try {
|
try {
|
||||||
int intValue = Integer.valueOf(value);
|
int intValue = Integer.valueOf(value);
|
||||||
|
Reference in New Issue
Block a user