diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/ControllerBindingDialog.java b/android/app/src/main/java/com/github/stenzek/duckstation/ControllerBindingDialog.java index bffc00079..53f345cd7 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/ControllerBindingDialog.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/ControllerBindingDialog.java @@ -107,7 +107,7 @@ public class ControllerBindingDialog extends AlertDialog { } private boolean doAxisDetection(MotionEvent event) { - if (!EmulationSurfaceView.isBindableDevice(event.getDevice())) + if (!EmulationSurfaceView.isBindableDevice(event.getDevice()) || !EmulationSurfaceView.isJoystickMotionEvent(event)) return false; final List motionEventList = event.getDevice().getMotionRanges(); diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/EmulationSurfaceView.java b/android/app/src/main/java/com/github/stenzek/duckstation/EmulationSurfaceView.java index 5fdc71040..7a4b3a578 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/EmulationSurfaceView.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/EmulationSurfaceView.java @@ -1,7 +1,6 @@ package com.github.stenzek.duckstation; import android.content.Context; -import android.content.SharedPreferences; import android.os.Vibrator; import android.util.AttributeSet; import android.util.Log; @@ -10,10 +9,7 @@ import android.view.KeyEvent; import android.view.MotionEvent; import android.view.SurfaceView; -import androidx.core.util.Pair; - import java.util.ArrayList; -import java.util.HashMap; import java.util.List; public class EmulationSurfaceView extends SurfaceView { @@ -30,19 +26,20 @@ public class EmulationSurfaceView extends SurfaceView { } public static boolean isBindableDevice(InputDevice inputDevice) { - if (inputDevice == null) + if (inputDevice == null || inputDevice.isVirtual()) return false; + // Accept all devices with an axis or buttons, filter in events. final int sources = inputDevice.getSources(); - - // Prevent binding pointer devices such as a mouse. - if ((sources & InputDevice.SOURCE_CLASS_POINTER) == InputDevice.SOURCE_CLASS_POINTER) - return false; - return ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) || ((sources & InputDevice.SOURCE_CLASS_BUTTON) == InputDevice.SOURCE_CLASS_BUTTON); } + public static boolean isJoystickMotionEvent(MotionEvent event) { + final int source = event.getSource(); + return ((source & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK); + } + public static boolean isGamepadDevice(InputDevice inputDevice) { final int sources = inputDevice.getSources(); return ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD); @@ -233,7 +230,7 @@ public class EmulationSurfaceView extends SurfaceView { @Override public boolean onGenericMotionEvent(MotionEvent event) { - if (!isBindableDevice(event.getDevice())) + if (!isJoystickMotionEvent(event)) return false; final InputDeviceData data = getDataForDeviceId(event.getDeviceId());