Example usage for android.view MotionEvent getEventTime

List of usage examples for android.view MotionEvent getEventTime

Introduction

In this page you can find the example usage for android.view MotionEvent getEventTime.

Prototype

@Override
public final long getEventTime() 

Source Link

Document

Retrieve the time this event occurred, in the android.os.SystemClock#uptimeMillis time base.

Usage

From source file:Main.java

/**
 * Checks if touch event is treat as single tap
 *
 * @param context android context// w ww . j  a v  a2 s  .com
 * @param downX   axis x of touch down
 * @param downY   axis y of touch down
 * @param upEvent MotionEvent for touch up
 * @return true if it's single tap, otherwise false
 */
public static boolean isSingleTap(Context context, float downX, float downY, MotionEvent upEvent) {
    return isSingleTap(context, upEvent.getDownTime(), upEvent.getEventTime(), downX, downY, upEvent.getX(),
            upEvent.getY());
}

From source file:Main.java

public static void inspectEvent(MotionEvent e) {
    if (e == null)
        return;/*from w  ww .j a va 2s .c  om*/

    final int pointerCount = e.getPointerCount();

    Log.d(TAG, "Input: event time: " + e.getEventTime());
    for (int p = 0; p < pointerCount; p++) {
        Log.d(TAG, "Input:  pointer:" + e.getPointerId(p) + " x:" + e.getX(p) + " y:" + e.getY(p) + " action:"
                + e.getAction());
    }
}

From source file:Main.java

private static MotionEvent transformEventOld(MotionEvent e, Matrix m) {
    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    PointerCoords[] pointerCoords = getPointerCoords(e);
    int metaState = e.getMetaState();
    float xPrecision = e.getXPrecision();
    float yPrecision = e.getYPrecision();
    int deviceId = e.getDeviceId();
    int edgeFlags = e.getEdgeFlags();
    int source = e.getSource();
    int flags = e.getFlags();

    // Copy the x and y coordinates into an array, map them, and copy back.
    float[] xy = new float[pointerCoords.length * 2];
    for (int i = 0; i < pointerCount; i++) {
        xy[2 * i] = pointerCoords[i].x;/*from w w  w . ja v  a 2s .c  o  m*/
        xy[2 * i + 1] = pointerCoords[i].y;
    }
    m.mapPoints(xy);
    for (int i = 0; i < pointerCount; i++) {
        pointerCoords[i].x = xy[2 * i];
        pointerCoords[i].y = xy[2 * i + 1];
        pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation);
    }

    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords,
            metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags);

    return n;
}

From source file:Main.java

private static MotionEvent transformEventOld(MotionEvent e, Matrix m) {
    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    PointerCoords[] pointerCoords = getPointerCoords(e);
    int metaState = e.getMetaState();
    float xPrecision = e.getXPrecision();
    float yPrecision = e.getYPrecision();
    int deviceId = e.getDeviceId();
    int edgeFlags = e.getEdgeFlags();
    int source = e.getSource();
    int flags = e.getFlags();
    // Copy the x and y coordinates into an array, map them, and copy back.
    float[] xy = new float[pointerCoords.length * 2];
    for (int i = 0; i < pointerCount; i++) {
        xy[2 * i] = pointerCoords[i].x;/*from www  . j a va  2s. c  o  m*/
        xy[2 * i + 1] = pointerCoords[i].y;
    }
    m.mapPoints(xy);
    for (int i = 0; i < pointerCount; i++) {
        pointerCoords[i].x = xy[2 * i];
        pointerCoords[i].y = xy[2 * i + 1];
        pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation);
    }
    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords,
            metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags);
    return n;
}

From source file:Main.java

public static JSONObject CreateJSonObjectFromMotionEvent(MotionEvent e) throws JSONException {
    JSONObject jObj = new JSONObject();
    jObj.put("downTime", e.getDownTime());
    jObj.put("eventTime", e.getEventTime());
    jObj.put("action", e.getAction());
    jObj.put("pointerCount", e.getPointerCount());
    jObj.put("metaState", e.getMetaState());
    jObj.put("buttonState", e.getButtonState());
    jObj.put("xPrecision", e.getXPrecision());
    jObj.put("yPrecision", e.getYPrecision());
    jObj.put("deviceId", e.getDeviceId());
    jObj.put("edgeFlags", e.getEdgeFlags());
    jObj.put("source", e.getSource());
    jObj.put("flags", e.getFlags());

    for (int i = 0; i < e.getPointerCount(); i++) {
        PointerProperties prop = new PointerProperties();
        e.getPointerProperties(i, prop);

        PointerCoords coords = new PointerCoords();
        e.getPointerCoords(i, coords);//from  w w  w  .  ja  va 2 s  . c  om

        JSONObject pointer = JObjFromPointer(prop, coords);
        jObj.accumulate("pointers", pointer);
    }

    return jObj;
}

From source file:Main.java

public static MotionEvent hoverMotionEventAtPosition(View view, int action, int xPercent, int yPercent) {
    MotionEvent ev = motionEventAtPosition(view, action, xPercent, yPercent);

    MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[1];
    pointerProperties[0] = new MotionEvent.PointerProperties();

    MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[1];
    pointerCoords[0] = new MotionEvent.PointerCoords();
    pointerCoords[0].x = ev.getX();/*from  w ww  .j  a v a  2  s . c  o m*/
    pointerCoords[0].y = ev.getY();

    return MotionEvent.obtain(ev.getDownTime(), ev.getEventTime(), ev.getAction(), 1, pointerProperties,
            pointerCoords, ev.getMetaState(), 0, ev.getXPrecision(), ev.getYPrecision(), ev.getDeviceId(),
            ev.getEdgeFlags(), InputDevice.SOURCE_CLASS_POINTER, ev.getFlags());
}

From source file:org.mozilla.gecko.ui.SimpleScaleGestureDetector.java

private void onTouchStart(MotionEvent event) {
    mLastEventTime = event.getEventTime();
    mPointerInfo.addFirst(PointerInfo.create(event, getActionIndex(event)));
    if (getPointersDown() == 2) {
        sendScaleGesture(EventType.BEGIN);
    }/*  w w w.j  a v  a  2s .c om*/
}

From source file:org.mozilla.gecko.ui.SimpleScaleGestureDetector.java

private void onTouchMove(MotionEvent event) {
    mLastEventTime = event.getEventTime();
    for (int i = 0; i < event.getPointerCount(); i++) {
        PointerInfo pointerInfo = pointerInfoForEventIndex(event, i);
        if (pointerInfo != null) {
            pointerInfo.populate(event, i);
        }/*from w  w w . j  a va 2 s .com*/
    }

    if (getPointersDown() == 2) {
        sendScaleGesture(EventType.CONTINUE);
    }
}

From source file:org.mozilla.gecko.ui.SimpleScaleGestureDetector.java

private void onTouchEnd(MotionEvent event) {
    mLastEventTime = event.getEventTime();

    int id = event.getPointerId(getActionIndex(event));
    ListIterator<PointerInfo> iterator = mPointerInfo.listIterator();
    while (iterator.hasNext()) {
        PointerInfo pointerInfo = iterator.next();
        if (pointerInfo.getId() != id) {
            continue;
        }/*from w  ww.  j a va 2  s .c o  m*/

        // One of the pointers we were tracking was lifted. Remove its info object from the
        // list, recycle it to avoid GC pauses, and send an onScaleEnd() notification if this
        // ended the gesture.
        iterator.remove();
        pointerInfo.recycle();
        if (getPointersDown() == 1) {
            sendScaleGesture(EventType.END);
        }
    }
}

From source file:com.jinzht.pro.view.RecyclerViewHeader.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    if (mRecyclerWantsTouchEvent) {
        int scrollDiff = mCurrentScroll - mDownScroll;
        MotionEvent recyclerEvent = MotionEvent.obtain(event.getDownTime(), event.getEventTime(),
                event.getAction(), event.getX(), event.getY() - scrollDiff, event.getMetaState());
        mRecycler.onTouchEvent(recyclerEvent);
        return false;
    }//from   w w w . j a v a2s .  c  om
    return super.onTouchEvent(event);
}