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;
}
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);
}
}
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);
}
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();
}
}
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;
}
Aggregations