简体   繁体   English

Android 无障碍服务同时与多个开关交互

[英]Android Accessibility service interact with numerous switches at once

I was wondering if there is a good way to turn on/off numerous switches at once using Accessibility service.我想知道是否有一种使用辅助功能服务同时打开/关闭多个开关的好方法。

So basically I have a view that contains a RecyclerView that has about 40 switches in it and I need a way to switch them on/off as fast as possible.所以基本上我有一个包含 RecyclerView 的视图,其中有大约 40 个开关,我需要一种方法来尽快打开/关闭它们。 Here is what I tried.这是我尝试过的。

public static void scrollView(final AccessibilityNodeInfo nodeInfo) {

    if (nodeInfo == null) return;

    if (nodeInfo.isScrollable()) {
        if (nodeInfo.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD)) {
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    turnOffSwitches(nodeInfo);
                }
            }, 1000);

        }
    }
}

public static void turnOffSwitches(final AccessibilityNodeInfo parentView) {
    if (parentView.getClassName().equals("android.support.v7.widget.RecyclerView")) {
        for (int i = 0; i < parentView.getChildCount(); i++) {
            final AccessibilityNodeInfo child = parentView.getChild(i);
            final Boolean isLasteOne = (i == parentView.getChildCount() - 1);
            child.performAction(AccessibilityNodeInfo.ACTION_CLICK);
            if (isLasteOne) {
                scrollView(parentView);
            }
        }
    }
}

I even tried introducing a delay between ACTION_CLICK actions that helped a bit but did not solve my problem fully.我什至尝试在 ACTION_CLICK 操作之间引入延迟,这有点帮助但没有完全解决我的问题。 So the issue that I am having is that not all switches get turned off.所以我遇到的问题是并非所有开关都关闭。 It seems like there is a limit on how fast this can be done.这样做的速度似乎是有限的。 So my question is, is there a better way to do this?所以我的问题是,有没有更好的方法来做到这一点?

ACTION_SCROLL_FORWARD - it's not paging just scrolling some portion of your whole matrix of elements and some visible are already switched to the state so in your next loop you are trying to click on those which were already swiched (next visible area overlaps with previous one) ACTION_SCROLL_FORWARD - 它不是分页,只是滚动整个元素矩阵的一部分,一些可见的已经切换到状态,所以在你的下一个循环中,你试图点击那些已经切换的(下一个可见区域与前一个重叠)

  1. either check the state on/off - if the view is not already at the desired state before changing it要么检查状态开/关 - 如果视图在更改之前尚未处于所需状态

  2. or check event.getScrollX() and event.getScrollY() if action was not already performed in those bounds或检查 event.getScrollX() 和 event.getScrollY() 如果尚未在这些范围内执行操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM