summaryrefslogtreecommitdiffstats
path: root/tests/StatusBar/src
diff options
context:
space:
mode:
authorJoe Onorato <joeo@google.com>2010-11-22 16:09:29 -0800
committerJoe Onorato <joeo@google.com>2010-11-22 16:19:40 -0800
commit8d0b655c496e9125fc8d289c4e5bc9a78297ba3d (patch)
tree49ad9d96824e62cf44451de6f20d870e8941e0f5 /tests/StatusBar/src
parent83d97c8c7ddff9374f876bef48758414a7775cb1 (diff)
downloadframeworks_base-8d0b655c496e9125fc8d289c4e5bc9a78297ba3d.zip
frameworks_base-8d0b655c496e9125fc8d289c4e5bc9a78297ba3d.tar.gz
frameworks_base-8d0b655c496e9125fc8d289c4e5bc9a78297ba3d.tar.bz2
Add a better notification test and clean up the flag handling in the notification builder.
Change-Id: I9354ed2c2cda690f53e5f43ad60943b63b02e7d4
Diffstat (limited to 'tests/StatusBar/src')
-rw-r--r--tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java392
1 files changed, 329 insertions, 63 deletions
diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java b/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java
index 3c26212..e9a3513 100644
--- a/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java
+++ b/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java
@@ -16,6 +16,7 @@
package com.android.statusbartest;
+import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -25,106 +26,363 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
+import android.os.Bundle;
import android.os.Environment;
import android.os.Vibrator;
import android.os.Handler;
+import android.text.TextUtils;
import android.util.Log;
import android.net.Uri;
import android.os.SystemClock;
+import android.view.View;
+import android.widget.CompoundButton;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
import android.widget.RemoteViews;
import android.os.PowerManager;
-public class NotificationBuilderTest extends TestActivity
+public class NotificationBuilderTest extends Activity
{
private final static String TAG = "NotificationTestList";
NotificationManager mNM;
@Override
- protected String tag() {
- return TAG;
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
+ setContentView(R.layout.notification_builder_test);
+ if (icicle == null) {
+ setDefaults();
+ }
+ for (int id: new int[] {
+ R.id.clear_1,
+ R.id.clear_2,
+ R.id.clear_3,
+ R.id.clear_4,
+ R.id.clear_5,
+ R.id.clear_6,
+ R.id.clear_7,
+ R.id.clear_8,
+ R.id.clear_9,
+ R.id.clear_10,
+ R.id.notify_1,
+ R.id.notify_2,
+ R.id.notify_3,
+ R.id.notify_4,
+ R.id.notify_5,
+ R.id.notify_6,
+ R.id.notify_7,
+ R.id.notify_8,
+ R.id.notify_9,
+ R.id.notify_10,
+ R.id.ten,
+ R.id.clear_all,
+ }) {
+ findViewById(id).setOnClickListener(mClickListener);
+ }
}
- @Override
- protected Test[] tests() {
- mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
-
- return mTests;
+ private void setDefaults() {
+ setChecked(R.id.when_now);
+ setChecked(R.id.icon_surprise);
+ setChecked(R.id.title_medium);
+ setChecked(R.id.text_medium);
+ setChecked(R.id.info_none);
+ setChecked(R.id.number_0);
+ setChecked(R.id.intent_alert);
+ setChecked(R.id.delete_none);
+ setChecked(R.id.full_screen_none);
+ setChecked(R.id.ticker_none);
+ setChecked(R.id.large_icon_none);
+ setChecked(R.id.sound_none);
+ setChecked(R.id.vibrate_none);
+ setChecked(R.id.lights_red);
+ setChecked(R.id.lights_off);
}
- private Test[] mTests = new Test[] {
- new Test("Cancel (1)") {
- public void run() {
- mNM.cancel(1);
+ private View.OnClickListener mClickListener = new View.OnClickListener() {
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.clear_1:
+ mNM.cancel(1);
+ break;
+ case R.id.clear_2:
+ mNM.cancel(2);
+ break;
+ case R.id.clear_3:
+ mNM.cancel(3);
+ break;
+ case R.id.clear_4:
+ mNM.cancel(4);
+ break;
+ case R.id.clear_5:
+ mNM.cancel(5);
+ break;
+ case R.id.clear_6:
+ mNM.cancel(6);
+ break;
+ case R.id.clear_7:
+ mNM.cancel(7);
+ break;
+ case R.id.clear_8:
+ mNM.cancel(8);
+ break;
+ case R.id.clear_9:
+ mNM.cancel(9);
+ break;
+ case R.id.clear_10:
+ mNM.cancel(10);
+ break;
+ case R.id.notify_1:
+ sendNotification(1);
+ break;
+ case R.id.notify_2:
+ sendNotification(2);
+ break;
+ case R.id.notify_3:
+ sendNotification(3);
+ break;
+ case R.id.notify_4:
+ sendNotification(4);
+ break;
+ case R.id.notify_5:
+ sendNotification(5);
+ break;
+ case R.id.notify_6:
+ sendNotification(6);
+ break;
+ case R.id.notify_7:
+ sendNotification(7);
+ break;
+ case R.id.notify_8:
+ sendNotification(8);
+ break;
+ case R.id.notify_9:
+ sendNotification(9);
+ break;
+ case R.id.notify_10:
+ sendNotification(10);
+ break;
+ case R.id.ten: {
+ for (int id=1; id<=10; id++) {
+ sendNotification(id);
+ }
+ break;
+ }
+ case R.id.clear_all: {
+ for (int id=1; id<=10; id++) {
+ mNM.cancel(id);
+ }
+ break;
+ }
}
- },
+ }
+ };
- new Test("Basic Content (1)") {
- public void run() {
- int id = 1;
- final Notification.Builder b = makeBasicBuilder(this, id);
+ private void sendNotification(int id) {
+ final Notification n = buildNotification(id);
+ mNM.notify(id, n);
+ }
- mNM.notify(id, b.getNotification());
- }
- },
+ private Notification buildNotification(int id) {
+ Notification.Builder b = new Notification.Builder(this);
- new Test("Content w/ Info (1)") {
- public void run() {
- int id = 1;
- final Notification.Builder b = makeBasicBuilder(this, id);
+ // when
+ switch (getRadioChecked(R.id.group_when)) {
+ case R.id.when_midnight:
+ break;
+ case R.id.when_now:
+ b.setWhen(System.currentTimeMillis());
+ break;
+ case R.id.when_now_plus_1h:
+ break;
+ case R.id.when_tomorrow:
+ break;
+ }
- b.setContentInfo("Snoozed");
+ // icon
+ switch (getRadioChecked(R.id.group_icon)) {
+ case R.id.icon_im:
+ b.setSmallIcon(R.drawable.icon1);
+ break;
+ case R.id.icon_alert:
+ b.setSmallIcon(R.drawable.icon2);
+ break;
+ case R.id.icon_surprise:
+ b.setSmallIcon(R.drawable.emo_im_kissing);
+ break;
+ }
- mNM.notify(id, b.getNotification());
- }
- },
+ // title
+ final String title = getRadioTag(R.id.group_title);
+ if (!TextUtils.isEmpty(title)) {
+ b.setContentTitle(title);
+ }
- new Test("w/ Number (1)") {
- public void run() {
- int id = 1;
- final Notification.Builder b = makeBasicBuilder(this, id);
+ // text
+ final String text = getRadioTag(R.id.group_text);
+ if (!TextUtils.isEmpty(text)) {
+ b.setContentText(text);
+ }
- b.setNumber(12345);
+ // info
+ final String info = getRadioTag(R.id.group_info);
+ if (!TextUtils.isEmpty(info)) {
+ b.setContentInfo(info);
+ }
- mNM.notify(id, b.getNotification());
- }
- },
+ // number
+ b.setNumber(getRadioInt(R.id.group_number, 0));
- new Test("w/ Number and Large Icon (1)") {
- public void run() {
- int id = 1;
- final Notification.Builder b = makeBasicBuilder(this, id);
+ // contentIntent
+ switch (getRadioChecked(R.id.group_intent)) {
+ case R.id.intent_none:
+ break;
+ case R.id.intent_alert:
+ b.setContentIntent(makeContentIntent(id));
+ break;
+ }
- b.setNumber(42);
+ // deleteIntent
+ switch (getRadioChecked(R.id.group_delete)) {
+ case R.id.delete_none:
+ break;
+ case R.id.delete_alert:
+ b.setDeleteIntent(makeDeleteIntent(id));
+ break;
+ }
- final BitmapDrawable bd = (BitmapDrawable)getResources().getDrawable(
- R.drawable.pineapple);
- b.setLargeIcon(Bitmap.createBitmap(bd.getBitmap()));
+ // fullScreenIntent TODO
- mNM.notify(id, b.getNotification());
- }
- },
- };
+ // ticker
+ switch (getRadioChecked(R.id.group_ticker)) {
+ case R.id.ticker_none:
+ break;
+ case R.id.ticker_short:
+ case R.id.ticker_wrap:
+ case R.id.ticker_haiku:
+ b.setTicker(getRadioTag(R.id.group_ticker));
+ break;
+ case R.id.ticker_custom:
+ // TODO
+ break;
+ }
- private Notification.Builder makeBasicBuilder(Test t, int id) {
- final Notification.Builder b = new Notification.Builder(this);
+ // largeIcon
+ switch (getRadioChecked(R.id.group_large_icon)) {
+ case R.id.large_icon_none:
+ break;
+ case R.id.large_icon_pineapple:
+ b.setLargeIcon(loadBitmap(R.drawable.pineapple));
+ break;
+ }
- b.setWhen(System.currentTimeMillis());
- b.setSmallIcon(R.drawable.ic_statusbar_chat);
- b.setContentTitle("Notification builder Test");
- b.setContentText(t.name + "\nhappy notifying");
- b.setContentIntent(makeContentIntent(id));
- b.setDeleteIntent(makeDeleteIntent(id));
+ // sound TODO
- return b;
+ // vibrate
+ switch (getRadioChecked(R.id.group_vibrate)) {
+ case R.id.vibrate_none:
+ break;
+ case R.id.vibrate_short:
+ b.setVibrate(new long[] { 0, 200 });
+ break;
+ case R.id.vibrate_medium:
+ b.setVibrate(new long[] { 0, 500 });
+ break;
+ case R.id.vibrate_long:
+ b.setVibrate(new long[] { 0, 1000 });
+ break;
+ case R.id.vibrate_pattern:
+ b.setVibrate(new long[] { 0, 250, 250, 250, 250, 250, 250, 250 });
+ break;
+ }
+
+ // lights
+ final int color = getRadioInt(R.id.group_lights_color, 0xff0000);
+ int onMs;
+ int offMs;
+ switch (getRadioChecked(R.id.group_lights_blink)) {
+ case R.id.lights_slow:
+ onMs = 1300;
+ offMs = 1300;
+ break;
+ case R.id.lights_fast:
+ onMs = 300;
+ offMs = 300;
+ break;
+ case R.id.lights_on:
+ onMs = 1;
+ offMs = 0;
+ break;
+ case R.id.lights_off:
+ default:
+ onMs = 0;
+ offMs = 0;
+ break;
+ }
+ if (onMs != 0 && offMs != 0) {
+ b.setLights(color, onMs, offMs);
+ }
+
+ // flags
+ b.setOngoing(getChecked(R.id.flag_ongoing));
+ b.setOnlyAlertOnce(getChecked(R.id.flag_once));
+ b.setAutoCancel(getChecked(R.id.flag_auto_cancel));
+
+ // defaults
+ int defaults = 0;
+ if (getChecked(R.id.default_sound)) {
+ defaults |= Notification.DEFAULT_SOUND;
+ }
+ if (getChecked(R.id.default_vibrate)) {
+ defaults |= Notification.DEFAULT_VIBRATE;
+ }
+ if (getChecked(R.id.default_lights)) {
+ defaults |= Notification.DEFAULT_LIGHTS;
+ }
+ b.setDefaults(defaults);
+
+ return b.getNotification();
}
- private PendingIntent makeContentIntent(int id) {
- Intent intent = new Intent(this, ConfirmationActivity.class);
- intent.setData(Uri.fromParts("content", "//status_bar_test/content/" + id, null));
- intent.putExtra(ConfirmationActivity.EXTRA_TITLE, "Content intent");
- intent.putExtra(ConfirmationActivity.EXTRA_TEXT, "id: " + id);
- return PendingIntent.getActivity(this, 0, intent, 0);
+ private void setChecked(int id) {
+ final CompoundButton b = (CompoundButton)findViewById(id);
+ b.setChecked(true);
+ }
+
+ private int getRadioChecked(int id) {
+ final RadioGroup g = (RadioGroup)findViewById(id);
+ return g.getCheckedRadioButtonId();
+ }
+
+ private String getRadioTag(int id) {
+ final RadioGroup g = (RadioGroup)findViewById(id);
+ final View v = findViewById(g.getCheckedRadioButtonId());
+ return (String)v.getTag();
+ }
+
+ private int getRadioInt(int id, int def) {
+ String str = getRadioTag(id);
+ if (TextUtils.isEmpty(str)) {
+ return def;
+ } else {
+ try {
+ return Integer.parseInt(str);
+ } catch (NumberFormatException ex) {
+ return def;
+ }
+ }
+ }
+
+ private boolean getChecked(int id) {
+ final CompoundButton b = (CompoundButton)findViewById(id);
+ return b.isChecked();
+ }
+
+ private Bitmap loadBitmap(int id) {
+ final BitmapDrawable bd = (BitmapDrawable)getResources().getDrawable(id);
+ return Bitmap.createBitmap(bd.getBitmap());
}
private PendingIntent makeDeleteIntent(int id) {
@@ -134,5 +392,13 @@ public class NotificationBuilderTest extends TestActivity
intent.putExtra(ConfirmationActivity.EXTRA_TEXT, "id: " + id);
return PendingIntent.getActivity(this, 0, intent, 0);
}
+
+ private PendingIntent makeContentIntent(int id) {
+ Intent intent = new Intent(this, ConfirmationActivity.class);
+ intent.setData(Uri.fromParts("content", "//status_bar_test/content/" + id, null));
+ intent.putExtra(ConfirmationActivity.EXTRA_TITLE, "Content intent");
+ intent.putExtra(ConfirmationActivity.EXTRA_TEXT, "id: " + id);
+ return PendingIntent.getActivity(this, 0, intent, 0);
+ }
}