ListBuilder
@RequiresApi(19) open class ListBuilder : TemplateSliceBuilder
kotlin.Any | ||
↳ | androidx.slice.builders.TemplateSliceBuilder | |
↳ | androidx.slice.builders.ListBuilder |
Builder for constructing slices composed of rows of content.
A slice is a piece of templated app content that can be presented outside of the app providing the slice in a androidx.slice.widget.SliceView
. To provide a slice you should implement a androidx.slice.SliceProvider
and use ListBuilder to construct your slice when androidx.slice.SliceProvider#onBindSlice(Uri)
is called.
ListBuilder allows you to construct a slice made up of rows of content. The row types that ListBuilder supports are:
HeaderBuilder
- The first row of your slice should be a header. The header supports a title, subtitle, and tappable row action. A header can also have a summary of the contents of the slice which can be shown when not all of the slice can be displayed.RowBuilder
- A basic row supports title, subtitle, timestamps, and various action types.GridRowBuilder
- A grid row supports cells of vertically laid out content displayed in a single row.RangeBuilder
- A range row supports displaying a horizontal progress indicator.InputRangeBuilder
- An input range row supports displaying a horizontal slider allowing slider input (e.g. brightness or volume slider).RatingBuilder
- An star rating row supports displaying a horizontal star rating input (e.g. rating 4/5 stars)
Slices are meant to be presented outside of the app providing them, the slice presenter could be an Android system surface or another application. The presenter will normally use a androidx.slice.widget.SliceView
to display a slice. SliceView supports a couple of different modes. These modes are not controlled by the app providing the slice, but rather by the surface that is presenting the slice. To ensure your slice is presented correctly you should consider the different modes SliceView supports:
androidx.slice.widget.SliceView#MODE_SMALL
- Only the first row of content is displayed in small format, normally this will be the header. If no header was set, then the first row will be used and may appear differently depending on the row type and the configuration ofandroidx.slice.widget.SliceView
.androidx.slice.widget.SliceView#MODE_LARGE
- As many rows of content are shown as possible. If the presenter of the slice allows scrolling then all rows of content will be displayed in a scrollable view.androidx.slice.widget.SliceView#MODE_SHORTCUT
- In shortcut mode only a tappable image is displayed. The image and action used to represent this will be the primary action of your slice, i.e.HeaderBuilder#setPrimaryAction(SliceAction)
.
In addition to rows of content, ListBuilder can also have SliceAction
s added to it. These actions may appear differently on your slice depending on how androidx.slice.widget.SliceView
is configured. Normally the actions appear as icons in the header of the slice.
There is no limit to the number of rows added to ListBuilder, however, the contents of a slice should be related to a primary task, action, or set of information. For example: it might make sense for a slice to manage wi-fi state to have a row for each available network, this might result in a large number of rows but each of these rows serve utility for the primary purpose of the slice which is managing wi-fi.
Note that scrolling on SliceView can be disabled, in which case only the header and one or two rows of content may be shown for your slice. If your slice contains many rows of content to scroll through (e.g. list of wifi networks), consider using setSeeMoreAction(PendingIntent)
to provide a link to open the activity associated with the content.
Summary
Nested classes | |
---|---|
open |
Builder to construct a header row. |
open |
Builder to construct a input range row. |
open |
Builder to construct a range row which can be added to a |
Builder to construct a input star rating. |
|
open |
Builder to construct a row. |
Constants | |
---|---|
static Int |
Indicates that an button should be presented with text. |
static Int |
Indicates that an image should be presented as an icon and it can be tinted. |
static Long |
Constant representing infinity. |
static Int |
Indicates that an image presented in a larger size and it shouldn't be tinted. |
static Int |
Indicates that the progress bar should be presented in determinate mode. |
static Int |
Indicates that the progress bar should be presented in indeterminate mode. |
static Int |
Indicates that the progress bar should be presented as a star rating. |
static Int |
Indicates that an image should be presented in its intrinsic size and shouldn't be tinted. |
static Int |
Indicates that an image should be presented in its intrinsic size and shouldn't be tinted. |
static Int |
Indicates that an image should be presented in a smaller size and it shouldn't be tinted. |
static Int |
Indicates that an image mode is unknown. |
Public constructors | |
---|---|
Create a ListBuilder for constructing slice content. |
|
Create a ListBuilder for constructing slice content. |
Public methods | |
---|---|
open ListBuilder |
addAction(@NonNull action: SliceAction) Adds an action to this list builder. |
open ListBuilder |
addGridRow(@NonNull builder: GridRowBuilder) Add a grid row to the list builder. |
open ListBuilder |
addInputRange(@NonNull b: ListBuilder.InputRangeBuilder) Add an input range row to the list builder. |
open ListBuilder |
addRange(@NonNull rangeBuilder: ListBuilder.RangeBuilder) Add a range row to the list builder. |
open ListBuilder |
addRating(@NonNull b: ListBuilder.RatingBuilder) Add an star rating row to the list builder. |
open ListBuilder |
addRow(@NonNull builder: ListBuilder.RowBuilder) Add a row to the list builder. |
open ListBuilder |
addSelection(@NonNull selectionBuilder: SelectionBuilder) Add a selection row to the list builder. |
open Slice |
build() Construct the slice defined by this ListBuilder. |
open ListBuilder |
setAccentColor(@ColorInt color: Int) Sets the color to use on tintable items within the list builder. |
open ListBuilder |
setHeader(@NonNull builder: ListBuilder.HeaderBuilder) Sets a header for this list builder. |
open ListBuilder |
setHostExtras(@NonNull extras: PersistableBundle) Sets additional information to be passed to the host of the slice. |
open ListBuilder |
setIsError(isError: Boolean) Sets whether this slice indicates an error, i. |
open ListBuilder |
setKeywords(@NonNull keywords: MutableSet<String!>) Sets keywords to associate with this slice. |
open ListBuilder |
setLayoutDirection(layoutDirection: Int) Sets the desired layout direction for this slice. |
open ListBuilder |
setSeeMoreAction(@NonNull intent: PendingIntent) If all content in a slice cannot be shown, a "see more" affordance may be displayed where the content is cut off. |
open ListBuilder |
setSeeMoreAction(@NonNull callback: RemoteCallback) If all content in a slice cannot be shown, a "see more" affordance may be displayed where the content is cut off. |
open ListBuilder |
setSeeMoreRow(@NonNull builder: ListBuilder.RowBuilder) If all content in a slice cannot be shown, the row added here may be displayed where the content is cut off. |
Constants
ACTION_WITH_LABEL
static val ACTION_WITH_LABEL: Int
Indicates that an button should be presented with text.
Value: SliceHints.ACTION_WITH_LABEL
ICON_IMAGE
static val ICON_IMAGE: Int
Indicates that an image should be presented as an icon and it can be tinted.
Value: SliceHints.ICON_IMAGE
LARGE_IMAGE
static val LARGE_IMAGE: Int
Indicates that an image presented in a larger size and it shouldn't be tinted.
Value: SliceHints.LARGE_IMAGE
RANGE_MODE_DETERMINATE
static val RANGE_MODE_DETERMINATE: Int
Indicates that the progress bar should be presented in determinate mode.
Value: SliceHints.DETERMINATE_RANGE
RANGE_MODE_INDETERMINATE
static val RANGE_MODE_INDETERMINATE: Int
Indicates that the progress bar should be presented in indeterminate mode.
Value: SliceHints.INDETERMINATE_RANGE
RANGE_MODE_STAR_RATING
static val RANGE_MODE_STAR_RATING: Int
Indicates that the progress bar should be presented as a star rating.
Value: SliceHints.STAR_RATING
RAW_IMAGE_LARGE
static val RAW_IMAGE_LARGE: Int
Indicates that an image should be presented in its intrinsic size and shouldn't be tinted. If SliceView in the call-site doesn't support RAW_IMAGE, fallback to LARGE_IMAGE instead.
Value: SliceHints.RAW_IMAGE_LARGE
RAW_IMAGE_SMALL
static val RAW_IMAGE_SMALL: Int
Indicates that an image should be presented in its intrinsic size and shouldn't be tinted. If SliceView in the call-site doesn't support RAW_IMAGE, fallback to SMALL_IMAGE instead.
Value: SliceHints.RAW_IMAGE_SMALL
SMALL_IMAGE
static val SMALL_IMAGE: Int
Indicates that an image should be presented in a smaller size and it shouldn't be tinted.
Value: SliceHints.SMALL_IMAGE
UNKNOWN_IMAGE
static val UNKNOWN_IMAGE: Int
Indicates that an image mode is unknown.
Value: SliceHints.UNKNOWN_IMAGE
Public constructors
<init>
ListBuilder(
@NonNull context: Context,
@NonNull uri: