summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-04-05 19:34:58 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-05 19:34:58 -0700
commit11ca81e1f0f95e6ace612045c14ebd38e00fd819 (patch)
treec4f720ae3627b187b08ff8a6a3945ace6fe2141c
parent7719be16df6457ad8294ac7455cc9b7e4d8e8d21 (diff)
parentb4765ac70d4ebf7ce0e3bbcbc2697cb242ed176d (diff)
downloadpackages_apps_Settings-11ca81e1f0f95e6ace612045c14ebd38e00fd819.zip
packages_apps_Settings-11ca81e1f0f95e6ace612045c14ebd38e00fd819.tar.gz
packages_apps_Settings-11ca81e1f0f95e6ace612045c14ebd38e00fd819.tar.bz2
Merge "Use new input manager API."
-rw-r--r--src/com/android/settings/PointerSpeedPreference.java52
1 files changed, 13 insertions, 39 deletions
diff --git a/src/com/android/settings/PointerSpeedPreference.java b/src/com/android/settings/PointerSpeedPreference.java
index 6a6a71f..7679cfb 100644
--- a/src/com/android/settings/PointerSpeedPreference.java
+++ b/src/com/android/settings/PointerSpeedPreference.java
@@ -19,22 +19,20 @@ package com.android.settings;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
+import android.hardware.input.InputManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
-import android.os.RemoteException;
-import android.os.ServiceManager;
import android.preference.SeekBarDialogPreference;
import android.provider.Settings;
-import android.provider.Settings.SettingNotFoundException;
import android.util.AttributeSet;
-import android.view.IWindowManager;
import android.view.View;
import android.widget.SeekBar;
public class PointerSpeedPreference extends SeekBarDialogPreference implements
SeekBar.OnSeekBarChangeListener {
+ private final InputManager mIm;
private SeekBar mSeekBar;
private int mOldSpeed;
@@ -42,9 +40,6 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements
private boolean mTouchInProgress;
- private static final int MIN_SPEED = -7;
- private static final int MAX_SPEED = 7;
-
private ContentObserver mSpeedObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
@@ -54,6 +49,7 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements
public PointerSpeedPreference(Context context, AttributeSet attrs) {
super(context, attrs);
+ mIm = (InputManager)getContext().getSystemService(Context.INPUT_SERVICE);
}
@Override
@@ -72,15 +68,15 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements
super.onBindDialogView(view);
mSeekBar = getSeekBar(view);
- mSeekBar.setMax(MAX_SPEED - MIN_SPEED);
- mOldSpeed = getSpeed(0);
- mSeekBar.setProgress(mOldSpeed - MIN_SPEED);
+ mSeekBar.setMax(InputManager.MAX_POINTER_SPEED - InputManager.MIN_POINTER_SPEED);
+ mOldSpeed = mIm.getPointerSpeed();
+ mSeekBar.setProgress(mOldSpeed - InputManager.MIN_POINTER_SPEED);
mSeekBar.setOnSeekBarChangeListener(this);
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
if (!mTouchInProgress) {
- setSpeed(progress + MIN_SPEED);
+ mIm.tryPointerSpeed(progress + InputManager.MIN_POINTER_SPEED);
}
}
@@ -90,22 +86,12 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements
public void onStopTrackingTouch(SeekBar seekBar) {
mTouchInProgress = false;
- setSpeed(seekBar.getProgress() + MIN_SPEED);
- }
-
- private int getSpeed(int defaultValue) {
- int speed = defaultValue;
- try {
- speed = Settings.System.getInt(getContext().getContentResolver(),
- Settings.System.POINTER_SPEED);
- } catch (SettingNotFoundException snfe) {
- }
- return speed;
+ mIm.tryPointerSpeed(seekBar.getProgress() + InputManager.MIN_POINTER_SPEED);
}
private void onSpeedChanged() {
- int speed = getSpeed(0);
- mSeekBar.setProgress(speed - MIN_SPEED);
+ int speed = mIm.getPointerSpeed();
+ mSeekBar.setProgress(speed - InputManager.MIN_POINTER_SPEED);
}
@Override
@@ -115,8 +101,7 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements
final ContentResolver resolver = getContext().getContentResolver();
if (positiveResult) {
- Settings.System.putInt(resolver, Settings.System.POINTER_SPEED,
- mSeekBar.getProgress() + MIN_SPEED);
+ mIm.setPointerSpeed(mSeekBar.getProgress() + InputManager.MIN_POINTER_SPEED);
} else {
restoreOldState();
}
@@ -127,21 +112,10 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements
private void restoreOldState() {
if (mRestoredOldState) return;
- setSpeed(mOldSpeed);
+ mIm.tryPointerSpeed(mOldSpeed);
mRestoredOldState = true;
}
- private void setSpeed(int speed) {
- try {
- IWindowManager wm = IWindowManager.Stub.asInterface(
- ServiceManager.getService("window"));
- if (wm != null) {
- wm.setPointerSpeed(speed);
- }
- } catch (RemoteException e) {
- }
- }
-
@Override
protected Parcelable onSaveInstanceState() {
final Parcelable superState = super.onSaveInstanceState();
@@ -169,7 +143,7 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements
super.onRestoreInstanceState(myState.getSuperState());
mOldSpeed = myState.oldSpeed;
mSeekBar.setProgress(myState.progress);
- setSpeed(myState.progress + MIN_SPEED);
+ mIm.tryPointerSpeed(myState.progress + InputManager.MIN_POINTER_SPEED);
}
private static class SavedState extends BaseSavedState {