Example usage for android.support.v4.view MotionEventCompat ACTION_POINTER_UP

List of usage examples for android.support.v4.view MotionEventCompat ACTION_POINTER_UP

Introduction

In this page you can find the example usage for android.support.v4.view MotionEventCompat ACTION_POINTER_UP.

Prototype

int ACTION_POINTER_UP

To view the source code for android.support.v4.view MotionEventCompat ACTION_POINTER_UP.

Click Source Link

Document

Synonym for MotionEvent#ACTION_POINTER_UP .

Usage

From source file:com.example.lansosdk.util.SlidingLayer.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (!mEnabled) {
        return false;
    }/*from w  w w .j  a  va 2 s  .  c o m*/

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mIsDragging = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        return false;
    }

    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsDragging) {
            return true;
        } else if (mIsUnableToDrag) {
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE:
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        if (pointerIndex == -1) {
            mActivePointerId = INVALID_POINTER;
            break;
        }

        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float dy = y - mLastY;
        final float yDiff = Math.abs(y - mLastY);

        if (xDiff > mTouchSlop && xDiff > yDiff && allowDragingX(dx, mInitialX)) {
            // mIsDragging = true;
            mLastX = x;
            setDrawingCacheEnabled(true);
        } else if (yDiff > mTouchSlop && yDiff > xDiff && allowDragingY(dy, mInitialY)) {
            //  mIsDragging = true;
            mLastY = y;
            setDrawingCacheEnabled(true);
        }
        break;

    case MotionEvent.ACTION_DOWN:
        mActivePointerId = ev.getAction() & (Build.VERSION.SDK_INT >= 8 ? MotionEvent.ACTION_POINTER_INDEX_MASK
                : MotionEventCompat.ACTION_POINTER_INDEX_MASK);
        mLastX = mInitialX = MotionEventCompat.getX(ev, mActivePointerId);
        mLastY = mInitialY = MotionEventCompat.getY(ev, mActivePointerId);
        if (allowSlidingFromHereX(ev, mInitialX)) {
            mIsDragging = false;
            mIsUnableToDrag = false;
            // If nobody else got the focus we use it to close the layer
            return super.onInterceptTouchEvent(ev);
        } else if (allowSlidingFromHereY(ev, mInitialY)) {
            mIsDragging = false;
            mIsUnableToDrag = false;
            // If nobody else got the focus we use it to close the layer
            return super.onInterceptTouchEvent(ev);
        } else {
            mIsUnableToDrag = true;
        }
        break;
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

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

    return mIsDragging;
}

From source file:com.shizhefei.view.coolrefreshview.CoolRefreshView.java

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

    if (!isEnabled() || canChildScrollUp() || mRefreshing || mNestedScrollInProgress) {
        // Fail fast if we're not in a state where a swipe is possible
        return false;
    }/* w  ww .  j  a  va 2 s  .  co m*/

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = ev.getPointerId(0);
        mIsBeingDragged = false;
        mLastMotionY = getMotionEventY(ev, mActivePointerId);
        break;

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

        final float y = ev.getY(pointerIndex);
        startDragging(y);

        if (mIsBeingDragged) {
            float dy = mLastMotionY - y;
            touchMove((int) dy);
            mLastMotionY = y;
        }
        break;
    }
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        pointerIndex = MotionEventCompat.getActionIndex(ev);
        if (pointerIndex < 0) {
            Log.e(LOG_TAG, "Got ACTION_POINTER_DOWN event but have an invalid action index.");
            return false;
        }
        mActivePointerId = ev.getPointerId(pointerIndex);
        break;
    }

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

    case MotionEvent.ACTION_UP: {
        pointerIndex = ev.findPointerIndex(mActivePointerId);
        if (pointerIndex < 0) {
            Log.e(LOG_TAG, "Got ACTION_UP event but don't have an active pointer id.");
            return false;
        }

        if (mIsBeingDragged) {
            //                    final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            mIsBeingDragged = false;
            finishSpinner();
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    case MotionEvent.ACTION_CANCEL:
        return false;
    }

    return true;
}

From source file:com.nao20010128nao.RSRL.SwipeRefreshLayout.java

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

    final int action = MotionEventCompat.getActionMasked(ev);

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

    if (!isEnabled() || mReturningToStart || canChildScrollUp() || ev.getY() < mTarget.getTop()
            || ev.getY() > mTarget.getBottom()) {
        // Fail fast if we're not in a state where a swipe is possible
        // This includes if the swipe is outside mTarget
        touchEventFailFast();
        return false;
    }

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

    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 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 (yDiff > mTouchSlop) {
            mLastMotionY = y;
            mIsBeingDragged = true;
        }
        break;

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

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        touchEventFailFast();
        break;
    }

    return mIsBeingDragged;
}

From source file:com.hakerjack.experiments.CustomSwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();/*from www.  j  ava2 s  .c  o m*/

    final int action = MotionEventCompat.getActionMasked(ev);

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

    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:
        int offset = mOriginalOffsetTop - mSpinner.getTop();
        setTargetOffsetTopAndBottom(offset, true);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        final float initialDownY = getMotionEventY(ev, mActivePointerId);
        if (initialDownY == -1) {
            return false;
        }
        mInitialDownY = initialDownY;
        break;

    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 - mInitialDownY;
        if (yDiff > mTouchSlop && !mIsBeingDragged) {
            mInitialMotionY = mInitialDownY + mTouchSlop;
            mIsBeingDragged = true;
            mSpinner.setSpinnerAlpha(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.hayukleung.app.view.refresh.SwipeRefreshLayout.java

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

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;/*from w w w  .  ja v a2 s . c  om*/
    }

    if (!isEnabled() || mReturningToStart || canChildScrollUp()) {
        // 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;
        mCurrPercentage = 0;
        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) {
            // User velocity passed min velocity; trigger a refresh
            if (yDiff > mDistanceToTriggerSync) {
                // User movement passed distance; trigger a refresh
                mIsRefreshable = true;
            } else {
                // Just track the user's movement
                mIsRefreshable = false;
                if (mLastMotionY > y && mTarget.getTop() == getPaddingTop()) {
                    // 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();
                }
            }
            float diff = Math.min(yDiff, mDistanceToTriggerSync);
            setTriggerPercentage(mAccelerateInterpolator.getInterpolation(diff / mDistanceToTriggerSync));
            updateContentOffsetTop((int) (yDiff));
            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 (mIsRefreshable) {
            startRefresh();
        }
        mIsRefreshable = false;
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        mActivePointerId = INVALID_POINTER;
        mCancel.run();
        return false;
    }

    return true;
}

From source file:com.bluepixel.android.sgpool.ui.widget.SwipeRefreshLayout.java

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

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;//  w w  w .  jav a 2s .com
    }

    if (!isEnabled() || mReturningToStart || canChildScrollUp()) {
        // 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;
        mCurrPercentage = 0;
        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) {
            // User velocity passed min velocity; trigger a refresh
            if (yDiff > mDistanceToTriggerSync) {
                // User movement passed distance; trigger a refresh
                startRefresh();
            } else {
                // Just track the user's movement
                setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                updateContentOffsetTop((int) (yDiff));
                if (mLastMotionY > y && mTarget.getTop() == getPaddingTop()) {
                    // 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();
                }
            }
            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:
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    return true;
}

From source file:com.sohu.xzd.widget.SwipeRefresh.java

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

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;//w  w  w . j a v  a 2s . c om
    }

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

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = 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 overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
        if (mIsBeingDragged) {
            float originalDragPercent = overscrollTop / mTotalDragDistance;
            if (originalDragPercent < 0) {
                return false;
            }
            float dragPercent = Math.min(1f, Math.abs(originalDragPercent));
            float adjustedPercent = (float) Math.max(dragPercent - .4, 0) * 5 / 3;
            float extraOS = Math.abs(overscrollTop) - mTotalDragDistance;
            float slingshotDist = mSpinnerFinalOffset;
            float tensionSlingshotPercent = Math.max(0, Math.min(extraOS, slingshotDist * 2) / slingshotDist);
            float tensionPercent = (float) ((tensionSlingshotPercent / 4)
                    - Math.pow((tensionSlingshotPercent / 4), 2)) * 2f;
            float extraMove = (slingshotDist) * tensionPercent * 2;

            int targetY = mOriginalTargetOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            if (mRefreshHeader.getVisibility() != View.VISIBLE) {
                mRefreshHeader.setVisibility(View.VISIBLE);
            }
            if (overscrollTop < mTotalDragDistance) {

            } else {

            }
            float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
            mRefreshHeader.onPull(overscrollTop, mTotalDragDistance, rotation);
            setTargetOffsetTopAndBottom(targetY - mCurrentTargetOffsetTop, true /* requires update */);
        }
        break;
    }
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

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

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL: {
        if (mActivePointerId == INVALID_POINTER) {
            if (action == MotionEvent.ACTION_UP) {
                Log.e(LOG_TAG, "Got ACTION_UP event but don't have an active pointer id.");
            }
            return false;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
        mIsBeingDragged = false;
        if (overscrollTop > mTotalDragDistance) {
            setRefreshing(true, true /* notify */);
        } else {
            mRefreshing = false;
            AnimationListener listener = null;
            listener = new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    startScaleDownAnimation(null);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }
            };
            animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    }

    return true;
}

From source file:com.linsq.androiddemo.refresh2.SwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);// ?
    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        // ???//from w w w.ja v  a2s. c  o m
        mReturningToStart = false;
    }
    if (!isEnabled() || mReturningToStart || canChildScrollUp()) {
        // viewGroup????view??
        // view
        return false;
    }
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = mInitialMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        break;
    case MotionEvent.ACTION_MOVE:
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            // ???
            Logger.e("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;// down??
        if (!mIsBeingDragged && yDiff > mTouchSlop) {
            mIsBeingDragged = true;
        }
        if (mIsBeingDragged) {
            if (yDiff > mDistanceToTriggerSync) {
                // ????starRefresh
                startRefresh();
            } else {
                // ????
                // ?
                setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                updateContentOffsetTop((int) (yDiff));// view??
                if (mLastMotionY > y && mTarget.getTop() == getPaddingTop()) {
                    // ?????
                    removeCallbacks(mCancel);
                } else {
                    updatePositionTimeout();
                }
            }
            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:
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    return true;
}

From source file:com.example.harris.onionweather.ui.swipe.SwipeRefreshLayout.java

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

    final int action = MotionEventCompat.getActionMasked(ev);

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

    if (!isEnabled() || mReturningToStart || canChildScrollUp()) {
        // 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;
        mCurrPercentage = 0;
        mIsPulling = false;
        mCanRefreshing = false;
        break;

    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 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 (yDiff > mTouchSlop) {
            mLastMotionY = y;
            mIsBeingDragged = true;
        }
        break;

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

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

    return mIsBeingDragged;
}

From source file:com.ljmob.corner.view.SwipeRefreshLayoutOverlay.java

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

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;/*  w ww  .j a va2s. com*/
    }

    if (!isEnabled() || mReturningToStart || canChildScrollUp()) {
        // 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;
        mCurrPercentage = 0;
        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) {
            // User velocity passed min velocity; trigger a refresh
            if (yDiff > mDistanceToTriggerSync) {
                // User movement passed distance; trigger a refresh
                startRefresh();
            } else {
                // Just track the user's movement
                setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                updateContentOffsetTop((int) (yDiff));
                if (mLastMotionY > y && mTarget.getTop() == getPaddingTop()) {
                    // 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();
                }
            }
            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:
        mIsBeingDragged = false;
        mCurrPercentage = 0;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    return true;
}