Update ApiDemos to use new input source check

Change-Id: Iab20881dca49cfef66fa35396942cdb5045137aa
This commit is contained in:
Michael Wright
2013-03-11 15:57:21 -07:00
parent b74c3ef70b
commit 8f48506e2d
2 changed files with 5 additions and 9 deletions

View File

@@ -142,7 +142,7 @@ public class GameControllerInput extends Activity
public boolean dispatchGenericMotionEvent(MotionEvent event) {
// Check that the event came from a joystick since a generic motion event
// could be almost anything.
if (isJoystick(event.getSource())
if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)
&& event.getAction() == MotionEvent.ACTION_MOVE) {
// Update device state for visualization and logging.
InputDeviceState state = getInputDeviceState(event.getDeviceId());
@@ -195,10 +195,6 @@ public class GameControllerInput extends Activity
}
}
private static boolean isJoystick(int source) {
return (source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0;
}
/**
* Tracks the state of joystick axes and game controller buttons for a particular
* input device for diagnostic purposes.
@@ -215,7 +211,7 @@ public class GameControllerInput extends Activity
int numAxes = 0;
final List<MotionRange> ranges = device.getMotionRanges();
for (MotionRange range : ranges) {
if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
if (range.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) {
numAxes += 1;
}
}
@@ -224,7 +220,7 @@ public class GameControllerInput extends Activity
mAxisValues = new float[numAxes];
int i = 0;
for (MotionRange range : ranges) {
if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
if (range.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) {
mAxes[i++] = range.getAxis();
}
}

View File

@@ -209,7 +209,7 @@ public class GameView extends View {
// Check that the event came from a joystick since a generic motion event
// could be almost anything.
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0
if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)
&& event.getAction() == MotionEvent.ACTION_MOVE) {
// Cache the most recently obtained device information.
// The device information may change over time but it can be
@@ -771,4 +771,4 @@ public class GameView extends View {
return 0.25f;
}
}
}
}