Update use of input manager API in settings.
Change-Id: I7aa033df8b5eec69cc6002b0bcc20b1d9902e4e0
This commit is contained in:
@@ -54,6 +54,7 @@
|
|||||||
<uses-permission android:name="android.permission.STATUS_BAR" />
|
<uses-permission android:name="android.permission.STATUS_BAR" />
|
||||||
<uses-permission android:name="android.permission.MANAGE_USB" />
|
<uses-permission android:name="android.permission.MANAGE_USB" />
|
||||||
<uses-permission android:name="android.permission.SET_POINTER_SPEED" />
|
<uses-permission android:name="android.permission.SET_POINTER_SPEED" />
|
||||||
|
<uses-permission android:name="android.permission.SET_KEYBOARD_LAYOUT" />
|
||||||
|
|
||||||
<application android:label="@string/settings_label"
|
<application android:label="@string/settings_label"
|
||||||
android:icon="@mipmap/ic_launcher_settings"
|
android:icon="@mipmap/ic_launcher_settings"
|
||||||
|
@@ -69,7 +69,7 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements
|
|||||||
|
|
||||||
mSeekBar = getSeekBar(view);
|
mSeekBar = getSeekBar(view);
|
||||||
mSeekBar.setMax(InputManager.MAX_POINTER_SPEED - InputManager.MIN_POINTER_SPEED);
|
mSeekBar.setMax(InputManager.MAX_POINTER_SPEED - InputManager.MIN_POINTER_SPEED);
|
||||||
mOldSpeed = mIm.getPointerSpeed();
|
mOldSpeed = mIm.getPointerSpeed(getContext());
|
||||||
mSeekBar.setProgress(mOldSpeed - InputManager.MIN_POINTER_SPEED);
|
mSeekBar.setProgress(mOldSpeed - InputManager.MIN_POINTER_SPEED);
|
||||||
mSeekBar.setOnSeekBarChangeListener(this);
|
mSeekBar.setOnSeekBarChangeListener(this);
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onSpeedChanged() {
|
private void onSpeedChanged() {
|
||||||
int speed = mIm.getPointerSpeed();
|
int speed = mIm.getPointerSpeed(getContext());
|
||||||
mSeekBar.setProgress(speed - InputManager.MIN_POINTER_SPEED);
|
mSeekBar.setProgress(speed - InputManager.MIN_POINTER_SPEED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,8 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements
|
|||||||
final ContentResolver resolver = getContext().getContentResolver();
|
final ContentResolver resolver = getContext().getContentResolver();
|
||||||
|
|
||||||
if (positiveResult) {
|
if (positiveResult) {
|
||||||
mIm.setPointerSpeed(mSeekBar.getProgress() + InputManager.MIN_POINTER_SPEED);
|
mIm.setPointerSpeed(getContext(),
|
||||||
|
mSeekBar.getProgress() + InputManager.MIN_POINTER_SPEED);
|
||||||
} else {
|
} else {
|
||||||
restoreOldState();
|
restoreOldState();
|
||||||
}
|
}
|
||||||
|
@@ -31,27 +31,23 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.hardware.input.InputManager;
|
import android.hardware.input.InputManager;
|
||||||
import android.hardware.input.InputManager.KeyboardLayout;
|
import android.hardware.input.KeyboardLayout;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceGroup;
|
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.System;
|
import android.provider.Settings.System;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
import android.view.KeyCharacterMap;
|
|
||||||
import android.view.KeyCharacterMap.UnavailableException;
|
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -373,11 +369,12 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
|||||||
for (int i = 0; i < devices.length; i++) {
|
for (int i = 0; i < devices.length; i++) {
|
||||||
InputDevice device = InputDevice.getDevice(devices[i]);
|
InputDevice device = InputDevice.getDevice(devices[i]);
|
||||||
if (device != null
|
if (device != null
|
||||||
|
&& !device.isVirtual()
|
||||||
&& (device.getSources() & InputDevice.SOURCE_KEYBOARD) != 0
|
&& (device.getSources() & InputDevice.SOURCE_KEYBOARD) != 0
|
||||||
&& device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
|
&& device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
|
||||||
final String inputDeviceDescriptor = device.getDescriptor();
|
final String inputDeviceDescriptor = device.getDescriptor();
|
||||||
final String keyboardLayoutDescriptor =
|
final String keyboardLayoutDescriptor =
|
||||||
im.getInputDeviceKeyboardLayoutDescriptor(inputDeviceDescriptor);
|
im.getKeyboardLayoutForInputDevice(inputDeviceDescriptor);
|
||||||
final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ?
|
final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ?
|
||||||
im.getKeyboardLayout(keyboardLayoutDescriptor) : null;
|
im.getKeyboardLayout(keyboardLayoutDescriptor) : null;
|
||||||
|
|
||||||
|
@@ -24,19 +24,17 @@ import android.content.AsyncTaskLoader;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Loader;
|
import android.content.Loader;
|
||||||
import android.hardware.input.InputManager;
|
import android.hardware.input.InputManager;
|
||||||
import android.hardware.input.InputManager.KeyboardLayout;
|
import android.hardware.input.KeyboardLayout;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListAdapter;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class KeyboardLayoutPicker extends ListFragment
|
public class KeyboardLayoutPicker extends ListFragment
|
||||||
implements LoaderCallbacks<List<KeyboardLayout>> {
|
implements LoaderCallbacks<KeyboardLayout[]> {
|
||||||
private static final String TAG = "KeyboardLayoutPicker";
|
private static final String TAG = "KeyboardLayoutPicker";
|
||||||
|
|
||||||
private String mInputDeviceDescriptor;
|
private String mInputDeviceDescriptor;
|
||||||
@@ -73,46 +71,46 @@ public class KeyboardLayoutPicker extends ListFragment
|
|||||||
if (mInputDeviceDescriptor != null) {
|
if (mInputDeviceDescriptor != null) {
|
||||||
KeyboardLayout c = (KeyboardLayout)l.getItemAtPosition(position);
|
KeyboardLayout c = (KeyboardLayout)l.getItemAtPosition(position);
|
||||||
InputManager im = (InputManager)getActivity().getSystemService(Context.INPUT_SERVICE);
|
InputManager im = (InputManager)getActivity().getSystemService(Context.INPUT_SERVICE);
|
||||||
im.setInputDeviceKeyboardLayoutDescriptor(mInputDeviceDescriptor, c.getDescriptor());
|
im.setKeyboardLayoutForInputDevice(mInputDeviceDescriptor, c.getDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<List<KeyboardLayout>> onCreateLoader(int id, Bundle args) {
|
public Loader<KeyboardLayout[]> onCreateLoader(int id, Bundle args) {
|
||||||
return new KeyboardLayoutLoader(getActivity());
|
return new KeyboardLayoutLoader(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<List<KeyboardLayout>> loader,
|
public void onLoadFinished(Loader<KeyboardLayout[]> loader,
|
||||||
List<KeyboardLayout> data) {
|
KeyboardLayout[] data) {
|
||||||
setListAdapter(new KeyboardLayoutAdapter(getActivity(), data));
|
setListAdapter(new KeyboardLayoutAdapter(getActivity(), data));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoaderReset(Loader<List<KeyboardLayout>> loader) {
|
public void onLoaderReset(Loader<KeyboardLayout[]> loader) {
|
||||||
setListAdapter(null);
|
setListAdapter(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class KeyboardLayoutAdapter
|
private static final class KeyboardLayoutAdapter
|
||||||
extends ArrayAdapter<KeyboardLayout> {
|
extends ArrayAdapter<KeyboardLayout> {
|
||||||
public KeyboardLayoutAdapter(Context context, List<KeyboardLayout> list) {
|
public KeyboardLayoutAdapter(Context context, KeyboardLayout[] list) {
|
||||||
super(context, android.R.layout.simple_list_item_1, list);
|
super(context, android.R.layout.simple_list_item_1, list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class KeyboardLayoutLoader
|
private static final class KeyboardLayoutLoader
|
||||||
extends AsyncTaskLoader<List<KeyboardLayout>> {
|
extends AsyncTaskLoader<KeyboardLayout[]> {
|
||||||
public KeyboardLayoutLoader(Context context) {
|
public KeyboardLayoutLoader(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<KeyboardLayout> loadInBackground() {
|
public KeyboardLayout[] loadInBackground() {
|
||||||
InputManager im = (InputManager)getContext().getSystemService(Context.INPUT_SERVICE);
|
InputManager im = (InputManager)getContext().getSystemService(Context.INPUT_SERVICE);
|
||||||
List<KeyboardLayout> list = im.getKeyboardLayouts();
|
KeyboardLayout[] list = im.getKeyboardLayouts();
|
||||||
Collections.sort(list);
|
Arrays.sort(list);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user