Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

GridItem.Builder

public static final class GridItem.Builder
extends Object

java.lang.Object
   ↳ androidx.car.app.model.GridItem.Builder


A builder of GridItem.

Summary

Public constructors

Builder()

Returns an empty GridItem.Builder instance.

Public methods

GridItem build()

Constructs the GridItem defined by this builder.

GridItem.Builder setImage(CarIcon image, int imageType)

Sets an image to show in the grid item with the given imageType.

GridItem.Builder setImage(CarIcon image)

Sets an image to show in the grid item with the default size GridItem.IMAGE_TYPE_LARGE.

GridItem.Builder setLoading(boolean isLoading)

Sets whether the item is in a loading state.

GridItem.Builder setOnClickListener(OnClickListener onClickListener)

Sets the OnClickListener to be called back when the grid item is clicked, or null to make the grid item non-clickable.

GridItem.Builder setText(CharSequence text)

Sets a secondary text string to the grid item that is displayed below the title.

GridItem.Builder setText(CarText text)

Sets a secondary text string to the grid item that is displayed below the title.

GridItem.Builder setTitle(CharSequence title)

Sets the title of the GridItem.

GridItem.Builder setTitle(CarText title)

Sets the title of the GridItem.

Inherited methods

Public constructors

Builder

public Builder ()

Returns an empty GridItem.Builder instance.

Public methods

build

public GridItem build ()

Constructs the GridItem defined by this builder.

Returns
GridItem

Throws
IllegalStateException if the grid item's title is not set, if the grid item's image is set when it is loading or vice versa, or if the grid item is loading but the click listener is set

setImage

public GridItem.Builder setImage (CarIcon image, 
                int imageType)

Sets an image to show in the grid item with the given imageType.

For a custom CarIcon, its IconCompat instance can be of IconCompat.TYPE_BITMAP, IconCompat.TYPE_RESOURCE, or IconCompat.TYPE_URI.

Image Sizing Guidance

If the input image's size exceeds the sizing requirements for the given image type in either one of the dimensions, it will be scaled down to be centered inside the bounding box while preserving the aspect ratio.

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

Parameters
image CarIcon: the CarIcon to display

imageType int: one of GridItem.IMAGE_TYPE_ICON or GridItem.IMAGE_TYPE_LARGE

Returns
GridItem.Builder

Throws
NullPointerException if image is null

setImage

public GridItem.Builder setImage (CarIcon image)

Sets an image to show in the grid item with the default size GridItem.IMAGE_TYPE_LARGE.

Parameters
image CarIcon

Returns
GridItem.Builder

Throws
NullPointerException if image is null

setLoading

public GridItem.Builder setLoading (boolean isLoading)

Sets whether the item is in a loading state.

If set to true, the UI shows a loading indicator where the grid item would be otherwise. The caller is expected to call Screen.invalidate() and send the new template content to the host once the data is ready. If set to false, the UI shows the item contents.

Parameters
isLoading boolean

Returns
GridItem.Builder

setOnClickListener

public GridItem.Builder setOnClickListener (OnClickListener onClickListener)

Sets the OnClickListener to be called back when the grid item is clicked, or null to make the grid item non-clickable.

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

Parameters
onClickListener OnClickListener

Returns
GridItem.Builder

Throws
NullPointerException if onClickListener is null

setText

public GridItem.Builder setText (CharSequence text)

Sets a secondary text string to the grid item that is displayed below the title.

The text's color can be customized with ForegroundCarColorSpan instances, any other spans will be ignored by the host.

Text Wrapping

This text is truncated at the end to fit in a single line below the title

Parameters
text CharSequence

Returns
GridItem.Builder

Throws
NullPointerException if text is null

setText

public GridItem.Builder setText (CarText text)

Sets a secondary text string to the grid item that is displayed below the title.

The text's color can be customized with ForegroundCarColorSpan instances, any other spans will be ignored by the host.

Text Wrapping

This text is truncated at the end to fit in a single line below the title

Parameters
text CarText

Returns
GridItem.Builder

Throws
NullPointerException if text is null

setTitle

public GridItem.Builder setTitle (CharSequence title)

Sets the title of the GridItem.

Spans are not supported in the input string.

Parameters
title CharSequence

Returns
GridItem.Builder

Throws
NullPointerException if title is null
IllegalArgumentException if title is empty

setTitle

public GridItem.Builder setTitle (CarText title)

Sets the title of the GridItem.

Spans are not supported in the input string.

Parameters
title CarText

Returns
GridItem.Builder

Throws
NullPointerException if title is null
IllegalArgumentException if title is empty