Code example for MotionEvent

Methods: getActiongetDownTimegetEventTimegetXgetY

0
    } 
 
    // Cancel LONG_PRESS timers. 
    void cancelLongPressIfNeeded(MotionEvent ev) {
        if (!hasPendingMessage() || 
            mCurrentDownEvent == null || ev.getDownTime() != mCurrentDownEvent.getDownTime()) {
            return; 
        } 
        final int action = ev.getAction();
        final float y = ev.getY();
        final float x = ev.getX();
        switch (action & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_MOVE:
                final int deltaX = (int) (x - mCurrentDownEvent.getX());
                final int deltaY = (int) (y - mCurrentDownEvent.getY());
                int distance = (deltaX * deltaX) + (deltaY * deltaY);
                if (distance > mTouchSlopSquare) {
                    mInLongPress = false;
                    mLongPressHandler.removeMessages(LONG_PRESS);
                } 
                break; 
            case MotionEvent.ACTION_UP:
                if (mCurrentDownEvent.getDownTime() + TAP_TIMEOUT + LONGPRESS_TIMEOUT >
                    ev.getEventTime()) {
                    mInLongPress = false;
                    mLongPressHandler.removeMessages(LONG_PRESS);
                } 
                break; 
            default: 
                break;