Search in sources :

Example 46 with AccessibilityNodeInfo

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

the class QueryController method findNodePatternRecursive.

private AccessibilityNodeInfo findNodePatternRecursive(UiSelector subSelector, AccessibilityNodeInfo fromNode, int index, UiSelector originalPattern) {
    if (subSelector.isMatchFor(fromNode, index)) {
        if (subSelector.isLeaf()) {
            if (mPatternIndexer == 0) {
                if (DEBUG)
                    Log.d(LOG_TAG, formatLog(String.format("%s", subSelector.dumpToString(false))));
                return fromNode;
            } else {
                if (DEBUG)
                    Log.d(LOG_TAG, formatLog(String.format("%s", subSelector.dumpToString(false))));
                //count the pattern matched
                mPatternCounter++;
                //decrement until zero for the instance requested
                mPatternIndexer--;
                // At a leaf selector within a group and still not instance matched
                // then reset the  selector to continue search from current position
                // in the accessibility tree for the next pattern match up until the
                // pattern index hits 0.
                subSelector = originalPattern;
                // starting over with next pattern search so reset to parent level
                mLogIndent = mLogParentIndent;
            }
        } else {
            if (DEBUG)
                Log.d(LOG_TAG, formatLog(String.format("%s", subSelector.dumpToString(false))));
            if (subSelector.hasChildSelector()) {
                // next selector
                mLogIndent++;
                subSelector = subSelector.getChildSelector();
                if (subSelector == null) {
                    Log.e(LOG_TAG, "Error: A child selector without content");
                    return null;
                }
            } else if (subSelector.hasParentSelector()) {
                // next selector
                mLogIndent++;
                subSelector = subSelector.getParentSelector();
                if (subSelector == null) {
                    Log.e(LOG_TAG, "Error: A parent selector without content");
                    return null;
                }
                fromNode = fromNode.getParent();
                if (fromNode == null)
                    return null;
            }
        }
    }
    int childCount = fromNode.getChildCount();
    boolean hasNullChild = false;
    for (int i = 0; i < childCount; i++) {
        AccessibilityNodeInfo childNode = fromNode.getChild(i);
        if (childNode == null) {
            Log.w(LOG_TAG, String.format("AccessibilityNodeInfo returned a null child (%d of %d)", i, childCount));
            if (!hasNullChild) {
                Log.w(LOG_TAG, String.format("parent = %s", fromNode.toString()));
            }
            hasNullChild = true;
            continue;
        }
        if (!childNode.isVisibleToUser()) {
            if (DEBUG)
                Log.d(LOG_TAG, String.format("Skipping invisible child: %s", childNode.toString()));
            continue;
        }
        AccessibilityNodeInfo retNode = findNodePatternRecursive(subSelector, childNode, i, originalPattern);
        if (retNode != null) {
            return retNode;
        }
    }
    return null;
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)

Example 47 with AccessibilityNodeInfo

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

the class QueryController method findAccessibilityNodeInfo.

protected AccessibilityNodeInfo findAccessibilityNodeInfo(UiSelector selector, boolean isCounting) {
    mUiAutomatorBridge.waitForIdle();
    initializeNewSearch();
    if (DEBUG)
        Log.d(LOG_TAG, "Searching: " + selector);
    synchronized (mLock) {
        AccessibilityNodeInfo rootNode = getRootNode();
        if (rootNode == null) {
            Log.e(LOG_TAG, "Cannot proceed when root node is null. Aborted search");
            return null;
        }
        // Copy so that we don't modify the original's sub selectors
        UiSelector uiSelector = new UiSelector(selector);
        return translateCompoundSelector(uiSelector, rootNode, isCounting);
    }
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)

Example 48 with AccessibilityNodeInfo

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

the class UiScrollable method scrollForward.

/**
     * Performs a forward scroll. If the swipe direction is set to vertical,
     * then the swipes will be performed from bottom to top. If the swipe
     * direction is set to horizontal, then the swipes will be performed from
     * right to left. Make sure to take into account devices configured with
     * right-to-left languages like Arabic and Hebrew.
     *
     * @param steps number of steps. Use this to control the speed of the scroll action
     * @return true if scrolled, false if can't scroll anymore
     * @since API Level 16
     */
public boolean scrollForward(int steps) throws UiObjectNotFoundException {
    Tracer.trace(steps);
    Log.d(LOG_TAG, "scrollForward() on selector = " + getSelector());
    AccessibilityNodeInfo node = findAccessibilityNodeInfo(WAIT_FOR_SELECTOR_TIMEOUT);
    if (node == null) {
        throw new UiObjectNotFoundException(getSelector().toString());
    }
    Rect rect = new Rect();
    node.getBoundsInScreen(rect);
    int downX = 0;
    int downY = 0;
    int upX = 0;
    int upY = 0;
    // set otherwise by setAsHorizontalContainer()
    if (mIsVerticalList) {
        int swipeAreaAdjust = (int) (rect.height() * getSwipeDeadZonePercentage());
        // scroll vertically: swipe down -> up
        downX = rect.centerX();
        downY = rect.bottom - swipeAreaAdjust;
        upX = rect.centerX();
        upY = rect.top + swipeAreaAdjust;
    } else {
        int swipeAreaAdjust = (int) (rect.width() * getSwipeDeadZonePercentage());
        // scroll horizontally: swipe right -> left
        // TODO: Assuming device is not in right to left language
        downX = rect.right - swipeAreaAdjust;
        downY = rect.centerY();
        upX = rect.left + swipeAreaAdjust;
        upY = rect.centerY();
    }
    return getInteractionController().scrollSwipe(downX, downY, upX, upY, steps);
}
Also used : Rect(android.graphics.Rect) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)

Example 49 with AccessibilityNodeInfo

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

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 50 with AccessibilityNodeInfo

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

the class UiObject method getClassName.

/**
     * Retrieves the <code>className</code> property of the UI element.
     *
     * @return class name of the current node represented by this UiObject
     * @throws UiObjectNotFoundException if no match was found
     * @since API Level 18
     */
public String getClassName() throws UiObjectNotFoundException {
    Tracer.trace();
    AccessibilityNodeInfo node = findAccessibilityNodeInfo(mConfig.getWaitForSelectorTimeout());
    if (node == null) {
        throw new UiObjectNotFoundException(getSelector().toString());
    }
    String retVal = safeStringReturn(node.getClassName());
    Log.d(LOG_TAG, String.format("getClassName() = %s", retVal));
    return retVal;
}
Also used : 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