Example usage for android.view MotionEvent ACTION_CANCEL

List of usage examples for android.view MotionEvent ACTION_CANCEL

Introduction

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

Prototype

int ACTION_CANCEL

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

Click Source Link

Document

Constant for #getActionMasked : The current gesture has been aborted.

Usage

From source file:cn.sdgundam.comicatsdgo.extension.SwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;/*  w  ww . ja  va2  s  .  c  om*/
        mDownEvent = MotionEvent.obtain(event);
        mPrevY = mDownEvent.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart) {
            final float eventY = event.getY();
            float yDiff = eventY - mDownEvent.getY();
            if (yDiff > mTouchSlop) {
                // User velocity passed min velocity; trigger a refresh
                if (yDiff > mDistanceToTriggerSync) {
                    // User movement passed distance; trigger a refresh
                    startRefresh();
                    break;
                } else {
                    // Just track the user's movement
                    setTriggerPercentage(
                            mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                    float offsetTop = yDiff;
                    if (mPrevY > eventY) {
                        offsetTop = yDiff - mTouchSlop;
                    }
                    updateContentOffsetTop((int) (offsetTop));
                    if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) {
                        // If the user puts the view back at the top, we
                        // don't need to. This shouldn't be considered
                        // cancelling the gesture as the user can restart from the top.
                        removeCallbacks(mCancel);
                    }
                    //                            else {
                    //                                updatePositionTimeout();
                    //                            }
                    mPrevY = event.getY();
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
            updatePositionImmediately();
        }
        break;
    }
    return handled;
}

From source file:com.cyj.ui.component.listview.CusSwipeRefreshLayout.java

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

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;/*from w  ww  .  j av a2  s  .c o  m*/
    }

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

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = mInitialMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        mIsPulling = false;
        mCanRefreshing = false;
        break;

    case MotionEvent.ACTION_MOVE:
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
            return false;
        }

        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = y - mInitialMotionY;

        if (!mIsBeingDragged && yDiff > mTouchSlop) {
            mIsBeingDragged = true;
        }

        if (mIsBeingDragged) {
            if (yDiff / 2 > mDistanceToTriggerSync) {
                mCanStartRefresh = true;
            } else {
                mCanStartRefresh = false;
            }
            updateContentOffsetTop((int) (yDiff / 2));
            if (mLastMotionY > y && mTarget.getTop() == getPaddingTop()) {
                removeCallbacks(mCancel);
            }
            mLastMotionY = y;
        }
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionY = MotionEventCompat.getY(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

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

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (mCanStartRefresh) {
            startRefresh();
        } else {
            removeCallbacks(mCancel);
            post(mCancel);
        }

        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    return true;
}

From source file:com.bxbxbai.zhuanlan.ui.widget.SwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;/*from ww  w .j a v  a  2s .  c  o  m*/
        mDownEvent = MotionEvent.obtain(event);
        mPrevY = mDownEvent.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart) {
            final float eventY = event.getY();
            float yDiff = eventY - mDownEvent.getY();
            if (yDiff > mTouchSlop) {
                // User velocity passed min velocity; trigger a refresh
                if (yDiff > mDistanceToTriggerSync) {
                    // User movement passed distance; trigger a refresh
                    startRefresh();
                    handled = true;
                    break;
                } else {
                    // Just track the user's movement
                    setTriggerPercentage(
                            mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                    float offsetTop = yDiff;
                    if (mPrevY > eventY) {
                        offsetTop = yDiff - mTouchSlop;
                    }
                    updateContentOffsetTop();
                    if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) {
                        // If the user puts the view back at the top, we
                        // don't need to. This shouldn't be considered
                        // cancelling the gesture as the user can restart from the top.
                        removeCallbacks(mCancel);
                    } else {
                        updatePositionTimeout();
                    }
                    mPrevY = event.getY();
                    handled = true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}

From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java

private boolean handleMoveEvent(@Nullable final View view, @NonNull final MotionEvent motionEvent) {
    if (mVelocityTracker == null || mCurrentView == null) {
        return false;
    }/*  www.j  a  va 2s . c o m*/

    //  ?? ?? ?  ? ? 
    mVelocityTracker.addMovement(motionEvent);

    //  ? ?
    float deltaX = motionEvent.getX() - mDownX;
    float deltaY = motionEvent.getY() - mDownY;

    boolean dismissToRight = deltaX < 0;
    mflingToRight = dismissToRight;

    // ? ?  ?? ?,  ??  ? ? ??? ?
    if (Math.abs(deltaX) > mSlop && Math.abs(deltaX) > Math.abs(deltaY)) {

        // ? ? ??
        if (!mSwiping) {
            mActiveSwipeCount++;
        }

        // ? ?? 
        mSwiping = true;
        mListViewWrapper.getListView().requestDisallowInterceptTouchEvent(true);

        /* Cancel ListView's touch (un-highlighting the item) */
        if (view != null) {
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL
                    | motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT);
            view.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
        }
    }

    // ????
    if (mSwiping) {

        // ? ?
        if (mCanDismissCurrent) {

            // ? ?? 
            onStartSwipe(mCurrentView, mCurrentPosition, dismissToRight);

            //   ??
            ViewHelper.setTranslationX(mSwipingView, deltaX);

            // ??? ? .
            //ViewHelper.setAlpha(mSwipingView, Math.max(mMinimumAlpha, Math.min(1, 1 - 2 * Math.abs(deltaX) / mViewWidth)));

            if (dismissToRight) {

                mLeftSwipingView.setVisibility(View.GONE);
                mRightSwipingView.setVisibility(View.VISIBLE);
            } else {
                mLeftSwipingView.setVisibility(View.VISIBLE);
                mRightSwipingView.setVisibility(View.GONE);
            }

        } else {

            //  ? ? ?
            ViewHelper.setTranslationX(mSwipingView, deltaX * 0.1f);
        }
        return true;
    }
    return false;
}

From source file:com.dm.xz.views.PinnedSectionListView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {

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

    if (action == MotionEvent.ACTION_DOWN && mTouchTarget == null && mPinnedSection != null
            && isPinnedViewTouched(mPinnedSection.view, x, y)) { // create touch target

        // user touched pinned view
        mTouchTarget = mPinnedSection.view;
        mTouchPoint.x = x;//from  ww w.j a v a  2  s  .  c  o  m
        mTouchPoint.y = y;

        // copy down event for eventually be used later
        mDownEvent = MotionEvent.obtain(ev);
    }

    if (mTouchTarget != null) {
        if (isPinnedViewTouched(mTouchTarget, x, y)) { // forward event to pinned view
            mTouchTarget.dispatchTouchEvent(ev);
        }

        if (action == MotionEvent.ACTION_UP) { // perform onClick on pinned view
            super.dispatchTouchEvent(ev);
            performPinnedItemClick();
            clearTouchTarget();

        } else if (action == MotionEvent.ACTION_CANCEL) { // cancel
            clearTouchTarget();

        } else if (action == MotionEvent.ACTION_MOVE) {
            if (Math.abs(y - mTouchPoint.y) > mTouchSlop) {

                // cancel sequence on touch target
                MotionEvent event = MotionEvent.obtain(ev);
                event.setAction(MotionEvent.ACTION_CANCEL);
                mTouchTarget.dispatchTouchEvent(event);
                event.recycle();

                // provide correct sequence to super class for further handling
                super.dispatchTouchEvent(mDownEvent);
                super.dispatchTouchEvent(ev);
                clearTouchTarget();

            }
        }

        return true;
    }

    // call super if this was not our pinned view
    return super.dispatchTouchEvent(ev);
}

From source file:co.vn.e_alarm.customwiget.SlidingLayer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!mEnabled || !mIsDragging && !mLastTouchAllowed && !allowSlidingFromHereX(ev, mInitialX)
            && !allowSlidingFromHereY(ev, mInitialY)) {
        return false;
    }//w w  w  .j  a v a2s .c  o  m

    final int action = ev.getAction();

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        mLastTouchAllowed = false;
    } else {
        mLastTouchAllowed = true;
    }

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        completeScroll();
        // Remember where the motion event started
        mLastX = mInitialX = ev.getX();
        mLastY = mInitialY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    case MotionEvent.ACTION_MOVE:
        if (!mIsDragging) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastX);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float yDiff = Math.abs(y - mLastY);
            if (xDiff > mTouchSlop && xDiff > yDiff) {
                mIsDragging = true;
                mLastX = x;
                setDrawingCacheEnabled(true);
            } else if (yDiff > mTouchSlop && yDiff > xDiff) {
                mIsDragging = true;
                mLastY = y;
                setDrawingCacheEnabled(true);
            }
        }
        if (mIsDragging) {
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (activePointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            final float deltaX = mLastX - x;
            final float deltaY = mLastY - y;
            mLastX = x;
            mLastY = y;
            final float oldScrollX = getScrollX();
            final float oldScrollY = getScrollY();
            float scrollX = oldScrollX + deltaX;
            float scrollY = oldScrollY + deltaY;

            /*
             * Not need change : Done
             */
            final float leftBound, rightBound;
            final float bottomBound, topBound;
            switch (mScreenSide) {
            case STICK_TO_LEFT:
                topBound = bottomBound = rightBound = 0;
                leftBound = getWidth(); // How far left we can scroll
                break;
            case STICK_TO_MIDDLE:
                topBound = getHeight();
                bottomBound = -getHeight();
                leftBound = getWidth();
                rightBound = -getWidth();
                break;
            case STICK_TO_RIGHT:
                rightBound = -getWidth();
                topBound = bottomBound = leftBound = 0;
                break;
            case STICK_TO_TOP:
                topBound = getHeight();
                bottomBound = rightBound = leftBound = 0;
                break;
            case STICK_TO_BOTTOM:
                topBound = rightBound = leftBound = 0;
                bottomBound = -getHeight();
                break;
            default:
                topBound = bottomBound = rightBound = leftBound = 0;
                break;
            }
            if (scrollX > leftBound) {
                scrollX = leftBound;
            } else if (scrollX < rightBound) {
                scrollX = rightBound;
            }
            if (scrollY > topBound) {
                scrollY = topBound;
            } else if (scrollY < bottomBound) {
                scrollY = bottomBound;
            }

            // TODO top/bottom bounds
            // Keep the precision
            mLastX += scrollX - (int) scrollX;
            mLastY += scrollY - (int) scrollY;
            scrollTo((int) scrollX, (int) scrollY);
        }
        break;
    //--- Doan nay dang kiem tra
    case MotionEvent.ACTION_UP:
        if (mIsDragging) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker,
                    mActivePointerId);
            final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker,
                    mActivePointerId);
            final int scrollX = getScrollX();
            final int scrollY = getScrollY();
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            final int totalDeltaX = (int) (x - mInitialX);
            final int totalDeltaY = (int) (y - mInitialY);

            /*
            * Here is condition to check when to change state of layer. open / close.
            */
            boolean nextStateOpened = determineNextStateOpened(mIsOpen, scrollX, scrollY, initialVelocityX,
                    initialVelocityY, totalDeltaX, totalDeltaY);
            switchLayer(nextStateOpened, true, true, initialVelocityX, initialVelocityY);

            mActivePointerId = INVALID_POINTER;
            endDrag();
        } else if (mIsOpen && closeOnTapEnabled) {
            closeLayer(true);
        } else if (!mIsOpen && openOnTapEnabled) {
            openLayer(true);
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            switchLayer(mIsOpen, true, true);
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastX = MotionEventCompat.getX(ev, index);
        mLastY = MotionEventCompat.getY(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        mLastY = MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (mActivePointerId == INVALID_POINTER) {
        mLastTouchAllowed = false;
    }
    return true;
}

From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java

@Override
public boolean onTouch(final View view, final MotionEvent event) {
    final int action = event.getAction();
    if (action == MotionEvent.ACTION_CANCEL) {
        showTop = false;/*ww  w . j  av a2  s .  co m*/
        showBottom = false;
    } else if (action == MotionEvent.ACTION_UP) {
        if (showTop) {
            if (listener != null && lastUid != null) {
                listener.showLastItem();
            }
        } else if (showBottom) {
            if (listener != null && nextUid != null) {
                listener.showNextItem();
            }
        }
        showTop = false;
        showBottom = false;
    }
    return false;
}

From source file:com.danilov.supermanga.core.view.SlidingLayer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (ev.getEdgeFlags() == 4099) {
        return false;
    }//from   ww  w. ja  va  2s. com
    if (!mEnabled || !mIsDragging && !mLastTouchAllowed && !allowSlidingFromHereX(ev, mInitialX)
            && !allowSlidingFromHereY(ev, mInitialY)) {
        return false;
    }

    final int action = ev.getAction();

    mLastTouchAllowed = !(action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE);

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        completeScroll();

        // Remember where the motion event started
        mLastX = mInitialX = ev.getX();
        mLastY = mInitialY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    case MotionEvent.ACTION_MOVE:
        if (!mIsDragging) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastX);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float yDiff = Math.abs(y - mLastY);
            if (xDiff > mTouchSlop && xDiff > yDiff) {
                mIsDragging = true;
                mLastX = x;
                setDrawingCacheEnabled(true);
            } else if (yDiff > mTouchSlop && yDiff > xDiff) {
                mIsDragging = true;
                mLastY = y;
                setDrawingCacheEnabled(true);
            }
        }
        if (mIsDragging) {
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (activePointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            final float deltaX = mLastX - x;
            final float deltaY = mLastY - y;
            mLastX = x;
            mLastY = y;
            final float oldScrollX = getScrollX();
            final float oldScrollY = getScrollY();
            float scrollX = oldScrollX + deltaX;
            float scrollY = oldScrollY + deltaY;

            // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]", scrollX, scrollY));
            final float leftBound, rightBound;
            final float bottomBound, topBound;
            switch (mScreenSide) {
            case STICK_TO_LEFT:
                topBound = bottomBound = rightBound = 0;
                leftBound = getWidth(); // How far left we can scroll
                break;
            case STICK_TO_MIDDLE:
                topBound = getHeight();
                bottomBound = -getHeight();
                leftBound = getWidth();
                rightBound = -getWidth();
                break;
            case STICK_TO_RIGHT:
                rightBound = -getWidth();
                topBound = bottomBound = leftBound = 0;
                break;
            case STICK_TO_TOP:
                topBound = getHeight();
                bottomBound = rightBound = leftBound = 0;
                break;
            case STICK_TO_BOTTOM:
                topBound = rightBound = leftBound = 0;
                bottomBound = -getHeight();
                break;
            default:
                topBound = bottomBound = rightBound = leftBound = 0;
                break;
            }
            if (scrollX > leftBound) {
                scrollX = leftBound;
            } else if (scrollX < rightBound) {
                scrollX = rightBound;
            }
            if (scrollY > topBound) {
                scrollY = topBound;
            } else if (scrollY < bottomBound) {
                scrollY = bottomBound;
            }

            // Keep the precision
            mLastX += scrollX - (int) scrollX;
            mLastY += scrollY - (int) scrollY;
            scrollTo((int) scrollX, (int) scrollY);
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mIsDragging) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker,
                    mActivePointerId);
            final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker,
                    mActivePointerId);
            final int scrollX = getScrollX();
            final int scrollY = getScrollY();
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            final int totalDeltaX = (int) (x - mInitialX);
            final int totalDeltaY = (int) (y - mInitialY);

            boolean nextStateOpened = determineNextStateOpened(mIsOpen, scrollX, scrollY, initialVelocityX,
                    initialVelocityY, totalDeltaX, totalDeltaY);
            switchLayer(nextStateOpened, true, true, initialVelocityX, initialVelocityY);

            mActivePointerId = INVALID_POINTER;
            endDrag();
        } else if (mIsOpen && closeOnTapEnabled) {
            closeLayer(true);
        } else if (!mIsOpen && openOnTapEnabled) {
            openLayer(true);
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            switchLayer(mIsOpen, true, true);
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastX = MotionEventCompat.getX(ev, index);
        mLastY = MotionEventCompat.getY(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        mLastY = MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (mActivePointerId == INVALID_POINTER) {
        mLastTouchAllowed = false;
    }
    return true;
}

From source file:cn.bvin.app.swiperefresh.OldSwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;/*  ww  w .j a  v  a  2 s .com*/
        mDownEvent = MotionEvent.obtain(event);
        mPrevY = mDownEvent.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart) {
            final float eventY = event.getY();
            float yDiff = eventY - mDownEvent.getY();
            if (yDiff > mTouchSlop) {//?
                // User velocity passed min velocity; trigger a refresh
                if (yDiff > mDistanceToTriggerSync) {//??
                    // User movement passed distance; trigger a refresh
                    startRefresh();
                    handled = true;
                    break;
                } else {
                    // Just track the user's movement
                    setTriggerPercentage(
                            mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                    float offsetTop = yDiff;
                    if (mPrevY > eventY) {
                        offsetTop = yDiff - mTouchSlop;
                    }
                    //content????
                    updateContentOffsetTop((int) (offsetTop * mResistance));
                    if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) {
                        // If the user puts the view back at the top, we
                        // don't need to. This shouldn't be considered
                        // cancelling the gesture as the user can restart from the top.
                        removeCallbacks(mCancel);
                    } else {
                        updatePositionTimeout();
                    }
                    mPrevY = event.getY();
                    handled = true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}

From source file:com.aretha.slidemenu.SlideMenu.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    final float x = event.getX();
    final float y = event.getY();
    final int currentState = mCurrentState;
    final boolean isTapContent = mIsTapContent;

    mVelocityTracker.addMovement(event);

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mPressedX = mLastMotionX = x;//from w  ww  . j  a v a2  s . c om
        mIsTapContent = isTapContent(x, y);
        if (mIsTapContent) {
            mScroller.abortAnimation();
        }
        mVelocityTracker = VelocityTracker.obtain();
        break;
    case MotionEvent.ACTION_MOVE:
        if (Math.abs(x - mPressedX) >= mTouchSlop && isTapContent && currentState != STATE_DRAG) {
            setCurrentState(STATE_DRAG);
        }
        if (STATE_DRAG != currentState) {
            mLastMotionX = x;
            return false;
        }

        drag(mLastMotionX, x);
        mLastMotionX = x;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
        if (STATE_DRAG == currentState) {
            mVelocityTracker.computeCurrentVelocity(1000);
            endDrag(x, mVelocityTracker.getXVelocity());
        } else if (isTapContent) {
            performContentClick();
        }
        mVelocityTracker.recycle();
        mIsTapContent = false;
        break;
    }

    return true;
}