forked from RobotiumTech/robotium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RobotiumTech#32 from olekp/scrollViewToSide
added method for scrolling a view to side
- Loading branch information
Showing
2 changed files
with
48 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,9 @@ | |
/** | ||
* Contains scroll methods. Examples are scrollDown(), scrollUpList(), | ||
* scrollToSide(). | ||
* | ||
* | ||
* @author Renas Reda, [email protected] | ||
* | ||
* | ||
*/ | ||
|
||
class Scroller { | ||
|
@@ -92,10 +92,10 @@ public void drag(float fromX, float toX, float fromY, float toY, | |
|
||
/** | ||
* Scrolls a ScrollView. | ||
* | ||
* | ||
* @param direction the direction to be scrolled | ||
* @return {@code true} if scrolling occurred, false if it did not | ||
* | ||
* | ||
*/ | ||
|
||
private boolean scrollScrollView(final ScrollView view, int direction){ | ||
|
@@ -157,20 +157,20 @@ public boolean scroll(int direction) { | |
|
||
/** | ||
* Scrolls up and down. | ||
* | ||
* | ||
* @param direction the direction in which to scroll | ||
* @param allTheWay <code>true</code> if the view should be scrolled to the beginning or end, | ||
* <code>false</code> to scroll one page up or down. | ||
* @return {@code true} if more scrolling can be done | ||
* | ||
* | ||
*/ | ||
|
||
public boolean scroll(int direction, boolean allTheWay) { | ||
|
||
final ArrayList<View> viewList = RobotiumUtils. | ||
removeInvisibleViews(viewFetcher.getAllViews(true)); | ||
@SuppressWarnings("unchecked") | ||
ArrayList<View> views = RobotiumUtils.filterViewsToSet(new Class[] { ListView.class, | ||
ArrayList<View> views = RobotiumUtils.filterViewsToSet(new Class[] { ListView.class, | ||
ScrollView.class, GridView.class}, viewList); | ||
View view = viewFetcher.getFreshestView(views); | ||
|
||
|
@@ -197,13 +197,13 @@ public boolean scroll(int direction, boolean allTheWay) { | |
|
||
/** | ||
* Scrolls a list. | ||
* | ||
* | ||
* @param absListView the list to be scrolled | ||
* @param direction the direction to be scrolled | ||
* @param allTheWay {@code true} to scroll the view all the way up or down, {@code false} to scroll one page up | ||
* or down. | ||
* @return {@code true} if more scrolling can be done | ||
* | ||
* | ||
*/ | ||
|
||
public <T extends AbsListView> boolean scrollList(T absListView, int direction, boolean allTheWay) { | ||
|
@@ -244,15 +244,15 @@ public <T extends AbsListView> boolean scrollList(T absListView, int direction, | |
lineToScrollTo = 0; | ||
|
||
scrollListToLine(absListView, lineToScrollTo); | ||
} | ||
} | ||
sleeper.sleep(); | ||
return true; | ||
} | ||
|
||
|
||
/** | ||
* Scroll the list to a given line | ||
* | ||
* | ||
* @param view the {@link AbsListView} to scroll | ||
* @param line the line to scroll to | ||
*/ | ||
|
@@ -293,4 +293,25 @@ else if (side == Side.RIGHT) | |
drag(x, 0, y, y, 40); | ||
} | ||
|
||
/** | ||
* Scrolls view horizontally. | ||
* | ||
* @param view the view to scroll | ||
* @param side the side to which to scroll; {@link Side#RIGHT} or {@link Side#LEFT} | ||
* | ||
*/ | ||
|
||
public void scrollViewToSide(View view, Side side) { | ||
int[] corners = new int[2]; | ||
view.getLocationOnScreen(corners); | ||
int viewHeight = view.getHeight(); | ||
int viewWidth = view.getWidth(); | ||
float x = corners[0] + viewWidth / 2.0f; | ||
float y = corners[1] + viewHeight / 2.0f; | ||
if (side == Side.LEFT) | ||
drag(corners[0], x, y, y, 40); | ||
else if (side == Side.RIGHT) | ||
drag(x, corners[0], y, y, 40); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters