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.

Composables

action

Create an Action that runs block when triggered.

clickable

Run block in response to a user click.

Constants summary

const @DrawableRes Int

Constant.

Top-level functions summary

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

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.

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

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 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. 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

GlanceModifier.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.

GlanceModifier.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.

ActionParameters.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

ActionParameters.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

Preferences.Key.toParametersKey

fun <T : Any> Preferences.Key<T>.toParametersKey(): ActionParameters.Key<T>

Creates an action key from a preferences key.