NotificationTestList.java revision ddf680bff5bb9bc04ef04667644db8ade0b38c46
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.statusbartest; 18 19import android.app.Notification; 20import android.app.NotificationManager; 21import android.app.PendingIntent; 22import android.content.Context; 23import android.content.ContentResolver; 24import android.content.Intent; 25import android.graphics.Bitmap; 26import android.graphics.drawable.BitmapDrawable; 27import android.os.Environment; 28import android.os.Vibrator; 29import android.os.Handler; 30import android.util.Log; 31import android.net.Uri; 32import android.os.SystemClock; 33import android.widget.RemoteViews; 34import android.os.PowerManager; 35 36public class NotificationTestList extends TestActivity 37{ 38 private final static String TAG = "NotificationTestList"; 39 40 NotificationManager mNM; 41 Vibrator mVibrator = new Vibrator(); 42 Handler mHandler = new Handler(); 43 44 long mActivityCreateTime = System.currentTimeMillis(); 45 long mChronometerBase = 0; 46 47 @Override 48 protected String tag() { 49 return TAG; 50 } 51 52 @Override 53 protected Test[] tests() { 54 mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 55 56 return mTests; 57 } 58 59 private Test[] mTests = new Test[] { 60 new Test("Off and sound") { 61 public void run() { 62 PowerManager pm = (PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE); 63 PowerManager.WakeLock wl = 64 pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sound"); 65 wl.acquire(); 66 67 pm.goToSleep(SystemClock.uptimeMillis()); 68 69 Notification n = new Notification(); 70 n.sound = Uri.parse("file://" + Environment.getExternalStorageDirectory() + 71 "/virtual-void.mp3"); 72 Log.d(TAG, "n.sound=" + n.sound); 73 74 mNM.notify(1, n); 75 76 Log.d(TAG, "releasing wake lock"); 77 wl.release(); 78 Log.d(TAG, "released wake lock"); 79 } 80 }, 81 82 new Test("Cancel #1") { 83 public void run() 84 { 85 mNM.cancel(1); 86 } 87 }, 88 89 new Test("Ticker 1 line") { 90 public void run() { 91 Notification n = new Notification(R.drawable.icon1, "tick tick tick", 92 mActivityCreateTime); 93 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 94 "This is a notification!!!", makeIntent()); 95 mNM.notify(1, n); 96 } 97 }, 98 99 new Test("Ticker 1 line & icon") { 100 public void run() { 101 Notification n = new Notification(R.drawable.icon1, "tick tick tick", 102 mActivityCreateTime); 103 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 104 "This is a notification!!!", makeIntent()); 105 n.tickerIcons = new Bitmap[1]; 106 n.tickerIcons[0] = loadBitmap(R.drawable.icon3); 107 mNM.notify(1, n); 108 } 109 }, 110 111 new Test("Ticker 2 lines") { 112 public void run() { 113 Notification n = new Notification(R.drawable.icon1, "tick tick tick\ntock tock", 114 mActivityCreateTime); 115 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 116 "This is a notification!!!", makeIntent()); 117 mNM.notify(1, n); 118 } 119 }, 120 121 new Test("Ticker title") { 122 public void run() { 123 Notification n = new Notification(R.drawable.icon1, null, 124 mActivityCreateTime); 125 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 126 "This is a notification!!!", makeIntent()); 127 n.tickerTitle = "This is a title"; 128 mNM.notify(1, n); 129 } 130 }, 131 132 new Test("Ticker subtitle") { 133 public void run() { 134 Notification n = new Notification(R.drawable.icon1, null, 135 mActivityCreateTime); 136 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 137 "This is a notification!!!", makeIntent()); 138 n.tickerSubtitle = "and a subtitle"; 139 mNM.notify(1, n); 140 } 141 }, 142 143 new Test("Ticker title & subtitle") { 144 public void run() { 145 Notification n = new Notification(R.drawable.icon1, null, 146 mActivityCreateTime); 147 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 148 "This is a notification!!!", makeIntent()); 149 n.tickerTitle = "This is a title it is really really longggggg long long long long"; 150 n.tickerSubtitle = "and a subtitle it is really really longggggg long long long long long long long long long long long long long long long long"; 151 mNM.notify(1, n); 152 } 153 }, 154 155 new Test("Ticker text, title & subtitle") { 156 public void run() { 157 Notification n = new Notification(R.drawable.icon1, "not visible", 158 mActivityCreateTime); 159 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 160 "This is a notification!!!", makeIntent()); 161 n.tickerTitle = "This is a title"; 162 n.tickerSubtitle = "and a subtitle"; 163 mNM.notify(1, n); 164 } 165 }, 166 167 new Test("Ticker title, subtitle & 2 icons") { 168 public void run() { 169 Notification n = new Notification(R.drawable.icon1, null, 170 mActivityCreateTime); 171 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 172 "This is a notification!!!", makeIntent()); 173 n.tickerTitle = "This is a title"; 174 n.tickerSubtitle = "and a subtitle"; 175 176 n.tickerIcons = new Bitmap[2]; 177 n.tickerIcons[0] = loadBitmap(R.drawable.icon3); 178 n.tickerIcons[1] = loadBitmap(R.drawable.app_gmail); 179 180 mNM.notify(1, n); 181 /* 182 n.tickerIcons[0].recycle(); 183 n.tickerIcons[1].recycle(); 184 */ 185 } 186 }, 187 188 new Test("No view") { 189 public void run() { 190 Notification n = new Notification(R.drawable.icon1, "No view", 191 System.currentTimeMillis()); 192 mNM.notify(1, n); 193 } 194 }, 195 196 new Test("No intent") { 197 public void run() { 198 Notification n = new Notification(R.drawable.icon1, "No intent", 199 System.currentTimeMillis()); 200 n.setLatestEventInfo(NotificationTestList.this, "No intent", 201 "No intent", null); 202 mNM.notify(1, n); 203 } 204 }, 205 206 new Test("Layout") { 207 public void run() 208 { 209 Notification n; 210 211 n = new Notification(NotificationTestList.this, 212 R.drawable.ic_statusbar_missedcall, 213 null, System.currentTimeMillis()-(1000*60*60*24), 214 "(453) 123-2328", 215 "", null); 216 n.flags |= Notification.FLAG_ONGOING_EVENT; 217 218 mNM.notify(1, n); 219 220 mNM.notify(2, new Notification(NotificationTestList.this, 221 R.drawable.ic_statusbar_email, 222 null, System.currentTimeMillis(), 223 "Mark Willem, Me (2)", 224 "Re: Didn't you get the memo?", null)); 225 226 mNM.notify(3, new Notification(NotificationTestList.this, 227 R.drawable.ic_statusbar_chat, 228 null, System.currentTimeMillis()+(1000*60*60*24), 229 "Sophia Winterlanden", 230 "Lorem ipsum dolor sit amet.", null)); 231 } 232 }, 233 234 new Test("Bad Icon #1 (when=create)") { 235 public void run() { 236 Notification n = new Notification(R.layout.chrono_notification /* not an icon */, 237 null, mActivityCreateTime); 238 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 239 "This is the same notification!!!", makeIntent()); 240 mNM.notify(1, n); 241 } 242 }, 243 244 new Test("Bad Icon #1 (when=now)") { 245 public void run() { 246 Notification n = new Notification(R.layout.chrono_notification /* not an icon */, 247 null, System.currentTimeMillis()); 248 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 249 "This is the same notification!!!", makeIntent()); 250 mNM.notify(1, n); 251 } 252 }, 253 254 new Test("Bad resource #1 (when=create)") { 255 public void run() { 256 Notification n = new Notification(R.drawable.icon2, 257 null, mActivityCreateTime); 258 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 259 "This is the same notification!!!", makeIntent()); 260 n.contentView.setInt(1 /*bogus*/, "bogus method", 666); 261 mNM.notify(1, n); 262 } 263 }, 264 265 new Test("Bad resource #1 (when=now)") { 266 public void run() { 267 Notification n = new Notification(R.drawable.icon2, 268 null, System.currentTimeMillis()); 269 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 270 "This is the same notification!!!", makeIntent()); 271 n.contentView.setInt(1 /*bogus*/, "bogus method", 666); 272 mNM.notify(1, n); 273 } 274 }, 275 276 277 new Test("Bad resource #3") { 278 public void run() 279 { 280 Notification n = new Notification(NotificationTestList.this, 281 R.drawable.ic_statusbar_missedcall, 282 null, System.currentTimeMillis()-(1000*60*60*24), 283 "(453) 123-2328", 284 "", null); 285 n.contentView.setInt(1 /*bogus*/, "bogus method", 666); 286 mNM.notify(3, n); 287 } 288 }, 289 290 new Test("Times") { 291 public void run() 292 { 293 long now = System.currentTimeMillis(); 294 295 timeNotification(7, "24 hours from now", now+(1000*60*60*24)); 296 timeNotification(6, "12:01:00 from now", now+(1000*60*60*12)+(60*1000)); 297 timeNotification(5, "12 hours from now", now+(1000*60*60*12)); 298 timeNotification(4, "now", now); 299 timeNotification(3, "11:59:00 ago", now-((1000*60*60*12)-(60*1000))); 300 timeNotification(2, "12 hours ago", now-(1000*60*60*12)); 301 timeNotification(1, "24 hours ago", now-(1000*60*60*24)); 302 } 303 }, 304 new StateStress("Stress - Ongoing / Latest", 100, 100, new Runnable[] { 305 new Runnable() { 306 public void run() { 307 Log.d(TAG, "Stress - Ongoing/Latest 0"); 308 Notification n = new Notification(NotificationTestList.this, 309 R.drawable.icon3, 310 null, System.currentTimeMillis(), "Stress - Ongoing", 311 "Notify me!!!", null); 312 n.flags |= Notification.FLAG_ONGOING_EVENT; 313 mNM.notify(1, n); 314 } 315 }, 316 new Runnable() { 317 public void run() { 318 Log.d(TAG, "Stress - Ongoing/Latest 1"); 319 Notification n = new Notification(NotificationTestList.this, 320 R.drawable.icon4, 321 null, System.currentTimeMillis(), "Stress - Latest", 322 "Notify me!!!", null); 323 //n.flags |= Notification.FLAG_ONGOING_EVENT; 324 mNM.notify(1, n); 325 } 326 } 327 }), 328 329 new Test("Long") { 330 public void run() 331 { 332 Notification n = new Notification(); 333 n.defaults |= Notification.DEFAULT_SOUND ; 334 n.vibrate = new long[] { 335 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 336 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 337 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 }; 338 mNM.notify(1, n); 339 } 340 }, 341 342 new Test("Blue Lights") { 343 public void run() 344 { 345 Notification n = new Notification(); 346 n.flags |= Notification.FLAG_SHOW_LIGHTS; 347 n.ledARGB = 0xff0000ff; 348 n.ledOnMS = 1; 349 n.ledOffMS = 0; 350 mNM.notify(1, n); 351 } 352 }, 353 354 new Test("Red Lights") { 355 public void run() 356 { 357 Notification n = new Notification(); 358 n.flags |= Notification.FLAG_SHOW_LIGHTS; 359 n.ledARGB = 0xffff0000; 360 n.ledOnMS = 1; 361 n.ledOffMS = 0; 362 mNM.notify(1, n); 363 } 364 }, 365 366 new Test("Yellow Lights") { 367 public void run() 368 { 369 Notification n = new Notification(); 370 n.flags |= Notification.FLAG_SHOW_LIGHTS; 371 n.ledARGB = 0xffffff00; 372 n.ledOnMS = 1; 373 n.ledOffMS = 0; 374 mNM.notify(1, n); 375 } 376 }, 377 378 new Test("Lights off") { 379 public void run() 380 { 381 Notification n = new Notification(); 382 n.flags |= Notification.FLAG_SHOW_LIGHTS; 383 n.ledARGB = 0x00000000; 384 n.ledOnMS = 0; 385 n.ledOffMS = 0; 386 mNM.notify(1, n); 387 } 388 }, 389 390 new Test("Blue Blinking Slow") { 391 public void run() 392 { 393 Notification n = new Notification(); 394 n.flags |= Notification.FLAG_SHOW_LIGHTS; 395 n.ledARGB = 0xff0000ff; 396 n.ledOnMS = 1300; 397 n.ledOffMS = 1300; 398 mNM.notify(1, n); 399 } 400 }, 401 402 new Test("Blue Blinking Fast") { 403 public void run() 404 { 405 Notification n = new Notification(); 406 n.flags |= Notification.FLAG_SHOW_LIGHTS; 407 n.ledARGB = 0xff0000ff; 408 n.ledOnMS = 300; 409 n.ledOffMS = 300; 410 mNM.notify(1, n); 411 } 412 }, 413 414 new Test("Default All") { 415 public void run() 416 { 417 Notification n = new Notification(); 418 n.defaults |= Notification.DEFAULT_ALL; 419 mNM.notify(1, n); 420 } 421 }, 422 423 new Test("Default All, once") { 424 public void run() 425 { 426 Notification n = new Notification(); 427 n.defaults |= Notification.DEFAULT_ALL; 428 n.flags |= Notification.FLAG_ONLY_ALERT_ONCE ; 429 mNM.notify(1, n); 430 } 431 }, 432 433 new Test("Content Sound") { 434 public void run() 435 { 436 Notification n = new Notification(); 437 n.sound = Uri.parse( 438 "content://media/internal/audio/media/7"); 439 440 mNM.notify(1, n); 441 } 442 }, 443 444 new Test("Resource Sound") { 445 public void run() 446 { 447 Notification n = new Notification(); 448 n.sound = Uri.parse( 449 ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + 450 getPackageName() + "/raw/ringer"); 451 Log.d(TAG, "n.sound=" + n.sound); 452 453 mNM.notify(1, n); 454 } 455 }, 456 457 new Test("Sound and Cancel") { 458 public void run() 459 { 460 Notification n = new Notification(); 461 n.sound = Uri.parse( 462 "content://media/internal/audio/media/7"); 463 464 mNM.notify(1, n); 465 SystemClock.sleep(200); 466 mNM.cancel(1); 467 } 468 }, 469 470 new Test("Vibrate") { 471 public void run() 472 { 473 Notification n = new Notification(); 474 n.vibrate = new long[] { 0, 700, 500, 1000 }; 475 476 mNM.notify(1, n); 477 } 478 }, 479 480 new Test("Vibrate and cancel") { 481 public void run() 482 { 483 Notification n = new Notification(); 484 n.vibrate = new long[] { 0, 700, 500, 1000 }; 485 486 mNM.notify(1, n); 487 SystemClock.sleep(500); 488 mNM.cancel(1); 489 } 490 }, 491 492 new Test("Vibrate pattern") { 493 public void run() 494 { 495 mVibrator.vibrate(new long[] { 250, 1000, 500, 2000 }, -1); 496 } 497 }, 498 499 new Test("Vibrate pattern repeating") { 500 public void run() 501 { 502 mVibrator.vibrate(new long[] { 250, 1000, 500 }, 1); 503 } 504 }, 505 506 new Test("Vibrate 3s") { 507 public void run() 508 { 509 mVibrator.vibrate(3000); 510 } 511 }, 512 513 new Test("Vibrate 100s") { 514 public void run() 515 { 516 mVibrator.vibrate(100000); 517 } 518 }, 519 520 new Test("Vibrate off") { 521 public void run() 522 { 523 mVibrator.cancel(); 524 } 525 }, 526 527 new Test("Cancel #1") { 528 public void run() { 529 mNM.cancel(1); 530 } 531 }, 532 533 new Test("Cancel #1 in 3 sec") { 534 public void run() { 535 mHandler.postDelayed(new Runnable() { 536 public void run() { 537 Log.d(TAG, "Cancelling now..."); 538 mNM.cancel(1); 539 } 540 }, 3000); 541 } 542 }, 543 544 new Test("Cancel #2") { 545 public void run() { 546 mNM.cancel(2); 547 } 548 }, 549 550 new Test("Persistent #1") { 551 public void run() { 552 Notification n = new Notification(R.drawable.icon1, "tick tick tick", 553 mActivityCreateTime); 554 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 555 "This is a notification!!!", makeIntent()); 556 mNM.notify(1, n); 557 } 558 }, 559 560 new Test("Persistent #1 in 3 sec") { 561 public void run() { 562 mHandler.postDelayed(new Runnable() { 563 public void run() { 564 Notification n = new Notification(R.drawable.icon1, 565 " " 566 + "tick tock tick tock\n\nSometimes notifications can " 567 + "be really long and wrap to more than one line.\n" 568 + "Sometimes." 569 + "Ohandwhathappensifwehaveonereallylongstringarewesure" 570 + "thatwesegmentitcorrectly?\n", 571 System.currentTimeMillis()); 572 n.setLatestEventInfo(NotificationTestList.this, 573 "Still Persistent #1", 574 "This is still a notification!!!", 575 makeIntent()); 576 mNM.notify(1, n); 577 } 578 }, 3000); 579 } 580 }, 581 582 new Test("Persistent #2") { 583 public void run() { 584 Notification n = new Notification(R.drawable.icon2, "tock tock tock", 585 System.currentTimeMillis()); 586 n.setLatestEventInfo(NotificationTestList.this, "Persistent #2", 587 "Notify me!!!", makeIntent()); 588 mNM.notify(2, n); 589 } 590 }, 591 592 new Test("Persistent #3") { 593 public void run() { 594 Notification n = new Notification(R.drawable.icon2, "tock tock tock\nmooooo", 595 System.currentTimeMillis()); 596 n.setLatestEventInfo(NotificationTestList.this, "Persistent #3", 597 "Notify me!!!", makeIntent()); 598 mNM.notify(3, n); 599 } 600 }, 601 602 new Test("Persistent #2 Vibrate") { 603 public void run() { 604 Notification n = new Notification(R.drawable.icon2, "tock tock tock", 605 System.currentTimeMillis()); 606 n.setLatestEventInfo(NotificationTestList.this, "Persistent #2", 607 "Notify me!!!", makeIntent()); 608 n.defaults = Notification.DEFAULT_VIBRATE; 609 mNM.notify(2, n); 610 } 611 }, 612 613 new Test("Persistent #1 - different icon") { 614 public void run() { 615 Notification n = new Notification(R.drawable.icon2, null, 616 mActivityCreateTime); 617 n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", 618 "This is the same notification!!!", makeIntent()); 619 mNM.notify(1, n); 620 } 621 }, 622 623 new Test("Chronometer Start") { 624 public void run() { 625 Notification n = new Notification(R.drawable.icon2, "me me me me", 626 System.currentTimeMillis()); 627 n.contentView = new RemoteViews(getPackageName(), R.layout.chrono_notification); 628 mChronometerBase = SystemClock.elapsedRealtime(); 629 n.contentView.setChronometer(R.id.time, mChronometerBase, "Yay! (%s)", true); 630 n.flags |= Notification.FLAG_ONGOING_EVENT; 631 n.contentIntent = makeIntent(); 632 mNM.notify(2, n); 633 } 634 }, 635 636 new Test("Chronometer Stop") { 637 public void run() { 638 mHandler.postDelayed(new Runnable() { 639 public void run() { 640 Log.d(TAG, "Chronometer Stop"); 641 Notification n = new Notification(); 642 n.icon = R.drawable.icon1; 643 n.contentView = new RemoteViews(getPackageName(), 644 R.layout.chrono_notification); 645 n.contentView.setChronometer(R.id.time, mChronometerBase, null, false); 646 n.contentIntent = makeIntent(); 647 mNM.notify(2, n); 648 } 649 }, 3000); 650 } 651 }, 652 653 new Test("Sequential Persistent") { 654 public void run() { 655 mNM.notify(1, notificationWithNumbers(1)); 656 mNM.notify(2, notificationWithNumbers(2)); 657 } 658 }, 659 660 new Test("Replace Persistent") { 661 public void run() { 662 mNM.notify(1, notificationWithNumbers(1)); 663 mNM.notify(1, notificationWithNumbers(1)); 664 } 665 }, 666 667 new Test("Run and Cancel (n=1)") { 668 public void run() { 669 mNM.notify(1, notificationWithNumbers(1)); 670 mNM.cancel(1); 671 } 672 }, 673 674 new Test("Run an Cancel (n=2)") { 675 public void run() { 676 mNM.notify(1, notificationWithNumbers(1)); 677 mNM.notify(2, notificationWithNumbers(2)); 678 mNM.cancel(2); 679 } 680 }, 681 682 // Repeatedly notify and cancel -- triggers bug #670627 683 new Test("Bug 670627") { 684 public void run() { 685 for (int i = 0; i < 10; i++) { 686 Log.d(TAG, "Add two notifications"); 687 mNM.notify(1, notificationWithNumbers(1)); 688 mNM.notify(2, notificationWithNumbers(2)); 689 Log.d(TAG, "Cancel two notifications"); 690 mNM.cancel(1); 691 mNM.cancel(2); 692 } 693 } 694 }, 695 696 new Test("Ten Notifications") { 697 public void run() { 698 for (int i = 0; i < 2; i++) { 699 Notification n = new Notification(NotificationTestList.this, R.drawable.icon2, 700 null, System.currentTimeMillis(), "Persistent #" + i, 701 "Notify me!!!" + i, null); 702 n.flags |= Notification.FLAG_ONGOING_EVENT; 703 n.number = i; 704 mNM.notify((i+1)*10, n); 705 } 706 for (int i = 2; i < 10; i++) { 707 Notification n = new Notification(NotificationTestList.this, R.drawable.icon2, 708 null, System.currentTimeMillis(), "Persistent #" + i, 709 "Notify me!!!" + i, null); 710 n.number = i; 711 mNM.notify((i+1)*10, n); 712 } 713 } 714 }, 715 716 new Test("Cancel eight notifications") { 717 public void run() { 718 for (int i = 1; i < 9; i++) { 719 mNM.cancel((i+1)*10); 720 } 721 } 722 }, 723 724 new Test("Persistent with numbers 1") { 725 public void run() { 726 mNM.notify(1, notificationWithNumbers(1)); 727 } 728 }, 729 730 new Test("Persistent with numbers 222") { 731 public void run() { 732 mNM.notify(1, notificationWithNumbers(22)); 733 } 734 }, 735 736 new Test("Persistent with numbers 333") { 737 public void run() { 738 mNM.notify(1, notificationWithNumbers(333)); 739 } 740 }, 741 742 new Test("Persistent with numbers 4444") { 743 public void run() { 744 mNM.notify(1, notificationWithNumbers(4444)); 745 } 746 }, 747 748 new Test("Crash") { 749 public void run() 750 { 751 PowerManager.WakeLock wl 752 = ((PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE)) 753 .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "crasher"); 754 wl.acquire(); 755 mHandler.postDelayed(new Runnable() { 756 public void run() { 757 throw new RuntimeException("Die!"); 758 } 759 }, 10000); 760 761 } 762 }, 763 764 }; 765 766 private Notification notificationWithNumbers(int num) { 767 Notification n = new Notification(this, R.drawable.icon2, null, System.currentTimeMillis(), 768 "Persistent #2", "Notify me!!!", null); 769 n.number = num; 770 return n; 771 } 772 773 private PendingIntent makeIntent() { 774 Intent intent = new Intent(Intent.ACTION_MAIN); 775 intent.addCategory(Intent.CATEGORY_HOME); 776 return PendingIntent.getActivity(this, 0, intent, 0); 777 } 778 779 class StateStress extends Test { 780 StateStress(String name, int pause, int iterations, Runnable[] tasks) { 781 super(name); 782 mPause = pause; 783 mTasks = tasks; 784 mIteration = iterations; 785 } 786 Runnable[] mTasks; 787 int mNext; 788 int mIteration; 789 long mPause; 790 Runnable mRunnable = new Runnable() { 791 public void run() { 792 mTasks[mNext].run(); 793 mNext++; 794 if (mNext >= mTasks.length) { 795 mNext = 0; 796 mIteration--; 797 if (mIteration <= 0) { 798 return; 799 } 800 } 801 mHandler.postDelayed(mRunnable, mPause); 802 } 803 }; 804 public void run() { 805 mNext = 0; 806 mHandler.postDelayed(mRunnable, mPause); 807 } 808 } 809 810 void timeNotification(int n, String label, long time) { 811 mNM.notify(n, new Notification(NotificationTestList.this, 812 R.drawable.ic_statusbar_missedcall, null, 813 time, label, "" + new java.util.Date(time), null)); 814 815 } 816 817 Bitmap loadBitmap(int resId) { 818 BitmapDrawable bd = (BitmapDrawable)getResources().getDrawable(resId); 819 return Bitmap.createBitmap(bd.getBitmap()); 820 } 821} 822 823