Example usage for android.view MotionEvent ACTION_UP

List of usage examples for android.view MotionEvent ACTION_UP

Introduction

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

Prototype

int ACTION_UP

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

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.

Usage

From source file:com.appunite.list.FastScroller.java

boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN:
        if (mState > STATE_NONE && isPointInside(ev.getX(), ev.getY())) {
            if (!mList.isInScrollingContainerUnhide()) {
                beginDrag();/*from  w  w w .java2s.  c  om*/
                return true;
            }
            mInitialTouchY = ev.getY();
            startPendingDrag();
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        cancelPendingDrag();
        break;
    }
    return false;
}

From source file:anabolicandroids.chanobol.util.swipebottom.SwipeRefreshLayoutBottom.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();/*from  w w  w.  ja v  a2  s .c  om*/

    final int action = MotionEventCompat.getActionMasked(ev);

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;
    }

    //if (!isEnabled() || mReturningToStart || canChildScrollUp() || mRefreshing) {
    if (!isEnabled() || mReturningToStart || canChildScrollDown() || mRefreshing) { // TODO
        // Fail fast if we're not in a state where a swipe is possible
        return false;
    }

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCircleView.getTop(), true);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        final float initialMotionY = getMotionEventY(ev, mActivePointerId);
        if (initialMotionY == -1) {
            return false;
        }
        mInitialMotionY = initialMotionY;

    case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER) {
            Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
            return false;
        }

        final float y = getMotionEventY(ev, mActivePointerId);
        if (y == -1) {
            return false;
        }
        //final float yDiff = y - mInitialMotionY;
        final float yDiff = mInitialMotionY - y; // TODO                
        if (yDiff > mTouchSlop && !mIsBeingDragged) {
            mIsBeingDragged = true;
            mProgress.setAlpha(STARTING_PROGRESS_ALPHA);
        }
        break;

    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        break;
    }

    return mIsBeingDragged;
}

From source file:com.appunite.list.FastScroller.java

boolean onTouchEvent(MotionEvent me) {
    if (mState == STATE_NONE) {
        return false;
    }/*from  w w w  .  ja v a  2  s  . c  om*/

    final int action = me.getAction();

    if (action == MotionEvent.ACTION_DOWN) {
        if (isPointInside(me.getX(), me.getY())) {
            if (!mList.isInScrollingContainerUnhide()) {
                beginDrag();
                return true;
            }
            mInitialTouchY = me.getY();
            startPendingDrag();
        }
    } else if (action == MotionEvent.ACTION_UP) { // don't add ACTION_CANCEL here
        if (mPendingDrag) {
            // Allow a tap to scroll.
            beginDrag();

            final int viewHeight = mList.getHeight();
            // Jitter
            int newThumbY = (int) me.getY() - mThumbH + 10;
            if (newThumbY < 0) {
                newThumbY = 0;
            } else if (newThumbY + mThumbH > viewHeight) {
                newThumbY = viewHeight - mThumbH;
            }
            mThumbY = newThumbY;
            scrollTo((float) mThumbY / (viewHeight - mThumbH));

            cancelPendingDrag();
            // Will hit the STATE_DRAGGING check below
        }
        if (mState == STATE_DRAGGING) {
            if (mList != null) {
                // ViewGroup does the right thing already, but there might
                // be other classes that don't properly reset on touch-up,
                // so do this explicitly just in case.
                mList.requestDisallowInterceptTouchEvent(false);
                mList.reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            }
            setState(STATE_VISIBLE);
            final Handler handler = mHandler;
            handler.removeCallbacks(mScrollFade);
            if (!mAlwaysShow) {
                handler.postDelayed(mScrollFade, 1000);
            }

            mList.invalidate();
            return true;
        }
    } else if (action == MotionEvent.ACTION_MOVE) {
        if (mPendingDrag) {
            final float y = me.getY();
            if (Math.abs(y - mInitialTouchY) > mScaledTouchSlop) {
                setState(STATE_DRAGGING);
                if (mListAdapter == null && mList != null) {
                    getSectionsFromIndexer();
                }
                if (mList != null) {
                    mList.requestDisallowInterceptTouchEvent(true);
                    mList.reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
                }

                cancelFling();
                cancelPendingDrag();
                // Will hit the STATE_DRAGGING check below
            }
        }
        if (mState == STATE_DRAGGING) {
            final int viewHeight = mList.getHeight();
            // Jitter
            int newThumbY = (int) me.getY() - mThumbH + 10;
            if (newThumbY < 0) {
                newThumbY = 0;
            } else if (newThumbY + mThumbH > viewHeight) {
                newThumbY = viewHeight - mThumbH;
            }
            if (Math.abs(mThumbY - newThumbY) < 2) {
                return true;
            }
            mThumbY = newThumbY;
            // If the previous scrollTo is still pending
            if (mScrollCompleted) {
                scrollTo((float) mThumbY / (viewHeight - mThumbH));
            }
            return true;
        }
    } else if (action == MotionEvent.ACTION_CANCEL) {
        cancelPendingDrag();
    }
    return false;
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (isInGraphView(event.getX(0), event.getY(0))) {
        this.mDetector.onTouchEvent(event);
        if (isMeasure) {
            measureEvent(event);//from  ww w . j  a v  a2 s. c  om
        } else {
            scaleEvent(event);
        }
        invalidateGraphView();
        // Go to scaling mode when user release finger in measure mode.
        if (event.getActionMasked() == MotionEvent.ACTION_UP) {
            if (isMeasure) {
                switchMeasureAndScaleMode();
            }
        }
    } else {
        // When finger is outside the plot, hide the cursor and go to scaling mode.
        if (isMeasure) {
            graphView.hideCursor();
            switchMeasureAndScaleMode();
        }
    }
    return super.onTouchEvent(event);
}

From source file:com.android.yijiang.kzx.widget.betterpickers.radialtimepicker.RadialPickerLayout.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    final float eventX = event.getX();
    final float eventY = event.getY();
    int degrees;/*from   w  ww.  ja  va  2s .  c  o m*/
    int value;
    final Boolean[] isInnerCircle = new Boolean[1];
    isInnerCircle[0] = false;

    long millis = SystemClock.uptimeMillis();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mInputEnabled) {
            return true;
        }

        mDownX = eventX;
        mDownY = eventY;

        mLastValueSelected = -1;
        mDoingMove = false;
        mDoingTouch = true;
        // If we're showing the AM/PM, check to see if the user is touching it.
        if (!mHideAmPm) {
            mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
        } else {
            mIsTouchingAmOrPm = -1;
        }
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            // If the touch is on AM or PM, set it as "touched" after the tapTimeout
            // in case the user moves their finger quickly.
            tryVibrate();
            mDownDegrees = -1;
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm);
                    mAmPmCirclesView.invalidate();
                }
            }, tapTimeout);
        } else {
            // If we're in accessibility mode, force the touch to be legal. Otherwise,
            // it will only register within the given touch target zone.
            boolean forceLegal = AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager);
            // Calculate the degrees that is currently being touched.
            mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle);
            if (mDownDegrees != -1) {
                // If it's a legal touch, set that number as "selected" after the
                // tapTimeout in case the user moves their finger quickly.
                tryVibrate();
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mDoingMove = true;
                        int value = reselectSelector(mDownDegrees, isInnerCircle[0], false, true);
                        mLastValueSelected = value;
                        mListener.onValueSelected(getCurrentItemShowing(), value, false);
                    }
                }, tapTimeout);
            }
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (!mInputEnabled) {
            // We shouldn't be in this state, because input is disabled.
            Log.e(TAG, "Input was disabled, but received ACTION_MOVE.");
            return true;
        }

        float dY = Math.abs(eventY - mDownY);
        float dX = Math.abs(eventX - mDownX);

        if (!mDoingMove && dX <= touchSlop && dY <= touchSlop) {
            // Hasn't registered down yet, just slight, accidental movement of finger.
            break;
        }

        // If we're in the middle of touching down on AM or PM, check if we still are.
        // If so, no-op. If not, remove its pressed state. Either way, no need to check
        // for touches on the other circle.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            mHandler.removeCallbacksAndMessages(null);
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            if (isTouchingAmOrPm != mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPmPressed(-1);
                mAmPmCirclesView.invalidate();
                mIsTouchingAmOrPm = -1;
            }
            break;
        }

        if (mDownDegrees == -1) {
            // Original down was illegal, so no movement will register.
            break;
        }

        // We're doing a move along the circle, so move the selection as appropriate.
        mDoingMove = true;
        mHandler.removeCallbacksAndMessages(null);
        degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle);
        if (degrees != -1) {
            value = reselectSelector(degrees, isInnerCircle[0], false, true);
            if (value != mLastValueSelected) {
                tryVibrate();
                mLastValueSelected = value;
                mListener.onValueSelected(getCurrentItemShowing(), value, false);
            }
        }
        return true;
    case MotionEvent.ACTION_UP:
        if (!mInputEnabled) {
            // If our touch input was disabled, tell the listener to re-enable us.
            Log.d(TAG, "Input was disabled, but received ACTION_UP.");
            mListener.onValueSelected(ENABLE_PICKER_INDEX, 1, false);
            return true;
        }

        mHandler.removeCallbacksAndMessages(null);
        mDoingTouch = false;

        // If we're touching AM or PM, set it as selected, and tell the listener.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            mAmPmCirclesView.setAmOrPmPressed(-1);
            mAmPmCirclesView.invalidate();

            if (isTouchingAmOrPm == mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm);
                if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) {
                    mListener.onValueSelected(AMPM_INDEX, mIsTouchingAmOrPm, false);
                    setValueForItem(AMPM_INDEX, isTouchingAmOrPm);
                }
            }
            mIsTouchingAmOrPm = -1;
            break;
        }

        // If we have a legal degrees selected, set the value and tell the listener.
        if (mDownDegrees != -1) {
            degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle);
            if (degrees != -1) {
                value = reselectSelector(degrees, isInnerCircle[0], !mDoingMove, false);
                if (getCurrentItemShowing() == HOUR_INDEX && !mIs24HourMode) {
                    int amOrPm = getIsCurrentlyAmOrPm();
                    if (amOrPm == AM && value == 12) {
                        value = 0;
                    } else if (amOrPm == PM && value != 12) {
                        value += 12;
                    }
                }
                setValueForItem(getCurrentItemShowing(), value);
                mListener.onValueSelected(getCurrentItemShowing(), value, true);
            }
        }
        mDoingMove = false;
        return true;
    default:
        break;
    }
    return false;
}

From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java

/**
 * Handles the touch events to dismiss all apps when clicking outside the bounds of the
 * recycler view.//from  ww w  . j ava2  s . c  o  m
 */
private boolean handleTouchEvent(MotionEvent ev) {
    DeviceProfile grid = mLauncher.getDeviceProfile();
    int x = (int) ev.getX();
    int y = (int) ev.getY();

    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mContentBounds.isEmpty()) {
            // Outset the fixed bounds and check if the touch is outside all apps
            Rect tmpRect = new Rect(mContentBounds);
            tmpRect.inset(-grid.allAppsIconSizePx / 2, 0);
            if (ev.getX() < tmpRect.left || ev.getX() > tmpRect.right) {
                mBoundsCheckLastTouchDownPos.set(x, y);
                return true;
            }
        } else {
            // Check if the touch is outside all apps
            if (ev.getX() < getPaddingLeft() || ev.getX() > (getWidth() - getPaddingRight())) {
                mBoundsCheckLastTouchDownPos.set(x, y);
                return true;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mBoundsCheckLastTouchDownPos.x > -1) {
            ViewConfiguration viewConfig = ViewConfiguration.get(getContext());
            float dx = ev.getX() - mBoundsCheckLastTouchDownPos.x;
            float dy = ev.getY() - mBoundsCheckLastTouchDownPos.y;
            float distance = (float) Math.hypot(dx, dy);
            if (distance < viewConfig.getScaledTouchSlop()) {
                // The background was clicked, so just go home
                Launcher launcher = Launcher.getLauncher(getContext());
                launcher.showWorkspace(true);
                return true;
            }
        }
        // Fall through
    case MotionEvent.ACTION_CANCEL:
        mBoundsCheckLastTouchDownPos.set(-1, -1);
        break;
    }
    return false;
}

From source file:xiaofan.llongimageview.view.SubsamplingScaleImageView.java

/**
 * Handle touch events. One finger pans, and two finger pinch and zoom plus panning.
 *//*from w ww  . j  a va  2s .  c  o  m*/
@Override
public boolean onTouchEvent(MotionEvent event) {
    PointF vCenterEnd;
    float vDistEnd;
    // During non-interruptible anims, ignore all touch events
    if (anim != null && !anim.interruptible) {
        getParent().requestDisallowInterceptTouchEvent(true);
        return true;
    } else {
        anim = null;
    }

    // Abort if not ready
    if (vTranslate == null) {
        return true;
    }
    // Detect flings, taps and double taps
    if (detector == null || detector.onTouchEvent(event)) {
        return true;
    }

    int touchCount = event.getPointerCount();
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_1_DOWN:
    case MotionEvent.ACTION_POINTER_2_DOWN:
        anim = null;
        getParent().requestDisallowInterceptTouchEvent(true);
        maxTouchCount = Math.max(maxTouchCount, touchCount);
        if (touchCount >= 2) {
            if (zoomEnabled) {
                // Start pinch to zoom. Calculate distance between touch points and center point of the pinch.
                float distance = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                scaleStart = scale;
                vDistStart = distance;
                vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                vCenterStart = new PointF((event.getX(0) + event.getX(1)) / 2,
                        (event.getY(0) + event.getY(1)) / 2);
            } else {
                // Abort all gestures on second touch
                maxTouchCount = 0;
            }
            // Cancel long click timer
            handler.removeMessages(MESSAGE_LONG_CLICK);
        } else {
            // Start one-finger pan
            vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
            vCenterStart = new PointF(event.getX(), event.getY());

            // Start long click timer
            handler.sendEmptyMessageDelayed(MESSAGE_LONG_CLICK, 600);
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        boolean consumed = false;
        if (maxTouchCount > 0) {
            if (touchCount >= 2) {
                // Calculate new distance between touch points, to scale and pan relative to start values.
                vDistEnd = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                vCenterEnd = new PointF((event.getX(0) + event.getX(1)) / 2,
                        (event.getY(0) + event.getY(1)) / 2);

                if (zoomEnabled && (distance(vCenterStart.x, vCenterEnd.x, vCenterStart.y, vCenterEnd.y) > 5
                        || Math.abs(vDistEnd - vDistStart) > 5 || isPanning)) {
                    isZooming = true;
                    isPanning = true;
                    consumed = true;

                    scale = Math.min(maxScale, (vDistEnd / vDistStart) * scaleStart);

                    if (scale <= minScale()) {
                        // Minimum scale reached so don't pan. Adjust start settings so any expand will zoom in.
                        vDistStart = vDistEnd;
                        scaleStart = minScale();
                        vCenterStart = vCenterEnd;
                        vTranslateStart = vTranslate;
                    } else if (panEnabled) {
                        // Translate to place the source image coordinate that was at the center of the pinch at the start
                        // at the center of the pinch now, to give simultaneous pan + zoom.
                        float vLeftStart = vCenterStart.x - vTranslateStart.x;
                        float vTopStart = vCenterStart.y - vTranslateStart.y;
                        float vLeftNow = vLeftStart * (scale / scaleStart);
                        float vTopNow = vTopStart * (scale / scaleStart);
                        vTranslate.x = vCenterEnd.x - vLeftNow;
                        vTranslate.y = vCenterEnd.y - vTopNow;
                    } else if (sRequestedCenter != null) {
                        // With a center specified from code, zoom around that point.
                        vTranslate.x = (getWidth() / 2) - (scale * sRequestedCenter.x);
                        vTranslate.y = (getHeight() / 2) - (scale * sRequestedCenter.y);
                    } else {
                        // With no requested center, scale around the image center.
                        vTranslate.x = (getWidth() / 2) - (scale * (sWidth() / 2));
                        vTranslate.y = (getHeight() / 2) - (scale * (sHeight() / 2));
                    }

                    fitToBounds(true);
                    refreshRequiredTiles(false);
                }
            } else if (!isZooming) {
                // One finger pan - translate the image. We do this calculation even with pan disabled so click
                // and long click behaviour is preserved.
                float dx = Math.abs(event.getX() - vCenterStart.x);
                float dy = Math.abs(event.getY() - vCenterStart.y);
                if (dx > 5 || dy > 5 || isPanning) {
                    consumed = true;
                    vTranslate.x = vTranslateStart.x + (event.getX() - vCenterStart.x);
                    vTranslate.y = vTranslateStart.y + (event.getY() - vCenterStart.y);

                    float lastX = vTranslate.x;
                    float lastY = vTranslate.y;
                    fitToBounds(true);
                    if (lastX == vTranslate.x || (lastY == vTranslate.y && dy > 10) || isPanning) {
                        isPanning = true;
                    } else if (dx > 5) {
                        // Haven't panned the image, and we're at the left or right edge. Switch to page swipe.
                        maxTouchCount = 0;
                        handler.removeMessages(MESSAGE_LONG_CLICK);
                        getParent().requestDisallowInterceptTouchEvent(false);
                    }

                    if (!panEnabled) {
                        vTranslate.x = vTranslateStart.x;
                        vTranslate.y = vTranslateStart.y;
                        getParent().requestDisallowInterceptTouchEvent(false);
                    }

                    refreshRequiredTiles(false);
                }
            }
        }
        if (consumed) {
            handler.removeMessages(MESSAGE_LONG_CLICK);
            invalidate();
            return true;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_POINTER_2_UP:
        handler.removeMessages(MESSAGE_LONG_CLICK);
        if (maxTouchCount > 0 && (isZooming || isPanning)) {
            if (isZooming && touchCount == 2) {
                // Convert from zoom to pan with remaining touch
                isPanning = true;
                vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                if (event.getActionIndex() == 1) {
                    vCenterStart = new PointF(event.getX(0), event.getY(0));
                } else {
                    vCenterStart = new PointF(event.getX(1), event.getY(1));
                }
            }
            if (touchCount < 3) {
                // End zooming when only one touch point
                isZooming = false;
            }
            if (touchCount < 2) {
                // End panning when no touch points
                isPanning = false;
                maxTouchCount = 0;
            }
            // Trigger load of tiles now required
            refreshRequiredTiles(true);
            return true;
        }
        if (touchCount == 1) {
            isZooming = false;
            isPanning = false;
            maxTouchCount = 0;
        }
        return true;
    }
    return super.onTouchEvent(event);
}

From source file:caesar.feng.framework.widget.StaggeredGrid.ExtendableListView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = ev.getAction();

    if (!mIsAttached) {
        // Something isn't right.
        // Since we rely on being attached to get data set change notifications,
        // don't risk doing anything where we might try to resync and find things
        // in a bogus state.
        return false;
    }/*w  w w .  j  a  v a  2 s  .  c  o m*/

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        int touchMode = mTouchMode;

        // TODO : overscroll
        //                if (touchMode == TOUCH_MODE_OVERFLING || touchMode == TOUCH_MODE_OVERSCROLL) {
        //                    mMotionCorrection = 0;
        //                    return true;
        //                }

        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        mActivePointerId = ev.getPointerId(0);

        int motionPosition = findMotionRow(y);
        if (touchMode != TOUCH_MODE_FLINGING && motionPosition >= 0) {
            // User clicked on an actual view (and was not stopping a fling).
            // Remember where the motion event started
            mMotionX = x;
            mMotionY = y;
            mMotionPosition = motionPosition;
            mTouchMode = TOUCH_MODE_DOWN;
        }
        mLastY = Integer.MIN_VALUE;
        initOrResetVelocityTracker();
        mVelocityTracker.addMovement(ev);
        if (touchMode == TOUCH_MODE_FLINGING) {
            return true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        switch (mTouchMode) {
        case TOUCH_MODE_DOWN:
            int pointerIndex = ev.findPointerIndex(mActivePointerId);
            if (pointerIndex == -1) {
                pointerIndex = 0;
                mActivePointerId = ev.getPointerId(pointerIndex);
            }
            final int y = (int) ev.getY(pointerIndex);
            initVelocityTrackerIfNotExists();
            mVelocityTracker.addMovement(ev);
            if (startScrollIfNeeded(y)) {
                return true;
            }
            break;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mTouchMode = TOUCH_MODE_IDLE;
        mActivePointerId = INVALID_POINTER;
        recycleVelocityTracker();
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        break;
    }
    }

    return false;
}

From source file:co.codecrunch.musicplayerlite.slidinguppanelhelper.SlidingUpPanelLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (!isEnabled() || !isTouchEnabled() || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
        mDragHelper.cancel();/* www  . jav a 2s . c om*/
        return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mDragHelper.cancel();
        return false;
    }

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

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mIsUnableToDrag = false;
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final float adx = Math.abs(x - mInitialMotionX);
        final float ady = Math.abs(y - mInitialMotionY);
        final int dragSlop = mDragHelper.getTouchSlop();

        // Handle any horizontal scrolling on the drag view.
        if (mIsUsingDragViewTouchEvents && adx > dragSlop && ady < dragSlop) {
            return super.onInterceptTouchEvent(ev);
        }

        if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int) mInitialMotionX, (int) mInitialMotionY)) {
            mDragHelper.cancel();
            mIsUnableToDrag = true;
            return false;
        }
        break;
    }
    }

    return mDragHelper.shouldInterceptTouchEvent(ev);
}

From source file:cn.usmaker.ben.view.refresh.NeuSwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();//ww w. j  a  v  a  2  s .c  o  m

    final int action = MotionEventCompat.getActionMasked(ev);

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;
    }

    switch (mDirection) {
    case BOTTOM:
        if (!isEnabled() || mReturningToStart || (!mBothDirection && canChildScrollDown()) || mRefreshing) {
            // Fail fast if we're not in a state where a swipe is possible
            return false;
        }
        break;
    case TOP:
    default:
        if (!isEnabled() || mReturningToStart || (!mBothDirection && canChildScrollUp()) || mRefreshing) {
            // Fail fast if we're not in a state where a swipe is possible
            return false;
        }
        break;
    }

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCircleView.getTop(), true);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        final float initialDownY = getMotionEventY(ev, mActivePointerId);
        if (initialDownY == -1) {
            return false;
        }
        mInitialDownY = initialDownY;

    case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER) {
            return false;
        }

        final float y = getMotionEventY(ev, mActivePointerId);
        if (y == -1) {
            return false;
        }
        if (mBothDirection) {
            if (y > mInitialDownY) {
                setRawDirection(NeuSwipeRefreshLayoutDirection.TOP);
            } else if (y < mInitialDownY) {
                setRawDirection(NeuSwipeRefreshLayoutDirection.BOTTOM);
            }
            if ((mDirection == NeuSwipeRefreshLayoutDirection.BOTTOM && canChildScrollDown())
                    || (mDirection == NeuSwipeRefreshLayoutDirection.TOP && canChildScrollUp())) {
                mInitialDownY = y;
                return false;
            }
        }
        float yDiff = 0;
        switch (mDirection) {
        case BOTTOM:
            yDiff = mInitialDownY - y;
            break;
        case TOP:
            yDiff = y - mInitialDownY;
            break;
        case NONE:
            break;
        default:
            yDiff = y - mInitialDownY;
            break;
        }
        if (yDiff > mTouchSlop && !mIsBeingDragged) {
            switch (mDirection) {
            case BOTTOM:
                mInitialMotionY = mInitialDownY - mTouchSlop;
                break;
            case TOP:
            default:
                mInitialMotionY = mInitialDownY + mTouchSlop;
                break;
            }
            mIsBeingDragged = true;
            mProgress.setAlpha(STARTING_PROGRESS_ALPHA);
        }
        break;

    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        break;
    }

    return mIsBeingDragged;
}