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

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

Introduction

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

Prototype

public static float getY(MotionEvent event, int pointerIndex) 

Source Link

Document

Call MotionEvent#getY(int) .

Usage

From source file:com.open.ui.viewpager.view.TabViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*//from   w  ww  .j  a v  a  2s .c  om
     * This method JUST determines whether we want to intercept the motion.
     * If we return true, onMotionEvent will be called and we do the actual
     * scrolling there.
     */

    // If mDisableIntercept true, pass the event to child view
    //Log.i("setOnTouchListener","view_pager mDisableIntercept"+mDisableIntercept);
    if (mDisableIntercept) {
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

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

    // Always take care of the touch gesture being complete.
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.
        //if (DEBUG) Log.v(TAG, "Intercept done!");
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_POINTER;
        return false;
    }

    // Nothing more to do here if we have decided whether or not we
    // are dragging.
    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsBeingDragged) {
            //if (DEBUG) Log.v(TAG, "Intercept returning true!");
            return true;
        }
        if (mIsUnableToDrag) {
            //if (DEBUG) Log.v(TAG, "Intercept returning false!");
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        /*
         * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
         * whether the user has moved far enough from his original down touch.
         */

        /*
        * Locally do absolute value. mLastMotionY is set to the y value
        * of the down event.
        */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastMotionX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = Math.abs(y - mLastMotionY);
        //if (DEBUG) Log.v(TAG, "onInterceptTouchEvent Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);

        if (xDiff > mTouchSlop && xDiff > yDiff) {
            //if (DEBUG) Log.v(TAG, "onInterceptTouchEvent Starting drag!");
            mIsBeingDragged = true;
            setScrollState(SCROLL_STATE_DRAGGING);
            mLastMotionX = x;
            setScrollingCacheEnabled(true);
        } else {
            if (yDiff > mTouchSlop) {
                // The finger has moved enough in the vertical
                // direction to be counted as a drag...  abort
                // any attempt to drag horizontally, to work correctly
                // with children that have scrolling containers.
                //if (DEBUG) Log.v(TAG, "Starting unable to drag!");
                mIsUnableToDrag = true;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        /*
         * Remember location of down touch.
         * ACTION_DOWN always refers to pointer index 0.
         */
        mLastMotionX = mInitialMotionX = ev.getX();
        mLastMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (mScrollState == SCROLL_STATE_SETTLING) {
            // Let the user 'catch' the pager as it animates.
            mIsBeingDragged = true;
            mIsUnableToDrag = false;
            setScrollState(SCROLL_STATE_DRAGGING);
        } else {
            completeScroll();
            mIsBeingDragged = false;
            mIsUnableToDrag = false;
        }

        //if (DEBUG) Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY
        //        + " mIsBeingDragged=" + mIsBeingDragged
        //        + " mIsUnableToDrag=" + mIsUnableToDrag);
        break;
    }

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

    /*
    * The only time we want to intercept motion events is if we are in the
    * drag mode.
    */
    return mIsBeingDragged;
}

From source file:com.hp.hoopeasy.widget.swipeRefresh.SwipeRefreshLayout.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 a v a 2s  .  c o m
    }

    switch (mDirection) {
    case BOTTOM:
        if (!isEnabled() || mReturningToStart || 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 || 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:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        break;

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            return false;
        }

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

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        if (mIsBeingDragged) {
            mProgress.showArrow(true);
            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 = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop
                    : 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 = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            int targetY;
            if (mDirection == SwipeRefreshLayoutDirection.TOP) {
                targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            } else {
                targetY = mOriginalOffsetTop - (int) ((slingshotDist * dragPercent) + extraMove);
            }
            // where 1.0f is a full circle
            if (mCircleView.getVisibility() != View.VISIBLE) {
                mCircleView.setVisibility(View.VISIBLE);
            }
            if (!mScale) {
                ViewCompat.setScaleX(mCircleView, 1f);
                ViewCompat.setScaleY(mCircleView, 1f);
            }
            if (overscrollTop < mTotalDragDistance) {
                if (mScale) {
                    setAnimationProgress(overscrollTop / mTotalDragDistance);
                }
                if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                        && !isAnimationRunning(mAlphaStartAnimation)) {
                    // Animate the alpha
                    startProgressAlphaStartAnimation();
                }
                float strokeStart = adjustedPercent * .8f;
                mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
                mProgress.setArrowScale(Math.min(1f, adjustedPercent));
            } else {
                if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                    // Animate the alpha
                    startProgressAlphaMaxAnimation();
                }
            }
            float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
            mProgress.setProgressRotation(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) {
            }
            return false;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        mIsBeingDragged = false;
        if (overscrollTop > mTotalDragDistance) {
            setRefreshing(true, true /* notify */);
        } else {
            // dialog_cancel refresh
            mRefreshing = false;
            mProgress.setStartEndTrim(0f, 0f);
            AnimationListener listener = null;
            if (!mScale) {
                listener = new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                };
            }
            animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
            mProgress.showArrow(false);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    }

    return true;
}

From source file:com.mucfc.refreshview.refresh.MySwipeRefreshLayout.java

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

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;//www.j av a 2 s  .  c  o m
    }

    switch (mDirection) {
    case BOTTOM:
        if (!isEnabled() || mReturningToStart || 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 || 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:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        break;

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            return false;
        }

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

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        if (mIsBeingDragged) {
            mProgress.showArrow(true);
            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 = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop
                    : 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 = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            int targetY;
            if (mDirection == MySwipeRefreshLayoutDirection.TOP) {
                targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            } else {
                targetY = mOriginalOffsetTop - (int) ((slingshotDist * dragPercent) + extraMove);
            }
            // where 1.0f is a full circle
            if (mCircleView.getVisibility() != View.VISIBLE) {
                mCircleView.setVisibility(View.VISIBLE);
            }
            if (!mScale) {
                ViewCompat.setScaleX(mCircleView, 1f);
                ViewCompat.setScaleY(mCircleView, 1f);
            }
            if (overscrollTop < mTotalDragDistance) {
                if (mScale) {
                    setAnimationProgress(overscrollTop / mTotalDragDistance);
                }
                if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                        && !isAnimationRunning(mAlphaStartAnimation)) {
                    // Animate the alpha
                    startProgressAlphaStartAnimation();
                }
                float strokeStart = (float) (adjustedPercent * .8f);
                mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
                mProgress.setArrowScale(Math.min(1f, adjustedPercent));
            } else {
                if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                    // Animate the alpha
                    startProgressAlphaMaxAnimation();
                }
            }
            float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
            mProgress.setProgressRotation(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) {
            }
            return false;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        mIsBeingDragged = false;
        if (overscrollTop > mTotalDragDistance) {
            setRefreshing(true, true /* notify */);
        } else {
            // cancel refresh
            mRefreshing = false;
            mProgress.setStartEndTrim(0f, 0f);
            AnimationListener listener = null;
            if (!mScale) {
                listener = new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                };
            }
            animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
            mProgress.showArrow(false);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    }

    return true;
}

From source file:com.king.view.superswiperefreshlayout.SuperSwipeRefreshLayout.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 a va 2 s .  co m*/
    }

    switch (mDirection) {
    case BOTTOM:
        if (!isEnabled() || mReturningToStart || 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 || 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:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        break;

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            return false;
        }

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

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        if (mIsBeingDragged) {
            mProgress.showArrow(true);
            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 = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop
                    : 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 = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            int targetY;
            if (mDirection == Direction.TOP) {
                targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            } else {
                targetY = mOriginalOffsetTop - (int) ((slingshotDist * dragPercent) + extraMove);
            }
            // where 1.0f is a full circle
            if (mCircleView.getVisibility() != View.VISIBLE) {
                mCircleView.setVisibility(View.VISIBLE);
            }
            if (!mScale) {
                ViewCompat.setScaleX(mCircleView, 1f);
                ViewCompat.setScaleY(mCircleView, 1f);
            }
            if (overscrollTop < mTotalDragDistance) {
                if (mScale) {
                    setAnimationProgress(overscrollTop / mTotalDragDistance);
                }
                if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                        && !isAnimationRunning(mAlphaStartAnimation)) {
                    // Animate the alpha
                    startProgressAlphaStartAnimation();
                }
                float strokeStart = (float) (adjustedPercent * .8f);
                mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
                mProgress.setArrowScale(Math.min(1f, adjustedPercent));
            } else {
                if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                    // Animate the alpha
                    startProgressAlphaMaxAnimation();
                }
            }
            float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
            mProgress.setProgressRotation(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) {
            }
            return false;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        mIsBeingDragged = false;
        if (overscrollTop > mTotalDragDistance) {
            setRefreshing(true, true /* notify */);
        } else {
            // cancel refresh
            mRefreshing = false;
            mProgress.setStartEndTrim(0f, 0f);
            AnimationListener listener = null;
            if (!mScale) {
                listener = new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                };
            }
            animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
            mProgress.showArrow(false);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    }

    return true;
}

From source file:com.swiprefreshload.SwipeRefreshLoadLayout.java

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

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

    switch (mDirection) {
    case BOTTOM:
        if (!isEnabled() || mReturningToStart || 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 || 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:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        break;

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            return false;
        }

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

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        if (mIsBeingDragged) {
            mProgress.showArrow(true);
            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 = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop
                    : 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 = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            int targetY;
            if (mDirection == SwipeDirection.TOP) {
                targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            } else {
                targetY = mOriginalOffsetTop - (int) ((slingshotDist * dragPercent) + extraMove);
            }
            // where 1.0f is a full circle
            if (mCircleView.getVisibility() != View.VISIBLE) {
                mCircleView.setVisibility(View.VISIBLE);
            }
            if (!mScale) {
                ViewCompat.setScaleX(mCircleView, 1f);
                ViewCompat.setScaleY(mCircleView, 1f);
            }
            if (overscrollTop < mTotalDragDistance) {
                if (mScale) {
                    setAnimationProgress(overscrollTop / mTotalDragDistance);
                }
                if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                        && !isAnimationRunning(mAlphaStartAnimation)) {
                    // Animate the alpha
                    startProgressAlphaStartAnimation();
                }
                float strokeStart = (float) (adjustedPercent * .8f);
                mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
                mProgress.setArrowScale(Math.min(1f, adjustedPercent));
            } else {
                if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                    // Animate the alpha
                    startProgressAlphaMaxAnimation();
                }
            }
            float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
            mProgress.setProgressRotation(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) {
            }
            return false;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        mIsBeingDragged = false;
        if (overscrollTop > mTotalDragDistance) {
            setRefreshing(true, true /* notify */);
        } else {
            // cancel refresh
            mRefreshing = false;
            mProgress.setStartEndTrim(0f, 0f);
            AnimationListener listener = null;
            if (!mScale) {
                listener = new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                };
            }
            animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
            mProgress.showArrow(false);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    }

    return true;
}

From source file:cn.usmaker.ben.view.refresh.NeuSwipeRefreshLayout.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 . j a v  a 2s  .  co m
    }

    switch (mDirection) {
    case BOTTOM:
        if (!isEnabled() || mReturningToStart || 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 || 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:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        break;

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            return false;
        }

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

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        if (mIsBeingDragged) {
            mProgress.showArrow(true);
            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 = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop
                    : 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 = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            int targetY;
            if (mDirection == NeuSwipeRefreshLayoutDirection.TOP) {
                targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            } else {
                targetY = mOriginalOffsetTop - (int) ((slingshotDist * dragPercent) + extraMove);
            }
            // where 1.0f is a full circle
            if (mCircleView.getVisibility() != View.VISIBLE) {
                mCircleView.setVisibility(View.VISIBLE);
            }
            if (!mScale) {
                ViewCompat.setScaleX(mCircleView, 1f);
                ViewCompat.setScaleY(mCircleView, 1f);
            }
            if (overscrollTop < mTotalDragDistance) {
                if (mScale) {
                    setAnimationProgress(overscrollTop / mTotalDragDistance);
                }
                if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                        && !isAnimationRunning(mAlphaStartAnimation)) {
                    // Animate the alpha
                    startProgressAlphaStartAnimation();
                }
                float strokeStart = (float) (adjustedPercent * .8f);
                mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
                mProgress.setArrowScale(Math.min(1f, adjustedPercent));
            } else {
                if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                    // Animate the alpha
                    startProgressAlphaMaxAnimation();
                }
            }
            float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
            mProgress.setProgressRotation(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) {
            }
            return false;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        mIsBeingDragged = false;
        if (overscrollTop > mTotalDragDistance) {
            setRefreshing(true, true /* notify */);
        } else {
            // cancel refresh
            mRefreshing = false;
            mProgress.setStartEndTrim(0f, 0f);
            AnimationListener listener = null;
            if (!mScale) {
                listener = new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                };
            }
            animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
            mProgress.showArrow(false);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    }

    return true;
}

From source file:com.patr.radix.ui.view.swipe.SwipeRefreshLayout.java

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

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;/*from   www  .j  av  a2s  . c  o m*/
    }

    switch (mDirection) {
    case BOTTOM:
        if (!isEnabled() || mReturningToStart || 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 || 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:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        break;

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            return false;
        }

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

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        if (mIsBeingDragged) {
            mProgress.showArrow(true);
            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 = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop
                    : 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 = mOriginalOffsetTop + (int) ((slingshotDist *
            // dragPercent) + extraMove);
            int targetY;
            if (mDirection == SwipeRefreshLayoutDirection.TOP) {
                targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            } else {
                targetY = mOriginalOffsetTop - (int) ((slingshotDist * dragPercent) + extraMove);
            }
            // where 1.0f is a full circle
            if (mCircleView.getVisibility() != View.VISIBLE) {
                mCircleView.setVisibility(View.VISIBLE);
            }
            if (!mScale) {
                ViewCompat.setScaleX(mCircleView, 1f);
                ViewCompat.setScaleY(mCircleView, 1f);
            }
            if (overscrollTop < mTotalDragDistance) {
                if (mScale) {
                    setAnimationProgress(overscrollTop / mTotalDragDistance);
                }
                if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                        && !isAnimationRunning(mAlphaStartAnimation)) {
                    // Animate the alpha
                    startProgressAlphaStartAnimation();
                }
                float strokeStart = (float) (adjustedPercent * .8f);
                mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
                mProgress.setArrowScale(Math.min(1f, adjustedPercent));
            } else {
                if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                    // Animate the alpha
                    startProgressAlphaMaxAnimation();
                }
            }
            float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
            mProgress.setProgressRotation(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) {
            }
            return false;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        mIsBeingDragged = false;
        if (overscrollTop > mTotalDragDistance) {
            setRefreshing(true, true /* notify */);
        } else {
            // cancel refresh
            mRefreshing = false;
            mProgress.setStartEndTrim(0f, 0f);
            AnimationListener listener = null;
            if (!mScale) {
                listener = new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                };
            }
            animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
            mProgress.showArrow(false);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    }

    return true;
}

From source file:atownsend.swipeopenhelper.SwipeOpenItemTouchHelper.java

private RecyclerView.ViewHolder findSwipedView(MotionEvent motionEvent) {
    final RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();
    if (activePointerId == ACTIVE_POINTER_ID_NONE) {
        return null;
    }/*from w  ww  .  jav a  2  s.com*/
    final int pointerIndex = MotionEventCompat.findPointerIndex(motionEvent, activePointerId);
    final float dx = MotionEventCompat.getX(motionEvent, pointerIndex) - initialTouchX;
    final float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - initialTouchY;
    final float absDx = Math.abs(dx);
    final float absDy = Math.abs(dy);

    if (absDx < slop && absDy < slop) {
        return null;
    }
    if (absDx > absDy && lm.canScrollHorizontally()) {
        return null;
    } else if (absDy > absDx && lm.canScrollVertically()) {
        return null;
    }
    View child = findChildView(motionEvent);
    if (child == null) {
        return null;
    }
    RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(child);
    if (holder instanceof SwipeOpenViewHolder) {
        return recyclerView.getChildViewHolder(child);
    } else {
        throw new IllegalStateException("Swiped View Holders must implement SwipeOpenViewHolder");
    }
}

From source file:com.viettel.image.zoom.ZoomViewPaper.java

@Override
public boolean onTouchEvent(MotionEvent ev) {

    if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
        // Don't handle edge touches immediately -- they may actually belong
        // to one of our
        // descendants.
        return false;
    }/*from   ww w. j  a  va 2 s.c om*/

    if (mAdapter == null || mAdapter.getCount() == 0) {
        // Nothing to present or scroll; nothing to touch.
        return false;
    }

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

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        /*
         * If being flinged and user touches, stop the fling. isFinished
         * will be false if being flinged.
         */
        completeScroll();

        // Remember where the motion event started
        mLastMotionX = mInitialMotionX = ev.getX();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }
    case MotionEvent.ACTION_MOVE:
        if (!mIsBeingDragged) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastMotionX);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float yDiff = Math.abs(y - mLastMotionY);
            if (DEBUG)
                VTLog.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
            if (xDiff > mTouchSlop && xDiff > yDiff) {
                if (DEBUG)
                    VTLog.v(TAG, "Starting drag!");
                mIsBeingDragged = true;
                mLastMotionX = x;
                setScrollState(SCROLL_STATE_DRAGGING);
                setScrollingCacheEnabled(true);
            }
        }
        if (mIsBeingDragged) {
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float deltaX = mLastMotionX - x;
            mLastMotionX = x;
            float scrollX = getScrollX() + deltaX;
            final int width = getWidth();

            final float leftBound = Math.max(0, (mCurItem - 1) * width);
            final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * width;
            if (scrollX < leftBound) {
                scrollX = leftBound;
            } else if (scrollX > rightBound) {
                scrollX = rightBound;
            }
            // Don't lose the rounded component
            mLastMotionX += scrollX - (int) scrollX;
            scrollTo((int) scrollX, getScrollY());
            if (mOnPageChangeListener != null) {
                final int position = (int) scrollX / width;
                final int positionOffsetPixels = (int) scrollX % width;
                final float positionOffset = (float) positionOffsetPixels / width;
                mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mIsBeingDragged) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId);
            mPopulatePending = true;
            if ((Math.abs(initialVelocity) > mMinimumVelocity)
                    || Math.abs(mInitialMotionX - mLastMotionX) >= (getWidth() / 3)) {
                if (mLastMotionX > mInitialMotionX) {
                    setCurrentItemInternal(mCurItem - 1, true, true);
                } else {
                    setCurrentItemInternal(mCurItem + 1, true, true);
                }
            } else {
                setCurrentItemInternal(mCurItem, true, true);
            }

            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsBeingDragged) {
            setCurrentItemInternal(mCurItem, true, true);
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        final float x = MotionEventCompat.getX(ev, index);
        mLastMotionX = x;
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    return true;
}

From source file:com.yisa.pray.views.swipe.SwipyRefreshLayout.java

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

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

    switch (mDirection) {
    case BOTTOM:
        if (!isEnabled() || mReturningToStart || 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 || 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:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        break;

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            return false;
        }

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

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        if (mIsBeingDragged) {
            mProgress.showArrow(true);
            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 = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop
                    : 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 = mOriginalOffsetTop + (int) ((slingshotDist *
            // dragPercent) + extraMove);
            int targetY;
            if (mDirection == SwipyRefreshLayoutDirection.TOP) {
                targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
            } else {
                targetY = mOriginalOffsetTop - (int) ((slingshotDist * dragPercent) + extraMove);
            }
            // where 1.0f is a full circle
            if (mCircleView.getVisibility() != View.VISIBLE) {
                mCircleView.setVisibility(View.VISIBLE);
            }
            if (!mScale) {
                ViewCompat.setScaleX(mCircleView, 1f);
                ViewCompat.setScaleY(mCircleView, 1f);
            }
            if (overscrollTop < mTotalDragDistance) {
                if (mScale) {
                    setAnimationProgress(overscrollTop / mTotalDragDistance);
                }
                if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                        && !isAnimationRunning(mAlphaStartAnimation)) {
                    // Animate the alpha
                    startProgressAlphaStartAnimation();
                }
                float strokeStart = (float) (adjustedPercent * .8f);
                mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
                mProgress.setArrowScale(Math.min(1f, adjustedPercent));
            } else {
                if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                    // Animate the alpha
                    startProgressAlphaMaxAnimation();
                }
            }
            float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
            mProgress.setProgressRotation(rotation);
            if (mDirection == SwipyRefreshLayoutDirection.TOP) {
                setTargetOffsetTopAndBottom(targetY - mCurrentTargetOffsetTop, true /*
                                                                                    * requires
                                                                                    * update
                                                                                    */);
            } else {
                setTargetOffsetTopAndBottom(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) {
            }
            return false;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float y = MotionEventCompat.getY(ev, pointerIndex);

        float overscrollTop;
        switch (mDirection) {
        case BOTTOM:
            overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
            break;
        case TOP:
        default:
            overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
            break;
        }
        mIsBeingDragged = false;
        if (overscrollTop > mTotalDragDistance) {
            setRefreshing(true, true /* notify */);
        } else {
            // cancel refresh
            mRefreshing = false;
            mProgress.setStartEndTrim(0f, 0f);
            AnimationListener listener = null;
            if (!mScale) {
                listener = new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                };
            }
            animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
            mProgress.showArrow(false);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    }

    return true;
}