-
public abstract class ItemTouchHelper.SimpleCallback extends ItemTouchHelper.Callback
A simple wrapper to the default Callback which you can construct with drag and swipedirections and this class will handle the flag callbacks. You should still override onMoveoronSwiped depending on your use case.
ItemTouchHelper mIth = new ItemTouchHelper( new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT) { public boolean onMove(RecyclerView recyclerView, ViewHolder viewHolder, ViewHolder target) { final int fromPos = viewHolder.getAdapterPosition(); final int toPos = target.getAdapterPosition(); // move item in `fromPos` to `toPos` in adapter. return true;// true if moved, false otherwise } public void onSwiped(ViewHolder viewHolder, int direction) { // remove from adapter } });
-
-
Constructor Summary
Constructors Constructor Description ItemTouchHelper.SimpleCallback(int dragDirs, int swipeDirs)
Creates a Callback for the given drag and swipe allowance.
-
Method Summary
Modifier and Type Method Description void
setDefaultSwipeDirs(int defaultSwipeDirs)
Updates the default swipe directions. void
setDefaultDragDirs(int defaultDragDirs)
Updates the default drag directions. int
getSwipeDirs(@NonNull() RecyclerView recyclerView, @NonNull() RecyclerView.ViewHolder viewHolder)
Returns the swipe directions for the provided ViewHolder. int
getDragDirs(@NonNull() RecyclerView recyclerView, @NonNull() RecyclerView.ViewHolder viewHolder)
Returns the drag directions for the provided ViewHolder. int
getMovementFlags(@NonNull() RecyclerView recyclerView, @NonNull() RecyclerView.ViewHolder viewHolder)
Should return a composite flag which defines the enabled move directions in each state(idle, swiping, dragging). -
Methods inherited from class tds.androidx.recyclerview.widget.ItemTouchHelper.Callback
canDropOver, chooseDropTarget, clearView, convertToAbsoluteDirection, convertToRelativeDirection, getAnimationDuration, getBoundingBoxMargin, getDefaultUIUtil, getMoveThreshold, 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
-
ItemTouchHelper.SimpleCallback
ItemTouchHelper.SimpleCallback(int dragDirs, int swipeDirs)
Creates a Callback for the given drag and swipe allowance.- Parameters:
dragDirs
- Binary OR of direction flags in which the Views can be dragged.swipeDirs
- Binary OR of direction flags in which the Views can be swiped.
-
-
Method Detail
-
setDefaultSwipeDirs
void setDefaultSwipeDirs(int defaultSwipeDirs)
Updates the default swipe directions. For example, you can use this method to togglecertain directions depending on your use case.
- Parameters:
defaultSwipeDirs
- Binary OR of directions in which the ViewHolders can be swiped.
-
setDefaultDragDirs
void setDefaultDragDirs(int defaultDragDirs)
Updates the default drag directions. For example, you can use this method to togglecertain directions depending on your use case.
- Parameters:
defaultDragDirs
- Binary OR of directions in which the ViewHolders can be dragged.
-
getSwipeDirs
int getSwipeDirs(@NonNull() RecyclerView recyclerView, @NonNull() RecyclerView.ViewHolder viewHolder)
Returns the swipe directions for the provided ViewHolder.Default implementation returns the swipe directions that was set via constructor or setDefaultSwipeDirs.
- Parameters:
recyclerView
- The RecyclerView to which the ItemTouchHelper is attached to.viewHolder
- The ViewHolder for which the swipe direction is queried.
-
getDragDirs
int getDragDirs(@NonNull() RecyclerView recyclerView, @NonNull() RecyclerView.ViewHolder viewHolder)
Returns the drag directions for the provided ViewHolder.Default implementation returns the drag directions that was set via constructor or setDefaultDragDirs.
- Parameters:
recyclerView
- The RecyclerView to which the ItemTouchHelper is attached to.viewHolder
- The ViewHolder for which the swipe direction is queried.
-
getMovementFlags
int getMovementFlags(@NonNull() RecyclerView recyclerView, @NonNull() RecyclerView.ViewHolder viewHolder)
Should return a composite flag which defines the enabled move directions in each state(idle, swiping, dragging).
Instead of composing this flag manually, you can use makeMovementFlags or makeFlag.
This flag is composed of 3 sets of 8 bits, where first 8 bits are for IDLE state, next8 bits are for SWIPE state and third 8 bits are for DRAG state.Each 8 bit sections can be constructed by simply OR'ing direction flags defined in ItemTouchHelper.
For example, if you want it to allow swiping LEFT and RIGHT but only allow starting toswipe by swiping RIGHT, you can return:
This means, allow right movement while IDLE and allow right and left movement whileswiping.makeFlag(ACTION_STATE_IDLE, RIGHT) | makeFlag(ACTION_STATE_SWIPE, LEFT | RIGHT);
- Parameters:
recyclerView
- The RecyclerView to which ItemTouchHelper is attached.viewHolder
- The ViewHolder for which the movement information is necessary.
-
-
-
-