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
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -45,8 +45,10 @@
|
||||
|
||||
<style name="FieldTitle">
|
||||
<item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_width">120dp</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:gravity">right</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
</style>
|
||||
|
||||
<style name="FieldContents">
|
||||
@@ -61,5 +63,18 @@
|
||||
<item name="android:visibility">gone</item>
|
||||
</style>
|
||||
|
||||
<style name="FieldGroup">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:orientation">horizontal</item>
|
||||
<item name="android:layout_marginTop">18dp</item>
|
||||
</style>
|
||||
|
||||
<style name="FieldChoices">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:orientation">vertical</item>
|
||||
<item name="android:baselineAlignedChildIndex">0</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
|
||||
@@ -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_zero:
|
||||
b.setVibrate(new long[] { 0 });
|
||||
break;
|
||||
case R.id.vibrate_short:
|
||||
b.setVibrate(new long[] { 0, 200 });
|
||||
break;
|
||||
case R.id.vibrate_medium:
|
||||
b.setVibrate(new long[] { 0, 500 });
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user