List of usage examples for android.view MotionEvent setAction
public final void setAction(int action)
From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java
private boolean handleMoveEvent(@Nullable final View view, @NonNull final MotionEvent motionEvent) { if (mVelocityTracker == null || mCurrentView == null) { return false; }//from w w w. ja va2 s .c om // ?? ?? ? ? ? mVelocityTracker.addMovement(motionEvent); // ? ? float deltaX = motionEvent.getX() - mDownX; float deltaY = motionEvent.getY() - mDownY; boolean dismissToRight = deltaX < 0; mflingToRight = dismissToRight; // ? ? ?? ?, ?? ? ? ??? ? if (Math.abs(deltaX) > mSlop && Math.abs(deltaX) > Math.abs(deltaY)) { // ? ? ?? if (!mSwiping) { mActiveSwipeCount++; } // ? ?? mSwiping = true; mListViewWrapper.getListView().requestDisallowInterceptTouchEvent(true); /* Cancel ListView's touch (un-highlighting the item) */ if (view != null) { MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT); view.onTouchEvent(cancelEvent); cancelEvent.recycle(); } } // ???? if (mSwiping) { // ? ? if (mCanDismissCurrent) { // ? ?? onStartSwipe(mCurrentView, mCurrentPosition, dismissToRight); // ?? ViewHelper.setTranslationX(mSwipingView, deltaX); // ??? ? . //ViewHelper.setAlpha(mSwipingView, Math.max(mMinimumAlpha, Math.min(1, 1 - 2 * Math.abs(deltaX) / mViewWidth))); if (dismissToRight) { mLeftSwipingView.setVisibility(View.GONE); mRightSwipingView.setVisibility(View.VISIBLE); } else { mLeftSwipingView.setVisibility(View.VISIBLE); mRightSwipingView.setVisibility(View.GONE); } } else { // ? ? ? ViewHelper.setTranslationX(mSwipingView, deltaX * 0.1f); } return true; } return false; }
From source file:net.czlee.debatekeeper.EnableableViewPager.java
@Override public boolean onTouchEvent(MotionEvent event) { boolean execute = false; // Allow for situations where paging becomes enabled or disabled in the middle of a touch. // This can create awkward situations where a gesture starts to be seen in the middle of it // (so appears not to have started) or is cut off (so appears not to have finished). // We catch these out by tracking mPagingEnabled and modifying the action if it appears // to have changed since the last touch event. If paging has just been enabled and it // looks like we're in the middle of an gesture, change it to the beginning of a gesture, // i.e. ACTION_DOWN. If paging has just been disabled, change it to an ACTION_CANCEL so // that the ViewPager will scroll back to the current item. if (mLastPagingEnabled && !mPagingEnabled) { event.setAction(MotionEvent.ACTION_CANCEL); execute = true;/*from w ww.jav a 2 s . c om*/ } else if (!mLastPagingEnabled && mPagingEnabled && event.getAction() == MotionEvent.ACTION_MOVE) { event.setAction(MotionEvent.ACTION_DOWN); execute = true; } else if (mPagingEnabled) { execute = true; } mLastPagingEnabled = mPagingEnabled; if (execute) return super.onTouchEvent(event); else return false; }
From source file:de.timroes.swipetodismiss.SwipeDismissList.java
@Override public boolean onTouch(View view, MotionEvent motionEvent) { if (mViewWidth < 2) { mViewWidth = mListView.getWidth(); }// w ww .ja v a 2 s . co m switch (MotionEventCompat.getActionMasked(motionEvent)) { case MotionEvent.ACTION_DOWN: { if (mPaused || !mEnabled) { return false; } resetSwipeState(); // 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; for (int i = 0; i < childCount; i++) { child = mListView.getChildAt(i); child.getHitRect(rect); if (rect.contains(x, y)) { if (mSwipeLayout != 0) { View swipeView = child.findViewById(mSwipeLayout); if (swipeView != null) { mDownView = swipeView; break; } } mDownView = child; break; } } if (mDownView != null) { mDownX = motionEvent.getRawX(); mDownY = motionEvent.getRawY(); mDownPosition = mListView.getPositionForView(mDownView); mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(motionEvent); } view.onTouchEvent(motionEvent); return true; } case MotionEvent.ACTION_UP: { if (mVelocityTracker == null) { break; } float deltaX = motionEvent.getRawX() - mDownX; mVelocityTracker.addMovement(motionEvent); mVelocityTracker.computeCurrentVelocity(1000); 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 <= velocityX && velocityX <= mMaxFlingVelocity && velocityY < velocityX && mSwiping && isDirectionValid(mVelocityTracker.getXVelocity()) && deltaX >= mViewWidth * 0.2f) { dismiss = true; dismissRight = mVelocityTracker.getXVelocity() > 0; } if (dismiss) { // dismiss final View downView = mDownView; // mDownView gets null'd before animation ends final int downPosition = mDownPosition; ++mDismissAnimationRefCount; mPaused = true; animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0) .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { performDismiss(downView, downPosition); } }); } else { // cancel animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null); } resetSwipeState(); break; } case MotionEvent.ACTION_MOVE: { if (mUndoPopup.isShowing()) { // Send a delayed message to hide popup mHandler.sendMessageDelayed(mHandler.obtainMessage(mDelayedMsgId), mAutoHideDelay); } if (mVelocityTracker == null || mPaused || !mEnabled) { break; } mVelocityTracker.addMovement(motionEvent); float deltaX = motionEvent.getRawX() - mDownX; float deltaY = motionEvent.getRawY() - mDownY; // Only start swipe in correct direction if (isDirectionValid(deltaX)) { if (Math.abs(deltaX) > mSlop && Math.abs(deltaX) > Math.abs(deltaY)) { mSwiping = true; mListView.requestDisallowInterceptTouchEvent(true); // Cancel ListView's touch (un-highlighting the item) MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat .getActionIndex(motionEvent) << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); mListView.onTouchEvent(cancelEvent); cancelEvent.recycle(); } } else { // If we swiped into wrong direction, act like this was the new // touch down point mDownX = motionEvent.getRawX(); deltaX = 0; } if (mSwiping) { 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:am.widget.scalerecyclerview.ScaleRecyclerView.java
@SuppressLint("ClickableViewAccessibility") @Override//from w w w . j ava 2 s . c o m public boolean onTouchEvent(MotionEvent e) { if (!mScaleEnable) return super.onTouchEvent(e); boolean superResult = false; // if (e.getPointerCount() >= 2) { // if (!mScaleBegin) { // ACTION_UP final int action = e.getAction(); e.setAction(MotionEvent.ACTION_UP); setForceInterceptDispatchOnScrollStateChanged(true); superResult = super.onTouchEvent(e); setForceInterceptDispatchOnScrollStateChanged(false); e.setAction(action); mScaleBegin = true; } superResult = mScaleGestureDetector.onTouchEvent(e) || superResult; } else { // ? final int action = e.getAction(); boolean dispatch = false; if (action == MotionEvent.ACTION_UP && getScrollState() == SCROLL_STATE_IDLE) { dispatch = true; } if (mScaleBegin) { mScaleBegin = false; // ?ACTION_DOWN e.setAction(MotionEvent.ACTION_DOWN); super.onInterceptTouchEvent(e); e.setAction(action); } superResult = super.onTouchEvent(e); if (dispatch) { dispatchOnScrollStateChanged(SCROLL_STATE_IDLE); } } return superResult; }
From source file:net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.java
@Override public boolean onTouch(View view, MotionEvent ev) { if (mViewWidth < 2) { mViewWidth = mListView.getWidth(); }// ww w . j a v a2 s . c o m switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: { if (mSwipePaused) { return false; } // 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) ev.getRawX() - listViewCoords[0]; int y = (int) ev.getRawY() - listViewCoords[1]; View child; for (int i = mListView.getHeaderViewsCount(); i < childCount; i++) { child = mListView.getChildAt(i); if (child != null) { child.getHitRect(rect); if (rect.contains(x, y)) { // if a specific swiping layout has been giving, use this to swipe. if (mSwipingLayout > 0) { View swipingView = child.findViewById(mSwipingLayout); if (swipingView != null) { mSwipeDownView = swipingView; mSwipeDownChild = child; break; } } // If no swiping layout has been found, swipe the whole child mSwipeDownView = mSwipeDownChild = child; break; } } } if (mSwipeDownView != null) { // test if the item should be swiped int position = mListView.getPositionForView(mSwipeDownView) - mListView.getHeaderViewsCount(); if (mCallbacks == null || mCallbacks.canDismiss(position)) { mDownX = ev.getRawX(); mDownY = ev.getRawY(); mDownPosition = position; mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(ev); } else { // set back to null to revert swiping mSwipeDownView = mSwipeDownChild = null; } } return false; } case MotionEvent.ACTION_CANCEL: { if (mVelocityTracker == null) { break; } if (mSwipeDownView != null && mSwiping) { // cancel ViewCompat.animate(mSwipeDownView).translationX(0).alpha(1).setDuration(mAnimationTime) .setListener(null); } mVelocityTracker.recycle(); mVelocityTracker = null; mDownX = 0; mDownY = 0; mSwipeDownView = mSwipeDownChild = null; mDownPosition = ListView.INVALID_POSITION; mSwiping = false; break; } case MotionEvent.ACTION_UP: { if (mVelocityTracker == null) { break; } float deltaX = ev.getRawX() - mDownX; mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); 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 <= velocityX && velocityX <= mMaxFlingVelocity && velocityY < velocityX && mSwiping && isSwipeDirectionValid(mVelocityTracker.getXVelocity()) && deltaX >= mViewWidth * 0.2f) { dismiss = true; dismissRight = mVelocityTracker.getXVelocity() > 0; } if (dismiss) { // dismiss slideOutView(mSwipeDownView, mSwipeDownChild, mDownPosition, dismissRight); } else if (mSwiping) { // Swipe back to regular position ViewCompat.animate(mSwipeDownView).translationX(0).alpha(1).setDuration(mAnimationTime) .setListener(null); } mVelocityTracker = null; mDownX = 0; mDownY = 0; mSwipeDownView = null; mSwipeDownChild = null; mDownPosition = AbsListView.INVALID_POSITION; mSwiping = false; break; } case MotionEvent.ACTION_MOVE: { if (mVelocityTracker == null || mSwipePaused) { break; } mVelocityTracker.addMovement(ev); float deltaX = ev.getRawX() - mDownX; float deltaY = ev.getRawY() - mDownY; // Only start swipe in correct direction if (isSwipeDirectionValid(deltaX)) { ViewParent parent = mListView.getParent(); if (parent != null) { // If we swipe don't allow parent to intercept touch (e.g. like NavigationDrawer does) // otherwise swipe would not be working. parent.requestDisallowInterceptTouchEvent(true); } if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) { mSwiping = true; mListView.requestDisallowInterceptTouchEvent(true); // Cancel ListView's touch (un-highlighting the item) MotionEvent cancelEvent = MotionEvent.obtain(ev); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (ev.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); mListView.onTouchEvent(cancelEvent); } } else { // If we swiped into wrong direction, act like this was the new // touch down point mDownX = ev.getRawX(); deltaX = 0; } if (mSwiping) { ViewCompat.setTranslationX(mSwipeDownView, deltaX); ViewCompat.setAlpha(mSwipeDownView, Math.max(0f, 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); mWebView.onTouchEvent(newEvent);//w w w . j a va 2 s . co m 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:android.support.v7.widget.SwitchCompat.java
private void cancelSuperTouch(MotionEvent ev) { MotionEvent cancel = MotionEvent.obtain(ev); cancel.setAction(MotionEvent.ACTION_CANCEL); super.onTouchEvent(cancel); cancel.recycle();/* w ww . j a va 2 s . c om*/ }
From source file:com.llf.nestlayout.library.NestedWebView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isNestedScrollingEnabled()) return super.onTouchEvent(event); boolean rs = false; final int action = MotionEventCompat.getActionMasked(event); if (action == MotionEvent.ACTION_DOWN) { mNestedOffsetY = 0;// w w w .j ava 2 s . c o m super.onTouchEvent(event); } MotionEvent ne = MotionEvent.obtain(event); switch (action) { case MotionEvent.ACTION_DOWN: rs = super.onTouchEvent(ne); startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); mTouchCancel = false; mLastX = (int) event.getX(); mLastY = (int) event.getY(); mTouchY = mLastY; break; case MotionEvent.ACTION_MOVE: final int y = (int) event.getY(); if (Math.abs(mTouchY - y) >= mTouchSlop) { //cancel click,Long click if (!mTouchCancel) { mTouchCancel = true; event.setAction(MotionEvent.ACTION_CANCEL); super.onTouchEvent(event); } int x = (int) event.getX(); int dx = mLastX - x; int dy = mLastY - y; int oldY = getScrollY(); if (dispatchNestedPreScroll(0, dy, mScrollConsumed, mScrollOffset)) { dy -= mScrollConsumed[1]; mNestedOffsetY += mScrollOffset[1]; } // overScrollBy(dx, dy, getScrollX(), oldY, computeHorizontalScrollRange(), computeVerticalScrollRange(), computeHorizontalScrollExtent(), computeVerticalScrollExtent(), true); mLastX = x; mLastY = y - mScrollOffset[1]; int scrollDelta = getScrollY() - oldY; dy -= scrollDelta; if (dispatchNestedScroll(0, scrollDelta, 0, dy, mScrollOffset)) { mNestedOffsetY += mScrollOffset[1]; mLastY -= mScrollOffset[1]; } rs = true; } else { rs = super.onTouchEvent(event); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (!mTouchCancel) rs = super.onTouchEvent(ne); stopNestedScroll(); break; } return rs; }
From source file:com.agitive.usembassy.libraries.SwipeListView.SwipeListViewTouchListener.java
/** * @see View.OnTouchListener#onTouch(android.view.View, android.view.MotionEvent) *///w w w .ja v a2 s. c o m @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (!isSwipeEnabled()) { return false; } if (viewWidth < 2) { viewWidth = swipeListView.getWidth(); } switch (MotionEventCompat.getActionMasked(motionEvent)) { case MotionEvent.ACTION_DOWN: { if (paused && downPosition != ListView.INVALID_POSITION) { 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); int childPosition = swipeListView.getPositionForView(child); // dont allow swiping if this is on the header or footer or IGNORE_ITEM_VIEW_TYPE or enabled is false on the adapter boolean allowSwipe = swipeListView.getAdapter().isEnabled(childPosition) && swipeListView.getAdapter().getItemViewType(childPosition) >= 0; if (allowSwipe && rect.contains(x, y)) { setParentView(child); setFrontView(child.findViewById(swipeFrontView)); downX = motionEvent.getRawX(); downPosition = childPosition; 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 || downPosition == ListView.INVALID_POSITION) { 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 * 2 < velocityX) { swapRight = velocityTracker.getXVelocity() > 0; if (swapRight != swipingRight && swipeActionLeft != swipeActionRight) { swap = false; } else 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); if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { swapChoiceState(downPosition); } velocityTracker.recycle(); velocityTracker = null; downX = 0; // change clickable front view // if (swap) { // frontView.setClickable(opened.get(downPosition)); // frontView.setLongClickable(opened.get(downPosition)); // } swiping = false; break; } case MotionEvent.ACTION_MOVE: { if (velocityTracker == null || paused || downPosition == ListView.INVALID_POSITION) { 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); int swipeMode = this.swipeMode; int changeSwipeMode = swipeListView.changeSwipeMode(downPosition); if (changeSwipeMode >= 0) { swipeMode = changeSwipeMode; } 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; swipingRight = (deltaX > 0); if (opened.get(downPosition)) { swipeListView.onStartClose(downPosition, swipingRight); 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_CHOICE) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_CHOICE) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; } else { swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } swipeListView.onStartOpen(downPosition, swipeCurrentAction, swipingRight); } swipeListView.requestDisallowInterceptTouchEvent(true); MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT)); swipeListView.onTouchEvent(cancelEvent); if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { backView.setVisibility(View.GONE); } } if (swiping && downPosition != ListView.INVALID_POSITION) { if (opened.get(downPosition)) { deltaX += openedRight.get(downPosition) ? viewWidth - rightOffset : -viewWidth + leftOffset; } move(deltaX); return true; } break; } } return false; }
From source file:SwipeListViewTouchListener.java
/** * @see View.OnTouchListener#onTouch(android.view.View, android.view.MotionEvent) *//*from ww w . ja v a 2 s. co m*/ @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (!isSwipeEnabled()) { return false; } if (viewWidth < 2) { viewWidth = swipeListView.getWidth(); } switch (MotionEventCompat.getActionMasked(motionEvent)) { case MotionEvent.ACTION_DOWN: { if (paused && downPosition != ListView.INVALID_POSITION) { 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); int childPosition = swipeListView.getPositionForView(child); // dont allow swiping if this is on the header or footer or IGNORE_ITEM_VIEW_TYPE or enabled is false on the adapter boolean allowSwipe = swipeListView.getAdapter().isEnabled(childPosition) && swipeListView.getAdapter().getItemViewType(childPosition) >= 0; if (allowSwipe && rect.contains(x, y)) { setParentView(child); setFrontView(child.findViewById(swipeFrontView)); downX = motionEvent.getRawX(); downPosition = childPosition; 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 || downPosition == ListView.INVALID_POSITION) { 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 * 2 < velocityX) { swapRight = velocityTracker.getXVelocity() > 0; Log.d("SwipeListView", "swapRight: " + swapRight + " - swipingRight: " + swipingRight); if (swapRight != swipingRight && swipeActionLeft != swipeActionRight) { swap = false; } else 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); if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { swapChoiceState(downPosition); } velocityTracker.recycle(); velocityTracker = null; downX = 0; // change clickable front view // if (swap) { // frontView.setClickable(opened.get(downPosition)); // frontView.setLongClickable(opened.get(downPosition)); // } swiping = false; break; } case MotionEvent.ACTION_MOVE: { if (velocityTracker == null || paused || downPosition == ListView.INVALID_POSITION) { 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); int swipeMode = this.swipeMode; int changeSwipeMode = swipeListView.changeSwipeMode(downPosition); if (changeSwipeMode >= 0) { swipeMode = changeSwipeMode; } 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; swipingRight = (deltaX > 0); Log.d("SwipeListView", "deltaX: " + deltaX + " - swipingRight: " + swipingRight); if (opened.get(downPosition)) { swipeListView.onStartClose(downPosition, swipingRight); 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_CHOICE) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_CHOICE) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; } else { swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } swipeListView.onStartOpen(downPosition, swipeCurrentAction, swipingRight); } swipeListView.requestDisallowInterceptTouchEvent(true); MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT)); swipeListView.onTouchEvent(cancelEvent); if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { backView.setVisibility(View.GONE); } } if (swiping && downPosition != ListView.INVALID_POSITION) { if (opened.get(downPosition)) { deltaX += openedRight.get(downPosition) ? viewWidth - rightOffset : -viewWidth + leftOffset; } move(deltaX); return true; } break; } } return false; }