List of usage examples for android.view VelocityTracker obtain
static public VelocityTracker obtain()
From source file:com.malinskiy.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java
private void caseMotionActionDown(MotionEvent motionEvent) { // 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;/*from www .jav a2 s .co m*/ 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.getChildLayoutPosition(mDownView); if (mCallbacks.canDismiss(mDownPosition)) { mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(motionEvent); } else { mDownView = null; } } }
From source file:com.codingfeel.sm.views.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java
private void caseMotionActionDown(MotionEvent motionEvent) { // 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;//from w w w .ja va 2s.com 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.getChildAdapterPosition(mDownView); if (mCallbacks.canDismiss(mDownPosition)) { mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(motionEvent); } else { mDownView = null; } } }
From source file:com.xiaoyu.erbao.cctrls.SlidingLayer.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { return false; }//from w w w . j av a 2s . c o m if (!mEnabled || !mIsDragging && !touchPointIsWithinBounds(mInitialX, mInitialY)) { return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); final int action = ev.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { completeScroll(); // Remember where the motion event started mLastX = mInitialRawX = getViewX(ev); mLastY = mInitialRawY = getViewY(ev); mInitialX = ev.getX(); mInitialY = ev.getY(); mActivePointerId = ev.getPointerId(0); break; } case MotionEvent.ACTION_MOVE: { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (!touchPointIsWithinBounds(ev.getX(), ev.getY(), false)) return false; final float x = getViewX(ev); final float y = getViewY(ev); final float deltaX = mLastX - x; final float deltaY = mLastY - y; mLastX = x; mLastY = y; if (!mIsDragging) { final float xDiff = Math.abs(x - mInitialRawX); final float yDiff = Math.abs(y - mInitialRawY); final boolean validHorizontalDrag = xDiff > mTouchSlop && xDiff > yDiff; final boolean validVerticalDrag = yDiff > mTouchSlop && yDiff > xDiff; if (validHorizontalDrag || validVerticalDrag) { mIsDragging = true; setDrawingCacheEnabled(true); } } if (mIsDragging) { final float oldScrollX = getScrollX(); final float oldScrollY = getScrollY(); float scrollX = oldScrollX + deltaX; float scrollY = oldScrollY + deltaY; // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]", scrollX, scrollY)); final float leftBound, rightBound; final float bottomBound, topBound; switch (mScreenSide) { case STICK_TO_LEFT: topBound = bottomBound = rightBound = 0; leftBound = getWidth(); // How far left we can scroll break; case STICK_TO_RIGHT: rightBound = -getWidth(); topBound = bottomBound = leftBound = 0; break; case STICK_TO_TOP: topBound = getHeight(); bottomBound = rightBound = leftBound = 0; break; case STICK_TO_BOTTOM: bottomBound = -(getHeight() - computeOffsetDistance()); topBound = rightBound = leftBound = 0; break; default: topBound = bottomBound = rightBound = leftBound = 0; break; } if (scrollX > leftBound) { scrollX = leftBound; } else if (scrollX < rightBound) { scrollX = rightBound; } if (scrollY > topBound) { scrollY = topBound; } else if (scrollY < bottomBound) { scrollY = bottomBound; } // Keep the precision mLastX += scrollX - (int) scrollX; mLastY += scrollY - (int) scrollY; scrollToAndNotify((int) scrollX, (int) scrollY); } break; } case MotionEvent.ACTION_UP: { if (mIsDragging) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId); final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); final int scrollX = getScrollX(); final int scrollY = getScrollY(); final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = getViewX(ev); final float y = getViewY(ev); int nextState = determineNextStateForDrag(scrollX, scrollY, initialVelocityX, initialVelocityY, (int) mInitialRawX, (int) mInitialRawY, (int) x, (int) y); setLayerState(nextState, true, true, initialVelocityX, initialVelocityY); mActivePointerId = INVALID_VALUE; endDrag(); } else if (changeStateOnTap) { int nextState = determineNextStateAfterTap(); setLayerState(nextState, true, true); } break; } case MotionEvent.ACTION_CANCEL: if (mIsDragging) { setLayerState(mCurrentState, true, true); mActivePointerId = INVALID_VALUE; endDrag(); } break; case MotionEvent.ACTION_POINTER_DOWN: { final int pointerIndex = MotionEventCompat.getActionIndex(ev); mActivePointerId = ev.getPointerId(pointerIndex); mLastX = getViewX(ev); mLastY = getViewY(ev); break; } case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); mLastX = getViewX(ev); mLastY = getViewY(ev); break; } } return true; }
From source file:net.woggle.shackbrowse.SlideFrame.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mEnabled) { return false; }// www .ja va 2 s .c om final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mIsDragging = false; mIsUnableToDrag = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } return false; } if (action != MotionEvent.ACTION_DOWN) { if (mIsDragging) { return true; } else if (mIsUnableToDrag) { return false; } } switch (action) { case MotionEvent.ACTION_MOVE: final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == -1) { mActivePointerId = INVALID_POINTER; break; } final float x = MotionEventCompat.getX(ev, pointerIndex); final float dx = x - mLastX; final float xDiff = Math.abs(dx); final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = Math.abs(y - mLastY); if (xDiff > mTouchSlop && xDiff > yDiff && allowDragging(dx)) { mIsDragging = true; mLastX = x; setDrawingCacheEnabled(true); mOnInteractListener.onDrag(); } else if (yDiff > mTouchSlop) { mIsUnableToDrag = true; } break; case MotionEvent.ACTION_DOWN: mActivePointerId = ev.getAction() & (Build.VERSION.SDK_INT >= 8 ? MotionEvent.ACTION_POINTER_INDEX_MASK : MotionEvent.ACTION_POINTER_INDEX_MASK); mLastX = mInitialX = MotionEventCompat.getX(ev, mActivePointerId); mLastY = MotionEventCompat.getY(ev, mActivePointerId); if (allowSlidingFromHere(ev)) { mIsDragging = false; mIsUnableToDrag = false; // If nobody else got the focus we use it to close the layer return super.onInterceptTouchEvent(ev); } else { mIsUnableToDrag = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (!mIsDragging) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); } return mIsDragging; }
From source file:com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown() || !mAllowUserDragging) { return false; }/*from w w w . j av a 2s . co m*/ int action = MotionEventCompat.getActionMasked(event); if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) { return true; } if (mViewDragHelper != null) { mViewDragHelper.processTouchEvent(event); } // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it // to capture the bottom sheet in case it is not captured and the touch slop is passed. if (action == MotionEvent.ACTION_MOVE && !mIgnoreEvents) { if (Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) { mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex())); } } return !mIgnoreEvents; }
From source file:com.xyczero.customswipelistview.CustomSwipeListView.java
private void addVelocityTrackerMotionEvent(MotionEvent ev) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); }//from w w w . jav a 2 s . com mVelocityTracker.addMovement(ev); }
From source file:net.woggle.shackbrowse.SlideFrame.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mEnabled || !mIsDragging && !mLastTouchAllowed && !allowSlidingFromHere(ev)) { return false; }/*from ww w . j av a 2s. c o m*/ final int action = ev.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_OUTSIDE) { mLastTouchAllowed = false; } else { mLastTouchAllowed = true; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: completeScroll(); // Remember where the motion event started mLastX = mInitialX = ev.getX(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; case MotionEvent.ACTION_MOVE: if (!mIsDragging) { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex == -1) { mActivePointerId = INVALID_POINTER; break; } final float x = MotionEventCompat.getX(ev, pointerIndex); final float xDiff = Math.abs(x - mLastX); final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = Math.abs(y - mLastY); if (xDiff > mTouchSlop && xDiff > yDiff) { mIsDragging = true; mLastX = x; setDrawingCacheEnabled(true); mOnInteractListener.onDrag(); } } if (mIsDragging) { // Scroll to follow the motion event final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (activePointerIndex == -1) { mActivePointerId = INVALID_POINTER; break; } final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = mLastX - x; mLastX = x; float oldScrollX = getScrollX(); float scrollX = oldScrollX + deltaX; final float leftBound = mScreenSide < STICK_TO_RIGHT ? getWidth() : 0; final float rightBound = mScreenSide == STICK_TO_LEFT ? 0 : -getWidth(); if (scrollX > leftBound) { scrollX = leftBound; } else if (scrollX < rightBound) { scrollX = rightBound; } // Keep the precision mLastX += scrollX - (int) scrollX; scrollToWrapper((int) scrollX, getScrollY()); } break; case MotionEvent.ACTION_UP: if (mIsDragging) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId); final int scrollX = getScrollX(); final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final int totalDelta = (int) (x - mInitialX); boolean nextStateOpened = determineNextStateOpened(mIsOpen, scrollX, initialVelocity, totalDelta); switchLayer(nextStateOpened, true, true, initialVelocity); mActivePointerId = INVALID_POINTER; endDrag(); } else if (mIsOpen && closeOnTapEnabled) { closeLayer(true); } break; case MotionEvent.ACTION_CANCEL: if (mIsDragging) { switchLayer(mIsOpen, 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); mLastX = x; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); mLastX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } if (mActivePointerId == INVALID_POINTER) { mLastTouchAllowed = false; } return true; }
From source file:com.bitflake.counter.HorizontalPicker.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) { return false; }/* w ww .j a va 2s . co m*/ if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_MOVE: float currentMoveX = event.getX(); int deltaMoveX = (int) (lastDownEventX - currentMoveX); if (scrollingX || (Math.abs(deltaMoveX) > touchSlop) && values != null && values.length > 0) { if (!scrollingX) { deltaMoveX = 0; pressedItem = -1; scrollingX = true; getParent().requestDisallowInterceptTouchEvent(true); stopMarqueeIfNeeded(); } final int range = getScrollRange(); if (overScrollBy(deltaMoveX, 0, getScrollX(), 0, range, 0, overscrollDistance, 0, true)) { mVelocityTracker.clear(); } final float pulledToX = getScrollX() + deltaMoveX; if (pulledToX < 0) { leftEdgeEffect.onPull((float) deltaMoveX / getWidth()); if (!rightEdgeEffect.isFinished()) { rightEdgeEffect.onRelease(); } } else if (pulledToX > range) { rightEdgeEffect.onPull((float) deltaMoveX / getWidth()); if (!leftEdgeEffect.isFinished()) { leftEdgeEffect.onRelease(); } } lastDownEventX = currentMoveX; invalidate(); } break; case MotionEvent.ACTION_DOWN: if (!adjustScrollerX.isFinished()) { adjustScrollerX.forceFinished(true); } else if (!flingScrollerX.isFinished()) { flingScrollerX.forceFinished(true); } else { scrollingX = false; } lastDownEventX = event.getX(); if (!scrollingX) { pressedItem = getPositionFromTouch(event.getX()); } invalidate(); break; case MotionEvent.ACTION_UP: VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, maximumFlingVelocity); int initialVelocityX = (int) velocityTracker.getXVelocity(); if (scrollingX && Math.abs(initialVelocityX) > mMinimumFlingVelocity) { flingX(initialVelocityX); } else if (values != null) { float positionX = event.getX(); if (!scrollingX) { int itemPos = getPositionOnScreen(positionX); int relativePos = itemPos - sideItems; if (relativePos == 0) { selectItem(); } else { smoothScrollBy(relativePos); } } else if (scrollingX) { finishScrolling(); } } mVelocityTracker.recycle(); mVelocityTracker = null; if (leftEdgeEffect != null) { leftEdgeEffect.onRelease(); rightEdgeEffect.onRelease(); } case MotionEvent.ACTION_CANCEL: pressedItem = -1; invalidate(); if (leftEdgeEffect != null) { leftEdgeEffect.onRelease(); rightEdgeEffect.onRelease(); } break; } return true; }
From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) { return false; }/*from w ww .java 2 s.c o m*/ if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_MOVE: float currentMoveX = event.getX(); int deltaMoveX = (int) (mLastDownEventX - currentMoveX); if (mScrollingX || (Math.abs(deltaMoveX) > mTouchSlop) && mValues != null && mValues.length > 0) { if (!mScrollingX) { deltaMoveX = 0; mPressedItem = -1; mScrollingX = true; stopMarqueeIfNeeded(); } final int range = getScrollRange(); if (overScrollBy(deltaMoveX, 0, getScrollX(), 0, range, 0, mOverscrollDistance, 0, true)) { mVelocityTracker.clear(); } final float pulledToX = getScrollX() + deltaMoveX; if (pulledToX < 0) { mLeftEdgeEffect.onPull((float) deltaMoveX / getWidth()); if (!mRightEdgeEffect.isFinished()) { mRightEdgeEffect.onRelease(); } } else if (pulledToX > range) { mRightEdgeEffect.onPull((float) deltaMoveX / getWidth()); if (!mLeftEdgeEffect.isFinished()) { mLeftEdgeEffect.onRelease(); } } mLastDownEventX = currentMoveX; invalidate(); } break; case MotionEvent.ACTION_DOWN: if (!mAdjustScrollerX.isFinished()) { mAdjustScrollerX.forceFinished(true); } else if (!mFlingScrollerX.isFinished()) { mFlingScrollerX.forceFinished(true); } else { mScrollingX = false; } mLastDownEventX = event.getX(); if (!mScrollingX) { mPressedItem = getPositionFromTouch(event.getX()); } invalidate(); break; case MotionEvent.ACTION_UP: VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumFlingVelocity); int initialVelocityX = (int) velocityTracker.getXVelocity(); if (mScrollingX && Math.abs(initialVelocityX) > mMinimumFlingVelocity) { flingX(initialVelocityX); } else if (mValues != null) { float positionX = event.getX(); if (!mScrollingX) { int itemPos = getPositionOnScreen(positionX); int relativePos = itemPos - mSideItems; if (relativePos == 0) { selectItem(); } else { smoothScrollBy(relativePos); } } else if (mScrollingX) { finishScrolling(); } } mVelocityTracker.recycle(); mVelocityTracker = null; if (mLeftEdgeEffect != null) { mLeftEdgeEffect.onRelease(); mRightEdgeEffect.onRelease(); } case MotionEvent.ACTION_CANCEL: mPressedItem = -1; invalidate(); if (mLeftEdgeEffect != null) { mLeftEdgeEffect.onRelease(); mRightEdgeEffect.onRelease(); } break; } return true; }
From source file:com.me.harris.androidanimations._06_touch.swipelistview.SwipeListViewTouchListener.java
/** * @see View.OnTouchListener#onTouch(View, MotionEvent) *//*from w w w .j a v a 2 s.co m*/ @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (viewWidth < 2) { viewWidth = swipeListView.getWidth(); } switch (motionEvent.getActionMasked()) { case MotionEvent.ACTION_DOWN: { if (paused) { return false; } swipeCurrentAction = SwipeListView.SWIPE_ACTION_NONE; int childCount = swipeListView.getChildCount(); int[] listViewCoords = new int[2]; swipeListView.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 = swipeListView.getChildAt(i); child.getHitRect(rect); if (rect.contains(x, y)) { setParentView(child); setFrontView(child.findViewById(swipeFrontView)); downX = motionEvent.getRawX(); downPosition = swipeListView.getPositionForView(child); frontView.setClickable(!opened.get(downPosition)); frontView.setLongClickable(!opened.get(downPosition)); velocityTracker = VelocityTracker.obtain(); velocityTracker.addMovement(motionEvent); if (swipeBackView > 0) { setBackView(child.findViewById(swipeBackView)); } break; } } view.onTouchEvent(motionEvent); return true; } case MotionEvent.ACTION_UP: { if (velocityTracker == null || !swiping) { break; } float deltaX = motionEvent.getRawX() - downX; velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(velocityTracker.getXVelocity()); if (!opened.get(downPosition)) { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && velocityTracker.getXVelocity() > 0) { velocityX = 0; } if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && velocityTracker.getXVelocity() < 0) { velocityX = 0; } } float velocityY = Math.abs(velocityTracker.getYVelocity()); boolean swap = false; boolean swapRight = false; if (minFlingVelocity <= velocityX && velocityX <= maxFlingVelocity && velocityY < velocityX) { swapRight = velocityTracker.getXVelocity() > 0; if (opened.get(downPosition) && openedRight.get(downPosition) && swapRight) { swap = false; } else if (opened.get(downPosition) && !openedRight.get(downPosition) && !swapRight) { swap = false; } else { swap = true; } } else if (Math.abs(deltaX) > viewWidth / 2) { swap = true; swapRight = deltaX > 0; } generateAnimate(frontView, swap, swapRight, downPosition); velocityTracker.recycle(); velocityTracker = null; downX = 0; // change clickable front view if (swap) { frontView.setClickable(opened.get(downPosition)); frontView.setLongClickable(opened.get(downPosition)); } frontView = null; backView = null; this.downPosition = ListView.INVALID_POSITION; swiping = false; break; } case MotionEvent.ACTION_MOVE: { if (velocityTracker == null || paused) { break; } velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(velocityTracker.getXVelocity()); float velocityY = Math.abs(velocityTracker.getYVelocity()); float deltaX = motionEvent.getRawX() - downX; float deltaMode = Math.abs(deltaX); if (swipeMode == SwipeListView.SWIPE_MODE_NONE) { deltaMode = 0; } else if (swipeMode != SwipeListView.SWIPE_MODE_BOTH) { if (opened.get(downPosition)) { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX < 0) { deltaMode = 0; } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX > 0) { deltaMode = 0; } } else { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX > 0) { deltaMode = 0; } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX < 0) { deltaMode = 0; } } } if (deltaMode > slop && swipeCurrentAction == SwipeListView.SWIPE_ACTION_NONE && velocityY < velocityX) { swiping = true; boolean swipingRight = (deltaX > 0); if (opened.get(downPosition)) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } else { if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_DISMISS) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_DISMISS) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; } else if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_CHECK) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHECK; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_CHECK) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHECK; } else { swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } } swipeListView.requestDisallowInterceptTouchEvent(true); MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); swipeListView.onTouchEvent(cancelEvent); } if (swiping) { if (opened.get(downPosition)) { deltaX += openedRight.get(downPosition) ? viewWidth - rightOffset : -viewWidth + leftOffset; } move(deltaX); return true; } break; } } return false; }