NotificationBuilderTest.java revision 3f76aa7755fbb2e77ca6a648bbfa1f75680788c9
1/* 2 * Copyright (C) 2010 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.net.Uri; 28import android.os.Environment; 29import android.os.Vibrator; 30import android.os.Handler; 31import android.util.Log; 32import android.net.Uri; 33import android.os.SystemClock; 34import android.widget.RemoteViews; 35import android.os.PowerManager; 36 37public class NotificationBuilderTest extends TestActivity 38{ 39 private final static String TAG = "NotificationTestList"; 40 41 NotificationManager mNM; 42 43 @Override 44 protected String tag() { 45 return TAG; 46 } 47 48 @Override 49 protected Test[] tests() { 50 mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 51 52 return mTests; 53 } 54 55 private Test[] mTests = new Test[] { 56 new Test("Cancel (1)") { 57 public void run() { 58 mNM.cancel(1); 59 } 60 }, 61 62 new Test("Basic Content (1)") { 63 public void run() { 64 int id = 1; 65 66 Notification.Builder b = new Notification.Builder(NotificationBuilderTest.this); 67 68 b.setWhen(System.currentTimeMillis()); 69 b.setSmallIcon(R.drawable.ic_statusbar_chat); 70 b.setContentTitle("Title"); 71 b.setContentText("text\nline2"); 72 b.setContentIntent(makeContentIntent(id)); 73 b.setDeleteIntent(makeDeleteIntent(id)); 74 75 mNM.notify(id, b.getNotification()); 76 } 77 }, 78 79 new Test("Basic Content w/ Info (1)") { 80 public void run() { 81 int id = 1; 82 83 Notification.Builder b = new Notification.Builder(NotificationBuilderTest.this); 84 85 b.setWhen(System.currentTimeMillis()); 86 b.setSmallIcon(R.drawable.ic_statusbar_chat); 87 b.setContentTitle("Title"); 88 b.setContentText("text\nline2"); 89 b.setContentIntent(makeContentIntent(id)); 90 b.setDeleteIntent(makeDeleteIntent(id)); 91 b.setContentInfo("Snoozed"); 92 93 mNM.notify(id, b.getNotification()); 94 } 95 }, 96 97 new Test("Basic Content w/ Number (1)") { 98 public void run() { 99 int id = 1; 100 101 Notification.Builder b = new Notification.Builder(NotificationBuilderTest.this); 102 103 b.setWhen(System.currentTimeMillis()); 104 b.setSmallIcon(R.drawable.ic_statusbar_chat); 105 b.setContentTitle("Title"); 106 b.setContentText("text\nline2"); 107 b.setContentIntent(makeContentIntent(id)); 108 b.setDeleteIntent(makeDeleteIntent(id)); 109 b.setNumber(12345); 110 111 mNM.notify(id, b.getNotification()); 112 } 113 }, 114 }; 115 116 private PendingIntent makeContentIntent(int id) { 117 Intent intent = new Intent(this, ConfirmationActivity.class); 118 intent.setData(Uri.fromParts("content", "//status_bar_test/content/" + id, null)); 119 intent.putExtra(ConfirmationActivity.EXTRA_TITLE, "Content intent"); 120 intent.putExtra(ConfirmationActivity.EXTRA_TEXT, "id: " + id); 121 return PendingIntent.getActivity(this, 0, intent, 0); 122 } 123 124 private PendingIntent makeDeleteIntent(int id) { 125 Intent intent = new Intent(this, ConfirmationActivity.class); 126 intent.setData(Uri.fromParts("content", "//status_bar_test/delete/" + id, null)); 127 intent.putExtra(ConfirmationActivity.EXTRA_TITLE, "Delete intent"); 128 intent.putExtra(ConfirmationActivity.EXTRA_TEXT, "id: " + id); 129 return PendingIntent.getActivity(this, 0, intent, 0); 130 } 131} 132 133