Android: Be less strict about bindable devices

This commit is contained in:
Connor McLaughlin 2021-03-20 02:22:45 +10:00
parent 8b7e2b525e
commit ab02fbdfad
2 changed files with 9 additions and 12 deletions

View file

@ -107,7 +107,7 @@ public class ControllerBindingDialog extends AlertDialog {
} }
private boolean doAxisDetection(MotionEvent event) { private boolean doAxisDetection(MotionEvent event) {
if (!EmulationSurfaceView.isBindableDevice(event.getDevice())) if (!EmulationSurfaceView.isBindableDevice(event.getDevice()) || !EmulationSurfaceView.isJoystickMotionEvent(event))
return false; return false;
final List<InputDevice.MotionRange> motionEventList = event.getDevice().getMotionRanges(); final List<InputDevice.MotionRange> motionEventList = event.getDevice().getMotionRanges();

View file

@ -1,7 +1,6 @@
package com.github.stenzek.duckstation; package com.github.stenzek.duckstation;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.Vibrator; import android.os.Vibrator;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
@ -10,10 +9,7 @@ import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.SurfaceView; import android.view.SurfaceView;
import androidx.core.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
public class EmulationSurfaceView extends SurfaceView { public class EmulationSurfaceView extends SurfaceView {
@ -30,19 +26,20 @@ public class EmulationSurfaceView extends SurfaceView {
} }
public static boolean isBindableDevice(InputDevice inputDevice) { public static boolean isBindableDevice(InputDevice inputDevice) {
if (inputDevice == null) if (inputDevice == null || inputDevice.isVirtual())
return false; return false;
// Accept all devices with an axis or buttons, filter in events.
final int sources = inputDevice.getSources(); 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) || return ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) ||
((sources & InputDevice.SOURCE_CLASS_BUTTON) == InputDevice.SOURCE_CLASS_BUTTON); ((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) { public static boolean isGamepadDevice(InputDevice inputDevice) {
final int sources = inputDevice.getSources(); final int sources = inputDevice.getSources();
return ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD); return ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD);
@ -233,7 +230,7 @@ public class EmulationSurfaceView extends SurfaceView {
@Override @Override
public boolean onGenericMotionEvent(MotionEvent event) { public boolean onGenericMotionEvent(MotionEvent event) {
if (!isBindableDevice(event.getDevice())) if (!isJoystickMotionEvent(event))
return false; return false;
final InputDeviceData data = getDataForDeviceId(event.getDeviceId()); final InputDeviceData data = getDataForDeviceId(event.getDeviceId());