0

I am trying to scroll down continuously using gesture description using accessibility. Here is my code for swipe down

        val displayMetrics = resources.displayMetrics
        val height : Int = displayMetrics.heightPixels;
        val top : Float = height*0.25.toFloat()
        val bottom :Float = height *0.75.toFloat()
        
        val swipePath = Path()
        swipePath.moveTo(top, bottom)
        swipePath.lineTo(top, top)
        val gestureBuilder = GestureDescription.Builder()
        gestureBuilder.addStroke(GestureDescription.StrokeDescription(swipePath, 0, 1000))
        dispatchGesture(gestureBuilder.build(), null, null)

Please help.

1 Answers1

0

path.moveTo() and path.lineTo() both takes two arguments that are x and y coordinates and to swipe vertically x coordinate of start and end point should be same. You are taking x coordinate from height instead of width and that may create other problems like point outside the screen also. so I modified your code a little bit

val displayMetrics = resources.displayMetrics
val height : Int = displayMetrics.heightPixels
val xCenter: Float = displayMetrics.widthPixels.toFloat()/2
val top : Float = height*0.25.toFloat()
val bottom :Float = height *0.75.toFloat()

val swipePath = Path()
swipePath.moveTo(xCenter, bottom)
swipePath.lineTo(xCenter, top)
val gestureBuilder = GestureDescription.Builder()
gestureBuilder.addStroke(GestureDescription.StrokeDescription(swipePath, 0, 1000))
dispatchGesture(gestureBuilder.build(), null, null)