Java Code Examples for android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#equals()

The following examples show how to use android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#equals() . 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: AccessibilityNodeInfoUtils.java    From brailleback with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    }
    return null;
}
 
Example 2
Source File: AccessibilityNodeInfoUtils.java    From brailleback with Apache License 2.0 6 votes vote down vote up
private static AccessibilityNodeInfoCompat refreshFromParent(
        AccessibilityNodeInfoCompat node) {
    AccessibilityNodeInfoCompat parent = node.getParent();
    if (parent != null) {
        try {
            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;
}
 
Example 3
Source File: IMENavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
/** Returns true if a self-brailled node is focused. */
private boolean isSelfBrailledFieldFocused() {
    AccessibilityNodeInfoCompat root = null;
    AccessibilityNodeInfoCompat inputFocused = null;
    AccessibilityNodeInfoCompat accessibilityFocused = null;
    try {
        root = AccessibilityServiceCompatUtils.getRootInActiveWindow(
                mAccessibilityService);
        if (root == null) {
            return false;
        }
        inputFocused = root.findFocus(
            AccessibilityNodeInfoCompat.FOCUS_INPUT);
        if (!mSelfBrailleManager.hasContentForNode(inputFocused)) {
            return false;
        }
        accessibilityFocused = root.findFocus(
            AccessibilityNodeInfoCompat.FOCUS_ACCESSIBILITY);
        return inputFocused.equals(accessibilityFocused);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(
            root, inputFocused, accessibilityFocused);
    }
}
 
Example 4
Source File: IMENavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
/** Returns the node with both accessibility and input focus, if any. */
private AccessibilityNodeInfoCompat getFocusedNode() {
    AccessibilityNodeInfoCompat root = null;
    AccessibilityNodeInfoCompat inputFocused = null;
    AccessibilityNodeInfoCompat accessibilityFocused = null;
    try {
        root = AccessibilityServiceCompatUtils.getRootInActiveWindow(
                mAccessibilityService);
        if (root == null) {
            return null;
        }
        inputFocused = root.findFocus(
            AccessibilityNodeInfoCompat.FOCUS_INPUT);
        if (inputFocused == null) {
            return null;
        }
        accessibilityFocused = root.findFocus(
            AccessibilityNodeInfoCompat.FOCUS_ACCESSIBILITY);
        return inputFocused.equals(accessibilityFocused)
            ? inputFocused : null;
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(
            root, accessibilityFocused);
    }
}
 
Example 5
Source File: DefaultNavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
private boolean brailleFocusedNode() {
    AccessibilityNodeInfoCompat focused = getFocusedNode(false);
    if (focused != null) {
        DisplayManager.Content content = mNodeBrailler.brailleNode(
            focused);
        if (focused.equals(mLastFocusedNode.get())
                && (content.getPanStrategy()
                        == DisplayManager.Content.PAN_RESET)) {
            content.setPanStrategy(DisplayManager.Content.PAN_KEEP);
        }
        mDisplayManager.setContent(content);
        mLastFocusedNode.reset(focused);
        return true;
    }
    return false;
}
 
Example 6
Source File: AccessibilityNodeInfoUtils.java    From brailleback with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method for determining if a searching past a particular node will
 * fall off the edge of a scrollable container.
 *
 * @param cursor Node to check.
 * @param direction The direction in which to move from the cursor.
 * @param filter Filter used to validate list-type ancestors.
 * @return {@code true} if focusing search in the specified direction will
 *         fall off the edge of the container.
 */
private static boolean isMatchingEdgeListItem(Context context,
        AccessibilityNodeInfoCompat cursor, int direction, NodeFilter filter) {
    AccessibilityNodeInfoCompat ancestor = null;
    AccessibilityNodeInfoCompat searched = null;
    AccessibilityNodeInfoCompat searchedAncestor = null;

    try {
        ancestor = getMatchingAncestor(null, cursor, filter);
        if (ancestor == null) {
            // Not contained in a scrollable list.
            return false;
        }

        // Search in the specified direction until we find a focusable node.
        // TODO: This happens elsewhere -- make into a single utility method.
        searched = NodeFocusFinder.focusSearch(cursor, direction);
        while ((searched != null)
                && !AccessibilityNodeInfoUtils.shouldFocusNode(context, searched)) {
            final AccessibilityNodeInfoCompat temp = searched;
            searched = NodeFocusFinder.focusSearch(temp, direction);
            temp.recycle();
        }

        if ((searched == null) || searched.equals(ancestor)) {
            // Can't move from this position.
            return true;
        }

        searchedAncestor = getMatchingAncestor(null, searched, filter);
        if (!ancestor.equals(searchedAncestor)) {
            // Moves outside of the scrollable list.
            return true;
        }
    } finally {
        recycleNodes(ancestor, searched, searchedAncestor);
    }

    return false;
}