Skip to content

InputService: real-time gestures #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

gm-vm
Copy link

@gm-vm gm-vm commented Mar 30, 2025

Android O has added support for building gestures incrementally, allowing to send input events almost in real-time.

Older versions of Android will continue to wait for gestures to complete before dispatching them.

@gm-vm gm-vm mentioned this pull request Mar 30, 2025
@gm-vm gm-vm force-pushed the real-time-gestures branch from ab6a0f6 to c81edd0 Compare March 30, 2025 12:57
Android O has added support for building gestures incrementally,
allowing to send input events almost in real-time.

Older versions of Android will continue to wait for gestures to
complete before dispatching them.
@gm-vm gm-vm force-pushed the real-time-gestures branch from c81edd0 to 7882167 Compare March 30, 2025 13:57
@@ -260,7 +269,7 @@ public static void onPointerEvent(int buttonMask, int x, int y, long client) {
// down, was up
if ((buttonMask & (1 << 0)) != 0 && !inputContext.isButtonOneDown) {
inputContext.isButtonOneDown = true;
instance.startGesture(inputContext, x, y);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a regression regarding multi-client input. Please leave the logic client-specific.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I was so focused on getting gestures to work that I didn't even notice that there are multiple InputContext instances. Fixed this here.

void endGesture(InputContext inputContext, int x, int y);
}

private static class LegacyGestureHandler implements GestureHandler {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for these classes IMO, just do the Android version differentiation in the existing handlers .-)

Copy link
Author

@gm-vm gm-vm Mar 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you have in mind exactly? I'm trying to merge the two handlers, but the code is getting a lot more confusing and hard to follow.

Unrelated: I noticed that you were using System.currentTimeMillis(), which is not monotonic. This means that if the system time changes while there is an ongoing gesture the resulting duration will be wrong. SystemClock.elapsedRealtime() is better for measuring intervals.

gm-vm added 3 commits March 30, 2025 17:46
 - Pass InputContext to the constructor to make the GestureHandler
   interface independent.
 - Remove unnecessary instance methods.
 - Duplicate some comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants