CellBuilder
class CellBuilder : TemplateSliceBuilder
kotlin.Any | ||
↳ | androidx.slice.builders.TemplateSliceBuilder | |
↳ | androidx.slice.builders.GridRowBuilder.CellBuilder |
Builder to construct a cell. A cell can be added as an item to GridRowBuilder via GridRowBuilder#addCell(CellBuilder)
.
A cell supports up to two lines of text and one image. Content added to a cell will be displayed in the order that the content is added to it. For example, the below code would construct a cell with "First text", and image below it, and then "Second text" below the image.
CellBuilder cb = new CellBuilder(parent, sliceUri); cb.addText("First text") .addImage(middleIcon) .addText("Second text");
A cell supports a couple of image types:
ListBuilder#ICON_IMAGE
- icon images are expected to be tintable and are shown at a standard icon size.ListBuilder#SMALL_IMAGE
- small images are not tinted and are shown at a small size.ListBuilder#LARGE_IMAGE
- large images are not tinted and are shown as large as they can be, in aandroid.widget.ImageView.ScaleType#CENTER_CROP
Summary
Public constructors | |
---|---|
<init>(parent: GridRowBuilder) Create a builder which will construct a slice displayed as a cell in a grid. |
|
<init>(parent: GridRowBuilder, uri: Uri) Create a builder which will construct a slice displayed as a cell in a grid. |
Public methods | |
---|---|
GridRowBuilder.CellBuilder |
addTitleText(text: CharSequence) Adds text to the cell. |
GridRowBuilder.CellBuilder |
addTitleText(text: CharSequence?, isLoading: Boolean) Adds text to the cell. |
GridRowBuilder.CellBuilder |
Adds an image to the cell. |
GridRowBuilder.CellBuilder |
Adds an image to the cell. |
GridRowBuilder.CellBuilder |
addText(text: CharSequence) Adds text to the cell. |
GridRowBuilder.CellBuilder |
addText(text: CharSequence?, isLoading: Boolean) Adds text to the cell. |
GridRowBuilder.CellBuilder |
setContentDescription(description: CharSequence) Sets the content description for this cell. |
GridRowBuilder.CellBuilder |
setContentIntent(intent: PendingIntent) Sets the action to be invoked if the user taps on this cell in the row. |
Inherited functions | |
---|---|
Public constructors
<init>
CellBuilder(parent: GridRowBuilder)
Create a builder which will construct a slice displayed as a cell in a grid.
Parameters | |
---|---|
parent |
GridRowBuilder: The builder constructing the parent slice. |
<init>
CellBuilder(parent: GridRowBuilder, uri: Uri)
Create a builder which will construct a slice displayed as a cell in a grid.
Parameters | |
---|---|
uri |
GridRowBuilder: Uri to tag for this slice. |
Public methods
addTitleText
fun addTitleText(text: CharSequence): GridRowBuilder.CellBuilder
Adds text to the cell. Text added with this method will be styled as a title. There can be at most two text items, the first two added will be used, others will be ignored.
addTitleText
fun addTitleText(text: CharSequence?, isLoading: Boolean): GridRowBuilder.CellBuilder
Adds text to the cell. Text added with this method will be styled as a title. There can be at most two text items, the first two added will be used, others will be ignored.
Use this method to specify content that will appear in the template once it's been loaded.
Parameters | |
---|---|
isLoading |
CharSequence?: indicates whether the app is doing work to load the added content in the background or not. |
addImage
fun addImage(image: IconCompat, imageMode: Int): GridRowBuilder.CellBuilder
Adds an image to the cell. There can be at most one image, the first one added will be used, others will be ignored.
Parameters | |
---|---|
image |
IconCompat: the image to display in the cell. |
imageMode |
IconCompat: the mode that image should be displayed in. |
addImage
fun addImage(image: IconCompat?, imageMode: Int, isLoading: Boolean): GridRowBuilder.CellBuilder
Adds an image to the cell. There can be at most one image, the first one added will be used, others will be ignored.
Use this method to specify content that will appear in the template once it's been loaded.
Parameters | |
---|---|
image |
IconCompat?: the image to display in the cell. |
imageMode |
IconCompat?: the mode that image should be displayed in. |
isLoading |
IconCompat?: indicates whether the app is doing work to load the added content in the background or not. |
addText
fun addText(text: CharSequence): GridRowBuilder.CellBuilder
Adds text to the cell. There can be at most two text items, the first two added will be used, others will be ignored.
addText
fun addText(text: CharSequence?, isLoading: Boolean): GridRowBuilder.CellBuilder
Adds text to the cell. There can be at most two text items, the first two added will be used, others will be ignored.
Use this method to specify content that will appear in the template once it's been loaded.
Parameters | |
---|---|
isLoading |
CharSequence?: indicates whether the app is doing work to load the added content in the background or not. |
setContentDescription
fun setContentDescription(description: CharSequence): GridRowBuilder.CellBuilder
Sets the content description for this cell.
setContentIntent
fun setContentIntent(intent: PendingIntent): GridRowBuilder.CellBuilder
Sets the action to be invoked if the user taps on this cell in the row.