Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dispatch multi touch gestures using AccessibilityService (disptachGesture)

As we know that Android O.S. supports **multi finger gestures **. I want to develop an app that dispatches complex gesture for user. I am able to capture the motion events and dispatch gestures which are made only of one finger.

But if the user uses multiple pointers (fingers) for making a gesture, then I am able to capture them but then how can I dispatch them using Accessibility Service (dispatchGesture) function.

Any help would be most welcomed. Thanks

like image 343
Just a Person Avatar asked Sep 11 '25 15:09

Just a Person


1 Answers

So, actually to dispatch multi finger gestures using accessibility services we can use strokes for each fingers. For ex- to dispatch a two finger gesture it would be required to add two gesture stroke to gesture description and then dispatch it.

Double swipe up gesture as an example

Point position=new Point(100,10);
GestureDescription.Builder builder = new GestureDescription.Builder();
Path p = new Path();
Path q = new Path();
//For first finger
p.moveTo(position.x, position.y);
p.lineTo(position.x, position.y+300); 

//For second finger
q.moveTo(position.x, position.y);
q.lineTo(position.x + 50, position.y+300); 

//Two strokes for two fingers
builder.addStroke(new GestureDescription.StrokeDescription(p, 100L, 50L));
builder.addStroke(new GestureDescription.StrokeDescription(q, 100L, 50L));
GestureDescription gesture = builder.build();
boolean isDispatched = dispatchGesture(gesture,gestureResultCallback,null);
like image 151
Just a Person Avatar answered Sep 14 '25 05:09

Just a Person