Reenable pre-N style hard keyboard layout settings
This CL logically reverts Settings app changes for Bug 25752812, which aimed to improve UX by tightly integrating physical keyboard layout with input method subtype. What went wrong is that the concept of input method subtype is not widely accepted by the ecosystem actually. Until we figoure out any other better way here, let's revert back to the good old way that enables users to specify multiple keyboard layouts per physical keyboard device, not one layout per one input method subtype. Note that we cannot simply revert the CL that originally introduced the new flow [1] because it was indeed a huge CL that also touched IME settings, which we want to continue using. In that sense, this CL is a kind of re-implementation of the previous style on top of the recent language settings flow. Note also that a fix [2] fox Bug 25062009 was also ported from previous InputMethodAndLanguageSetting to KeyboardLayoutPickerFragment. [1]: I728d7ee185827ed328c16cb7abce244557a26518976bb3f459
[2]: I4483dfc89afc8d148b2cfa7c6a5f66d2a02f712a17b6319884
Fix: 66498367 Test: make -j RunSettingsRoboTests Test: Manually done with two Bluetooth keyboards Change-Id: I7a2ed6dd39dcd8207d3d94e12cd01d5d67ba4bb5
This commit is contained in:
@@ -16,43 +16,31 @@
|
||||
|
||||
package com.android.settings.inputmethod;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.hardware.input.InputDeviceIdentifier;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.hardware.input.InputManager.InputDeviceListener;
|
||||
import android.hardware.input.KeyboardLayout;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.CheckBoxPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.view.InputDevice;
|
||||
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.inputmethod.PhysicalKeyboardFragment.KeyboardInfoPreference;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class KeyboardLayoutPickerFragment extends SettingsPreferenceFragment
|
||||
public class KeyboardLayoutPickerFragment extends SettingsPreferenceFragment
|
||||
implements InputDeviceListener {
|
||||
|
||||
private InputDeviceIdentifier mInputDeviceIdentifier;
|
||||
private int mInputDeviceId = -1;
|
||||
private InputManager mIm;
|
||||
private InputMethodInfo mImi;
|
||||
@Nullable
|
||||
private InputMethodSubtype mSubtype;
|
||||
private KeyboardLayout[] mKeyboardLayouts;
|
||||
private Map<Preference, KeyboardLayout> mPreferenceMap = new HashMap<>();
|
||||
|
||||
// TODO: Make these constants public API for b/25752827
|
||||
private HashMap<CheckBoxPreference, KeyboardLayout> mPreferenceMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Intent extra: The input device descriptor of the keyboard whose keyboard
|
||||
@@ -60,16 +48,6 @@ public final class KeyboardLayoutPickerFragment extends SettingsPreferenceFragme
|
||||
*/
|
||||
public static final String EXTRA_INPUT_DEVICE_IDENTIFIER = "input_device_identifier";
|
||||
|
||||
/**
|
||||
* Intent extra: The associated {@link InputMethodInfo}.
|
||||
*/
|
||||
public static final String EXTRA_INPUT_METHOD_INFO = "input_method_info";
|
||||
|
||||
/**
|
||||
* Intent extra: The associated {@link InputMethodSubtype}.
|
||||
*/
|
||||
public static final String EXTRA_INPUT_METHOD_SUBTYPE = "input_method_subtype";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.INPUTMETHOD_KEYBOARD;
|
||||
@@ -78,18 +56,14 @@ public final class KeyboardLayoutPickerFragment extends SettingsPreferenceFragme
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
Activity activity = Preconditions.checkNotNull(getActivity());
|
||||
|
||||
mInputDeviceIdentifier = activity.getIntent().getParcelableExtra(
|
||||
mInputDeviceIdentifier = getActivity().getIntent().getParcelableExtra(
|
||||
EXTRA_INPUT_DEVICE_IDENTIFIER);
|
||||
mImi = activity.getIntent().getParcelableExtra(EXTRA_INPUT_METHOD_INFO);
|
||||
mSubtype = activity.getIntent().getParcelableExtra(EXTRA_INPUT_METHOD_SUBTYPE);
|
||||
|
||||
if (mInputDeviceIdentifier == null || mImi == null) {
|
||||
activity.finish();
|
||||
if (mInputDeviceIdentifier == null) {
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
mIm = activity.getSystemService(InputManager.class);
|
||||
mIm = (InputManager) getSystemService(Context.INPUT_SERVICE);
|
||||
mKeyboardLayouts = mIm.getKeyboardLayoutsForInputDevice(mInputDeviceIdentifier);
|
||||
Arrays.sort(mKeyboardLayouts);
|
||||
setPreferenceScreen(createPreferenceHierarchy());
|
||||
@@ -108,6 +82,8 @@ public final class KeyboardLayoutPickerFragment extends SettingsPreferenceFragme
|
||||
return;
|
||||
}
|
||||
mInputDeviceId = inputDevice.getId();
|
||||
|
||||
updateCheckedState();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,21 +96,34 @@ public final class KeyboardLayoutPickerFragment extends SettingsPreferenceFragme
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
KeyboardLayout layout = mPreferenceMap.get(preference);
|
||||
if (layout != null) {
|
||||
mIm.setKeyboardLayoutForInputDevice(mInputDeviceIdentifier, mImi, mSubtype,
|
||||
layout.getDescriptor());
|
||||
getActivity().finish();
|
||||
return true;
|
||||
if (preference instanceof CheckBoxPreference) {
|
||||
CheckBoxPreference checkboxPref = (CheckBoxPreference)preference;
|
||||
KeyboardLayout layout = mPreferenceMap.get(checkboxPref);
|
||||
if (layout != null) {
|
||||
boolean checked = checkboxPref.isChecked();
|
||||
if (checked) {
|
||||
mIm.addKeyboardLayoutForInputDevice(mInputDeviceIdentifier,
|
||||
layout.getDescriptor());
|
||||
} else {
|
||||
mIm.removeKeyboardLayoutForInputDevice(mInputDeviceIdentifier,
|
||||
layout.getDescriptor());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {}
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceChanged(int deviceId) {}
|
||||
public void onInputDeviceChanged(int deviceId) {
|
||||
if (mInputDeviceId >= 0 && deviceId == mInputDeviceId) {
|
||||
updateCheckedState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceRemoved(int deviceId) {
|
||||
@@ -147,14 +136,23 @@ public final class KeyboardLayoutPickerFragment extends SettingsPreferenceFragme
|
||||
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(getActivity());
|
||||
|
||||
for (KeyboardLayout layout : mKeyboardLayouts) {
|
||||
Preference pref = new Preference(getPrefContext());
|
||||
CheckBoxPreference pref = new CheckBoxPreference(getPrefContext());
|
||||
pref.setTitle(layout.getLabel());
|
||||
pref.setSummary(layout.getCollection());
|
||||
root.addPreference(pref);
|
||||
mPreferenceMap.put(pref, layout);
|
||||
}
|
||||
|
||||
root.setTitle(KeyboardInfoPreference.getDisplayName(getContext(), mImi, mSubtype));
|
||||
return root;
|
||||
}
|
||||
|
||||
private void updateCheckedState() {
|
||||
String[] enabledKeyboardLayouts = mIm.getEnabledKeyboardLayoutsForInputDevice(
|
||||
mInputDeviceIdentifier);
|
||||
Arrays.sort(enabledKeyboardLayouts);
|
||||
|
||||
for (Map.Entry<CheckBoxPreference, KeyboardLayout> entry : mPreferenceMap.entrySet()) {
|
||||
entry.getKey().setChecked(Arrays.binarySearch(enabledKeyboardLayouts,
|
||||
entry.getValue().getDescriptor()) >= 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user