public void scroll(Coordinates where, int xOffset, int yOffset) {
    long downTime = SystemClock.uptimeMillis();
    List<MotionEvent> motionEvents = new ArrayList<MotionEvent>();
    Point origin = where.getLocationOnScreen();
    Point destination = new Point(origin.x + xOffset, origin.y + yOffset);
    motionEvents.add(getMotionEvent(downTime, downTime, MotionEvent.ACTION_DOWN, origin));

    Scroll scroll = new Scroll(origin, destination, downTime);
    // Initial acceleration from origin to reference point
    motionEvents.addAll(
        getMoveEvents(
            downTime,
            downTime,
            origin,
            scroll.getDecelerationPoint(),
            scroll.INITIAL_STEPS,
            scroll.TIME_BETWEEN_EVENTS));
    // Deceleration phase from reference point to destination
    motionEvents.addAll(
        getMoveEvents(
            downTime,
            scroll.getEventTimeForReferencePoint(),
            scroll.getDecelerationPoint(),
            destination,
            scroll.DECELERATION_STEPS,
            scroll.TIME_BETWEEN_EVENTS));

    motionEvents.add(
        getMotionEvent(
            downTime,
            (downTime + scroll.getEventTimeForDestinationPoint()),
            MotionEvent.ACTION_UP,
            destination));
    sendMotionEvents(motionEvents);
  }
  public void longPress(Coordinates where) {
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    Point point = where.getLocationOnScreen();
    // List<MotionEvent> motionEvents = new ArrayList<MotionEvent>();
    //
    // motionEvents.add(getMotionEvent(downTime, downTime, MotionEvent.ACTION_DOWN, point));
    // motionEvents.add(getMotionEvent(downTime, (downTime + 3000), MotionEvent.ACTION_UP, point));
    // sendMotionEvents(motionEvents);
    Instrumentation inst = instrumentation;

    MotionEvent event = null;
    boolean successfull = false;
    int retry = 0;
    while (!successfull && retry < 10) {
      try {
        if (event == null) {
          event =
              MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, point.x, point.y, 0);
        }
        System.out.println("trying to send pointer");
        inst.sendPointerSync(event);
        successfull = true;
      } catch (SecurityException e) {
        System.out.println("failed: " + retry);
        // activityUtils.hideSoftKeyboard(null, false, true);
        retry++;
      }
    }
    if (!successfull) {
      throw new SelendroidException("Click can not be completed!");
    }
    inst.sendPointerSync(event);
    inst.waitForIdleSync();

    eventTime = SystemClock.uptimeMillis();
    final int touchSlop = ViewConfiguration.get(inst.getTargetContext()).getScaledTouchSlop();
    event =
        MotionEvent.obtain(
            downTime,
            eventTime,
            MotionEvent.ACTION_MOVE,
            point.x + touchSlop / 2,
            point.y + touchSlop / 2,
            0);
    inst.sendPointerSync(event);
    inst.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, point.x, point.y, 0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();
  }
 public void singleTap(Coordinates where) {
   Point toTap = where.getLocationOnScreen();
   List<MotionEvent> motionEvents = new ArrayList<MotionEvent>();
   long downTime = SystemClock.uptimeMillis();
   motionEvents.add(getMotionEvent(downTime, downTime, MotionEvent.ACTION_DOWN, toTap));
   motionEvents.add(getMotionEvent(downTime, downTime, MotionEvent.ACTION_UP, toTap));
   sendMotionEvents(motionEvents);
 }
 public void flick(Coordinates where, int xOffset, int yOffset, int speed) {
   long downTime = SystemClock.uptimeMillis();
   List<MotionEvent> motionEvents = new ArrayList<MotionEvent>();
   Point origin = where.getLocationOnScreen();
   Point destination = new Point(origin.x + xOffset, origin.y + yOffset);
   Flick flick = new Flick(speed);
   motionEvents.add(getMotionEvent(downTime, downTime, MotionEvent.ACTION_DOWN, origin));
   motionEvents.addAll(
       getMoveEvents(
           downTime, downTime, origin, destination, flick.STEPS, flick.getTimeBetweenEvents()));
   motionEvents.add(
       getMotionEvent(
           downTime,
           flick.getTimeForDestinationPoint(downTime),
           MotionEvent.ACTION_UP,
           destination));
   sendMotionEvents(motionEvents);
 }