Skip to content

Commit

Permalink
Shortened snippet names and tagged template snippets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Sigelbaum committed Jun 21, 2018
1 parent f1ea1a9 commit e301548
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean onCreateSliceProvider() {
return false;
}

// [START slices_getting_started_onBindSlice]
// [START on_bind_slice]
@Override
public Slice onBindSlice(Uri sliceUri) {
// Create parent ListBuilder.
Expand All @@ -58,9 +58,9 @@ public Slice onBindSlice(Uri sliceUri) {
// Build List.
return listBuilder.build();
}
// [END slices_getting_started_onBindSlice]
// [END on_bind_slice]

// [START slices_getting_started_createSlice]
// [START create_slice]
public Slice createSlice(Uri sliceUri) {
SliceAction activityAction = createActivityAction();
ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY);
Expand All @@ -77,9 +77,9 @@ public SliceAction createActivityAction() {
IconCompat.createWithResource(getContext(), R.drawable.ic_home),
"Open MainActivity");
}
// [END slices_getting_started_createSlice]
// [END create_slice]

// [START slices_getting_started_createBrightnessSlice]
// [START create_brightness_slice]
public Slice createBrightnessSlice(Uri sliceUri) {
SliceAction toggleAction = new SliceAction(createToggleIntent(),
"Toggle adaptive brightness", true);
Expand All @@ -106,9 +106,9 @@ public PendingIntent createToggleIntent() {
Intent intent = new Intent(getContext(), MyBroadcastReceiver.class);
return PendingIntent.getBroadcast(getContext(), 0, intent, 0);
}
// [END slices_getting_started_createBrightnessSlice]
// [END create_brightness_slice]

// [START slices_getting_started_createDynamicSlice]
// [START create_dynamic_slice]
public Slice createDynamicSlice(Uri sliceUri) {
ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY);
ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder(listBuilder);
Expand All @@ -134,5 +134,5 @@ public PendingIntent createToastAndIncrementIntent(String s) {
.putExtra(MyBroadcastReceiver.EXTRA_MESSAGE, s);
return PendingIntent.getBroadcast(getContext(), 0, intent, 0);
}
// [END slices_getting_started_createDynamicSlice]
// [END create_dynamic_slice]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import android.net.Uri;
import android.widget.Toast;

// [START slices_getting_started_MyBroadcastReceiver]
// [START broadcast_receiver_example]
public class MyBroadcastReceiver extends BroadcastReceiver {

public static int sReceivedCount = 0;
Expand All @@ -41,4 +41,4 @@ public void onReceive(Context context, Intent intent) {
}
}
}
// [END slices_getting_started_MyBroadcastReceiver]
// [END broadcast_receiver_example]
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public Slice onBindSlice(Uri sliceUri) {
return null;
}

// [START create_slice_with_header]
public Slice createSliceWithHeader(Uri sliceUri) {
// Construct the parent.
ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY)
Expand Down Expand Up @@ -88,7 +89,9 @@ public Slice createSliceWithHeader(Uri sliceUri) {

return listBuilder.build();
}
// [END create_slice_with_header]

// [START create_slice_with_action_in_header]
public Slice createSliceWithActionInHeader(Uri sliceUri) {

// Construct the list.
Expand Down Expand Up @@ -125,7 +128,9 @@ public Slice createSliceWithActionInHeader(Uri sliceUri) {

return listBuilder.build();
}
// [END create_slice_with_action_in_header]

// [START create_action_with_action_in_row]
public Slice createActionWithActionInRow(Uri sliceUri) {
// Primary action - open wifi settings.
SliceAction primaryAction = new SliceAction(wifiSettingsPendingIntent,
Expand Down Expand Up @@ -154,7 +159,9 @@ public Slice createActionWithActionInRow(Uri sliceUri) {
// Build the slice.
return listBuilder.build();
}
// [END create_action_with_action_in_row]

// [START create_slice_with_gridrow]
public Slice createSliceWithGridRow(Uri sliceUri) {
// Create the parent builder.
ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY);
Expand Down Expand Up @@ -198,7 +205,9 @@ public Slice createSliceWithGridRow(Uri sliceUri) {

return listBuilder.build();
}
// [END create_slice_with_gridrow]

// [START create_slice_with_range]
public Slice createSliceWithRange(Uri sliceUri) {
// Construct the parent.
ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY);
Expand All @@ -216,7 +225,9 @@ public Slice createSliceWithRange(Uri sliceUri) {

return listBuilder.build();
}
// [END create_slice_with_range]

// [START create_slice_showing_loading]
public Slice createSliceShowingLoading(Uri sliceUri) {
// Construct the parent.
ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY);
Expand All @@ -236,12 +247,25 @@ public Slice createSliceShowingLoading(Uri sliceUri) {

return listBuilder.build();
}
// [END create_slice_showing_loading]

public void seeMoreAction(ListBuilder listBuilder) {
// [START see_more_action]
public Slice seeMoreActionSlice(Uri sliceUri) {
ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY);
// [START_EXCLUDE]
// [END_EXCLUDE]
listBuilder.setSeeMoreAction(seeAllNetworksPendingIntent);
// [START_EXCLUDE]
// [END_EXCLUDE]
return listBuilder.build();
}
// [END see_more_action]

public void seeMoreRow(ListBuilder listBuilder) {
// [START see_more_row]
public Slice seeMoreRowSlice(Uri sliceUri) {
ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY);
// [START_EXCLUDE]
// [END_EXCLUDE]
RowBuilder rowBuilder = new RowBuilder(listBuilder)
.setTitle("See all available networks")
.addEndItem(IconCompat.createWithResource(getContext(), R.drawable.ic_right_caret),
Expand All @@ -250,5 +274,9 @@ public void seeMoreRow(ListBuilder listBuilder) {
IconCompat.createWithResource(getContext(), R.drawable.ic_wifi),
"Wi-Fi Networks"));
listBuilder.setSeeMoreRow(rowBuilder);
// [START_EXCLUDE]
// [END_EXCLUDE]
return listBuilder.build();
}
// [END see_more_row]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.example.android.snippets.R
class GettingStartedSliceProvider : SliceProvider() {
lateinit var brightnessPendingIntent: PendingIntent

// [START slices_getting_started_onBindSlice]
// [START on_bind_slice]
override fun onBindSlice(sliceUri: Uri): Slice? {
return if (sliceUri.path == "/hello") {
ListBuilder(context, sliceUri, ListBuilder.INFINITY)
Expand All @@ -43,13 +43,13 @@ class GettingStartedSliceProvider : SliceProvider() {
.build()
}
}
// [END slices_getting_started_onBindSlice]
// [END on_bind_slice]

override fun onCreateSliceProvider(): Boolean {
return true
}

// [START slices_getting_started_createSlice]
// [START create_slice]
fun createSlice(sliceUri: Uri): Slice {
val activityAction = createActivityAction()
return list(context, sliceUri, INFINITY) {
Expand All @@ -68,9 +68,9 @@ class GettingStartedSliceProvider : SliceProvider() {
"Open MainActivity."
)
}
// [END slices_getting_started_createSlice]
// [END create_slice]

// [START slices_getting_started_createBrightnessSlice]
// [START create_brightness_slice]
fun createBrightnessSlice(sliceUri: Uri): Slice {
val toggleAction =
SliceAction(createToggleIntent(), "Toggle adaptive brightness", true)
Expand All @@ -92,11 +92,11 @@ class GettingStartedSliceProvider : SliceProvider() {
val intent = Intent(context, MyBroadcastReceiver::class.java)
return PendingIntent.getBroadcast(context, 0, intent, 0)
}
// [END slices_getting_started_createBrightnessSlice]
// [END create_brightness_slice]

lateinit var actionIcon: IconCompat

// [START slices_getting_started_createDynamicSlice]
// [START create_dynamic_slice]
fun createDynamicSlice(sliceUri: Uri): Slice {
return when (sliceUri.path) {
"/count" -> {
Expand Down Expand Up @@ -128,5 +128,5 @@ class GettingStartedSliceProvider : SliceProvider() {
.putExtra(MyBroadcastReceiver.EXTRA_MESSAGE, s), 0
)
}
// [END slices_getting_started_createDynamicSlice]
// [END create_dynamic_slice]
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import android.widget.Toast
// const val EXTRA_MESSAGE = "message"
// }
//}
// [START slices_getting_started_MyBroadcastReceiver]
// [START broadcastreceiver_example]
class MyBroadcastReceiver : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
Expand All @@ -57,4 +57,4 @@ class MyBroadcastReceiver : BroadcastReceiver() {
const val EXTRA_MESSAGE = "message"
}
}
// [END slices_getting_started_MyBroadcastReceiver]
// [END broadcastreceiver_example]
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.slice.builders.header
import androidx.slice.builders.inputRange
import androidx.slice.builders.list
import androidx.slice.builders.row
import androidx.slice.builders.seeMoreRow
import androidx.slice.core.SliceHints
import androidx.slice.core.SliceHints.ICON_IMAGE
import com.example.android.snippets.R
Expand Down Expand Up @@ -61,6 +62,7 @@ class MySliceProvider : SliceProvider() {
return false
}

// [START create_slice_with_header]
fun createSliceWithHeader(sliceUri: Uri) =
list(context, sliceUri, ListBuilder.INFINITY) {
setAccentColor(0xff0F9D) // Specify color for tinting icons
Expand All @@ -78,7 +80,9 @@ class MySliceProvider : SliceProvider() {
)
}
}
// [END create_slice_with_header]

// [START create_slice_with_action_in_header]
fun createSliceWithActionInHeader(sliceUri: Uri): Slice {
// Construct our slice actions.
val noteAction = SliceAction(
Expand Down Expand Up @@ -114,7 +118,9 @@ class MySliceProvider : SliceProvider() {
addAction(cameraNoteAction)
}
}
// [END create_slice_with_action_in_header]

// [START create_action_with_action_in_row]
fun createActionWithActionInRow(sliceUri: Uri): Slice {
// Primary action - open wifi settings.
val primaryAction = SliceAction(
Expand All @@ -139,7 +145,9 @@ class MySliceProvider : SliceProvider() {
}
}
}
// [END create_action_with_action_in_row]

// [START create_slice_with_gridrow]
fun createSliceWithGridRow(sliceUri: Uri): Slice {
// Create the parent builder.
return list(context, sliceUri, ListBuilder.INFINITY) {
Expand Down Expand Up @@ -175,7 +183,9 @@ class MySliceProvider : SliceProvider() {
}
}
}
// [END create_slice_with_gridrow]

// [START create_slice_with_range]
fun createSliceWithRange(sliceUri: Uri): Slice {
return list(context, sliceUri, ListBuilder.INFINITY) {
inputRange {
Expand All @@ -186,7 +196,9 @@ class MySliceProvider : SliceProvider() {
}
}
}
// [END create_slice_with_range]

// [START create_slice_showing_loading]
fun createSliceShowingLoading(sliceUri: Uri): Slice {
// We’re waiting to load the time to work so indicate that on the slice by
// setting the subtitle with the overloaded method and indicate true.
Expand All @@ -200,26 +212,37 @@ class MySliceProvider : SliceProvider() {
}
}
}
// [END create_slice_showing_loading]

// fun seeMoreAction(listBuilder: ListBuilder) {
// listBuilder.setSeeMoreAction(seeAllNetworksPendingIntent)
// }
//
// fun seeMoreRow(listBuilder: ListBuilder) {
// listBuilder.setSeeMoreRow {
// it.apply {
// setTitle("See all available networks")
// addEndItem(
// IconCompat.createWithResource(context, R.drawable.ic_right_caret), ICON_IMAGE
// )
// setPrimaryAction(
// SliceAction(
// seeAllNetworksPendingIntent,
// IconCompat.createWithResource(context, R.drawable.ic_wifi),
// "Wi-Fi Networks"
// )
// )
// }
// }
// }
// [START see_more_action]
fun seeMoreActionSlice(sliceUri: Uri) =
list(context, sliceUri, ListBuilder.INFINITY) {
// [START_EXCLUDE]
// [END_EXCLUDE]
setSeeMoreAction(seeAllNetworksPendingIntent)
// [START_EXCLUDE]
// [END_EXCLUDE]
}
// [END see_more_action

// [START see_more_row]
fun seeMoreRowSlice(sliceUri: Uri) =
list(context, sliceUri, ListBuilder.INFINITY) {
// [START_EXCLUDE]
// [END_EXCLUDE]
seeMoreRow {
setTitle("See all available networks")
addEndItem(
IconCompat.createWithResource(context, R.drawable.ic_right_caret), ICON_IMAGE
)
setPrimaryAction(
SliceAction(
seeAllNetworksPendingIntent,
IconCompat.createWithResource(context, R.drawable.ic_wifi),
"Wi-Fi Networks"
)
)
}
}
// [END see_more_row]
}

0 comments on commit e301548

Please sign in to comment.