Merge "[Fixed] UI issues after rotation" into udc-dev am: 28aa2964fb
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23109896 Change-Id: Icbc09be2306b0a5a6bcc2d55aa7777acd1d8cfb9 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -169,9 +169,11 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
||||
|
||||
private void mapLanguageWithLayout(InputMethodInfo info, InputMethodSubtype subtype) {
|
||||
CharSequence subtypeLabel = getSubtypeLabel(mContext, info, subtype);
|
||||
KeyboardLayout[] keyboardLayouts = getKeyboardLayouts(info, subtype);
|
||||
String layout = getKeyboardLayout(info, subtype);
|
||||
|
||||
KeyboardLayout[] keyboardLayouts =
|
||||
NewKeyboardSettingsUtils.getKeyboardLayouts(
|
||||
mIm, mUserId, mInputDeviceIdentifier, info, subtype);
|
||||
String layout = NewKeyboardSettingsUtils.getKeyboardLayout(
|
||||
mIm, mUserId, mInputDeviceIdentifier, info, subtype);
|
||||
if (layout != null) {
|
||||
for (int i = 0; i < keyboardLayouts.length; i++) {
|
||||
if (keyboardLayouts[i].getDescriptor().equals(layout)) {
|
||||
@@ -220,7 +222,6 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
||||
preference -> {
|
||||
showKeyboardLayoutPicker(
|
||||
keyboardInfo.getSubtypeLabel(),
|
||||
keyboardInfo.getLayout(),
|
||||
mInputDeviceIdentifier,
|
||||
mUserId,
|
||||
keyboardInfo.getInputMethodInfo(),
|
||||
@@ -267,7 +268,6 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
||||
|
||||
private void showKeyboardLayoutPicker(
|
||||
CharSequence subtypeLabel,
|
||||
String layout,
|
||||
InputDeviceIdentifier inputDeviceIdentifier,
|
||||
int userId,
|
||||
InputMethodInfo inputMethodInfo,
|
||||
@@ -281,7 +281,6 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
||||
NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_SUBTYPE, inputMethodSubtype);
|
||||
arguments.putInt(NewKeyboardSettingsUtils.EXTRA_USER_ID, userId);
|
||||
arguments.putCharSequence(NewKeyboardSettingsUtils.EXTRA_TITLE, subtypeLabel);
|
||||
arguments.putString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_LAYOUT, layout);
|
||||
new SubSettingLauncher(mContext)
|
||||
.setSourceMetricsCategory(getMetricsCategory())
|
||||
.setDestination(NewKeyboardLayoutPickerFragment.class.getName())
|
||||
@@ -289,16 +288,6 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment
|
||||
.launch();
|
||||
}
|
||||
|
||||
private KeyboardLayout[] getKeyboardLayouts(InputMethodInfo info, InputMethodSubtype subtype) {
|
||||
return mIm.getKeyboardLayoutListForInputDevice(
|
||||
mInputDeviceIdentifier, mUserId, info, subtype);
|
||||
}
|
||||
|
||||
private String getKeyboardLayout(InputMethodInfo info, InputMethodSubtype subtype) {
|
||||
return mIm.getKeyboardLayoutForInputDevice(
|
||||
mInputDeviceIdentifier, mUserId, info, subtype);
|
||||
}
|
||||
|
||||
private CharSequence getSubtypeLabel(
|
||||
Context context, InputMethodInfo info, InputMethodSubtype subtype) {
|
||||
return subtype.getDisplayName(
|
||||
|
@@ -20,6 +20,7 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.hardware.input.InputDeviceIdentifier;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.hardware.input.KeyboardLayout;
|
||||
import android.os.Bundle;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
@@ -31,28 +32,50 @@ public class NewKeyboardLayoutPickerContent extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "KeyboardLayoutPicker";
|
||||
|
||||
private InputManager mIm;
|
||||
private int mUserId;
|
||||
private InputDeviceIdentifier mIdentifier;
|
||||
private InputMethodInfo mInputMethodInfo;
|
||||
private InputMethodSubtype mInputMethodSubtype;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
InputManager inputManager = getContext().getSystemService(InputManager.class);
|
||||
mIm = getContext().getSystemService(InputManager.class);
|
||||
Bundle arguments = getArguments();
|
||||
final CharSequence title = arguments.getCharSequence(NewKeyboardSettingsUtils.EXTRA_TITLE);
|
||||
final String layout = arguments.getString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_LAYOUT);
|
||||
final int userId = arguments.getInt(NewKeyboardSettingsUtils.EXTRA_USER_ID);
|
||||
final InputDeviceIdentifier identifier =
|
||||
mUserId = arguments.getInt(NewKeyboardSettingsUtils.EXTRA_USER_ID);
|
||||
mIdentifier =
|
||||
arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER);
|
||||
final InputMethodInfo inputMethodInfo =
|
||||
mInputMethodInfo =
|
||||
arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_INFO);
|
||||
final InputMethodSubtype inputMethodSubtype =
|
||||
mInputMethodSubtype =
|
||||
arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_SUBTYPE);
|
||||
if (identifier == null
|
||||
|| NewKeyboardSettingsUtils.getInputDevice(inputManager, identifier) == null) {
|
||||
if (mIdentifier == null
|
||||
|| NewKeyboardSettingsUtils.getInputDevice(mIm, mIdentifier) == null) {
|
||||
getActivity().finish();
|
||||
return;
|
||||
}
|
||||
getActivity().setTitle(title);
|
||||
use(NewKeyboardLayoutPickerController.class).initialize(this /*parent*/, userId,
|
||||
identifier, inputMethodInfo, inputMethodSubtype, layout);
|
||||
use(NewKeyboardLayoutPickerController.class).initialize(this /*parent*/, mUserId,
|
||||
mIdentifier, mInputMethodInfo, mInputMethodSubtype, getSelectedLayoutLabel());
|
||||
}
|
||||
|
||||
private String getSelectedLayoutLabel() {
|
||||
String label = getContext().getString(R.string.keyboard_default_layout);
|
||||
String layout = NewKeyboardSettingsUtils.getKeyboardLayout(
|
||||
mIm, mUserId, mIdentifier, mInputMethodInfo, mInputMethodSubtype);
|
||||
KeyboardLayout[] keyboardLayouts = NewKeyboardSettingsUtils.getKeyboardLayouts(
|
||||
mIm, mUserId, mIdentifier, mInputMethodInfo, mInputMethodSubtype);
|
||||
if (layout != null) {
|
||||
for (int i = 0; i < keyboardLayouts.length; i++) {
|
||||
if (keyboardLayouts[i].getDescriptor().equals(layout)) {
|
||||
label = keyboardLayouts[i].getLabel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.inputmethod;
|
||||
import android.content.Context;
|
||||
import android.hardware.input.InputDeviceIdentifier;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.hardware.input.KeyboardLayout;
|
||||
import android.view.InputDevice;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
@@ -39,7 +40,6 @@ public class NewKeyboardSettingsUtils {
|
||||
"com.android.settings.inputmethod.EXTRA_INTENT_FROM";
|
||||
|
||||
static final String EXTRA_TITLE = "keyboard_layout_picker_title";
|
||||
static final String EXTRA_KEYBOARD_LAYOUT = "keyboard_layout";
|
||||
static final String EXTRA_USER_ID = "user_id";
|
||||
static final String EXTRA_INPUT_DEVICE_IDENTIFIER = "input_device_identifier";
|
||||
static final String EXTRA_INPUT_METHOD_INFO = "input_method_info";
|
||||
@@ -117,4 +117,14 @@ public class NewKeyboardSettingsUtils {
|
||||
static InputDevice getInputDevice(InputManager im, InputDeviceIdentifier identifier) {
|
||||
return im.getInputDeviceByDescriptor(identifier.getDescriptor());
|
||||
}
|
||||
|
||||
static KeyboardLayout[] getKeyboardLayouts(InputManager inputManager, int userId,
|
||||
InputDeviceIdentifier identifier, InputMethodInfo info, InputMethodSubtype subtype) {
|
||||
return inputManager.getKeyboardLayoutListForInputDevice(identifier, userId, info, subtype);
|
||||
}
|
||||
|
||||
static String getKeyboardLayout(InputManager inputManager, int userId,
|
||||
InputDeviceIdentifier identifier, InputMethodInfo info, InputMethodSubtype subtype) {
|
||||
return inputManager.getKeyboardLayoutForInputDevice(identifier, userId, info, subtype);
|
||||
}
|
||||
}
|
||||
|
@@ -67,12 +67,14 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
||||
private static final String SHOW_VIRTUAL_KEYBOARD_SWITCH = "show_virtual_keyboard_switch";
|
||||
private static final String KEYBOARD_SHORTCUTS_HELPER = "keyboard_shortcuts_helper";
|
||||
private static final String MODIFIER_KEYS_SETTINGS = "modifier_keys_settings";
|
||||
private static final String EXTRA_AUTO_SELECTION = "auto_selection";
|
||||
|
||||
@NonNull
|
||||
private final ArrayList<HardKeyboardDeviceInfo> mLastHardKeyboards = new ArrayList<>();
|
||||
|
||||
private InputManager mIm;
|
||||
private InputMethodManager mImm;
|
||||
private InputDeviceIdentifier mAutoInputDeviceIdentifier;
|
||||
@NonNull
|
||||
private PreferenceCategory mKeyboardAssistanceCategory;
|
||||
@NonNull
|
||||
@@ -84,6 +86,12 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
||||
static final String EXTRA_BT_ADDRESS = "extra_bt_address";
|
||||
private String mBluetoothAddress;
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putParcelable(EXTRA_AUTO_SELECTION, mAutoInputDeviceIdentifier);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
Activity activity = Preconditions.checkNotNull(getActivity());
|
||||
@@ -107,15 +115,19 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
||||
KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_IDENTIFIER);
|
||||
// TODO (b/271391879): The EXTRA_INTENT_FROM is used for the future metrics.
|
||||
if (inputDeviceIdentifier != null) {
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
||||
inputDeviceIdentifier);
|
||||
new SubSettingLauncher(getContext())
|
||||
.setSourceMetricsCategory(getMetricsCategory())
|
||||
.setDestination(NewKeyboardLayoutEnabledLocalesFragment.class.getName())
|
||||
.setArguments(arguments)
|
||||
.launch();
|
||||
mAutoInputDeviceIdentifier = inputDeviceIdentifier;
|
||||
}
|
||||
// Don't repeat the autoselection.
|
||||
if (isAutoSelection(bundle, inputDeviceIdentifier)) {
|
||||
showEnabledLocalesKeyboardLayoutList(inputDeviceIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isAutoSelection(Bundle bundle, InputDeviceIdentifier identifier) {
|
||||
if (bundle != null && bundle.getParcelable(EXTRA_AUTO_SELECTION) != null) {
|
||||
return false;
|
||||
}
|
||||
return identifier != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,7 +232,6 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
||||
pref.setOnPreferenceClickListener(
|
||||
preference -> {
|
||||
showEnabledLocalesKeyboardLayoutList(
|
||||
hardKeyboardDeviceInfo.mDeviceName,
|
||||
hardKeyboardDeviceInfo.mDeviceIdentifier);
|
||||
return true;
|
||||
});
|
||||
@@ -246,8 +257,7 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
||||
fragment.show(getActivity().getSupportFragmentManager(), "keyboardLayout");
|
||||
}
|
||||
|
||||
private void showEnabledLocalesKeyboardLayoutList(String keyboardName,
|
||||
InputDeviceIdentifier inputDeviceIdentifier) {
|
||||
private void showEnabledLocalesKeyboardLayoutList(InputDeviceIdentifier inputDeviceIdentifier) {
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
||||
inputDeviceIdentifier);
|
||||
|
Reference in New Issue
Block a user