Search in sources :

Example 71 with AccessibilityNodeInfo

use of android.view.accessibility.AccessibilityNodeInfo in project android_frameworks_base by DirtyUnicorns.

the class UiObject method isChecked.

/**
     * Check if the UI element's <code>checked</code> property is currently true
     *
     * @return true if it is else false
     * @since API Level 16
     */
public boolean isChecked() throws UiObjectNotFoundException {
    Tracer.trace();
    AccessibilityNodeInfo node = findAccessibilityNodeInfo(mConfig.getWaitForSelectorTimeout());
    if (node == null) {
        throw new UiObjectNotFoundException(getSelector().toString());
    }
    return node.isChecked();
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)

Example 72 with AccessibilityNodeInfo

use of android.view.accessibility.AccessibilityNodeInfo in project android_frameworks_base by DirtyUnicorns.

the class UiObject method getVisibleBounds.

/**
     * Finds the visible bounds of a partially visible UI element
     *
     * @param node
     * @return null if node is null, else a Rect containing visible bounds
     */
private Rect getVisibleBounds(AccessibilityNodeInfo node) {
    if (node == null) {
        return null;
    }
    // targeted node's bounds
    int w = UiDevice.getInstance().getDisplayWidth();
    int h = UiDevice.getInstance().getDisplayHeight();
    Rect nodeRect = AccessibilityNodeInfoHelper.getVisibleBoundsInScreen(node, w, h);
    // is the targeted node within a scrollable container?
    AccessibilityNodeInfo scrollableParentNode = getScrollableParent(node);
    if (scrollableParentNode == null) {
        // nothing to adjust for so return the node's Rect as is
        return nodeRect;
    }
    // Scrollable parent's visible bounds
    Rect parentRect = AccessibilityNodeInfoHelper.getVisibleBoundsInScreen(scrollableParentNode, w, h);
    // adjust for partial clipping of targeted by parent node if required
    if (nodeRect.intersect(parentRect)) {
        return nodeRect;
    } else {
        // Node rect has no intersection with parent Rect
        return new Rect();
    }
}
Also used : Rect(android.graphics.Rect) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) Point(android.graphics.Point)

Example 73 with AccessibilityNodeInfo

use of android.view.accessibility.AccessibilityNodeInfo in project android_frameworks_base by DirtyUnicorns.

the class UiObject method longClickTopLeft.

/**
     * Long clicks on the top and left corner of the UI element
     *
     * @return true if operation was successful
     * @throws UiObjectNotFoundException
     * @since API Level 16
     */
public boolean longClickTopLeft() throws UiObjectNotFoundException {
    Tracer.trace();
    AccessibilityNodeInfo node = findAccessibilityNodeInfo(mConfig.getWaitForSelectorTimeout());
    if (node == null) {
        throw new UiObjectNotFoundException(getSelector().toString());
    }
    Rect rect = getVisibleBounds(node);
    return getInteractionController().longTapNoSync(rect.left + 5, rect.top + 5);
}
Also used : Rect(android.graphics.Rect) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)

Example 74 with AccessibilityNodeInfo

use of android.view.accessibility.AccessibilityNodeInfo in project android_frameworks_base by DirtyUnicorns.

the class ExploreByTouchHelper method createNodeForHost.

/**
     * Constructs and returns an {@link AccessibilityNodeInfo} for the
     * host view populated with its virtual descendants.
     *
     * @return An {@link AccessibilityNodeInfo} for the parent node.
     */
private AccessibilityNodeInfo createNodeForHost() {
    final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain(mView);
    mView.onInitializeAccessibilityNodeInfo(node);
    final int realNodeCount = node.getChildCount();
    // Allow the client to populate the host node.
    onPopulateNodeForHost(node);
    // Add the virtual descendants.
    if (mTempArray == null) {
        mTempArray = new IntArray();
    } else {
        mTempArray.clear();
    }
    final IntArray virtualViewIds = mTempArray;
    getVisibleVirtualViews(virtualViewIds);
    if (realNodeCount > 0 && virtualViewIds.size() > 0) {
        throw new RuntimeException("Views cannot have both real and virtual children");
    }
    final int N = virtualViewIds.size();
    for (int i = 0; i < N; i++) {
        node.addChild(mView, virtualViewIds.get(i));
    }
    return node;
}
Also used : IntArray(android.util.IntArray) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)

Example 75 with AccessibilityNodeInfo

use of android.view.accessibility.AccessibilityNodeInfo in project android_frameworks_base by DirtyUnicorns.

the class ExploreByTouchHelper method createNodeForChild.

/**
     * Constructs and returns an {@link AccessibilityNodeInfo} for the
     * specified item. Automatically manages accessibility focus actions.
     * <p>
     * Allows the implementing class to specify most node properties, but
     * overrides the following:
     * <ul>
     * <li>{@link AccessibilityNodeInfo#setPackageName}
     * <li>{@link AccessibilityNodeInfo#setClassName}
     * <li>{@link AccessibilityNodeInfo#setParent(View)}
     * <li>{@link AccessibilityNodeInfo#setSource(View, int)}
     * <li>{@link AccessibilityNodeInfo#setVisibleToUser}
     * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)}
     * </ul>
     * <p>
     * Uses the bounds of the parent view and the parent-relative bounding
     * rectangle specified by
     * {@link AccessibilityNodeInfo#getBoundsInParent} to automatically
     * update the following properties:
     * <ul>
     * <li>{@link AccessibilityNodeInfo#setVisibleToUser}
     * <li>{@link AccessibilityNodeInfo#setBoundsInParent}
     * </ul>
     *
     * @param virtualViewId The virtual view id for item for which to construct
     *            a node.
     * @return An {@link AccessibilityNodeInfo} for the specified item.
     */
private AccessibilityNodeInfo createNodeForChild(int virtualViewId) {
    ensureTempRects();
    final Rect tempParentRect = mTempParentRect;
    final int[] tempGlobalRect = mTempGlobalRect;
    final Rect tempScreenRect = mTempScreenRect;
    final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain();
    // Ensure the client has good defaults.
    node.setEnabled(true);
    node.setClassName(DEFAULT_CLASS_NAME);
    node.setBoundsInParent(INVALID_PARENT_BOUNDS);
    // Allow the client to populate the node.
    onPopulateNodeForVirtualView(virtualViewId, node);
    // Make sure the developer is following the rules.
    if ((node.getText() == null) && (node.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in " + "populateNodeForVirtualViewId()");
    }
    node.getBoundsInParent(tempParentRect);
    if (tempParentRect.equals(INVALID_PARENT_BOUNDS)) {
        throw new RuntimeException("Callbacks must set parent bounds in " + "populateNodeForVirtualViewId()");
    }
    final int actions = node.getActions();
    if ((actions & AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in " + "populateNodeForVirtualViewId()");
    }
    if ((actions & AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
        throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in " + "populateNodeForVirtualViewId()");
    }
    // Don't allow the client to override these properties.
    node.setPackageName(mView.getContext().getPackageName());
    node.setSource(mView, virtualViewId);
    node.setParent(mView);
    // Manage internal accessibility focus state.
    if (mFocusedVirtualViewId == virtualViewId) {
        node.setAccessibilityFocused(true);
        node.addAction(AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        node.setAccessibilityFocused(false);
        node.addAction(AccessibilityAction.ACTION_ACCESSIBILITY_FOCUS);
    }
    // Set the visibility based on the parent bound.
    if (intersectVisibleToUser(tempParentRect)) {
        node.setVisibleToUser(true);
        node.setBoundsInParent(tempParentRect);
    }
    // Calculate screen-relative bound.
    mView.getLocationOnScreen(tempGlobalRect);
    final int offsetX = tempGlobalRect[0];
    final int offsetY = tempGlobalRect[1];
    tempScreenRect.set(tempParentRect);
    tempScreenRect.offset(offsetX, offsetY);
    node.setBoundsInScreen(tempScreenRect);
    return node;
}
Also used : Rect(android.graphics.Rect) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)

Aggregations

AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)310 Point (android.graphics.Point)84 Rect (android.graphics.Rect)84 AccessibilityNodeProvider (android.view.accessibility.AccessibilityNodeProvider)45 RemoteException (android.os.RemoteException)30 IAccessibilityInteractionConnectionCallback (android.view.accessibility.IAccessibilityInteractionConnectionCallback)30 SomeArgs (com.android.internal.os.SomeArgs)30 Region (android.graphics.Region)25 Paint (android.graphics.Paint)19 View (android.view.View)12 ViewRootImpl (android.view.ViewRootImpl)11 RemoteView (android.widget.RemoteViews.RemoteView)11 Display (android.view.Display)10 File (java.io.File)10 LinkedList (java.util.LinkedList)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 UiAutomation (android.app.UiAutomation)5 InputFilter (android.text.InputFilter)5 TextPaint (android.text.TextPaint)5