为什么continueStroke函数不起作用

时间:2019-05-31 06:32:54

标签: android

我使用onTouch()记录了手势的所有点,但是StrokeDescription有持续时间。持续时间越短,我看到的手势就越粗糙。当我执行它时,它不是我记录的点。

然后我看到了continueStroke方法。看起来它可以仔细设置每个时间段的时间,但是它不起作用。

谁可以举一个使用continueStroke方法的示例?谢谢。

@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 个答案:

答案 0 :(得分:2)

如果其他任何人搜索此问题:

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);