Alert.Builder


public final class Alert.Builder


A builder of Alert.

Summary

Public constructors

Builder(int alertId, @NonNull CarText title, long durationMillis)

Creates an Builder instance.

Public methods

@NonNull Alert.Builder

Adds the action to the list of actions on the alert.

@NonNull Alert

Constructs the Alert defined by this builder.

@NonNull Alert.Builder

Sets the AlertCallback to receive alert related events.

@NonNull Alert.Builder

Sets the icon to display in the alert.

@NonNull Alert.Builder

Sets the subtitle to display in the alert, with support for multiple length variants.

Public constructors

Builder

Added in 1.2.0
public Builder(int alertId, @NonNull CarText title, long durationMillis)

Creates an Builder instance.

Text spans are supported.

Parameters
int alertId

The unique identifier used for the alert. Alerts with the same id are considered equal.

@NonNull CarText title

The title of the alert.

long durationMillis

The maximum duration the alert can be shown in milli seconds.

Throws
java.lang.NullPointerException

if title is null

java.lang.IllegalArgumentException

if duration is not positive

See also
CarText

Public methods

addAction

Added in 1.2.0
public @NonNull Alert.Builder addAction(@NonNull Action action)

Adds the action to the list of actions on the alert.

An alert can have up to 2 actions.

Throws
java.lang.IllegalStateException

if more than 2 actions are added.

build

Added in 1.2.0
public @NonNull Alert build()

Constructs the Alert defined by this builder.

setCallback

Added in 1.2.0
public @NonNull Alert.Builder setCallback(@NonNull AlertCallback callback)

Sets the AlertCallback to receive alert related events.

Throws
java.lang.NullPointerException

if callback is null

setIcon

Added in 1.2.0
public @NonNull Alert.Builder setIcon(@NonNull CarIcon icon)

Sets the icon to display in the alert.

Icon Sizing Guidance To minimize scaling artifacts across a wide range of car screens, apps should provide icons targeting a 88 x 88 dp bounding box. If the icon exceeds this maximum size in either one of the dimensions, it will be scaled down to be centered inside the bounding box while preserving its aspect ratio.

See CarIcon for more details related to providing icon and image resources that work with different car screen pixel densities.

Throws
java.lang.NullPointerException

if icon is null

setSubtitle

Added in 1.2.0
public @NonNull Alert.Builder setSubtitle(@NonNull CarText subtitle)

Sets the subtitle to display in the alert, with support for multiple length variants.

Text spans are supported.

Throws
java.lang.NullPointerException

if subtitle is null

See also
CarText