Methods Summary |
---|
public boolean | ensureFullyVisible(UiObject childObject)Scrolls forward until the UiObject is fully visible in the scrollable container.
Use this method to make sure that the child item's edges are not offscreen.
Rect actual = childObject.getBounds();
Rect visible = childObject.getVisibleBounds();
if (visible.width() * visible.height() == actual.width() * actual.height()) {
// area match, item fully visible
return true;
}
boolean shouldSwipeForward = false;
if (mIsVerticalList) {
// if list is vertical, matching top edge implies obscured bottom edge
// so we need to scroll list forward
shouldSwipeForward = actual.top == visible.top;
} else {
// if list is horizontal, matching left edge implies obscured right edge,
// so we need to scroll list forward
shouldSwipeForward = actual.left == visible.left;
}
if (mIsVerticalList) {
if (shouldSwipeForward) {
return swipeUp(10);
} else {
return swipeDown(10);
}
} else {
if (shouldSwipeForward) {
return swipeLeft(10);
} else {
return swipeRight(10);
}
}
|
protected boolean | exists(UiSelector selector)Used privately when performing swipe searches to decide if an element has become
visible or not.
if(getQueryController().findAccessibilityNodeInfo(selector) != null) {
return true;
}
return false;
|
public boolean | flingBackward()Performs a backwards fling action with the default number of fling
steps (5). If the swipe direction is set to vertical,
then the swipe will be performed from top to bottom. If the swipe
direction is set to horizontal, then the swipes will be performed from
left to right. Make sure to take into account devices configured with
right-to-left languages like Arabic and Hebrew.
Tracer.trace();
return scrollBackward(FLING_STEPS);
|
public boolean | flingForward()Performs a forward fling with the default number of fling steps (5).
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.
Tracer.trace();
return scrollForward(FLING_STEPS);
|
public boolean | flingToBeginning(int maxSwipes)Performs a fling gesture to reach the beginning of a scrollable layout element.
The beginning can be at the top-most edge in the case of vertical controls, or
the left-most edge for horizontal controls. Make sure to take into
account devices configured with right-to-left languages like Arabic and Hebrew.
Tracer.trace(maxSwipes);
return scrollToBeginning(maxSwipes, FLING_STEPS);
|
public boolean | flingToEnd(int maxSwipes)Performs a fling gesture to reach the end of a scrollable layout element.
The end can be at the bottom-most edge in the case of vertical controls, or
the right-most edge for horizontal controls. Make sure to take into
account devices configured with right-to-left languages like Arabic and Hebrew.
Tracer.trace(maxSwipes);
return scrollToEnd(maxSwipes, FLING_STEPS);
|
public UiObject | getChildByDescription(UiSelector childPattern, java.lang.String text)Searches for a child element in the present scrollable container.
The search first looks for a child element that matches the selector
you provided, then looks for the content-description in its children elements.
If both search conditions are fulfilled, the method returns a {@ link UiObject}
representing the element matching the selector (not the child element in its
subhierarchy containing the content-description). By default, this method performs a
scroll search.
See {@link #getChildByDescription(UiSelector, String, boolean)}
Tracer.trace(childPattern, text);
return getChildByDescription(childPattern, text, true);
|
public UiObject | getChildByDescription(UiSelector childPattern, java.lang.String text, boolean allowScrollSearch)Searches for a child element in the present scrollable container.
The search first looks for a child element that matches the selector
you provided, then looks for the content-description in its children elements.
If both search conditions are fulfilled, the method returns a {@ link UiObject}
representing the element matching the selector (not the child element in its
subhierarchy containing the content-description).
Tracer.trace(childPattern, text, allowScrollSearch);
if (text != null) {
if (allowScrollSearch) {
scrollIntoView(new UiSelector().descriptionContains(text));
}
return super.getChildByDescription(childPattern, text);
}
throw new UiObjectNotFoundException("for description= \"" + text + "\"");
|
public UiObject | getChildByInstance(UiSelector childPattern, int instance)Searches for a child element in the present scrollable container that
matches the selector you provided. The search is performed without
scrolling and only on visible elements.
Tracer.trace(childPattern, instance);
UiSelector patternSelector = UiSelector.patternBuilder(getSelector(),
UiSelector.patternBuilder(childPattern).instance(instance));
return new UiObject(patternSelector);
|
public UiObject | getChildByText(UiSelector childPattern, java.lang.String text)Searches for a child element in the present scrollable
container. The search first looks for a child element that matches the
selector you provided, then looks for the text in its children elements.
If both search conditions are fulfilled, the method returns a {@ link UiObject}
representing the element matching the selector (not the child element in its
subhierarchy containing the text). By default, this method performs a
scroll search.
See {@link #getChildByText(UiSelector, String, boolean)}
Tracer.trace(childPattern, text);
return getChildByText(childPattern, text, true);
|
public UiObject | getChildByText(UiSelector childPattern, java.lang.String text, boolean allowScrollSearch)Searches for a child element in the present scrollable container. The
search first looks for a child element that matches the
selector you provided, then looks for the text in its children elements.
If both search conditions are fulfilled, the method returns a {@ link UiObject}
representing the element matching the selector (not the child element in its
subhierarchy containing the text).
Tracer.trace(childPattern, text, allowScrollSearch);
if (text != null) {
if (allowScrollSearch) {
scrollIntoView(new UiSelector().text(text));
}
return super.getChildByText(childPattern, text);
}
throw new UiObjectNotFoundException("for text= \"" + text + "\"");
|
public int | getMaxSearchSwipes()Gets the maximum number of scrolls allowed when performing a
scroll action in search of a child element.
See {@link #getChildByDescription(UiSelector, String)} and
{@link #getChildByText(UiSelector, String)}.
Tracer.trace();
return mMaxSearchSwipes;
|
public double | getSwipeDeadZonePercentage()Returns the percentage of a widget's size that's considered as a no-touch
zone when swiping. The no-touch zone is set as a percentage of a widget's total
width or height, denoting a margin around the swipable area of the widget.
Swipes must start and end inside this margin. This is important when the
widget being swiped may not respond to the swipe if started at a point
too near to the edge. The default is 10% from either edge.
Tracer.trace();
return mSwipeDeadZonePercentage;
|
public boolean | scrollBackward()Performs a backward scroll with the default number of scroll steps (55).
If the swipe direction is set to vertical,
then the swipes will be performed from top to bottom. If the swipe
direction is set to horizontal, then the swipes will be performed from
left to right. Make sure to take into account devices configured with
right-to-left languages like Arabic and Hebrew.
Tracer.trace();
return scrollBackward(SCROLL_STEPS);
|
public boolean | scrollBackward(int steps)Performs a backward scroll. If the swipe direction is set to vertical,
then the swipes will be performed from top to bottom. If the swipe
direction is set to horizontal, then the swipes will be performed from
left to right. Make sure to take into account devices configured with
right-to-left languages like Arabic and Hebrew.
Tracer.trace(steps);
Log.d(LOG_TAG, "scrollBackward() 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;
// scrolling is by default assumed vertically unless the object is explicitly
// set otherwise by setAsHorizontalContainer()
if(mIsVerticalList) {
int swipeAreaAdjust = (int)(rect.height() * getSwipeDeadZonePercentage());
Log.d(LOG_TAG, "scrollToBegining() using vertical scroll");
// scroll vertically: swipe up -> down
downX = rect.centerX();
downY = rect.top + swipeAreaAdjust;
upX = rect.centerX();
upY = rect.bottom - swipeAreaAdjust;
} else {
int swipeAreaAdjust = (int)(rect.width() * getSwipeDeadZonePercentage());
Log.d(LOG_TAG, "scrollToBegining() using hotizontal scroll");
// scroll horizontally: swipe left -> right
// TODO: Assuming device is not in right to left language
downX = rect.left + swipeAreaAdjust;
downY = rect.centerY();
upX = rect.right - swipeAreaAdjust;
upY = rect.centerY();
}
return getInteractionController().scrollSwipe(downX, downY, upX, upY, steps);
|
public boolean | scrollDescriptionIntoView(java.lang.String text)Performs a forward scroll action on the scrollable layout element until
the content-description is found, or until swipe attempts have been exhausted.
See {@link #setMaxSearchSwipes(int)}
Tracer.trace(text);
return scrollIntoView(new UiSelector().description(text));
|
public boolean | scrollForward()Performs a forward scroll with the default number of scroll steps (55).
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.
Tracer.trace();
return scrollForward(SCROLL_STEPS);
|
public boolean | scrollForward(int steps)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.
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;
// scrolling is by default assumed vertically unless the object is explicitly
// 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);
|
public boolean | scrollIntoView(UiObject obj)Perform a forward scroll action to move through the scrollable layout element until
a visible item that matches the {@link UiObject} is found.
Tracer.trace(obj.getSelector());
return scrollIntoView(obj.getSelector());
|
public boolean | scrollIntoView(UiSelector selector)Perform a scroll forward action to move through the scrollable layout
element until a visible item that matches the selector is found.
See {@link #scrollDescriptionIntoView(String)} and {@link #scrollTextIntoView(String)}.
Tracer.trace(selector);
// if we happen to be on top of the text we want then return here
UiSelector childSelector = getSelector().childSelector(selector);
if (exists(childSelector)) {
return (true);
} else {
// we will need to reset the search from the beginning to start search
scrollToBeginning(mMaxSearchSwipes);
if (exists(childSelector)) {
return (true);
}
for (int x = 0; x < mMaxSearchSwipes; x++) {
boolean scrolled = scrollForward();
if(exists(childSelector)) {
return true;
}
if (!scrolled) {
return false;
}
}
}
return false;
|
public boolean | scrollTextIntoView(java.lang.String text)Performs a forward scroll action on the scrollable layout element until
the text you provided is visible, or until swipe attempts have been exhausted.
See {@link #setMaxSearchSwipes(int)}
Tracer.trace(text);
return scrollIntoView(new UiSelector().text(text));
|
public boolean | scrollToBeginning(int maxSwipes, int steps)Scrolls to the beginning of a scrollable layout element. The beginning
can be at the top-most edge in the case of vertical controls, or the
left-most edge for horizontal controls. Make sure to take into account
devices configured with right-to-left languages like Arabic and Hebrew.
Tracer.trace(maxSwipes, steps);
Log.d(LOG_TAG, "scrollToBeginning() on selector = " + getSelector());
// protect against potential hanging and return after preset attempts
for(int x = 0; x < maxSwipes; x++) {
if(!scrollBackward(steps)) {
break;
}
}
return true;
|
public boolean | scrollToBeginning(int maxSwipes)Scrolls to the beginning of a scrollable layout element. The beginning
can be at the top-most edge in the case of vertical controls, or the
left-most edge for horizontal controls. Make sure to take into account
devices configured with right-to-left languages like Arabic and Hebrew.
Tracer.trace(maxSwipes);
return scrollToBeginning(maxSwipes, SCROLL_STEPS);
|
public boolean | scrollToEnd(int maxSwipes, int steps)Scrolls to the end of a scrollable layout element. The end can be at the
bottom-most edge in the case of vertical controls, or the right-most edge for
horizontal controls. Make sure to take into account devices configured with
right-to-left languages like Arabic and Hebrew.
Tracer.trace(maxSwipes, steps);
// protect against potential hanging and return after preset attempts
for(int x = 0; x < maxSwipes; x++) {
if(!scrollForward(steps)) {
break;
}
}
return true;
|
public boolean | scrollToEnd(int maxSwipes)Scrolls to the end of a scrollable layout element. The end can be at the
bottom-most edge in the case of vertical controls, or the right-most edge for
horizontal controls. Make sure to take into account devices configured with
right-to-left languages like Arabic and Hebrew.
Tracer.trace(maxSwipes);
return scrollToEnd(maxSwipes, SCROLL_STEPS);
|
public com.android.uiautomator.core.UiScrollable | setAsHorizontalList()Set the direction of swipes to be horizontal when performing scroll actions.
Tracer.trace();
mIsVerticalList = false;
return this;
|
public com.android.uiautomator.core.UiScrollable | setAsVerticalList()Set the direction of swipes to be vertical when performing scroll actions.
Tracer.trace();
mIsVerticalList = true;
return this;
|
public com.android.uiautomator.core.UiScrollable | setMaxSearchSwipes(int swipes)Sets the maximum number of scrolls allowed when performing a
scroll action in search of a child element.
See {@link #getChildByDescription(UiSelector, String)} and
{@link #getChildByText(UiSelector, String)}.
Tracer.trace(swipes);
mMaxSearchSwipes = swipes;
return this;
|
public com.android.uiautomator.core.UiScrollable | setSwipeDeadZonePercentage(double swipeDeadZonePercentage)Sets the percentage of a widget's size that's considered as no-touch
zone when swiping.
The no-touch zone is set as percentage of a widget's total width or height,
denoting a margin around the swipable area of the widget. Swipes must
always start and end inside this margin. This is important when the
widget being swiped may not respond to the swipe if started at a point
too near to the edge. The default is 10% from either edge.
Tracer.trace(swipeDeadZonePercentage);
mSwipeDeadZonePercentage = swipeDeadZonePercentage;
return this;
|