androidx.glance.action
Interfaces
Action |
An Action defines the actions a user can take. |
Classes
ActionParameters |
Action parameters, used to pass information to an |
ActionParameters.Key |
Key for |
ActionParameters.Pair |
Key Value pairs for Parameters. |
MutableActionParameters |
Mutable version of |
Constants summary
const @DrawableRes Int |
NoRippleOverride = 0Constant. |
Top-level functions summary
Action |
@Composable |
ActionParameters |
actionParametersOf(vararg pairs: ActionParameters.Pair<Any>)Returns a new read-only Parameters, from the specified contents. |
inline Action |
<T : Activity> actionStartActivity(parameters: ActionParameters)Creates an |
Action |
<T : Activity> actionStartActivity(Creates an |
Action |
actionStartActivity(Creates an |
inline Action |
@ExperimentalGlanceApiCreates an |
Action |
@ExperimentalGlanceApiCreates an |
Action |
@ExperimentalGlanceApiCreates an |
MutableActionParameters |
mutableActionParametersOf(vararg pairs: ActionParameters.Pair<Any>)Returns a new MutableParameters, from the specified contents. |
Extension functions summary
GlanceModifier |
@ComposableRun |
GlanceModifier |
GlanceModifier.clickable(onClick: Action)Apply an |
GlanceModifier |
GlanceModifier.clickable(Apply an |
GlanceModifier |
@ComposableRun |
GlanceModifier |
@ComposableRun |
MutableActionParameters |
Gets a mutable copy of Parameters, containing all key value pairs. |
ActionParameters |
Gets a read-only copy of Parameters, containing all key value pairs. |
ActionParameters.Key<T> |
<T : Any> Preferences.Key<T>.toParametersKey()Creates an action key from a preferences key. |
Constants
NoRippleOverride
const val NoRippleOverride = 0: @DrawableRes Int
Constant. Tells the system that there is no ripple override. When this is passed, the system will use default behavior for the ripple.
Top-level functions
action
@Composable
fun action(key: String? = null, block: () -> Unit): Action
Create an Action that runs block when triggered.
| Parameters | |
|---|---|
key: String? = null |
A stable and unique key that identifies this action. This key is saved in the PendingIntent for the UI element, and used to trigger this action when the element is clicked. If not provided we use |
block: () -> Unit |
the function to be run when this action is triggered. |
actionParametersOf
fun actionParametersOf(vararg pairs: ActionParameters.Pair<Any>): ActionParameters
Returns a new read-only Parameters, from the specified contents. The key element in the given pairs will point to the corresponding value element. All values must be either of primitive or Parcelable types.
If multiple pairs have the same key, the resulting map will contain only the value from the last of those pairs.
actionStartActivity
inline fun <T : Activity> actionStartActivity(
parameters: ActionParameters = actionParametersOf()
): Action
Creates an Action that launches the specified Activity when triggered.
| Parameters | |
|---|---|
parameters: ActionParameters = actionParametersOf() |
the parameters associated with the action. Parameter values will be added to the activity intent, keyed by the parameter key name string. |
actionStartActivity
fun <T : Activity> actionStartActivity(
activity: Class<T>,
parameters: ActionParameters = actionParametersOf()
): Action
Creates an Action that launches the specified Activity when triggered.
| Parameters | |
|---|---|
activity: Class<T> |
class of the activity to launch |
parameters: ActionParameters = actionParametersOf() |
the parameters associated with the action. Parameter values will be added to the activity intent, keyed by the parameter key name string. |
actionStartActivity
fun actionStartActivity(
componentName: ComponentName,
parameters: ActionParameters = actionParametersOf()
): Action
Creates an Action that launches the Activity specified by the given ComponentName.
| Parameters | |
|---|---|
componentName: ComponentName |
component of the activity to launch |
parameters: ActionParameters = actionParametersOf() |
the parameters associated with the action. Parameter values will be added to the activity intent, keyed by the parameter key name string. |
actionStartActivity
@ExperimentalGlanceApi
inline fun <T : Activity> actionStartActivity(
parameters: ActionParameters = actionParametersOf(),
activityOptions: Bundle? = null
): Action
Creates an Action that launches the specified Activity when triggered.
| Parameters | |
|---|---|
parameters: ActionParameters = actionParametersOf() |
the parameters associated with the action. Parameter values will be added to the activity intent, keyed by the parameter key name string. |
activityOptions: Bundle? = null |
Additional options built from an |
actionStartActivity
@ExperimentalGlanceApi
fun <T : Activity> actionStartActivity(
activity: Class<T>,
parameters: ActionParameters = actionParametersOf(),
activityOptions: Bundle? = null
): Action
Creates an Action that launches the specified Activity when triggered.
| Parameters | |
|---|---|
activity: Class<T> |
class of the activity to launch |
parameters: ActionParameters = actionParametersOf() |
the parameters associated with the action. Parameter values will be added to the activity intent, keyed by the parameter key name string. |
activityOptions: Bundle? = null |
Additional options built from an |
actionStartActivity
@ExperimentalGlanceApi
fun actionStartActivity(
componentName: ComponentName,
parameters: ActionParameters = actionParametersOf(),
activityOptions: Bundle? = null
): Action
Creates an Action that launches the Activity specified by the given ComponentName.
| Parameters | |
|---|---|
componentName: ComponentName |
component of the activity to launch |
parameters: ActionParameters = actionParametersOf() |
the parameters associated with the action. Parameter values will be added to the activity intent, keyed by the parameter key name string. |
activityOptions: Bundle? = null |
Additional options built from an |
mutableActionParametersOf
fun mutableActionParametersOf(vararg pairs: ActionParameters.Pair<Any>): MutableActionParameters
Returns a new MutableParameters, from the specified contents. The key element in the given pairs will point to the corresponding value element. All values must be either of primitive or Parcelable types.
If multiple pairs have the same key, the resulting Parameters will contain only the value from the last of those pairs.
Extension functions
clickable
@Composable
fun GlanceModifier.clickable(block: () -> Unit): GlanceModifier
Run block in response to a user click.
The lambda provided to this function will use the androidx.compose.runtime.currentCompositeKeyHash to set a key for this lambda that will be used to trigger it when the corresponding UI element is clicked. Since that key is based on the location within the composition, it will be identical for lambdas generated in a loop (if not using androidx.compose.runtime.key).
To avoid this, prefer setting explicit keys for your lambdas, by using the overload of clickable that accepts a key parameter.
| Parameters | |
|---|---|
block: () -> Unit |
The action to run. |
clickable
fun GlanceModifier.clickable(onClick: Action): GlanceModifier
Apply an Action, to be executed in response to a user click.
| Parameters | |
|---|---|
onClick: Action |
The action to run. |
clickable
fun GlanceModifier.clickable(
onClick: Action,
rippleOverride: @DrawableRes Int = NoRippleOverride
): GlanceModifier
Apply an Action, to be executed in response to a user click.
| Parameters | |
|---|---|
onClick: Action |
The action to run. |
rippleOverride: @DrawableRes Int = NoRippleOverride |
A drawable resource to use as the onClick ripple. Use |
clickable
@Composable
fun GlanceModifier.clickable(
rippleOverride: @DrawableRes Int = NoRippleOverride,
block: () -> Unit
): GlanceModifier
Run block in response to a user click.
The lambda provided to this function will use the androidx.compose.runtime.currentCompositeKeyHash to set a key for this lambda that will be used to trigger it when the corresponding UI element is clicked. Since that key is based on the location within the composition, it will be identical for lambdas generated in a loop (if not using androidx.compose.runtime.key).
To avoid this, prefer setting explicit keys for your lambdas, by using the overload of clickable that accepts a key parameter.
| Parameters | |
|---|---|
rippleOverride: @DrawableRes Int = NoRippleOverride |
A drawable resource to use as the onClick ripple. Use |
block: () -> Unit |
The action to run. |
clickable
@Composable
fun GlanceModifier.clickable(
key: String? = null,
rippleOverride: @DrawableRes Int = NoRippleOverride,
block: () -> Unit
): GlanceModifier
Run block in response to a user click.
| Parameters | |
|---|---|
key: String? = null |
A stable and unique key that identifies this action. This key is saved in the PendingIntent for the UI element, and used to trigger this action when the element is clicked. If not provided we use |
rippleOverride: @DrawableRes Int = NoRippleOverride |
A drawable resource to use as the onClick ripple. Use |
block: () -> Unit |
The action to run. |
toMutableParameters
fun ActionParameters.toMutableParameters(): MutableActionParameters
Gets a mutable copy of Parameters, containing all key value pairs. This can be used to edit the parameter data without creating a new object.
This is similar to Map.toMutableMap.
| Returns | |
|---|---|
MutableActionParameters |
a MutableParameters with all the same parameters as this Parameters |
toParameters
fun ActionParameters.toParameters(): ActionParameters
Gets a read-only copy of Parameters, containing all key value pairs.
This is similar to Map.toMap.
| Returns | |
|---|---|
ActionParameters |
a copy of this Parameters |
toParametersKey
fun <T : Any> Preferences.Key<T>.toParametersKey(): ActionParameters.Key<T>
Creates an action key from a preferences key.