Example usage for android.app Instrumentation sendPointerSync

List of usage examples for android.app Instrumentation sendPointerSync

Introduction

In this page you can find the example usage for android.app Instrumentation sendPointerSync.

Prototype

public void sendPointerSync(MotionEvent event) 

Source Link

Document

Dispatch a pointer event.

Usage

From source file:Main.java

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 {//from w  w w  .ja v  a  2 s.  co m
            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);
    }
}

From source file:Main.java

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 {/*  w ww  .  ja  v a  2s.  c o m*/
            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);
    }
}

From source file:love.juhe.androidmonkey.MonkeyTouchEvent.java

@Override
public int fireEvent(Instrumentation testRuner) {
    event = getEvent();/*from  w  w  w. j  a  va 2  s.c o  m*/
    // System.out.println(":Touching Key (" + getTypeLabel() + "): ");
    printInfo();
    try {
        testRuner.sendPointerSync(event);
    } catch (Exception e) {
        MonkeyLog.l(":Touching rejected ");
        return MonkeyEvent.INJECT_FAIL;
    } finally {
        event.recycle();
    }

    // testRuner.clickOnScreen(event.getRawX(), event.getRawY());

    return MonkeyEvent.INJECT_SUCCESS;
}