-
public class ItemTouchHelperCallback extends ItemTouchHelper.Callback
This class is an implementation of Callback that enables Drag & Drop and Swipe actions. Drag and Swipe events are started depending by the configuration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceItemTouchHelperCallback.AdapterCallbackInternal interface for Adapter to listen for a move or swipe dismissal eventfrom a ItemTouchHelperCallback.
public interfaceItemTouchHelperCallback.ViewHolderCallbackInternal Interface for ViewHolder to notify of relevant callbacks from Callback.This listener, is to intend as a further way to display How a ViewHolder will displaythe middle and final activation state.
Generally the final action should be handled by the listeners OnItemMoveListener and OnItemSwipeListener.
-
Field Summary
Fields Modifier and Type Field Description protected booleanlongPressDragEnabledprotected booleanhandleDragEnabledprotected booleanswipeEnabled
-
Constructor Summary
Constructors Constructor Description ItemTouchHelperCallback(ItemTouchHelperCallback.AdapterCallback adapterCallback)
-
Method Summary
Modifier and Type Method Description voidsetLongPressDragEnabled(boolean isLongPressDragEnabled)Enable / Disable the drag operation with long press on the ViewHolder. voidsetHandleDragEnabled(boolean handleDragEnabled)Enable / Disable the drag of the itemView with a handle view. voidsetSwipeEnabled(boolean isSwipeEnabled)Enable the swipe operation on the ViewHolder. booleanisLongPressDragEnabled()booleanisHandleDragEnabled()booleancanDropOver(RecyclerView recyclerView, RecyclerView.ViewHolder current, RecyclerView.ViewHolder target)voidsetMoveThreshold(float moveThreshold)Configures the fraction that the user should move the View to be considered as it isdragged. floatgetMoveThreshold(RecyclerView.ViewHolder viewHolder)booleanisItemViewSwipeEnabled()voidsetSwipeThreshold(float threshold)Configures the fraction that the user should move the View to be considered as swiped. voidsetSwipeFlags(int swipeFlags)Configures the directions in which the item can be swiped. floatgetSwipeThreshold(RecyclerView.ViewHolder viewHolder)Returns the fraction that the user should move the View to be considered as swiped.The fraction is calculated with respect to RecyclerView's bounds. voidsetDragAnimationDuration(long animationDuration)Sets the animation duration of Drag event, starting when the items is released. voidsetSwipeAnimationDuration(long animationDuration)Sets the animation duration of Swipe removal event, starting when the items is released. longgetAnimationDuration(RecyclerView recyclerView, int animationType, float animateDx, float animateDy)Provides the animation duration for Drag and Swipe previously set with setDragAnimationDuration and setSwipeAnimationDuration. booleanonMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target)voidonSwiped(RecyclerView.ViewHolder viewHolder, int direction)intgetMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder)voidonSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState)voidclearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder)voidonChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive)-
Methods inherited from class androidx.recyclerview.widget.ItemTouchHelper.Callback
canDropOver, chooseDropTarget, clearView, convertToAbsoluteDirection, convertToRelativeDirection, getAnimationDuration, getBoundingBoxMargin, getDefaultUIUtil, getMoveThreshold, getMovementFlags, getSwipeEscapeVelocity, getSwipeThreshold, getSwipeVelocityThreshold, interpolateOutOfBoundsScroll, isItemViewSwipeEnabled, isLongPressDragEnabled, makeFlag, makeMovementFlags, onChildDraw, onChildDrawOver, onMove, onMoved, onSelectedChanged, onSwiped -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
ItemTouchHelperCallback
ItemTouchHelperCallback(ItemTouchHelperCallback.AdapterCallback adapterCallback)
-
-
Method Detail
-
setLongPressDragEnabled
void setLongPressDragEnabled(boolean isLongPressDragEnabled)
Enable / Disable the drag operation with long press on the ViewHolder.
Default value is
{@code false}.- Parameters:
isLongPressDragEnabled- true to enable, false to disable
-
setHandleDragEnabled
void setHandleDragEnabled(boolean handleDragEnabled)
Enable / Disable the drag of the itemView with a handle view.
Default value is
{@code false}.- Parameters:
handleDragEnabled- true to activate, false to disable
-
setSwipeEnabled
void setSwipeEnabled(boolean isSwipeEnabled)
Enable the swipe operation on the ViewHolder.
Default value is
{@code false}.- Parameters:
isSwipeEnabled- true to enable swipe, false to disable
-
isLongPressDragEnabled
boolean isLongPressDragEnabled()
-
isHandleDragEnabled
boolean isHandleDragEnabled()
-
canDropOver
boolean canDropOver(RecyclerView recyclerView, RecyclerView.ViewHolder current, RecyclerView.ViewHolder target)
-
setMoveThreshold
void setMoveThreshold(float moveThreshold)
Configures the fraction that the user should move the View to be considered as it isdragged. After a view is moved this amount, ItemTouchHelper starts checking for Viewsbelow it for a possible drop.
Default value is
{@code 0.5f}.- Parameters:
moveThreshold- A float value that denotes the fraction of the View size.
-
getMoveThreshold
float getMoveThreshold(RecyclerView.ViewHolder viewHolder)
-
isItemViewSwipeEnabled
boolean isItemViewSwipeEnabled()
-
setSwipeThreshold
void setSwipeThreshold(float threshold)
Configures the fraction that the user should move the View to be considered as swiped.
Default value is
{@code 0.5f}.- Parameters:
threshold- A float value that denotes the fraction of the View size.
-
setSwipeFlags
void setSwipeFlags(int swipeFlags)
Configures the directions in which the item can be swiped.
NOTE: Swipe is not supported in case of GridLayout and StaggeredGridLayout.
-
getSwipeThreshold
float getSwipeThreshold(RecyclerView.ViewHolder viewHolder)
Returns the fraction that the user should move the View to be considered as swiped.The fraction is calculated with respect to RecyclerView's bounds.
Default value is 0.5f, which means, to swipe a View, user must move the View at leasthalf of RecyclerView's width or height, depending on the swipe direction.
- Parameters:
viewHolder- The ViewHolder that is being dragged.
-
setDragAnimationDuration
void setDragAnimationDuration(long animationDuration)
Sets the animation duration of Drag event, starting when the items is released.
Default value is
{@code 400ms}.- Parameters:
animationDuration- duration in milliseconds
-
setSwipeAnimationDuration
void setSwipeAnimationDuration(long animationDuration)
Sets the animation duration of Swipe removal event, starting when the items is released.
Default value is
{@code 300ms}.- Parameters:
animationDuration- duration in milliseconds
-
getAnimationDuration
long getAnimationDuration(RecyclerView recyclerView, int animationType, float animateDx, float animateDy)
Provides the animation duration for Drag and Swipe previously set with setDragAnimationDuration and setSwipeAnimationDuration.
-
onMove
boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target)
-
onSwiped
void onSwiped(RecyclerView.ViewHolder viewHolder, int direction)
-
getMovementFlags
int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder)
-
onSelectedChanged
void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState)
-
clearView
void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder)
-
onChildDraw
void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive)
-
-
-
-