android.view.accessibility.AccessibilityWindowInfo#getAnchor ( )源码实例Demo

下面列出了android.view.accessibility.AccessibilityWindowInfo#getAnchor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: talkback   文件: WindowManager.java
/** 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;
}
 
源代码2 项目: talkback   文件: AccessibilityNodeInfoUtils.java
/**
 * 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);
}