StrokeDescription的continueStroke这个方法根本就用不了啊,想用MyAccessibilityService模拟手势

hellengoodd 2019-06-01 11:09:05
我用onTouch() 记录了所有手势点击的点, 然后用MyAccessibilityService里的dispatchGesture.模拟我记录的手势,但是StrokeDescription里的duration这个参数貌似会把这些点的距离根据时间平均掉. duaration时间越短,得到的手势路径就越不符合我记录的, 根本就不是我记录的那些点,中间好多点都被自动删除了,而且我记录的路径点跟点的时间都不一样,但是StrokeDescription里只能传入整个手势的总时间,不能插入路径中两个点之间的时间,后来我就发现了continueStroke 这个方法,发现这个方法根本就不工作,下面是我用来测试这个方法的代码,各位大佬麻烦帮看看,我google了下几乎没人用这个方法,我都怀疑android api的开发人员把这个方法遗忘了。。。


@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();
}


而且,我发现我在slackoverflow问的好几个问题从来都没人回答过,不知道是啥原因。。。

谢谢各位大佬,老外不爱我希望国人爱我~~
...全文
885 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hellengoodd 2019-12-03
  • 打赏
  • 举报
回复
引用 1 楼 王能 的回复:
这个貌似是无解的,谷歌应该限制了每秒只能发送多少个点,所以时间越短手势越不对。 还有那个continueStroke你用错了,如下

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);
你说的是对的,太感谢了!!还以为没人理我了
王能 2019-06-03
  • 打赏
  • 举报
回复 2
这个貌似是无解的,谷歌应该限制了每秒只能发送多少个点,所以时间越短手势越不对。 还有那个continueStroke你用错了,如下

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

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧