|
@@ -1,6 +1,5 @@
|
|
|
package com.xugame.app;
|
|
|
|
|
|
-import android.util.Log;
|
|
|
import android.view.InputDevice;
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
@@ -15,19 +14,29 @@ public class JoypadManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void uninitialize() {
|
|
|
+ mJoystickHandler.removeInputDevices();
|
|
|
+ mJoystickHandler = null;
|
|
|
+ }
|
|
|
+
|
|
|
// Using for JNI
|
|
|
public static void pollInputDevices() {
|
|
|
mJoystickHandler.pollInputDevices();
|
|
|
}
|
|
|
|
|
|
// Check if a given device is considered a possible SDL joystick
|
|
|
- public static boolean isDeviceSDLJoystick(int deviceId) {
|
|
|
+ public static boolean isDeviceJoystick(int deviceId) {
|
|
|
InputDevice device = InputDevice.getDevice(deviceId);
|
|
|
// We cannot use InputDevice.isVirtual before API 16, so let's accept
|
|
|
// only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
|
|
|
if ((device == null) || (deviceId < 0)) {
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ if (device.isVirtual()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
int sources = device.getSources();
|
|
|
|
|
|
/* This is called for every button press, so let's not spam the logs */
|
|
@@ -42,6 +51,13 @@ public class JoypadManager {
|
|
|
Log.v(TAG, "Input device " + device.getName() + " is a gamepad.");
|
|
|
}
|
|
|
*/
|
|
|
+ InputDevice.MotionRange range = device.getMotionRange(MotionEvent.AXIS_HAT_X);
|
|
|
+ if(range == null)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ range = device.getMotionRange(MotionEvent.AXIS_HAT_Y);
|
|
|
+ if(range == null)
|
|
|
+ return false;
|
|
|
|
|
|
return ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 ||
|
|
|
((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) ||
|
|
@@ -59,6 +75,9 @@ class JoypadHandler {
|
|
|
*/
|
|
|
public void pollInputDevices() {
|
|
|
}
|
|
|
+
|
|
|
+ public void removeInputDevices() {
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class JoypadHandler_API extends JoypadHandler {
|
|
@@ -74,7 +93,7 @@ class JoypadHandler_API extends JoypadHandler {
|
|
|
|
|
|
for (int deviceId : deviceIds) {
|
|
|
if (!mJoypadIds.contains(deviceId)) {
|
|
|
- if (JoypadManager.isDeviceSDLJoystick(deviceId)) {
|
|
|
+ if (JoypadManager.isDeviceJoystick(deviceId)) {
|
|
|
InputDevice joypadDevice = InputDevice.getDevice(deviceId);
|
|
|
mJoypadIds.add(deviceId);
|
|
|
JoypadManager.addJoystickNative(
|
|
@@ -108,4 +127,12 @@ class JoypadHandler_API extends JoypadHandler {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void removeInputDevices() {
|
|
|
+ for (int deviceId : mJoypadIds) {
|
|
|
+ JoypadManager.removeJoystickNative(deviceId);
|
|
|
+ }
|
|
|
+ mJoypadIds.clear();
|
|
|
+ }
|
|
|
}
|