Skip to content

Commit

Permalink
Merge pull request RobotiumTech#32 from olekp/scrollViewToSide
Browse files Browse the repository at this point in the history
added method for scrolling a view to side
  • Loading branch information
renas committed Oct 30, 2012
2 parents d30b5a0 + 0ae6a9d commit 309bac9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
/**
* Contains scroll methods. Examples are scrollDown(), scrollUpList(),
* scrollToSide().
*
*
* @author Renas Reda, [email protected]
*
*
*/

class Scroller {
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1232,8 +1232,22 @@ public void scrollToSide(int side) {
case LEFT: scroller.scrollToSide(Scroller.Side.LEFT); break;
}
}



/**
* Scrolls horizontally.
*
* @param view the view to scroll
* @param side the side to which to scroll; {@link #RIGHT} or {@link #LEFT}
*
*/

public void scrollViewToSide(View view, int side) {
switch (side){
case RIGHT: scroller.scrollViewToSide(view, Scroller.Side.RIGHT); break;
case LEFT: scroller.scrollViewToSide(view, Scroller.Side.LEFT); break;
}
}

/**
* Sets the date in a DatePicker with a given index.
*
Expand Down

0 comments on commit 309bac9

Please sign in to comment.