The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.statusbartest; |
| 18 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 19 | import android.app.Notification; |
| 20 | import android.app.NotificationManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.app.PendingIntent; |
Christian Mehlmauer | ef36752 | 2010-05-31 23:08:30 +0200 | [diff] [blame] | 22 | import android.content.Context; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 23 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 25 | import android.graphics.Bitmap; |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 26 | import android.graphics.BitmapFactory; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 27 | import android.graphics.drawable.BitmapDrawable; |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 28 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.os.Vibrator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.Handler; |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 31 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.util.Log; |
| 33 | import android.net.Uri; |
| 34 | import android.os.SystemClock; |
| 35 | import android.widget.RemoteViews; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.PowerManager; |
| 37 | |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 38 | // private NM API |
| 39 | import android.app.INotificationManager; |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 40 | import android.widget.Toast; |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 41 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | public class NotificationTestList extends TestActivity |
| 43 | { |
| 44 | private final static String TAG = "NotificationTestList"; |
| 45 | |
| 46 | NotificationManager mNM; |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 47 | Vibrator mVibrator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | Handler mHandler = new Handler(); |
| 49 | |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 50 | long mActivityCreateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | long mChronometerBase = 0; |
| 52 | |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 53 | boolean mProgressDone = true; |
| 54 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 55 | final int[] kNumberedIconResIDs = { |
| 56 | R.drawable.notification0, |
| 57 | R.drawable.notification1, |
| 58 | R.drawable.notification2, |
| 59 | R.drawable.notification3, |
| 60 | R.drawable.notification4, |
| 61 | R.drawable.notification5, |
| 62 | R.drawable.notification6, |
| 63 | R.drawable.notification7, |
| 64 | R.drawable.notification8, |
| 65 | R.drawable.notification9 |
| 66 | }; |
| 67 | final int kUnnumberedIconResID = R.drawable.notificationx; |
| 68 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | @Override |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 70 | public void onCreate(Bundle icicle) { |
| 71 | super.onCreate(icicle); |
| 72 | mVibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE); |
| 73 | mActivityCreateTime = System.currentTimeMillis(); |
| 74 | } |
| 75 | |
| 76 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | protected String tag() { |
| 78 | return TAG; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | protected Test[] tests() { |
| 83 | mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); |
| 84 | |
| 85 | return mTests; |
| 86 | } |
| 87 | |
| 88 | private Test[] mTests = new Test[] { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 89 | new Test("Off") { |
Joe Onorato | e71d9e4 | 2009-11-05 17:12:18 -0500 | [diff] [blame] | 90 | public void run() { |
Christian Mehlmauer | ef36752 | 2010-05-31 23:08:30 +0200 | [diff] [blame] | 91 | PowerManager pm = (PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE); |
Joe Onorato | e71d9e4 | 2009-11-05 17:12:18 -0500 | [diff] [blame] | 92 | PowerManager.WakeLock wl = |
| 93 | pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sound"); |
| 94 | wl.acquire(); |
| 95 | |
| 96 | pm.goToSleep(SystemClock.uptimeMillis()); |
| 97 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 98 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 99 | .setSmallIcon(R.drawable.stat_sys_phone) |
| 100 | .setContentTitle(name) |
| 101 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 102 | getPackageName() + "/raw/ringer")) |
| 103 | .build(); |
Joe Onorato | e71d9e4 | 2009-11-05 17:12:18 -0500 | [diff] [blame] | 104 | Log.d(TAG, "n.sound=" + n.sound); |
| 105 | |
| 106 | mNM.notify(1, n); |
| 107 | |
| 108 | Log.d(TAG, "releasing wake lock"); |
| 109 | wl.release(); |
| 110 | Log.d(TAG, "released wake lock"); |
| 111 | } |
| 112 | }, |
| 113 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 114 | new Test("Cancel #1") { |
| 115 | public void run() |
| 116 | { |
| 117 | mNM.cancel(1); |
| 118 | } |
| 119 | }, |
| 120 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 121 | new Test("Custom Button") { |
Joe Onorato | 4058ba0 | 2010-10-31 11:38:04 -0700 | [diff] [blame] | 122 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 123 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 124 | .setSmallIcon(R.drawable.icon1) |
| 125 | .setWhen(mActivityCreateTime) |
| 126 | .setContentTitle(name) |
| 127 | .setOngoing(true) |
| 128 | .build(); |
Joe Onorato | 4058ba0 | 2010-10-31 11:38:04 -0700 | [diff] [blame] | 129 | n.contentView = new RemoteViews(getPackageName(), R.layout.button_notification); |
Joe Onorato | 4058ba0 | 2010-10-31 11:38:04 -0700 | [diff] [blame] | 130 | n.contentView.setOnClickPendingIntent(R.id.button, makeIntent2()); |
| 131 | |
| 132 | mNM.notify(1, n); |
| 133 | } |
| 134 | }, |
| 135 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 136 | new Test("Action Button") { |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 137 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 138 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 139 | .setSmallIcon(R.drawable.icon1) |
| 140 | .setWhen(mActivityCreateTime) |
| 141 | .setContentTitle(name) |
| 142 | .setOngoing(true) |
| 143 | .addAction(R.drawable.ic_statusbar_chat, "Button", makeIntent2()) |
| 144 | .build(); |
| 145 | |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 146 | mNM.notify(1, n); |
| 147 | } |
| 148 | }, |
| 149 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 150 | new Test("with intent") { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 151 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 152 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 153 | .setSmallIcon(R.drawable.icon1) |
| 154 | .setWhen(mActivityCreateTime) |
| 155 | .setContentTitle("Persistent #1") |
| 156 | .setContentText("This is a notification!!!") |
| 157 | .setContentIntent(makeIntent2()) |
| 158 | .setOngoing(true) |
| 159 | .build(); |
| 160 | |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 161 | mNM.notify(1, n); |
| 162 | } |
| 163 | }, |
| 164 | |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 165 | new Test("Is blocked?") { |
| 166 | public void run() { |
| 167 | Toast.makeText(NotificationTestList.this, |
| 168 | "package enabled? " + mNM.areNotificationsEnabled(), |
| 169 | Toast.LENGTH_LONG).show(); |
| 170 | } |
| 171 | }, |
| 172 | |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 173 | new Test("importance?") { |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 174 | public void run() { |
| 175 | Toast.makeText(NotificationTestList.this, |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 176 | "importance? " + mNM.getImportance(), |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 177 | Toast.LENGTH_LONG).show(); |
| 178 | } |
| 179 | }, |
| 180 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 181 | new Test("Whens") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | public void run() |
| 183 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 184 | Notification.Builder n = new Notification.Builder(NotificationTestList.this) |
| 185 | .setSmallIcon(R.drawable.icon1) |
| 186 | .setContentTitle(name) |
| 187 | .setOngoing(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 189 | mNM.notify(1, n.setContentTitle("(453) 123-2328") |
| 190 | .setWhen(System.currentTimeMillis()-(1000*60*60*24)) |
| 191 | .build()); |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 192 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 193 | mNM.notify(1, n.setContentTitle("Mark Willem, Me (2)") |
| 194 | .setWhen(System.currentTimeMillis()) |
| 195 | .build()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 197 | mNM.notify(1, n.setContentTitle("Sophia Winterlanden") |
| 198 | .setWhen(System.currentTimeMillis() + (1000 * 60 * 60 * 24)) |
| 199 | .build()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | } |
| 201 | }, |
| 202 | |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 203 | new Test("Bad Icon #1 (when=create)") { |
Joe Onorato | 871bdb9 | 2010-05-24 18:36:53 -0400 | [diff] [blame] | 204 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 205 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 206 | .setSmallIcon(R.layout.chrono_notification /* not an icon */) |
| 207 | .setWhen(mActivityCreateTime) |
| 208 | .setContentTitle("Persistent #1") |
| 209 | .setContentText("This is the same notification!!") |
| 210 | .setContentIntent(makeIntent()) |
| 211 | .build(); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 212 | mNM.notify(1, n); |
Joe Onorato | 871bdb9 | 2010-05-24 18:36:53 -0400 | [diff] [blame] | 213 | } |
| 214 | }, |
| 215 | |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 216 | new Test("Bad Icon #1 (when=now)") { |
| 217 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 218 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 219 | .setSmallIcon(R.layout.chrono_notification /* not an icon */) |
| 220 | .setWhen(System.currentTimeMillis()) |
| 221 | .setContentTitle("Persistent #1") |
| 222 | .setContentText("This is the same notification!!") |
| 223 | .setContentIntent(makeIntent()) |
| 224 | .build(); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 225 | mNM.notify(1, n); |
Joe Onorato | 68065e0 | 2010-02-03 20:21:41 -0800 | [diff] [blame] | 226 | } |
| 227 | }, |
| 228 | |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 229 | new Test("Null Icon #1 (when=now)") { |
| 230 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 231 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 232 | .setSmallIcon(0) |
| 233 | .setWhen(System.currentTimeMillis()) |
| 234 | .setContentTitle("Persistent #1") |
| 235 | .setContentText("This is the same notification!!") |
| 236 | .setContentIntent(makeIntent()) |
| 237 | .build(); |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 238 | mNM.notify(1, n); |
| 239 | } |
| 240 | }, |
| 241 | |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 242 | new Test("Bad resource #1 (when=create)") { |
| 243 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 244 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 245 | .setSmallIcon(R.drawable.icon2) |
| 246 | .setWhen(mActivityCreateTime) |
| 247 | .setContentTitle("Persistent #1") |
| 248 | .setContentText("This is the same notification!!") |
| 249 | .setContentIntent(makeIntent()) |
| 250 | .build(); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 251 | n.contentView.setInt(1 /*bogus*/, "bogus method", 666); |
| 252 | mNM.notify(1, n); |
| 253 | } |
| 254 | }, |
| 255 | |
| 256 | new Test("Bad resource #1 (when=now)") { |
| 257 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 258 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 259 | .setSmallIcon(R.drawable.icon2) |
| 260 | .setWhen(System.currentTimeMillis()) |
| 261 | .setContentTitle("Persistent #1") |
| 262 | .setContentText("This is the same notification!!") |
| 263 | .setContentIntent(makeIntent()) |
| 264 | .build(); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 265 | n.contentView.setInt(1 /*bogus*/, "bogus method", 666); |
| 266 | mNM.notify(1, n); |
| 267 | } |
| 268 | }, |
| 269 | |
Joe Onorato | c83bb73 | 2010-01-19 16:32:22 -0800 | [diff] [blame] | 270 | new Test("Times") { |
| 271 | public void run() |
| 272 | { |
| 273 | long now = System.currentTimeMillis(); |
| 274 | |
| 275 | timeNotification(7, "24 hours from now", now+(1000*60*60*24)); |
| 276 | timeNotification(6, "12:01:00 from now", now+(1000*60*60*12)+(60*1000)); |
| 277 | timeNotification(5, "12 hours from now", now+(1000*60*60*12)); |
| 278 | timeNotification(4, "now", now); |
| 279 | timeNotification(3, "11:59:00 ago", now-((1000*60*60*12)-(60*1000))); |
| 280 | timeNotification(2, "12 hours ago", now-(1000*60*60*12)); |
| 281 | timeNotification(1, "24 hours ago", now-(1000*60*60*24)); |
| 282 | } |
| 283 | }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | new StateStress("Stress - Ongoing / Latest", 100, 100, new Runnable[] { |
| 285 | new Runnable() { |
| 286 | public void run() { |
| 287 | Log.d(TAG, "Stress - Ongoing/Latest 0"); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 288 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 289 | .setSmallIcon(R.drawable.icon3) |
| 290 | .setWhen(System.currentTimeMillis()) |
| 291 | .setContentTitle("Stress - Ongoing") |
| 292 | .setContentText("Notify me!!!") |
| 293 | .setOngoing(true) |
| 294 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | mNM.notify(1, n); |
| 296 | } |
| 297 | }, |
| 298 | new Runnable() { |
| 299 | public void run() { |
| 300 | Log.d(TAG, "Stress - Ongoing/Latest 1"); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 301 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 302 | .setSmallIcon(R.drawable.icon4) |
| 303 | .setWhen(System.currentTimeMillis()) |
| 304 | .setContentTitle("Stress - Latest") |
| 305 | .setContentText("Notify me!!!") |
| 306 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | mNM.notify(1, n); |
| 308 | } |
| 309 | } |
| 310 | }), |
| 311 | |
| 312 | new Test("Long") { |
| 313 | public void run() |
| 314 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 315 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 316 | .setSmallIcon(R.drawable.icon1) |
| 317 | .setContentTitle(name) |
| 318 | .setDefaults(Notification.DEFAULT_SOUND) |
| 319 | .setVibrate(new long[] { |
| 320 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, |
| 321 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, |
| 322 | 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 }) |
| 323 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | mNM.notify(1, n); |
| 325 | } |
| 326 | }, |
| 327 | |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 328 | new Test("Progress #1") { |
| 329 | public void run() { |
| 330 | final boolean PROGRESS_UPDATES_WHEN = true; |
| 331 | if (!mProgressDone) return; |
| 332 | mProgressDone = false; |
| 333 | Thread t = new Thread() { |
| 334 | public void run() { |
| 335 | int x = 0; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 336 | final Notification.Builder n = new Notification.Builder(NotificationTestList.this) |
| 337 | .setSmallIcon(R.drawable.icon1) |
| 338 | .setContentTitle(name) |
| 339 | .setOngoing(true); |
| 340 | |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 341 | while (!mProgressDone) { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 342 | n.setWhen(PROGRESS_UPDATES_WHEN |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 343 | ? System.currentTimeMillis() |
| 344 | : mActivityCreateTime); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 345 | n.setProgress(100, x, false); |
| 346 | n.setContentText("Progress: " + x + "%"); |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 347 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 348 | mNM.notify(500, n.build()); |
Daniel Sandler | 373a998 | 2010-11-30 12:03:59 -0500 | [diff] [blame] | 349 | x = (x + 7) % 100; |
| 350 | |
| 351 | try { |
| 352 | Thread.sleep(1000); |
| 353 | } catch (InterruptedException e) { |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | }; |
| 359 | t.start(); |
| 360 | } |
| 361 | }, |
| 362 | |
| 363 | new Test("Stop Progress") { |
| 364 | public void run() { |
| 365 | mProgressDone = true; |
| 366 | mNM.cancel(500); |
| 367 | } |
| 368 | }, |
| 369 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 370 | new Test("Blue Lights") { |
| 371 | public void run() |
| 372 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 373 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 374 | .setSmallIcon(R.drawable.icon2) |
| 375 | .setContentTitle(name) |
| 376 | .setLights(0xff0000ff, 1, 0) |
| 377 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 378 | .build(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 379 | mNM.notify(1, n); |
| 380 | } |
| 381 | }, |
| 382 | |
| 383 | new Test("Red Lights") { |
| 384 | public void run() |
| 385 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 386 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 387 | .setSmallIcon(R.drawable.icon2) |
| 388 | .setContentTitle(name) |
| 389 | .setLights(0xffff0000, 1, 0) |
| 390 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 391 | .build(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 392 | mNM.notify(1, n); |
| 393 | } |
| 394 | }, |
| 395 | |
| 396 | new Test("Yellow Lights") { |
| 397 | public void run() |
| 398 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 399 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 400 | .setSmallIcon(R.drawable.icon2) |
| 401 | .setContentTitle(name) |
| 402 | .setLights(0xffffff00, 1, 0) |
| 403 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 404 | .build(); |
Mattias Östergren | b0fbe29 | 2010-03-05 09:44:15 +0100 | [diff] [blame] | 405 | mNM.notify(1, n); |
| 406 | } |
| 407 | }, |
| 408 | |
| 409 | new Test("Lights off") { |
| 410 | public void run() |
| 411 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 412 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 413 | .setSmallIcon(R.drawable.icon2) |
| 414 | .setContentTitle(name) |
| 415 | .setLights(0x00000000, 0, 0) |
| 416 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 417 | .build(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 418 | mNM.notify(1, n); |
| 419 | } |
| 420 | }, |
| 421 | |
| 422 | new Test("Blue Blinking Slow") { |
| 423 | public void run() |
| 424 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 425 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 426 | .setSmallIcon(R.drawable.icon2) |
| 427 | .setContentTitle(name) |
| 428 | .setLights(0xff0000ff, 1300, 1300) |
| 429 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 430 | .build(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 431 | mNM.notify(1, n); |
| 432 | } |
| 433 | }, |
| 434 | |
| 435 | new Test("Blue Blinking Fast") { |
| 436 | public void run() |
| 437 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 438 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 439 | .setSmallIcon(R.drawable.icon2) |
| 440 | .setContentTitle(name) |
| 441 | .setLights(0xff0000ff, 300, 300) |
| 442 | .setDefaults(Notification.DEFAULT_LIGHTS) |
| 443 | .build(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 444 | mNM.notify(1, n); |
| 445 | } |
| 446 | }, |
| 447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | new Test("Default All") { |
| 449 | public void run() |
| 450 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 451 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 452 | .setSmallIcon(R.drawable.icon2) |
| 453 | .setContentTitle(name) |
| 454 | .setDefaults(Notification.DEFAULT_ALL) |
| 455 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | mNM.notify(1, n); |
| 457 | } |
| 458 | }, |
| 459 | |
| 460 | new Test("Default All, once") { |
| 461 | public void run() |
| 462 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 463 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 464 | .setSmallIcon(R.drawable.icon2) |
| 465 | .setContentTitle(name) |
| 466 | .setOnlyAlertOnce(true) |
| 467 | .setDefaults(Notification.DEFAULT_ALL) |
| 468 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | mNM.notify(1, n); |
| 470 | } |
| 471 | }, |
| 472 | |
| 473 | new Test("Resource Sound") { |
| 474 | public void run() |
| 475 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 476 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 477 | .setSmallIcon(R.drawable.stat_sys_phone) |
| 478 | .setContentTitle(name) |
| 479 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 480 | getPackageName() + "/raw/ringer")) |
| 481 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | Log.d(TAG, "n.sound=" + n.sound); |
| 483 | |
| 484 | mNM.notify(1, n); |
| 485 | } |
| 486 | }, |
| 487 | |
| 488 | new Test("Sound and Cancel") { |
| 489 | public void run() |
| 490 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 491 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 492 | .setSmallIcon(R.drawable.stat_sys_phone) |
| 493 | .setContentTitle(name) |
| 494 | .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + |
| 495 | getPackageName() + "/raw/ringer")) |
| 496 | .build(); |
| 497 | Log.d(TAG, "n.sound=" + n.sound); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | |
| 499 | mNM.notify(1, n); |
| 500 | SystemClock.sleep(200); |
| 501 | mNM.cancel(1); |
| 502 | } |
| 503 | }, |
| 504 | |
| 505 | new Test("Vibrate") { |
| 506 | public void run() |
| 507 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 508 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 509 | .setSmallIcon(R.drawable.stat_sys_phone) |
| 510 | .setContentTitle(name) |
| 511 | .setVibrate(new long[]{0, 700, 500, 1000}) |
| 512 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | |
| 514 | mNM.notify(1, n); |
| 515 | } |
| 516 | }, |
| 517 | |
| 518 | new Test("Vibrate and cancel") { |
| 519 | public void run() |
| 520 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 521 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 522 | .setSmallIcon(R.drawable.stat_sys_phone) |
| 523 | .setContentTitle(name) |
| 524 | .setVibrate(new long[]{0, 700, 500, 1000}) |
| 525 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | |
| 527 | mNM.notify(1, n); |
| 528 | SystemClock.sleep(500); |
| 529 | mNM.cancel(1); |
| 530 | } |
| 531 | }, |
| 532 | |
| 533 | new Test("Vibrate pattern") { |
| 534 | public void run() |
| 535 | { |
| 536 | mVibrator.vibrate(new long[] { 250, 1000, 500, 2000 }, -1); |
| 537 | } |
| 538 | }, |
| 539 | |
| 540 | new Test("Vibrate pattern repeating") { |
| 541 | public void run() |
| 542 | { |
| 543 | mVibrator.vibrate(new long[] { 250, 1000, 500 }, 1); |
| 544 | } |
| 545 | }, |
| 546 | |
| 547 | new Test("Vibrate 3s") { |
| 548 | public void run() |
| 549 | { |
| 550 | mVibrator.vibrate(3000); |
| 551 | } |
| 552 | }, |
| 553 | |
| 554 | new Test("Vibrate 100s") { |
| 555 | public void run() |
| 556 | { |
| 557 | mVibrator.vibrate(100000); |
| 558 | } |
| 559 | }, |
| 560 | |
| 561 | new Test("Vibrate off") { |
| 562 | public void run() |
| 563 | { |
| 564 | mVibrator.cancel(); |
| 565 | } |
| 566 | }, |
| 567 | |
| 568 | new Test("Cancel #1") { |
| 569 | public void run() { |
| 570 | mNM.cancel(1); |
| 571 | } |
| 572 | }, |
| 573 | |
| 574 | new Test("Cancel #1 in 3 sec") { |
| 575 | public void run() { |
| 576 | mHandler.postDelayed(new Runnable() { |
| 577 | public void run() { |
| 578 | Log.d(TAG, "Cancelling now..."); |
| 579 | mNM.cancel(1); |
| 580 | } |
| 581 | }, 3000); |
| 582 | } |
| 583 | }, |
| 584 | |
| 585 | new Test("Cancel #2") { |
| 586 | public void run() { |
| 587 | mNM.cancel(2); |
| 588 | } |
| 589 | }, |
| 590 | |
| 591 | new Test("Persistent #1") { |
| 592 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 593 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 594 | .setSmallIcon(R.drawable.icon1) |
| 595 | .setWhen(mActivityCreateTime) |
| 596 | .setContentTitle(name) |
| 597 | .setContentText("This is a notification!!!") |
| 598 | .setContentIntent(makeIntent()) |
| 599 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | mNM.notify(1, n); |
| 601 | } |
| 602 | }, |
| 603 | |
| 604 | new Test("Persistent #1 in 3 sec") { |
| 605 | public void run() { |
| 606 | mHandler.postDelayed(new Runnable() { |
| 607 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 608 | String message = " " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | + "tick tock tick tock\n\nSometimes notifications can " |
| 610 | + "be really long and wrap to more than one line.\n" |
| 611 | + "Sometimes." |
| 612 | + "Ohandwhathappensifwehaveonereallylongstringarewesure" |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 613 | + "thatwesegmentitcorrectly?\n"; |
| 614 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 615 | .setSmallIcon(R.drawable.icon1) |
| 616 | .setContentTitle(name) |
| 617 | .setContentText("This is still a notification!!!") |
| 618 | .setContentIntent(makeIntent()) |
| 619 | .setStyle(new Notification.BigTextStyle().bigText(message)) |
| 620 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | mNM.notify(1, n); |
| 622 | } |
| 623 | }, 3000); |
| 624 | } |
| 625 | }, |
| 626 | |
| 627 | new Test("Persistent #2") { |
| 628 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 629 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 630 | .setSmallIcon(R.drawable.icon1) |
| 631 | .setWhen(mActivityCreateTime) |
| 632 | .setContentTitle(name) |
| 633 | .setContentText("This is a notification!!!") |
| 634 | .setContentIntent(makeIntent()) |
| 635 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | mNM.notify(2, n); |
| 637 | } |
| 638 | }, |
| 639 | |
Joe Onorato | 68065e0 | 2010-02-03 20:21:41 -0800 | [diff] [blame] | 640 | new Test("Persistent #3") { |
| 641 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 642 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 643 | .setSmallIcon(R.drawable.icon1) |
| 644 | .setWhen(mActivityCreateTime) |
| 645 | .setContentTitle(name) |
| 646 | .setContentText("This is a notification!!!") |
| 647 | .setContentIntent(makeIntent()) |
| 648 | .build(); |
Joe Onorato | 68065e0 | 2010-02-03 20:21:41 -0800 | [diff] [blame] | 649 | mNM.notify(3, n); |
| 650 | } |
| 651 | }, |
| 652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | new Test("Persistent #2 Vibrate") { |
| 654 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 655 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 656 | .setSmallIcon(R.drawable.icon1) |
| 657 | .setWhen(mActivityCreateTime) |
| 658 | .setContentTitle(name) |
| 659 | .setContentText("This is a notification!!!") |
| 660 | .setContentIntent(makeIntent()) |
| 661 | .setDefaults(Notification.DEFAULT_VIBRATE) |
| 662 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | mNM.notify(2, n); |
| 664 | } |
| 665 | }, |
| 666 | |
Joe Onorato | d2b1f00 | 2010-06-04 10:42:41 -0700 | [diff] [blame] | 667 | new Test("Persistent #1 - different icon") { |
| 668 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 669 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 670 | .setSmallIcon(R.drawable.icon2) |
| 671 | .setWhen(mActivityCreateTime) |
| 672 | .setContentTitle(name) |
| 673 | .setContentText("This is a notification!!!") |
| 674 | .setContentIntent(makeIntent()) |
| 675 | .build(); |
Joe Onorato | d2b1f00 | 2010-06-04 10:42:41 -0700 | [diff] [blame] | 676 | mNM.notify(1, n); |
| 677 | } |
| 678 | }, |
| 679 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 680 | new Test("Chronometer Start") { |
| 681 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 682 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 683 | .setSmallIcon(R.drawable.icon1) |
| 684 | .setWhen(System.currentTimeMillis()) |
| 685 | .setContentTitle(name) |
| 686 | .setContentIntent(makeIntent()) |
| 687 | .setOngoing(true) |
| 688 | .setUsesChronometer(true) |
| 689 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | mNM.notify(2, n); |
| 691 | } |
| 692 | }, |
| 693 | |
| 694 | new Test("Chronometer Stop") { |
| 695 | public void run() { |
| 696 | mHandler.postDelayed(new Runnable() { |
| 697 | public void run() { |
| 698 | Log.d(TAG, "Chronometer Stop"); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 699 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 700 | .setSmallIcon(R.drawable.icon1) |
| 701 | .setWhen(System.currentTimeMillis()) |
| 702 | .setContentTitle(name) |
| 703 | .setContentIntent(makeIntent()) |
| 704 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | mNM.notify(2, n); |
| 706 | } |
| 707 | }, 3000); |
| 708 | } |
| 709 | }, |
| 710 | |
| 711 | new Test("Sequential Persistent") { |
| 712 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 713 | mNM.notify(1, notificationWithNumbers(name, 1)); |
| 714 | mNM.notify(2, notificationWithNumbers(name, 2)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 715 | } |
| 716 | }, |
| 717 | |
| 718 | new Test("Replace Persistent") { |
| 719 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 720 | mNM.notify(1, notificationWithNumbers(name, 1)); |
| 721 | mNM.notify(1, notificationWithNumbers(name, 1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | } |
| 723 | }, |
| 724 | |
| 725 | new Test("Run and Cancel (n=1)") { |
| 726 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 727 | mNM.notify(1, notificationWithNumbers(name, 1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | mNM.cancel(1); |
| 729 | } |
| 730 | }, |
| 731 | |
| 732 | new Test("Run an Cancel (n=2)") { |
| 733 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 734 | mNM.notify(1, notificationWithNumbers(name, 1)); |
| 735 | mNM.notify(2, notificationWithNumbers(name, 2)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | mNM.cancel(2); |
| 737 | } |
| 738 | }, |
| 739 | |
| 740 | // Repeatedly notify and cancel -- triggers bug #670627 |
| 741 | new Test("Bug 670627") { |
| 742 | public void run() { |
| 743 | for (int i = 0; i < 10; i++) { |
| 744 | Log.d(TAG, "Add two notifications"); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 745 | mNM.notify(1, notificationWithNumbers(name, 1)); |
| 746 | mNM.notify(2, notificationWithNumbers(name, 2)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 747 | Log.d(TAG, "Cancel two notifications"); |
| 748 | mNM.cancel(1); |
| 749 | mNM.cancel(2); |
| 750 | } |
| 751 | } |
| 752 | }, |
| 753 | |
| 754 | new Test("Ten Notifications") { |
| 755 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 756 | for (int i = 0; i < 10; i++) { |
| 757 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 758 | .setSmallIcon(kNumberedIconResIDs[i]) |
| 759 | .setContentTitle("Persistent #" + i) |
| 760 | .setContentText("Notify me!!!" + i) |
| 761 | .setOngoing(i < 2) |
| 762 | .setNumber(i) |
| 763 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 764 | mNM.notify((i+1)*10, n); |
| 765 | } |
| 766 | } |
| 767 | }, |
| 768 | |
| 769 | new Test("Cancel eight notifications") { |
| 770 | public void run() { |
| 771 | for (int i = 1; i < 9; i++) { |
| 772 | mNM.cancel((i+1)*10); |
| 773 | } |
| 774 | } |
| 775 | }, |
| 776 | |
Daniel Sandler | b0cc50d | 2010-10-26 16:55:56 -0400 | [diff] [blame] | 777 | new Test("Cancel the other two notifications") { |
| 778 | public void run() { |
| 779 | mNM.cancel(10); |
| 780 | mNM.cancel(100); |
| 781 | } |
| 782 | }, |
| 783 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | new Test("Persistent with numbers 1") { |
| 785 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 786 | mNM.notify(1, notificationWithNumbers(name, 1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | } |
| 788 | }, |
| 789 | |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 790 | new Test("Persistent with numbers 22") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 792 | mNM.notify(1, notificationWithNumbers(name, 22)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | } |
| 794 | }, |
| 795 | |
| 796 | new Test("Persistent with numbers 333") { |
| 797 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 798 | mNM.notify(1, notificationWithNumbers(name, 333)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | } |
| 800 | }, |
| 801 | |
| 802 | new Test("Persistent with numbers 4444") { |
| 803 | public void run() { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 804 | mNM.notify(1, notificationWithNumbers(name, 4444)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | } |
| 806 | }, |
| 807 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 808 | new Test("PRIORITY_HIGH") { |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 809 | public void run() { |
| 810 | Notification n = new Notification.Builder(NotificationTestList.this) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 811 | .setSmallIcon(R.drawable.notification5) |
| 812 | .setContentTitle("High priority") |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 813 | .setContentText("This should appear before all others") |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 814 | .setPriority(Notification.PRIORITY_HIGH) |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 815 | .build(); |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 816 | |
| 817 | int[] idOut = new int[1]; |
| 818 | try { |
| 819 | INotificationManager directLine = mNM.getService(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 820 | directLine.enqueueNotificationWithTag( |
| 821 | getPackageName(), |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 822 | getPackageName(), |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 823 | null, |
| 824 | 100, |
| 825 | n, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 826 | idOut, |
| 827 | UserHandle.myUserId()); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 828 | } catch (android.os.RemoteException ex) { |
| 829 | // oh well |
| 830 | } |
| 831 | } |
| 832 | }, |
| 833 | |
| 834 | new Test("PRIORITY_MAX") { |
| 835 | public void run() { |
| 836 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 837 | .setSmallIcon(R.drawable.notification9) |
| 838 | .setContentTitle("MAX priority") |
| 839 | .setContentText("This might appear as an intruder alert") |
| 840 | .setPriority(Notification.PRIORITY_MAX) |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 841 | .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 842 | |
| 843 | int[] idOut = new int[1]; |
| 844 | try { |
| 845 | INotificationManager directLine = mNM.getService(); |
| 846 | directLine.enqueueNotificationWithTag( |
| 847 | getPackageName(), |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 848 | getPackageName(), |
| 849 | null, |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 850 | 200, |
| 851 | n, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 852 | idOut, |
| 853 | UserHandle.myUserId()); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 854 | } catch (android.os.RemoteException ex) { |
| 855 | // oh well |
| 856 | } |
| 857 | } |
| 858 | }, |
| 859 | |
| 860 | new Test("PRIORITY_MIN") { |
| 861 | public void run() { |
| 862 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 863 | .setSmallIcon(R.drawable.notification0) |
| 864 | .setContentTitle("MIN priority") |
| 865 | .setContentText("You should not see this") |
| 866 | .setPriority(Notification.PRIORITY_MIN) |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 867 | .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 868 | |
| 869 | int[] idOut = new int[1]; |
| 870 | try { |
| 871 | INotificationManager directLine = mNM.getService(); |
| 872 | directLine.enqueueNotificationWithTag( |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 873 | getPackageName(), |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 874 | getPackageName(), |
| 875 | null, |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 876 | 1, |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 877 | n, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 878 | idOut, |
| 879 | UserHandle.myUserId()); |
Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 880 | } catch (android.os.RemoteException ex) { |
| 881 | // oh well |
| 882 | } |
| 883 | } |
| 884 | }, |
| 885 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 886 | new Test("Crash") { |
| 887 | public void run() |
| 888 | { |
| 889 | PowerManager.WakeLock wl |
Christian Mehlmauer | ef36752 | 2010-05-31 23:08:30 +0200 | [diff] [blame] | 890 | = ((PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE)) |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 891 | .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "crasher"); |
| 892 | wl.acquire(); |
| 893 | mHandler.postDelayed(new Runnable() { |
| 894 | public void run() { |
| 895 | throw new RuntimeException("Die!"); |
| 896 | } |
| 897 | }, 10000); |
| 898 | |
| 899 | } |
| 900 | }, |
| 901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | }; |
| 903 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 904 | private Notification notificationWithNumbers(String name, int num) { |
| 905 | Notification n = new Notification.Builder(NotificationTestList.this) |
| 906 | .setSmallIcon((num >= 0 && num < kNumberedIconResIDs.length) |
| 907 | ? kNumberedIconResIDs[num] |
| 908 | : kUnnumberedIconResID) |
| 909 | .setContentTitle(name) |
| 910 | .setContentText("Number=" + num) |
| 911 | .setNumber(num) |
| 912 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | return n; |
| 914 | } |
| 915 | |
| 916 | private PendingIntent makeIntent() { |
| 917 | Intent intent = new Intent(Intent.ACTION_MAIN); |
Joe Onorato | 0e26dff | 2010-05-24 16:17:02 -0400 | [diff] [blame] | 918 | intent.addCategory(Intent.CATEGORY_HOME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | return PendingIntent.getActivity(this, 0, intent, 0); |
| 920 | } |
| 921 | |
Joe Onorato | 184498c | 2010-10-08 17:57:18 -0400 | [diff] [blame] | 922 | private PendingIntent makeIntent2() { |
| 923 | Intent intent = new Intent(this, StatusBarTest.class); |
| 924 | return PendingIntent.getActivity(this, 0, intent, 0); |
| 925 | } |
| 926 | |
| 927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | class StateStress extends Test { |
| 929 | StateStress(String name, int pause, int iterations, Runnable[] tasks) { |
| 930 | super(name); |
| 931 | mPause = pause; |
| 932 | mTasks = tasks; |
| 933 | mIteration = iterations; |
| 934 | } |
| 935 | Runnable[] mTasks; |
| 936 | int mNext; |
| 937 | int mIteration; |
| 938 | long mPause; |
| 939 | Runnable mRunnable = new Runnable() { |
| 940 | public void run() { |
| 941 | mTasks[mNext].run(); |
| 942 | mNext++; |
| 943 | if (mNext >= mTasks.length) { |
| 944 | mNext = 0; |
| 945 | mIteration--; |
| 946 | if (mIteration <= 0) { |
| 947 | return; |
| 948 | } |
| 949 | } |
| 950 | mHandler.postDelayed(mRunnable, mPause); |
| 951 | } |
| 952 | }; |
| 953 | public void run() { |
| 954 | mNext = 0; |
| 955 | mHandler.postDelayed(mRunnable, mPause); |
| 956 | } |
| 957 | } |
Joe Onorato | c83bb73 | 2010-01-19 16:32:22 -0800 | [diff] [blame] | 958 | |
| 959 | void timeNotification(int n, String label, long time) { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 960 | mNM.notify(n, new Notification.Builder(NotificationTestList.this) |
| 961 | .setSmallIcon(R.drawable.ic_statusbar_missedcall) |
| 962 | .setWhen(time) |
| 963 | .setContentTitle(label) |
| 964 | .setContentText(new java.util.Date(time).toString()) |
| 965 | .build()); |
Joe Onorato | c83bb73 | 2010-01-19 16:32:22 -0800 | [diff] [blame] | 966 | |
| 967 | } |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 968 | |
| 969 | Bitmap loadBitmap(int resId) { |
| 970 | BitmapDrawable bd = (BitmapDrawable)getResources().getDrawable(resId); |
| 971 | return Bitmap.createBitmap(bd.getBitmap()); |
| 972 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | } |
| 974 | |