Java Code Examples for android.view.accessibility.AccessibilityWindowInfo#getAnchor()

The following examples show how to use android.view.accessibility.AccessibilityWindowInfo#getAnchor() . 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: WindowManager.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** Gets the window whose anchor equals the given node. */
public @Nullable AccessibilityWindowInfo getAnchoredWindow(
    @Nullable AccessibilityNodeInfoCompat targetAnchor) {
  if (!BuildVersionUtils.isAtLeastN() || targetAnchor == null) {
    return null;
  }

  int windowCount = mWindows.size();
  for (int i = 0; i < windowCount; ++i) {
    AccessibilityWindowInfo window = mWindows.get(i);
    if (window != null) {
      AccessibilityNodeInfo anchor = window.getAnchor();
      if (anchor != null) {
        try {
          if (anchor.equals(targetAnchor.unwrap())) {
            return window;
          }
        } finally {
          anchor.recycle();
        }
      }
    }
  }

  return null;
}
 
Example 2
Source File: AccessibilityNodeInfoUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the node to which the given node's window is anchored, if there is an anchor. Note: you
 * must recycle the node that is returned from this method.
 */
public static AccessibilityNodeInfoCompat getAnchor(@Nullable AccessibilityNodeInfoCompat node) {
  if (!BuildVersionUtils.isAtLeastN()) {
    return null;
  }

  if (node == null) {
    return null;
  }

  AccessibilityNodeInfo nativeNode = node.unwrap();
  if (nativeNode == null) {
    return null;
  }

  AccessibilityWindowInfo nativeWindow = getWindow(nativeNode);
  if (nativeWindow == null) {
    return null;
  }

  AccessibilityNodeInfo nativeAnchor = nativeWindow.getAnchor();
  if (nativeAnchor == null) {
    return null;
  }

  return AccessibilityNodeInfoUtils.toCompat(nativeAnchor);
}