Modify PK Settings page to make it more user friendly

PK Settings page:
    - Show current PK layout selected for the current user profile and current IME language instead of a list of IMEs

PK layout mapping page:
    - Show IME name in header only if multiple active IMEs
    - Show the PK layout selection criteria (Automatic v/s User selected)

Bug: 325925410
Bug: 326195401
Test: manual
Change-Id: I93a2e169742a800fa116fa5d55e1a91e5548cebb
This commit is contained in:
Vaibhav Devmurari
2024-02-27 20:35:14 +00:00
parent 8371b4314b
commit 8754f114ac
5 changed files with 85 additions and 38 deletions

View File

@@ -21,6 +21,7 @@ import android.content.Context;
import android.hardware.input.InputDeviceIdentifier;
import android.hardware.input.InputManager;
import android.hardware.input.KeyboardLayout;
import android.hardware.input.KeyboardLayoutSelectionResult;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
@@ -180,7 +181,7 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
mapLanguageWithLayout(info, subtype);
}
}
updatePreferenceLayout(preferenceScreen, info);
updatePreferenceLayout(preferenceScreen, info, infoList.size() > 1);
}
}
@@ -189,14 +190,15 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
KeyboardLayout[] keyboardLayouts =
NewKeyboardSettingsUtils.getKeyboardLayouts(
mIm, mUserId, mInputDeviceIdentifier, info, subtype);
String layout = NewKeyboardSettingsUtils.getKeyboardLayout(
KeyboardLayoutSelectionResult result = NewKeyboardSettingsUtils.getKeyboardLayout(
mIm, mUserId, mInputDeviceIdentifier, info, subtype);
if (layout != null) {
if (result.getLayoutDescriptor() != null) {
for (int i = 0; i < keyboardLayouts.length; i++) {
if (keyboardLayouts[i].getDescriptor().equals(layout)) {
if (keyboardLayouts[i].getDescriptor().equals(result.getLayoutDescriptor())) {
KeyboardInfo keyboardInfo = new KeyboardInfo(
subtypeLabel,
keyboardLayouts[i].getLabel(),
result.getSelectionCriteria(),
info,
subtype);
mKeyboardInfoList.add(keyboardInfo);
@@ -208,18 +210,22 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
KeyboardInfo keyboardInfo = new KeyboardInfo(
subtypeLabel,
mContext.getString(R.string.keyboard_default_layout),
KeyboardLayoutSelectionResult.LAYOUT_SELECTION_CRITERIA_UNSPECIFIED,
info,
subtype);
mKeyboardInfoList.add(keyboardInfo);
}
}
private void updatePreferenceLayout(PreferenceScreen preferenceScreen, InputMethodInfo info) {
private void updatePreferenceLayout(PreferenceScreen preferenceScreen, InputMethodInfo info,
boolean hasMultipleImes) {
if (mKeyboardInfoList.isEmpty()) {
return;
}
PreferenceCategory preferenceCategory = new PreferenceCategory(mContext);
preferenceCategory.setTitle(info.loadLabel(mContext.getPackageManager()));
preferenceCategory.setTitle(hasMultipleImes ? mContext.getString(R.string.ime_label_title,
info.loadLabel(mContext.getPackageManager()))
: mContext.getString(R.string.enabled_locales_keyboard_layout));
preferenceCategory.setKey(info.getPackageName());
preferenceScreen.addPreference(preferenceCategory);
Collections.sort(mKeyboardInfoList, new Comparator<KeyboardInfo>() {
@@ -234,7 +240,7 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
final Preference pref = new Preference(mContext);
pref.setKey(keyboardInfo.getPrefId());
pref.setTitle(keyboardInfo.getSubtypeLabel());
pref.setSummary(keyboardInfo.getLayout());
pref.setSummary(keyboardInfo.getLayoutSummaryText(mContext));
pref.setOnPreferenceClickListener(
preference -> {
showKeyboardLayoutPicker(