use of android.view.MotionEvent in project ListViewAnimations by nhaarman.
the class HoverDrawableTest method testReversedDoubleMovedState.
public void testReversedDoubleMovedState() {
MotionEvent motionEvent = createMotionEvent(START_Y - 10);
mHoverDrawable.handleMoveEvent(motionEvent);
MotionEvent motionEvent2 = createMotionEvent(START_Y - 20);
mHoverDrawable.handleMoveEvent(motionEvent2);
assertThat(mHoverDrawable.getDeltaY(), is(-20));
assertThat(mHoverDrawable.getBounds().top, is(-20));
assertThat(mHoverDrawable.isMovingUpwards(), is(true));
}
use of android.view.MotionEvent in project ListViewAnimations by nhaarman.
the class MotionEventUtils method dispatchDragMotionEvents.
public static void dispatchDragMotionEvents(final Instrumentation instrumentation, final DynamicListView dynamicListView, final int fromPosition, final int toPosition) throws InterruptedException {
int[] location = new int[2];
dynamicListView.getLocationOnScreen(location);
View view = dynamicListView.getChildAt(fromPosition);
float fromY = (int) (view.getY() + view.getHeight() / 2) + location[1];
View toView = dynamicListView.getChildAt(toPosition);
float toY = (int) toView.getY() + location[1];
toY += fromPosition < toPosition ? toView.getHeight() : 0;
List<MotionEvent> motionEvents = createMotionEvents(dynamicListView, fromY, toY);
dispatchMotionEvents(instrumentation, motionEvents, true);
}
use of android.view.MotionEvent in project ListViewAnimations by nhaarman.
the class MotionEventUtils method dispatchMotionEvents.
public static void dispatchMotionEvents(final Instrumentation instrumentation, final Iterable<MotionEvent> motionEvents, final boolean wait) throws InterruptedException {
for (final MotionEvent event : motionEvents) {
int i = 0;
boolean success = false;
do {
try {
instrumentation.sendPointerSync(event);
success = true;
} catch (SecurityException e) {
i++;
if (i > 3) {
throw e;
}
}
} while (i < 3 && !success);
Thread.sleep(100);
}
if (wait) {
/* We need to wait for the fling animation to complete */
Thread.sleep(1500);
}
}
use of android.view.MotionEvent in project ListViewAnimations by nhaarman.
the class MotionEventUtils method dispatchDragScrollDownMotionEvents.
public static void dispatchDragScrollDownMotionEvents(final Instrumentation instrumentation, final DynamicListView dynamicListView, final int fromPosition) throws InterruptedException {
int[] location = new int[2];
dynamicListView.getLocationOnScreen(location);
View view = dynamicListView.getChildAt(fromPosition);
float fromY = (int) (view.getY()) + location[1];
View toView = dynamicListView.getChildAt(dynamicListView.getLastVisiblePosition());
float toY = (int) (toView.getY() + toView.getHeight()) + location[1] + 2;
List<MotionEvent> motionEvents = createMotionEvents(dynamicListView, fromY, toY);
MotionEvent upEvent = motionEvents.remove(motionEvents.size() - 1);
dispatchMotionEvents(instrumentation, motionEvents, true);
Thread.sleep(10000);
dispatchMotionEvents(instrumentation, Arrays.asList(upEvent), true);
}
use of android.view.MotionEvent in project ListViewAnimations by nhaarman.
the class MotionEventUtils method dispatchMotionEvents.
public static void dispatchMotionEvents(final Instrumentation instrumentation, final Iterable<MotionEvent> motionEvents, final boolean wait) throws InterruptedException {
for (final MotionEvent event : motionEvents) {
int i = 0;
boolean success = false;
do {
try {
instrumentation.sendPointerSync(event);
success = true;
} catch (SecurityException ignored) {
i++;
}
} while (i < 3 && !success);
Thread.sleep(100);
}
if (wait) {
/* We need to wait for the fling animation to complete */
Thread.sleep(1500);
}
}
Aggregations