Fix handling of ACTION_CANCEL for multi-pointer gestures

This commit is contained in:
Cameron Gutman
2023-08-03 02:29:55 -05:00
parent c9c1ef91fd
commit 2636d79b86
4 changed files with 31 additions and 5 deletions
@@ -1548,7 +1548,11 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
break;
case MotionEvent.ACTION_CANCEL:
touchType = MoonBridge.LI_TOUCH_EVENT_CANCEL;
// ACTION_CANCEL applies to *all* pointers in the gesture, so it maps to CANCEL_ALL
// rather than CANCEL. For a single pointer cancellation, that's indicated via
// FLAG_CANCELED on a ACTION_POINTER_UP.
// https://developer.android.com/develop/ui/views/touch-and-input/gestures/multi
touchType = MoonBridge.LI_TOUCH_EVENT_CANCEL_ALL;
break;
case MotionEvent.ACTION_BUTTON_PRESS:
@@ -1595,6 +1599,11 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
}
return true;
}
else if (event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
// Cancel impacts all active pointers
return conn.sendControllerTouchEvent((byte)context.controllerNumber, MoonBridge.LI_TOUCH_EVENT_CANCEL_ALL,
0, 0, 0, 0) != MoonBridge.LI_ERR_UNSUPPORTED;
}
else {
// Down and Up events impact the action index pointer
return sendTouchpadEventForPointer(context, event, touchType, event.getActionIndex());