Code example for Instrumentation

Methods: sendPointerSyncwaitForIdleSync, sleep

4
        int absoluteX = location[0];
        int absoluteY = location[1];
 
        MotionEvent event = MotionEvent.obtain(downTime, eventTime,
                MotionEvent.ACTION_DOWN, absoluteX, absoluteY, 0);
        instrumentation.sendPointerSync(event);
        instrumentation.waitForIdleSync();
 
        eventTime = SystemClock.uptimeMillis();
        final int touchSlop = ViewConfiguration.get(v.getContext()).getScaledTouchSlop();
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE,
                absoluteX + touchSlop / 2, absoluteY + touchSlop / 2, 0);
        instrumentation.sendPointerSync(event);
        instrumentation.waitForIdleSync();
 
        try { 
            Thread.sleep((long)(ViewConfiguration.getLongPressTimeout() * 1.5f));
        } catch (InterruptedException e) {
            e.printStackTrace();
        } 
 
        eventTime = SystemClock.uptimeMillis();
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP,
                absoluteX, absoluteY, 0);
        instrumentation.sendPointerSync(event);
        instrumentation.waitForIdleSync();
    } 
 
    /** 
     * Starts (synchronously) a drag motion. Normally followed by dragTo() and dragEnd(). 
     *