Example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat recycle

List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat recycle

Introduction

In this page you can find the example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat recycle.

Prototype

public void recycle() 

Source Link

Document

Return an instance back to be reused.

Usage

From source file:Main.java

/**
 * Recycles the given nodes./*from  w w w  .ja v a 2s.co  m*/
 *
 * @param nodes The nodes to recycle.
 */
public static void recycleNodes(AccessibilityNodeInfoCompat... nodes) {
    if (nodes == null) {
        return;
    }

    for (AccessibilityNodeInfoCompat node : nodes) {
        if (node != null) {
            node.recycle();
        }
    }
}

From source file:Main.java

/**
 * Recycles the given nodes./*from  ww  w. j a v a 2  s .  c o m*/
 *
 * @param nodes The nodes to recycle.
 */
public static void recycleNodes(Collection<AccessibilityNodeInfoCompat> nodes) {
    if (nodes == null) {
        return;
    }

    for (AccessibilityNodeInfoCompat node : nodes) {
        if (node != null) {
            node.recycle();
        }
    }

    nodes.clear();
}

From source file:com.googlecode.eyesfree.brailleback.DisplaySpans.java

/**
 * Recycles objects owned by the spannable.  In particular, any
 * accessibility nodes that have been associated with {@code spannable}
 * are recycled and removed./*from w w w .  j  a va2  s.  co m*/
 */
public static void recycleSpans(CharSequence chars) {
    if (!(chars instanceof Spannable)) {
        return;
    }
    Spannable spannable = (Spannable) chars;
    AccessibilityNodeInfoCompat[] nodes = spannable.getSpans(0, spannable.length(),
            AccessibilityNodeInfoCompat.class);
    for (AccessibilityNodeInfoCompat node : nodes) {
        node.recycle();
        spannable.removeSpan(node);
    }
}

From source file:com.googlecode.eyesfree.utils.TreeDebug.java

/**
 * Logs the tree using the input node as the root.
 *///from  ww  w .jav a2s .c om
public static void logNodeTree(AccessibilityNodeInfoCompat node) {
    if (node == null) {
        return;
    }

    HashSet<AccessibilityNodeInfoCompat> seen = new HashSet<AccessibilityNodeInfoCompat>();
    logNodeTree(AccessibilityNodeInfoCompat.obtain(node), "", seen);
    for (AccessibilityNodeInfoCompat n : seen) {
        n.recycle();
    }
}

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

/**
 * Logs the tree using the input node as the root.
 */// w w w .j ava 2s .  c o m
public static void logNodeTree(AccessibilityNodeInfoCompat node) {
    if (node == null) {
        return;
    }

    HashSet<AccessibilityNodeInfoCompat> seen = new HashSet<>();
    logNodeTree(AccessibilityNodeInfoCompat.obtain(node), "", seen);
    for (AccessibilityNodeInfoCompat n : seen) {
        n.recycle();
    }
}

From source file:Main.java

private static AccessibilityNodeInfoCompat refreshFromChild(AccessibilityNodeInfoCompat node) {
    if (node.getChildCount() > 0) {
        AccessibilityNodeInfoCompat firstChild = node.getChild(0);
        if (firstChild != null) {
            AccessibilityNodeInfoCompat parent = firstChild.getParent();
            firstChild.recycle();
            if (node.equals(parent)) {
                return parent;
            } else {
                recycleNodes(parent);//from ww w.  java2s .  c o  m
            }
        }
    }
    return null;
}

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

/**
 * Determines whether or not the given node contains native web content (and not ChromeVox).
 *
 * @param node The node to evaluate/*from  w ww . java  2 s  .  c  o m*/
 * @return {@code true} if the node contains native web content, {@code false} otherwise
 */
public static boolean hasNativeWebContent(AccessibilityNodeInfoCompat node) {
    if (node == null) {
        return false;
    }

    if (!supportsWebActions(node)) {
        return false;
    }

    // ChromeVox does not have sub elements, so if the parent element also has web content
    // this cannot be ChromeVox.
    AccessibilityNodeInfoCompat parent = node.getParent();
    if (supportsWebActions(parent)) {
        if (parent != null) {
            parent.recycle();
        }
        return true;
    }

    if (parent != null) {
        parent.recycle();
    }

    // ChromeVox never has child elements
    return node.getChildCount() > 0;
}

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

/**
 * Determines whether or not the given node contains ChromeVox content.
 *
 * @param node The node to evaluate/*from   ww  w.ja va2  s.c  om*/
 * @return {@code true} if the node contains ChromeVox content, {@code false} otherwise
 */
public static boolean hasLegacyWebContent(AccessibilityNodeInfoCompat node) {
    if (node == null) {
        return false;
    }

    // TODO: Need better checking for native versus legacy web content.
    // Right now Firefox is accidentally treated as legacy web content using the current
    // detection routines; the `isNodeFromFirefox` check blacklists any Firefox that supports
    // the native web actions from being treated as "legacy" content.
    // Once we have resolved this issue, remove the `isNodeFromFirefox` disjunct from the check.
    if (!supportsWebActions(node) || isNodeFromFirefox(node)) {
        return false;
    }

    // ChromeVox does not have sub elements, so if the parent element also has web content
    // this cannot be ChromeVox.
    AccessibilityNodeInfoCompat parent = node.getParent();
    if (supportsWebActions(parent)) {
        if (parent != null) {
            parent.recycle();
        }

        return false;
    }

    if (parent != null) {
        parent.recycle();
    }

    // ChromeVox never has child elements
    return node.getChildCount() == 0;
}

From source file:Main.java

private static AccessibilityNodeInfoCompat refreshFromParent(AccessibilityNodeInfoCompat node) {
    AccessibilityNodeInfoCompat parent = node.getParent();
    if (parent != null) {
        try {/*from  w  w w .  j  ava2  s  .  co  m*/
            int childCount = parent.getChildCount();
            for (int i = 0; i < childCount; ++i) {
                AccessibilityNodeInfoCompat child = parent.getChild(i);
                if (node.equals(child)) {
                    return child;
                }
                recycleNodes(child);
            }
        } finally {
            parent.recycle();
        }
    }
    return null;
}

From source file:com.googlecode.eyesfree.brailleback.FocusFinder.java

private static AccessibilityNodeInfoCompat findFirstFocusableDescendantInternal(
        AccessibilityNodeInfoCompat root, Context context, HashSet<AccessibilityNodeInfoCompat> seenNodes) {
    for (int i = 0, end = root.getChildCount(); i < end; ++i) {
        AccessibilityNodeInfoCompat child = root.getChild(i);
        if (child == null) {
            continue;
        }// w ww.j  av a 2  s.co  m
        if (AccessibilityNodeInfoUtils.shouldFocusNode(context, child)) {
            return child;
        }
        if (!seenNodes.add(child)) {
            LogUtils.log(FocusFinder.class, Log.ERROR, "Cycle in node tree");
            child.recycle();
            return null;
        }
        AccessibilityNodeInfoCompat n = findFirstFocusableDescendantInternal(child, context, seenNodes);
        if (n != null) {
            return n;
        }
    }
    return null;
}