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

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

Introduction

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

Prototype

public void getBoundsInScreen(Rect outBounds) 

Source Link

Document

Gets the node bounds in screen coordinates.

Usage

From source file:Main.java

public static Rect getBoundsInScreen(AccessibilityNodeInfoCompat nodeInfo) {
    Rect rect = new Rect();
    nodeInfo.getBoundsInScreen(rect);
    return rect;// ww  w.j  av a 2s. c om
}

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

/**
 * Gets a description of the properties of a node.
 *///from w ww.j a  v a2 s  .  co m
private static CharSequence nodeDebugDescription(AccessibilityNodeInfoCompat node) {
    StringBuilder sb = new StringBuilder();
    sb.append(node.getWindowId());

    if (node.getClassName() != null) {
        appendSimpleName(sb, node.getClassName());
    } else {
        sb.append("??");
    }

    if (!node.isVisibleToUser()) {
        sb.append(":invisible");
    }

    Rect rect = new Rect();
    node.getBoundsInScreen(rect);
    sb.append(":");
    sb.append("(").append(rect.left).append(", ").append(rect.top).append(" - ").append(rect.right).append(", ")
            .append(rect.bottom).append(")");

    if (node.getText() != null) {
        sb.append(":");
        sb.append(node.getText().toString().trim());
    }

    if (node.getContentDescription() != null) {
        sb.append(":");
        sb.append(node.getContentDescription().toString().trim());
    }

    int actions = node.getActions();
    if (actions != 0) {
        sb.append(":");
        if ((actions & AccessibilityNodeInfoCompat.ACTION_FOCUS) != 0) {
            sb.append("F");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("A");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("a");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) != 0) {
            sb.append("-");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_CLICK) != 0) {
            sb.append("C");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_LONG_CLICK) != 0) {
            sb.append("L");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) != 0) {
            sb.append("+");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_EXPAND) != 0) {
            sb.append("e");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_COLLAPSE) != 0) {
            sb.append("c");
        }
    }

    if (node.isCheckable()) {
        sb.append(":");
        if (node.isChecked()) {
            sb.append("(X)");
        } else {
            sb.append("( )");
        }
    }

    if (node.isFocusable()) {
        sb.append(":focusable");
    }

    if (node.isFocused()) {
        sb.append(":focused");
    }

    if (node.isSelected()) {
        sb.append(":selected");
    }

    if (node.isClickable()) {
        sb.append(":clickable");
    }

    if (node.isLongClickable()) {
        sb.append(":longClickable");
    }

    if (node.isAccessibilityFocused()) {
        sb.append(":accessibilityFocused");
    }

    if (!node.isEnabled()) {
        sb.append(":disabled");
    }

    if (node.getCollectionInfo() != null) {
        sb.append(":collection");
        sb.append("#R");
        sb.append(node.getCollectionInfo().getRowCount());
        sb.append("C");
        sb.append(node.getCollectionInfo().getColumnCount());
    }

    if (node.getCollectionItemInfo() != null) {
        if (node.getCollectionItemInfo().isHeading()) {
            sb.append(":heading");
        } else {
            sb.append(":item");
        }

        sb.append("#r");
        sb.append(node.getCollectionItemInfo().getRowIndex());
        sb.append("c");
        sb.append(node.getCollectionItemInfo().getColumnIndex());
    }

    return sb.toString();
}

From source file:com.google.android.marvin.utils.HighlightBoundsView.java

@Override
public void onDraw(Canvas c) {
    final int saveCount = c.save();
    c.translate(-SCREEN_LOCATION[0], -SCREEN_LOCATION[1]);
    c.setMatrix(mMatrix);/*from w w  w.j  a v  a2 s  .  c o m*/

    mPaint.setColor(mHighlightColor);

    for (AccessibilityNodeInfoCompat node : mNodes) {
        node.getBoundsInScreen(mTemp);
        c.drawRect(mTemp, mPaint);
    }

    c.restoreToCount(saveCount);
}

From source file:com.android.utils.traversal.NodeCachedBoundsCalculator.java

/**
 * If node is not supposed to be accessibility focused by TalkBack
 * NodeBoundsCalculator calculates useful bounds of focusable children.
 * The method checks if the node uses its children useful bounds or uses its own bounds
 *///  w ww.  j av a 2s  .c  o  m
public boolean usesChildrenBounds(AccessibilityNodeInfoCompat node) {
    if (node == null) {
        return false;
    }

    Rect bounds = getBounds(node);
    if (bounds == null) {
        return false;
    }

    node.getBoundsInScreen(mTempRect);
    return !mTempRect.equals(bounds);
}

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

/**
 * Finds the display extent for {@code node}, putting the
 * result in {@code outLeft} and {@code outRight}.
 * The display extent is the first and last node that will
 * contribute to the content of the display when {@code node}
 * has accessibility focus.//from   w w  w  . j  a  v a  2s.  c  om
 */
public void findDisplayExtentFromNode(AccessibilityNodeInfoCompat node, AccessibilityNodeInfoRef outLeft,
        AccessibilityNodeInfoRef outRight) {
    Rect nodeRect = new Rect();
    node.getBoundsInScreen(nodeRect);
    AccessibilityNodeInfoRef current = AccessibilityNodeInfoRef.unOwned(node);
    boolean currentIncludesChildren = includesChildren(current.get());
    // Walk up the node tree as long as all siblings overlap
    // the original node vertically on screen.
    do {
        if (currentIncludesChildren) {
            if (!findOverlappingRange(current.get(), nodeRect, outLeft, outRight)) {
                break;
            }
        } else {
            // If the start node doesn't include its children, don't
            // include any adjacent nodes, since that causes line-by-line
            // navigation to be confusing and get stuck in a cycle.
            outLeft.reset(current);
            outRight.reset(current);
            break;
        }
        if (!current.parent()) {
            break;
        }
        // TODO: why not format bottom-up and avoid having to lookup the
        // rule twice?  Consider that at some point.
        currentIncludesChildren = includesChildren(current.get());
        // Don't let any parent prevent us from getting onto the
        // display, *we* contain the focused node.
    } while (currentIncludesChildren);
}

From source file:com.android.utils.traversal.NodeCachedBoundsCalculator.java

private Rect fetchBound(AccessibilityNodeInfoCompat node) {
    if (node == null || !AccessibilityNodeInfoUtils.isVisible(node)) {
        return EMPTY_RECT;
    }//from www .  ja v  a 2  s .c om

    if (AccessibilityNodeInfoUtils.shouldFocusNode(node, mSpeakNodesCache)) {
        Rect bounds = new Rect();
        node.getBoundsInScreen(bounds);
        return bounds;
    }

    int childCount = node.getChildCount();
    int minTop = Integer.MAX_VALUE;
    int minLeft = Integer.MAX_VALUE;
    int maxBottom = Integer.MIN_VALUE;
    int maxRight = Integer.MIN_VALUE;
    AccessibilityNodeInfoCompat child = null;
    boolean hasChildBounds = false;
    for (int i = 0; i < childCount; i++) {
        try {
            child = node.getChild(i);
            Rect bounds = getBoundsInternal(child);
            if (bounds != EMPTY_RECT) {
                hasChildBounds = true;
                if (bounds.top < minTop) {
                    minTop = bounds.top;
                }

                if (bounds.left < minLeft) {
                    minLeft = bounds.left;
                }

                if (bounds.right > maxRight) {
                    maxRight = bounds.right;
                }

                if (bounds.bottom > maxBottom) {
                    maxBottom = bounds.bottom;
                }
            }
        } finally {
            AccessibilityNodeInfoUtils.recycleNodes(child);
        }
    }

    Rect bounds = new Rect();
    node.getBoundsInScreen(bounds);
    if (hasChildBounds) {
        bounds.top = Math.max(minTop, bounds.top);
        bounds.left = Math.max(minLeft, bounds.left);
        bounds.right = Math.min(maxRight, bounds.right);
        bounds.bottom = Math.min(maxBottom, bounds.bottom);
    }

    return bounds;
}

From source file:com.android.utils.traversal.DirectionalTraversalStrategy.java

/**
 * Returns the bounding rect of the given node for directional navigation purposes.
 * Any node that is a container of a focusable node will be reduced to a strip at its very
 * top edge.//from  ww  w  .ja  v a 2  s .  c  om
 */
private void getAssumedRectInScreen(AccessibilityNodeInfoCompat node, Rect assumedRect) {
    node.getBoundsInScreen(assumedRect);
    if (mContainers.contains(node)) {
        assumedRect.set(assumedRect.left, assumedRect.top, assumedRect.right, assumedRect.top + 1);
    }
}

From source file:com.android.utils.traversal.DirectionalTraversalStrategy.java

/**
 * Given a focus rectangle, returns another rectangle that is placed at the beginning of the
 * row or column of the focused object, depending on the direction in which we are navigating.
 *
 * Example:// w  w w .  j a  v a2  s. c om
 * <pre>
 *  +---------+
 *  |         | node=#
 * A|      #  | When direction=TraversalStrategy.SEARCH_FOCUS_RIGHT, then a rectangle A with
 *  |         |   same width and height as node gets returned.
 *  |         | When direction=TraversalStrategy.SEARCH_FOCUS_UP, then a rectangle B with same
 *  +---------+   width and height as node gets returned.
 *         B
 * </pre>
 */
private void getSearchStartRect(AccessibilityNodeInfoCompat node, int direction, Rect rect) {
    Rect focusedRect = new Rect();
    node.getBoundsInScreen(focusedRect);

    Rect rootBounds = new Rect();
    mRoot.getBoundsInScreen(rootBounds);

    switch (direction) {
    case TraversalStrategy.SEARCH_FOCUS_LEFT: // Start from right and move leftwards.
        rect.set(rootBounds.right, focusedRect.top, rootBounds.right + focusedRect.width(), focusedRect.bottom);
        break;
    case TraversalStrategy.SEARCH_FOCUS_RIGHT: // Start from left and move rightwards.
        rect.set(rootBounds.left - focusedRect.width(), focusedRect.top, rootBounds.left, focusedRect.bottom);
        break;
    case TraversalStrategy.SEARCH_FOCUS_UP: // Start from bottom and move upwards.
        rect.set(focusedRect.left, rootBounds.bottom, focusedRect.right,
                rootBounds.bottom + focusedRect.height());
        break;
    case TraversalStrategy.SEARCH_FOCUS_DOWN: // Start from top and move downwards.
        rect.set(focusedRect.left, rootBounds.top - focusedRect.height(), focusedRect.right, rootBounds.top);
        break;
    default:
        throw new IllegalArgumentException("direction must be a SearchDirection");
    }
}

From source file:com.android.utils.traversal.DirectionalTraversalStrategy.java

@Override
public AccessibilityNodeInfoCompat focusInitial(AccessibilityNodeInfoCompat root, int direction) {
    if (root == null) {
        return null;
    }/*from  www  .  ja va 2s .c om*/

    Rect rootRect = new Rect();
    root.getBoundsInScreen(rootRect);

    AccessibilityNodeInfoCompat focusedNode = root.findFocus(AccessibilityNodeInfoCompat.FOCUS_ACCESSIBILITY);

    Rect searchRect = new Rect();
    if (focusedNode != null) {
        getSearchStartRect(focusedNode, direction, searchRect);
    } else if (direction == TraversalStrategy.SEARCH_FOCUS_LEFT) {
        searchRect.set(rootRect.right, rootRect.top, rootRect.right + 1, rootRect.bottom);
    } else if (direction == TraversalStrategy.SEARCH_FOCUS_RIGHT) {
        searchRect.set(rootRect.left - 1, rootRect.top, rootRect.left, rootRect.bottom);
    } else if (direction == TraversalStrategy.SEARCH_FOCUS_UP) {
        searchRect.set(rootRect.left, rootRect.bottom, rootRect.right, rootRect.bottom + 1);
    } else {
        searchRect.set(rootRect.left, rootRect.top - 1, rootRect.right, rootRect.top);
    }

    AccessibilityNodeInfoCompat newFocus = findFocus(focusedNode, searchRect, direction);
    if (newFocus != null) {
        return AccessibilityNodeInfoCompat.obtain(newFocus);
    }

    return null;
}

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

private static boolean isNodeInBoundsOfOther(AccessibilityNodeInfoCompat outerNode,
        AccessibilityNodeInfoCompat innerNode) {
    if (outerNode == null || innerNode == null) {
        return false;
    }//from w w  w .  java2  s  .c o m

    Rect outerRect = new Rect();
    Rect innerRect = new Rect();
    outerNode.getBoundsInScreen(outerRect);
    innerNode.getBoundsInScreen(innerRect);

    if (outerRect.top > innerRect.bottom || outerRect.bottom < innerRect.top) {
        return false;
    }

    //noinspection RedundantIfStatement
    if (outerRect.left > innerRect.right || outerRect.right < innerRect.left) {
        return false;
    }

    return true;
}