public class ItemTouchHelperCallback
extends Callback
Callback that enables Drag & Drop
and Swipe actions. Drag and Swipe events are started depending by the configuration.| Modifier and Type | Class and Description |
|---|---|
static interface |
ItemTouchHelperCallback.AdapterCallback
Internal interface for Adapter to listen for a move or swipe dismissal event
from a
ItemTouchHelperCallback. |
static interface |
ItemTouchHelperCallback.ViewHolderCallback
Internal Interface for ViewHolder to notify of relevant callbacks from
Callback. |
| Modifier and Type | Field and Description |
|---|---|
protected static float |
ALPHA_FULL |
protected boolean |
handleDragEnabled |
protected boolean |
longPressDragEnabled |
protected ItemTouchHelperCallback.AdapterCallback |
mAdapterCallback |
protected long |
mDragAnimationDuration |
protected float |
mMoveThreshold |
protected long |
mSwipeAnimationDuration |
protected int |
mSwipeFlags |
protected float |
mSwipeThreshold |
protected boolean |
swipeEnabled |
| Constructor and Description |
|---|
ItemTouchHelperCallback(ItemTouchHelperCallback.AdapterCallback adapterCallback) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canDropOver(RecyclerView recyclerView,
RecyclerView.ViewHolder current,
RecyclerView.ViewHolder target) |
void |
clearView(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder) |
long |
getAnimationDuration(RecyclerView recyclerView,
int animationType,
float animateDx,
float animateDy)
Provides the animation duration for Drag and Swipe previously set with
setDragAnimationDuration(long) and setSwipeAnimationDuration(long). |
int |
getMovementFlags(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder) |
float |
getMoveThreshold(RecyclerView.ViewHolder viewHolder) |
float |
getSwipeThreshold(RecyclerView.ViewHolder viewHolder)
Returns the fraction that the user should move the View to be considered as swiped.
|
boolean |
isHandleDragEnabled() |
boolean |
isItemViewSwipeEnabled() |
boolean |
isLongPressDragEnabled() |
void |
onChildDraw(android.graphics.Canvas c,
RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder,
float dX,
float dY,
int actionState,
boolean isCurrentlyActive) |
boolean |
onMove(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder,
RecyclerView.ViewHolder target) |
void |
onSelectedChanged(RecyclerView.ViewHolder viewHolder,
int actionState) |
void |
onSwiped(RecyclerView.ViewHolder viewHolder,
int direction) |
void |
setDragAnimationDuration(long animationDuration)
Sets the animation duration of Drag event, starting when the items is released.
|
void |
setHandleDragEnabled(boolean handleDragEnabled)
Enable / Disable the drag of the itemView with a handle view.
|
void |
setLongPressDragEnabled(boolean isLongPressDragEnabled)
Enable / Disable the drag operation with long press on the ViewHolder.
|
void |
setMoveThreshold(float moveThreshold)
Configures the fraction that the user should move the View to be considered as it is
dragged.
|
void |
setSwipeAnimationDuration(long animationDuration)
Sets the animation duration of Swipe removal event, starting when the items is released.
|
void |
setSwipeEnabled(boolean isSwipeEnabled)
Enable the swipe operation on the ViewHolder.
|
void |
setSwipeFlags(int swipeFlags)
Configures the directions in which the item can be swiped.
|
void |
setSwipeThreshold(float threshold)
Configures the fraction that the user should move the View to be considered as swiped.
|
protected static final float ALPHA_FULL
protected ItemTouchHelperCallback.AdapterCallback mAdapterCallback
protected boolean longPressDragEnabled
protected boolean handleDragEnabled
protected boolean swipeEnabled
protected long mSwipeAnimationDuration
protected long mDragAnimationDuration
protected float mSwipeThreshold
protected float mMoveThreshold
protected int mSwipeFlags
public ItemTouchHelperCallback(ItemTouchHelperCallback.AdapterCallback adapterCallback)
public void setLongPressDragEnabled(boolean isLongPressDragEnabled)
Default value is false.
isLongPressDragEnabled - true to enable, false to disablepublic boolean isLongPressDragEnabled()
public boolean isHandleDragEnabled()
public void setHandleDragEnabled(boolean handleDragEnabled)
Default value is false.
handleDragEnabled - true to activate, false to disablepublic boolean canDropOver(RecyclerView recyclerView,
RecyclerView.ViewHolder current,
RecyclerView.ViewHolder target)
public void setMoveThreshold(float moveThreshold)
Default value is 0.5f.
moveThreshold - A float value that denotes the fraction of the View size.public float getMoveThreshold(RecyclerView.ViewHolder viewHolder)
public void setSwipeEnabled(boolean isSwipeEnabled)
Default value is false.
isSwipeEnabled - true to enable swipe, false to disablepublic boolean isItemViewSwipeEnabled()
public void setSwipeThreshold(float threshold)
Default value is 0.5f.
threshold - A float value that denotes the fraction of the View size.public void setSwipeFlags(int swipeFlags)
Default values are ItemTouchHelper#LEFT, ItemTouchHelper#RIGHT
for VERTICAL LinearLayout.
swipeFlags - flags directions, a combination of:
ItemTouchHelper#LEFT, ItemTouchHelper#RIGHT,
ItemTouchHelper#UP, ItemTouchHelper#DOWNpublic float getSwipeThreshold(RecyclerView.ViewHolder viewHolder)
Default value is 0.5f, which means, to swipe a View, user must move the View at least half of RecyclerView's width or height, depending on the swipe direction.
viewHolder - The ViewHolder that is being dragged.public void setDragAnimationDuration(long animationDuration)
Default value is 400ms.
animationDuration - duration in millisecondspublic void setSwipeAnimationDuration(long animationDuration)
Default value is 300ms.
animationDuration - duration in millisecondspublic long getAnimationDuration(RecyclerView recyclerView,
int animationType,
float animateDx,
float animateDy)
setDragAnimationDuration(long) and setSwipeAnimationDuration(long).setDragAnimationDuration(long),
setSwipeAnimationDuration(long)public boolean onMove(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder,
RecyclerView.ViewHolder target)
public void onSwiped(RecyclerView.ViewHolder viewHolder,
int direction)
public int getMovementFlags(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder)
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder,
int actionState)
public void clearView(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder)
public void onChildDraw(android.graphics.Canvas c,
RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder,
float dX,
float dY,
int actionState,
boolean isCurrentlyActive)