Java Code Examples for androidx.recyclerview.widget.ItemTouchHelper#ACTION_STATE_DRAG
The following examples show how to use
androidx.recyclerview.widget.ItemTouchHelper#ACTION_STATE_DRAG .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DragAndSwipeCallback.java From DoraemonKit with Apache License 2.0 | 6 votes |
@Override public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) { if (actionState == ItemTouchHelper.ACTION_STATE_DRAG && !isViewCreateByAdapter(viewHolder)) { if (mDraggableModule != null) { mDraggableModule.onItemDragStart(viewHolder); } viewHolder.itemView.setTag(R.id.dokit_baseQuickAdapter_dragging_support, true); } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && !isViewCreateByAdapter(viewHolder)) { if (mDraggableModule != null) { mDraggableModule.onItemSwipeStart(viewHolder); } viewHolder.itemView.setTag(R.id.dokit_baseQuickAdapter_swiping_support, true); } super.onSelectedChanged(viewHolder, actionState); }
Example 2
Source File: DragAndSwipeCallback.java From DoraemonKit with Apache License 2.0 | 6 votes |
@Override public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) { if (actionState == ItemTouchHelper.ACTION_STATE_DRAG && !isViewCreateByAdapter(viewHolder)) { if (mDraggableModule != null) { mDraggableModule.onItemDragStart(viewHolder); } viewHolder.itemView.setTag(R.id.dokit_baseQuickAdapter_dragging_support, true); } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && !isViewCreateByAdapter(viewHolder)) { if (mDraggableModule != null) { mDraggableModule.onItemSwipeStart(viewHolder); } viewHolder.itemView.setTag(R.id.dokit_baseQuickAdapter_swiping_support, true); } super.onSelectedChanged(viewHolder, actionState); }
Example 3
Source File: DragAndSwipeCallback.java From BaseRecyclerViewAdapterHelper with MIT License | 6 votes |
@Override public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) { if (actionState == ItemTouchHelper.ACTION_STATE_DRAG && !isViewCreateByAdapter(viewHolder)) { if (mDraggableModule != null) { mDraggableModule.onItemDragStart(viewHolder); } viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true); } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && !isViewCreateByAdapter(viewHolder)) { if (mDraggableModule != null) { mDraggableModule.onItemSwipeStart(viewHolder); } viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true); } super.onSelectedChanged(viewHolder, actionState); }
Example 4
Source File: LocationTouchCallback.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); switch (actionState) { case ItemTouchHelper.ACTION_STATE_SWIPE: ((LocationHolder) viewHolder).drawSwipe(activity, dX); break; case ItemTouchHelper.ACTION_STATE_DRAG: ((LocationHolder) viewHolder).drawDrag(activity, dY != 0); break; case ItemTouchHelper.ACTION_STATE_IDLE: break; } }
Example 5
Source File: CardDisplayManageActivity.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); switch (actionState) { case ItemTouchHelper.ACTION_STATE_SWIPE: ((CardDisplayAdapter.ViewHolder) viewHolder) .drawSwipe(dX); break; case ItemTouchHelper.ACTION_STATE_DRAG: ((CardDisplayAdapter.ViewHolder) viewHolder) .drawDrag(CardDisplayManageActivity.this, dY != 0); break; case ItemTouchHelper.ACTION_STATE_IDLE: ((CardDisplayAdapter.ViewHolder) viewHolder) .drawSwipe(0) .drawDrag(CardDisplayManageActivity.this, false); break; } }
Example 6
Source File: DailyTrendDisplayManageActivity.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); switch (actionState) { case ItemTouchHelper.ACTION_STATE_SWIPE: ((DailyTrendDisplayAdapter.ViewHolder) viewHolder).drawSwipe(dX); break; case ItemTouchHelper.ACTION_STATE_DRAG: ((DailyTrendDisplayAdapter.ViewHolder) viewHolder) .drawDrag(DailyTrendDisplayManageActivity.this, dY != 0); break; case ItemTouchHelper.ACTION_STATE_IDLE: ((DailyTrendDisplayAdapter.ViewHolder) viewHolder) .drawSwipe(0) .drawDrag(DailyTrendDisplayManageActivity.this, false); break; } }
Example 7
Source File: FlexibleViewHolder.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
/** * Here we handle the event of when the ItemTouchHelper has completed the move or swipe. * <p>In this implementation, View activation is automatically handled.</p> * In case of Drag, the state will be cleared depends by current selection mode! * * @param position the position of the item released * @see #shouldActivateViewWhileSwiping() * @see #shouldAddSelectionInActionMode() * @since 5.0.0-b1 */ @Override @CallSuper public void onItemReleased(int position) { Log.v("onItemReleased position=%s mode=%s actionState=%s", position, LayoutUtils.getModeName(mAdapter.getMode()), (mActionState == ItemTouchHelper.ACTION_STATE_SWIPE ? "Swipe(1)" : "Drag(2)")); // Be sure to keep selection if MULTI and shouldAddSelectionInActionMode is active if (!alreadySelected) { if (shouldAddSelectionInActionMode() && mAdapter.getMode() == Mode.MULTI) { Log.v("onLongClick for ActionMode on position %s mode=%s", position, mAdapter.getMode()); if (mAdapter.mItemLongClickListener != null) { mAdapter.mItemLongClickListener.onItemLongClick(position); } if (mAdapter.isSelected(position)) { toggleActivation(); } } else if (shouldActivateViewWhileSwiping() && getContentView().isActivated()) { mAdapter.toggleSelection(position); toggleActivation(); } else if (mActionState == ItemTouchHelper.ACTION_STATE_DRAG) { mAdapter.toggleSelection(position); if (getContentView().isActivated()) { toggleActivation(); } } } // Reset internal action state ready for next action mLongClickSkipped = false; mActionState = ItemTouchHelper.ACTION_STATE_IDLE; }
Example 8
Source File: ItemTouchCallback.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void onSelectedChanged(@Nullable RecyclerView.ViewHolder viewHolder, int actionState) { super.onSelectedChanged(viewHolder, actionState); final boolean swiping = actionState == ItemTouchHelper.ACTION_STATE_DRAG; if (swipeRefreshLayout != null) { swipeRefreshLayout.setEnabled(!swiping); } if (viewPager != null) { viewPager.requestDisallowInterceptTouchEvent(swiping); } }
Example 9
Source File: FlexibleViewHolder.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
/** * Here we handle the event of when the {@code ItemTouchHelper} first registers an item * as being moved or swiped. * <p>In this implementation, View activation is automatically handled if dragged: The Item * will be added to the selection list if not selected yet and mode MULTI is activated.</p> * * @param position the position of the item touched * @param actionState one of {@link ItemTouchHelper#ACTION_STATE_SWIPE} or * {@link ItemTouchHelper#ACTION_STATE_DRAG}. * @see #shouldActivateViewWhileSwiping() * @see #shouldAddSelectionInActionMode() * @since 5.0.0-b1 */ @Override @CallSuper public void onActionStateChanged(int position, int actionState) { mActionState = actionState; alreadySelected = mAdapter.isSelected(position); Log.v("onActionStateChanged position=%s mode=%s actionState=%s", position, LayoutUtils.getModeName(mAdapter.getMode()), (actionState == ItemTouchHelper.ACTION_STATE_SWIPE ? "Swipe(1)" : "Drag(2)")); if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) { if (!alreadySelected) { // Be sure, if MULTI is active, to add this item to the selection list (call listener!) // Also be sure user consumes the long click event if not done in onLongClick. // Drag by LongPress or Drag by handleView if (mLongClickSkipped || mAdapter.getMode() == Mode.MULTI) { // Next check, allows to initiate the ActionMode and to add selection if configured if ((shouldAddSelectionInActionMode() || mAdapter.getMode() != Mode.MULTI) && mAdapter.mItemLongClickListener != null && mAdapter.isSelectable(position)) { Log.v("onLongClick on position %s mode=%s", position, mAdapter.getMode()); mAdapter.mItemLongClickListener.onItemLongClick(position); alreadySelected = true; // Keep selection on release! } } // If still not selected, be sure current item appears selected for the Drag transition if (!alreadySelected) { mAdapter.toggleSelection(position); } } // Now toggle the activation, Activate view and make selection visible only if necessary if (!getContentView().isActivated()) { toggleActivation(); } } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && shouldActivateViewWhileSwiping() && !alreadySelected) { mAdapter.toggleSelection(position); toggleActivation(); } }
Example 10
Source File: ItemDragAndSwipeCallback.java From BaseProject with Apache License 2.0 | 5 votes |
@Override public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) { if (actionState == ItemTouchHelper.ACTION_STATE_DRAG && !isViewCreateByAdapter(viewHolder)) { mAdapter.onItemDragStart(viewHolder); viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true); } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && !isViewCreateByAdapter(viewHolder)) { mAdapter.onItemSwipeStart(viewHolder); viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true); } super.onSelectedChanged(viewHolder, actionState); }
Example 11
Source File: CardListDemoFragment.java From material-components-android with Apache License 2.0 | 5 votes |
@Override public void onSelectedChanged(@Nullable ViewHolder viewHolder, int actionState) { super.onSelectedChanged(viewHolder, actionState); if (actionState == ItemTouchHelper.ACTION_STATE_DRAG && viewHolder != null) { dragCardView = (MaterialCardView) viewHolder.itemView; dragCardView.setDragged(true); } else if (actionState == ItemTouchHelper.ACTION_STATE_IDLE && dragCardView != null) { dragCardView.setDragged(false); dragCardView = null; } }
Example 12
Source File: EpoxyModelTouchCallback.java From epoxy with Apache License 2.0 | 5 votes |
@Override protected void onSelectedChanged(@Nullable EpoxyViewHolder viewHolder, int actionState) { super.onSelectedChanged(viewHolder, actionState); if (viewHolder != null) { EpoxyModel<?> model = viewHolder.getModel(); if (!isTouchableModel(model)) { throw new IllegalStateException( "A model was selected that is not a valid target: " + model.getClass()); } markRecyclerViewHasSelection((RecyclerView) viewHolder.itemView.getParent()); if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { holderBeingSwiped = viewHolder; //noinspection unchecked onSwipeStarted((T) model, viewHolder.itemView, viewHolder.getAdapterPosition()); } else if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) { holderBeingDragged = viewHolder; //noinspection unchecked onDragStarted((T) model, viewHolder.itemView, viewHolder.getAdapterPosition()); } } else if (holderBeingDragged != null) { //noinspection unchecked onDragReleased((T) holderBeingDragged.getModel(), holderBeingDragged.itemView); holderBeingDragged = null; } else if (holderBeingSwiped != null) { //noinspection unchecked onSwipeReleased((T) holderBeingSwiped.getModel(), holderBeingSwiped.itemView); holderBeingSwiped = null; } }
Example 13
Source File: ItemTouchUIUtilImpl.java From CrazyDaily with Apache License 2.0 | 5 votes |
@Override public void onDrawOver(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) { draw(c, recyclerView, view, dX, dY); } }
Example 14
Source File: ItemTouchUIUtilImpl.java From CrazyDaily with Apache License 2.0 | 5 votes |
@Override public void onDraw(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (actionState != ItemTouchHelper.ACTION_STATE_DRAG) { draw(c, recyclerView, view, dX, dY); } }
Example 15
Source File: SimpleItemTouchHelperCallback.java From YImagePicker with Apache License 2.0 | 5 votes |
@Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { // Fade out the view as it is swiped out of the parent's bounds final float alpha = ALPHA_FULL - Math.abs(dX) / (float) viewHolder.itemView.getWidth(); viewHolder.itemView.setAlpha(alpha); viewHolder.itemView.setTranslationX(dX); } else if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) { if (isCurrentlyActive) { viewHolder.itemView.setAlpha(0.5f); viewHolder.itemView.setScaleX(moveScaleFactor); viewHolder.itemView.setScaleY(moveScaleFactor); } else { viewHolder.itemView.setAlpha(1f); viewHolder.itemView.setScaleX(1f); viewHolder.itemView.setScaleY(1f); } super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } else { super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } // 从拖动到释放的过程 if (null != mOnSelectChangedListener && !isCurrentlyActive && lastActive) { mOnSelectChangedListener.onSelectedChanged(viewHolder, dX, dY, actionState, isCurrentlyActive); } lastActive = isCurrentlyActive; }
Example 16
Source File: ItemTouchCallback.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
@Override public void onSelectedChanged(@Nullable RecyclerView.ViewHolder viewHolder, int actionState) { super.onSelectedChanged(viewHolder, actionState); final boolean swiping = actionState == ItemTouchHelper.ACTION_STATE_DRAG; if (swipeRefreshLayout != null) { swipeRefreshLayout.setEnabled(!swiping); } if (viewPager != null) { viewPager.requestDisallowInterceptTouchEvent(swiping); } }
Example 17
Source File: ItemTouchUIUtilImpl.java From monero-wallet-android-app with MIT License | 5 votes |
@Override public void onDrawOver(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) { draw(c, recyclerView, view, dX, dY); } }
Example 18
Source File: ItemTouchUIUtilImpl.java From monero-wallet-android-app with MIT License | 5 votes |
@Override public void onDraw(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (actionState != ItemTouchHelper.ACTION_STATE_DRAG) { draw(c, recyclerView, view, dX, dY); } }