The Android Developer Challenge is back! Submit your idea before December 2.

CellBuilder

open class CellBuilder
kotlin.Any
   ↳ 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:

Summary

Public constructors

Create a builder which will construct a slice displayed as a cell in a grid.

Public methods

open GridRowBuilder.CellBuilder
addImage(@NonNull image: IconCompat, imageMode: Int)

Adds an image to the cell.

open GridRowBuilder.CellBuilder
addImage(@Nullable image: IconCompat?, imageMode: Int, isLoading: Boolean)

Adds an image to the cell.

open GridRowBuilder.CellBuilder
addText(@NonNull text: CharSequence)

Adds text to the cell.

open GridRowBuilder.CellBuilder
addText(@Nullable text: CharSequence?, isLoading: Boolean)

Adds text to the cell.

open GridRowBuilder.CellBuilder
addTitleText(@NonNull text: CharSequence)

Adds text to the cell.

open GridRowBuilder.CellBuilder
addTitleText(@Nullable text: CharSequence?, isLoading: Boolean)

Adds text to the cell.

open GridRowBuilder.CellBuilder
setContentDescription(@NonNull description: CharSequence)

Sets the content description for this cell.

open GridRowBuilder.CellBuilder
setContentIntent(@NonNull intent: PendingIntent)

Sets the action to be invoked if the user taps on this cell in the row.

open GridRowBuilder.CellBuilder
setContentIntent(@NonNull callback: RemoteCallback)

Sets the action to be invoked if the user taps on this cell in the row.

Public constructors

<init>

CellBuilder()

Create a builder which will construct a slice displayed as a cell in a grid.

Public methods

addImage

@NonNull open fun addImage(@NonNull 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

@NonNull open fun addImage(@Nullable 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

@NonNull open fun addText(@NonNull 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

@NonNull open fun addText(@Nullable 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.

addTitleText

@NonNull open fun addTitleText(@NonNull 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

@NonNull open fun addTitleText(@Nullable 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.

setContentDescription

@NonNull open fun setContentDescription(@NonNull description: CharSequence): GridRowBuilder.CellBuilder

Sets the content description for this cell.

setContentIntent

@NonNull open fun setContentIntent(@NonNull intent: PendingIntent): GridRowBuilder.CellBuilder

Sets the action to be invoked if the user taps on this cell in the row.

setContentIntent

@NonNull open fun setContentIntent(@NonNull callback: RemoteCallback): GridRowBuilder.CellBuilder

Sets the action to be invoked if the user taps on this cell in the row.