-
- All Implemented Interfaces:
-
androidx.appcompat.view.ActionMode.Callback
public class ActionModeHelper implements ActionMode.Callback
Helper Class to coordinate the MULTI selection with FlexibleAdapter.
-
-
Constructor Summary
Constructors Constructor Description ActionModeHelper(FlexibleAdapter adapter, int cabMenu)Default constructor with internal callback. ActionModeHelper(FlexibleAdapter adapter, int cabMenu, ActionMode.Callback callback)Constructor with internal callback + custom callback.
-
Method Summary
Modifier and Type Method Description final ActionModeHelperwithDefaultMode(int defaultMode)Changes the default mode to apply when the ActionMode is destroyed and normal selection isagain active. final ActionModeHelperdisableDragOnActionMode(boolean disableDrag)Automatically disables LongPress drag and Handle drag capability when ActionMode isactivated and enable it again when ActionMode is destroyed. final ActionModeHelperdisableSwipeOnActionMode(boolean disableSwipe)Automatically disables Swipe capability when ActionMode is activated and enable it againwhen ActionMode is destroyed. ActionModegetActionMode()intgetActivatedPosition()Gets the activated position only when mode is {@code SINGLE}.booleanonClick(int position)Implements the basic behavior of a CAB and multi select behavior. ActionModeonLongClick(AppCompatActivity activity, int position)Implements the basic behavior of a CAB and multi select behavior onLongClick. voidtoggleSelection(int position)Toggle the selection state of an item. voidupdateContextTitle(int count)Updates the title of the Context Menu. voidrestoreSelection(AppCompatActivity activity)Helper method to restart the action mode after a restoration of deleted items and afterscreen rotation. booleanonCreateActionMode(ActionMode actionMode, Menu menu)booleanonPrepareActionMode(ActionMode actionMode, Menu menu)booleanonActionItemClicked(ActionMode actionMode, MenuItem item)voidonDestroyActionMode(ActionMode actionMode)With FlexibleAdapter v5.0. booleandestroyActionModeIfCan()Utility method to be called from Activity in many occasions such as: onBackPressed,onRefresh for SwipeRefreshLayout, after deleting all selected items. -
-
Constructor Detail
-
ActionModeHelper
ActionModeHelper(FlexibleAdapter adapter, int cabMenu)
Default constructor with internal callback.- Parameters:
adapter- the FlexibleAdapter instancecabMenu- the Contextual Action Bar menu resourceId
-
ActionModeHelper
ActionModeHelper(FlexibleAdapter adapter, int cabMenu, ActionMode.Callback callback)
Constructor with internal callback + custom callback.- Parameters:
adapter- the FlexibleAdapter instancecabMenu- the Contextual Action Bar menu resourceIdcallback- the custom androidx.appcompat.view.ActionMode.Callback
-
-
Method Detail
-
withDefaultMode
final ActionModeHelper withDefaultMode(int defaultMode)
Changes the default mode to apply when the ActionMode is destroyed and normal selection isagain active.
Default value is IDLE.
- Parameters:
defaultMode- the new default mode when ActionMode is off, accepted values:{@code IDLE, SINGLE}
-
disableDragOnActionMode
final ActionModeHelper disableDragOnActionMode(boolean disableDrag)
Automatically disables LongPress drag and Handle drag capability when ActionMode isactivated and enable it again when ActionMode is destroyed.
- Parameters:
disableDrag- true to disable the drag, false to maintain the drag during ActionMode
-
disableSwipeOnActionMode
final ActionModeHelper disableSwipeOnActionMode(boolean disableSwipe)
Automatically disables Swipe capability when ActionMode is activated and enable it againwhen ActionMode is destroyed.
- Parameters:
disableSwipe- true to disable the swipe, false to maintain the swipe during ActionMode
-
getActionMode
ActionMode getActionMode()
-
getActivatedPosition
int getActivatedPosition()
Gets the activated position only when mode is
{@code SINGLE}.
-
onClick
boolean onClick(int position)
Implements the basic behavior of a CAB and multi select behavior.
- Parameters:
position- the current item position
-
onLongClick
@NonNull() ActionMode onLongClick(AppCompatActivity activity, int position)
Implements the basic behavior of a CAB and multi select behavior onLongClick.
- Parameters:
activity- the current Activityposition- the position of the clicked item
-
toggleSelection
void toggleSelection(int position)
Toggle the selection state of an item.
If the item was the last one in the selection and is unselected, the selection is stopped.Note that the selection must already be started (actionMode must not be null).
- Parameters:
position- position of the item to toggle the selection state
-
updateContextTitle
void updateContextTitle(int count)
Updates the title of the Context Menu.
Override to customize the title and subtitle.
- Parameters:
count- the current number of selected items
-
restoreSelection
void restoreSelection(AppCompatActivity activity)
Helper method to restart the action mode after a restoration of deleted items and afterscreen rotation. The ActionMode will be activated only if getSelectedItemCount has selections.
To be called in the
{@code onUndo}method after the restoration is done or at the endof{@code onRestoreInstanceState}.- Parameters:
activity- the current Activity
-
onCreateActionMode
@CallSuper() boolean onCreateActionMode(ActionMode actionMode, Menu menu)
-
onPrepareActionMode
@CallSuper() boolean onPrepareActionMode(ActionMode actionMode, Menu menu)
-
onActionItemClicked
@CallSuper() boolean onActionItemClicked(ActionMode actionMode, MenuItem item)
-
onDestroyActionMode
@CallSuper() void onDestroyActionMode(ActionMode actionMode)
With FlexibleAdapter v5.0.0 the default mode is IDLE, ifyou want single selection enabled change default mode with withDefaultMode.
-
destroyActionModeIfCan
boolean destroyActionModeIfCan()
Utility method to be called from Activity in many occasions such as: onBackPressed,onRefresh for SwipeRefreshLayout, after deleting all selected items.
-
-
-
-