android-components / mozilla.components.feature.prompts / PromptFeature

PromptFeature

class PromptFeature : LifecycleAwareFeature, PermissionsFeature, Prompter (source)

Feature for displaying native dialogs for html elements like: input type date, file, time, color, option, menu, authentication, confirmation and alerts.

There are some requests that are handled with intents instead of dialogs, like file choosers and others. For this reason, you have to keep the feature aware of the flow of requesting data from other apps, overriding onActivityResult in your Activity or Fragment and forward its calls to onActivityResult.

This feature will subscribe to the currently selected session and display a suitable native dialog based on Session.Observer.onPromptRequested events. Once the dialog is closed or the user selects an item from the dialog the related PromptRequest will be consumed.

Constructors

Name Summary
<init> PromptFeature(activity: <ERROR CLASS>, store: BrowserStore, customTabId: String? = null, fragmentManager: FragmentManager, shareDelegate: ShareDelegate = DefaultShareDelegate(), loginValidationDelegate: LoginValidationDelegate? = null, isSaveLoginEnabled: () -> Boolean = { false }, onNeedToRequestPermissions: OnNeedToRequestPermissions)
PromptFeature(fragment: Fragment, store: BrowserStore, customTabId: String? = null, fragmentManager: FragmentManager, shareDelegate: ShareDelegate = DefaultShareDelegate(), loginValidationDelegate: LoginValidationDelegate? = null, isSaveLoginEnabled: () -> Boolean = { false }, onNeedToRequestPermissions: OnNeedToRequestPermissions)
PromptFeature(activity: <ERROR CLASS>? = null, fragment: Fragment? = null, store: BrowserStore, customTabId: String? = null, fragmentManager: FragmentManager, onNeedToRequestPermissions: OnNeedToRequestPermissions)

Properties

Name Summary
loginValidationDelegate val loginValidationDelegate: LoginValidationDelegate?
Validates whether or not a given Login may be stored.
onNeedToRequestPermissions val onNeedToRequestPermissions: OnNeedToRequestPermissions
A callback invoked when permissions need to be requested before a prompt (e.g. a file picker) can be displayed. Once the request is completed, onPermissionsResult needs to be invoked.

Functions

Name Summary
onActivityResult fun onActivityResult(requestCode: Int, resultCode: Int, intent: <ERROR CLASS>?): Unit
Notifies the feature of intent results for prompt requests handled by other apps like file chooser requests.
onCancel fun onCancel(sessionId: String): Unit
Invoked when a dialog is dismissed. This consumes the PromptFeature value from the session indicated by sessionId.
onClear fun onClear(sessionId: String): Unit
Invoked when the user is requesting to clear the selected value from the dialog. This consumes the PromptFeature value from the SessionState indicated by sessionId.
onConfirm fun onConfirm(sessionId: String, value: Any?): Unit
Invoked when the user confirms the action on the dialog. This consumes the PromptFeature value from the SessionState indicated by sessionId.
onPermissionsResult fun onPermissionsResult(permissions: Array<String>, grantResults: IntArray): Unit
Notifies the feature that the permissions request was completed. It will then either process or dismiss the prompt request.
start fun start(): Unit
Starts observing the selected session to listen for prompt requests and displays a dialog when needed.
stop fun stop(): Unit
Stops observing the selected session for incoming prompt requests.

Extension Functions

Name Summary
loadResourceAsString fun Any.loadResourceAsString(path: String): String
Loads a file from the resources folder and returns its content as a string object.