Banner.Builder


public final class Banner.Builder


A builder of Banner.

Summary

Public constructors

Returns an empty Builder instance.

Public methods

@NonNull Banner.Builder

Adds an Action below the title and subtitle of the Banner.

@NonNull Banner.Builder

Adds an Action to the trailing part of the banner.

@NonNull Banner.Builder

Adds a CarIcon to be displayed as an icon to the trailing part of the banner.

@NonNull Banner.Builder

Adds a CarIcon to be displayed as an image to the trailing part of the banner.

@NonNull Banner

Constructs the Banner defined by this builder.

@NonNull Banner.Builder

Sets the Background of the banner.

@NonNull Banner.Builder

Sets the leading element in this banner to be a CarIcon displayed as an icon.

@NonNull Banner.Builder

Sets the leading element in this banner to be a CarIcon displayed as an image.

@NonNull Banner.Builder

Sets the OnClickListener to be called back when the banner is clicked.

@NonNull Banner.Builder

Sets the subtitle of the banner.

@NonNull Banner.Builder

Sets the subtitle of the banner.

@NonNull Banner.Builder

Sets the title of the banner.

@NonNull Banner.Builder

Sets the title of the banner.

Public constructors

Builder

Added in 1.8.0
public Builder()

Returns an empty Builder instance.

Public methods

addBelowAction

Added in 1.8.0
public @NonNull Banner.Builder addBelowAction(@NonNull Action action)

Adds an Action below the title and subtitle of the Banner.

A Banner's below actions must conform to ACTION_CONSTRAINTS_BANNER_BELOW

addTrailingAction

Added in 1.8.0
public @NonNull Banner.Builder addTrailingAction(@NonNull Action action)

Adds an Action to the trailing part of the banner.

A banner can have at most 2 trailing elements

action must conform to ACTION_CONSTRAINTS_BANNER_TRAILING.

Throws
java.lang.NullPointerException

if action is null

java.lang.IllegalArgumentException

if there are already 2 trailing elements

addTrailingIcon

Added in 1.8.0
public @NonNull Banner.Builder addTrailingIcon(@NonNull CarIcon icon)

Adds a CarIcon to be displayed as an icon to the trailing part of the banner.

A banner can have at most 2 trailing elements

Throws
java.lang.NullPointerException

if icon is null

java.lang.IllegalArgumentException

if there are already 2 trailing elements

addTrailingImage

Added in 1.8.0
public @NonNull Banner.Builder addTrailingImage(@NonNull CarIcon image)

Adds a CarIcon to be displayed as an image to the trailing part of the banner.

A banner can have at most 2 trailing elements

Throws
java.lang.NullPointerException

if image is null

java.lang.IllegalArgumentException

if there are already 2 trailing elements

build

Added in 1.8.0
public @NonNull Banner build()

Constructs the Banner defined by this builder.

Throws
java.lang.IllegalStateException

if the title is null or empty

java.lang.IllegalStateException

if there are more than 4 elements across the banner's leading and trailing elements lists OR more than 2 of these elements are Actions

setBackground

Added in 1.9.0-alpha01
public @NonNull Banner.Builder setBackground(@NonNull Background background)

Sets the Background of the banner.

The background must conform to COLOR_ONLY.

Throws
java.lang.NullPointerException

if background is null

java.lang.IllegalArgumentException

if an unsupported background is added

setLeadingIcon

Added in 1.9.0-alpha01
public @NonNull Banner.Builder setLeadingIcon(@NonNull CarIcon icon)

Sets the leading element in this banner to be a CarIcon displayed as an icon.

Only a single leading icon or image can be set, so this will overwrite calls to setLeadingImage.

This is visually distinct from setLeadingImage as icons are smaller due to added padding, and are expected to be tinted.

Throws
java.lang.NullPointerException

if icon is null

setLeadingImage

Added in 1.9.0-alpha01
public @NonNull Banner.Builder setLeadingImage(@NonNull CarIcon image)

Sets the leading element in this banner to be a CarIcon displayed as an image.

Only a single leading icon or image can be set, so this will overwrite calls to setLeadingIcon.

This is visually distinct from setLeadingIcon as images have no added padding, and are not expected to be tinted.

Throws
java.lang.NullPointerException

if image is null

setOnClickListener

Added in 1.8.0
public @NonNull Banner.Builder setOnClickListener(@NonNull OnClickListener onClickListener)

Sets the OnClickListener to be called back when the banner is clicked.

Note that the listener relates to UI events and will be executed on the main thread using getMainLooper.

Throws
java.lang.NullPointerException

if onClickListener is null

setSubtitle

Added in 1.8.0
public @NonNull Banner.Builder setSubtitle(@NonNull CarText subtitle)

Sets the subtitle of the banner.

The subtitle allows TEXT_WITH_COLORS_AND_ICON spans to be added.

The subtitle is automatically truncated if it's too long.

Throws
java.lang.NullPointerException

if subtitle is null

java.lang.IllegalArgumentException

if any unsupported span types are added

setSubtitle

Added in 1.8.0
public @NonNull Banner.Builder setSubtitle(@NonNull CharSequence subtitle)

Sets the subtitle of the banner.

The subtitle allows TEXT_WITH_COLORS_AND_ICON spans to be added.

The subtitle is automatically truncated if it's too long.

Throws
java.lang.NullPointerException

if subtitle is null

java.lang.IllegalArgumentException

if any unsupported span types are added

setTitle

Added in 1.8.0
public @NonNull Banner.Builder setTitle(@NonNull CarText title)

Sets the title of the banner.

The title allows TEXT_AND_ICON spans to be added.

Throws
java.lang.NullPointerException

if title is null

java.lang.IllegalArgumentException

if any unsupported span types are added

setTitle

Added in 1.8.0
public @NonNull Banner.Builder setTitle(@NonNull CharSequence title)

Sets the title of the banner.

The title allows TEXT_AND_ICON spans to be added.

Throws
java.lang.NullPointerException

if title is null

java.lang.IllegalArgumentException

if any unsupported span types are added