我用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问的好几个问题从来都没人回答过,不知道是啥原因谢谢各位大佬,老外不爱我希望国人爱我~~
@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问的好几个问题从来都没人回答过,不知道是啥原因谢谢各位大佬,老外不爱我希望国人爱我~~
还有那个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);