使用无障碍服务清理SeekBar

问题描述 投票:0回答:1

我正在尝试使用Accessibility Services清理第三方应用程序的搜索栏。这就是我用来擦洗的东西。

 val arguments = Bundle()
 arguments.putFloat(AccessibilityNodeInfo.ACTION_ARGUMENT_PROGRESS_VALUE, 50.0.toFloat())
 seekBarNode?.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_PROGRESS.id, arguments)

因为我正在整理视频,所以SeekBar位置发生了变化,但是内容没有发生变化

有人知道这里的问题吗?还是可以使用无障碍服务来擦洗第三方SeekBar的替代方法?

而且,我已经读过关于GestureDescription进行滑动的信息。但是我不知道如何使用它来执行SeekBar清理。

android seekbar accessibilityservice
1个回答
0
投票

尝试使用dispatchGesture并单击搜索栏的中心:

fun AccessibilityService.tapCenterOfNode(node: AccessibilityNodeInfo, onDone: (Boolean) -> Any){
    this.dispatchPath(
        drawPath = pathOnPoint(node.centerInScreen()),
        pathDuration = 10,
        onDone = { 
            success -> Log.d("dispatch", "success? $success")
        }
    )
}

fun AccessibilityService.dispatchPath(drawPath: Path, pathDuration: Long, onDone: (Boolean) -> Any) {
    val stroke = GestureDescription.StrokeDescription(drawPath, 0, pathDuration)
    val gesture = GestureDescription.Builder().addStroke(stroke).build()

    this.dispatchGesture(gesture, object : AccessibilityService.GestureResultCallback() {
        override fun onCompleted(gestureDescription: GestureDescription) {
            super.onCompleted(gestureDescription)
            onDone(true)
        }

        override fun onCancelled(gestureDescription: GestureDescription) {
            super.onCancelled(gestureDescription)
            onDone(false)
        }
    }, null)
}

fun AccessibilityNodeInfo.centerInScreen(): Pair<Float, Float> = 
    Pair(this.getBoundsInScreen().exactCenterX(), this.getBoundsInScreen().exactCenterY())

fun AccessibilityNodeInfo.getBoundsInScreen(): Rect {
    val rect = Rect()
    getBoundsInScreen(rect)
    return rect
}

fun pathOnPoint(point: Pair<Float, Float>) = Path().apply {
    val (x, y) = point
    moveTo(x, y)
    lineTo(x, y)
}
© www.soinside.com 2019 - 2024. All rights reserved.