Merge \\\"Fix sentence capitalization of locale names.\\\" into nyc-dev am: 294b1586ed
am: 2d1d002eea
am: effed5adc0
Change-Id: I712cd50fe4e47120477edaa85696a1fa4cce9627
This commit is contained in:
@@ -758,22 +758,10 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
|||||||
final int inputMethodCount = (inputMethods == null ? 0 : inputMethods.size());
|
final int inputMethodCount = (inputMethods == null ? 0 : inputMethods.size());
|
||||||
for (int i = 0; i < inputMethodCount; ++i) {
|
for (int i = 0; i < inputMethodCount; ++i) {
|
||||||
InputMethodInfo inputMethod = inputMethods.get(i);
|
InputMethodInfo inputMethod = inputMethods.get(i);
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
List<InputMethodSubtype> subtypes = inputMethodManager
|
List<InputMethodSubtype> subtypes = inputMethodManager
|
||||||
.getEnabledInputMethodSubtypeList(inputMethod, true);
|
.getEnabledInputMethodSubtypeList(inputMethod, true);
|
||||||
final int subtypeCount = subtypes.size();
|
String summary = InputMethodAndSubtypeUtil.getSubtypeLocaleNameListAsSentence(
|
||||||
for (int j = 0; j < subtypeCount; j++) {
|
subtypes, context, inputMethod);
|
||||||
InputMethodSubtype subtype = subtypes.get(j);
|
|
||||||
if (builder.length() > 0) {
|
|
||||||
builder.append(',');
|
|
||||||
}
|
|
||||||
CharSequence subtypeLabel = subtype.getDisplayName(context,
|
|
||||||
inputMethod.getPackageName(), inputMethod.getServiceInfo()
|
|
||||||
.applicationInfo);
|
|
||||||
builder.append(subtypeLabel);
|
|
||||||
}
|
|
||||||
String summary = builder.toString();
|
|
||||||
|
|
||||||
ServiceInfo serviceInfo = inputMethod.getServiceInfo();
|
ServiceInfo serviceInfo = inputMethod.getServiceInfo();
|
||||||
ComponentName componentName = new ComponentName(serviceInfo.packageName,
|
ComponentName componentName = new ComponentName(serviceInfo.packageName,
|
||||||
|
@@ -189,8 +189,8 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment
|
|||||||
final InputMethodSubtype subtype = imi.getSubtypeAt(index);
|
final InputMethodSubtype subtype = imi.getSubtypeAt(index);
|
||||||
if (subtype.overridesImplicitlyEnabledSubtype()) {
|
if (subtype.overridesImplicitlyEnabledSubtype()) {
|
||||||
if (autoSubtypeLabel == null) {
|
if (autoSubtypeLabel == null) {
|
||||||
autoSubtypeLabel = subtype.getDisplayName(
|
autoSubtypeLabel = InputMethodAndSubtypeUtil.getSubtypeLocaleNameAsSentence(
|
||||||
context, imi.getPackageName(), imi.getServiceInfo().applicationInfo);
|
subtype, context, imi);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final Preference subtypePref = new InputMethodSubtypePreference(
|
final Preference subtypePref = new InputMethodSubtypePreference(
|
||||||
|
@@ -16,8 +16,13 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.icu.text.ListFormatter;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.SettingNotFoundException;
|
import android.provider.Settings.SettingNotFoundException;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
@@ -28,12 +33,14 @@ import android.util.Log;
|
|||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
|
import com.android.internal.app.LocaleHelper;
|
||||||
import com.android.internal.inputmethod.InputMethodUtils;
|
import com.android.internal.inputmethod.InputMethodUtils;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
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.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
// TODO: Consolidate this with {@link InputMethodSettingValuesWrapper}.
|
// TODO: Consolidate this with {@link InputMethodSettingValuesWrapper}.
|
||||||
@@ -370,4 +377,55 @@ class InputMethodAndSubtypeUtil {
|
|||||||
prefs.edit().remove(key).apply();
|
prefs.edit().remove(key).apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
static String getSubtypeLocaleNameAsSentence(@Nullable InputMethodSubtype subtype,
|
||||||
|
@NonNull final Context context, @NonNull final InputMethodInfo inputMethodInfo) {
|
||||||
|
if (subtype == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
final Locale locale = getDisplayLocale(context);
|
||||||
|
final CharSequence subtypeName = subtype.getDisplayName(context,
|
||||||
|
inputMethodInfo.getPackageName(), inputMethodInfo.getServiceInfo()
|
||||||
|
.applicationInfo);
|
||||||
|
return LocaleHelper.toSentenceCase(subtypeName.toString(), locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
static String getSubtypeLocaleNameListAsSentence(
|
||||||
|
@NonNull final List<InputMethodSubtype> subtypes, @NonNull final Context context,
|
||||||
|
@NonNull final InputMethodInfo inputMethodInfo) {
|
||||||
|
if (subtypes.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
final Locale locale = getDisplayLocale(context);
|
||||||
|
final int subtypeCount = subtypes.size();
|
||||||
|
final CharSequence[] subtypeNames = new CharSequence[subtypeCount];
|
||||||
|
for (int i = 0; i < subtypeCount; i++) {
|
||||||
|
subtypeNames[i] = subtypes.get(i).getDisplayName(context,
|
||||||
|
inputMethodInfo.getPackageName(), inputMethodInfo.getServiceInfo()
|
||||||
|
.applicationInfo);
|
||||||
|
}
|
||||||
|
return LocaleHelper.toSentenceCase(
|
||||||
|
ListFormatter.getInstance(locale).format(subtypeNames), locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private static Locale getDisplayLocale(@Nullable final Context context) {
|
||||||
|
if (context == null) {
|
||||||
|
return Locale.getDefault();
|
||||||
|
}
|
||||||
|
if (context.getResources() == null) {
|
||||||
|
return Locale.getDefault();
|
||||||
|
}
|
||||||
|
final Configuration configuration = context.getResources().getConfiguration();
|
||||||
|
if (configuration == null) {
|
||||||
|
return Locale.getDefault();
|
||||||
|
}
|
||||||
|
final Locale configurationLocale = configuration.getLocales().get(0);
|
||||||
|
if (configurationLocale == null) {
|
||||||
|
return Locale.getDefault();
|
||||||
|
}
|
||||||
|
return configurationLocale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,6 @@ import com.android.settingslib.RestrictedLockUtils;
|
|||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
@@ -213,17 +212,10 @@ class InputMethodPreference extends RestrictedSwitchPreference implements OnPref
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getSummaryString() {
|
private String getSummaryString() {
|
||||||
final Context context = getContext();
|
|
||||||
final InputMethodManager imm = getInputMethodManager();
|
final InputMethodManager imm = getInputMethodManager();
|
||||||
final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(mImi, true);
|
final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(mImi, true);
|
||||||
final ArrayList<CharSequence> subtypeLabels = new ArrayList<>();
|
return InputMethodAndSubtypeUtil.getSubtypeLocaleNameListAsSentence(
|
||||||
for (final InputMethodSubtype subtype : subtypes) {
|
subtypes, getContext(), mImi);
|
||||||
final CharSequence label = subtype.getDisplayName(
|
|
||||||
context, mImi.getPackageName(), mImi.getServiceInfo().applicationInfo);
|
|
||||||
subtypeLabels.add(label);
|
|
||||||
}
|
|
||||||
// TODO: A delimiter of subtype labels should be localized.
|
|
||||||
return TextUtils.join(", ", subtypeLabels);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSecurityWarnDialog(final InputMethodInfo imi) {
|
private void showSecurityWarnDialog(final InputMethodInfo imi) {
|
||||||
|
@@ -41,8 +41,8 @@ class InputMethodSubtypePreference extends SwitchWithNoTextPreference {
|
|||||||
super(context);
|
super(context);
|
||||||
setPersistent(false);
|
setPersistent(false);
|
||||||
setKey(imi.getId() + subtype.hashCode());
|
setKey(imi.getId() + subtype.hashCode());
|
||||||
final CharSequence subtypeLabel = subtype.getDisplayName(context,
|
final CharSequence subtypeLabel =
|
||||||
imi.getPackageName(), imi.getServiceInfo().applicationInfo);
|
InputMethodAndSubtypeUtil.getSubtypeLocaleNameAsSentence(subtype, context, imi);
|
||||||
setTitle(subtypeLabel);
|
setTitle(subtypeLabel);
|
||||||
final String subtypeLocaleString = subtype.getLocale();
|
final String subtypeLocaleString = subtype.getLocale();
|
||||||
if (TextUtils.isEmpty(subtypeLocaleString)) {
|
if (TextUtils.isEmpty(subtypeLocaleString)) {
|
||||||
|
@@ -496,8 +496,8 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
|||||||
@NonNull Context context, @NonNull InputMethodInfo imi,
|
@NonNull Context context, @NonNull InputMethodInfo imi,
|
||||||
@Nullable InputMethodSubtype imSubtype) {
|
@Nullable InputMethodSubtype imSubtype) {
|
||||||
if (imSubtype != null) {
|
if (imSubtype != null) {
|
||||||
return imSubtype.getDisplayName(
|
return InputMethodAndSubtypeUtil.getSubtypeLocaleNameAsSentence(
|
||||||
context, imi.getPackageName(), imi.getServiceInfo().applicationInfo);
|
imSubtype, context, imi);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user