Example usage for android.view MotionEvent ACTION_CANCEL

List of usage examples for android.view MotionEvent ACTION_CANCEL

Introduction

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

Prototype

int ACTION_CANCEL

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

Click Source Link

Document

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

Usage

From source file:br.com.devmix.baseapp.listener.OnSwipeableRecyclerViewTouchListener.java

private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalLayoutParamsHeight = lp.height;
    final int originalHeight = dismissView.getHeight();

    ValueAnimatorCompat animatorCompat = AnimatorCompatHelper.emptyValueAnimator();
    animatorCompat.setDuration(mAnimationTime);
    animatorCompat.addListener(new AnimatorListenerCompat() {
        @Override/*from  www.j ava2  s . c  om*/
        public void onAnimationStart(ValueAnimatorCompat animation) {
        }

        @Override
        public void onAnimationEnd(ValueAnimatorCompat animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);

                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }

                if (mFinalDelta > 0) {
                    mSwipeListener.onDismissedBySwipeRight(mRecyclerView, dismissPositions);
                } else {
                    mSwipeListener.onDismissedBySwipeLeft(mRecyclerView, dismissPositions);
                }

                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;

                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    ViewCompat.setAlpha(pendingDismiss.view, mAlpha);
                    ViewCompat.setTranslationX(pendingDismiss.view, 0);

                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalLayoutParamsHeight;

                    pendingDismiss.view.setLayoutParams(lp);
                }

                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);

                mPendingDismisses.clear();
                mAnimatingPosition = ListView.INVALID_POSITION;
            }
        }

        @Override
        public void onAnimationCancel(ValueAnimatorCompat animation) {
        }

        @Override
        public void onAnimationRepeat(ValueAnimatorCompat animation) {
        }
    });
    animatorCompat.addUpdateListener(new AnimatorUpdateListenerCompat() {
        @Override
        public void onAnimationUpdate(ValueAnimatorCompat animation) {
            float fraction = animation.getAnimatedFraction();
            lp.height = (int) (originalHeight * (1 - fraction));
            dismissView.setLayoutParams(lp);
        }
    });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animatorCompat.start();
}

From source file:com.bolaa.medical.view.banner.LoopCirclePageIndicator.java

public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*from  w  w w .ja v  a2s  .  c  o  m*/
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        //                invalidate();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            if (!mViewPager.isFakeDragging()) {
                mViewPager.beginFakeDrag();
            }

            mLastMotionX = x;

            // tyl ?beginFakeDrag()false,pagermFakeDragging???,
            // ?isFakeDragging()?false??fakeDragBy()
            if (mViewPager != null && mViewPager.isFakeDragging()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                mViewPager.setCurrentItem(mCurrentPage - 1);
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                mViewPager.setCurrentItem(mCurrentPage + 1);
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager != null && mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        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:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:cc.solart.turbo.TurboRecyclerView.java

@Override
public boolean onTouchEvent(MotionEvent e) {
    if (!mLoadEnabled || canScrollEnd() || mIsLoading || isEmpty()) {
        return super.onTouchEvent(e);
    }/*www .jav  a 2s .  co  m*/

    if (dispatchOnItemTouch(e)) {
        return true;
    }

    if (getLayoutManager() == null) {
        return false;
    }

    final boolean canScrollHorizontally = getLayoutManager().canScrollHorizontally();
    final boolean canScrollVertically = getLayoutManager().canScrollVertically();

    final int action = MotionEventCompat.getActionMasked(e);
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        final int index = MotionEventCompat.getActionIndex(e);
        mActivePointerId = MotionEventCompat.getPointerId(e, 0);
        mInitialMotionX = getMotionEventX(e, index);
        mInitialMotionY = getMotionEventY(e, index);
    }
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(e);
        mActivePointerId = MotionEventCompat.getPointerId(e, index);
        mInitialMotionX = getMotionEventX(e, index);
        mInitialMotionY = getMotionEventY(e, index);
    }
        break;

    case MotionEvent.ACTION_MOVE: {

        final int index = MotionEventCompat.findPointerIndex(e, mActivePointerId);
        if (index < 0) {
            Log.w(TAG, "pointer index for id " + index + " not found. return super");
            return super.onTouchEvent(e);
        }

        final int x = getMotionEventX(e, index);
        final int y = getMotionEventY(e, index);

        int deltaY = y - mInitialMotionY;
        if (canScrollVertically && Math.abs(deltaY) > mTouchSlop && deltaY < 0) {
            float targetEnd = -dampAxis(deltaY);
            setTranslationY(targetEnd);
            return true;
        }

        int deltaX = x - mInitialMotionX;
        if (canScrollHorizontally && Math.abs(deltaX) > mTouchSlop && deltaX < 0) {
            float targetEnd = -dampAxis(deltaX);
            setTranslationX(targetEnd);
            return true;
        }
    }
        break;
    case MotionEventCompat.ACTION_POINTER_UP: {
        onPointerUp(e);
    }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL: {
        if (canScrollHorizontally)
            animateOffsetToEnd("translationX", mInterpolator, 0f);
        if (canScrollVertically)
            animateOffsetToEnd("translationY", mInterpolator, 0f);
        final int index = MotionEventCompat.findPointerIndex(e, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "Got ACTION_UP event but don't have an active pointer id.");
            return super.onTouchEvent(e);
        }

        final int y = getMotionEventY(e, index);
        final int x = getMotionEventX(e, index);
        final float overScrollBottom = (mInitialMotionY - y) * DRAG_RATE;
        final float overScrollRight = (mInitialMotionX - x) * DRAG_RATE;

        if ((canScrollVertically && overScrollBottom > mTotalDragDistance)
                || (canScrollHorizontally && overScrollRight > mTotalDragDistance)) {
            Log.i(TAG, "refreshing...");
            mIsLoading = true;
            dispatchOnLoadingMoreListeners();
            smoothScrollToPosition(mLastVisibleItemPosition + 1);
            mActivePointerId = INVALID_POINTER;
            return true;
        } else {
            mIsLoading = false;
            mActivePointerId = INVALID_POINTER;
        }

    }
        break;
    }
    return super.onTouchEvent(e);
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {

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

    if (action == MotionEvent.ACTION_DOWN && touchTarget == null && stickyWrapper != null
            && isStickyViewTouched(stickyWrapper.view, x, y)) {
        touchTarget = stickyWrapper.view;
        touchPt.x = x;//from  w  ww .  j a va2s.c o m
        touchPt.y = y;

        downEvent = MotionEvent.obtain(ev);
    }

    if (touchTarget != null) {
        if (isStickyViewTouched(touchTarget, x, y)) {
            // forward event to header view
            touchTarget.dispatchTouchEvent(ev);
        }

        if (action == MotionEvent.ACTION_UP) {
            super.dispatchTouchEvent(ev);
            clearTouchTarget();

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

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

                MotionEvent event = MotionEvent.obtain(ev);
                event.setAction(MotionEvent.ACTION_CANCEL);
                touchTarget.dispatchTouchEvent(event);
                event.recycle();

                super.dispatchTouchEvent(downEvent);
                super.dispatchTouchEvent(ev);
                clearTouchTarget();

            }
        }

        return true;
    }

    return super.dispatchTouchEvent(ev);
}

From source file:com.achep.acdisplay.ui.widgets.CircleView.java

public boolean sendTouchEvent(@NonNull MotionEvent event) {
    final int action = event.getActionMasked();

    // If current circle is canceled then
    // ignore all actions except of touch down (to reset state.)
    if (mCanceled && action != MotionEvent.ACTION_DOWN)
        return false;

    // Cancel the current circle on two-or-more-fingers touch.
    if (event.getPointerCount() > 1) {
        cancelCircle();//from w ww  . ja  va 2  s . co  m
        return false;
    }

    final float x = event.getX();
    final float y = event.getY();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        clearAnimation();
        Config config = Config.getInstance();

        // Corner actions
        int width = getWidth();
        int height = getHeight();
        int radius = Math.min(width, height) / 3;
        if (MathUtils.isInCircle(x, y, 0, 0, radius)) { // Top left
            mCornerActionId = config.getCornerActionLeftTop();
        } else if (MathUtils.isInCircle(x, y, -width, 0, radius)) { // Top right
            mCornerActionId = config.getCornerActionRightTop();
        } else if (MathUtils.isInCircle(x, y, 0, -height, radius)) { // Bottom left
            mCornerActionId = config.getCornerActionLeftBottom();
        } else if (MathUtils.isInCircle(x, y, -width, -height, radius)) { // Bottom right
            mCornerActionId = config.getCornerActionRightBottom();
        } else {
            // The default action is unlocking.
            mCornerActionId = Config.CORNER_UNLOCK;
        }

        // Update colors and icon drawable.
        boolean needsColorReset = updateIcon();
        setInnerColor(getColor(config.getCircleInnerColor()), needsColorReset);
        setOuterColor(getColor(config.getCircleOuterColor()));

        // Initialize circle
        mRadiusTargetAimed = false;
        mRadiusMaxPeak = 0;
        mPoint[0] = x;
        mPoint[1] = y;
        mCanceled = false;

        if (mHandler.hasMessages(ACTION_UNLOCK)) {
            // Cancel unlocking process.
            mHandler.sendEmptyMessage(ACTION_UNLOCK_CANCEL);
        }

        mHandler.removeCallbacksAndMessages(null);
        mHandler.sendEmptyMessageDelayed(MSG_CANCEL, 1000);
        mHandler.sendEmptyMessage(ACTION_START);
        break;
    case MotionEvent.ACTION_MOVE:
        setRadius(x, y);
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mRadiusTargetAimed || action == MotionEvent.ACTION_CANCEL) {
            cancelCircle();
            break;
        }

        startUnlock();
        break;
    }
    return true;
}

From source file:org.cocos2dx.lib.TextInputWraper.java

public boolean onTouchEvent(final MotionEvent event) {
    // these data are used in ACTION_MOVE and ACTION_CANCEL
    final int pointerNumber = event.getPointerCount();
    final int[] ids = new int[pointerNumber];
    final float[] xs = new float[pointerNumber];
    final float[] ys = new float[pointerNumber];

    for (int i = 0; i < pointerNumber; i++) {
        ids[i] = event.getPointerId(i);//  w w w.  ja  va  2s.  co m
        xs[i] = event.getX(i);
        ys[i] = event.getY(i);
    }

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_POINTER_DOWN:
        final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        final int idPointerDown = event.getPointerId(indexPointerDown);
        final float xPointerDown = event.getX(indexPointerDown);
        final float yPointerDown = event.getY(indexPointerDown);

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionDown(idPointerDown, xPointerDown, yPointerDown);
            }
        });
        break;

    case MotionEvent.ACTION_DOWN:
        // there are only one finger on the screen
        final int idDown = event.getPointerId(0);
        final float xDown = xs[0];
        final float yDown = ys[0];

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionDown(idDown, xDown, yDown);
            }
        });
        break;

    case MotionEvent.ACTION_MOVE:
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionMove(ids, xs, ys);
            }
        });
        break;

    case MotionEvent.ACTION_POINTER_UP:
        final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        final int idPointerUp = event.getPointerId(indexPointUp);
        final float xPointerUp = event.getX(indexPointUp);
        final float yPointerUp = event.getY(indexPointUp);

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionUp(idPointerUp, xPointerUp, yPointerUp);
            }
        });
        break;

    case MotionEvent.ACTION_UP:
        // there are only one finger on the screen
        final int idUp = event.getPointerId(0);
        final float xUp = xs[0];
        final float yUp = ys[0];

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionUp(idUp, xUp, yUp);
            }
        });
        break;

    case MotionEvent.ACTION_CANCEL:
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionCancel(ids, xs, ys);
            }
        });
        break;
    }

    if (debug) {
        dumpEvent(event);
    }
    return true;
}

From source file:cn.meiqu.baseproject.view.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java

private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override/* w w w . j ava 2s. c om*/
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);

                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }
                mCallbacks.onDismiss(mRecyclerView, dismissPositions);

                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss 
                // animation with a stale position
                mDownPosition = INVALID_POSITION;

                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    setAlpha(pendingDismiss.view, 1f);
                    setTranslationX(pendingDismiss.view, 0);
                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalHeight;
                    pendingDismiss.view.setLayoutParams(lp);
                }

                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);

                mPendingDismisses.clear();
            }
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

From source file:cn.ieclipse.af.view.StaggeredGridView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);/* w w  w  .  j  a  v a2  s  .c o  m*/
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mVelocityTracker.clear();
        mScroller.abortAnimation();
        mLastTouchY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mTouchRemainderY = 0;
        break;

    case MotionEvent.ACTION_MOVE: {
        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float y = MotionEventCompat.getY(ev, index);
        final float dy = y - mLastTouchY + mTouchRemainderY;
        final int deltaY = (int) dy;
        mTouchRemainderY = dy - deltaY;

        if (Math.abs(dy) > mTouchSlop) {
            mTouchMode = TOUCH_MODE_DRAGGING;
        }

        if (mTouchMode == TOUCH_MODE_DRAGGING) {
            mLastTouchY = y;

            if (!trackMotionScroll(deltaY, true)) {
                // Break fling velocity if we impacted an edge.
                mVelocityTracker.clear();
            }
        }
    }
        break;

    case MotionEvent.ACTION_CANCEL:
        mTouchMode = TOUCH_MODE_IDLE;
        break;

    case MotionEvent.ACTION_UP: {
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
        if (Math.abs(velocity) > mFlingVelocity) { // TODO
            mTouchMode = TOUCH_MODE_FLINGING;
            mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
            mLastTouchY = 0;
            ViewCompat.postInvalidateOnAnimation(this);
        } else {
            mTouchMode = TOUCH_MODE_IDLE;
        }

    }
        break;
    }
    return true;
}

From source file:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {

    if (!isEnabled() || canChildScrollUp()) {
        return false;
    }//from  w ww.  j av  a2 s  . com
    mIsBeingDropped = mWaveView.isDisappearCircleAnimatorRunning();

    final int action = MotionEventCompat.getActionMasked(event);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        // Here is not called from anywhere
        break;

    case MotionEvent.ACTION_MOVE:
        final int pointerIndex = MotionEventCompat.findPointerIndex(event, mActivePointerId);
        return pointerIndex >= 0 && onMoveTouchEvent(event, pointerIndex);

    case MotionEvent.ACTION_UP:
        if (mIsBeingDropped) {
            mIsBeingDropped = false;
            return false;
        }

        final float diffY = event.getY() - mFirstTouchDownPointY;
        final float waveHeightThreshold = diffY
                * (5f - 2 * diffY / Math.min(getMeasuredWidth(), getMeasuredHeight())) / 1000f;
        mWaveView.startWaveAnimation(waveHeightThreshold);

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

        if (!isRefreshing()) {
            mCircleView.setProgressStartEndTrim(0f, 0f);
            mCircleView.showArrow(false);
            mCircleView.setVisibility(GONE);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    return true;
}

From source file:com.android.photos.views.GalleryThumbnailView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);//w  ww . j  av a  2 s.  c  om
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mVelocityTracker.clear();
        mScroller.abortAnimation();
        mLastTouchX = ev.getX();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mTouchRemainderX = 0;
        break;

    case MotionEvent.ACTION_MOVE: {
        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float x = MotionEventCompat.getX(ev, index);
        final float dx = x - mLastTouchX + mTouchRemainderX;
        final int deltaX = (int) dx;
        mTouchRemainderX = dx - deltaX;

        if (Math.abs(dx) > mTouchSlop) {
            mTouchMode = TOUCH_MODE_DRAGGING;
        }

        if (mTouchMode == TOUCH_MODE_DRAGGING) {
            mLastTouchX = x;

            if (!trackMotionScroll(deltaX, true)) {
                // Break fling velocity if we impacted an edge.
                mVelocityTracker.clear();
            }
        }
    }
        break;

    case MotionEvent.ACTION_CANCEL:
        mTouchMode = TOUCH_MODE_IDLE;
        break;

    case MotionEvent.ACTION_UP: {
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        final float velocity = VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId);
        if (Math.abs(velocity) > mFlingVelocity) { // TODO
            mTouchMode = TOUCH_MODE_FLINGING;
            mScroller.fling(0, 0, (int) velocity, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0);
            mLastTouchX = 0;
            ViewCompat.postInvalidateOnAnimation(this);
        } else {
            mTouchMode = TOUCH_MODE_IDLE;
        }

    }
        break;
    }
    return true;
}