public class ActionModeHelper
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected ActionMode |
mActionMode |
| Constructor and 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.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
destroyActionModeIfCan()
Utility method to be called from Activity in many occasions such as: onBackPressed,
onRefresh for SwipeRefreshLayout, after deleting all selected items.
|
ActionModeHelper |
disableDragOnActionMode(boolean disableDrag)
Automatically disables LongPress drag and Handle drag capability when ActionMode is
activated and enable it again when ActionMode is destroyed.
|
ActionModeHelper |
disableSwipeOnActionMode(boolean disableSwipe)
Automatically disables Swipe capability when ActionMode is activated and enable it again
when ActionMode is destroyed.
|
ActionMode |
getActionMode() |
int |
getActivatedPosition()
Gets the activated position only when mode is
SINGLE. |
boolean |
onActionItemClicked(ActionMode actionMode,
android.view.MenuItem item) |
boolean |
onClick(int position)
Implements the basic behavior of a CAB and multi select behavior.
|
boolean |
onCreateActionMode(ActionMode actionMode,
android.view.Menu menu) |
void |
onDestroyActionMode(ActionMode actionMode)
With FlexibleAdapter v5.0.0 the default mode is
Mode#IDLE, if
you want single selection enabled change default mode with withDefaultMode(int). |
ActionMode |
onLongClick(AppCompatActivity activity,
int position)
Implements the basic behavior of a CAB and multi select behavior onLongClick.
|
boolean |
onPrepareActionMode(ActionMode actionMode,
android.view.Menu menu) |
void |
restoreSelection(AppCompatActivity activity)
Helper method to restart the action mode after a restoration of deleted items and after
screen rotation.
|
void |
toggleSelection(int position)
Toggle the selection state of an item.
|
void |
updateContextTitle(int count)
Updates the title of the Context Menu.
|
ActionModeHelper |
withDefaultMode(int defaultMode)
Changes the default mode to apply when the ActionMode is destroyed and normal selection is
again active.
|
public ActionModeHelper(FlexibleAdapter adapter,
int cabMenu)
adapter - the FlexibleAdapter instancecabMenu - the Contextual Action Bar menu resourceIdActionModeHelper(FlexibleAdapter, int, ActionMode.Callback)public ActionModeHelper(FlexibleAdapter adapter,
int cabMenu,
ActionMode.Callback callback)
adapter - the FlexibleAdapter instancecabMenu - the Contextual Action Bar menu resourceIdcallback - the custom androidx.appcompat.view.ActionMode.CallbackActionModeHelper(FlexibleAdapter, int)public final ActionModeHelper withDefaultMode(int defaultMode)
Default value is Mode#IDLE.
defaultMode - the new default mode when ActionMode is off, accepted values:
IDLE, SINGLEpublic final ActionModeHelper disableDragOnActionMode(boolean disableDrag)
disableDrag - true to disable the drag, false to maintain the drag during ActionModepublic final ActionModeHelper disableSwipeOnActionMode(boolean disableSwipe)
disableSwipe - true to disable the swipe, false to maintain the swipe during ActionModepublic ActionMode getActionMode()
null if ActionMode is off.public int getActivatedPosition()
SINGLE.SINGLE. -1 if no item is selectedpublic boolean onClick(int position)
position - the current item positionpublic ActionMode onLongClick(AppCompatActivity activity,
int position)
activity - the current Activityposition - the position of the clicked itempublic void toggleSelection(int position)
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).
position - position of the item to toggle the selection statepublic void updateContextTitle(int count)
Override to customize the title and subtitle.
count - the current number of selected itemspublic void restoreSelection(AppCompatActivity activity)
FlexibleAdapter#getSelectedItemCount() has selections.
To be called in the onUndo method after the restoration is done or at the end
of onRestoreInstanceState.
activity - the current Activitypublic boolean onCreateActionMode(ActionMode actionMode,
android.view.Menu menu)
public boolean onPrepareActionMode(ActionMode actionMode,
android.view.Menu menu)
public boolean onActionItemClicked(ActionMode actionMode,
android.view.MenuItem item)
public void onDestroyActionMode(ActionMode actionMode)
Mode#IDLE, if
you want single selection enabled change default mode with withDefaultMode(int).public boolean destroyActionModeIfCan()