Action


@CarProtocol
public final class Action


Represents an action with an optional icon and text.

Actions may be displayed differently depending on the template or model they are added to. For example, the host may decide to display an action as a floating action button (FAB) when displayed over a map, as a button when displayed in a Pane, or as a simple icon with no title when displayed within a Row.

Standard actions A set of standard, built-in Action instances is available with a few of the common basic actions car apps may need (for example a BACK action).

With the exception of APP_ICON and BACK, an app can provide a custom title and icon for the action. However, depending on the template the action belongs to, the title or icon may be disallowed. If such restrictions apply, the documentation of the APIs that consume the action will note them accordingly.

Summary

Nested types

public final class Action.Builder

A builder of Action.

Constants

static final @NonNull Action

A standard action to show the app's icon.

static final @NonNull Action

A standard action to navigate back in the user interface.

static final @NonNull Action

A standard action to show the message compose button

static final int
@RequiresCarApi(value = 5)
FLAG_DEFAULT = 4

Indicates that this action is the default action out of a set of other actions.

static final int

Indicates that this action will not fade in/out inside an ActionStrip.

static final int
@RequiresCarApi(value = 4)
FLAG_PRIMARY = 1

Indicates that this action is the most important one, out of a set of other actions.

static final @NonNull Action

A standard action to toggle the pan mode in a map-based template.

static final int

An action representing an app's icon.

static final int
TYPE_BACK = 65539

An action to navigate back in the user interface.

static final int

An action to allow user compose a message.

static final int

An app-defined custom action type.

static final int
TYPE_PAN = 65540

An action to toggle the pan mode in a map-based template.

Public methods

boolean
@Nullable CarColor

Returns the CarColor used for the background color of the action.

int
@RequiresCarApi(value = 4)
getFlags()

Returns flags affecting how this action should be treated

@Nullable CarIcon

Returns the CarIcon to display in the action or null if the action does not have an icon.

@Nullable OnClickDelegate

Returns the OnClickDelegate that should be used for this action.

@Nullable CarText

Returns the title displayed in the action or null if the action does not have a title.

int

Returns the type of the action.

int
boolean
@RequiresCarApi(value = 5)
isEnabled()

Returns true if the action is enabled.

boolean

Returns whether the action is a standard action such as BACK.

@NonNull String
static @NonNull String
typeToString(int type)

Converts the given type into a string representation.

Constants

APP_ICON

Added in 1.0.0
public static final @NonNull Action APP_ICON

A standard action to show the app's icon.

This action is non-interactive.

BACK

Added in 1.0.0
public static final @NonNull Action BACK

A standard action to navigate back in the user interface.

The default behavior for a back press will call pop.

To override the default behavior, register a OnBackPressedCallback via addCallback, which you can retrieve from getOnBackPressedDispatcher.

COMPOSE_MESSAGE

Added in 1.4.0
@ExperimentalCarApi
@RequiresCarApi(value = 7)
public static final @NonNull Action COMPOSE_MESSAGE

A standard action to show the message compose button

This action is interactive.

FLAG_DEFAULT

Added in 1.3.0
@RequiresCarApi(value = 5)
public static final int FLAG_DEFAULT = 4

Indicates that this action is the default action out of a set of other actions.

The action with this flag may be treated differently by the host depending on where they are used. For example, it may be set as the default action to be triggered when the Alerter times out in the AlertCard. The first action with the FLAG_DEFAULT in an action list will be treated as the Default Action. See the documentation on where the Action is added for more details on any restriction(s) that might apply.

FLAG_IS_PERSISTENT

Added in 1.2.0
@RequiresCarApi(value = 5)
public static final int FLAG_IS_PERSISTENT = 2

Indicates that this action will not fade in/out inside an ActionStrip.

FLAG_PRIMARY

Added in 1.1.0
@RequiresCarApi(value = 4)
public static final int FLAG_PRIMARY = 1

Indicates that this action is the most important one, out of a set of other actions.

The action with this flag may be treated differently by the host depending on where they are used. For example, it may be colored or ordered differently to align with the vehicle's look and feel. See the documentation on where the Action is added for more details on any restriction(s) that might apply.

PAN

Added in 1.1.0
public static final @NonNull Action PAN

A standard action to toggle the pan mode in a map-based template.

If the app does not provide a custom icon, a default pan icon will be used.

You can set a custom icon in a pan action with the following code:

Action panAction = new Action.Builder(Action.PAN).setIcon(customIcon).build();

TYPE_APP_ICON

Added in 1.0.0
public static final int TYPE_APP_ICON = 65538

An action representing an app's icon.

See also
APP_ICON

TYPE_BACK

Added in 1.0.0
public static final int TYPE_BACK = 65539

An action to navigate back in the user interface.

See also
BACK

TYPE_COMPOSE_MESSAGE

Added in 1.4.0
@ExperimentalCarApi
@RequiresCarApi(value = 7)
public static final int TYPE_COMPOSE_MESSAGE = 65541

An action to allow user compose a message.

TYPE_CUSTOM

Added in 1.0.0
public static final int TYPE_CUSTOM = 1

An app-defined custom action type.

TYPE_PAN

Added in 1.1.0
public static final int TYPE_PAN = 65540

An action to toggle the pan mode in a map-based template.

Public methods

equals

public boolean equals(@Nullable Object other)

getBackgroundColor

Added in 1.0.0
public @Nullable CarColor getBackgroundColor()

Returns the CarColor used for the background color of the action.

getFlags

Added in 1.1.0
@RequiresCarApi(value = 4)
public int getFlags()

Returns flags affecting how this action should be treated

getIcon

Added in 1.0.0
public @Nullable CarIcon getIcon()

Returns the CarIcon to display in the action or null if the action does not have an icon.

See also
setIcon

getOnClickDelegate

Added in 1.0.0
public @Nullable OnClickDelegate getOnClickDelegate()

Returns the OnClickDelegate that should be used for this action.

getTitle

Added in 1.0.0
public @Nullable CarText getTitle()

Returns the title displayed in the action or null if the action does not have a title.

See also
setTitle

getType

Added in 1.0.0
public int getType()

Returns the type of the action.

hashCode

public int hashCode()

isEnabled

Added in 1.3.0
@RequiresCarApi(value = 5)
public boolean isEnabled()

Returns true if the action is enabled.

isStandard

Added in 1.0.0
public boolean isStandard()

Returns whether the action is a standard action such as BACK.

toString

public @NonNull String toString()

typeToString

Added in 1.0.0
public static @NonNull String typeToString(int type)

Converts the given type into a string representation.