public static void swipeHorizontally(InstrumentationTestCase test, View v, Direction direction) {
int[] xy = new int[2];
v.getLocationOnScreen(xy);
final int viewWidth = v.getWidth();
final int viewHeight = v.getHeight();
float distanceFromEdge = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
v.getResources().getDisplayMetrics());
float xStart = xy[0] + ((direction == Direction.LEFT) ? (viewWidth - distanceFromEdge) : distanceFromEdge);
float xEnd = xy[0] + ((direction == Direction.LEFT) ? distanceFromEdge : (viewWidth - distanceFromEdge));
float y = xy[1] + (viewHeight / 2.0f);
TouchUtils.drag(test, xStart, xEnd, y, y, DRAG_STEP_COUNT);
}