private void handleActionDown(@NonNull RecyclerView rv, @NonNull MotionEvent e) { final RecyclerView.ViewHolder holder = CustomRecyclerViewUtils.findChildViewHolderUnderWithTranslation(rv, e.getX(), e.getY()); mInitialTouchX = (int) (e.getX() + 0.5f); mInitialTouchY = (int) (e.getY() + 0.5f); if (holder instanceof ExpandableItemViewHolder) { mTouchedItemId = holder.getItemId(); } else { mTouchedItemId = RecyclerView.NO_ID; } }
public DraggingItemInfo(RecyclerView rv, RecyclerView.ViewHolder vh, int touchX, int touchY) { width = vh.itemView.getWidth(); height = vh.itemView.getHeight(); id = vh.getItemId(); initialItemLeft = vh.itemView.getLeft(); initialItemTop = vh.itemView.getTop(); grabbedPositionX = touchX - initialItemLeft; grabbedPositionY = touchY - initialItemTop; margins = new Rect(); CustomRecyclerViewUtils.getLayoutMargins(vh.itemView, margins); spanSize = CustomRecyclerViewUtils.getSpanSize(vh); }
/*package*/ void startDraggingItem(DraggingItemInfo draggingItemInfo, RecyclerView.ViewHolder holder, ItemDraggableRange range, int wrappedItemPosition, int itemMoveMode) { if (LOCAL_LOGD) { Log.d(TAG, "onDragItemStarted(holder = " + holder + ")"); } if (DEBUG_BYPASS_MOVE_OPERATION_MODE) { return; } if (holder.getItemId() == RecyclerView.NO_ID) { throw new IllegalStateException("dragging target must provides valid ID"); } mDraggableItemAdapter = WrapperAdapterUtils.findWrappedAdapter(this, DraggableItemAdapter.class, wrappedItemPosition); if (mDraggableItemAdapter == null) { throw new IllegalStateException("DraggableItemAdapter not found!"); } mDraggingItemInitialPosition = mDraggingItemCurrentPosition = wrappedItemPosition; mDraggingItemInfo = draggingItemInfo; mDraggingItemViewHolder = holder; mDraggableRange = range; mItemMoveMode = itemMoveMode; }
@Override public void onSwiped(RecyclerView.ViewHolder holder, int swipeDir) { Uri uri = ContentUris.withAppendedId(HistoryProvider.Columns.CONTENT_URI, holder.getItemId()); ContentValues values = null; Cursor cursor = mResolver.query(uri, null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { values = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, values); } cursor.close(); } mResolver.delete(uri, null, null); if (values != null && mDeleteListener != null) { mDeleteListener.onItemDeleted(values); } }
@Override public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) { DataHelper.deleteItemAsync(realm, viewHolder.getItemId()); }
if (holder == null || holder.getItemId() != mCheckingTouchSlop) { mCheckingTouchSlop = RecyclerView.NO_ID; return false;
fc.draggingItem.getItemId() == fc.draggingItemInfo.id)) {
if (!((holder != null) && (holder.getItemId() == touchedItemId))) { return false;
int flags = Constants.STATE_FLAG_SWIPING; if (holder.getItemId() == mSwipingItemId) { flags |= Constants.STATE_FLAG_IS_ACTIVE;
private boolean handleActionDown(RecyclerView rv, MotionEvent e) { final RecyclerView.ViewHolder holder = CustomRecyclerViewUtils.findChildViewHolderUnderWithoutTranslation(rv, e.getX(), e.getY()); if (!checkTouchedItemState(rv, holder)) { return false; } final int touchX = (int) (e.getX() + 0.5f); final int touchY = (int) (e.getY() + 0.5f); if (!canStartDrag(holder, touchX, touchY)) { return false; } final int orientation = CustomRecyclerViewUtils.getOrientation(mRecyclerView); final int spanCount = CustomRecyclerViewUtils.getSpanCount(mRecyclerView); mInitialTouchX = mLastTouchX = touchX; mInitialTouchY = mLastTouchY = touchY; mInitialTouchItemId = holder.getItemId(); mCanDragH = (orientation == CustomRecyclerViewUtils.ORIENTATION_HORIZONTAL) || ((orientation == CustomRecyclerViewUtils.ORIENTATION_VERTICAL) && (spanCount > 1)); mCanDragV = (orientation == CustomRecyclerViewUtils.ORIENTATION_VERTICAL) || ((orientation == CustomRecyclerViewUtils.ORIENTATION_HORIZONTAL) && (spanCount > 1)); boolean handled; if (mInitiateOnTouch) { handled = checkConditionAndStartDragging(rv, e, false); } else if (mInitiateOnLongPress) { mHandler.startLongPressDetection(e, mLongPressTimeout); handled = false; } else { handled = false; } return handled; }
@Override public void onBindViewHolder(@NonNull VH holder, int position, @NonNull List<Object> payloads) { if (isDragging()) { final long draggingItemId = mDraggingItemInfo.id; final long itemId = holder.getItemId(); final int origPosition = convertToOriginalPosition( position, mDraggingItemInitialPosition, mDraggingItemCurrentPosition, mItemMoveMode); if (itemId == draggingItemId && holder != mDraggingItemViewHolder) { if (LOCAL_LOGI) { Log.i(TAG, "a new view holder object for the currently dragging item is assigned"); } mDraggingItemViewHolder = holder; mDragDropManager.onNewDraggingItemViewBound(holder); } int flags = Constants.STATE_FLAG_DRAGGING; if (itemId == draggingItemId) { flags |= Constants.STATE_FLAG_IS_ACTIVE; } if (mDraggableRange.checkInRange(position)) { flags |= Constants.STATE_FLAG_IS_IN_RANGE; } safeUpdateFlags(holder, flags); super.onBindViewHolder(holder, origPosition, payloads); } else { safeUpdateFlags(holder, 0); super.onBindViewHolder(holder, position, payloads); } }
@Override public void onViewRecycled(@NonNull VH holder, int viewType) { super.onViewRecycled(holder, viewType); if ((mSwipingItemId != RecyclerView.NO_ID) && (mSwipingItemId == holder.getItemId())) { mSwipeManager.cancelSwipe(); } // reset SwipeableItemViewHolder state if (holder instanceof SwipeableItemViewHolder) { if (mSwipeManager != null) { mSwipeManager.cancelPendingAnimations(holder); } SwipeableItemViewHolder swipeableHolder = (SwipeableItemViewHolder) holder; // reset result and reaction (#262) swipeableHolder.setSwipeResult(SwipeableItemConstants.RESULT_NONE); swipeableHolder.setAfterSwipeReaction(SwipeableItemConstants.AFTER_SWIPE_REACTION_DEFAULT); swipeableHolder.setSwipeItemHorizontalSlideAmount(0); swipeableHolder.setSwipeItemVerticalSlideAmount(0); swipeableHolder.setProportionalSwipeAmountModeEnabled(true); View containerView = SwipeableViewHolderUtils.getSwipeableContainerView(swipeableHolder); if (containerView != null) { ViewCompat.animate(containerView).cancel(); containerView.setTranslationX(0.0f); containerView.setTranslationY(0.0f); } } }
@Override public boolean animateChange( RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY) { if (oldHolder == newHolder) { // NOTE: This condition can be occurred since v23.1.0. // Don't know how to run change animations when the same view holder is re-used. // run a move animation to handle position changes. return mMoveAnimationsManager.addPendingAnimation(oldHolder, fromX, fromY, toX, toY); } if (mDebug) { final String oldId = (oldHolder != null) ? Long.toString(oldHolder.getItemId()) : "-"; final String oldPosition = (oldHolder != null) ? Long.toString(oldHolder.getLayoutPosition()) : "-"; final String newId = (newHolder != null) ? Long.toString(newHolder.getItemId()) : "-"; final String newPosition = (newHolder != null) ? Long.toString(newHolder.getLayoutPosition()) : "-"; Log.d(TAG, "animateChange(old.id = " + oldId + ", old.position = " + oldPosition + ", new.id = " + newId + ", new.position = " + newPosition + ", fromX = " + fromX + ", fromY = " + fromY + ", toX = " + toX + ", toY = " + toY + ")"); } return mChangeAnimationsManager.addPendingAnimation(oldHolder, newHolder, fromX, fromY, toX, toY); }
@Override public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { final RecyclerView.ViewHolder draggingItem = mDraggingItemViewHolder; final RecyclerView.ViewHolder swapTargetItem = mSwapTargetItem; if (draggingItem == null || swapTargetItem == null || draggingItem.getItemId() != mDraggingItemInfo.id) { return; } mReqTranslationPhase = calculateTranslationPhase(draggingItem, swapTargetItem); if (mSwapTargetItemChanged) { mSwapTargetItemChanged = false; mCurTranslationPhase = mReqTranslationPhase; } else { // interpolate to make it moves smoothly mCurTranslationPhase = calculateCurrentTranslationPhase(mCurTranslationPhase, mReqTranslationPhase); } updateSwapTargetTranslation(draggingItem, swapTargetItem, mCurTranslationPhase); }
@Override public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { final long elapsedTime = getElapsedTime(mStartTime); final float scale = determineBackgroundScaleSwipeCompletedSuccessfully(elapsedTime); fillSwipingItemBackground(c, mSwipeBackgroundDrawable, scale); if (mSwipingItemId == mSwipingItem.getItemId()) { mTranslationX = (int) (mSwipingItem.itemView.getTranslationX() + 0.5f); mTranslationY = (int) (mSwipingItem.itemView.getTranslationY() + 0.5f); } if (requiresContinuousAnimationAfterSwipeCompletedSuccessfully(elapsedTime)) { postInvalidateOnAnimation(); } }
@Override public boolean animateAdd(final RecyclerView.ViewHolder holder) { if (mDebug) { Log.d(TAG, "animateAdd(id = " + holder.getItemId() + ", position = " + holder.getLayoutPosition() + ")"); } return mAddAnimationsManager.addPendingAnimation(holder); }
@Override public boolean animateMove(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) { if (mDebug) { Log.d(TAG, "animateMove(id = " + holder.getItemId() + ", position = " + holder.getLayoutPosition() + ", fromX = " + fromX + ", fromY = " + fromY + ", toX = " + toX + ", toY = " + toY + ")"); } return mMoveAnimationsManager.addPendingAnimation(holder, fromX, fromY, toX, toY); }
@Override public boolean animateRemove(final RecyclerView.ViewHolder holder) { if (mDebug) { Log.d(TAG, "animateRemove(id = " + holder.getItemId() + ", position = " + holder.getLayoutPosition() + ")"); } return mRemoveAnimationManager.addPendingAnimation(holder); }
public RemovingItemDecorator(RecyclerView rv, RecyclerView.ViewHolder swipingItem, int result, long removeAnimationDuration, long moveAnimationDuration) { mRecyclerView = rv; mSwipingItem = swipingItem; mSwipingItemId = swipingItem.getItemId(); mHorizontal = (result == RecyclerViewSwipeManager.RESULT_SWIPED_LEFT || result == RecyclerViewSwipeManager.RESULT_SWIPED_RIGHT); mRemoveAnimationDuration = removeAnimationDuration + ADDITIONAL_REMOVE_DURATION; mMoveAnimationDuration = moveAnimationDuration; mTranslationX = (int) (swipingItem.itemView.getTranslationX() + 0.5f); mTranslationY = (int) (swipingItem.itemView.getTranslationY() + 0.5f); CustomRecyclerViewUtils.getViewBounds(mSwipingItem.itemView, mSwipingItemBounds); }