Search in sources :

Example 96 with MotionEvent

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));
}
Also used : MotionEvent(android.view.MotionEvent)

Example 97 with MotionEvent

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);
}
Also used : View(android.view.View) AbsListView(android.widget.AbsListView) DynamicListView(com.nhaarman.listviewanimations.itemmanipulation.DynamicListView) MotionEvent(android.view.MotionEvent)

Example 98 with MotionEvent

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);
    }
}
Also used : MotionEvent(android.view.MotionEvent)

Example 99 with MotionEvent

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);
}
Also used : View(android.view.View) AbsListView(android.widget.AbsListView) DynamicListView(com.nhaarman.listviewanimations.itemmanipulation.DynamicListView) MotionEvent(android.view.MotionEvent)

Example 100 with MotionEvent

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);
    }
}
Also used : MotionEvent(android.view.MotionEvent)

Aggregations

MotionEvent (android.view.MotionEvent)702 View (android.view.View)242 TextView (android.widget.TextView)109 ImageView (android.widget.ImageView)86 Point (android.graphics.Point)62 GestureDetector (android.view.GestureDetector)46 OnTouchListener (android.view.View.OnTouchListener)44 Paint (android.graphics.Paint)40 ViewGroup (android.view.ViewGroup)36 Test (org.junit.Test)35 RecyclerView (android.support.v7.widget.RecyclerView)31 AdapterView (android.widget.AdapterView)31 ListView (android.widget.ListView)30 SuppressLint (android.annotation.SuppressLint)29 Intent (android.content.Intent)29 Instrumentation (android.app.Instrumentation)27 AbsListView (android.widget.AbsListView)27 Rect (android.graphics.Rect)22 OnClickListener (android.view.View.OnClickListener)22 Handler (android.os.Handler)20