List of usage examples for android.view MotionEvent ACTION_CANCEL
int ACTION_CANCEL
To view the source code for android.view MotionEvent ACTION_CANCEL.
Click Source Link
From source file:com.andview.refreshview.swipe.SwipeMenuLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (mVelocityTracker == null) mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(ev);/*from w ww . j av a 2 s. com*/ int dx; int dy; int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mLastX = (int) ev.getX(); mLastY = (int) ev.getY(); break; case MotionEvent.ACTION_MOVE: if (!isSwipeEnable()) break; int disX = (int) (mLastX - ev.getX()); int disY = (int) (mLastY - ev.getY()); if (!mDragging && Math.abs(disX) > mScaledTouchSlop && Math.abs(disX) > Math.abs(disY)) { mDragging = true; } if (mDragging) { if (mSwipeCurrentHorizontal == null || shouldResetSwipe) { if (disX < 0) { if (mSwipeLeftHorizontal != null) mSwipeCurrentHorizontal = mSwipeLeftHorizontal; else mSwipeCurrentHorizontal = mSwipeRightHorizontal; } else { if (mSwipeRightHorizontal != null) mSwipeCurrentHorizontal = mSwipeRightHorizontal; else mSwipeCurrentHorizontal = mSwipeLeftHorizontal; } } scrollBy(disX, 0); mLastX = (int) ev.getX(); mLastY = (int) ev.getY(); shouldResetSwipe = false; } break; case MotionEvent.ACTION_UP: dx = (int) (mDownX - ev.getX()); dy = (int) (mDownY - ev.getY()); mDragging = false; mVelocityTracker.computeCurrentVelocity(1000, mScaledMaximumFlingVelocity); int velocityX = (int) mVelocityTracker.getXVelocity(); int velocity = Math.abs(velocityX); if (velocity > mScaledMinimumFlingVelocity) { if (mSwipeCurrentHorizontal != null) { int duration = getSwipeDuration(ev, velocity); if (mSwipeCurrentHorizontal instanceof SwipeRightHorizontal) { if (velocityX < 0) { smoothOpenMenu(duration); } else { smoothCloseMenu(duration); } } else { if (velocityX > 0) { smoothOpenMenu(duration); } else { smoothCloseMenu(duration); } } ViewCompat.postInvalidateOnAnimation(this); } } else { judgeOpenClose(dx, dy); } mVelocityTracker.clear(); mVelocityTracker.recycle(); mVelocityTracker = null; if (Math.abs(mDownX - ev.getX()) > mScaledTouchSlop || Math.abs(mDownY - ev.getY()) > mScaledTouchSlop || isMenuOpen()) { ev.setAction(MotionEvent.ACTION_CANCEL); super.onTouchEvent(ev); return true; } break; case MotionEvent.ACTION_CANCEL: mDragging = false; if (!mScroller.isFinished()) { mScroller.abortAnimation(); } else { dx = (int) (mDownX - ev.getX()); dy = (int) (mDownY - ev.getY()); judgeOpenClose(dx, dy); } break; } return super.onTouchEvent(ev); }
From source file:cn.ieclipse.af.view.ScrollLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (debug) {/*from w w w . j av a 2 s . c o m*/ Log.e(TAG, "onInterceptTouchEvent-slop:" + mTouchSlop); } final int action = ev.getAction(); if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) { return true; } final float x = ev.getX(); final float y = ev.getY(); switch (action) { case MotionEvent.ACTION_MOVE: final int xDiff = (int) Math.abs(mLastMotionX - x); if (xDiff > mTouchSlop) { mTouchState = TOUCH_STATE_SCROLLING; } break; case MotionEvent.ACTION_DOWN: mLastMotionX = x; mLastMotionY = y; mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING; break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: mTouchState = TOUCH_STATE_REST; break; } return mTouchState != TOUCH_STATE_REST; }
From source file:cc.solart.turbo.TurboRecyclerView.java
@Override public boolean onInterceptTouchEvent(MotionEvent e) { if (!mLoadEnabled || canScrollEnd() || mIsLoading || isEmpty()) { return super.onInterceptTouchEvent(e); }/*from w w w . j a va2 s . co m*/ if (dispatchOnItemTouchIntercept(e)) { return true; } final int action = MotionEventCompat.getActionMasked(e); final int actionIndex = MotionEventCompat.getActionIndex(e); switch (action) { case MotionEvent.ACTION_DOWN: { mActivePointerId = MotionEventCompat.getPointerId(e, 0); mInitialMotionX = getMotionEventX(e, actionIndex); mInitialMotionY = getMotionEventY(e, actionIndex); } break; case MotionEvent.ACTION_POINTER_DOWN: { mActivePointerId = MotionEventCompat.getPointerId(e, actionIndex); mInitialMotionX = getMotionEventX(e, actionIndex); mInitialMotionY = getMotionEventY(e, actionIndex); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mActivePointerId = INVALID_POINTER; break; case MotionEventCompat.ACTION_POINTER_UP: { onPointerUp(e); } break; } return super.onInterceptTouchEvent(e); }
From source file:android.support.design.widget.BottomSheetBehavior.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { mIgnoreEvents = true;/*from ww w .ja v a 2s .c o m*/ return false; } int action = MotionEventCompat.getActionMasked(event); // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mTouchingScrollingChild = false; mActivePointerId = MotionEvent.INVALID_POINTER_ID; // Reset the ignore flag if (mIgnoreEvents) { mIgnoreEvents = false; return false; } break; case MotionEvent.ACTION_DOWN: int initialX = (int) event.getX(); mInitialY = (int) event.getY(); View scroll = mNestedScrollingChildRef.get(); if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) { mActivePointerId = event.getPointerId(event.getActionIndex()); mTouchingScrollingChild = true; } mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID && !parent.isPointInChildBounds(child, initialX, mInitialY); break; } if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) { return true; } // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because // it is not the top most view of its parent. This is not necessary when the touch event is // happening over the scrolling content as nested scrolling logic handles that case. View scroll = mNestedScrollingChildRef.get(); return action == MotionEvent.ACTION_MOVE && scroll != null && !mIgnoreEvents && mState != STATE_DRAGGING && !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY()) && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop(); }
From source file:com.commonsware.cwac.crossport.design.widget.BottomSheetBehavior.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { mIgnoreEvents = true;/*from ww w . j a v a2s . co m*/ return false; } int action = event.getActionMasked(); // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mTouchingScrollingChild = false; mActivePointerId = MotionEvent.INVALID_POINTER_ID; // Reset the ignore flag if (mIgnoreEvents) { mIgnoreEvents = false; return false; } break; case MotionEvent.ACTION_DOWN: int initialX = (int) event.getX(); mInitialY = (int) event.getY(); View scroll = mNestedScrollingChildRef != null ? mNestedScrollingChildRef.get() : null; if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) { mActivePointerId = event.getPointerId(event.getActionIndex()); mTouchingScrollingChild = true; } mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID && !parent.isPointInChildBounds(child, initialX, mInitialY); break; } if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) { return true; } // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because // it is not the top most view of its parent. This is not necessary when the touch event is // happening over the scrolling content as nested scrolling logic handles that case. View scroll = mNestedScrollingChildRef.get(); return action == MotionEvent.ACTION_MOVE && scroll != null && !mIgnoreEvents && mState != STATE_DRAGGING && !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY()) && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop(); }
From source file:cn.bingoogolapple.refreshlayout.BGAStickyNavLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { initVelocityTrackerIfNotExists();// ww w.ja v a 2 s. co m mVelocityTracker.addMovement(event); float currentTouchY = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mOverScroller.isFinished()) { mOverScroller.abortAnimation(); } mLastTouchY = currentTouchY; break; case MotionEvent.ACTION_MOVE: float differentY = currentTouchY - mLastTouchY; mLastTouchY = currentTouchY; if (Math.abs(differentY) > 0) { scrollBy(0, (int) -differentY); } break; case MotionEvent.ACTION_CANCEL: recycleVelocityTracker(); if (!mOverScroller.isFinished()) { mOverScroller.abortAnimation(); } break; case MotionEvent.ACTION_UP: mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) mVelocityTracker.getYVelocity(); if ((Math.abs(initialVelocity) > mMinimumVelocity)) { fling(-initialVelocity); } recycleVelocityTracker(); break; } return true; }
From source file:com.cocarechina.pullrefreshview.layout.FlingLayout.java
/******************************************************************/ @Override//w ww . ja v a2 s . c o m public boolean dispatchTouchEvent(MotionEvent ev) { if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) { float moveY = getMoveY(); int pointerCount = ev.getPointerCount(); int pointerIndex = ev.getActionIndex(); if (!mScroller.isFinished()) { mScroller.abortAnimation(); } switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mPointerId = ev.getPointerId(pointerIndex); float x = ev.getX(pointerIndex); float y = ev.getY(pointerIndex); tepmY = downY = y; tepmX = downX = x; tempStateType = SCROLL_STATE_TOUCH_SCROLL; if (moveY != 0) { return true; } lastY = ev.getY(); Log.v("lastY", moveY + ""); break; case MotionEvent.ACTION_POINTER_DOWN: mPointerId = ev.getPointerId(pointerIndex); tepmX = ev.getX(pointerIndex); tepmY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: pointerIndex = ev.findPointerIndex(mPointerId); float mx; float my; if (pointerCount > pointerIndex && pointerIndex >= 0) { mx = ev.getX(pointerIndex); my = ev.getY(pointerIndex); } else { mx = ev.getX(); my = ev.getY(); } //????? int dataX = (int) (mx - tepmX); int dataY = (int) (my - tepmY); tepmX = mx; tepmY = my; if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) { isScrolling = true; if (moveY == 0) { // 0,0 //?? if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) { moveBy(dataY); return true; } } else { //?0,0 ev.setAction(MotionEvent.ACTION_CANCEL);//? if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) { //0,0 ev.setAction(MotionEvent.ACTION_DOWN); moveTo(0); } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) { //?? if (maxDistance == 0 || Math.abs(moveY) < maxDistance) { int ps = 0; int hDataY = dataY / 2; if (maxDistance == 0) { ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY; } else { ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY; } moveBy(ps + dataY); } else if (moveY > maxDistance) { moveTo(maxDistance); } else if (moveY < -maxDistance) { moveTo(-maxDistance); } } else { moveBy(dataY); } } } else { ev.setLocation(mx, downY); } Log.v("flingLayout", "ev.getY()" + ev.getY() + " --- lastY " + lastY); if (ev.getY() - lastY > 5) { if (monScrollHeadListener != null) { monScrollHeadListener.onScrollBottom(); } } else if (ev.getY() - lastY < -10) { if (monScrollHeadListener != null) { monScrollHeadListener.onScrollTop(); } } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: startFling(); isScrolling = false; break; case MotionEvent.ACTION_POINTER_UP: // ?? int pointerIdLeave = ev.getPointerId(pointerIndex); if (mPointerId == pointerIdLeave) { // ??????VelocityTracker int reIndex = pointerIndex == 0 ? 1 : 0; mPointerId = ev.getPointerId(reIndex); // ? tepmY = ev.getY(reIndex); } } return super.dispatchTouchEvent(ev) || isScrolling; } else { return super.dispatchTouchEvent(ev); } }
From source file:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { mIgnoreEvents = true;//w w w. ja v a 2 s. co m return false; } int action = MotionEventCompat.getActionMasked(event); // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mTouchingScrollingChild = false; mActivePointerId = MotionEvent.INVALID_POINTER_ID; // Reset the ignore flag if (mIgnoreEvents) { mIgnoreEvents = false; return false; } break; case MotionEvent.ACTION_DOWN: int initialX = (int) event.getX(); mInitialY = (int) event.getY(); for (WeakReference<View> scrollableView : scrollableViews) { View scroll = scrollableView.get(); if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) { mActivePointerId = event.getPointerId(event.getActionIndex()); mTouchingScrollingChild = true; break; } } mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID && !parent.isPointInChildBounds(child, initialX, mInitialY); break; } if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) { return true; } // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because // it is not the top most view of its parent. This is not necessary when the touch event is // happening over the scrolling content as nested scrolling logic handles that case. boolean isPointInChildBounds = false; for (WeakReference<View> scrollableView : scrollableViews) { isPointInChildBounds = scrollableView.get() != null && parent.isPointInChildBounds(scrollableView.get(), (int) event.getX(), (int) event.getY()); if (isPointInChildBounds) { break; } } return action == MotionEvent.ACTION_MOVE && !mIgnoreEvents && mState != STATE_DRAGGING && !isPointInChildBounds && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop(); }
From source file:com.dgnt.dominionCardPicker.view.DynamicListView.java
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mDownX = (int) event.getX(); mDownY = (int) event.getY(); mActivePointerId = event.getPointerId(0); break;// ww w.j a v a 2s .c om case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER_ID) { break; } int pointerIndex = event.findPointerIndex(mActivePointerId); mLastEventY = (int) event.getY(pointerIndex); int deltaY = mLastEventY - mDownY; if (mCellIsMobile) { mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mHoverCellOriginalBounds.top + deltaY + mTotalOffset); mHoverCell.setBounds(mHoverCellCurrentBounds); invalidate(); handleCellSwitch(); mIsMobileScrolling = false; handleMobileCellScroll(); return false; } break; case MotionEvent.ACTION_UP: touchEventsEnded(); break; case MotionEvent.ACTION_CANCEL: touchEventsCancelled(); break; case MotionEvent.ACTION_POINTER_UP: /* If a multitouch event took place and the original touch dictating * the movement of the hover cell has ended, then the dragging event * ends and the hover cell is animated to its corresponding position * in the listview. */ pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; final int pointerId = event.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { touchEventsEnded(); } break; default: break; } return super.onTouchEvent(event); }
From source file:com.anjuke.library.uicomponent.photo.EndlessCircleIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from w w w . j a v a 2 s.c o m if ((mViewPager == null) || (mCount == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: 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) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } else if ((mCurrentPage < mCount - 1) && (ev.getX() > halfWidth + sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); 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; }