@UiThread public class BasicSelectionActionDelegate extends Object implements ActionMode.Callback, GeckoSession.SelectionActionDelegate
getAllActions()
to include custom action IDs in the returned array. This
array must include all actions, available or not, and must not change over the class lifetime.
2) Override isActionAvailable(java.lang.String)
to return whether a custom action is currently available.
3) Override prepareAction(java.lang.String, android.view.MenuItem)
to set custom title and/or icon for a custom action.
4) Override performAction(java.lang.String, android.view.MenuItem)
to perform a custom action when used.GeckoSession.SelectionActionDelegate.Selection
Modifier and Type | Field and Description |
---|---|
protected static String |
ACTION_PROCESS_TEXT |
protected ActionMode |
mActionMode |
protected Activity |
mActivity |
protected boolean |
mRepopulatedMenu |
protected GeckoSession.SelectionActionDelegate.Selection |
mSelection |
protected GeckoSession |
mSession |
protected Matrix |
mTempMatrix |
protected RectF |
mTempRect |
protected boolean |
mUseFloatingToolbar |
ACTION_COLLAPSE_TO_END, ACTION_COLLAPSE_TO_START, ACTION_COPY, ACTION_CUT, ACTION_DELETE, ACTION_HIDE, ACTION_PASTE, ACTION_SELECT_ALL, ACTION_UNSELECT, FLAG_IS_COLLAPSED, FLAG_IS_EDITABLE, FLAG_IS_PASSWORD, HIDE_REASON_ACTIVE_SCROLL, HIDE_REASON_ACTIVE_SELECTION, HIDE_REASON_INVISIBLE_SELECTION, HIDE_REASON_NO_SELECTION
Constructor and Description |
---|
BasicSelectionActionDelegate(Activity activity) |
BasicSelectionActionDelegate(Activity activity,
boolean useFloatingToolbar) |
Modifier and Type | Method and Description |
---|---|
boolean |
areExternalActionsEnabled()
Get whether text actions from other apps are enabled.
|
void |
clearSelection()
Clear the current selection, if possible.
|
void |
enableExternalActions(boolean enable)
Set whether to include text actions from other apps in the floating toolbar.
|
protected String[] |
getAllActions()
Return list of all actions in proper order, regardless of their availability at present.
|
GeckoSession.SelectionActionDelegate.Selection |
getSelection()
Get the current selection object.
|
boolean |
isActionAvailable()
Provides access to whether there are text selection actions available.
|
protected boolean |
isActionAvailable(String id)
Return whether an action is presently available.
|
boolean |
onActionItemClicked(ActionMode actionMode,
MenuItem menuItem) |
boolean |
onCreateActionMode(ActionMode actionMode,
Menu menu) |
void |
onDestroyActionMode(ActionMode actionMode) |
void |
onGetContentRect(ActionMode mode,
View view,
Rect outRect) |
void |
onHideAction(GeckoSession session,
int reason)
Previous actions are no longer available due to the user interacting with the
page.
|
boolean |
onPrepareActionMode(ActionMode actionMode,
Menu menu) |
void |
onShowActionRequest(GeckoSession session,
GeckoSession.SelectionActionDelegate.Selection selection)
Selection actions are available.
|
protected boolean |
performAction(String id,
MenuItem item)
Perform the specified action.
|
protected void |
prepareAction(String id,
MenuItem item)
Prepare a menu item corresponding to a certain action.
|
protected static final String ACTION_PROCESS_TEXT
@NonNull protected final Activity mActivity
protected final boolean mUseFloatingToolbar
@NonNull protected final Matrix mTempMatrix
@NonNull protected final RectF mTempRect
@Nullable protected ActionMode mActionMode
@Nullable protected GeckoSession mSession
@Nullable protected GeckoSession.SelectionActionDelegate.Selection mSelection
protected boolean mRepopulatedMenu
public BasicSelectionActionDelegate(@NonNull Activity activity)
public BasicSelectionActionDelegate(@NonNull Activity activity, boolean useFloatingToolbar)
public void enableExternalActions(boolean enable)
enable
- True if external actions should be enabled.public boolean areExternalActionsEnabled()
@NonNull protected String[] getAllActions()
protected boolean isActionAvailable(@NonNull String id)
id
- Action ID.public boolean isActionAvailable()
protected void prepareAction(@NonNull String id, @NonNull MenuItem item)
id
- Action ID.item
- New menu item to prepare.protected boolean performAction(@NonNull String id, @NonNull MenuItem item)
id
- Action ID.item
- Nenu item for the action.@Nullable public GeckoSession.SelectionActionDelegate.Selection getSelection()
GeckoSession.SelectionActionDelegate.Selection
attached to the current
action menu. null
if no action menu is active.public void clearSelection()
public boolean onCreateActionMode(ActionMode actionMode, Menu menu)
onCreateActionMode
in interface ActionMode.Callback
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu)
onPrepareActionMode
in interface ActionMode.Callback
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem)
onActionItemClicked
in interface ActionMode.Callback
public void onDestroyActionMode(ActionMode actionMode)
onDestroyActionMode
in interface ActionMode.Callback
public void onGetContentRect(@Nullable ActionMode mode, @Nullable View view, @NonNull Rect outRect)
public void onShowActionRequest(GeckoSession session, GeckoSession.SelectionActionDelegate.Selection selection)
GeckoSession.SelectionActionDelegate
GeckoSession.SelectionActionDelegate.Selection.isActionAvailable(java.lang.String)
then either use the relevant
helper method or GeckoSession.SelectionActionDelegate.Selection.execute(java.lang.String)
Once an GeckoSession.SelectionActionDelegate.onHideAction(org.mozilla.geckoview.GeckoSession, int)
call (with particular reasons) or another GeckoSession.SelectionActionDelegate.onShowActionRequest(org.mozilla.geckoview.GeckoSession, org.mozilla.geckoview.GeckoSession.SelectionActionDelegate.Selection)
call is received, the previous Selection object is no longer
usable.onShowActionRequest
in interface GeckoSession.SelectionActionDelegate
session
- The GeckoSession that initiated the callback.selection
- Current selection attributes and Callback object for performing built-in
actions. May be used multiple times to perform multiple actions at once.public void onHideAction(GeckoSession session, int reason)
GeckoSession.SelectionActionDelegate
onHideAction
in interface GeckoSession.SelectionActionDelegate
session
- The GeckoSession that initiated the callback.reason
- The reason that actions are no longer available, as one of the
HIDE_REASON_*
constants.