Simulating joystick movement using AccessibilityService
Asked Answered
S

1

1

I am trying to simulate tap and joystick movement on screen using AccessibilityService.

In addition i'm getting my input from gamepad controller device. doing tap is ok and done. my problem is simulating joystick movement on screen.

I don't know how can i do continuous touch with GestureDescription, because of time duration that this function requires.

i have used this code for tap:

  public void virtual_touch(int posX, int posY)
{
    Path path = new Path();

    path.moveTo(posX, posY);
    GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
    gestureBuilder.addStroke(new GestureDescription.StrokeDescription(path, 10, 10));
    //gestureBuilder.build();

    boolean isDispatched = dispatchGesture(gestureBuilder.build(), new AccessibilityService.GestureResultCallback()
    {
        @Override
        public void onCompleted(GestureDescription gestureDescription)
        {
            super.onCompleted(gestureDescription);
            MyUtils.Log("onCompleted");
        }

        @Override
        public void onCancelled(GestureDescription gestureDescription)
        {
            super.onCancelled(gestureDescription);
            MyUtils.Log("onCancelled");
        }
    }, null);

    MyUtils.Log("virtual_touch isDispatched : " + isDispatched);
}
Shiftless answered 25/7, 2019 at 6:43 Comment(0)
A
2

For Continue Stroke Use this method may be this will help to you.

willContinue -- continueStroke

public GestureDescription.StrokeDescription continueStroke (Path path, long startTime, long duration, boolean willContinue)

boolean: true if this stroke will be continued by one in the next gesture false otherwise. Continued strokes keep their pointers down when the gesture completes.

Algie answered 25/7, 2019 at 7:19 Comment(3)
thanks for your reply. but willContinue supports api 28 and above.Shiftless
normally these code for API -26 but please try once with api 28Algie
but i want to support android 6 and above. willContinue is for android 8 and above!Shiftless

© 2022 - 2024 — McMap. All rights reserved.