Row.Builder
class Row.Builder
A builder of Row.
Summary
Public functions |
|
|---|---|
Row.Builder |
@RequiresCarApi(value = 6)Adds an additional action to the end of the row. |
Row.Builder |
Adds a text string to the row below the title, with support for multiple length variants. |
Row.Builder |
addText(text: CharSequence)Adds a text string to the row below the title. |
Row |
build()Constructs the |
Row.Builder |
setBrowsable(isBrowsable: Boolean)Shows an icon at the end of the row that indicates that the row is browsable. |
Row.Builder |
@RequiresCarApi(value = 5)Sets the initial enabled state for |
Row.Builder |
@RequiresCarApi(value = 8)Sets an image at the end of the row, with the default size |
Row.Builder |
@RequiresCarApi(value = 8)Sets an image to show at the end of the row content, but before the secondary actions (if set via |
Row.Builder |
Sets an image to show in the row with the default size |
Row.Builder |
Sets an image to show in the row with the given image type. |
Row.Builder |
@ExperimentalCarApiSets whether this item can be included in indexed lists. |
Row.Builder |
setMetadata(metadata: Metadata)Sets the |
@IntRange(from = 0) Row.Builder |
@RequiresCarApi(value = 6)Sets a numeric decoration to display in the row. |
Row.Builder |
setOnClickListener(onClickListener: OnClickListener)Sets the |
Row.Builder |
Sets the title of the row, with support for multiple length variants. |
Row.Builder |
setTitle(title: CharSequence)Sets the title of the row. |
Row.Builder |
Sets a |
Public functions
addAction
@RequiresCarApi(value = 6)
fun addAction(action: Action): Row.Builder
Adds an additional action to the end of the row. Note: From Car API 8 onwards, Rows are allowed to have 2 max actions to be set.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
java.lang.IllegalArgumentException |
if |
addText
fun addText(text: CarText): Row.Builder
Adds a text string to the row below the title, with support for multiple length variants.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
java.lang.IllegalArgumentException |
if |
| See also | |
|---|---|
addText |
addText
fun addText(text: CharSequence): Row.Builder
Adds a text string to the row below the title.
The text can be customized with ForegroundCarColorSpan, androidx.car.app.model.DistanceSpan, and androidx.car.app.model.DurationSpan instances, any other spans will be ignored by the host.
Most templates allow up to 2 text strings, but this may vary. This limit is documented in each individual template.
Text Wrapping Each string added with this method will not wrap more than 1 line in the UI, with one exception: if the template allows a maximum number of text strings larger than 1, and the app adds a single text string, then this string will wrap up to the maximum.For example, assuming 2 lines are allowed in the template where the row will be used, this code:
rowBuilder .addText("This is a rather long line of text") .addText("More text")
would wrap the text like this:
This is a rather long li... More text
rowBuilder .addText("This is a rather long line of text. More text")
would wrap the single line of text at a maximum of 2 lines, producing a different result:
This is a rather long line of text. More text
Note that when using a single line, a line break character can be used to break it into two, but the results may be unpredictable depending on the width the text is wrapped at:
rowBuilder .addText("This is a rather long line of text\nMore text")
would produce a result that may loose the "More text" string:
This is a rather long line of text
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
java.lang.IllegalArgumentException |
if |
| See also | |
|---|---|
ForegroundCarColorSpan |
build
fun build(): Row
Constructs the Row defined by this builder.
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the row's title is not set or if the row is not set correctly. See |
setBrowsable
fun setBrowsable(isBrowsable: Boolean): Row.Builder
Shows an icon at the end of the row that indicates that the row is browsable.
Browsable rows can be used, for example, to represent the parent row in a hierarchy of lists with child lists.
If a row is browsable, then no Action or Toggle can be added to it. A browsable row must have an OnClickListener set.
setEnabled
@RequiresCarApi(value = 5)
fun setEnabled(enabled: Boolean): Row.Builder
Sets the initial enabled state for Row.
The default state of a Row is enabled.
setEndImage
@RequiresCarApi(value = 8)
fun setEndImage(image: CarIcon): Row.Builder
Sets an image at the end of the row, with the default size IMAGE_TYPE_SMALL.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
setEndImage |
setEndImage
@RequiresCarApi(value = 8)
fun setEndImage(endImage: CarIcon, rowEndImageType: Int): Row.Builder
Sets an image to show at the end of the row content, but before the secondary actions (if set via addAction), and is distinct from the primary image set via setImage.
The end image will not be honored if the row has any of the following elements:
- A
Toggleis set viasetToggle. - The row is set to be browsable via
setBrowsable. - The row is part of a selectable itemlist
| Parameters | |
|---|---|
endImage: CarIcon |
The |
rowEndImageType: Int |
one of {IMAGE_TYPE_SMALL, IMAGE_TYPE_ICON, IMAGE_TYPE_LARGE, IMAGE_TYPE_EXTRA_SMALL} |
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setImage
fun setImage(image: CarIcon): Row.Builder
Sets an image to show in the row with the default size IMAGE_TYPE_SMALL.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
setImage |
setImage
fun setImage(image: CarIcon, imageType: Int): Row.Builder
Sets an image to show in the row with the given image type.
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 |
setIndexable
@ExperimentalCarApi
fun setIndexable(indexable: Boolean): Row.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)).
setMetadata
fun setMetadata(metadata: Metadata): Row.Builder
Sets the Metadata associated with the row.
| Parameters | |
|---|---|
metadata: Metadata |
The metadata to set with the row. Pass |
setNumericDecoration
@RequiresCarApi(value = 6)
fun setNumericDecoration(decoration: Int): @IntRange(from = 0) Row.Builder
Sets a numeric decoration to display in the row.
Numeric decorations are displayed at the end of the row. A numeric decoration cannot be set with only a single action which will end up only showing the action; however, the decoration may be set with 2 actions. Numeric decorations are not displayed in half-list templates.
Numeric decorations typically represent a quantity of unseen content. For example, a decoration might represent a number of missed notifications, or a number of unread messages in a conversation.
| Parameters | |
|---|---|
decoration: Int |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if |
setOnClickListener
fun setOnClickListener(onClickListener: OnClickListener): Row.Builder
Sets the OnClickListener to be called back when the row 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 |
setTitle
fun setTitle(title: CarText): Row.Builder
Sets the title of the row, with support for multiple length variants.
Only DistanceSpans and DurationSpans are supported in the input string.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
java.lang.IllegalArgumentException |
if |
setTitle
fun setTitle(title: CharSequence): Row.Builder
Sets the title of the row.
Only DistanceSpans and DurationSpans are supported in the input string.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
java.lang.IllegalArgumentException |
if |
setToggle
fun setToggle(toggle: Toggle): Row.Builder
Sets a Toggle to show in the row.
If a row has a toggle set, then no Action, OnClickListener or numeric decoration can be set.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |