in car_app_library/showcase/common/src/main/java/androidx/car/app/sample/showcase/common/misc/NotificationDemoScreen.java [118:191]
public Template onGetTemplate() {
ItemList.Builder listBuilder = new ItemList.Builder();
// Send a single notification with the settings configured by other buttons.
listBuilder.addItem(
new GridItem.Builder()
.setTitle("Send a notification")
.setImage(new CarIcon.Builder(mIcon).build())
.setOnClickListener(this::sendNotification)
.build());
// Start a repeating notification with the settings configured by other buttons.
listBuilder.addItem(
new GridItem.Builder()
.setTitle("Start notifications")
.setImage(new CarIcon.Builder(mIcon).build())
.setOnClickListener(() -> mHandler.sendMessage(
mHandler.obtainMessage(MSG_SEND_NOTIFICATION)))
.build());
// Stop the repeating notification and reset the count.
listBuilder.addItem(
new GridItem.Builder()
.setTitle("Stop notifications")
.setImage(new CarIcon.Builder(mIcon).build())
.setOnClickListener(() -> {
mHandler.removeMessages(MSG_SEND_NOTIFICATION);
CarNotificationManager.from(getCarContext()).cancelAll();
mNotificationCount = 0;
})
.build());
// Configure the notification importance.
listBuilder.addItem(
new GridItem.Builder()
.setImage(new CarIcon.Builder(mIcon).build())
.setTitle("Importance")
.setText(getImportanceString())
.setOnClickListener(() -> {
setImportance();
invalidate();
})
.build());
// Configure whether the notification's category is navigation.
listBuilder.addItem(
new GridItem.Builder()
.setImage(new CarIcon.Builder(mIcon).build())
.setTitle("Category")
.setText(getCategoryString())
.setOnClickListener(() -> {
mIsNavCategory = !mIsNavCategory;
invalidate();
})
.build());
// Configure whether the notification is an ongoing notification.
listBuilder.addItem(
new GridItem.Builder()
.setImage(new CarIcon.Builder(mIcon).build())
.setTitle("Ongoing")
.setText(String.valueOf(mSetOngoing))
.setOnClickListener(() -> {
mSetOngoing = !mSetOngoing;
invalidate();
})
.build());
return new GridTemplate.Builder()
.setSingleList(listBuilder.build())
.setTitle("Notification Demo")
.setHeaderAction(Action.BACK)
.build();
}