public static final class ItemSwipeHelper.Interactor extends RecyclerViewItemHelper.ItemInteractor
ItemInteractor implementation used by ItemSwipeHelper to handle swipe
gesture related callbacks and to delegate swipe events to the view holder that is being swiped.DEFAULT_DRAG_ANIMATION_DURATION, DEFAULT_SWIPE_ANIMATION_DURATION| Modifier and Type | Method and Description |
|---|---|
void |
addOnSwipeListener(ItemSwipeHelper.OnSwipeListener listener)
Registers a callback to be invoked whenever swipe 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.
|
void |
clearView(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder) |
int |
getMovementFlags(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder) |
float |
getSwipeThreshold()
Returns the fraction that the user should move the holder's
View to be considered
as swiped. |
float |
getSwipeThreshold(RecyclerView.ViewHolder viewHolder) |
boolean |
isActive()
Returns boolean flag indicating whether this interactor is currently active.
|
boolean |
isItemViewSwipeEnabled() |
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 viewHolder,
RecyclerView.ViewHolder target) |
void |
onSelectedChanged(RecyclerView.ViewHolder viewHolder,
int actionState) |
void |
onSwiped(RecyclerView.ViewHolder viewHolder,
int direction) |
void |
removeOnSwipeListener(ItemSwipeHelper.OnSwipeListener listener)
Removes the given swipe listener from the registered listeners.
|
void |
setEnabled(boolean enabled)
Sets a boolean flag indicating whether this interactor should be enabled or not.
|
void |
setItemViewSwipeEnabled(boolean enabled)
Sets a boolean flag indicating whether the swipe should be started whenever an active
pointer is swiped over an item view or not.
|
void |
setSwipeThreshold(float threshold)
Sets a fraction that the user should move the holder's
View to be considered as
swiped. |
isEnabled, onAttachedToHelper, onChildDraw, onChildDrawOver, shouldHandleInteractioncanDropOver, chooseDropTarget, convertToAbsoluteDirection, convertToRelativeDirection, getAnimationDuration, getBoundingBoxMargin, getDefaultUIUtil, getMoveThreshold, getSwipeEscapeVelocity, getSwipeVelocityThreshold, interpolateOutOfBoundsScroll, isLongPressDragEnabled, makeFlag, makeMovementFlags, onMovedpublic void setItemViewSwipeEnabled(boolean enabled)
If disabled, a swipe for a particular view holder needs to be started via
ItemTouchHelper.startSwipe(RecyclerView.ViewHolder) manually.
Default value: true
enabled - True to enable automatic swipe, false to disable it.isItemViewSwipeEnabled()public boolean isItemViewSwipeEnabled()
isItemViewSwipeEnabled in class ItemTouchHelper.Callbackpublic void setSwipeThreshold(float threshold)
View to be considered as
swiped.
Default value: ItemSwipeHelper.SWIPE_THRESHOLD
threshold - The desired threshold from the range [0.0, 1.0].getSwipeThreshold(),
ItemSwipeHelper.Callback#getSwipeThreshold(RecyclerView.ViewHolder)public float getSwipeThreshold()
View to be considered
as swiped.[0.0, 1.0].setSwipeThreshold(float)public float getSwipeThreshold(@NonNull RecyclerView.ViewHolder viewHolder)
getSwipeThreshold in class ItemTouchHelper.Callbackpublic void addOnSwipeListener(@NonNull ItemSwipeHelper.OnSwipeListener listener)
RecyclerView.ViewHolder instance.listener - The desired listener callback to add.#removeOnSwipeListener(OnSwipeListener)public void removeOnSwipeListener(@NonNull ItemSwipeHelper.OnSwipeListener listener)
listener - The desired listener to remove.#addOnSwipeListener(OnSwipeListener)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 viewHolder, @NonNull RecyclerView.ViewHolder target)
onMove in class ItemTouchHelper.Callbackpublic void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction)
onSwiped in class ItemTouchHelper.Callbackpublic void clearView(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder)
clearView in class ItemTouchHelper.Callback