Example usage for android.view.accessibility AccessibilityWindowInfo getAnchor

List of usage examples for android.view.accessibility AccessibilityWindowInfo getAnchor

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityWindowInfo getAnchor.

Prototype

public AccessibilityNodeInfo getAnchor() 

Source Link

Document

Gets the node that anchors this window to another.

Usage

From source file:com.android.utils.WindowManager.java

/**
 * Gets the window whose anchor equals the given node.
 *///  w w w  .  ja  va 2s  .co m
public AccessibilityWindowInfo getAnchoredWindow(@Nullable AccessibilityNodeInfoCompat targetAnchor) {
    if (!BuildCompat.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.getInfo())) {
                        return window;
                    }
                } finally {
                    anchor.recycle();
                }
            }
        }
    }

    return null;
}

From source file:com.android.utils.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.
 *//*from w  w w. ja  v a  2 s .  c om*/
public static AccessibilityNodeInfoCompat getAnchor(@Nullable AccessibilityNodeInfoCompat node) {
    if (!BuildCompat.isAtLeastN()) {
        return null;
    }

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

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

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

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

    return new AccessibilityNodeInfoCompat(nativeAnchor);
}