1

I used onTouch() to record all points of a gesture, but StrokeDescription has a duration. The shorter the duration, the rougher the gesture I can see. When I executed it, it wasn't the points I recorded.

Then I saw the continueStroke method. It looks like it can set the time of each period carefully, but it doesn't work.

Who can give an example of using the continueStroke method? thank you.

@RequiresApi(api = Build.VERSION_CODES.O)
    static public GestureDescription CreateGestureDescription(){
        Path dragRightPath = new Path();
        dragRightPath.moveTo(200, 200);
        dragRightPath.lineTo(400, 200);
        long dragRightDuration = 500L; // 0.5 second

        Path dragDownPath = new Path();
        dragDownPath.moveTo(400, 200);
        dragDownPath.lineTo(400, 400);
        long dragDownDuration = 500L;
        GestureDescription.StrokeDescription rightThenDownDrag =
                new GestureDescription.StrokeDescription(dragRightPath, 0L,
                        dragRightDuration, true);
        rightThenDownDrag.continueStroke(dragDownPath, dragRightDuration,
                dragDownDuration, false);
        GestureDescription.Builder clickBuilder = new GestureDescription.Builder();
        return clickBuilder.addStroke(rightThenDownDrag).build();
    }

1 Answers1

3

In case that anyone else who searches this question:

Path path = new Path();
path.moveTo(200, 200);
path.lineTo(400, 200);
final GestureDescription.StrokeDescription sd = new GestureDescription.StrokeDescription(path, 0, 500, true);
Path path2 = new Path();
path2.moveTo(400, 200);
path2.lineTo(400, 400);
final GestureDescription.StrokeDescription sd2 = sd.continueStroke(path2, 0, 500, false);
HongBaoService.mService.dispatchGesture(new GestureDescription.Builder().addStroke(sd).build(), new AccessibilityService.GestureResultCallback() {
    @Override
    public void onCompleted(GestureDescription gestureDescription) {
        super.onCompleted(gestureDescription);
        HongBaoService.mService.dispatchGesture(new GestureDescription.Builder().addStroke(sd2).build(), null, null);
    }

    @Override
    public void onCancelled(GestureDescription gestureDescription) {
        super.onCancelled(gestureDescription);
    }
}, null);
Particle_G
  • 46
  • 3