aboutsummaryrefslogtreecommitdiff
path: root/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink
diff options
context:
space:
mode:
authorAdora Zhang <qiaozhang@google.com>2018-03-02 18:29:41 -0800
committerQiao (Adora) Zhang <qiaozhang@google.com>2018-03-15 02:44:08 +0000
commit6ce058961ba1eb9263151ec2cdf809413f1e6f4f (patch)
tree7b45ee19ed36c5c623d52a1a3f928a0face4135a /tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink
parent20aaa2f51cd42834a894822f0abec377d122639e (diff)
downloadCar-6ce058961ba1eb9263151ec2cdf809413f1e6f4f.tar.gz
Add kitchen sink test fragment for notifications.
Bug: 74862300 Test: N/A Change-Id: Iedc605c4d62820abc97e4cf88b7d4b03d4b91c98 (cherry picked from commit 406a205467dac3c0e5ce99befba31b38d035548d)
Diffstat (limited to 'tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink')
-rw-r--r--tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java2
-rw-r--r--tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/notification/NotificationFragment.java187
2 files changed, 189 insertions, 0 deletions
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
index bfc90d1be6..32e0349d44 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
@@ -31,6 +31,7 @@ import com.google.android.car.kitchensink.displayinfo.DisplayInfoFragment;
import com.google.android.car.kitchensink.hvac.HvacTestFragment;
import com.google.android.car.kitchensink.input.InputTestFragment;
import com.google.android.car.kitchensink.job.JobSchedulerFragment;
+import com.google.android.car.kitchensink.notification.NotificationFragment;
import com.google.android.car.kitchensink.orientation.OrientationTestFragment;
import com.google.android.car.kitchensink.power.PowerTestFragment;
import com.google.android.car.kitchensink.radio.RadioTestFragment;
@@ -148,6 +149,7 @@ public class KitchenSinkActivity extends CarDrawerActivity {
add("inst cluster", InstrumentClusterFragment.class);
add("input test", InputTestFragment.class);
add("job scheduler", JobSchedulerFragment.class);
+ add("notification", NotificationFragment.class);
add("orientation test", OrientationTestFragment.class);
add("power test", PowerTestFragment.class);
add("radio", RadioTestFragment.class);
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/notification/NotificationFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/notification/NotificationFragment.java
new file mode 100644
index 0000000000..ab171f9993
--- /dev/null
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/notification/NotificationFragment.java
@@ -0,0 +1,187 @@
+package com.google.android.car.kitchensink.notification;
+
+import static android.security.KeyStore.getApplicationContext;
+
+import android.annotation.Nullable;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.RemoteInput;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+import com.google.android.car.kitchensink.KitchenSinkActivity;
+import com.google.android.car.kitchensink.R;
+
+/**
+ * Test fragment that can send all sorts of notifications.
+ */
+public class NotificationFragment extends Fragment {
+ private static final String CHANNEL_ID_1 = "kitchensink.channel1";
+ private static final String CHANNEL_ID_2 = "kitchensink.channel2";
+ private static final String CHANNEL_ID_3 = "kitchensink.channel3";
+ private static final String CHANNEL_ID_4 = "kitchensink.channel4";
+ private static final String CHANNEL_ID_5 = "kitchensink.channel5";
+ private static final String CHANNEL_ID_6 = "kitchensink.channel6";
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.notification_fragment, container, false);
+ Button cancelAllButton = view.findViewById(R.id.cancel_all_button);
+ Button importanceHighButton = view.findViewById(R.id.importance_high_button);
+ Button importanceHighButton2 = view.findViewById(R.id.importance_high_button_2);
+ Button importanceLowButton = view.findViewById(R.id.importance_low_button);
+ Button importanceMinButton = view.findViewById(R.id.importance_min_button);
+ Button importanceDefaultButton = view.findViewById(R.id.importance_default_button);
+ Button ongoingButton = view.findViewById(R.id.ongoing_button);
+ Button messageButton = view.findViewById(R.id.category_message_button);
+
+ NotificationManager manager =
+ (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
+
+ // cancel all button
+ cancelAllButton.setOnClickListener(v -> manager.cancelAll());
+
+ // importance high notifications
+ NotificationChannel highImportanceChannel =
+ new NotificationChannel(
+ CHANNEL_ID_1, "Importance High", NotificationManager.IMPORTANCE_HIGH);
+ manager.createNotificationChannel(highImportanceChannel);
+
+ importanceHighButton.setOnClickListener(v -> {
+
+ Notification notification = new Notification.Builder(getActivity(), CHANNEL_ID_1)
+ .setContentTitle("Importance High")
+ .setContentText("blah")
+ .setSmallIcon(R.drawable.car_ic_mode)
+ .build();
+ manager.notify(1, notification);
+ });
+
+ importanceHighButton2.setOnClickListener(v -> {
+ Notification notification = new Notification.Builder(getActivity(), CHANNEL_ID_1)
+ .setContentTitle("Importance High 2")
+ .setContentText("blah blah blah")
+ .setSmallIcon(R.drawable.car_ic_mode)
+ .build();
+ manager.notify(2, notification);
+ });
+
+ // importance default
+ importanceDefaultButton.setOnClickListener(v -> {
+ NotificationChannel channel =
+ new NotificationChannel(
+ CHANNEL_ID_3,
+ "Importance Default",
+ NotificationManager.IMPORTANCE_DEFAULT);
+ manager.createNotificationChannel(channel);
+
+ Notification notification = new Notification.Builder(getActivity(), CHANNEL_ID_3)
+ .setContentTitle("Importance Default")
+ .setSmallIcon(R.drawable.car_ic_mode)
+ .build();
+ manager.notify(4, notification);
+ });
+
+ // importance low
+ importanceLowButton.setOnClickListener(v -> {
+ NotificationChannel channel =
+ new NotificationChannel(
+ CHANNEL_ID_4, "Importance Low", NotificationManager.IMPORTANCE_LOW);
+ manager.createNotificationChannel(channel);
+
+ Notification notification = new Notification.Builder(getActivity(), CHANNEL_ID_4)
+ .setContentTitle("Importance Low")
+ .setContentText("low low low")
+ .setSmallIcon(R.drawable.car_ic_mode)
+ .build();
+ manager.notify(5, notification);
+ });
+
+ // importance min
+ importanceMinButton.setOnClickListener(v -> {
+ NotificationChannel channel =
+ new NotificationChannel(
+ CHANNEL_ID_5, "Importance Min", NotificationManager.IMPORTANCE_MIN);
+ manager.createNotificationChannel(channel);
+
+ Notification notification = new Notification.Builder(getActivity(), CHANNEL_ID_5)
+ .setContentTitle("Importance Min")
+ .setContentText("min min min")
+ .setSmallIcon(R.drawable.car_ic_mode)
+ .build();
+ manager.notify(6, notification);
+ });
+
+ // ongoing
+ ongoingButton.setOnClickListener(v -> {
+ NotificationChannel channel =
+ new NotificationChannel(
+ CHANNEL_ID_6, "Ongoing", NotificationManager.IMPORTANCE_DEFAULT);
+ manager.createNotificationChannel(channel);
+
+ Notification notification = new Notification.Builder(getActivity(), CHANNEL_ID_6)
+ .setContentTitle("Playing music or something")
+ .setSmallIcon(R.drawable.car_ic_mode)
+ .setOngoing(true)
+ .build();
+ manager.notify(7, notification);
+ });
+
+ // category message
+ messageButton.setOnClickListener(v -> {
+ NotificationChannel channel =
+ new NotificationChannel(
+ CHANNEL_ID_2, "Message", NotificationManager.IMPORTANCE_HIGH);
+ manager.createNotificationChannel(channel);
+
+ Intent intent = new Intent(getActivity(), KitchenSinkActivity.class);
+ PendingIntent readIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);
+
+ RemoteInput remoteInput = new RemoteInput.Builder("voice reply").build();
+ PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(),
+ 12345,
+ intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
+ Notification.Person personJohn = new Notification.Person().setName("John Doe");
+ Notification.Person personJane = new Notification.Person().setName("Jane Roe");
+ Notification.MessagingStyle messagingStyle =
+ new Notification.MessagingStyle(personJohn)
+ .setConversationTitle("Whassup")
+ .addHistoricMessage(
+ new Notification.MessagingStyle.Message(
+ "historic message",
+ System.currentTimeMillis() - 3600,
+ personJohn))
+ .addMessage(new Notification.MessagingStyle.Message(
+ "message", System.currentTimeMillis(), personJane));
+
+ Notification notification = new Notification.Builder(getActivity(), CHANNEL_ID_2)
+ .setContentTitle("Message from someone")
+ .setContentText("hi")
+ .setCategory(Notification.CATEGORY_MESSAGE)
+ .setSmallIcon(R.drawable.car_ic_mode)
+ .setStyle(messagingStyle)
+ .setAutoCancel(true)
+ .addAction(
+ new Notification.Action.Builder(null, "read", readIntent).build())
+ .addAction(
+ new Notification.Action.Builder(null, "reply", replyIntent)
+ .addRemoteInput(remoteInput).build())
+ .extend(new Notification.CarExtender().setColor(R.color.car_red_500))
+ .build();
+ manager.notify(3, notification);
+ });
+
+ return view;
+ }
+}