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