Example usage for android.view MotionEvent ACTION_POINTER_UP

List of usage examples for android.view MotionEvent ACTION_POINTER_UP

Introduction

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

Prototype

int ACTION_POINTER_UP

To view the source code for android.view MotionEvent ACTION_POINTER_UP.

Click Source Link

Document

Constant for #getActionMasked : A non-primary pointer has gone up.

Usage

From source file:ch.jeda.platform.android.CanvasFragment.java

@Override
public boolean onTouch(final View view, final MotionEvent event) {
    int index;// w  ww  . jav a  2 s  .co m
    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        index = event.getActionIndex();
        this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_DOWN, event.getPointerId(index),
                (int) event.getX(index), (int) event.getY(index)));
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        index = event.getActionIndex();
        this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_UP, event.getPointerId(index),
                (int) event.getX(index), (int) event.getY(index)));
        break;
    case MotionEvent.ACTION_MOVE:
        for (index = 0; index < event.getPointerCount(); ++index) {
            this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_MOVED,
                    event.getPointerId(index), (int) event.getX(index), (int) event.getY(index)));
        }

        break;
    }
    return true;
}

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

/** Forward touch events to this function. */
public void onTouchEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        onTouchStart(event);/*from ww w .ja v  a 2  s  . c  om*/
        break;
    case MotionEvent.ACTION_MOVE:
        onTouchMove(event);
        break;
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        onTouchEnd(event);
        break;
    }
}

From source file:ngoctdn.vng.gesture.CupcakeGestureDetector.java

public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        mVelocityTracker = VelocityTracker.obtain();
        if (null != mVelocityTracker) {
            mVelocityTracker.addMovement(ev);
        } else {//from w  ww.ja  v a  2 s . c  o  m
            Log.i(LOG_TAG, "Velocity tracker is null");
        }

        mLastTouchX = getActiveX(ev);
        mLastTouchY = getActiveY(ev);
        mFirstRawTouchY = ev.getRawY();
        mLastRawTouchY = ev.getRawY();
        mIsDragging = false;
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }

    case MotionEvent.ACTION_POINTER_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;

    case MotionEvent.ACTION_MOVE: {
        final float x = getActiveX(ev);
        final float y = getActiveY(ev);
        final float dx = x - mLastTouchX, dy = y - mLastTouchY;

        if (!mIsDragging) {
            // Use Pythagoras to see if drag length is larger than
            // touch slop
            mIsDragging = Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
        }

        if (mIsDragging) {
            if (ev.getPointerCount() == 1)
                mListener.onDrag(mLastRawTouchY, ev.getRawY(), dx, dy);
            mLastTouchX = x;
            mLastTouchY = y;
            mLastRawTouchY = ev.getRawY();
            // if (mListener != null) {
            // mListener.onScrolling(mLastRawTouchY, ev.getRawY());
            // mLastRawTouchY = ev.getRawY();
            // }

            if (null != mVelocityTracker) {
                mVelocityTracker.addMovement(ev);
            }
        }
        if (mActivePointerId == -1 && mListener != null) {
            mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }
        break;
    }

    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {

        if (mIsDragging) {
            if (null != mVelocityTracker) {

                mLastTouchX = getActiveX(ev);
                mLastTouchY = getActiveY(ev);

                // if (mListener != null) {
                // mListener.onScrolling(mFirstTouchY, mLastTouchY);
                // }

                // Compute velocity within the last 1000ms
                mVelocityTracker.addMovement(ev);
                mVelocityTracker.computeCurrentVelocity(1000);

                final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity();

                // If the velocity is greater than minVelocity, call
                // listener
                if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
                    mListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY);
                }
            }
        }

        if (mListener != null) {
            mLastRawTouchY = ev.getRawY();
            if (mVelocityTracker != null)
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), mVelocityTracker.getYVelocity());
            else
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }

        // Recycle Velocity Tracker
        if (null != mVelocityTracker) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

    return true;
}

From source file:com.intel.xdk.multitouch.MultiTouch.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();/*from www.jav  a 2s  .co m*/

    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                try {
                    Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class);
                    m.invoke(WebView.class, true);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //WebView.setWebContentsDebuggingEnabled(true);
            }
        }
    });

    touchy = new View.OnTouchListener() {

        private SparseArray<Long> pointerId2Identifier = new SparseArray<Long>();

        @Override
        public boolean onTouch(View v, MotionEvent ev) {
            if (isMultitouchEnabled) {
                int pointerCount = ev.getPointerCount();

                //get the correct action
                int maskedAction = ev.getActionMasked();
                int idx = ev.getActionIndex();
                try {
                    String js = null;
                    if (maskedAction == MotionEvent.ACTION_POINTER_DOWN
                            || maskedAction == MotionEvent.ACTION_DOWN) {
                        int x = (int) ev.getX(idx);
                        int y = (int) ev.getY(idx);
                        int h = (int) v.getHeight();
                        int w = (int) v.getWidth();
                        int id = ev.getPointerId(idx);
                        //make a timestamp identifier and store it
                        long identifier = System.currentTimeMillis();
                        pointerId2Identifier.put(id, identifier);
                        js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchstart'},", identifier, x, y,
                                h, w);
                        queueMultitouchData(js, id, maskedAction);
                    } else if (maskedAction == MotionEvent.ACTION_POINTER_UP
                            || maskedAction == MotionEvent.ACTION_UP) {
                        int x = (int) ev.getX(idx);
                        int y = (int) ev.getY(idx);
                        int h = (int) v.getHeight();
                        int w = (int) v.getWidth();
                        int id = ev.getPointerId(idx);
                        js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchend'},",
                                pointerId2Identifier.get(id), x, y, h, w);
                        pointerId2Identifier.remove(id);
                        queueMultitouchData(js, id, maskedAction);
                    } else if (maskedAction == MotionEvent.ACTION_MOVE) {
                        //send all events if it is a move
                        for (int i = 0; i < pointerCount; i++) {
                            int x = (int) ev.getX(i);
                            int y = (int) ev.getY(i);
                            int h = (int) v.getHeight();
                            int w = (int) v.getWidth();
                            int id = ev.getPointerId(i);
                            js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchmove'},",
                                    pointerId2Identifier.get(id), x, y, h, w);
                            queueMultitouchData(js, id, maskedAction);
                        }
                    } else {
                        Log.e("[intel.xdk]", "got a MotionEvent that is not up/down/move:" + ev);
                    }
                    //Log.i("[intel.xdk]", "onTouchEvent:"+js);
                } catch (Exception e) {
                    Log.e("[intel.xdk]", "Got an exception back from WebView: ", e);
                }

                return true;
            } else {
                return false;
            }
        }
    };
    webView.setOnTouchListener(touchy);

    lock = this;
    messages = new ArrayList<String>(0);
}

From source file:org.deviceconnect.android.deviceplugin.host.activity.TouchProfileActivity.java

@Override
public boolean onTouchEvent(final MotionEvent event) {
    List<Event> events;
    String state = null;//from w  w  w .  j  a va2 s. co  m
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: // 1st touch only.
    case MotionEvent.ACTION_POINTER_DOWN: // Others touch.
        state = HostDeviceApplication.STATE_START;
        // "ontouch" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH);
        if (events != null) {
            sendEventData(state, event, events);
        }

        // "ontouchstart" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_START);
        break;
    case MotionEvent.ACTION_UP: // Last touch remove only.
    case MotionEvent.ACTION_POINTER_UP: // Others touch move.
        state = HostDeviceApplication.STATE_END;
        // "ontouchend" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_END);
        break;
    case MotionEvent.ACTION_MOVE:
        state = HostDeviceApplication.STATE_MOVE;
        // "ontouchmove" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_MOVE);
        break;
    case MotionEvent.ACTION_CANCEL:
        state = HostDeviceApplication.STATE_CANCEL;
        // "ontouchcancel" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_CANCEL);
        break;
    default:
        return mGestureDetector.onTouchEvent(event);
    }

    if (events != null) {
        sendEventData(state, event, events);
    }
    return mGestureDetector.onTouchEvent(event);
}

From source file:org.deviceconnect.android.deviceplugin.wear.activity.WearTouchProfileActivity.java

@Override
public boolean dispatchTouchEvent(@NonNull final MotionEvent event) {
    boolean execFlag = false;
    int action = (event.getAction() & MotionEvent.ACTION_MASK);
    String strAction = null;/*  ww w  .ja  v a 2  s . c  om*/
    switch (action) {
    case MotionEvent.ACTION_DOWN: // 1st touch only.
    case MotionEvent.ACTION_POINTER_DOWN: // Others touch.
        // "ontouch" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCH) != 0) {
            sendEventData(WearConst.PARAM_TOUCH_TOUCH, event);
        }

        // "ontouchstart" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHSTART) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHSTART;
            execFlag = true;
        }
        break;
    case MotionEvent.ACTION_UP: // Last touch remove only.
    case MotionEvent.ACTION_POINTER_UP: // Others touch move.
        // "ontouchend" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHEND) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHEND;
            execFlag = true;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        // "ontouchmove" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHMOVE) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHMOVE;
            execFlag = true;
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        // "ontouchcancel" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCANCEL) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHCANCEL;
            execFlag = true;
        }
        break;
    default:
        return mGestureDetector.onTouchEvent(event);
    }

    if (execFlag) {
        sendEventData(strAction, event);
    }
    return mGestureDetector.onTouchEvent(event) || super.dispatchTouchEvent(event);
}

From source file:ch.fhnw.comgr.GLES3Activity.java

@Override
public boolean onTouch(View v, final MotionEvent event) {
    if (event == null) {
        Log.i(TAG, "onTouch: null event");
        return false;
    }//from   ww w. ja  v  a  2 s .  c  om

    int action = event.getAction();
    int actionCode = action & MotionEvent.ACTION_MASK;

    try {
        if (actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN)
            return handleTouchDown(event);
        else if (actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_POINTER_UP)
            return handleTouchUp(event);
        else if (actionCode == MotionEvent.ACTION_MOVE)
            return handleTouchMove(event);
        else
            Log.i(TAG, "Unhandeled Event: " + actionCode);
    } catch (Exception ex) {
        Log.i(TAG, "onTouch (Exception: " + actionCode);
    }

    return false;
}

From source file:ngoctdn.vng.gesture.DragGestureDetector.java

public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        mVelocityTracker = VelocityTracker.obtain();
        if (null != mVelocityTracker) {
            mVelocityTracker.addMovement(ev);
        } else {//from   ww w  .  ja  v  a2 s  . com
            Log.i(LOG_TAG, "Velocity tracker is null");
        }

        mLastTouchX = getActiveX(ev);
        mLastTouchY = getActiveY(ev);
        mFirstRawTouchY = ev.getRawY();
        mLastRawTouchY = ev.getRawY();
        mIsDragging = false;
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }

    case MotionEvent.ACTION_POINTER_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;

    case MotionEvent.ACTION_MOVE: {
        final float x = getActiveX(ev);
        final float y = getActiveY(ev);
        final float dx = x - mLastTouchX, dy = y - mLastTouchY;

        if (!mIsDragging) {
            // Use Pythagoras to see if drag length is larger than
            // touch slop
            mIsDragging = (float) Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
        }

        if (mIsDragging) {
            if (ev.getPointerCount() == 1)
                mListener.onDrag(mLastRawTouchY, ev.getRawY(), dx, dy);
            mLastTouchX = x;
            mLastTouchY = y;
            mLastRawTouchY = ev.getRawY();
            // if (mListener != null) {
            // mListener.onScrolling(mLastRawTouchY, ev.getRawY());
            // mLastRawTouchY = ev.getRawY();
            // }

            if (null != mVelocityTracker) {
                mVelocityTracker.addMovement(ev);
            }
        }
        if (mActivePointerId == -1 && mListener != null) {
            mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }
        break;
    }

    //      case MotionEvent.ACTION_CANCEL: {
    //         if (mListener != null) {
    //            mLastRawTouchY = ev.getRawY();
    //            mListener.onRelease(mFirstRawTouchY, ev.getRawY());
    //         }
    //         // Recycle Velocity Tracker
    //         if (null != mVelocityTracker) {
    //            mVelocityTracker.recycle();
    //            mVelocityTracker = null;
    //         }
    //         break;
    //      }
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {

        if (mIsDragging) {
            if (null != mVelocityTracker) {

                mLastTouchX = getActiveX(ev);
                mLastTouchY = getActiveY(ev);

                // if (mListener != null) {
                // mListener.onScrolling(mFirstTouchY, mLastTouchY);
                // }

                // Compute velocity within the last 1000ms
                mVelocityTracker.addMovement(ev);
                mVelocityTracker.computeCurrentVelocity(1000);

                final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity();

                // If the velocity is greater than minVelocity, call
                // listener
                if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
                    mListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY);
                }
            }
        }

        if (mListener != null) {
            mLastRawTouchY = ev.getRawY();
            if (mVelocityTracker != null)
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), mVelocityTracker.getYVelocity());
            else
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }

        // Recycle Velocity Tracker
        if (null != mVelocityTracker) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

    return true;
}

From source file:net.henryco.opalette.api.glES.glSurface.view.OPallSurfaceTouchListener.java

@Override
public void onTouchEvent(MotionEvent ev) {
    // Let the ScaleGestureDetector inspect all events.
    scaled = false;//from  w  w  w .  j  a  v  a2 s.c o  m
    if (scaleDetector != null)
        scaleDetector.onTouchEvent(ev);

    final int action = MotionEventCompat.getActionMasked(ev);

    if (!scaled || !scaleMatters) {
        switch (action) {
        case MotionEvent.ACTION_DOWN: {
            final int pointerIndex = MotionEventCompat.getActionIndex(ev);
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float y = MotionEventCompat.getY(ev, pointerIndex);

            if (onActionDown != null)
                onActionDown.onActionDown(x, y, ev);

            // Remember where we started (for dragging)
            last[0] = x;
            last[1] = y;
            // Save the ID of this pointer (for dragging)
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            break;
        }

        case MotionEvent.ACTION_MOVE: {
            // Find the index of the active pointer and fetch its position
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);

            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float y = MotionEventCompat.getY(ev, pointerIndex);

            // Calculate the distance moved
            final float dx = x - last[0];
            final float dy = y - last[1];

            if (onActionMove != null)
                onActionMove.onActionMove(dx, dy, ev);

            // Remember this touch position for the next move event
            last[0] = x;
            last[1] = y;

            break;
        }

        case MotionEvent.ACTION_UP: {
            mActivePointerId = MotionEvent.INVALID_POINTER_ID;
            if (onActionUp != null)
                onActionUp.onAction(ev);
            break;
        }

        case MotionEvent.ACTION_CANCEL: {
            mActivePointerId = MotionEvent.INVALID_POINTER_ID;
            break;
        }

        case MotionEvent.ACTION_POINTER_UP: {

            final int pointerIndex = MotionEventCompat.getActionIndex(ev);
            final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);

            if (pointerId == mActivePointerId) {
                // This was our active pointer going up. Choose a new
                // active pointer and adjust accordingly.
                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                last[0] = MotionEventCompat.getX(ev, newPointerIndex);
                last[1] = MotionEventCompat.getY(ev, newPointerIndex);
                mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
            }
            if (onActionPointerUp != null)
                onActionPointerUp.onAction(ev);
            break;
        }
        }
    }
}

From source file:com.heinrichreimersoftware.materialintro.view.SwipeBlockableViewPager.java

private boolean handleTouchEvent(MotionEvent event) {
    boolean allowTouch = false;
    final int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        lastTouchX = event.getX();/*from   www  . j av a 2 s . c o m*/

        // Save the ID of this pointer
        activePointerId = event.getPointerId(0);

        break;
    }

    case MotionEvent.ACTION_MOVE: {
        // Find the index of the active pointer and fetch its position
        final int pointerIndex = event.findPointerIndex(activePointerId);
        final float x = event.getX(pointerIndex);

        final float dx = x - lastTouchX;

        if (dx > 0) {
            // Swiped right
            if (!swipeRightEnabled && Math.abs(dx) > SWIPE_LOCK_THRESHOLD) {
                lockedRight = true;
            }
            if (!lockedRight) {
                allowTouch = true;
                if (Math.abs(dx) > SWIPE_UNLOCK_THRESHOLD) {
                    lockedLeft = false;
                }
            }
        } else if (dx < 0) {
            // Swiped left
            if (!swipeLeftEnabled && Math.abs(dx) > SWIPE_LOCK_THRESHOLD) {
                lockedLeft = true;
            }
            if (!lockedLeft) {
                allowTouch = true;
                if (Math.abs(dx) > SWIPE_UNLOCK_THRESHOLD) {
                    lockedRight = false;
                }
            }
        }

        lastTouchX = x;

        invalidate();
        break;
    }

    case MotionEvent.ACTION_UP: {
        activePointerId = INVALID_POINTER_ID;
        lockedLeft = false;
        lockedRight = false;
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        activePointerId = INVALID_POINTER_ID;
        lockedLeft = false;
        lockedRight = false;
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        // Extract the index of the pointer that left the touch sensor
        final int pointerIndex = (action
                & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        final int pointerId = event.getPointerId(pointerIndex);
        if (pointerId == activePointerId) {
            // This was our active pointer going up. Choose a new
            // active pointer and adjust accordingly.
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            lastTouchX = event.getX(newPointerIndex);
            activePointerId = event.getPointerId(newPointerIndex);
        }
        break;
    }
    }

    return (!lockedLeft && !lockedRight) || allowTouch;
}