@@ -25,6 +25,9 @@ import androidx.slice.Slice
2525import androidx.slice.SliceProvider
2626import androidx.slice.builders.ListBuilder
2727import androidx.slice.builders.SliceAction
28+ import androidx.slice.builders.header
29+ import androidx.slice.builders.list
30+ import androidx.slice.builders.row
2831import androidx.slice.core.SliceHints
2932import androidx.slice.core.SliceHints.ICON_IMAGE
3033import com.example.android.sliceviewer.R
@@ -34,7 +37,7 @@ class SampleSliceProvider : SliceProvider() {
3437 if (sliceUri == null || sliceUri.path == null ) {
3538 return null
3639 }
37- return when (sliceUri.path) {
40+ return when (sliceUri.path) {
3841 " /hello" -> createHelloWorldSlice(sliceUri)
3942 " /test" -> createTestSlice(sliceUri)
4043 else -> null
@@ -53,15 +56,13 @@ class SampleSliceProvider : SliceProvider() {
5356 }
5457
5558 private fun createHelloWorldSlice (sliceUri : Uri ): Slice {
56- return ListBuilder (context, sliceUri, ListBuilder .INFINITY )
57- .setHeader {
58- it.apply {
59- setTitle(" Hello World" )
60- }
61- }.build()
59+ return list(context, sliceUri, ListBuilder .INFINITY ) {
60+ header {
61+ setTitle(" Hello World" )
62+ }
63+ }
6264 }
6365
64-
6566 private fun createTestSlice (sliceUri : Uri ): Slice {
6667 val activityAction = SliceAction (
6768 PendingIntent .getActivity(
@@ -74,27 +75,23 @@ class SampleSliceProvider : SliceProvider() {
7475 ),
7576 " Go to app."
7677 )
77- return ListBuilder (context, sliceUri, SliceHints .INFINITY )
78- .setAccentColor(0x7f040047 )
79- .setHeader {
80- it.apply {
81- setTitle(" Test Slice" )
82- setSubtitle(" Slice for testing purposes" )
83- setSummary(" Welcome to the basic Slice presenter." )
84- }
78+ return list(context, sliceUri, SliceHints .INFINITY ) {
79+ setAccentColor(0x7f040047 )
80+ header {
81+ setTitle(" Test Slice" )
82+ setSubtitle(" Slice for testing purposes" )
83+ setSummary(" Welcome to the basic Slice presenter." )
8584 }
86- .addRow {
87- it.apply {
88- setTitle(" Example Row" )
89- setSubtitle(" Row Subtitle" )
90- addEndItem(
91- IconCompat .createWithResource(
92- context, R .drawable.ic_arrow_forward_black_24dp
93- ), ICON_IMAGE
94- )
95- }
85+ row {
86+ setTitle(" Example Row" )
87+ setSubtitle(" Row Subtitle" )
88+ addEndItem(
89+ IconCompat .createWithResource(
90+ context, R .drawable.ic_arrow_forward_black_24dp
91+ ), ICON_IMAGE
92+ )
9693 }
97- . addAction(activityAction)
98- .build()
94+ addAction(activityAction)
95+ }
9996 }
10097}
0 commit comments