GridItem.Builder
class GridItem.Builder
A builder of GridItem.
Summary
Public functions |
|
|---|---|
GridItem |
build()Constructs the |
GridItem.Builder |
Sets an image to show in the grid item with the default size |
GridItem.Builder |
@ExperimentalCarApiSets an image to show in the grid item with the given |
GridItem.Builder |
Sets an image to show in the grid item with the given |
GridItem.Builder |
@ExperimentalCarApiSets an image to show in the grid item with the given |
GridItem.Builder |
@ExperimentalCarApiSets whether this item can be included in indexed lists. |
GridItem.Builder |
setLoading(isLoading: Boolean)Sets whether the item is in a loading state. |
GridItem.Builder |
setOnClickListener(onClickListener: OnClickListener)Sets the |
GridItem.Builder |
Sets a secondary text string to the grid item that is displayed below the title, with support for multiple length variants. |
GridItem.Builder |
setText(text: CharSequence)Sets a secondary text string to the grid item that is displayed below the title. |
GridItem.Builder |
Sets the title of the |
GridItem.Builder |
setTitle(title: CharSequence?)Sets the title of the |
Public functions
build
fun build(): GridItem
Constructs the GridItem defined by this builder.
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the grid item's image is set when it is loading or vice versa, if the grid item is loading but the click listener is set, or if a badge is set and an image is not set |
setImage
fun setImage(image: CarIcon): GridItem.Builder
Sets an image to show in the grid item with the default size IMAGE_TYPE_LARGE.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
setImage |
setImage
@ExperimentalCarApi
fun setImage(image: CarIcon, badge: Badge): GridItem.Builder
Sets an image to show in the grid item with the given Badge to be displayed over the image, with the default size IMAGE_TYPE_LARGE.
A dot badge denotes some sort of call to action or notification and is displayed in the upper right corner of the image. An icon badge gives additional context about the image and is displayed in the lower right corner.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
setImage |
setImage
fun setImage(image: CarIcon, imageType: Int): GridItem.Builder
Sets an image to show in the grid item with the given imageType.
For a custom CarIcon, its androidx.core.graphics.drawable.IconCompat instance can be of TYPE_BITMAP, TYPE_RESOURCE, or TYPE_URI.
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 its 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 |
imageType: Int |
one of |
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setImage
@ExperimentalCarApi
fun setImage(image: CarIcon, imageType: Int, badge: Badge): GridItem.Builder
Sets an image to show in the grid item with the given imageType and given Badge to be displayed over the image.
A dot badge denotes a call to action or notification and is displayed in the upper right corner of the image. An icon badge gives additional context about the image and is displayed in the lower right corner.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
setImage |
setIndexable
@ExperimentalCarApi
fun setIndexable(indexable: Boolean): GridItem.Builder
Sets whether this item can be included in indexed lists. By default, this is set to true.
The host creates indexed lists to help users navigate through long lists more easily by sorting, filtering, or some other means.
For example, a media app may, by default, show a user's playlists sorted by date created. If the app provides these playlists via the SectionedItemTemplate and enables #isAlphabeticalIndexingAllowed, the user will be able to select a letter on a keyboard to jump to their playlists that start with that letter. When this happens, the list is reconstructed and sorted alphabetically, then shown to the user, jumping down to the letter. Items that are set to #setIndexable(false), do not show up in this new sorted list. Sticking with the media example, a media app may choose to hide things like "autogenerated playlists" from the list and only keep user created playlists.
Individual items can be set to be included or excluded from filtered lists, but it's also possible to enable/disable the creation of filtered lists as a whole via the template's API (eg. SectionedItemTemplate
.Builder#setAlphabeticalIndexingStrategy(int)).
setLoading
fun setLoading(isLoading: Boolean): GridItem.Builder
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 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.
setOnClickListener
fun setOnClickListener(onClickListener: OnClickListener): GridItem.Builder
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 getMainLooper
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setText
fun setText(text: CarText): GridItem.Builder
Sets a secondary text string to the grid item that is displayed below the title, with support for multiple length variants.
text must conform to CarTextConstraints.TEXT_WITH_COLORS in Car API 7 and below, and CarTextConstraints.TEXT_WITH_COLORS_AND_ICON in Car API 8 and above.
Text Wrapping
This text is truncated at the end to fit in a single line below the title| Throws | |
|---|---|
java.lang.NullPointerException |
if |
java.lang.IllegalArgumentException |
if |
setText
fun setText(text: CharSequence): GridItem.Builder
Sets a secondary text string to the grid item that is displayed below the title.
text must conform to CarTextConstraints.TEXT_WITH_COLORS in Car API 7 and below, and CarTextConstraints.TEXT_WITH_COLORS_AND_ICON in Car API 8 and above.
Text Wrapping
This text is truncated at the end to fit in a single line below the title| Throws | |
|---|---|
java.lang.NullPointerException |
if |
java.lang.IllegalArgumentException |
if |
setTitle
fun setTitle(title: CarText?): GridItem.Builder
Sets the title of the GridItem, with support for multiple length variants.
title must conform to CarTextConstraints.TEXT_ONLY in Car API 7 and below, and CarTextConstraints.TEXT_AND_ICON in Car API 8 and above.
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if |
setTitle
fun setTitle(title: CharSequence?): GridItem.Builder
Sets the title of the GridItem.
title must conform to CarTextConstraints.TEXT_ONLY in Car API 7 and below, and CarTextConstraints.TEXT_AND_ICON in Car API 8 and above.
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if |