Example usage for android.view MotionEvent getDownTime

List of usage examples for android.view MotionEvent getDownTime

Introduction

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

Prototype

public final long getDownTime() 

Source Link

Document

Returns the time (in ms) when the user originally pressed down to start a stream of position events.

Usage

From source file:Main.java

/**
 * Checks if touch event is treat as single tap
 *
 * @param context android context// w ww  .ja  va 2s . c o  m
 * @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

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;//  w  w w. j  a v a2s . 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;/*  ww  w  .  j  a 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

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 ww  .jav a  2s .  c  o m

        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();/*  w w w. ja  v  a 2s  . 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: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 va2 s . co  m
    return super.onTouchEvent(event);
}

From source file:com.facebook.react.uimanager.events.TouchEvent.java

private void init(int viewTag, long timestampMs, TouchEventType touchEventType, MotionEvent motionEventToCopy,
        float viewX, float viewY) {
    super.init(viewTag, timestampMs);

    short coalescingKey = 0;
    int action = (motionEventToCopy.getAction() & MotionEvent.ACTION_MASK);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        TouchEventCoalescingKeyHelper.addCoalescingKey(motionEventToCopy.getDownTime());
        break;/* w  w w .  j  a v a2  s  .c  o  m*/
    case MotionEvent.ACTION_UP:
        TouchEventCoalescingKeyHelper.removeCoalescingKey(motionEventToCopy.getDownTime());
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_POINTER_UP:
        TouchEventCoalescingKeyHelper.incrementCoalescingKey(motionEventToCopy.getDownTime());
        break;
    case MotionEvent.ACTION_MOVE:
        coalescingKey = TouchEventCoalescingKeyHelper.getCoalescingKey(motionEventToCopy.getDownTime());
        break;
    case MotionEvent.ACTION_CANCEL:
        TouchEventCoalescingKeyHelper.removeCoalescingKey(motionEventToCopy.getDownTime());
        break;
    default:
        throw new RuntimeException("Unhandled MotionEvent action: " + action);
    }
    mTouchEventType = touchEventType;
    mMotionEvent = MotionEvent.obtain(motionEventToCopy);
    mCoalescingKey = coalescingKey;
    mViewX = viewX;
    mViewY = viewY;
}

From source file:com.jwork.spycamera.MainFragment.java

@Override
public boolean onTouch(View view, MotionEvent event) {
    log.v(this, "onTouch(action:" + event.getAction() + "|actionindex:" + event.getActionIndex() + "|downtime:"
            + event.getDownTime() + "|eventtime:" + event.getEventTime() + ")");
    if (view == layoutBlack) {
        sgdBlack.onTouchEvent(event);//from  w  w  w.j  a v a  2 s .  c  o  m
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            controller.blackScreenClick();
        }
        return true;
    } else if (view == svPreview) {
        sgdPreview.onTouchEvent(event);
        return true;
    }
    return false;
}

From source file:org.solovyev.android.calculator.drag.SimpleDragListener.java

@Override
public boolean onDrag(@Nonnull DragButton dragButton, @Nonnull DragEvent event) {
    boolean consumed = false;

    final MotionEvent motionEvent = event.getMotionEvent();

    final Point2d start = event.getStartPoint();
    final Point2d end = new Point2d(motionEvent.getX(), motionEvent.getY());
    final float distance = Maths.getDistance(start, end);

    final MutableObject<Boolean> right = new MutableObject<>();
    final double angle = Math.toDegrees(Maths.getAngle(start, Maths.sum(start, axis), end, right));

    final long duration = motionEvent.getEventTime() - motionEvent.getDownTime();
    final DragDirection direction = getDirection(distance, (float) angle, right.getObject());
    if (direction != null && duration > 40 && duration < 2500) {
        consumed = processor.processDragEvent(direction, dragButton, start, motionEvent);
    }/*from   www.ja  v a2s. com*/

    return consumed;
}

From source file:android.support.wear.widget.util.ArcSwipe.java

private Swiper.Status sendArcSwipe(UiController uiController, float[] startCoordinates, float[] endCoordinates,
        float[] precision, int duration, boolean isClockwise) {

    float[][] steps = interpolate(startCoordinates, endCoordinates, SWIPE_EVENT_COUNT, isClockwise);
    final int delayBetweenMovements = duration / steps.length;

    MotionEvent downEvent = MotionEvents.sendDown(uiController, startCoordinates, precision).down;
    try {// w w  w . j av a 2 s.c  om
        for (int i = 0; i < steps.length; i++) {
            if (!MotionEvents.sendMovement(uiController, downEvent, steps[i])) {
                Log.e(TAG, "Injection of move event as part of the swipe failed. Sending cancel " + "event.");
                MotionEvents.sendCancel(uiController, downEvent);
                return Swiper.Status.FAILURE;
            }

            long desiredTime = downEvent.getDownTime() + delayBetweenMovements * i;
            long timeUntilDesired = desiredTime - SystemClock.uptimeMillis();
            if (timeUntilDesired > 10) {
                uiController.loopMainThreadForAtLeast(timeUntilDesired);
            }
        }

        if (!MotionEvents.sendUp(uiController, downEvent, endCoordinates)) {
            Log.e(TAG, "Injection of up event as part of the swipe failed. Sending cancel event.");
            MotionEvents.sendCancel(uiController, downEvent);
            return Swiper.Status.FAILURE;
        }
    } finally {
        downEvent.recycle();
    }
    return Swiper.Status.SUCCESS;
}