【问题标题】:Why the continueStroke function is not work为什么 continueStroke 函数不起作用
【发布时间】:2023-03-15 04:50:01
【问题描述】:

我使用 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();
    }

【问题讨论】:

    标签: android


    【解决方案1】:

    如果其他人搜索此问题:

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

    【讨论】:

      猜你喜欢
      • 2014-08-06
      • 2015-02-20
      • 2021-08-20
      • 2021-07-25
      • 2013-08-26
      • 2011-11-13
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多