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
FieldsModifier and TypeFieldDescriptionprotected static final StringIntent action for processing text.protected ActionModeThe current action mode, if any.protected final ActivityThe activity associated with this delegate.protected booleanWhether the menu has been repopulated.The current text selection.protected GeckoSessionThe current GeckoSession associated with selection.protected final booleanWhether to use floating toolbar for selection actions.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
ConstructorsConstructorDescriptionBasicSelectionActionDelegate(Activity activity) Construct a BasicSelectionActionDelegate.BasicSelectionActionDelegate(Activity activity, boolean useFloatingToolbar) Construct a BasicSelectionActionDelegate. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGet whether text actions from other apps are enabled.voidClear the current selection, if possible.voidenableExternalActions(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.booleanProvides access to whether there are text selection actions available.protected booleanReturn whether an action is presently available.booleanonActionItemClicked(ActionMode actionMode, MenuItem menuItem) booleanonCreateActionMode(ActionMode actionMode, Menu menu) voidonDestroyActionMode(ActionMode actionMode) voidDismiss action mode for requesting clipboard permission popup or model.voidonGetContentRect(ActionMode mode, View view, Rect outRect) Called to get the content rectangle for the selection.voidonHideAction(GeckoSession session, int reason) Previous actions are no longer available due to the user interacting with the page.booleanonPrepareActionMode(ActionMode actionMode, Menu menu) voidonShowActionRequest(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 booleanperformAction(String id, MenuItem item) Perform the specified action.protected voidprepareAction(String id, MenuItem item) Prepare a menu item corresponding to a certain action.
-
Field Details
-
ACTION_PROCESS_TEXT
Intent action for processing text.- See Also:
-
mActivity
The activity associated with this delegate. -
mUseFloatingToolbar
protected final boolean mUseFloatingToolbarWhether to use floating toolbar for selection actions. -
mActionMode
The current action mode, if any. -
mSession
The current GeckoSession associated with selection. -
mSelection
The current text selection. -
mRepopulatedMenu
protected boolean mRepopulatedMenuWhether the menu has been repopulated.
-
-
Constructor Details
-
BasicSelectionActionDelegate
Construct a BasicSelectionActionDelegate.- Parameters:
activity- The activity to associate with this delegate
-
BasicSelectionActionDelegate
Construct a BasicSelectionActionDelegate.- Parameters:
activity- The activity to associate with this delegateuseFloatingToolbar- Whether to use floating toolbar for selection
-
-
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.Selectionattached to the current action menu.nullif no action menu is active.
-
clearSelection
public void clearSelection()Clear the current selection, if possible. -
onCreateActionMode
- Specified by:
onCreateActionModein interfaceActionMode.Callback
-
onPrepareActionMode
- Specified by:
onPrepareActionModein interfaceActionMode.Callback
-
onActionItemClicked
- Specified by:
onActionItemClickedin interfaceActionMode.Callback
-
onDestroyActionMode
- Specified by:
onDestroyActionModein interfaceActionMode.Callback
-
onGetContentRect
Called to get the content rectangle for the selection.- Parameters:
mode- The action modeview- The viewoutRect- The rectangle to be filled with content bounds
-
onShowActionRequest
public void onShowActionRequest(GeckoSession session, GeckoSession.SelectionActionDelegate.Selection selection) Description copied from interface:GeckoSession.SelectionActionDelegateSelection 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:
onShowActionRequestin 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.SelectionActionDelegatePrevious actions are no longer available due to the user interacting with the page. Applications typically hide the action toolbar in response.- Specified by:
onHideActionin 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:
onShowClipboardPermissionRequestin interfaceGeckoSession.SelectionActionDelegate- Parameters:
session- The GeckoSession that initiated the callback.permission- AnGeckoSession.SelectionActionDelegate.ClipboardPermissiondescribing the permission being requested.- Returns:
- A
GeckoResultwithAllowOrDeny, determining the response to the permission request for this site.
-
onDismissClipboardPermissionRequest
Dismiss action mode for requesting clipboard permission popup or model.- Specified by:
onDismissClipboardPermissionRequestin interfaceGeckoSession.SelectionActionDelegate- Parameters:
session- The GeckoSession that initiated the callback.
-