问题
I want to perform multiple swipe when "Clicked" using AccessibilityService
. I already tried this but it doesn't perform multiple swipe. Any help is much appreciated. It is working but only one swipe is registered.
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent)
{
final int eventType= accessibilityEvent.getEventType();
switch (eventType)
{
case 1:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
{
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int middleYValue = displayMetrics.heightPixels / 2;
final int leftSideOfScreen = displayMetrics.widthPixels / 4;
final int rightSizeOfScreen = leftSideOfScreen * 3;
GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
Path path = new Path();
if (accessibilityEvent.getText() != null && accessibilityEvent.getText().toString().contains("1"))
{
path.moveTo(rightSizeOfScreen, middleYValue);
path.lineTo(leftSideOfScreen, middleYValue);
}
else
{
path.moveTo(leftSideOfScreen, middleYValue);
path.lineTo(rightSizeOfScreen, middleYValue);
}
gestureBuilder.addStroke(new GestureDescription.StrokeDescription(path, 100, 50));
gestureBuilder.addStroke(new GestureDescription.StrokeDescription(path, 100, 50));
for (int i=0;i<5;++i)
{
swipe(gestureBuilder.build());
}
}
}
}
回答1:
http://jatimqq.winpublic
void onAccessibilityEvent(AccessibilityEvent accessibilityEvent)
{
final int eventType= accessibilityEvent.getEventType();
switch (eventType)
{
case 1:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
{
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int middleYValue = displayMetrics.heightPixels / 2;
final int leftSideOfScreen = displayMetrics.widthPixels / 4;
final int rightSizeOfScreen = leftSideOfScreen * 3;
GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
Path path = new Path();
if (accessibilityEvent.getText() != null && accessibilityEvent.getText().toString().contains("1"))
{
path.moveTo(rightSizeOfScreen, middleYValue);
path.lineTo(leftSideOfScreen, middleYValue);
}
else
{
path.moveTo(leftSideOfScreen, middleYValue);
path.lineTo(rightSizeOfScreen, middleYValue);
}
gestureBuilder.addStroke(new GestureDescription.StrokeDescription(path, 100, 50));
gestureBuilder.addStroke(new GestureDescription.StrokeDescription(path, 100, 50));
for (int i=0;i<5;++i)
{
swipe(gestureBuilder.build());
}
}
}
}
来源:https://stackoverflow.com/questions/53356373/how-to-perform-multiple-swipe-using-accessibilityservice