Java Code Examples for android.accessibilityservice.AccessibilityService#getRootInActiveWindow()
The following examples show how to use
android.accessibilityservice.AccessibilityService#getRootInActiveWindow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessibilityUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 查找符合条件的节点 * @param service {@link AccessibilityService} * @param focus 焦点类型 * @param className 节点所属的类 ( 类名 ) * @return 拥有特定焦点类型的节点 */ @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) public static AccessibilityNodeInfo findFocus(final AccessibilityService service, final int focus, final String className) { if (service == null || className == null) return null; // 获取根节点 AccessibilityNodeInfo nodeInfo = service.getRootInActiveWindow(); // 取得当前激活窗体的根节点 if (nodeInfo == null) return null; // 通过指定的焦点类型找到当前的节点 AccessibilityNodeInfo node = nodeInfo.findFocus(focus); // 防止为 null if (node != null) { // 判断是否符合的类型 if (node.getClassName().equals(className) && node.isEnabled()) { return node; } } return null; }
Example 2
Source File: AccessibilityUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 查找符合条件的节点 * @param service {@link AccessibilityService} * @param text 文本内容 ( 搜索包含该文本内容的节点 ) * @param className 节点所属的类 ( 类名 ) * @return 包含该文本内容, 且属于指定类的节点集合 */ @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) public static List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(final AccessibilityService service, final String text, final String className) { if (service == null || text == null || className == null) return null; List<AccessibilityNodeInfo> lists = new ArrayList<>(); // 获取根节点 AccessibilityNodeInfo nodeInfo = service.getRootInActiveWindow(); // 取得当前激活窗体的根节点 if (nodeInfo == null) return lists; // 通过文字找到当前的节点 List<AccessibilityNodeInfo> nodes = nodeInfo.findAccessibilityNodeInfosByText(text); for (int i = 0; i < nodes.size(); i++) { AccessibilityNodeInfo node = nodes.get(i); // 判断是否符合的类型 if (node.getClassName().equals(className) && node.isEnabled()) { // 保存符合条件 lists.add(node); } } return lists; }
Example 3
Source File: AccessibilityUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 查找符合条件的节点 * @param service {@link AccessibilityService} * @param id viewId * @param className 节点所属的类 ( 类名 ) * @return 等于 viewId, 且属于指定类的节点集合 */ @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) public static List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewId(final AccessibilityService service, final String id, final String className) { if (service == null || id == null || className == null) return null; List<AccessibilityNodeInfo> lists = new ArrayList<>(); // 获取根节点 AccessibilityNodeInfo nodeInfo = service.getRootInActiveWindow(); // 取得当前激活窗体的根节点 if (nodeInfo == null) return lists; // 通过 id 找到当前的节点 List<AccessibilityNodeInfo> nodes = nodeInfo.findAccessibilityNodeInfosByViewId(id); for (int i = 0; i < nodes.size(); i++) { AccessibilityNodeInfo node = nodes.get(i); // 判断是否符合的类型 if (node.getClassName().equals(className) && node.isEnabled()) { // 保存符合条件 lists.add(node); } } return lists; }
Example 4
Source File: AccessUtil.java From pc-android-controller-android with Apache License 2.0 | 6 votes |
/** * 返回事件 */ public static void performBack(final AccessibilityService service, AccessibilityNodeInfo nodeInfo) { CharSequence packageName = nodeInfo.getPackageName(); if (!(packageName+"").equals(WECHAT_PACKAGE_NAME)) { L.d("不是微信,不能后退 " + packageName); return; } if (service == null) { L.e("performBackWithDelay service is null"); return; } if (service.getRootInActiveWindow() == null) { L.e("performBackWithDelay rootNode is null"); return; } L.d("performBack Reboot "); service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK); }
Example 5
Source File: AccessibilityUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 查找符合条件的节点 * @param service {@link AccessibilityService} * @param focus 焦点类型 * @return 拥有特定焦点类型的节点 */ @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) public static AccessibilityNodeInfo findFocus(final AccessibilityService service, final int focus) { if (service == null) return null; // 获取根节点 AccessibilityNodeInfo nodeInfo = service.getRootInActiveWindow(); // 取得当前激活窗体的根节点 if (nodeInfo == null) return null; // 通过指定的焦点类型找到当前的节点 return nodeInfo.findFocus(focus); }
Example 6
Source File: AccessibilityUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 查找符合条件的节点 * @param service {@link AccessibilityService} * @param text 文本内容 ( 搜索包含该文本内容的节点 ) * @return 包含该文本内容的节点集合 */ @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) public static List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(final AccessibilityService service, final String text) { if (service == null || text == null) return null; // 获取根节点 AccessibilityNodeInfo nodeInfo = service.getRootInActiveWindow(); // 取得当前激活窗体的根节点 if (nodeInfo == null) return null; // 通过文字找到当前的节点 return nodeInfo.findAccessibilityNodeInfosByText(text); }
Example 7
Source File: AccessibilityUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 查找符合条件的节点 * @param service {@link AccessibilityService} * @param id viewId * @return 等于 viewId 的节点集合 */ @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) public static List<AccessibilityNodeInfo> findAccessibilityNodeInfosByViewId(final AccessibilityService service, final String id) { if (service == null || id == null) return null; // 获取根节点 AccessibilityNodeInfo nodeInfo = service.getRootInActiveWindow(); // 取得当前激活窗体的根节点 if (nodeInfo == null) return null; // 通过 id 找到当前的节点 return nodeInfo.findAccessibilityNodeInfosByViewId(id); }
Example 8
Source File: AccessUtil.java From pc-android-controller-android with Apache License 2.0 | 5 votes |
/** * 返回事件 */ public static void performHome(final AccessibilityService service) { if (service == null) { L.e("performBackWithDelay service is null"); return; } if (service.getRootInActiveWindow() == null) { L.e("performBackWithDelay rootNode is null"); return; } L.d("performHome"); service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME); }
Example 9
Source File: FocusFinder.java From brailleback with Apache License 2.0 | 5 votes |
public static AccessibilityNodeInfoCompat getFocusedNode( AccessibilityService service, boolean fallbackOnRoot) { AccessibilityNodeInfo root = service.getRootInActiveWindow(); AccessibilityNodeInfo focused = null; try { AccessibilityNodeInfo ret = null; if (root != null) { focused = root.findFocus( AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (focused != null && focused.isVisibleToUser()) { ret = focused; focused = null; } else if (fallbackOnRoot) { ret = root; root = null; } } else { LogUtils.log(service, Log.ERROR, "No current window root"); } if (ret != null) { return new AccessibilityNodeInfoCompat(ret); } } finally { if (root != null) { root.recycle(); } if (focused != null) { focused.recycle(); } } return null; }
Example 10
Source File: FocusFinder.java From talkback with Apache License 2.0 | 5 votes |
public static @Nullable AccessibilityNodeInfoCompat getFocusedNode( AccessibilityService service, boolean fallbackOnRoot) { AccessibilityNodeInfo root = service.getRootInActiveWindow(); AccessibilityNodeInfo focused = null; try { AccessibilityNodeInfo ret = null; if (root != null) { focused = root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (focused != null && focused.isVisibleToUser()) { ret = focused; focused = null; } else if (fallbackOnRoot) { ret = root; root = null; } } else { LogUtils.e(TAG, "No current window root"); } if (ret != null) { return AccessibilityNodeInfoUtils.toCompat(ret); } } finally { if (root != null) { root.recycle(); } if (focused != null) { focused.recycle(); } } return null; }
Example 11
Source File: AccessibilityServiceCompatUtils.java From talkback with Apache License 2.0 | 5 votes |
/** @return root node of the Application window */ public static AccessibilityNodeInfoCompat getRootInActiveWindow(AccessibilityService service) { if (service == null) { return null; } AccessibilityNodeInfo root = service.getRootInActiveWindow(); if (root == null) { return null; } return AccessibilityNodeInfoUtils.toCompat(root); }
Example 12
Source File: AccessibilityServiceCompatUtils.java From talkback with Apache License 2.0 | 5 votes |
/** @return root node of the window that currently has accessibility focus */ public static @Nullable AccessibilityNodeInfoCompat getRootInAccessibilityFocusedWindow( AccessibilityService service) { if (service == null) { return null; } AccessibilityNodeInfo focusedRoot = null; List<AccessibilityWindowInfo> windows = getWindows(service); // Create window manager with fake value of isInRTL = false. This is okay here since // isInRTL will not change the result of getCurrentWindow. WindowManager manager = new WindowManager(false /* isInRTL */); manager.setWindows(windows); AccessibilityWindowInfo accessibilityFocusedWindow = manager.getCurrentWindow(false /* useInputFocus */); if (accessibilityFocusedWindow != null) { focusedRoot = AccessibilityWindowInfoUtils.getRoot(accessibilityFocusedWindow); } if (focusedRoot == null) { focusedRoot = service.getRootInActiveWindow(); } if (focusedRoot == null) { return null; } return AccessibilityNodeInfoUtils.toCompat(focusedRoot); }
Example 13
Source File: AccessibilityServiceCompatUtils.java From talkback with Apache License 2.0 | 5 votes |
public static AccessibilityWindowInfo getActiveWidow(AccessibilityService service) { if (service == null) { return null; } AccessibilityNodeInfo rootInActiveWindow = service.getRootInActiveWindow(); if (rootInActiveWindow == null) { return null; } AccessibilityWindowInfo window = AccessibilityNodeInfoUtils.getWindow(rootInActiveWindow); rootInActiveWindow.recycle(); return window; }