Example usage for android.view MotionEvent obtain

List of usage examples for android.view MotionEvent obtain

Introduction

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

Prototype

static public MotionEvent obtain(MotionEvent other) 

Source Link

Document

Create a new MotionEvent, copying from an existing one.

Usage

From source file:ugia.io.androidbeautytreatment.view.NoisySwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;//from   w  w w.  j a  va2s . co  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
                    setTriggerPercentage(1f);
                    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((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);
                    }
                    mPrevY = event.getY();
                    handled = true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:

        if (mCurrPercentage >= 1)
            startRefresh();

        removeCallbacks(mCancel);
        mReturnToStartPosition.run();

        mListener.onCancel();

        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}

From source file:com.aiga.events.android.views.NoScrollSwipeRefreshLayout.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);
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart && !mRefreshing && !mUserInteracting) {
            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
                    mUserInteracting = true;
                    startRefresh();
                    handled = true;
                    break;
                }
                // Just track the user's movement
                setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                updatePositionTimeout();
                handled = true;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mUserInteracting = false;
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}

From source file:edu.uark.spARK.SwipeDismissListViewTouchListener.java

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mListView.getWidth();
    }/*from   w  w  w  .  ja v a2 s.com*/
    switch (motionEvent.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        mPaused = false;
        longClickActive = false;
        //                if (mPaused) {
        //                    return false;
        //                }

        // TODO: ensure this is a finger, and set a flag

        // Find the child view that was touched (perform a hit test)
        Rect rect = new Rect();
        int childCount = mListView.getChildCount();
        int[] listViewCoords = new int[2];
        mListView.getLocationOnScreen(listViewCoords);
        int x = (int) motionEvent.getRawX() - listViewCoords[0];
        int y = (int) motionEvent.getRawY() - listViewCoords[1];
        View child;

        //ignore header views
        for (int i = 1; i < childCount; i++) {
            child = mListView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                mDownView = child;
                break;
            }
        }
        if (mDownView != null) {
            mDownView = mDownView.findViewById(R.id.table);
            mDownX = motionEvent.getRawX();
            //TODO: really need to figure out why npe is happening here
            try {
                mDownPosition = mListView.getPositionForView(mDownView);
            } catch (NullPointerException npe) {
                //why does this keep happening?
                npe.printStackTrace();
            }
            if (mCallbacks.canDismiss(mDownPosition)) {
                mVelocityTracker = VelocityTracker.obtain();
                mVelocityTracker.addMovement(motionEvent);
            } else {
                mDownView = null;
            }
        }
        view.onTouchEvent(motionEvent);
        return true;
    }

    case MotionEvent.ACTION_UP: {
        if (longClickActive) {
            RelativeLayout darkenTop = (RelativeLayout) mListView.getRootView()
                    .findViewById(R.id.darkenScreenTop);
            ImageView darkenBottom = (ImageView) mListView.getRootView().findViewById(R.id.darkenScreenBottom);
            darkenTop.animate().alpha(0).setDuration(mAnimationTime).setListener(null);
            darkenBottom.animate().alpha(0).setDuration(mAnimationTime).setListener(null);
            if (mVelocityTracker == null) {
                break;
            }
            float deltaX = motionEvent.getRawX() - mDownX;
            mVelocityTracker.addMovement(motionEvent);
            mVelocityTracker.computeCurrentVelocity(1000);
            float velocityX = mVelocityTracker.getXVelocity();
            float absVelocityX = Math.abs(velocityX);
            float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
            boolean dismiss = false;
            boolean dismissRight = false;
            if (Math.abs(deltaX) > mViewWidth / 2) {
                dismiss = true;
                dismissRight = deltaX > 0;
            } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                    && absVelocityY < absVelocityX) {
                // dismiss only if flinging in the same direction as dragging
                dismiss = (velocityX < 0) == (deltaX < 0);
                dismissRight = mVelocityTracker.getXVelocity() > 0;
            }
            if (dismiss) {
                // dismiss
                dismiss(mDownView, mDownPosition, dismissRight);
            } else {
                // cancel
                mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
            }
            mVelocityTracker.recycle();
            mVelocityTracker = null;
            mDownX = 0;
            mDownView = null;
            mDownPosition = ListView.INVALID_POSITION;
            mSwiping = false;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        longClickActive = false;
        mPaused = false;
        RelativeLayout darkenTop = (RelativeLayout) mListView.getRootView().findViewById(R.id.darkenScreenTop);
        ImageView darkenBottom = (ImageView) mListView.getRootView().findViewById(R.id.darkenScreenBottom);

        darkenTop.animate().alpha(0).setDuration(mAnimationTime).setListener(null);
        darkenBottom.animate().alpha(0).setDuration(mAnimationTime).setListener(null);

        if (mVelocityTracker == null) {
            break;
        }

        if (mDownView != null) {
            // cancel
            mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownView = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null || mPaused) {
            break;
        }
        if (longClickActive) {
            mVelocityTracker.addMovement(motionEvent);
            float deltaX = motionEvent.getRawX() - mDownX;
            //the if statement is allowing the listview to scroll until a sufficient deltaX is made, while we want swiping immediately 
            //                        if (Math.abs(deltaX) > mSlop) {
            mSwiping = true;
            mListView.requestDisallowInterceptTouchEvent(true);

            // Cancel ListView's touch (un-highlighting the item) which is not what we want
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL
                    | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
            mListView.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
            //                        }
            if (mSwiping) {

                mDownView.setTranslationX(deltaX);
                //we don't want the alpha to change
                //                    mDownView.setAlpha(Math.max(0.15f, Math.min(1f,
                //                            1f - 2f * Math.abs(deltaX) / mViewWidth)));
                return true;
            }
        }
        break;
    }
    }
    return false;
}

From source file:com.android.mail.browse.ConversationContainer.java

private void forwardFakeMotionEvent(MotionEvent original, int newAction) {
    MotionEvent newEvent = MotionEvent.obtain(original);
    newEvent.setAction(newAction);/*from w  w w.ja va  2 s.  c o m*/
    mWebView.onTouchEvent(newEvent);
    LogUtils.v(TAG, "in Container.OnTouch. fake: action=%d x/y=%f/%f pointers=%d", newEvent.getActionMasked(),
            newEvent.getX(), newEvent.getY(), newEvent.getPointerCount());
}

From source file:org.creativecommons.thelist.swipedismiss.SwipeDismissRecyclerViewTouchListener.java

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mRecyclerView.getWidth();
    }//w  ww  .  ja  v  a  2s  .c o  m

    switch (motionEvent.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        if (mPaused) {
            return false;
        }

        // TODO: ensure this is a finger, and set a flag

        // Find the child view that was touched (perform a hit test)
        Rect rect = new Rect();
        int childCount = mRecyclerView.getChildCount();
        int[] listViewCoords = new int[2];
        mRecyclerView.getLocationOnScreen(listViewCoords);
        int x = (int) motionEvent.getRawX() - listViewCoords[0];
        int y = (int) motionEvent.getRawY() - listViewCoords[1];
        View child;
        for (int i = 0; i < childCount; i++) {
            child = mRecyclerView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                mDownView = child;
                break;
            }
        }

        if (mDownView != null) {
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mRecyclerView.getChildPosition(mDownView);
            if (mCallbacks.canDismiss(mDownPosition)) {
                mVelocityTracker = VelocityTracker.obtain();
                mVelocityTracker.addMovement(motionEvent);
            } else {
                mDownView = null;
            }
        }
        return false;
    } //OnTouch

    case MotionEvent.ACTION_CANCEL: {
        if (mVelocityTracker == null) {
            break;
        }

        if (mDownView != null && mSwiping) {
            // cancel
            //TODO: DOES THIS WORK
            animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        mRefreshLayout.setEnabled(true);
        break;
    } //ACTION_CANCEL

    case MotionEvent.ACTION_UP: {
        if (mVelocityTracker == null) {
            break;
        }

        float deltaX = motionEvent.getRawX() - mDownX;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = mVelocityTracker.getXVelocity();
        float absVelocityX = Math.abs(velocityX);
        float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
        //                float velocityX = Math.abs(mVelocityTracker.getXVelocity());
        //                float velocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = deltaX > 0;
        } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                && absVelocityY < absVelocityX && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (deltaX < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }
        if (dismiss && mDownPosition != ListView.INVALID_POSITION) {
            // dismiss
            final View downView = mDownView; // mDownView gets null'd before animation ends
            final int downPosition = mDownPosition;
            ++mDismissAnimationRefCount;
            //TODO: add animation lock
            //                    synchronized (mAnimationLock){
            //                        if(mAnimatedViews.contains(downView)){
            //                            break;
            //                        }
            //                        ++mDismissAnimationRefCount;
            //                        mAnimatedViews.add(downView);
            //                    }

            animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                    .setDuration(mAnimationTime)
                    .setListener(new com.nineoldandroids.animation.AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(com.nineoldandroids.animation.Animator animation) {
                            performDismiss(downView, downPosition);
                        }
                    });
        } else {
            // cancel
            animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        mRefreshLayout.setEnabled(true);
        break;
    } //ACTION_UP

    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null || mPaused) {
            break;
        }

        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mRefreshLayout.setEnabled(false);
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
            mRecyclerView.requestDisallowInterceptTouchEvent(true);

            // CancelLogin ListView's touch (un-highlighting the item)
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL
                    | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
            mRecyclerView.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
        }

        if (mSwiping) {
            mDownView.setTranslationX(deltaX - mSwipingSlop);
            mDownView.setAlpha(Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
            return true;
            //                    setTranslationX(mDownView, deltaX);
            //                    setAlpha(mDownView, Math.max(0f, Math.min(1f,
            //                            1f - 2f * Math.abs(deltaX) / mViewWidth)));
            //                    return true;
        }
        break;
    }
    }
    return false;
}

From source file:org.duncavage.swipetorefresh.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;/*  w  w  w  . j a v a2 s.c  o  m*/
        mDownEvent = MotionEvent.obtain(event);
        break;
    case MotionEvent.ACTION_MOVE:
        if (mHasRefreshed || isRefreshing()) {
            // We've already triggered a refresh once during this gesture.
            return false;
        }
        if (mDownEvent != null) {
            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();
                    mHasRefreshed = handled = true;
                    break;
                } else {
                    // Just track the user's movement
                    setTriggerPercentage(
                            mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                    updatePositionTimeout();
                    handled = true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        removeCallbacks(mCancel);
        if (mHasRefreshed) {
            // If we've already refreshed, just unset the flag.
            // No need to run the cancel runnable;
            mHasRefreshed = false;
        } else {
            mCancel.run();
        }
        break;
    }
    return handled;
}

From source file:com.kescoode.android.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 w  w  w . jav a2 s .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((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();
                    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.gcloud.gaadi.chat.SwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;//  www.  j av a  2  s .co  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((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();
                    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.swiperefreshlayout.SwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mDistanceToTriggerSync == -1) {
        mDistanceToTriggerSync = mRefreshIndicatorHeight;
    }//from   w  w w. ja  va2 s. c om
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;
        mDownEvent = MotionEvent.obtain(event);
        mPrevY = mDownEvent.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart && !mRefreshing) {
            final float eventY = event.getY();
            float yDiff = eventY - mDownEvent.getY();
            if (yDiff > mDistanceToTriggerSync * 1.5) {
                yDiff = (float) (mDistanceToTriggerSync * 1.5);
            }
            if (yDiff > mTouchSlop || mPulling) {
                mPulling = true;
                if (mCurrentTargetOffsetTop + eventY - mPrevY - mOriginalOffsetTop > mDistanceToTriggerSync) {
                    if (mListener != null)
                        mListener.canRefresh();
                } else if (mListener != null) {
                    mListener.canNotRefresh();
                }
                setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                float offsetTop = mCurrentTargetOffsetTop + (eventY - mPrevY) / 2;
                updateContentOffsetTop((int) (offsetTop));
                handled = true;
            }
            mPrevY = event.getY();
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mDownEvent != null && !mReturningToStart && !mRefreshing) {
            mPulling = false;
            final float eventY = event.getY();
            float offsetTop = mCurrentTargetOffsetTop + eventY - mPrevY;
            updateContentOffsetTop((int) (offsetTop));
            if (mDownEvent != null && !mReturningToStart) {
                if (mCurrentTargetOffsetTop - mOriginalOffsetTop > mDistanceToTriggerSync) {
                    // User movement passed distance; trigger a refresh
                    startRefresh();
                    handled = true;
                    break;
                } else {
                    mCancel.run();
                    break;
                }
            }
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        mPulling = false;
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        mCancel.run();
        break;
    }
    return handled;
}

From source file:com.am.pullview.swiperefresh.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  w w .j ava  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;
                    }
                    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();
                    handled = true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}