boolean checkSelectForSwipe ( int action , MotionEvent motionEvent , int pointerIndex ) { if ( mSelected != null || action != MotionEvent . ACTION_MOVE || mActionState == ACTION_STATE_DRAG || ! mCallback . isItemViewSwipeEnabled ( ) ) { return false ; } if ( mRecyclerView . getScrollState ( ) == RecyclerView . SCROLL_STATE_DRAGGING ) { return false ; } final ViewHolder vh = findSwipedView ( motionEvent ) ; if ( vh == null ) { return false ; } final int movementFlags = mCallback . getAbsoluteMovementFlags ( mRecyclerView , vh ) ; final int swipeFlags = ( movementFlags & ACTION_MODE_SWIPE_MASK ) >> ( DIRECTION_FLAG_COUNT * ACTION_STATE_SWIPE ) ; if ( swipeFlags == 0 ) { return false ; } // mDx and mDy are only set in allowed directions. We use custom x/y here instead of // updateDxDy to avoid swiping if user moves more in the other direction final float x = motionEvent . getX ( pointerIndex ) ; final float y = motionEvent . getY ( pointerIndex ) ; // Calculate the distance moved final float dx = x - mInitialTouchX ; final float dy = y - mInitialTouchY ; // swipe target is chose w/o applying flags so it does not really check if swiping in that // direction is allowed. This why here, we use mDx mDy to check slope value again. final float absDx = Math . abs ( dx ) ; final float absDy = Math . abs ( dy ) ; if ( absDx < mSlop && absDy < mSlop ) { return false ; } if ( absDx > absDy ) { if ( dx < 0 && ( swipeFlags & LEFT ) == 0 ) { return false ; } if ( dx > 0 && ( swipeFlags & RIGHT ) == 0 ) { return false ; } } else { if ( dy < 0 && ( swipeFlags & UP ) == 0 ) { return false ; } if ( dy > 0 && ( swipeFlags & DOWN ) == 0 ) { return false ; } } mDx = mDy = 0f ; mActivePointerId = motionEvent . getPointerId ( 0 ) ; select ( vh , ACTION_STATE_SWIPE ) ; return true ; }
Checks whether we should select a View for swiping .