Class BasicSelectionActionDelegate
- All Implemented Interfaces:
ActionMode.Callback
,GeckoSession.SelectionActionDelegate
To provide custom actions, extend this class and override the following methods,
1) Override 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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.mozilla.geckoview.GeckoSession.SelectionActionDelegate
GeckoSession.SelectionActionDelegate.ClipboardPermission, GeckoSession.SelectionActionDelegate.Selection
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected ActionMode
protected final Activity
protected boolean
protected GeckoSession
protected final boolean
Fields inherited from interface org.mozilla.geckoview.GeckoSession.SelectionActionDelegate
ACTION_COLLAPSE_TO_END, ACTION_COLLAPSE_TO_START, ACTION_COPY, ACTION_CUT, ACTION_DELETE, ACTION_HIDE, ACTION_PASTE, ACTION_PASTE_AS_PLAIN_TEXT, 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, PERMISSION_CLIPBOARD_READ
-
Constructor Summary
ConstructorDescriptionBasicSelectionActionDelegate
(Activity activity) BasicSelectionActionDelegate
(Activity activity, boolean useFloatingToolbar) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Get whether text actions from other apps are enabled.void
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[]
Return list of all actions in proper order, regardless of their availability at present.Get the current selection object.boolean
Provides access to whether there are text selection actions available.protected boolean
Return whether an action is presently available.boolean
onActionItemClicked
(ActionMode actionMode, MenuItem menuItem) boolean
onCreateActionMode
(ActionMode actionMode, Menu menu) void
onDestroyActionMode
(ActionMode actionMode) void
Dismiss action mode for requesting clipboard permission popup or model.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.onShowClipboardPermissionRequest
(GeckoSession session, GeckoSession.SelectionActionDelegate.ClipboardPermission permission) Show action mode bar to request clipboard permissionprotected 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.
-
Field Details
-
ACTION_PROCESS_TEXT
- See Also:
-
mActivity
-
mUseFloatingToolbar
protected final boolean mUseFloatingToolbar -
mActionMode
-
mSession
-
mSelection
-
mRepopulatedMenu
protected boolean mRepopulatedMenu
-
-
Constructor Details
-
BasicSelectionActionDelegate
-
BasicSelectionActionDelegate
-
-
Method Details
-
enableExternalActions
public void enableExternalActions(boolean enable) Set whether to include text actions from other apps in the floating toolbar.- Parameters:
enable
- True if external actions should be enabled.
-
areExternalActionsEnabled
public boolean areExternalActionsEnabled()Get whether text actions from other apps are enabled.- Returns:
- True if external actions are enabled.
-
getAllActions
Return list of all actions in proper order, regardless of their availability at present. Override to add to or remove from the default set.- Returns:
- Array of action IDs in proper order.
-
isActionAvailable
Return whether an action is presently available. Override to indicate availability for custom actions.- Parameters:
id
- Action ID.- Returns:
- True if the action is presently available.
-
isActionAvailable
public boolean isActionAvailable()Provides access to whether there are text selection actions available. Override to indicate availability for custom actions.- Returns:
- True if there are text selection actions available.
-
prepareAction
Prepare a menu item corresponding to a certain action. Override to prepare menu item for custom action.- Parameters:
id
- Action ID.item
- New menu item to prepare.
-
performAction
Perform the specified action. Override to perform custom actions.- Parameters:
id
- Action ID.item
- Nenu item for the action.- Returns:
- True if the action was performed.
-
getSelection
Get the current selection object. This object should not be stored as it does not update when the selection becomes invalid. Stale actions are ignored.- Returns:
- The
GeckoSession.SelectionActionDelegate.Selection
attached to the current action menu.null
if no action menu is active.
-
clearSelection
public void clearSelection()Clear the current selection, if possible. -
onCreateActionMode
- Specified by:
onCreateActionMode
in interfaceActionMode.Callback
-
onPrepareActionMode
- Specified by:
onPrepareActionMode
in interfaceActionMode.Callback
-
onActionItemClicked
- Specified by:
onActionItemClicked
in interfaceActionMode.Callback
-
onDestroyActionMode
- Specified by:
onDestroyActionMode
in interfaceActionMode.Callback
-
onGetContentRect
-
onShowActionRequest
public void onShowActionRequest(GeckoSession session, GeckoSession.SelectionActionDelegate.Selection selection) Description copied from interface:GeckoSession.SelectionActionDelegate
Selection actions are available. Selection actions become available when the user selects some content in the document or editor. Inside an editor, selection actions can also become available when the user explicitly requests editor action UI, for example by tapping on the caret handle.In response to this callback, applications typically display a toolbar containing the selection actions. To perform a certain action, check if the action is available with
GeckoSession.SelectionActionDelegate.Selection.isActionAvailable(java.lang.String)
then either use the relevant helper method orGeckoSession.SelectionActionDelegate.Selection.execute(java.lang.String)
Once an
GeckoSession.SelectionActionDelegate.onHideAction(org.mozilla.geckoview.GeckoSession, int)
call (with particular reasons) or anotherGeckoSession.SelectionActionDelegate.onShowActionRequest(org.mozilla.geckoview.GeckoSession, org.mozilla.geckoview.GeckoSession.SelectionActionDelegate.Selection)
call is received, the previous Selection object is no longer usable.- Specified by:
onShowActionRequest
in interfaceGeckoSession.SelectionActionDelegate
- Parameters:
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.
-
onHideAction
Description copied from interface:GeckoSession.SelectionActionDelegate
Previous actions are no longer available due to the user interacting with the page. Applications typically hide the action toolbar in response.- Specified by:
onHideAction
in interfaceGeckoSession.SelectionActionDelegate
- Parameters:
session
- The GeckoSession that initiated the callback.reason
- The reason that actions are no longer available, as one of theHIDE_REASON_*
constants.
-
onShowClipboardPermissionRequest
public GeckoResult<AllowOrDeny> onShowClipboardPermissionRequest(GeckoSession session, GeckoSession.SelectionActionDelegate.ClipboardPermission permission) Show action mode bar to request clipboard permission- Specified by:
onShowClipboardPermissionRequest
in interfaceGeckoSession.SelectionActionDelegate
- Parameters:
session
- The GeckoSession that initiated the callback.permission
- AnGeckoSession.SelectionActionDelegate.ClipboardPermission
describing the permission being requested.- Returns:
- A
GeckoResult
withAllowOrDeny
, determining the response to the permission request for this site.
-
onDismissClipboardPermissionRequest
Dismiss action mode for requesting clipboard permission popup or model.- Specified by:
onDismissClipboardPermissionRequest
in interfaceGeckoSession.SelectionActionDelegate
- Parameters:
session
- The GeckoSession that initiated the callback.
-