List of usage examples for android.view.accessibility AccessibilityWindowInfo getRoot
public AccessibilityNodeInfo getRoot()
From source file:com.android.utils.compat.accessibilityservice.AccessibilityServiceCompatUtils.java
/** * @return root node of the window that currently has accessibility focus *//*from w w w. j a va2s. c o m*/ public static AccessibilityNodeInfoCompat getRootInAccessibilityFocusedWindow(AccessibilityService service) { if (service == null) { return null; } AccessibilityNodeInfo focusedRoot = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { List<AccessibilityWindowInfo> windows = service.getWindows(); // 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 = accessibilityFocusedWindow.getRoot(); } } if (focusedRoot == null) { focusedRoot = service.getRootInActiveWindow(); } if (focusedRoot == null) { return null; } return new AccessibilityNodeInfoCompat(focusedRoot); }
From source file:com.android.screenspeak.eventprocessor.ProcessorVolumeStream.java
private AccessibilityNodeInfoCompat findInputFocus() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { List<AccessibilityWindowInfo> awis = mService.getWindows(); for (AccessibilityWindowInfo awi : awis) { if (awi.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD) continue; AccessibilityNodeInfo info = awi.getRoot(); if (info == null) continue; AccessibilityNodeInfoCompat root = new AccessibilityNodeInfoCompat(awi.getRoot()); AccessibilityNodeInfoCompat focus = root.findFocus(AccessibilityNodeInfo.FOCUS_INPUT); if (focus != null) { if (!root.equals(focus)) root.recycle();/*from w ww. ja v a 2 s . c o m*/ return focus; } else { root.recycle(); } } return null; } else { AccessibilityNodeInfo info = mService.getRootInActiveWindow(); if (info == null) return null; AccessibilityNodeInfoCompat root = new AccessibilityNodeInfoCompat(info); AccessibilityNodeInfoCompat focus = root.findFocus(AccessibilityNodeInfoCompat.FOCUS_INPUT); if (focus != null && !focus.equals(root)) root.recycle(); return focus; } }
From source file:com.android.talkback.eventprocessor.ProcessorScreen.java
private CharSequence getWindowTitleForFeedback(int windowId) { CharSequence title = getWindowTitle(windowId); // Try to fall back to application label if window title is not available. if (title == null) { CharSequence packageName = mWindowToPackageName.get(windowId); // Try to get package name from accessibility window info if it's not in the map. if (packageName == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { for (AccessibilityWindowInfo window : mService.getWindows()) { if (window.getId() == windowId) { AccessibilityNodeInfo rootNode = window.getRoot(); if (rootNode != null) { packageName = rootNode.getPackageName(); rootNode.recycle(); }//from w w w.j a v a 2 s . c o m } } } if (packageName != null) { title = mService.getApplicationLabel(packageName); } } title = WindowManager.formatWindowTitleForFeedback(title, mService); if (isAlertDialog(windowId)) { title = mService.getString(R.string.template_alert_dialog_template, title); } return title; }
From source file:com.android.utils.AccessibilityNodeInfoUtils.java
/** * Returns a fresh copy of node by traversing the given window for a similar node. * For example, the node that you want might be in a popup window that has closed and re-opened, * causing the accessibility IDs of its views to be different. * Note: you must recycle the node that is returned from this method. *///from w w w. jav a 2 s .c om public static AccessibilityNodeInfoCompat refreshNodeFuzzy(final AccessibilityNodeInfoCompat node, AccessibilityWindowInfo window) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return null; } if (window == null || node == null) { return null; } AccessibilityNodeInfo root = window.getRoot(); if (root == null) { return null; } NodeFilter similarFilter = new NodeFilter() { @Override public boolean accept(AccessibilityNodeInfoCompat other) { return other != null && TextUtils.equals(node.getText(), other.getText()); } }; AccessibilityNodeInfoCompat rootCompat = new AccessibilityNodeInfoCompat(root); try { return getMatchingDescendant(rootCompat, similarFilter); } finally { rootCompat.recycle(); } }
From source file:com.android.screenspeak.controller.CursorControllerApp.java
private boolean navigateToNextApplicationWindow(int direction) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { WindowManager windowsManager = new WindowManager(); windowsManager.setWindows(mService.getWindows()); if (!windowsManager.isApplicationWindowFocused()) { return false; }/*from w w w . j a va2 s .c o m*/ AccessibilityWindowInfo currentWindow = windowsManager.getCurrentWindow(); if (currentWindow == null) { return false; } AccessibilityWindowInfo targetWindow = null; AccessibilityWindowInfo pivotWindow = currentWindow; while (!currentWindow.equals(targetWindow)) { switch (direction) { case NodeFocusFinder.SEARCH_FORWARD: targetWindow = windowsManager.getNextWindow(pivotWindow); break; case NodeFocusFinder.SEARCH_BACKWARD: targetWindow = windowsManager.getPreviousWindow(pivotWindow); break; } pivotWindow = targetWindow; if (targetWindow == null) { return false; } if (targetWindow.getType() != AccessibilityWindowInfo.TYPE_APPLICATION) { continue; } AccessibilityNodeInfo windowRoot = targetWindow.getRoot(); if (windowRoot == null) { continue; } AccessibilityNodeInfoCompat compatRoot = new AccessibilityNodeInfoCompat(windowRoot); TraversalStrategy traversalStrategy = new OrderedTraversalStrategy(compatRoot); if (navigateWrapAround(compatRoot, direction, traversalStrategy)) { return true; } } } return false; }
From source file:com.android.talkback.controller.CursorControllerApp.java
private boolean navigateToNextOrPreviousWindow(@TraversalStrategy.SearchDirection int direction, int windowTypeFilter, int focusStrategy, boolean useInputFocusAsPivot, int inputMode) { if (!mIsWindowNavigationAvailable) { return false; }//from w ww .ja v a2 s . c o m WindowManager windowManager = new WindowManager(mService.isScreenLayoutRTL()); windowManager.setWindows(mService.getWindows()); AccessibilityWindowInfo pivotWindow = windowManager.getCurrentWindow(useInputFocusAsPivot); if (pivotWindow == null || !matchWindowType(pivotWindow, windowTypeFilter)) { return false; } AccessibilityWindowInfo targetWindow = pivotWindow; while (true) { @TraversalStrategy.SearchDirection int logicalDirection = TraversalStrategyUtils.getLogicalDirection(direction, mService.isScreenLayoutRTL()); if (logicalDirection == TraversalStrategy.SEARCH_FOCUS_FORWARD) { targetWindow = windowManager.getNextWindow(targetWindow); } else if (logicalDirection == TraversalStrategy.SEARCH_FOCUS_BACKWARD) { targetWindow = windowManager.getPreviousWindow(targetWindow); } else { throw new IllegalStateException("Unknown logical direction"); } if (targetWindow == null || pivotWindow.equals(targetWindow)) { return false; } if (!matchWindowType(targetWindow, windowTypeFilter)) { continue; } AccessibilityNodeInfo windowRoot = targetWindow.getRoot(); if (windowRoot == null) { continue; } AccessibilityNodeInfoCompat compatRoot = new AccessibilityNodeInfoCompat(windowRoot); if (focusStrategy == FOCUS_STRATEGY_RESUME_FOCUS) { if (resumeLastFocus(targetWindow.getId(), inputMode)) { return true; } // If it cannot resume last focus, try to focus the first focusable element. TraversalStrategy traversalStrategy = TraversalStrategyUtils.getTraversalStrategy(compatRoot, TraversalStrategy.SEARCH_FOCUS_FORWARD); if (navigateWrapAround(compatRoot, TraversalStrategy.SEARCH_FOCUS_FORWARD, traversalStrategy, inputMode)) { return true; } } else { TraversalStrategy traversalStrategy = TraversalStrategyUtils.getTraversalStrategy(compatRoot, direction); if (navigateWrapAround(compatRoot, direction, traversalStrategy, inputMode)) { return true; } } } }