public static final class ItemDragHelper.Interactor extends RecyclerViewItemHelper.ItemInteractor
ItemInteractor implementation used by ItemDragHelper to handle drag gesture
related callbacks and to delegate drag events to the view holder that is being dragged and
also to it parent adapter in order to properly move dragged items in the adapter's data set.DEFAULT_DRAG_ANIMATION_DURATION, DEFAULT_SWIPE_ANIMATION_DURATION| Modifier and Type | Method and Description |
|---|---|
void |
addOnDragListener(ItemDragHelper.OnDragListener listener)
Registers a callback to be invoked whenever drag gesture is started, finished
or canceled for a specific
RecyclerView.ViewHolder instance. |
protected boolean |
canAttachAdapter(RecyclerView.Adapter adapter)
Called by the parent helper to check if the given adapter may be attached
to this interactor instance.
|
boolean |
canDropOver(RecyclerView recyclerView,
RecyclerView.ViewHolder current,
RecyclerView.ViewHolder target) |
void |
clearView(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder) |
float |
getDragThreshold()
Returns the fraction that the user should move the holder's
View
to be considered as it is dragged. |
int |
getMovementFlags(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder) |
float |
getMoveThreshold(RecyclerView.ViewHolder viewHolder) |
boolean |
isActive()
Returns boolean flag indicating whether this interactor is currently active.
|
boolean |
isLongPressDragEnabled() |
protected void |
onAdapterAttached(RecyclerView.Adapter adapter)
Invoked whenever a new adapter is attached to this interactor instance.
|
protected void |
onAdapterDetached(RecyclerView.Adapter adapter)
Invoked before a new adapter is attached to this interactor instance if there
is already previous adapter attached.
|
boolean |
onMove(RecyclerView recyclerView,
RecyclerView.ViewHolder current,
RecyclerView.ViewHolder target) |
void |
onSelectedChanged(RecyclerView.ViewHolder viewHolder,
int actionState) |
void |
onSwiped(RecyclerView.ViewHolder viewHolder,
int direction) |
void |
removeOnDragListener(ItemDragHelper.OnDragListener listener)
Removes the given drag listener from the registered listeners.
|
void |
setDragThreshold(float threshold)
Sets a fraction that the user should move the holder's
View to
be considered as it is dragged. |
void |
setEnabled(boolean enabled)
Sets a boolean flag indicating whether this interactor should be enabled or not.
|
void |
setLongPressDragEnabled(boolean enabled)
Sets a boolean flag indicating whether the drag should be started whenever an item view
is long pressed or not.
|
protected boolean |
shouldHandleInteraction(RecyclerView.ViewHolder viewHolder)
Checks whether this interactor should handle interaction for the specified viewHolder
due to received callback from the parent helper.
|
isEnabled, onAttachedToHelper, onChildDraw, onChildDrawOver, shouldHandleInteractionchooseDropTarget, convertToAbsoluteDirection, convertToRelativeDirection, getAnimationDuration, getBoundingBoxMargin, getDefaultUIUtil, getSwipeEscapeVelocity, getSwipeThreshold, getSwipeVelocityThreshold, interpolateOutOfBoundsScroll, isItemViewSwipeEnabled, makeFlag, makeMovementFlags, onMovedpublic void setLongPressDragEnabled(boolean enabled)
If disabled, a drag for a particular view holder needs to be started via
ItemTouchHelper.startDrag(RecyclerView.ViewHolder) manually.
Default value: true
enabled - True to enable automatic drag on long press, false to
disable it.isLongPressDragEnabled()public boolean isLongPressDragEnabled()
isLongPressDragEnabled in class ItemTouchHelper.Callbackpublic void setDragThreshold(float threshold)
View to
be considered as it is dragged.
Default value: ItemDragHelper.MOVE_THRESHOLD
threshold - The desired threshold from the range [0.0, 1.0].getDragThreshold(),
getMoveThreshold(RecyclerView.ViewHolder),
getMoveThreshold(RecyclerView.ViewHolder)public float getDragThreshold()
View
to be considered as it is dragged.[0.0, 1.0].setDragThreshold(float)public float getMoveThreshold(@NonNull RecyclerView.ViewHolder viewHolder)
getMoveThreshold in class ItemTouchHelper.Callbackpublic void addOnDragListener(@NonNull ItemDragHelper.OnDragListener listener)
RecyclerView.ViewHolder instance.listener - The desired listener callback to add.#removeOnDragListener(OnDragListener)public void removeOnDragListener(@NonNull ItemDragHelper.OnDragListener listener)
listener - The desired listener to remove.#addOnDragListener(OnDragListener)protected boolean canAttachAdapter(@NonNull RecyclerView.Adapter adapter)
RecyclerViewItemHelper.ItemInteractor
If this method returns true, RecyclerViewItemHelper.ItemInteractor.onAdapterAttached(RecyclerView.Adapter)
will follow. If this interactor has attached any previous adapter, such adapter will be
detached via RecyclerViewItemHelper.ItemInteractor.onAdapterDetached(RecyclerView.Adapter) before the new one is
attached.
canAttachAdapter in class RecyclerViewItemHelper.ItemInteractoradapter - The adapter to be checked if it may be attached.True if the parent helper may attach the adapter to this interactor,
false otherwise.protected void onAdapterAttached(@NonNull RecyclerView.Adapter adapter)
RecyclerViewItemHelper.ItemInteractor
This method is called as result of call to RecyclerViewItemHelper.attachToRecyclerView(RecyclerView)
for the parent helper.
onAdapterAttached in class RecyclerViewItemHelper.ItemInteractoradapter - The adapter of the associated RecyclerView to which is the parent
helper attached.RecyclerViewItemHelper.ItemInteractor.onAdapterDetached(RecyclerView.Adapter)protected void onAdapterDetached(@NonNull RecyclerView.Adapter adapter)
RecyclerViewItemHelper.ItemInteractoronAdapterDetached in class RecyclerViewItemHelper.ItemInteractoradapter - The previous adapter that has been detached from this interactor.RecyclerViewItemHelper.ItemInteractor.onAdapterAttached(RecyclerView.Adapter)public void setEnabled(boolean enabled)
RecyclerViewItemHelper.ItemInteractorsetEnabled in class RecyclerViewItemHelper.ItemInteractorenabled - True to enable this interactor, false otherwise.RecyclerViewItemHelper.ItemInteractor.isEnabled()public boolean isActive()
RecyclerViewItemHelper.ItemInteractorisActive in class RecyclerViewItemHelper.ItemInteractorTrue if this interactor performs some interaction logic at this time,
false otherwise.public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder)
getMovementFlags in class ItemTouchHelper.Callbackpublic void onSelectedChanged(@Nullable RecyclerView.ViewHolder viewHolder, int actionState)
onSelectedChanged in class ItemTouchHelper.Callbackpublic boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder current, @NonNull RecyclerView.ViewHolder target)
onMove in class ItemTouchHelper.Callbackpublic void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction)
onSwiped in class ItemTouchHelper.Callbackpublic boolean canDropOver(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder current, @NonNull RecyclerView.ViewHolder target)
canDropOver in class ItemTouchHelper.Callbackpublic void clearView(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder)
clearView in class ItemTouchHelper.Callbackprotected boolean shouldHandleInteraction(@Nullable RecyclerView.ViewHolder viewHolder)
RecyclerViewItemHelper.ItemInteractor
This implementation only extends RecyclerViewItemHelper.ItemInteractor.shouldHandleInteraction() in a way that the
view holder is checked if it is not null and has valid adapter position. Inheritance
hierarchies are allowed to override this behaviour as desired.
shouldHandleInteraction in class RecyclerViewItemHelper.ItemInteractorviewHolder - The desired view holder to be checked.True if RecyclerViewItemHelper.ItemInteractor.shouldHandleInteraction() returns true, view holder
is not null and has valid (not RecyclerView.NO_POSITION) adapter position,
false otherwise.