From 205ec5a969963f563b30b37385362ccfebdd5e4c Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Wed, 14 Nov 2012 08:43:18 -0800 Subject: Clean up the Builder test. Improved vibration coverage Fixed LED color Added priority Added a start delay (for testing LED while screen off) Change-Id: I3dab0a1a7494f0fe7631d1af49c0fb9a1fdd3f63 --- .../res/layout/notification_builder_test.xml | 1047 +++++++++++--------- tests/StatusBar/res/values/styles.xml | 17 +- .../statusbartest/NotificationBuilderTest.java | 85 +- 3 files changed, 654 insertions(+), 495 deletions(-) (limited to 'tests') diff --git a/tests/StatusBar/res/layout/notification_builder_test.xml b/tests/StatusBar/res/layout/notification_builder_test.xml index 94fc089..5987c84 100644 --- a/tests/StatusBar/res/layout/notification_builder_test.xml +++ b/tests/StatusBar/res/layout/notification_builder_test.xml @@ -222,307 +222,320 @@ > - + - - - - - + + + + + + + - + - - - - - - - - - + + + + + + + + + + + - + - - - - - - + + + + + + + + - + - - - - - - - + + + + + + + + + - + - - - - + + + + + + - + - - - - - - - - - + + + + + + + + + + + - + - - - - + + + + + + - + - - - - + + + + + - + - - - - - - - - + + + + + + + + + - + - - - - - - + + + + + + + - + - - - - - - - + + + + + + + + - + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - + + + + + + + + + style="@style/FieldGroup" + android:layout_marginTop="30dp" + > - - - + + + + + - + + style="@style/FieldGroup" + > - - - + + + + + - - - + + + + + + + + diff --git a/tests/StatusBar/res/values/styles.xml b/tests/StatusBar/res/values/styles.xml index 103a25a..f2c9f0d 100644 --- a/tests/StatusBar/res/values/styles.xml +++ b/tests/StatusBar/res/values/styles.xml @@ -45,8 +45,10 @@ + + + diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java b/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java index 2f0c173..5d0b155 100644 --- a/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java +++ b/tests/StatusBar/src/com/android/statusbartest/NotificationBuilderTest.java @@ -30,6 +30,7 @@ import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.os.Bundle; import android.os.Environment; +import android.os.Handler; import android.os.Vibrator; import android.os.Handler; import android.text.SpannableStringBuilder; @@ -49,11 +50,14 @@ public class NotificationBuilderTest extends Activity private final static String TAG = "NotificationTestList"; NotificationManager mNM; + Handler mHandler; + int mStartDelay; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); + mHandler = new Handler(); setContentView(R.layout.notification_builder_test); if (icicle == null) { setDefaults(); @@ -100,8 +104,13 @@ public class NotificationBuilderTest extends Activity setChecked(R.id.large_icon_none); setChecked(R.id.sound_none); setChecked(R.id.vibrate_none); + setChecked(R.id.pri_default); setChecked(R.id.lights_red); setChecked(R.id.lights_off); + setChecked(R.id.delay_none); +// setChecked(R.id.default_vibrate); +// setChecked(R.id.default_sound); +// setChecked(R.id.default_lights); } private View.OnClickListener mClickListener = new View.OnClickListener() { @@ -183,9 +192,13 @@ public class NotificationBuilderTest extends Activity } }; - private void sendNotification(int id) { + private void sendNotification(final int id) { final Notification n = buildNotification(id); - mNM.notify(id, n); + mHandler.postDelayed(new Runnable() { + public void run() { + mNM.notify(id, n); + } + }, mStartDelay); } private static CharSequence subst(CharSequence in, char ch, CharSequence sub) { @@ -323,23 +336,26 @@ public class NotificationBuilderTest extends Activity // vibrate switch (getRadioChecked(R.id.group_vibrate)) { case R.id.vibrate_none: + b.setVibrate(null); break; - case R.id.vibrate_short: - b.setVibrate(new long[] { 0, 200 }); + case R.id.vibrate_zero: + b.setVibrate(new long[] { 0 }); break; - case R.id.vibrate_medium: - b.setVibrate(new long[] { 0, 500 }); + case R.id.vibrate_short: + b.setVibrate(new long[] { 0, 100 }); 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 }); + b.setVibrate(new long[] { 0, 50, 200, 50, 200, 50, 500, + 500, 200, 500, 200, 500, 500, + 50, 200, 50, 200, 50 }); break; } // lights - final int color = getRadioInt(R.id.group_lights_color, 0xff0000); + final int color = getRadioHex(R.id.group_lights_color, 0xff0000); int onMs; int offMs; switch (getRadioChecked(R.id.group_lights_blink)) { @@ -365,6 +381,35 @@ public class NotificationBuilderTest extends Activity b.setLights(color, onMs, offMs); } + // priority + switch (getRadioChecked(R.id.group_priority)) { + case R.id.pri_min: + b.setPriority(Notification.PRIORITY_MIN); + break; + case R.id.pri_low: + b.setPriority(Notification.PRIORITY_LOW); + break; + case R.id.pri_default: + b.setPriority(Notification.PRIORITY_DEFAULT); + break; + case R.id.pri_high: + b.setPriority(Notification.PRIORITY_HIGH); + break; + case R.id.pri_max: + b.setPriority(Notification.PRIORITY_MAX); + break; + } + + // start delay + switch (getRadioChecked(R.id.group_delay)) { + case R.id.delay_none: + mStartDelay = 0; + break; + case R.id.delay_5: + mStartDelay = 5000; + break; + } + // flags b.setOngoing(getChecked(R.id.flag_ongoing)); b.setOnlyAlertOnce(getChecked(R.id.flag_once)); @@ -383,7 +428,7 @@ public class NotificationBuilderTest extends Activity } b.setDefaults(defaults); - return b.getNotification(); + return b.build(); } private void setChecked(int id) { @@ -396,14 +441,14 @@ public class NotificationBuilderTest extends Activity return g.getCheckedRadioButtonId(); } - private CharSequence getRadioTag(int id) { + private String getRadioTag(int id) { final RadioGroup g = (RadioGroup)findViewById(id); final View v = findViewById(g.getCheckedRadioButtonId()); - return (CharSequence) v.getTag(); + return (String) v.getTag(); } private int getRadioInt(int id, int def) { - CharSequence str = getRadioTag(id); + String str = getRadioTag(id); if (TextUtils.isEmpty(str)) { return def; } else { @@ -415,6 +460,22 @@ public class NotificationBuilderTest extends Activity } } + private int getRadioHex(int id, int def) { + String str = getRadioTag(id); + if (TextUtils.isEmpty(str)) { + return def; + } else { + if (str.startsWith("0x")) { + str = str.substring(2); + } + try { + return Integer.parseInt(str.toString(), 16); + } catch (NumberFormatException ex) { + return def; + } + } + } + private boolean getChecked(int id) { final CompoundButton b = (CompoundButton)findViewById(id); return b.isChecked(); -- cgit v1.1