The PK settings UI should show subtype labels instead of the subtype's language names.
1. Use InputMethodSubtype#getDisplayName() 2. Sorting by label Video: https://screencast.googleplex.com/cast/NjEzMjM3OTI0OTgwMzI2NHxiODBhNjQzZi1kZA Bug: 271504879 Test: manual Change-Id: Ia2be6f3a007c678e62bdda21fe20d95a2b304d70
This commit is contained in:
@@ -37,10 +37,10 @@ import com.android.settings.core.SubSettingLauncher;
|
|||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.inputmethod.NewKeyboardSettingsUtils.KeyboardInfo;
|
import com.android.settings.inputmethod.NewKeyboardSettingsUtils.KeyboardInfo;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
||||||
implements InputManager.InputDeviceListener {
|
implements InputManager.InputDeviceListener {
|
||||||
@@ -53,7 +53,7 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
|||||||
private int mUserId;
|
private int mUserId;
|
||||||
private int mInputDeviceId;
|
private int mInputDeviceId;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Map<String, KeyboardInfo> mKeyboardLanguageLayouts = new HashMap<>();
|
private ArrayList<KeyboardInfo> mKeyboardInfoList = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(final Bundle icicle) {
|
public void onActivityCreated(final Bundle icicle) {
|
||||||
@@ -74,8 +74,16 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
|||||||
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||||
preferenceScreen.removeAll();
|
preferenceScreen.removeAll();
|
||||||
List<InputMethodInfo> infoList = mImm.getEnabledInputMethodListAsUser(mUserId);
|
List<InputMethodInfo> infoList = mImm.getEnabledInputMethodListAsUser(mUserId);
|
||||||
|
Collections.sort(infoList, new Comparator<InputMethodInfo>() {
|
||||||
|
public int compare(InputMethodInfo o1, InputMethodInfo o2) {
|
||||||
|
String s1 = o1.loadLabel(mContext.getPackageManager()).toString();
|
||||||
|
String s2 = o2.loadLabel(mContext.getPackageManager()).toString();
|
||||||
|
return s1.compareTo(s2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
for (InputMethodInfo info : infoList) {
|
for (InputMethodInfo info : infoList) {
|
||||||
mKeyboardLanguageLayouts.clear();
|
mKeyboardInfoList.clear();
|
||||||
List<InputMethodSubtype> subtypes =
|
List<InputMethodSubtype> subtypes =
|
||||||
mImm.getEnabledInputMethodSubtypeList(info, true);
|
mImm.getEnabledInputMethodSubtypeList(info, true);
|
||||||
for (InputMethodSubtype subtype : subtypes) {
|
for (InputMethodSubtype subtype : subtypes) {
|
||||||
@@ -88,51 +96,58 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void mapLanguageWithLayout(InputMethodInfo info, InputMethodSubtype subtype) {
|
private void mapLanguageWithLayout(InputMethodInfo info, InputMethodSubtype subtype) {
|
||||||
|
CharSequence subtypeLabel = getSubtypeLabel(mContext, info, subtype);
|
||||||
KeyboardLayout[] keyboardLayouts = getKeyboardLayouts(info, subtype);
|
KeyboardLayout[] keyboardLayouts = getKeyboardLayouts(info, subtype);
|
||||||
String layout = getKeyboardLayout(info, subtype);
|
String layout = getKeyboardLayout(info, subtype);
|
||||||
String language = getLanguage(info, subtype);
|
|
||||||
if (layout != null) {
|
if (layout != null) {
|
||||||
for (int i = 0; i < keyboardLayouts.length; i++) {
|
for (int i = 0; i < keyboardLayouts.length; i++) {
|
||||||
if (keyboardLayouts[i].getDescriptor().equals(layout)) {
|
if (keyboardLayouts[i].getDescriptor().equals(layout)) {
|
||||||
KeyboardInfo keyboardInfo = new KeyboardInfo(
|
KeyboardInfo keyboardInfo = new KeyboardInfo(
|
||||||
language,
|
subtypeLabel,
|
||||||
keyboardLayouts[i].getLabel(),
|
keyboardLayouts[i].getLabel(),
|
||||||
info,
|
info,
|
||||||
subtype);
|
subtype);
|
||||||
mKeyboardLanguageLayouts.put(subtype.getLanguageTag(), keyboardInfo);
|
mKeyboardInfoList.add(keyboardInfo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if there is no auto-selected layout, we should show "Default"
|
// if there is no auto-selected layout, we should show "Default"
|
||||||
KeyboardInfo keyboardInfo = new KeyboardInfo(
|
KeyboardInfo keyboardInfo = new KeyboardInfo(
|
||||||
language,
|
subtypeLabel,
|
||||||
mContext.getString(R.string.keyboard_default_layout),
|
mContext.getString(R.string.keyboard_default_layout),
|
||||||
info,
|
info,
|
||||||
subtype);
|
subtype);
|
||||||
mKeyboardLanguageLayouts.put(subtype.getLanguageTag(), keyboardInfo);
|
mKeyboardInfoList.add(keyboardInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePreferenceLayout(PreferenceScreen preferenceScreen, InputMethodInfo info) {
|
private void updatePreferenceLayout(PreferenceScreen preferenceScreen, InputMethodInfo info) {
|
||||||
if (mKeyboardLanguageLayouts.isEmpty()) {
|
if (mKeyboardInfoList.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PreferenceCategory preferenceCategory = new PreferenceCategory(mContext);
|
PreferenceCategory preferenceCategory = new PreferenceCategory(mContext);
|
||||||
preferenceCategory.setTitle(info.loadLabel(mContext.getPackageManager()).toString());
|
preferenceCategory.setTitle(info.loadLabel(mContext.getPackageManager()));
|
||||||
preferenceCategory.setKey(info.getPackageName());
|
preferenceCategory.setKey(info.getPackageName());
|
||||||
preferenceScreen.addPreference(preferenceCategory);
|
preferenceScreen.addPreference(preferenceCategory);
|
||||||
for (Map.Entry<String, KeyboardInfo> entry : mKeyboardLanguageLayouts.entrySet()) {
|
Collections.sort(mKeyboardInfoList, new Comparator<KeyboardInfo>() {
|
||||||
|
public int compare(KeyboardInfo o1, KeyboardInfo o2) {
|
||||||
|
String s1 = o1.getSubtypeLabel().toString();
|
||||||
|
String s2 = o2.getSubtypeLabel().toString();
|
||||||
|
return s1.compareTo(s2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (KeyboardInfo keyboardInfo : mKeyboardInfoList) {
|
||||||
final Preference pref = new Preference(mContext);
|
final Preference pref = new Preference(mContext);
|
||||||
String key = "keyboard_language_" + entry.getKey();
|
pref.setKey(keyboardInfo.getPrefId());
|
||||||
NewKeyboardSettingsUtils.KeyboardInfo keyboardInfo = entry.getValue();
|
pref.setTitle(keyboardInfo.getSubtypeLabel());
|
||||||
pref.setKey(key);
|
|
||||||
pref.setTitle(keyboardInfo.getLanguage());
|
|
||||||
pref.setSummary(keyboardInfo.getLayout());
|
pref.setSummary(keyboardInfo.getLayout());
|
||||||
pref.setOnPreferenceClickListener(
|
pref.setOnPreferenceClickListener(
|
||||||
preference -> {
|
preference -> {
|
||||||
showKeyboardLayoutPicker(
|
showKeyboardLayoutPicker(
|
||||||
keyboardInfo.getLanguage(),
|
keyboardInfo.getSubtypeLabel(),
|
||||||
keyboardInfo.getLayout(),
|
keyboardInfo.getLayout(),
|
||||||
mInputDeviceIdentifier,
|
mInputDeviceIdentifier,
|
||||||
mUserId,
|
mUserId,
|
||||||
@@ -215,7 +230,7 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showKeyboardLayoutPicker(
|
private void showKeyboardLayoutPicker(
|
||||||
String language,
|
CharSequence subtypeLabel,
|
||||||
String layout,
|
String layout,
|
||||||
InputDeviceIdentifier inputDeviceIdentifier,
|
InputDeviceIdentifier inputDeviceIdentifier,
|
||||||
int userId,
|
int userId,
|
||||||
@@ -229,7 +244,7 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
|||||||
arguments.putParcelable(
|
arguments.putParcelable(
|
||||||
NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_SUBTYPE, inputMethodSubtype);
|
NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_SUBTYPE, inputMethodSubtype);
|
||||||
arguments.putInt(NewKeyboardSettingsUtils.EXTRA_USER_ID, userId);
|
arguments.putInt(NewKeyboardSettingsUtils.EXTRA_USER_ID, userId);
|
||||||
arguments.putString(NewKeyboardSettingsUtils.EXTRA_TITLE, language);
|
arguments.putCharSequence(NewKeyboardSettingsUtils.EXTRA_TITLE, subtypeLabel);
|
||||||
arguments.putString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_LAYOUT, layout);
|
arguments.putString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_LAYOUT, layout);
|
||||||
new SubSettingLauncher(mContext)
|
new SubSettingLauncher(mContext)
|
||||||
.setSourceMetricsCategory(getMetricsCategory())
|
.setSourceMetricsCategory(getMetricsCategory())
|
||||||
@@ -248,16 +263,9 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
|||||||
mInputDeviceIdentifier, mUserId, info, subtype);
|
mInputDeviceIdentifier, mUserId, info, subtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLanguage(InputMethodInfo info, InputMethodSubtype subtype) {
|
private CharSequence getSubtypeLabel(
|
||||||
String language;
|
Context context, InputMethodInfo info, InputMethodSubtype subtype) {
|
||||||
if (subtype.getLanguageTag().isEmpty()) {
|
return subtype.getDisplayName(
|
||||||
language = subtype.getDisplayName(
|
context, info.getPackageName(), info.getServiceInfo().applicationInfo);
|
||||||
mContext,
|
|
||||||
info.getPackageName(),
|
|
||||||
info.getServiceInfo().applicationInfo).toString();
|
|
||||||
} else {
|
|
||||||
language = Locale.forLanguageTag(subtype.getLanguageTag()).getDisplayName();
|
|
||||||
}
|
|
||||||
return language;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,7 @@ public class NewKeyboardLayoutPickerContent extends DashboardFragment {
|
|||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
InputManager inputManager = getContext().getSystemService(InputManager.class);
|
InputManager inputManager = getContext().getSystemService(InputManager.class);
|
||||||
Bundle arguments = getArguments();
|
Bundle arguments = getArguments();
|
||||||
final String title = arguments.getString(NewKeyboardSettingsUtils.EXTRA_TITLE);
|
final CharSequence title = arguments.getCharSequence(NewKeyboardSettingsUtils.EXTRA_TITLE);
|
||||||
final String layout = arguments.getString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_LAYOUT);
|
final String layout = arguments.getString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_LAYOUT);
|
||||||
final int userId = arguments.getInt(NewKeyboardSettingsUtils.EXTRA_USER_ID);
|
final int userId = arguments.getInt(NewKeyboardSettingsUtils.EXTRA_USER_ID);
|
||||||
final InputDeviceIdentifier identifier =
|
final InputDeviceIdentifier identifier =
|
||||||
|
@@ -72,24 +72,28 @@ public class NewKeyboardSettingsUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class KeyboardInfo {
|
static class KeyboardInfo {
|
||||||
String mLanguage;
|
CharSequence mSubtypeLabel;
|
||||||
String mLayout;
|
String mLayout;
|
||||||
InputMethodInfo mInputMethodInfo;
|
InputMethodInfo mInputMethodInfo;
|
||||||
InputMethodSubtype mInputMethodSubtype;
|
InputMethodSubtype mInputMethodSubtype;
|
||||||
|
|
||||||
KeyboardInfo(
|
KeyboardInfo(
|
||||||
String language,
|
CharSequence subtypeLabel,
|
||||||
String layout,
|
String layout,
|
||||||
InputMethodInfo inputMethodInfo,
|
InputMethodInfo inputMethodInfo,
|
||||||
InputMethodSubtype inputMethodSubtype) {
|
InputMethodSubtype inputMethodSubtype) {
|
||||||
mLanguage = language;
|
mSubtypeLabel = subtypeLabel;
|
||||||
mLayout = layout;
|
mLayout = layout;
|
||||||
mInputMethodInfo = inputMethodInfo;
|
mInputMethodInfo = inputMethodInfo;
|
||||||
mInputMethodSubtype = inputMethodSubtype;
|
mInputMethodSubtype = inputMethodSubtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLanguage() {
|
String getPrefId() {
|
||||||
return mLanguage;
|
return mInputMethodInfo.getId() + "_" + mInputMethodSubtype.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
CharSequence getSubtypeLabel() {
|
||||||
|
return mSubtypeLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLayout() {
|
String getLayout() {
|
||||||
|
Reference in New Issue
Block a user