From cb34b7c07a4ec532db6d8efe5c172813a2e2726e Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 8 Mar 2011 17:34:45 -0800 Subject: [PATCH] Update samples to use new getMotionRanges() API. Change-Id: I6b67b7cd1f739b5b52ac32745f52bf0a092480a0 --- .../apis/view/GameControllerInput.java | 21 +++++++++++++++++-- .../example/android/apis/view/GameView.java | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/samples/ApiDemos/src/com/example/android/apis/view/GameControllerInput.java b/samples/ApiDemos/src/com/example/android/apis/view/GameControllerInput.java index 8c0db32c1..8aea94916 100644 --- a/samples/ApiDemos/src/com/example/android/apis/view/GameControllerInput.java +++ b/samples/ApiDemos/src/com/example/android/apis/view/GameControllerInput.java @@ -33,6 +33,7 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.InputDevice.MotionRange; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ListView; @@ -152,8 +153,24 @@ public class GameControllerInput extends Activity { public InputDeviceState(InputDevice device) { mDevice = device; - mAxes = device.getMotionAxes(); - mAxisValues = new float[mAxes.length]; + + int numAxes = 0; + for (MotionRange range : device.getMotionRanges()) { + if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { + numAxes += 1; + } + } + + mAxes = new int[numAxes]; + mAxisValues = new float[numAxes]; + int i = 0; + for (MotionRange range : device.getMotionRanges()) { + if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { + numAxes += 1; + } + mAxes[i++] = range.getAxis(); + } + mKeys = new SparseIntArray(); } diff --git a/samples/ApiDemos/src/com/example/android/apis/view/GameView.java b/samples/ApiDemos/src/com/example/android/apis/view/GameView.java index 1791029c3..9fe236c3a 100644 --- a/samples/ApiDemos/src/com/example/android/apis/view/GameView.java +++ b/samples/ApiDemos/src/com/example/android/apis/view/GameView.java @@ -264,7 +264,7 @@ public class GameView extends View { private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { - final InputDevice.MotionRange range = device.getMotionRange(axis); + final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis)