b/12068020 Update calls to InputManager
This is part of work on making key layouts get saved per vendor/product instead of per device. The corresponding change in fw is https://googleplex-android-review.git.corp.google.com/#/c/399886/ This changes all uses of InputDevice descriptor to InputDeviceIdentifier. Change-Id: I3eeebc0223820aeab62c2b8aa822f4d91adaf2d1
This commit is contained in:
@@ -33,6 +33,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.hardware.input.InputDeviceIdentifier;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.hardware.input.KeyboardLayout;
|
||||
import android.os.Bundle;
|
||||
@@ -492,9 +493,9 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
if (device != null
|
||||
&& !device.isVirtual()
|
||||
&& device.isFullKeyboard()) {
|
||||
final String inputDeviceDescriptor = device.getDescriptor();
|
||||
final InputDeviceIdentifier identifier = device.getIdentifier();
|
||||
final String keyboardLayoutDescriptor =
|
||||
mIm.getCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor);
|
||||
mIm.getCurrentKeyboardLayoutForInputDevice(identifier);
|
||||
final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ?
|
||||
mIm.getKeyboardLayout(keyboardLayoutDescriptor) : null;
|
||||
|
||||
@@ -508,7 +509,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
showKeyboardLayoutDialog(inputDeviceDescriptor);
|
||||
showKeyboardLayoutDialog(identifier);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -539,19 +540,19 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void showKeyboardLayoutDialog(String inputDeviceDescriptor) {
|
||||
private void showKeyboardLayoutDialog(InputDeviceIdentifier inputDeviceIdentifier) {
|
||||
KeyboardLayoutDialogFragment fragment =
|
||||
new KeyboardLayoutDialogFragment(inputDeviceDescriptor);
|
||||
new KeyboardLayoutDialogFragment(inputDeviceIdentifier);
|
||||
fragment.setTargetFragment(this, 0);
|
||||
fragment.show(getActivity().getFragmentManager(), "keyboardLayout");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetupKeyboardLayouts(String inputDeviceDescriptor) {
|
||||
public void onSetupKeyboardLayouts(InputDeviceIdentifier inputDeviceIdentifier) {
|
||||
final Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.setClass(getActivity(), KeyboardLayoutPickerActivity.class);
|
||||
intent.putExtra(KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_DESCRIPTOR,
|
||||
inputDeviceDescriptor);
|
||||
intent.putExtra(KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
||||
inputDeviceIdentifier);
|
||||
mIntentWaitingForResult = intent;
|
||||
startActivityForResult(intent, 0);
|
||||
}
|
||||
@@ -561,10 +562,10 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (mIntentWaitingForResult != null) {
|
||||
String inputDeviceDescriptor = mIntentWaitingForResult.getStringExtra(
|
||||
KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_DESCRIPTOR);
|
||||
InputDeviceIdentifier inputDeviceIdentifier = mIntentWaitingForResult
|
||||
.getParcelableExtra(KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_IDENTIFIER);
|
||||
mIntentWaitingForResult = null;
|
||||
showKeyboardLayoutDialog(inputDeviceDescriptor);
|
||||
showKeyboardLayoutDialog(inputDeviceIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -30,6 +30,7 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.Loader;
|
||||
import android.content.res.Resources;
|
||||
import android.hardware.input.InputDeviceIdentifier;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.hardware.input.KeyboardLayout;
|
||||
import android.hardware.input.InputManager.InputDeviceListener;
|
||||
@@ -48,9 +49,9 @@ import java.util.Collections;
|
||||
|
||||
public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
implements InputDeviceListener, LoaderCallbacks<KeyboardLayoutDialogFragment.Keyboards> {
|
||||
private static final String KEY_INPUT_DEVICE_DESCRIPTOR = "inputDeviceDescriptor";
|
||||
private static final String KEY_INPUT_DEVICE_IDENTIFIER = "inputDeviceIdentifier";
|
||||
|
||||
private String mInputDeviceDescriptor;
|
||||
private InputDeviceIdentifier mInputDeviceIdentifier;
|
||||
private int mInputDeviceId = -1;
|
||||
private InputManager mIm;
|
||||
private KeyboardLayoutAdapter mAdapter;
|
||||
@@ -58,8 +59,8 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
public KeyboardLayoutDialogFragment() {
|
||||
}
|
||||
|
||||
public KeyboardLayoutDialogFragment(String inputDeviceDescriptor) {
|
||||
mInputDeviceDescriptor = inputDeviceDescriptor;
|
||||
public KeyboardLayoutDialogFragment(InputDeviceIdentifier inputDeviceIdentifier) {
|
||||
mInputDeviceIdentifier = inputDeviceIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,7 +77,7 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mInputDeviceDescriptor = savedInstanceState.getString(KEY_INPUT_DEVICE_DESCRIPTOR);
|
||||
mInputDeviceIdentifier = savedInstanceState.getParcelable(KEY_INPUT_DEVICE_IDENTIFIER);
|
||||
}
|
||||
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
@@ -85,7 +86,7 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(KEY_INPUT_DEVICE_DESCRIPTOR, mInputDeviceDescriptor);
|
||||
outState.putParcelable(KEY_INPUT_DEVICE_IDENTIFIER, mInputDeviceIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,7 +120,8 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
|
||||
mIm.registerInputDeviceListener(this, null);
|
||||
|
||||
InputDevice inputDevice = mIm.getInputDeviceByDescriptor(mInputDeviceDescriptor);
|
||||
InputDevice inputDevice =
|
||||
mIm.getInputDeviceByDescriptor(mInputDeviceIdentifier.getDescriptor());
|
||||
if (inputDevice == null) {
|
||||
dismiss();
|
||||
return;
|
||||
@@ -143,7 +145,7 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
|
||||
private void onSetupLayoutsButtonClicked() {
|
||||
((OnSetupKeyboardLayoutsListener)getTargetFragment()).onSetupKeyboardLayouts(
|
||||
mInputDeviceDescriptor);
|
||||
mInputDeviceIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,7 +158,7 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
if (which >= 0 && which < mAdapter.getCount()) {
|
||||
KeyboardLayout keyboardLayout = mAdapter.getItem(which);
|
||||
if (keyboardLayout != null) {
|
||||
mIm.setCurrentKeyboardLayoutForInputDevice(mInputDeviceDescriptor,
|
||||
mIm.setCurrentKeyboardLayoutForInputDevice(mInputDeviceIdentifier,
|
||||
keyboardLayout.getDescriptor());
|
||||
}
|
||||
dismiss();
|
||||
@@ -165,7 +167,7 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
|
||||
@Override
|
||||
public Loader<Keyboards> onCreateLoader(int id, Bundle args) {
|
||||
return new KeyboardLayoutLoader(getActivity().getBaseContext(), mInputDeviceDescriptor);
|
||||
return new KeyboardLayoutLoader(getActivity().getBaseContext(), mInputDeviceIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -289,11 +291,11 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
}
|
||||
|
||||
private static final class KeyboardLayoutLoader extends AsyncTaskLoader<Keyboards> {
|
||||
private final String mInputDeviceDescriptor;
|
||||
private final InputDeviceIdentifier mInputDeviceIdentifier;
|
||||
|
||||
public KeyboardLayoutLoader(Context context, String inputDeviceDescriptor) {
|
||||
public KeyboardLayoutLoader(Context context, InputDeviceIdentifier inputDeviceIdentifier) {
|
||||
super(context);
|
||||
mInputDeviceDescriptor = inputDeviceDescriptor;
|
||||
mInputDeviceIdentifier = inputDeviceIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -301,7 +303,7 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
Keyboards keyboards = new Keyboards();
|
||||
InputManager im = (InputManager)getContext().getSystemService(Context.INPUT_SERVICE);
|
||||
String[] keyboardLayoutDescriptors = im.getKeyboardLayoutsForInputDevice(
|
||||
mInputDeviceDescriptor);
|
||||
mInputDeviceIdentifier);
|
||||
for (String keyboardLayoutDescriptor : keyboardLayoutDescriptors) {
|
||||
KeyboardLayout keyboardLayout = im.getKeyboardLayout(keyboardLayoutDescriptor);
|
||||
if (keyboardLayout != null) {
|
||||
@@ -311,7 +313,7 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
Collections.sort(keyboards.keyboardLayouts);
|
||||
|
||||
String currentKeyboardLayoutDescriptor =
|
||||
im.getCurrentKeyboardLayoutForInputDevice(mInputDeviceDescriptor);
|
||||
im.getCurrentKeyboardLayoutForInputDevice(mInputDeviceIdentifier);
|
||||
if (currentKeyboardLayoutDescriptor != null) {
|
||||
final int numKeyboardLayouts = keyboards.keyboardLayouts.size();
|
||||
for (int i = 0; i < numKeyboardLayouts; i++) {
|
||||
@@ -349,6 +351,6 @@ public class KeyboardLayoutDialogFragment extends DialogFragment
|
||||
}
|
||||
|
||||
public interface OnSetupKeyboardLayoutsListener {
|
||||
public void onSetupKeyboardLayouts(String inputDeviceDescriptor);
|
||||
public void onSetupKeyboardLayouts(InputDeviceIdentifier mInputDeviceIdentifier);
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
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;
|
||||
@@ -35,7 +36,7 @@ import java.util.Map;
|
||||
|
||||
public class KeyboardLayoutPickerFragment extends SettingsPreferenceFragment
|
||||
implements InputDeviceListener {
|
||||
private String mInputDeviceDescriptor;
|
||||
private InputDeviceIdentifier mInputDeviceIdentifier;
|
||||
private int mInputDeviceId = -1;
|
||||
private InputManager mIm;
|
||||
private KeyboardLayout[] mKeyboardLayouts;
|
||||
@@ -46,15 +47,15 @@ public class KeyboardLayoutPickerFragment extends SettingsPreferenceFragment
|
||||
* Intent extra: The input device descriptor of the keyboard whose keyboard
|
||||
* layout is to be changed.
|
||||
*/
|
||||
public static final String EXTRA_INPUT_DEVICE_DESCRIPTOR = "input_device_descriptor";
|
||||
public static final String EXTRA_INPUT_DEVICE_IDENTIFIER = "input_device_identifier";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
mInputDeviceDescriptor = getActivity().getIntent().getStringExtra(
|
||||
EXTRA_INPUT_DEVICE_DESCRIPTOR);
|
||||
if (mInputDeviceDescriptor == null) {
|
||||
mInputDeviceIdentifier = getActivity().getIntent().getParcelableExtra(
|
||||
EXTRA_INPUT_DEVICE_IDENTIFIER);
|
||||
if (mInputDeviceIdentifier == null) {
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
@@ -70,7 +71,8 @@ public class KeyboardLayoutPickerFragment extends SettingsPreferenceFragment
|
||||
|
||||
mIm.registerInputDeviceListener(this, null);
|
||||
|
||||
InputDevice inputDevice = mIm.getInputDeviceByDescriptor(mInputDeviceDescriptor);
|
||||
InputDevice inputDevice =
|
||||
mIm.getInputDeviceByDescriptor(mInputDeviceIdentifier.getDescriptor());
|
||||
if (inputDevice == null) {
|
||||
getActivity().finish();
|
||||
return;
|
||||
@@ -97,10 +99,10 @@ public class KeyboardLayoutPickerFragment extends SettingsPreferenceFragment
|
||||
if (layout != null) {
|
||||
boolean checked = checkboxPref.isChecked();
|
||||
if (checked) {
|
||||
mIm.addKeyboardLayoutForInputDevice(mInputDeviceDescriptor,
|
||||
mIm.addKeyboardLayoutForInputDevice(mInputDeviceIdentifier,
|
||||
layout.getDescriptor());
|
||||
} else {
|
||||
mIm.removeKeyboardLayoutForInputDevice(mInputDeviceDescriptor,
|
||||
mIm.removeKeyboardLayoutForInputDevice(mInputDeviceIdentifier,
|
||||
layout.getDescriptor());
|
||||
}
|
||||
return true;
|
||||
@@ -143,7 +145,7 @@ public class KeyboardLayoutPickerFragment extends SettingsPreferenceFragment
|
||||
|
||||
private void updateCheckedState() {
|
||||
String[] enabledKeyboardLayouts = mIm.getKeyboardLayoutsForInputDevice(
|
||||
mInputDeviceDescriptor);
|
||||
mInputDeviceIdentifier);
|
||||
Arrays.sort(enabledKeyboardLayouts);
|
||||
|
||||
for (Map.Entry<CheckBoxPreference, KeyboardLayout> entry : mPreferenceMap.entrySet()) {
|
||||
|
Reference in New Issue
Block a user