androidx.glance.action

Interfaces

Action

An Action defines the actions a user can take.

Classes

ActionParameters

Action parameters, used to pass information to an Action.

ActionParameters.Key

Key for ActionParameters values.

ActionParameters.Pair

Key Value pairs for Parameters.

MutableActionParameters

Mutable version of ActionParameters.

Constants summary

const @DrawableRes Int

Constant.

Top-level functions summary

Action
@Composable
action(key: String?, block: () -> Unit)

Create an Action that runs block when triggered.

ActionParameters

Returns a new read-only Parameters, from the specified contents.

inline Action

Creates an Action that launches the specified Activity when triggered.

Action
<T : Activity> actionStartActivity(
    activity: Class<T>,
    parameters: ActionParameters
)

Creates an Action that launches the specified Activity when triggered.

Action
actionStartActivity(
    componentName: ComponentName,
    parameters: ActionParameters
)

Creates an Action that launches the Activity specified by the given ComponentName.

inline Action
@ExperimentalGlanceApi
<T : Activity> actionStartActivity(
    parameters: ActionParameters,
    activityOptions: Bundle?
)

Creates an Action that launches the specified Activity when triggered.

Action
@ExperimentalGlanceApi
<T : Activity> actionStartActivity(
    activity: Class<T>,
    parameters: ActionParameters,
    activityOptions: Bundle?
)

Creates an Action that launches the specified Activity when triggered.

Action
@ExperimentalGlanceApi
actionStartActivity(
    componentName: ComponentName,
    parameters: ActionParameters,
    activityOptions: Bundle?
)

Creates an Action that launches the Activity specified by the given ComponentName.

MutableActionParameters

Returns a new MutableParameters, from the specified contents.

Extension functions summary

GlanceModifier

Run block in response to a user click.

GlanceModifier

Apply an Action, to be executed in response to a user click.

GlanceModifier
GlanceModifier.clickable(
    onClick: Action,
    rippleOverride: @DrawableRes Int
)

Apply an Action, to be executed in response to a user click.

GlanceModifier
@Composable
GlanceModifier.clickable(
    rippleOverride: @DrawableRes Int,
    block: () -> Unit
)

Run block in response to a user click.

GlanceModifier
@ExperimentalGlanceApi
@Composable
GlanceModifier.clickable(
    key: String?,
    rippleOverride: @DrawableRes Int,
    block: () -> Unit
)

Run block in response to a user click.

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>

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

An optional key to be used as a key for the action. If not provided we use the key that is automatically generated by the Compose runtime which is unique for every exact code location in the composition tree.

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.

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 android.app.ActivityOptions to apply to an activity start.

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 android.app.ActivityOptions to apply to an activity start.

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 android.app.ActivityOptions to apply to an activity start.

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.

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.

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 NoRippleOverride if no custom behavior is needed.

clickable

@Composable
fun GlanceModifier.clickable(
    rippleOverride: @DrawableRes Int = NoRippleOverride,
    block: () -> Unit
): GlanceModifier

Run block in response to a user click.

Parameters
rippleOverride: @DrawableRes Int = NoRippleOverride

A drawable resource to use as the onClick ripple. Use NoRippleOverride if no custom behavior is needed.

block: () -> Unit

The action to run.

clickable

@ExperimentalGlanceApi
@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 the action for this element. This ensures that the correct action is triggered, especially in cases of items that change order. If not provided we use the key that is automatically generated by the Compose runtime, which is unique for every exact code location in the composition tree.

rippleOverride: @DrawableRes Int = NoRippleOverride

A drawable resource to use as the onClick ripple. Use NoRippleOverride if no custom behavior is needed.

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.