blob: 45992e3739f1759390163f8d61699dcf18d72216 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 android.app;
18
Andy Stadler110988c2010-12-03 14:29:16 -080019import com.android.internal.R;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020
Tor Norbyed9273d62013-05-30 15:59:53 -070021import android.annotation.IntDef;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040024import android.content.res.Resources;
Joe Onoratoef1e7762010-09-17 18:38:38 -040025import android.graphics.Bitmap;
Jeff Sharkey098d5802012-04-26 17:30:34 -070026import android.media.AudioManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.net.Uri;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040028import android.os.BadParcelableException;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050029import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Parcel;
31import android.os.Parcelable;
Daniel Sandlera2985ed2012-04-03 16:42:00 -040032import android.os.SystemClock;
Jeff Sharkey6d515712012-09-20 16:06:08 -070033import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.text.TextUtils;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040035import android.util.Log;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040036import android.util.TypedValue;
Joe Onorato8595a3d2010-11-19 18:12:07 -080037import android.view.View;
Jeff Sharkey1c400132011-08-05 14:50:13 -070038import android.widget.ProgressBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.widget.RemoteViews;
40
Tor Norbyed9273d62013-05-30 15:59:53 -070041import java.lang.annotation.Retention;
42import java.lang.annotation.RetentionPolicy;
Andy Stadler110988c2010-12-03 14:29:16 -080043import java.text.NumberFormat;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050044import java.util.ArrayList;
Joe Onorato561d3852010-11-20 18:09:34 -080045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046/**
47 * A class that represents how a persistent notification is to be presented to
48 * the user using the {@link android.app.NotificationManager}.
49 *
Joe Onoratocb109a02011-01-18 17:57:41 -080050 * <p>The {@link Notification.Builder Notification.Builder} has been added to make it
51 * easier to construct Notifications.</p>
52 *
Joe Fernandez558459f2011-10-13 16:47:36 -070053 * <div class="special reference">
54 * <h3>Developer Guides</h3>
55 * <p>For a guide to creating notifications, read the
56 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a>
57 * developer guide.</p>
58 * </div>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 */
60public class Notification implements Parcelable
61{
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040062 private static final String TAG = "Notification";
63
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 /**
65 * Use all default values (where applicable).
66 */
67 public static final int DEFAULT_ALL = ~0;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 /**
70 * Use the default notification sound. This will ignore any given
71 * {@link #sound}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050072 *
73
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050075 */
76
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 public static final int DEFAULT_SOUND = 1;
78
79 /**
80 * Use the default notification vibrate. This will ignore any given
Daniel Sandler2561b0b2012-02-13 21:04:12 -050081 * {@link #vibrate}. Using phone vibration requires the
Scott Mainb8b36452009-04-26 15:50:49 -070082 * {@link android.Manifest.permission#VIBRATE VIBRATE} permission.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050083 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050085 */
86
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 public static final int DEFAULT_VIBRATE = 2;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 /**
90 * Use the default notification lights. This will ignore the
91 * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or
92 * {@link #ledOnMS}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050093 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050095 */
96
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 public static final int DEFAULT_LIGHTS = 4;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500100 * A timestamp related to this notification, in milliseconds since the epoch.
Joe Malin8d40d042012-11-05 11:36:40 -0800101 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500102 * Default value: {@link System#currentTimeMillis() Now}.
103 *
104 * Choose a timestamp that will be most relevant to the user. For most finite events, this
105 * corresponds to the time the event happened (or will happen, in the case of events that have
106 * yet to occur but about which the user is being informed). Indefinite events should be
Joe Malin8d40d042012-11-05 11:36:40 -0800107 * timestamped according to when the activity began.
108 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500109 * Some examples:
Joe Malin8d40d042012-11-05 11:36:40 -0800110 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500111 * <ul>
112 * <li>Notification of a new chat message should be stamped when the message was received.</li>
113 * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li>
114 * <li>Notification of a completed file download should be stamped when the download finished.</li>
115 * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li>
116 * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
117 * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time.
Joe Malin8d40d042012-11-05 11:36:40 -0800118 * </ul>
119 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 */
121 public long when;
122
123 /**
124 * The resource id of a drawable to use as the icon in the status bar.
Daniel Sandlerd952dae2011-02-07 16:33:36 -0500125 * This is required; notifications with an invalid icon resource will not be shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 */
127 public int icon;
128
129 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800130 * If the icon in the status bar is to have more than one level, you can set this. Otherwise,
131 * leave it at its default value of 0.
132 *
133 * @see android.widget.ImageView#setImageLevel
134 * @see android.graphics.drawable#setLevel
135 */
136 public int iconLevel;
137
138 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500139 * The number of events that this notification represents. For example, in a new mail
140 * notification, this could be the number of unread messages.
Joe Malin8d40d042012-11-05 11:36:40 -0800141 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500142 * The system may or may not use this field to modify the appearance of the notification. For
143 * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was
144 * superimposed over the icon in the status bar. Starting with
145 * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by
146 * {@link Notification.Builder} has displayed the number in the expanded notification view.
Joe Malin8d40d042012-11-05 11:36:40 -0800147 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500148 * If the number is 0 or negative, it is never shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 */
150 public int number;
151
152 /**
153 * The intent to execute when the expanded status entry is clicked. If
154 * this is an activity, it must include the
155 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -0800156 * that you take care of task management as described in the
157 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
Dianne Hackborn6ceca582012-01-10 15:24:26 -0800158 * Stack</a> document. In particular, make sure to read the notification section
159 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling
160 * Notifications</a> for the correct ways to launch an application from a
161 * notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 */
163 public PendingIntent contentIntent;
164
165 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500166 * The intent to execute when the notification is explicitly dismissed by the user, either with
167 * the "Clear All" button or by swiping it away individually.
168 *
169 * This probably shouldn't be launching an activity since several of those will be sent
170 * at the same time.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 */
172 public PendingIntent deleteIntent;
173
174 /**
Dianne Hackborn170bae72010-09-03 15:14:28 -0700175 * An intent to launch instead of posting the notification to the status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -0800176 *
177 * @see Notification.Builder#setFullScreenIntent
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400178 */
179 public PendingIntent fullScreenIntent;
180
181 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 * Text to scroll across the screen when this item is added to
Joe Onoratoef1e7762010-09-17 18:38:38 -0400183 * the status bar on large and smaller devices.
184 *
Joe Onorato46439ce2010-11-19 13:56:21 -0800185 * @see #tickerView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 */
187 public CharSequence tickerText;
188
189 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800190 * The view to show as the ticker in the status bar when the notification
191 * is posted.
Joe Onoratoef1e7762010-09-17 18:38:38 -0400192 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800193 public RemoteViews tickerView;
Joe Onoratoef1e7762010-09-17 18:38:38 -0400194
195 /**
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400196 * The view that will represent this notification in the expanded status bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 */
198 public RemoteViews contentView;
199
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400200 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -0400201 * A large-format version of {@link #contentView}, giving the Notification an
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400202 * opportunity to show more detail. The system UI may choose to show this
203 * instead of the normal content view at its discretion.
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400204 */
205 public RemoteViews bigContentView;
206
207 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800208 * The bitmap that may escape the bounds of the panel and bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800210 public Bitmap largeIcon;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211
212 /**
213 * The sound to play.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500214 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 * <p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500216 * To play the default notification sound, see {@link #defaults}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 * </p>
218 */
219 public Uri sound;
220
221 /**
222 * Use this constant as the value for audioStreamType to request that
223 * the default stream type for notifications be used. Currently the
Jeff Sharkey098d5802012-04-26 17:30:34 -0700224 * default stream type is {@link AudioManager#STREAM_NOTIFICATION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 */
226 public static final int STREAM_DEFAULT = -1;
227
228 /**
229 * The audio stream type to use when playing the sound.
230 * Should be one of the STREAM_ constants from
231 * {@link android.media.AudioManager}.
232 */
233 public int audioStreamType = STREAM_DEFAULT;
234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500236 * The pattern with which to vibrate.
237 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 * <p>
239 * To vibrate the default pattern, see {@link #defaults}.
240 * </p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500241 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 * @see android.os.Vibrator#vibrate(long[],int)
243 */
244 public long[] vibrate;
245
246 /**
247 * The color of the led. The hardware will do its best approximation.
248 *
249 * @see #FLAG_SHOW_LIGHTS
250 * @see #flags
251 */
252 public int ledARGB;
253
254 /**
255 * The number of milliseconds for the LED to be on while it's flashing.
256 * The hardware will do its best approximation.
257 *
258 * @see #FLAG_SHOW_LIGHTS
259 * @see #flags
260 */
261 public int ledOnMS;
262
263 /**
264 * The number of milliseconds for the LED to be off while it's flashing.
265 * The hardware will do its best approximation.
266 *
267 * @see #FLAG_SHOW_LIGHTS
268 * @see #flags
269 */
270 public int ledOffMS;
271
272 /**
273 * Specifies which values should be taken from the defaults.
274 * <p>
275 * To set, OR the desired from {@link #DEFAULT_SOUND},
276 * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default
277 * values, use {@link #DEFAULT_ALL}.
278 * </p>
279 */
280 public int defaults;
281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 /**
283 * Bit to be bitwise-ored into the {@link #flags} field that should be
284 * set if you want the LED on for this notification.
285 * <ul>
286 * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB
287 * or 0 for both ledOnMS and ledOffMS.</li>
288 * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li>
289 * <li>To flash the LED, pass the number of milliseconds that it should
290 * be on and off to ledOnMS and ledOffMS.</li>
291 * </ul>
292 * <p>
293 * Since hardware varies, you are not guaranteed that any of the values
294 * you pass are honored exactly. Use the system defaults (TODO) if possible
295 * because they will be set to values that work on any given hardware.
296 * <p>
297 * The alpha channel must be set for forward compatibility.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500298 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 */
300 public static final int FLAG_SHOW_LIGHTS = 0x00000001;
301
302 /**
303 * Bit to be bitwise-ored into the {@link #flags} field that should be
304 * set if this notification is in reference to something that is ongoing,
305 * like a phone call. It should not be set if this notification is in
306 * reference to something that happened at a particular point in time,
307 * like a missed phone call.
308 */
309 public static final int FLAG_ONGOING_EVENT = 0x00000002;
310
311 /**
312 * Bit to be bitwise-ored into the {@link #flags} field that if set,
Scott Mainb8b36452009-04-26 15:50:49 -0700313 * the audio will be repeated until the notification is
314 * cancelled or the notification window is opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 */
316 public static final int FLAG_INSISTENT = 0x00000004;
317
318 /**
319 * Bit to be bitwise-ored into the {@link #flags} field that should be
320 * set if you want the sound and/or vibration play each time the
321 * notification is sent, even if it has not been canceled before that.
322 */
323 public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008;
324
325 /**
326 * Bit to be bitwise-ored into the {@link #flags} field that should be
327 * set if the notification should be canceled when it is clicked by the
Daniel Sandler8aa9ae62012-12-04 23:31:47 -0500328 * user.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 */
331 public static final int FLAG_AUTO_CANCEL = 0x00000010;
332
333 /**
334 * Bit to be bitwise-ored into the {@link #flags} field that should be
335 * set if the notification should not be canceled when the user clicks
336 * the Clear all button.
337 */
338 public static final int FLAG_NO_CLEAR = 0x00000020;
339
Dianne Hackbornd8a43f62009-08-17 23:33:56 -0700340 /**
341 * Bit to be bitwise-ored into the {@link #flags} field that should be
342 * set if this notification represents a currently running service. This
343 * will normally be set for you by {@link Service#startForeground}.
344 */
345 public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;
346
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400347 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500348 * Obsolete flag indicating high-priority notifications; use the priority field instead.
Joe Malin8d40d042012-11-05 11:36:40 -0800349 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500350 * @deprecated Use {@link #priority} with a positive value.
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400351 */
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500352 public static final int FLAG_HIGH_PRIORITY = 0x00000080;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 public int flags;
355
Tor Norbyed9273d62013-05-30 15:59:53 -0700356 /** @hide */
357 @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX})
358 @Retention(RetentionPolicy.SOURCE)
359 public @interface Priority {}
360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500362 * Default notification {@link #priority}. If your application does not prioritize its own
363 * notifications, use this value for all notifications.
364 */
365 public static final int PRIORITY_DEFAULT = 0;
366
367 /**
368 * Lower {@link #priority}, for items that are less important. The UI may choose to show these
369 * items smaller, or at a different position in the list, compared with your app's
370 * {@link #PRIORITY_DEFAULT} items.
371 */
372 public static final int PRIORITY_LOW = -1;
373
374 /**
375 * Lowest {@link #priority}; these items might not be shown to the user except under special
376 * circumstances, such as detailed notification logs.
377 */
378 public static final int PRIORITY_MIN = -2;
379
380 /**
381 * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to
382 * show these items larger, or at a different position in notification lists, compared with
383 * your app's {@link #PRIORITY_DEFAULT} items.
384 */
385 public static final int PRIORITY_HIGH = 1;
386
387 /**
388 * Highest {@link #priority}, for your application's most important items that require the
389 * user's prompt attention or input.
390 */
391 public static final int PRIORITY_MAX = 2;
392
393 /**
394 * Relative priority for this notification.
Joe Malin8d40d042012-11-05 11:36:40 -0800395 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500396 * Priority is an indication of how much of the user's valuable attention should be consumed by
397 * this notification. Low-priority notifications may be hidden from the user in certain
398 * situations, while the user might be interrupted for a higher-priority notification. The
Daniel Sandler6738eee2012-11-16 12:03:32 -0500399 * system will make a determination about how to interpret this priority when presenting
400 * the notification.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500401 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700402 @Priority
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500403 public int priority;
Joe Malin8d40d042012-11-05 11:36:40 -0800404
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500405 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400406 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500407 * Notification type: incoming call (voice or video) or similar synchronous communication request.
408 */
409 public static final String KIND_CALL = "android.call";
410
411 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400412 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500413 * Notification type: incoming direct message (SMS, instant message, etc.).
414 */
415 public static final String KIND_MESSAGE = "android.message";
416
417 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400418 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500419 * Notification type: asynchronous bulk message (email).
420 */
421 public static final String KIND_EMAIL = "android.email";
422
423 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400424 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500425 * Notification type: calendar event.
426 */
427 public static final String KIND_EVENT = "android.event";
428
429 /**
Daniel Sandlera90513d2012-06-04 02:11:17 -0400430 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500431 * Notification type: promotion or advertisement.
432 */
433 public static final String KIND_PROMO = "android.promo";
434
435 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400436 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500437 * If this notification matches of one or more special types (see the <code>KIND_*</code>
438 * constants), add them here, best match first.
439 */
440 public String[] kind;
441
442 /**
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400443 * Additional semantic data to be carried around with this Notification.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500444 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400445 public Bundle extras = new Bundle();
446
447 // extras keys for Builder inputs
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500448 public static final String EXTRA_TITLE = "android.title";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400449 public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big";
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500450 public static final String EXTRA_TEXT = "android.text";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400451 public static final String EXTRA_SUB_TEXT = "android.subText";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400452 public static final String EXTRA_INFO_TEXT = "android.infoText";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400453 public static final String EXTRA_SUMMARY_TEXT = "android.summaryText";
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500454 public static final String EXTRA_SMALL_ICON = "android.icon";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400455 public static final String EXTRA_LARGE_ICON = "android.largeIcon";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400456 public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400457 public static final String EXTRA_PROGRESS = "android.progress";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400458 public static final String EXTRA_PROGRESS_MAX = "android.progressMax";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400459 public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400460 public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400461 public static final String EXTRA_SHOW_WHEN = "android.showWhen";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400462 public static final String EXTRA_PICTURE = "android.picture";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400463 public static final String EXTRA_TEXT_LINES = "android.textLines";
464
465 // extras keys for other interesting pieces of information
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400466 public static final String EXTRA_PEOPLE = "android.people";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500467
468 /**
Scott Greenwald9a05b312013-06-28 00:37:54 -0400469 * @hide
470 * Extra added by NotificationManagerService to indicate whether a NotificationScorer
471 * modified the Notifications's score.
472 */
473 public static final String EXTRA_SCORE_MODIFIED = "android.scoreModified";
474
475 /**
Chris Wren51c75102013-07-16 20:49:17 -0400476 * Notification extra to specify heads up display preference.
477 * @hide
478 */
479 public static final String EXTRA_AS_HEADS_UP = "headsup";
480
481 /**
482 * Value for {@link #EXTRA_AS_HEADS_UP} indicating that heads up display is not appropriate.
483 * @hide
484 */
485 public static final int HEADS_UP_NEVER = 0;
486
487 /**
488 * Default value for {@link #EXTRA_AS_HEADS_UP} indicating that heads up display is appropriate.
489 * @hide
490 */
491 public static final int HEADS_UP_ALLOWED = 1;
492
493 /**
494 * Value for {@link #EXTRA_AS_HEADS_UP} that advocates for heads up display.
495 * @hide
496 */
497 public static final int HEADS_UP_REQUESTED = 2;
498
499 /**
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400500 * Structure to encapsulate an "action", including title and icon, that can be attached to a Notification.
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400501 */
Daniel Sandlerea2a3172013-02-20 22:24:20 -0500502 public static class Action implements Parcelable {
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400503 public int icon;
504 public CharSequence title;
505 public PendingIntent actionIntent;
506 @SuppressWarnings("unused")
507 public Action() { }
508 private Action(Parcel in) {
509 icon = in.readInt();
510 title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
511 if (in.readInt() == 1) {
512 actionIntent = PendingIntent.CREATOR.createFromParcel(in);
513 }
514 }
515 public Action(int icon_, CharSequence title_, PendingIntent intent_) {
516 this.icon = icon_;
517 this.title = title_;
518 this.actionIntent = intent_;
519 }
520 @Override
521 public Action clone() {
522 return new Action(
523 this.icon,
524 this.title.toString(),
525 this.actionIntent // safe to alias
526 );
527 }
528 @Override
529 public int describeContents() {
530 return 0;
531 }
532 @Override
533 public void writeToParcel(Parcel out, int flags) {
534 out.writeInt(icon);
535 TextUtils.writeToParcel(title, out, flags);
536 if (actionIntent != null) {
537 out.writeInt(1);
538 actionIntent.writeToParcel(out, flags);
539 } else {
540 out.writeInt(0);
541 }
542 }
543 public static final Parcelable.Creator<Action> CREATOR
544 = new Parcelable.Creator<Action>() {
545 public Action createFromParcel(Parcel in) {
546 return new Action(in);
547 }
548 public Action[] newArray(int size) {
549 return new Action[size];
550 }
551 };
552 }
553
Daniel Sandlerea2a3172013-02-20 22:24:20 -0500554 public Action[] actions;
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400555
556 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500557 * Constructs a Notification object with default values.
Joe Onorato46439ce2010-11-19 13:56:21 -0800558 * You might want to consider using {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 */
560 public Notification()
561 {
562 this.when = System.currentTimeMillis();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500563 this.priority = PRIORITY_DEFAULT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 }
565
566 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 * @hide
568 */
569 public Notification(Context context, int icon, CharSequence tickerText, long when,
570 CharSequence contentTitle, CharSequence contentText, Intent contentIntent)
571 {
572 this.when = when;
573 this.icon = icon;
574 this.tickerText = tickerText;
575 setLatestEventInfo(context, contentTitle, contentText,
576 PendingIntent.getActivity(context, 0, contentIntent, 0));
577 }
578
579 /**
580 * Constructs a Notification object with the information needed to
581 * have a status bar icon without the standard expanded view.
582 *
583 * @param icon The resource id of the icon to put in the status bar.
584 * @param tickerText The text that flows by in the status bar when the notification first
585 * activates.
586 * @param when The time to show in the time field. In the System.currentTimeMillis
587 * timebase.
Joe Onorato46439ce2010-11-19 13:56:21 -0800588 *
589 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800591 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 public Notification(int icon, CharSequence tickerText, long when)
593 {
594 this.icon = icon;
595 this.tickerText = tickerText;
596 this.when = when;
597 }
598
599 /**
600 * Unflatten the notification from a parcel.
601 */
602 public Notification(Parcel parcel)
603 {
604 int version = parcel.readInt();
605
606 when = parcel.readLong();
607 icon = parcel.readInt();
608 number = parcel.readInt();
609 if (parcel.readInt() != 0) {
610 contentIntent = PendingIntent.CREATOR.createFromParcel(parcel);
611 }
612 if (parcel.readInt() != 0) {
613 deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel);
614 }
615 if (parcel.readInt() != 0) {
616 tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
617 }
618 if (parcel.readInt() != 0) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800619 tickerView = RemoteViews.CREATOR.createFromParcel(parcel);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400620 }
621 if (parcel.readInt() != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 contentView = RemoteViews.CREATOR.createFromParcel(parcel);
623 }
Joe Onorato561d3852010-11-20 18:09:34 -0800624 if (parcel.readInt() != 0) {
625 largeIcon = Bitmap.CREATOR.createFromParcel(parcel);
626 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 defaults = parcel.readInt();
628 flags = parcel.readInt();
629 if (parcel.readInt() != 0) {
630 sound = Uri.CREATOR.createFromParcel(parcel);
631 }
632
633 audioStreamType = parcel.readInt();
634 vibrate = parcel.createLongArray();
635 ledARGB = parcel.readInt();
636 ledOnMS = parcel.readInt();
637 ledOffMS = parcel.readInt();
638 iconLevel = parcel.readInt();
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400639
640 if (parcel.readInt() != 0) {
641 fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel);
642 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500643
644 priority = parcel.readInt();
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400645
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500646 kind = parcel.createStringArray(); // may set kind to null
647
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500648 extras = parcel.readBundle(); // may be null
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400649
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500650 actions = parcel.createTypedArray(Action.CREATOR); // may be null
651
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400652 if (parcel.readInt() != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400653 bigContentView = RemoteViews.CREATOR.createFromParcel(parcel);
654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 }
656
Andy Stadler110988c2010-12-03 14:29:16 -0800657 @Override
Joe Onorato18e69df2010-05-17 22:26:12 -0700658 public Notification clone() {
659 Notification that = new Notification();
Daniel Sandler1a497d32013-04-18 14:52:45 -0400660 cloneInto(that, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500661 return that;
662 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700663
Daniel Sandler1a497d32013-04-18 14:52:45 -0400664 /**
665 * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members
666 * of this into that.
667 * @hide
668 */
669 public void cloneInto(Notification that, boolean heavy) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700670 that.when = this.when;
671 that.icon = this.icon;
672 that.number = this.number;
673
674 // PendingIntents are global, so there's no reason (or way) to clone them.
675 that.contentIntent = this.contentIntent;
676 that.deleteIntent = this.deleteIntent;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400677 that.fullScreenIntent = this.fullScreenIntent;
Joe Onorato18e69df2010-05-17 22:26:12 -0700678
679 if (this.tickerText != null) {
680 that.tickerText = this.tickerText.toString();
681 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400682 if (heavy && this.tickerView != null) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800683 that.tickerView = this.tickerView.clone();
Joe Onoratoef1e7762010-09-17 18:38:38 -0400684 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400685 if (heavy && this.contentView != null) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700686 that.contentView = this.contentView.clone();
687 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400688 if (heavy && this.largeIcon != null) {
Joe Onorato561d3852010-11-20 18:09:34 -0800689 that.largeIcon = Bitmap.createBitmap(this.largeIcon);
690 }
Jozef BABJAKa8b91832011-02-22 08:05:08 +0100691 that.iconLevel = this.iconLevel;
Joe Onorato18e69df2010-05-17 22:26:12 -0700692 that.sound = this.sound; // android.net.Uri is immutable
693 that.audioStreamType = this.audioStreamType;
694
695 final long[] vibrate = this.vibrate;
696 if (vibrate != null) {
697 final int N = vibrate.length;
698 final long[] vib = that.vibrate = new long[N];
699 System.arraycopy(vibrate, 0, vib, 0, N);
700 }
701
702 that.ledARGB = this.ledARGB;
703 that.ledOnMS = this.ledOnMS;
704 that.ledOffMS = this.ledOffMS;
705 that.defaults = this.defaults;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500706
Joe Onorato18e69df2010-05-17 22:26:12 -0700707 that.flags = this.flags;
708
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500709 that.priority = this.priority;
Joe Malin8d40d042012-11-05 11:36:40 -0800710
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500711 final String[] thiskind = this.kind;
712 if (thiskind != null) {
713 final int N = thiskind.length;
714 final String[] thatkind = that.kind = new String[N];
715 System.arraycopy(thiskind, 0, thatkind, 0, N);
716 }
717
718 if (this.extras != null) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -0400719 try {
720 that.extras = new Bundle(this.extras);
721 // will unparcel
722 that.extras.size();
723 } catch (BadParcelableException e) {
724 Log.e(TAG, "could not unparcel extras from notification: " + this, e);
725 that.extras = null;
726 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500727 }
728
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500729 if (this.actions != null) {
730 that.actions = new Action[this.actions.length];
731 for(int i=0; i<this.actions.length; i++) {
732 that.actions[i] = this.actions[i].clone();
733 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400734 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500735
Daniel Sandler1a497d32013-04-18 14:52:45 -0400736 if (heavy && this.bigContentView != null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400737 that.bigContentView = this.bigContentView.clone();
738 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400739
740 if (!heavy) {
741 that.lightenPayload(); // will clean out extras
742 }
743 }
744
745 /**
746 * Removes heavyweight parts of the Notification object for archival or for sending to
747 * listeners when the full contents are not necessary.
748 * @hide
749 */
750 public final void lightenPayload() {
751 tickerView = null;
752 contentView = null;
753 bigContentView = null;
754 largeIcon = null;
755 if (extras != null) {
756 extras.remove(Notification.EXTRA_LARGE_ICON);
757 extras.remove(Notification.EXTRA_LARGE_ICON_BIG);
758 extras.remove(Notification.EXTRA_PICTURE);
759 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700760 }
761
Daniel Sandlerdcbaf662013-04-26 16:23:09 -0400762 /**
763 * Make sure this CharSequence is safe to put into a bundle, which basically
764 * means it had better not be some custom Parcelable implementation.
765 * @hide
766 */
767 public static CharSequence safeCharSequence(CharSequence cs) {
768 if (cs instanceof Parcelable) {
769 Log.e(TAG, "warning: " + cs.getClass().getCanonicalName()
770 + " instance is a custom Parcelable and not allowed in Notification");
771 return cs.toString();
772 }
773
774 return cs;
775 }
776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 public int describeContents() {
778 return 0;
779 }
780
781 /**
782 * Flatten this notification from a parcel.
783 */
784 public void writeToParcel(Parcel parcel, int flags)
785 {
786 parcel.writeInt(1);
787
788 parcel.writeLong(when);
789 parcel.writeInt(icon);
790 parcel.writeInt(number);
791 if (contentIntent != null) {
792 parcel.writeInt(1);
793 contentIntent.writeToParcel(parcel, 0);
794 } else {
795 parcel.writeInt(0);
796 }
797 if (deleteIntent != null) {
798 parcel.writeInt(1);
799 deleteIntent.writeToParcel(parcel, 0);
800 } else {
801 parcel.writeInt(0);
802 }
803 if (tickerText != null) {
804 parcel.writeInt(1);
805 TextUtils.writeToParcel(tickerText, parcel, flags);
806 } else {
807 parcel.writeInt(0);
808 }
Joe Onorato46439ce2010-11-19 13:56:21 -0800809 if (tickerView != null) {
Joe Onoratoef1e7762010-09-17 18:38:38 -0400810 parcel.writeInt(1);
Joe Onorato46439ce2010-11-19 13:56:21 -0800811 tickerView.writeToParcel(parcel, 0);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400812 } else {
813 parcel.writeInt(0);
814 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 if (contentView != null) {
816 parcel.writeInt(1);
817 contentView.writeToParcel(parcel, 0);
818 } else {
819 parcel.writeInt(0);
820 }
Joe Onorato561d3852010-11-20 18:09:34 -0800821 if (largeIcon != null) {
822 parcel.writeInt(1);
823 largeIcon.writeToParcel(parcel, 0);
824 } else {
825 parcel.writeInt(0);
826 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827
828 parcel.writeInt(defaults);
829 parcel.writeInt(this.flags);
830
831 if (sound != null) {
832 parcel.writeInt(1);
833 sound.writeToParcel(parcel, 0);
834 } else {
835 parcel.writeInt(0);
836 }
837 parcel.writeInt(audioStreamType);
838 parcel.writeLongArray(vibrate);
839 parcel.writeInt(ledARGB);
840 parcel.writeInt(ledOnMS);
841 parcel.writeInt(ledOffMS);
842 parcel.writeInt(iconLevel);
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400843
844 if (fullScreenIntent != null) {
845 parcel.writeInt(1);
846 fullScreenIntent.writeToParcel(parcel, 0);
847 } else {
848 parcel.writeInt(0);
849 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500850
851 parcel.writeInt(priority);
Joe Malin8d40d042012-11-05 11:36:40 -0800852
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500853 parcel.writeStringArray(kind); // ok for null
Joe Malin8d40d042012-11-05 11:36:40 -0800854
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500855 parcel.writeBundle(extras); // null ok
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400856
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500857 parcel.writeTypedArray(actions, 0); // null ok
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400858
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400859 if (bigContentView != null) {
860 parcel.writeInt(1);
861 bigContentView.writeToParcel(parcel, 0);
862 } else {
863 parcel.writeInt(0);
864 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 }
866
867 /**
868 * Parcelable.Creator that instantiates Notification objects
869 */
870 public static final Parcelable.Creator<Notification> CREATOR
871 = new Parcelable.Creator<Notification>()
872 {
873 public Notification createFromParcel(Parcel parcel)
874 {
875 return new Notification(parcel);
876 }
877
878 public Notification[] newArray(int size)
879 {
880 return new Notification[size];
881 }
882 };
883
884 /**
885 * Sets the {@link #contentView} field to be a view with the standard "Latest Event"
886 * layout.
887 *
888 * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields
889 * in the view.</p>
890 * @param context The context for your application / activity.
891 * @param contentTitle The title that goes in the expanded entry.
892 * @param contentText The text that goes in the expanded entry.
893 * @param contentIntent The intent to launch when the user clicks the expanded notification.
894 * If this is an activity, it must include the
895 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -0800896 * that you take care of task management as described in the
897 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
898 * Stack</a> document.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500899 *
Joe Onorato46439ce2010-11-19 13:56:21 -0800900 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800902 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 public void setLatestEventInfo(Context context,
904 CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500905 Notification.Builder builder = new Notification.Builder(context);
906
907 // First, ensure that key pieces of information that may have been set directly
908 // are preserved
909 builder.setWhen(this.when);
910 builder.setSmallIcon(this.icon);
911 builder.setPriority(this.priority);
912 builder.setTicker(this.tickerText);
913 builder.setNumber(this.number);
914 builder.mFlags = this.flags;
915 builder.setSound(this.sound, this.audioStreamType);
916 builder.setDefaults(this.defaults);
917 builder.setVibrate(this.vibrate);
918
919 // now apply the latestEventInfo fields
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 if (contentTitle != null) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500921 builder.setContentTitle(contentTitle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 }
923 if (contentText != null) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500924 builder.setContentText(contentText);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500926 builder.setContentIntent(contentIntent);
927 builder.buildInto(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 }
929
930 @Override
931 public String toString() {
932 StringBuilder sb = new StringBuilder();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500933 sb.append("Notification(pri=");
934 sb.append(priority);
935 sb.append(" contentView=");
Joe Onoratoc9596d62011-01-12 17:03:11 -0800936 if (contentView != null) {
937 sb.append(contentView.getPackage());
938 sb.append("/0x");
939 sb.append(Integer.toHexString(contentView.getLayoutId()));
940 } else {
941 sb.append("null");
942 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500943 // TODO(dsandler): defaults take precedence over local values, so reorder the branches below
Joe Onoratoc9596d62011-01-12 17:03:11 -0800944 sb.append(" vibrate=");
Daniel Sandler6738eee2012-11-16 12:03:32 -0500945 if ((this.defaults & DEFAULT_VIBRATE) != 0) {
946 sb.append("default");
947 } else if (this.vibrate != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 int N = this.vibrate.length-1;
949 sb.append("[");
950 for (int i=0; i<N; i++) {
951 sb.append(this.vibrate[i]);
952 sb.append(',');
953 }
Simon Schoar8cf97d92009-06-10 22:08:37 +0200954 if (N != -1) {
955 sb.append(this.vibrate[N]);
956 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 sb.append("]");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 } else {
959 sb.append("null");
960 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500961 sb.append(" sound=");
Daniel Sandler6738eee2012-11-16 12:03:32 -0500962 if ((this.defaults & DEFAULT_SOUND) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 sb.append("default");
Daniel Sandler6738eee2012-11-16 12:03:32 -0500964 } else if (this.sound != null) {
965 sb.append(this.sound.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 } else {
967 sb.append("null");
968 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500969 sb.append(" defaults=0x");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 sb.append(Integer.toHexString(this.defaults));
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500971 sb.append(" flags=0x");
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400972 sb.append(Integer.toHexString(this.flags));
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500973 sb.append(" kind=[");
974 if (this.kind == null) {
975 sb.append("null");
976 } else {
977 for (int i=0; i<this.kind.length; i++) {
978 if (i>0) sb.append(",");
979 sb.append(this.kind[i]);
980 }
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400981 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400982 sb.append("]");
983 if (actions != null) {
984 sb.append(" ");
985 sb.append(actions.length);
986 sb.append(" action");
987 if (actions.length > 1) sb.append("s");
988 }
989 sb.append(")");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 return sb.toString();
991 }
Joe Onorato46439ce2010-11-19 13:56:21 -0800992
Jeff Sharkey6d515712012-09-20 16:06:08 -0700993 /** {@hide} */
994 public void setUser(UserHandle user) {
Amith Yamasaniecbd68b2012-11-02 12:17:19 -0700995 if (user.getIdentifier() == UserHandle.USER_ALL) {
996 user = UserHandle.OWNER;
997 }
Jeff Sharkey6d515712012-09-20 16:06:08 -0700998 if (tickerView != null) {
999 tickerView.setUser(user);
1000 }
1001 if (contentView != null) {
1002 contentView.setUser(user);
1003 }
1004 if (bigContentView != null) {
1005 bigContentView.setUser(user);
1006 }
1007 }
1008
Joe Onoratocb109a02011-01-18 17:57:41 -08001009 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001010 * Builder class for {@link Notification} objects.
Joe Malin8d40d042012-11-05 11:36:40 -08001011 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001012 * Provides a convenient way to set the various fields of a {@link Notification} and generate
Scott Main183bf112012-08-13 19:12:13 -07001013 * content views using the platform's notification layout template. If your app supports
1014 * versions of Android as old as API level 4, you can instead use
1015 * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder},
1016 * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support
1017 * library</a>.
Joe Malin8d40d042012-11-05 11:36:40 -08001018 *
Scott Main183bf112012-08-13 19:12:13 -07001019 * <p>Example:
Joe Malin8d40d042012-11-05 11:36:40 -08001020 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001021 * <pre class="prettyprint">
Scott Main183bf112012-08-13 19:12:13 -07001022 * Notification noti = new Notification.Builder(mContext)
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001023 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
1024 * .setContentText(subject)
1025 * .setSmallIcon(R.drawable.new_mail)
1026 * .setLargeIcon(aBitmap)
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001027 * .build();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001028 * </pre>
Joe Onoratocb109a02011-01-18 17:57:41 -08001029 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001030 public static class Builder {
Daniel Sandler602ad1c2012-06-12 16:06:27 -04001031 private static final int MAX_ACTION_BUTTONS = 3;
Daniel Sandler8680bf82012-05-15 16:52:52 -04001032
Joe Onorato46439ce2010-11-19 13:56:21 -08001033 private Context mContext;
1034
1035 private long mWhen;
1036 private int mSmallIcon;
1037 private int mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08001038 private int mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08001039 private CharSequence mContentTitle;
1040 private CharSequence mContentText;
1041 private CharSequence mContentInfo;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001042 private CharSequence mSubText;
Joe Onorato46439ce2010-11-19 13:56:21 -08001043 private PendingIntent mContentIntent;
1044 private RemoteViews mContentView;
1045 private PendingIntent mDeleteIntent;
1046 private PendingIntent mFullScreenIntent;
1047 private CharSequence mTickerText;
1048 private RemoteViews mTickerView;
1049 private Bitmap mLargeIcon;
1050 private Uri mSound;
1051 private int mAudioStreamType;
1052 private long[] mVibrate;
1053 private int mLedArgb;
1054 private int mLedOnMs;
1055 private int mLedOffMs;
1056 private int mDefaults;
1057 private int mFlags;
Jeff Sharkey1c400132011-08-05 14:50:13 -07001058 private int mProgressMax;
1059 private int mProgress;
1060 private boolean mProgressIndeterminate;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001061 private ArrayList<String> mKindList = new ArrayList<String>(1);
1062 private Bundle mExtras;
1063 private int mPriority;
Daniel Sandler8680bf82012-05-15 16:52:52 -04001064 private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS);
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001065 private boolean mUseChronometer;
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001066 private Style mStyle;
Daniel Sandler0c890492012-09-12 17:23:10 -07001067 private boolean mShowWhen = true;
Joe Onorato46439ce2010-11-19 13:56:21 -08001068
Joe Onoratocb109a02011-01-18 17:57:41 -08001069 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001070 * Constructs a new Builder with the defaults:
Joe Onoratocb109a02011-01-18 17:57:41 -08001071 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001072
1073 * <table>
1074 * <tr><th align=right>priority</th>
1075 * <td>{@link #PRIORITY_DEFAULT}</td></tr>
1076 * <tr><th align=right>when</th>
1077 * <td>now ({@link System#currentTimeMillis()})</td></tr>
1078 * <tr><th align=right>audio stream</th>
1079 * <td>{@link #STREAM_DEFAULT}</td></tr>
1080 * </table>
Joe Onoratocb109a02011-01-18 17:57:41 -08001081 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001082
1083 * @param context
1084 * A {@link Context} that will be used by the Builder to construct the
1085 * RemoteViews. The Context will not be held past the lifetime of this Builder
1086 * object.
Joe Onoratocb109a02011-01-18 17:57:41 -08001087 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001088 public Builder(Context context) {
1089 mContext = context;
Andy Stadler110988c2010-12-03 14:29:16 -08001090
1091 // Set defaults to match the defaults of a Notification
Joe Onorato46439ce2010-11-19 13:56:21 -08001092 mWhen = System.currentTimeMillis();
Andy Stadler110988c2010-12-03 14:29:16 -08001093 mAudioStreamType = STREAM_DEFAULT;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001094 mPriority = PRIORITY_DEFAULT;
Joe Onorato46439ce2010-11-19 13:56:21 -08001095 }
1096
Joe Onoratocb109a02011-01-18 17:57:41 -08001097 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001098 * Add a timestamp pertaining to the notification (usually the time the event occurred).
Daniel Sandler0c890492012-09-12 17:23:10 -07001099 * It will be shown in the notification content view by default; use
1100 * {@link Builder#setShowWhen(boolean) setShowWhen} to control this.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001101 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001102 * @see Notification#when
Joe Onoratocb109a02011-01-18 17:57:41 -08001103 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001104 public Builder setWhen(long when) {
1105 mWhen = when;
1106 return this;
1107 }
1108
Joe Onoratocb109a02011-01-18 17:57:41 -08001109 /**
Daniel Sandler0c890492012-09-12 17:23:10 -07001110 * Control whether the timestamp set with {@link Builder#setWhen(long) setWhen} is shown
1111 * in the content view.
1112 */
1113 public Builder setShowWhen(boolean show) {
1114 mShowWhen = show;
1115 return this;
1116 }
1117
1118 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001119 * Show the {@link Notification#when} field as a stopwatch.
Joe Malin8d40d042012-11-05 11:36:40 -08001120 *
1121 * Instead of presenting <code>when</code> as a timestamp, the notification will show an
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001122 * automatically updating display of the minutes and seconds since <code>when</code>.
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001123 *
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001124 * Useful when showing an elapsed time (like an ongoing phone call).
1125 *
1126 * @see android.widget.Chronometer
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001127 * @see Notification#when
1128 */
1129 public Builder setUsesChronometer(boolean b) {
1130 mUseChronometer = b;
1131 return this;
1132 }
1133
1134 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001135 * Set the small icon resource, which will be used to represent the notification in the
1136 * status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -08001137 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001138
1139 * The platform template for the expanded view will draw this icon in the left, unless a
1140 * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small
1141 * icon will be moved to the right-hand side.
1142 *
1143
1144 * @param icon
1145 * A resource ID in the application's package of the drawable to use.
1146 * @see Notification#icon
Joe Onoratocb109a02011-01-18 17:57:41 -08001147 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001148 public Builder setSmallIcon(int icon) {
1149 mSmallIcon = icon;
1150 return this;
1151 }
1152
Joe Onoratocb109a02011-01-18 17:57:41 -08001153 /**
1154 * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional
1155 * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable
1156 * LevelListDrawable}.
1157 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001158 * @param icon A resource ID in the application's package of the drawable to use.
Joe Onoratocb109a02011-01-18 17:57:41 -08001159 * @param level The level to use for the icon.
1160 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001161 * @see Notification#icon
1162 * @see Notification#iconLevel
Joe Onoratocb109a02011-01-18 17:57:41 -08001163 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001164 public Builder setSmallIcon(int icon, int level) {
1165 mSmallIcon = icon;
1166 mSmallIconLevel = level;
1167 return this;
1168 }
1169
Joe Onoratocb109a02011-01-18 17:57:41 -08001170 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001171 * Set the first line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001172 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001173 public Builder setContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001174 mContentTitle = safeCharSequence(title);
Joe Onorato46439ce2010-11-19 13:56:21 -08001175 return this;
1176 }
1177
Joe Onoratocb109a02011-01-18 17:57:41 -08001178 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001179 * Set the second line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001180 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001181 public Builder setContentText(CharSequence text) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001182 mContentText = safeCharSequence(text);
Joe Onorato46439ce2010-11-19 13:56:21 -08001183 return this;
1184 }
1185
Joe Onoratocb109a02011-01-18 17:57:41 -08001186 /**
Joe Malin8d40d042012-11-05 11:36:40 -08001187 * Set the third line of text in the platform notification template.
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001188 * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the
1189 * same location in the standard template.
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001190 */
1191 public Builder setSubText(CharSequence text) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001192 mSubText = safeCharSequence(text);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001193 return this;
1194 }
1195
1196 /**
Joe Onoratocb109a02011-01-18 17:57:41 -08001197 * Set the large number at the right-hand side of the notification. This is
1198 * equivalent to setContentInfo, although it might show the number in a different
1199 * font size for readability.
1200 */
Joe Onorato8595a3d2010-11-19 18:12:07 -08001201 public Builder setNumber(int number) {
1202 mNumber = number;
1203 return this;
1204 }
1205
Joe Onoratocb109a02011-01-18 17:57:41 -08001206 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001207 * A small piece of additional information pertaining to this notification.
1208 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001209 * The platform template will draw this on the last line of the notification, at the far
1210 * right (to the right of a smallIcon if it has been placed there).
Joe Onoratocb109a02011-01-18 17:57:41 -08001211 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001212 public Builder setContentInfo(CharSequence info) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001213 mContentInfo = safeCharSequence(info);
Joe Onorato46439ce2010-11-19 13:56:21 -08001214 return this;
1215 }
1216
Joe Onoratocb109a02011-01-18 17:57:41 -08001217 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001218 * Set the progress this notification represents.
1219 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001220 * The platform template will represent this using a {@link ProgressBar}.
Jeff Sharkey1c400132011-08-05 14:50:13 -07001221 */
1222 public Builder setProgress(int max, int progress, boolean indeterminate) {
1223 mProgressMax = max;
1224 mProgress = progress;
1225 mProgressIndeterminate = indeterminate;
1226 return this;
1227 }
1228
1229 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001230 * Supply a custom RemoteViews to use instead of the platform template.
1231 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001232 * @see Notification#contentView
Joe Onoratocb109a02011-01-18 17:57:41 -08001233 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001234 public Builder setContent(RemoteViews views) {
1235 mContentView = views;
1236 return this;
1237 }
1238
Joe Onoratocb109a02011-01-18 17:57:41 -08001239 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001240 * Supply a {@link PendingIntent} to be sent when the notification is clicked.
1241 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001242 * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you
1243 * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use
1244 * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)}
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001245 * to assign PendingIntents to individual views in that custom layout (i.e., to create
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001246 * clickable buttons inside the notification view).
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001247 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001248 * @see Notification#contentIntent Notification.contentIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001249 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001250 public Builder setContentIntent(PendingIntent intent) {
1251 mContentIntent = intent;
1252 return this;
1253 }
1254
Joe Onoratocb109a02011-01-18 17:57:41 -08001255 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001256 * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user.
1257 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001258 * @see Notification#deleteIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001259 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001260 public Builder setDeleteIntent(PendingIntent intent) {
1261 mDeleteIntent = intent;
1262 return this;
1263 }
1264
Joe Onoratocb109a02011-01-18 17:57:41 -08001265 /**
1266 * An intent to launch instead of posting the notification to the status bar.
1267 * Only for use with extremely high-priority notifications demanding the user's
1268 * <strong>immediate</strong> attention, such as an incoming phone call or
1269 * alarm clock that the user has explicitly set to a particular time.
1270 * If this facility is used for something else, please give the user an option
1271 * to turn it off and use a normal notification, as this can be extremely
1272 * disruptive.
1273 *
1274 * @param intent The pending intent to launch.
1275 * @param highPriority Passing true will cause this notification to be sent
1276 * even if other notifications are suppressed.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001277 *
1278 * @see Notification#fullScreenIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001279 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001280 public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
1281 mFullScreenIntent = intent;
1282 setFlag(FLAG_HIGH_PRIORITY, highPriority);
1283 return this;
1284 }
1285
Joe Onoratocb109a02011-01-18 17:57:41 -08001286 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001287 * Set the "ticker" text which is displayed in the status bar when the notification first
Joe Onoratocb109a02011-01-18 17:57:41 -08001288 * arrives.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001289 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001290 * @see Notification#tickerText
Joe Onoratocb109a02011-01-18 17:57:41 -08001291 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001292 public Builder setTicker(CharSequence tickerText) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001293 mTickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08001294 return this;
1295 }
1296
Joe Onoratocb109a02011-01-18 17:57:41 -08001297 /**
1298 * Set the text that is displayed in the status bar when the notification first
1299 * arrives, and also a RemoteViews object that may be displayed instead on some
1300 * devices.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001301 *
1302 * @see Notification#tickerText
1303 * @see Notification#tickerView
Joe Onoratocb109a02011-01-18 17:57:41 -08001304 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001305 public Builder setTicker(CharSequence tickerText, RemoteViews views) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001306 mTickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08001307 mTickerView = views;
1308 return this;
1309 }
1310
Joe Onoratocb109a02011-01-18 17:57:41 -08001311 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001312 * Add a large icon to the notification (and the ticker on some devices).
1313 *
1314 * In the platform template, this image will be shown on the left of the notification view
1315 * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side).
1316 *
1317 * @see Notification#largeIcon
Joe Onoratocb109a02011-01-18 17:57:41 -08001318 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001319 public Builder setLargeIcon(Bitmap icon) {
1320 mLargeIcon = icon;
1321 return this;
1322 }
1323
Joe Onoratocb109a02011-01-18 17:57:41 -08001324 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001325 * Set the sound to play.
1326 *
1327 * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications.
1328 *
1329 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001330 */
Joe Onorato52f80cd2010-11-21 15:34:48 -08001331 public Builder setSound(Uri sound) {
1332 mSound = sound;
1333 mAudioStreamType = STREAM_DEFAULT;
1334 return this;
1335 }
1336
Joe Onoratocb109a02011-01-18 17:57:41 -08001337 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001338 * Set the sound to play, along with a specific stream on which to play it.
Joe Onoratocb109a02011-01-18 17:57:41 -08001339 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001340 * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants.
1341 *
1342 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001343 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001344 public Builder setSound(Uri sound, int streamType) {
1345 mSound = sound;
1346 mAudioStreamType = streamType;
1347 return this;
1348 }
1349
Joe Onoratocb109a02011-01-18 17:57:41 -08001350 /**
1351 * Set the vibration pattern to use.
1352 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001353
1354 * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the
1355 * <code>pattern</code> parameter.
1356 *
1357
1358 * @see Notification#vibrate
Joe Onoratocb109a02011-01-18 17:57:41 -08001359 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001360 public Builder setVibrate(long[] pattern) {
1361 mVibrate = pattern;
1362 return this;
1363 }
1364
Joe Onoratocb109a02011-01-18 17:57:41 -08001365 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001366 * Set the desired color for the indicator LED on the device, as well as the
1367 * blink duty cycle (specified in milliseconds).
1368 *
1369
1370 * Not all devices will honor all (or even any) of these values.
1371 *
1372
1373 * @see Notification#ledARGB
1374 * @see Notification#ledOnMS
1375 * @see Notification#ledOffMS
Joe Onoratocb109a02011-01-18 17:57:41 -08001376 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001377 public Builder setLights(int argb, int onMs, int offMs) {
1378 mLedArgb = argb;
1379 mLedOnMs = onMs;
1380 mLedOffMs = offMs;
Joe Onorato46439ce2010-11-19 13:56:21 -08001381 return this;
1382 }
1383
Joe Onoratocb109a02011-01-18 17:57:41 -08001384 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001385 * Set whether this is an "ongoing" notification.
Joe Onoratocb109a02011-01-18 17:57:41 -08001386 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001387
1388 * Ongoing notifications cannot be dismissed by the user, so your application or service
1389 * must take care of canceling them.
1390 *
1391
1392 * They are typically used to indicate a background task that the user is actively engaged
1393 * with (e.g., playing music) or is pending in some way and therefore occupying the device
1394 * (e.g., a file download, sync operation, active network connection).
1395 *
1396
1397 * @see Notification#FLAG_ONGOING_EVENT
1398 * @see Service#setForeground(boolean)
Joe Onoratocb109a02011-01-18 17:57:41 -08001399 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001400 public Builder setOngoing(boolean ongoing) {
1401 setFlag(FLAG_ONGOING_EVENT, ongoing);
1402 return this;
1403 }
1404
Joe Onoratocb109a02011-01-18 17:57:41 -08001405 /**
1406 * Set this flag if you would only like the sound, vibrate
1407 * and ticker to be played if the notification is not already showing.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001408 *
1409 * @see Notification#FLAG_ONLY_ALERT_ONCE
Joe Onoratocb109a02011-01-18 17:57:41 -08001410 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001411 public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
1412 setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
1413 return this;
1414 }
1415
Joe Onoratocb109a02011-01-18 17:57:41 -08001416 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001417 * Make this notification automatically dismissed when the user touches it. The
1418 * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens.
1419 *
1420 * @see Notification#FLAG_AUTO_CANCEL
Joe Onoratocb109a02011-01-18 17:57:41 -08001421 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001422 public Builder setAutoCancel(boolean autoCancel) {
Joe Onorato281d83f2011-01-04 17:13:10 -08001423 setFlag(FLAG_AUTO_CANCEL, autoCancel);
Joe Onorato46439ce2010-11-19 13:56:21 -08001424 return this;
1425 }
1426
Joe Onoratocb109a02011-01-18 17:57:41 -08001427 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001428 * Set which notification properties will be inherited from system defaults.
Joe Onoratocb109a02011-01-18 17:57:41 -08001429 * <p>
1430 * The value should be one or more of the following fields combined with
1431 * bitwise-or:
1432 * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}.
1433 * <p>
1434 * For all default values, use {@link #DEFAULT_ALL}.
1435 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001436 public Builder setDefaults(int defaults) {
1437 mDefaults = defaults;
1438 return this;
1439 }
1440
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001441 /**
1442 * Set the priority of this notification.
1443 *
1444 * @see Notification#priority
1445 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001446 public Builder setPriority(@Priority int pri) {
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001447 mPriority = pri;
1448 return this;
1449 }
Joe Malin8d40d042012-11-05 11:36:40 -08001450
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001451 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001452 * @hide
Joe Malin8d40d042012-11-05 11:36:40 -08001453 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001454 * Add a kind (category) to this notification. Optional.
Joe Malin8d40d042012-11-05 11:36:40 -08001455 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001456 * @see Notification#kind
1457 */
1458 public Builder addKind(String k) {
1459 mKindList.add(k);
1460 return this;
1461 }
1462
1463 /**
1464 * Add metadata to this notification.
1465 *
1466 * A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001467 * current contents are copied into the Notification each time {@link #build()} is
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001468 * called.
1469 *
1470 * @see Notification#extras
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001471 */
1472 public Builder setExtras(Bundle bag) {
1473 mExtras = bag;
1474 return this;
1475 }
1476
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001477 /**
1478 * Add an action to this notification. Actions are typically displayed by
1479 * the system as a button adjacent to the notification content.
Joe Malin8d40d042012-11-05 11:36:40 -08001480 * <br>
1481 * A notification displays up to 3 actions, from left to right in the order they were added.
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001482 *
1483 * @param icon Resource ID of a drawable that represents the action.
1484 * @param title Text describing the action.
1485 * @param intent PendingIntent to be fired when the action is invoked.
1486 */
1487 public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001488 mActions.add(new Action(icon, safeCharSequence(title), intent));
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001489 return this;
1490 }
1491
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001492 /**
1493 * Add a rich notification style to be applied at build time.
1494 *
1495 * @param style Object responsible for modifying the notification style.
1496 */
1497 public Builder setStyle(Style style) {
1498 if (mStyle != style) {
1499 mStyle = style;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07001500 if (mStyle != null) {
1501 mStyle.setBuilder(this);
1502 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001503 }
1504 return this;
1505 }
1506
Joe Onorato46439ce2010-11-19 13:56:21 -08001507 private void setFlag(int mask, boolean value) {
1508 if (value) {
1509 mFlags |= mask;
1510 } else {
1511 mFlags &= ~mask;
1512 }
1513 }
1514
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001515 private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
Joe Onorato561d3852010-11-20 18:09:34 -08001516 RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001517 boolean showLine3 = false;
1518 boolean showLine2 = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001519 int smallIconImageViewId = R.id.icon;
1520 if (mLargeIcon != null) {
1521 contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
1522 smallIconImageViewId = R.id.right_icon;
1523 }
Daniel Sandlere95658c2012-05-10 00:33:54 -04001524 if (mPriority < PRIORITY_LOW) {
1525 contentView.setInt(R.id.icon,
1526 "setBackgroundResource", R.drawable.notification_template_icon_low_bg);
1527 contentView.setInt(R.id.status_bar_latest_event_content,
1528 "setBackgroundResource", R.drawable.notification_bg_low);
1529 }
Joe Onorato561d3852010-11-20 18:09:34 -08001530 if (mSmallIcon != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001531 contentView.setImageViewResource(smallIconImageViewId, mSmallIcon);
1532 contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001533 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001534 contentView.setViewVisibility(smallIconImageViewId, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001535 }
1536 if (mContentTitle != null) {
1537 contentView.setTextViewText(R.id.title, mContentTitle);
1538 }
1539 if (mContentText != null) {
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001540 contentView.setTextViewText(R.id.text, mContentText);
1541 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001542 }
1543 if (mContentInfo != null) {
1544 contentView.setTextViewText(R.id.info, mContentInfo);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001545 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001546 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001547 } else if (mNumber > 0) {
Daniel Sandlerebce0112011-06-16 16:44:51 -04001548 final int tooBig = mContext.getResources().getInteger(
1549 R.integer.status_bar_notification_info_maxnum);
1550 if (mNumber > tooBig) {
1551 contentView.setTextViewText(R.id.info, mContext.getResources().getString(
1552 R.string.status_bar_notification_info_overflow));
Joe Onorato059a2f82011-01-04 10:27:01 -08001553 } else {
1554 NumberFormat f = NumberFormat.getIntegerInstance();
1555 contentView.setTextViewText(R.id.info, f.format(mNumber));
1556 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001557 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001558 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001559 } else {
1560 contentView.setViewVisibility(R.id.info, View.GONE);
1561 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001562
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001563 // Need to show three lines?
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001564 if (mSubText != null) {
1565 contentView.setTextViewText(R.id.text, mSubText);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001566 if (mContentText != null) {
1567 contentView.setTextViewText(R.id.text2, mContentText);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001568 contentView.setViewVisibility(R.id.text2, View.VISIBLE);
1569 showLine2 = true;
1570 } else {
1571 contentView.setViewVisibility(R.id.text2, View.GONE);
1572 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001573 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001574 contentView.setViewVisibility(R.id.text2, View.GONE);
1575 if (mProgressMax != 0 || mProgressIndeterminate) {
1576 contentView.setProgressBar(
1577 R.id.progress, mProgressMax, mProgress, mProgressIndeterminate);
1578 contentView.setViewVisibility(R.id.progress, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001579 showLine2 = true;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001580 } else {
1581 contentView.setViewVisibility(R.id.progress, View.GONE);
1582 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001583 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001584 if (showLine2) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001585 if (fitIn1U) {
1586 // need to shrink all the type to make sure everything fits
1587 final Resources res = mContext.getResources();
1588 final float subTextSize = res.getDimensionPixelSize(
1589 R.dimen.notification_subtext_size);
1590 contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize);
1591 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001592 // vertical centering
1593 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
1594 }
1595
Daniel Sandler0c890492012-09-12 17:23:10 -07001596 if (mWhen != 0 && mShowWhen) {
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001597 if (mUseChronometer) {
1598 contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
1599 contentView.setLong(R.id.chronometer, "setBase",
1600 mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
1601 contentView.setBoolean(R.id.chronometer, "setStarted", true);
1602 } else {
1603 contentView.setViewVisibility(R.id.time, View.VISIBLE);
1604 contentView.setLong(R.id.time, "setTime", mWhen);
1605 }
Daniel Sandler0c890492012-09-12 17:23:10 -07001606 } else {
1607 contentView.setViewVisibility(R.id.time, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001608 }
Daniel Sandler0c890492012-09-12 17:23:10 -07001609
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001610 contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001611 contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001612 return contentView;
1613 }
1614
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001615 private RemoteViews applyStandardTemplateWithActions(int layoutId) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001616 RemoteViews big = applyStandardTemplate(layoutId, false);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001617
1618 int N = mActions.size();
1619 if (N > 0) {
Chris Wrend6297db2012-05-03 16:20:13 -04001620 // Log.d("Notification", "has actions: " + mContentText);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001621 big.setViewVisibility(R.id.actions, View.VISIBLE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001622 big.setViewVisibility(R.id.action_divider, View.VISIBLE);
Daniel Sandler8680bf82012-05-15 16:52:52 -04001623 if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS;
Chris Wren2c22eb02012-05-08 09:49:13 -04001624 big.removeAllViews(R.id.actions);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001625 for (int i=0; i<N; i++) {
1626 final RemoteViews button = generateActionButton(mActions.get(i));
Chris Wrend6297db2012-05-03 16:20:13 -04001627 //Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001628 big.addView(R.id.actions, button);
1629 }
1630 }
1631 return big;
1632 }
1633
Joe Onorato46439ce2010-11-19 13:56:21 -08001634 private RemoteViews makeContentView() {
1635 if (mContentView != null) {
1636 return mContentView;
1637 } else {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001638 return applyStandardTemplate(R.layout.notification_template_base, true); // no more special large_icon flavor
Joe Onorato46439ce2010-11-19 13:56:21 -08001639 }
1640 }
1641
1642 private RemoteViews makeTickerView() {
1643 if (mTickerView != null) {
1644 return mTickerView;
1645 } else {
Joe Onorato561d3852010-11-20 18:09:34 -08001646 if (mContentView == null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001647 return applyStandardTemplate(mLargeIcon == null
Joe Onorato561d3852010-11-20 18:09:34 -08001648 ? R.layout.status_bar_latest_event_ticker
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001649 : R.layout.status_bar_latest_event_ticker_large_icon, true);
Joe Onorato561d3852010-11-20 18:09:34 -08001650 } else {
1651 return null;
1652 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001653 }
1654 }
1655
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001656 private RemoteViews makeBigContentView() {
1657 if (mActions.size() == 0) return null;
1658
Chris Wrenb023bf82012-04-23 16:05:42 -04001659 return applyStandardTemplateWithActions(R.layout.notification_template_big_base);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001660 }
1661
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001662 private RemoteViews generateActionButton(Action action) {
Daniel Sandler8680bf82012-05-15 16:52:52 -04001663 final boolean tombstone = (action.actionIntent == null);
Joe Malin8d40d042012-11-05 11:36:40 -08001664 RemoteViews button = new RemoteViews(mContext.getPackageName(),
Daniel Sandler8680bf82012-05-15 16:52:52 -04001665 tombstone ? R.layout.notification_action_tombstone
1666 : R.layout.notification_action);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001667 button.setTextViewCompoundDrawables(R.id.action0, action.icon, 0, 0, 0);
1668 button.setTextViewText(R.id.action0, action.title);
Daniel Sandler8680bf82012-05-15 16:52:52 -04001669 if (!tombstone) {
Daniel Sandlere5518842012-05-10 16:20:40 -04001670 button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
Daniel Sandlere5518842012-05-10 16:20:40 -04001671 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001672 button.setContentDescription(R.id.action0, action.title);
1673 return button;
1674 }
1675
Joe Onoratocb109a02011-01-18 17:57:41 -08001676 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001677 * Apply the unstyled operations and return a new {@link Notification} object.
Joe Onoratocb109a02011-01-18 17:57:41 -08001678 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001679 private Notification buildUnstyled() {
Joe Onorato46439ce2010-11-19 13:56:21 -08001680 Notification n = new Notification();
1681 n.when = mWhen;
1682 n.icon = mSmallIcon;
1683 n.iconLevel = mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08001684 n.number = mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08001685 n.contentView = makeContentView();
1686 n.contentIntent = mContentIntent;
1687 n.deleteIntent = mDeleteIntent;
1688 n.fullScreenIntent = mFullScreenIntent;
1689 n.tickerText = mTickerText;
1690 n.tickerView = makeTickerView();
1691 n.largeIcon = mLargeIcon;
1692 n.sound = mSound;
1693 n.audioStreamType = mAudioStreamType;
1694 n.vibrate = mVibrate;
1695 n.ledARGB = mLedArgb;
1696 n.ledOnMS = mLedOnMs;
1697 n.ledOffMS = mLedOffMs;
1698 n.defaults = mDefaults;
1699 n.flags = mFlags;
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001700 n.bigContentView = makeBigContentView();
Daniel Sandler26c13432013-04-04 11:01:04 -04001701 if (mLedOnMs != 0 || mLedOffMs != 0) {
Joe Onorato8d0b6552010-11-22 16:09:29 -08001702 n.flags |= FLAG_SHOW_LIGHTS;
1703 }
1704 if ((mDefaults & DEFAULT_LIGHTS) != 0) {
1705 n.flags |= FLAG_SHOW_LIGHTS;
1706 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001707 if (mKindList.size() > 0) {
1708 n.kind = new String[mKindList.size()];
1709 mKindList.toArray(n.kind);
1710 } else {
1711 n.kind = null;
1712 }
1713 n.priority = mPriority;
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001714 if (mActions.size() > 0) {
1715 n.actions = new Action[mActions.size()];
1716 mActions.toArray(n.actions);
1717 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001718
Joe Onorato46439ce2010-11-19 13:56:21 -08001719 return n;
1720 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001721
1722 /**
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001723 * Capture, in the provided bundle, semantic information used in the construction of
1724 * this Notification object.
1725 * @hide
1726 */
1727 public void addExtras(Bundle extras) {
1728 // Store original information used in the construction of this object
1729 extras.putCharSequence(EXTRA_TITLE, mContentTitle);
1730 extras.putCharSequence(EXTRA_TEXT, mContentText);
1731 extras.putCharSequence(EXTRA_SUB_TEXT, mSubText);
1732 extras.putCharSequence(EXTRA_INFO_TEXT, mContentInfo);
1733 extras.putInt(EXTRA_SMALL_ICON, mSmallIcon);
1734 extras.putInt(EXTRA_PROGRESS, mProgress);
1735 extras.putInt(EXTRA_PROGRESS_MAX, mProgressMax);
1736 extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mProgressIndeterminate);
1737 extras.putBoolean(EXTRA_SHOW_CHRONOMETER, mUseChronometer);
1738 extras.putBoolean(EXTRA_SHOW_WHEN, mShowWhen);
John Spurlockac08a472013-06-10 11:37:08 -04001739 if (mLargeIcon != null) {
1740 extras.putParcelable(EXTRA_LARGE_ICON, mLargeIcon);
1741 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001742 }
1743
1744 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001745 * @deprecated Use {@link #build()} instead.
1746 */
1747 @Deprecated
1748 public Notification getNotification() {
1749 return build();
1750 }
1751
1752 /**
1753 * Combine all of the options that have been set and return a new {@link Notification}
1754 * object.
1755 */
1756 public Notification build() {
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001757 final Notification n;
1758
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001759 if (mStyle != null) {
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001760 n = mStyle.build();
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001761 } else {
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001762 n = buildUnstyled();
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001763 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001764
1765 n.extras = mExtras != null ? new Bundle(mExtras) : new Bundle();
1766
1767 addExtras(n.extras);
1768 if (mStyle != null) {
1769 mStyle.addExtras(n.extras);
1770 }
1771
1772 return n;
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001773 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001774
1775 /**
1776 * Apply this Builder to an existing {@link Notification} object.
1777 *
1778 * @hide
1779 */
1780 public Notification buildInto(Notification n) {
Daniel Sandler1a497d32013-04-18 14:52:45 -04001781 build().cloneInto(n, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001782 return n;
1783 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001784 }
1785
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001786 /**
1787 * An object that can apply a rich notification style to a {@link Notification.Builder}
1788 * object.
1789 */
Chris Wrend6297db2012-05-03 16:20:13 -04001790 public static abstract class Style
1791 {
1792 private CharSequence mBigContentTitle;
1793 private CharSequence mSummaryText = null;
Daniel Sandler619738c2012-06-07 16:33:08 -04001794 private boolean mSummaryTextSet = false;
Chris Wrend6297db2012-05-03 16:20:13 -04001795
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001796 protected Builder mBuilder;
1797
Chris Wrend6297db2012-05-03 16:20:13 -04001798 /**
1799 * Overrides ContentTitle in the big form of the template.
1800 * This defaults to the value passed to setContentTitle().
1801 */
1802 protected void internalSetBigContentTitle(CharSequence title) {
1803 mBigContentTitle = title;
1804 }
1805
1806 /**
1807 * Set the first line of text after the detail section in the big form of the template.
1808 */
1809 protected void internalSetSummaryText(CharSequence cs) {
1810 mSummaryText = cs;
Daniel Sandler619738c2012-06-07 16:33:08 -04001811 mSummaryTextSet = true;
Chris Wrend6297db2012-05-03 16:20:13 -04001812 }
1813
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001814 public void setBuilder(Builder builder) {
1815 if (mBuilder != builder) {
1816 mBuilder = builder;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07001817 if (mBuilder != null) {
1818 mBuilder.setStyle(this);
1819 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001820 }
1821 }
1822
Chris Wrend6297db2012-05-03 16:20:13 -04001823 protected void checkBuilder() {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001824 if (mBuilder == null) {
1825 throw new IllegalArgumentException("Style requires a valid Builder object");
1826 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001827 }
Chris Wrend6297db2012-05-03 16:20:13 -04001828
1829 protected RemoteViews getStandardView(int layoutId) {
1830 checkBuilder();
1831
1832 if (mBigContentTitle != null) {
1833 mBuilder.setContentTitle(mBigContentTitle);
1834 }
1835
Chris Wrend6297db2012-05-03 16:20:13 -04001836 RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId);
1837
Chris Wrend6297db2012-05-03 16:20:13 -04001838 if (mBigContentTitle != null && mBigContentTitle.equals("")) {
1839 contentView.setViewVisibility(R.id.line1, View.GONE);
Chris Wren67dc9a02012-05-16 01:03:20 -04001840 } else {
1841 contentView.setViewVisibility(R.id.line1, View.VISIBLE);
Chris Wrend6297db2012-05-03 16:20:13 -04001842 }
1843
Daniel Sandler619738c2012-06-07 16:33:08 -04001844 // The last line defaults to the subtext, but can be replaced by mSummaryText
1845 final CharSequence overflowText =
1846 mSummaryTextSet ? mSummaryText
1847 : mBuilder.mSubText;
1848 if (overflowText != null) {
1849 contentView.setTextViewText(R.id.text, overflowText);
1850 contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001851 contentView.setViewVisibility(R.id.line3, View.VISIBLE);
Daniel Sandler916ad912012-06-13 12:17:07 -04001852 } else {
1853 contentView.setViewVisibility(R.id.overflow_divider, View.GONE);
1854 contentView.setViewVisibility(R.id.line3, View.GONE);
Chris Wrend6297db2012-05-03 16:20:13 -04001855 }
1856
1857 return contentView;
1858 }
1859
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001860 /**
1861 * @hide
1862 */
1863 public void addExtras(Bundle extras) {
1864 if (mSummaryTextSet) {
1865 extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText);
1866 }
1867 if (mBigContentTitle != null) {
1868 extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle);
1869 }
1870 }
1871
Chris Wrend6297db2012-05-03 16:20:13 -04001872 public abstract Notification build();
Joe Onorato46439ce2010-11-19 13:56:21 -08001873 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001874
1875 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001876 * Helper class for generating large-format notifications that include a large image attachment.
Joe Malin8d40d042012-11-05 11:36:40 -08001877 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001878 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001879 * <pre class="prettyprint">
1880 * Notification noti = new Notification.BigPictureStyle(
1881 * new Notification.Builder()
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001882 * .setContentTitle(&quot;New photo from &quot; + sender.toString())
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001883 * .setContentText(subject)
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001884 * .setSmallIcon(R.drawable.new_post)
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001885 * .setLargeIcon(aBitmap))
1886 * .bigPicture(aBigBitmap)
1887 * .build();
1888 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08001889 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001890 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001891 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001892 public static class BigPictureStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001893 private Bitmap mPicture;
Chris Wren3745a3d2012-05-22 15:11:52 -04001894 private Bitmap mBigLargeIcon;
1895 private boolean mBigLargeIconSet = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001896
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001897 public BigPictureStyle() {
1898 }
1899
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001900 public BigPictureStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001901 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001902 }
1903
Chris Wrend6297db2012-05-03 16:20:13 -04001904 /**
1905 * Overrides ContentTitle in the big form of the template.
1906 * This defaults to the value passed to setContentTitle().
1907 */
1908 public BigPictureStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001909 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04001910 return this;
1911 }
1912
1913 /**
1914 * Set the first line of text after the detail section in the big form of the template.
1915 */
1916 public BigPictureStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001917 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04001918 return this;
1919 }
1920
Chris Wren0bd664d2012-08-01 13:56:56 -04001921 /**
1922 * Provide the bitmap to be used as the payload for the BigPicture notification.
1923 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001924 public BigPictureStyle bigPicture(Bitmap b) {
1925 mPicture = b;
1926 return this;
1927 }
1928
Chris Wren3745a3d2012-05-22 15:11:52 -04001929 /**
Chris Wren3745a3d2012-05-22 15:11:52 -04001930 * Override the large icon when the big notification is shown.
1931 */
1932 public BigPictureStyle bigLargeIcon(Bitmap b) {
1933 mBigLargeIconSet = true;
1934 mBigLargeIcon = b;
1935 return this;
1936 }
1937
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001938 private RemoteViews makeBigContentView() {
Chris Wrend6297db2012-05-03 16:20:13 -04001939 RemoteViews contentView = getStandardView(R.layout.notification_template_big_picture);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001940
1941 contentView.setImageViewBitmap(R.id.big_picture, mPicture);
1942
1943 return contentView;
1944 }
1945
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001946 /**
1947 * @hide
1948 */
1949 public void addExtras(Bundle extras) {
1950 super.addExtras(extras);
1951
1952 if (mBigLargeIconSet) {
1953 extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon);
1954 }
1955 extras.putParcelable(EXTRA_PICTURE, mPicture);
1956 }
1957
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001958 @Override
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001959 public Notification build() {
Chris Wrend6297db2012-05-03 16:20:13 -04001960 checkBuilder();
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001961 Notification wip = mBuilder.buildUnstyled();
Chris Wren3745a3d2012-05-22 15:11:52 -04001962 if (mBigLargeIconSet ) {
1963 mBuilder.mLargeIcon = mBigLargeIcon;
1964 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001965 wip.bigContentView = makeBigContentView();
1966 return wip;
1967 }
1968 }
1969
1970 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001971 * Helper class for generating large-format notifications that include a lot of text.
Joe Malin8d40d042012-11-05 11:36:40 -08001972 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001973 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001974 * <pre class="prettyprint">
Daniel Sandler87682782012-11-07 14:04:42 -05001975 * Notification noti = new Notification.BigTextStyle(
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001976 * new Notification.Builder()
1977 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
1978 * .setContentText(subject)
1979 * .setSmallIcon(R.drawable.new_mail)
1980 * .setLargeIcon(aBitmap))
1981 * .bigText(aVeryLongString)
1982 * .build();
1983 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08001984 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001985 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001986 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001987 public static class BigTextStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001988 private CharSequence mBigText;
1989
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001990 public BigTextStyle() {
1991 }
1992
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001993 public BigTextStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001994 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001995 }
1996
Chris Wrend6297db2012-05-03 16:20:13 -04001997 /**
1998 * Overrides ContentTitle in the big form of the template.
1999 * This defaults to the value passed to setContentTitle().
2000 */
2001 public BigTextStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002002 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002003 return this;
2004 }
2005
2006 /**
2007 * Set the first line of text after the detail section in the big form of the template.
2008 */
2009 public BigTextStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002010 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002011 return this;
2012 }
2013
Chris Wren0bd664d2012-08-01 13:56:56 -04002014 /**
2015 * Provide the longer text to be displayed in the big form of the
2016 * template in place of the content text.
2017 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002018 public BigTextStyle bigText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002019 mBigText = safeCharSequence(cs);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002020 return this;
2021 }
2022
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002023 /**
2024 * @hide
2025 */
2026 public void addExtras(Bundle extras) {
2027 super.addExtras(extras);
2028
2029 extras.putCharSequence(EXTRA_TEXT, mBigText);
2030 }
2031
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002032 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04002033 // Remove the content text so line3 only shows if you have a summary
2034 final boolean hadThreeLines = (mBuilder.mContentText != null && mBuilder.mSubText != null);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002035 mBuilder.mContentText = null;
Daniel Sandler916ad912012-06-13 12:17:07 -04002036
Chris Wrend6297db2012-05-03 16:20:13 -04002037 RemoteViews contentView = getStandardView(R.layout.notification_template_big_text);
Joe Malin8d40d042012-11-05 11:36:40 -08002038
Daniel Sandler619738c2012-06-07 16:33:08 -04002039 if (hadThreeLines) {
2040 // vertical centering
2041 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
2042 }
2043
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002044 contentView.setTextViewText(R.id.big_text, mBigText);
2045 contentView.setViewVisibility(R.id.big_text, View.VISIBLE);
Chris Wren3c5f92432012-05-04 16:31:17 -04002046 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002047
2048 return contentView;
2049 }
2050
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002051 @Override
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002052 public Notification build() {
Chris Wrend6297db2012-05-03 16:20:13 -04002053 checkBuilder();
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002054 Notification wip = mBuilder.buildUnstyled();
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002055 wip.bigContentView = makeBigContentView();
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002056
2057 wip.extras.putCharSequence(EXTRA_TEXT, mBigText);
2058
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002059 return wip;
2060 }
2061 }
Daniel Sandler879c5e02012-04-17 16:46:51 -04002062
2063 /**
2064 * Helper class for generating large-format notifications that include a list of (up to 5) strings.
Joe Malin8d40d042012-11-05 11:36:40 -08002065 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04002066 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
2067 * <pre class="prettyprint">
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002068 * Notification noti = new Notification.InboxStyle(
Daniel Sandler879c5e02012-04-17 16:46:51 -04002069 * new Notification.Builder()
Chris Wrend6297db2012-05-03 16:20:13 -04002070 * .setContentTitle(&quot;5 New mails from &quot; + sender.toString())
Daniel Sandler879c5e02012-04-17 16:46:51 -04002071 * .setContentText(subject)
2072 * .setSmallIcon(R.drawable.new_mail)
2073 * .setLargeIcon(aBitmap))
2074 * .addLine(str1)
2075 * .addLine(str2)
Chris Wrend6297db2012-05-03 16:20:13 -04002076 * .setContentTitle("")
2077 * .setSummaryText(&quot;+3 more&quot;)
Daniel Sandler879c5e02012-04-17 16:46:51 -04002078 * .build();
2079 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002080 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04002081 * @see Notification#bigContentView
2082 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002083 public static class InboxStyle extends Style {
Daniel Sandler879c5e02012-04-17 16:46:51 -04002084 private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5);
2085
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002086 public InboxStyle() {
2087 }
2088
Daniel Sandler879c5e02012-04-17 16:46:51 -04002089 public InboxStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002090 setBuilder(builder);
Daniel Sandler879c5e02012-04-17 16:46:51 -04002091 }
2092
Chris Wrend6297db2012-05-03 16:20:13 -04002093 /**
2094 * Overrides ContentTitle in the big form of the template.
2095 * This defaults to the value passed to setContentTitle().
2096 */
2097 public InboxStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002098 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002099 return this;
2100 }
2101
2102 /**
2103 * Set the first line of text after the detail section in the big form of the template.
2104 */
2105 public InboxStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002106 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002107 return this;
2108 }
2109
Chris Wren0bd664d2012-08-01 13:56:56 -04002110 /**
2111 * Append a line to the digest section of the Inbox notification.
2112 */
Daniel Sandler879c5e02012-04-17 16:46:51 -04002113 public InboxStyle addLine(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002114 mTexts.add(safeCharSequence(cs));
Daniel Sandler879c5e02012-04-17 16:46:51 -04002115 return this;
2116 }
2117
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002118 /**
2119 * @hide
2120 */
2121 public void addExtras(Bundle extras) {
2122 super.addExtras(extras);
2123 CharSequence[] a = new CharSequence[mTexts.size()];
2124 extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a));
2125 }
2126
Daniel Sandler879c5e02012-04-17 16:46:51 -04002127 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04002128 // Remove the content text so line3 disappears unless you have a summary
2129 mBuilder.mContentText = null;
Chris Wrend6297db2012-05-03 16:20:13 -04002130 RemoteViews contentView = getStandardView(R.layout.notification_template_inbox);
Daniel Sandler619738c2012-06-07 16:33:08 -04002131
Chris Wrend6297db2012-05-03 16:20:13 -04002132 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandler879c5e02012-04-17 16:46:51 -04002133
Chris Wrend6297db2012-05-03 16:20:13 -04002134 int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3,
Chris Wren29bb6d92012-05-17 18:09:42 -04002135 R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6};
Chris Wrend6297db2012-05-03 16:20:13 -04002136
Chris Wren4ed80d52012-05-17 09:30:03 -04002137 // Make sure all rows are gone in case we reuse a view.
2138 for (int rowId : rowIds) {
2139 contentView.setViewVisibility(rowId, View.GONE);
2140 }
2141
Chris Wren683ab002012-09-20 10:35:54 -04002142
Daniel Sandler879c5e02012-04-17 16:46:51 -04002143 int i=0;
2144 while (i < mTexts.size() && i < rowIds.length) {
2145 CharSequence str = mTexts.get(i);
2146 if (str != null && !str.equals("")) {
2147 contentView.setViewVisibility(rowIds[i], View.VISIBLE);
2148 contentView.setTextViewText(rowIds[i], str);
2149 }
2150 i++;
2151 }
2152
Chris Wren683ab002012-09-20 10:35:54 -04002153 contentView.setViewVisibility(R.id.inbox_end_pad,
2154 mTexts.size() > 0 ? View.VISIBLE : View.GONE);
2155
2156 contentView.setViewVisibility(R.id.inbox_more,
2157 mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE);
Chris Wren29bb6d92012-05-17 18:09:42 -04002158
Daniel Sandler879c5e02012-04-17 16:46:51 -04002159 return contentView;
2160 }
2161
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002162 @Override
Daniel Sandler879c5e02012-04-17 16:46:51 -04002163 public Notification build() {
Chris Wrend6297db2012-05-03 16:20:13 -04002164 checkBuilder();
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002165 Notification wip = mBuilder.buildUnstyled();
Daniel Sandler879c5e02012-04-17 16:46:51 -04002166 wip.bigContentView = makeBigContentView();
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002167
Daniel Sandler879c5e02012-04-17 16:46:51 -04002168 return wip;
2169 }
2170 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171}