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 ce7c749df..10b2f9a72 100644 --- a/samples/ApiDemos/src/com/example/android/apis/view/GameControllerInput.java +++ b/samples/ApiDemos/src/com/example/android/apis/view/GameControllerInput.java @@ -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 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(); } } 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 2904147ef..d7f039bdd 100644 --- a/samples/ApiDemos/src/com/example/android/apis/view/GameView.java +++ b/samples/ApiDemos/src/com/example/android/apis/view/GameView.java @@ -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; } } -} \ No newline at end of file +}