Merge "Update samples to use new getMotionRanges() API." into honeycomb-mr1
This commit is contained in:
@@ -33,6 +33,7 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.InputDevice.MotionRange;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
@@ -152,8 +153,24 @@ public class GameControllerInput extends Activity {
|
|||||||
|
|
||||||
public InputDeviceState(InputDevice device) {
|
public InputDeviceState(InputDevice device) {
|
||||||
mDevice = 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();
|
mKeys = new SparseIntArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ public class GameView extends View {
|
|||||||
|
|
||||||
private static float getCenteredAxis(MotionEvent event, InputDevice device,
|
private static float getCenteredAxis(MotionEvent event, InputDevice device,
|
||||||
int axis, int historyPos) {
|
int axis, int historyPos) {
|
||||||
final InputDevice.MotionRange range = device.getMotionRange(axis);
|
final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource());
|
||||||
if (range != null) {
|
if (range != null) {
|
||||||
final float flat = range.getFlat();
|
final float flat = range.getFlat();
|
||||||
final float value = historyPos < 0 ? event.getAxisValue(axis)
|
final float value = historyPos < 0 ? event.getAxisValue(axis)
|
||||||
|
|||||||
Reference in New Issue
Block a user