blob: 1356801db229cfd3a2590995ba468501037bc39e [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.Context;
22import android.content.Intent;
Joe Onoratoef1e7762010-09-17 18:38:38 -040023import android.graphics.Bitmap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.net.Uri;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050025import android.os.Bundle;
Daniel Sandlera0a938c2012-03-15 08:42:37 -040026import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.os.Parcel;
28import android.os.Parcelable;
29import android.text.TextUtils;
Daniel Sandlera0a938c2012-03-15 08:42:37 -040030import android.util.IntProperty;
Joe Onorato8595a3d2010-11-19 18:12:07 -080031import android.view.View;
Jeff Sharkey1c400132011-08-05 14:50:13 -070032import android.widget.ProgressBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.widget.RemoteViews;
34
Andy Stadler110988c2010-12-03 14:29:16 -080035import java.text.NumberFormat;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050036import java.util.ArrayList;
Joe Onorato561d3852010-11-20 18:09:34 -080037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038/**
39 * A class that represents how a persistent notification is to be presented to
40 * the user using the {@link android.app.NotificationManager}.
41 *
Joe Onoratocb109a02011-01-18 17:57:41 -080042 * <p>The {@link Notification.Builder Notification.Builder} has been added to make it
43 * easier to construct Notifications.</p>
44 *
Joe Fernandez558459f2011-10-13 16:47:36 -070045 * <div class="special reference">
46 * <h3>Developer Guides</h3>
47 * <p>For a guide to creating notifications, read the
48 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a>
49 * developer guide.</p>
50 * </div>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 */
52public class Notification implements Parcelable
53{
54 /**
55 * Use all default values (where applicable).
56 */
57 public static final int DEFAULT_ALL = ~0;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 /**
60 * Use the default notification sound. This will ignore any given
61 * {@link #sound}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050062 *
63
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050065 */
66
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 public static final int DEFAULT_SOUND = 1;
68
69 /**
70 * Use the default notification vibrate. This will ignore any given
Daniel Sandler2561b0b2012-02-13 21:04:12 -050071 * {@link #vibrate}. Using phone vibration requires the
Scott Mainb8b36452009-04-26 15:50:49 -070072 * {@link android.Manifest.permission#VIBRATE VIBRATE} permission.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050073 *
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_VIBRATE = 2;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 /**
80 * Use the default notification lights. This will ignore the
81 * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or
82 * {@link #ledOnMS}.
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_LIGHTS = 4;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -050090 * A timestamp related to this notification, in milliseconds since the epoch.
91 *
92 * Default value: {@link System#currentTimeMillis() Now}.
93 *
94 * Choose a timestamp that will be most relevant to the user. For most finite events, this
95 * corresponds to the time the event happened (or will happen, in the case of events that have
96 * yet to occur but about which the user is being informed). Indefinite events should be
97 * timestamped according to when the activity began.
98 *
99 * Some examples:
100 *
101 * <ul>
102 * <li>Notification of a new chat message should be stamped when the message was received.</li>
103 * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li>
104 * <li>Notification of a completed file download should be stamped when the download finished.</li>
105 * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li>
106 * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
107 * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time.
108 * </ul>
109 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 */
111 public long when;
112
113 /**
114 * The resource id of a drawable to use as the icon in the status bar.
Daniel Sandlerd952dae2011-02-07 16:33:36 -0500115 * This is required; notifications with an invalid icon resource will not be shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 */
117 public int icon;
118
119 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800120 * If the icon in the status bar is to have more than one level, you can set this. Otherwise,
121 * leave it at its default value of 0.
122 *
123 * @see android.widget.ImageView#setImageLevel
124 * @see android.graphics.drawable#setLevel
125 */
126 public int iconLevel;
127
128 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500129 * The number of events that this notification represents. For example, in a new mail
130 * notification, this could be the number of unread messages.
131 *
132 * The system may or may not use this field to modify the appearance of the notification. For
133 * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was
134 * superimposed over the icon in the status bar. Starting with
135 * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by
136 * {@link Notification.Builder} has displayed the number in the expanded notification view.
137 *
138 * If the number is 0 or negative, it is never shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 */
140 public int number;
141
142 /**
143 * The intent to execute when the expanded status entry is clicked. If
144 * this is an activity, it must include the
145 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -0800146 * that you take care of task management as described in the
147 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
Dianne Hackborn6ceca582012-01-10 15:24:26 -0800148 * Stack</a> document. In particular, make sure to read the notification section
149 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling
150 * Notifications</a> for the correct ways to launch an application from a
151 * notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 */
153 public PendingIntent contentIntent;
154
155 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500156 * The intent to execute when the notification is explicitly dismissed by the user, either with
157 * the "Clear All" button or by swiping it away individually.
158 *
159 * This probably shouldn't be launching an activity since several of those will be sent
160 * at the same time.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 */
162 public PendingIntent deleteIntent;
163
164 /**
Dianne Hackborn170bae72010-09-03 15:14:28 -0700165 * An intent to launch instead of posting the notification to the status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -0800166 *
167 * @see Notification.Builder#setFullScreenIntent
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400168 */
169 public PendingIntent fullScreenIntent;
170
171 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 * Text to scroll across the screen when this item is added to
Joe Onoratoef1e7762010-09-17 18:38:38 -0400173 * the status bar on large and smaller devices.
174 *
Joe Onorato46439ce2010-11-19 13:56:21 -0800175 * @see #tickerView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 */
177 public CharSequence tickerText;
178
179 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800180 * The view to show as the ticker in the status bar when the notification
181 * is posted.
Joe Onoratoef1e7762010-09-17 18:38:38 -0400182 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800183 public RemoteViews tickerView;
Joe Onoratoef1e7762010-09-17 18:38:38 -0400184
185 /**
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400186 * The view that will represent this notification in the expanded status bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 */
188 public RemoteViews contentView;
189
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400190 /**
191 * The view that will represent this notification in the pop-up "intruder alert" dialog.
192 * @hide
193 */
194 public RemoteViews intruderView;
195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 /**
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400197 * A larger version of {@link #contentView}, giving the Notification an
198 * opportunity to show more detail. The system UI may choose to show this
199 * instead of the normal content view at its discretion.
200 * @hide
201 */
202 public RemoteViews bigContentView;
203
204 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800205 * The bitmap that may escape the bounds of the panel and bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800207 public Bitmap largeIcon;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208
209 /**
210 * The sound to play.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500211 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 * <p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500213 * To play the default notification sound, see {@link #defaults}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 * </p>
215 */
216 public Uri sound;
217
218 /**
219 * Use this constant as the value for audioStreamType to request that
220 * the default stream type for notifications be used. Currently the
221 * default stream type is STREAM_RING.
222 */
223 public static final int STREAM_DEFAULT = -1;
224
225 /**
226 * The audio stream type to use when playing the sound.
227 * Should be one of the STREAM_ constants from
228 * {@link android.media.AudioManager}.
229 */
230 public int audioStreamType = STREAM_DEFAULT;
231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500233 * The pattern with which to vibrate.
234 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 * <p>
236 * To vibrate the default pattern, see {@link #defaults}.
237 * </p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500238 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 * @see android.os.Vibrator#vibrate(long[],int)
240 */
241 public long[] vibrate;
242
243 /**
244 * The color of the led. The hardware will do its best approximation.
245 *
246 * @see #FLAG_SHOW_LIGHTS
247 * @see #flags
248 */
249 public int ledARGB;
250
251 /**
252 * The number of milliseconds for the LED to be on while it's flashing.
253 * The hardware will do its best approximation.
254 *
255 * @see #FLAG_SHOW_LIGHTS
256 * @see #flags
257 */
258 public int ledOnMS;
259
260 /**
261 * The number of milliseconds for the LED to be off while it's flashing.
262 * The hardware will do its best approximation.
263 *
264 * @see #FLAG_SHOW_LIGHTS
265 * @see #flags
266 */
267 public int ledOffMS;
268
269 /**
270 * Specifies which values should be taken from the defaults.
271 * <p>
272 * To set, OR the desired from {@link #DEFAULT_SOUND},
273 * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default
274 * values, use {@link #DEFAULT_ALL}.
275 * </p>
276 */
277 public int defaults;
278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 /**
280 * Bit to be bitwise-ored into the {@link #flags} field that should be
281 * set if you want the LED on for this notification.
282 * <ul>
283 * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB
284 * or 0 for both ledOnMS and ledOffMS.</li>
285 * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li>
286 * <li>To flash the LED, pass the number of milliseconds that it should
287 * be on and off to ledOnMS and ledOffMS.</li>
288 * </ul>
289 * <p>
290 * Since hardware varies, you are not guaranteed that any of the values
291 * you pass are honored exactly. Use the system defaults (TODO) if possible
292 * because they will be set to values that work on any given hardware.
293 * <p>
294 * The alpha channel must be set for forward compatibility.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500295 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 */
297 public static final int FLAG_SHOW_LIGHTS = 0x00000001;
298
299 /**
300 * Bit to be bitwise-ored into the {@link #flags} field that should be
301 * set if this notification is in reference to something that is ongoing,
302 * like a phone call. It should not be set if this notification is in
303 * reference to something that happened at a particular point in time,
304 * like a missed phone call.
305 */
306 public static final int FLAG_ONGOING_EVENT = 0x00000002;
307
308 /**
309 * Bit to be bitwise-ored into the {@link #flags} field that if set,
Scott Mainb8b36452009-04-26 15:50:49 -0700310 * the audio will be repeated until the notification is
311 * cancelled or the notification window is opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 */
313 public static final int FLAG_INSISTENT = 0x00000004;
314
315 /**
316 * Bit to be bitwise-ored into the {@link #flags} field that should be
317 * set if you want the sound and/or vibration play each time the
318 * notification is sent, even if it has not been canceled before that.
319 */
320 public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008;
321
322 /**
323 * Bit to be bitwise-ored into the {@link #flags} field that should be
324 * set if the notification should be canceled when it is clicked by the
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500325 * user. On tablets, the
326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 */
328 public static final int FLAG_AUTO_CANCEL = 0x00000010;
329
330 /**
331 * Bit to be bitwise-ored into the {@link #flags} field that should be
332 * set if the notification should not be canceled when the user clicks
333 * the Clear all button.
334 */
335 public static final int FLAG_NO_CLEAR = 0x00000020;
336
Dianne Hackbornd8a43f62009-08-17 23:33:56 -0700337 /**
338 * Bit to be bitwise-ored into the {@link #flags} field that should be
339 * set if this notification represents a currently running service. This
340 * will normally be set for you by {@link Service#startForeground}.
341 */
342 public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;
343
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400344 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500345 * Obsolete flag indicating high-priority notifications; use the priority field instead.
346 *
347 * @deprecated Use {@link #priority} with a positive value.
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400348 */
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500349 public static final int FLAG_HIGH_PRIORITY = 0x00000080;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 public int flags;
352
353 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500354 * Default notification {@link #priority}. If your application does not prioritize its own
355 * notifications, use this value for all notifications.
356 */
357 public static final int PRIORITY_DEFAULT = 0;
358
359 /**
360 * Lower {@link #priority}, for items that are less important. The UI may choose to show these
361 * items smaller, or at a different position in the list, compared with your app's
362 * {@link #PRIORITY_DEFAULT} items.
363 */
364 public static final int PRIORITY_LOW = -1;
365
366 /**
367 * Lowest {@link #priority}; these items might not be shown to the user except under special
368 * circumstances, such as detailed notification logs.
369 */
370 public static final int PRIORITY_MIN = -2;
371
372 /**
373 * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to
374 * show these items larger, or at a different position in notification lists, compared with
375 * your app's {@link #PRIORITY_DEFAULT} items.
376 */
377 public static final int PRIORITY_HIGH = 1;
378
379 /**
380 * Highest {@link #priority}, for your application's most important items that require the
381 * user's prompt attention or input.
382 */
383 public static final int PRIORITY_MAX = 2;
384
385 /**
386 * Relative priority for this notification.
387 *
388 * Priority is an indication of how much of the user's valuable attention should be consumed by
389 * this notification. Low-priority notifications may be hidden from the user in certain
390 * situations, while the user might be interrupted for a higher-priority notification. The
391 * system will make a determination about how to interpret notification priority as described in
392 * MUMBLE MUMBLE.
393 */
394 public int priority;
395
396 /**
397 * Notification type: incoming call (voice or video) or similar synchronous communication request.
398 */
399 public static final String KIND_CALL = "android.call";
400
401 /**
402 * Notification type: incoming direct message (SMS, instant message, etc.).
403 */
404 public static final String KIND_MESSAGE = "android.message";
405
406 /**
407 * Notification type: asynchronous bulk message (email).
408 */
409 public static final String KIND_EMAIL = "android.email";
410
411 /**
412 * Notification type: calendar event.
413 */
414 public static final String KIND_EVENT = "android.event";
415
416 /**
417 * Notification type: promotion or advertisement.
418 */
419 public static final String KIND_PROMO = "android.promo";
420
421 /**
422 * If this notification matches of one or more special types (see the <code>KIND_*</code>
423 * constants), add them here, best match first.
424 */
425 public String[] kind;
426
427 /**
428 * Extra key for people values (type TBD).
429 *
430 * @hide
431 */
432 public static final String EXTRA_PEOPLE = "android.people";
433
434 private Bundle extras;
435
436 /**
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400437 * Structure to encapsulate an "action", including title and icon, that can be attached to a Notification.
438 * @hide
439 */
440 private static class Action implements Parcelable {
441 public int icon;
442 public CharSequence title;
443 public PendingIntent actionIntent;
444 @SuppressWarnings("unused")
445 public Action() { }
446 private Action(Parcel in) {
447 icon = in.readInt();
448 title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
449 if (in.readInt() == 1) {
450 actionIntent = PendingIntent.CREATOR.createFromParcel(in);
451 }
452 }
453 public Action(int icon_, CharSequence title_, PendingIntent intent_) {
454 this.icon = icon_;
455 this.title = title_;
456 this.actionIntent = intent_;
457 }
458 @Override
459 public Action clone() {
460 return new Action(
461 this.icon,
462 this.title.toString(),
463 this.actionIntent // safe to alias
464 );
465 }
466 @Override
467 public int describeContents() {
468 return 0;
469 }
470 @Override
471 public void writeToParcel(Parcel out, int flags) {
472 out.writeInt(icon);
473 TextUtils.writeToParcel(title, out, flags);
474 if (actionIntent != null) {
475 out.writeInt(1);
476 actionIntent.writeToParcel(out, flags);
477 } else {
478 out.writeInt(0);
479 }
480 }
481 public static final Parcelable.Creator<Action> CREATOR
482 = new Parcelable.Creator<Action>() {
483 public Action createFromParcel(Parcel in) {
484 return new Action(in);
485 }
486 public Action[] newArray(int size) {
487 return new Action[size];
488 }
489 };
490 }
491
492 private Action[] actions;
493
494 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500495 * Constructs a Notification object with default values.
Joe Onorato46439ce2010-11-19 13:56:21 -0800496 * You might want to consider using {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 */
498 public Notification()
499 {
500 this.when = System.currentTimeMillis();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500501 this.priority = PRIORITY_DEFAULT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 }
503
504 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 * @hide
506 */
507 public Notification(Context context, int icon, CharSequence tickerText, long when,
508 CharSequence contentTitle, CharSequence contentText, Intent contentIntent)
509 {
510 this.when = when;
511 this.icon = icon;
512 this.tickerText = tickerText;
513 setLatestEventInfo(context, contentTitle, contentText,
514 PendingIntent.getActivity(context, 0, contentIntent, 0));
515 }
516
517 /**
518 * Constructs a Notification object with the information needed to
519 * have a status bar icon without the standard expanded view.
520 *
521 * @param icon The resource id of the icon to put in the status bar.
522 * @param tickerText The text that flows by in the status bar when the notification first
523 * activates.
524 * @param when The time to show in the time field. In the System.currentTimeMillis
525 * timebase.
Joe Onorato46439ce2010-11-19 13:56:21 -0800526 *
527 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800529 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 public Notification(int icon, CharSequence tickerText, long when)
531 {
532 this.icon = icon;
533 this.tickerText = tickerText;
534 this.when = when;
535 }
536
537 /**
538 * Unflatten the notification from a parcel.
539 */
540 public Notification(Parcel parcel)
541 {
542 int version = parcel.readInt();
543
544 when = parcel.readLong();
545 icon = parcel.readInt();
546 number = parcel.readInt();
547 if (parcel.readInt() != 0) {
548 contentIntent = PendingIntent.CREATOR.createFromParcel(parcel);
549 }
550 if (parcel.readInt() != 0) {
551 deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel);
552 }
553 if (parcel.readInt() != 0) {
554 tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
555 }
556 if (parcel.readInt() != 0) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800557 tickerView = RemoteViews.CREATOR.createFromParcel(parcel);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400558 }
559 if (parcel.readInt() != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 contentView = RemoteViews.CREATOR.createFromParcel(parcel);
561 }
Joe Onorato561d3852010-11-20 18:09:34 -0800562 if (parcel.readInt() != 0) {
563 largeIcon = Bitmap.CREATOR.createFromParcel(parcel);
564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 defaults = parcel.readInt();
566 flags = parcel.readInt();
567 if (parcel.readInt() != 0) {
568 sound = Uri.CREATOR.createFromParcel(parcel);
569 }
570
571 audioStreamType = parcel.readInt();
572 vibrate = parcel.createLongArray();
573 ledARGB = parcel.readInt();
574 ledOnMS = parcel.readInt();
575 ledOffMS = parcel.readInt();
576 iconLevel = parcel.readInt();
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400577
578 if (parcel.readInt() != 0) {
579 fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel);
580 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500581
582 priority = parcel.readInt();
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400583
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500584 kind = parcel.createStringArray(); // may set kind to null
585
586 if (parcel.readInt() != 0) {
587 extras = parcel.readBundle();
588 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400589
590 actions = parcel.createTypedArray(Action.CREATOR);
591 if (parcel.readInt() != 0) {
592 intruderView = RemoteViews.CREATOR.createFromParcel(parcel);
593 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400594 if (parcel.readInt() != 0) {
595 bigContentView = RemoteViews.CREATOR.createFromParcel(parcel);
596 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 }
598
Andy Stadler110988c2010-12-03 14:29:16 -0800599 @Override
Joe Onorato18e69df2010-05-17 22:26:12 -0700600 public Notification clone() {
601 Notification that = new Notification();
602
603 that.when = this.when;
604 that.icon = this.icon;
605 that.number = this.number;
606
607 // PendingIntents are global, so there's no reason (or way) to clone them.
608 that.contentIntent = this.contentIntent;
609 that.deleteIntent = this.deleteIntent;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400610 that.fullScreenIntent = this.fullScreenIntent;
Joe Onorato18e69df2010-05-17 22:26:12 -0700611
612 if (this.tickerText != null) {
613 that.tickerText = this.tickerText.toString();
614 }
Joe Onorato46439ce2010-11-19 13:56:21 -0800615 if (this.tickerView != null) {
616 that.tickerView = this.tickerView.clone();
Joe Onoratoef1e7762010-09-17 18:38:38 -0400617 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700618 if (this.contentView != null) {
619 that.contentView = this.contentView.clone();
620 }
Joe Onorato561d3852010-11-20 18:09:34 -0800621 if (this.largeIcon != null) {
622 that.largeIcon = Bitmap.createBitmap(this.largeIcon);
623 }
Jozef BABJAKa8b91832011-02-22 08:05:08 +0100624 that.iconLevel = this.iconLevel;
Joe Onorato18e69df2010-05-17 22:26:12 -0700625 that.sound = this.sound; // android.net.Uri is immutable
626 that.audioStreamType = this.audioStreamType;
627
628 final long[] vibrate = this.vibrate;
629 if (vibrate != null) {
630 final int N = vibrate.length;
631 final long[] vib = that.vibrate = new long[N];
632 System.arraycopy(vibrate, 0, vib, 0, N);
633 }
634
635 that.ledARGB = this.ledARGB;
636 that.ledOnMS = this.ledOnMS;
637 that.ledOffMS = this.ledOffMS;
638 that.defaults = this.defaults;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500639
Joe Onorato18e69df2010-05-17 22:26:12 -0700640 that.flags = this.flags;
641
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500642 that.priority = this.priority;
643
644 final String[] thiskind = this.kind;
645 if (thiskind != null) {
646 final int N = thiskind.length;
647 final String[] thatkind = that.kind = new String[N];
648 System.arraycopy(thiskind, 0, thatkind, 0, N);
649 }
650
651 if (this.extras != null) {
652 that.extras = new Bundle(this.extras);
653
654 }
655
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400656 that.actions = new Action[this.actions.length];
657 for(int i=0; i<this.actions.length; i++) {
658 that.actions[i] = this.actions[i].clone();
659 }
660 if (this.intruderView != null) {
661 that.intruderView = this.intruderView.clone();
662 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400663 if (this.bigContentView != null) {
664 that.bigContentView = this.bigContentView.clone();
665 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400666
Joe Onorato18e69df2010-05-17 22:26:12 -0700667 return that;
668 }
669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 public int describeContents() {
671 return 0;
672 }
673
674 /**
675 * Flatten this notification from a parcel.
676 */
677 public void writeToParcel(Parcel parcel, int flags)
678 {
679 parcel.writeInt(1);
680
681 parcel.writeLong(when);
682 parcel.writeInt(icon);
683 parcel.writeInt(number);
684 if (contentIntent != null) {
685 parcel.writeInt(1);
686 contentIntent.writeToParcel(parcel, 0);
687 } else {
688 parcel.writeInt(0);
689 }
690 if (deleteIntent != null) {
691 parcel.writeInt(1);
692 deleteIntent.writeToParcel(parcel, 0);
693 } else {
694 parcel.writeInt(0);
695 }
696 if (tickerText != null) {
697 parcel.writeInt(1);
698 TextUtils.writeToParcel(tickerText, parcel, flags);
699 } else {
700 parcel.writeInt(0);
701 }
Joe Onorato46439ce2010-11-19 13:56:21 -0800702 if (tickerView != null) {
Joe Onoratoef1e7762010-09-17 18:38:38 -0400703 parcel.writeInt(1);
Joe Onorato46439ce2010-11-19 13:56:21 -0800704 tickerView.writeToParcel(parcel, 0);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400705 } else {
706 parcel.writeInt(0);
707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 if (contentView != null) {
709 parcel.writeInt(1);
710 contentView.writeToParcel(parcel, 0);
711 } else {
712 parcel.writeInt(0);
713 }
Joe Onorato561d3852010-11-20 18:09:34 -0800714 if (largeIcon != null) {
715 parcel.writeInt(1);
716 largeIcon.writeToParcel(parcel, 0);
717 } else {
718 parcel.writeInt(0);
719 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720
721 parcel.writeInt(defaults);
722 parcel.writeInt(this.flags);
723
724 if (sound != null) {
725 parcel.writeInt(1);
726 sound.writeToParcel(parcel, 0);
727 } else {
728 parcel.writeInt(0);
729 }
730 parcel.writeInt(audioStreamType);
731 parcel.writeLongArray(vibrate);
732 parcel.writeInt(ledARGB);
733 parcel.writeInt(ledOnMS);
734 parcel.writeInt(ledOffMS);
735 parcel.writeInt(iconLevel);
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400736
737 if (fullScreenIntent != null) {
738 parcel.writeInt(1);
739 fullScreenIntent.writeToParcel(parcel, 0);
740 } else {
741 parcel.writeInt(0);
742 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500743
744 parcel.writeInt(priority);
745
746 parcel.writeStringArray(kind); // ok for null
747
748 if (extras != null) {
749 parcel.writeInt(1);
750 extras.writeToParcel(parcel, 0);
751 } else {
752 parcel.writeInt(0);
753 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400754
755 parcel.writeTypedArray(actions, 0);
756
757 if (intruderView != null) {
758 parcel.writeInt(1);
759 intruderView.writeToParcel(parcel, 0);
760 } else {
761 parcel.writeInt(0);
762 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400763
764 if (bigContentView != null) {
765 parcel.writeInt(1);
766 bigContentView.writeToParcel(parcel, 0);
767 } else {
768 parcel.writeInt(0);
769 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 }
771
772 /**
773 * Parcelable.Creator that instantiates Notification objects
774 */
775 public static final Parcelable.Creator<Notification> CREATOR
776 = new Parcelable.Creator<Notification>()
777 {
778 public Notification createFromParcel(Parcel parcel)
779 {
780 return new Notification(parcel);
781 }
782
783 public Notification[] newArray(int size)
784 {
785 return new Notification[size];
786 }
787 };
788
789 /**
790 * Sets the {@link #contentView} field to be a view with the standard "Latest Event"
791 * layout.
792 *
793 * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields
794 * in the view.</p>
795 * @param context The context for your application / activity.
796 * @param contentTitle The title that goes in the expanded entry.
797 * @param contentText The text that goes in the expanded entry.
798 * @param contentIntent The intent to launch when the user clicks the expanded notification.
799 * If this is an activity, it must include the
800 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -0800801 * that you take care of task management as described in the
802 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
803 * Stack</a> document.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500804 *
Joe Onorato46439ce2010-11-19 13:56:21 -0800805 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800807 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 public void setLatestEventInfo(Context context,
809 CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) {
810 RemoteViews contentView = new RemoteViews(context.getPackageName(),
Joe Onorato561d3852010-11-20 18:09:34 -0800811 R.layout.status_bar_latest_event_content);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 if (this.icon != 0) {
Joe Onorato561d3852010-11-20 18:09:34 -0800813 contentView.setImageViewResource(R.id.icon, this.icon);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 }
815 if (contentTitle != null) {
Joe Onorato561d3852010-11-20 18:09:34 -0800816 contentView.setTextViewText(R.id.title, contentTitle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 }
818 if (contentText != null) {
Joe Onorato561d3852010-11-20 18:09:34 -0800819 contentView.setTextViewText(R.id.text, contentText);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 }
821 if (this.when != 0) {
Joe Onorato561d3852010-11-20 18:09:34 -0800822 contentView.setLong(R.id.time, "setTime", when);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 }
824
825 this.contentView = contentView;
826 this.contentIntent = contentIntent;
827 }
828
829 @Override
830 public String toString() {
831 StringBuilder sb = new StringBuilder();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500832 sb.append("Notification(pri=");
833 sb.append(priority);
834 sb.append(" contentView=");
Joe Onoratoc9596d62011-01-12 17:03:11 -0800835 if (contentView != null) {
836 sb.append(contentView.getPackage());
837 sb.append("/0x");
838 sb.append(Integer.toHexString(contentView.getLayoutId()));
839 } else {
840 sb.append("null");
841 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500842 // TODO(dsandler): defaults take precedence over local values, so reorder the branches below
Joe Onoratoc9596d62011-01-12 17:03:11 -0800843 sb.append(" vibrate=");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 if (this.vibrate != null) {
845 int N = this.vibrate.length-1;
846 sb.append("[");
847 for (int i=0; i<N; i++) {
848 sb.append(this.vibrate[i]);
849 sb.append(',');
850 }
Simon Schoar8cf97d92009-06-10 22:08:37 +0200851 if (N != -1) {
852 sb.append(this.vibrate[N]);
853 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 sb.append("]");
855 } else if ((this.defaults & DEFAULT_VIBRATE) != 0) {
856 sb.append("default");
857 } else {
858 sb.append("null");
859 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500860 sb.append(" sound=");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 if (this.sound != null) {
862 sb.append(this.sound.toString());
863 } else if ((this.defaults & DEFAULT_SOUND) != 0) {
864 sb.append("default");
865 } else {
866 sb.append("null");
867 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500868 sb.append(" defaults=0x");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 sb.append(Integer.toHexString(this.defaults));
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500870 sb.append(" flags=0x");
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400871 sb.append(Integer.toHexString(this.flags));
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500872 sb.append(" kind=[");
873 if (this.kind == null) {
874 sb.append("null");
875 } else {
876 for (int i=0; i<this.kind.length; i++) {
877 if (i>0) sb.append(",");
878 sb.append(this.kind[i]);
879 }
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400880 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400881 sb.append("]");
882 if (actions != null) {
883 sb.append(" ");
884 sb.append(actions.length);
885 sb.append(" action");
886 if (actions.length > 1) sb.append("s");
887 }
888 sb.append(")");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 return sb.toString();
890 }
Joe Onorato46439ce2010-11-19 13:56:21 -0800891
Joe Onoratocb109a02011-01-18 17:57:41 -0800892 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500893 * Builder class for {@link Notification} objects.
894 *
895 * Provides a convenient way to set the various fields of a {@link Notification} and generate
896 * content views using the platform's notification layout template.
897 *
898 * Example:
899 *
900 * <pre class="prettyprint">
901 * Notification noti = new Notification.Builder()
902 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
903 * .setContentText(subject)
904 * .setSmallIcon(R.drawable.new_mail)
905 * .setLargeIcon(aBitmap)
906 * .getNotification();
907 * </pre>
Joe Onoratocb109a02011-01-18 17:57:41 -0800908 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800909 public static class Builder {
910 private Context mContext;
911
912 private long mWhen;
913 private int mSmallIcon;
914 private int mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -0800915 private int mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -0800916 private CharSequence mContentTitle;
917 private CharSequence mContentText;
918 private CharSequence mContentInfo;
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400919 private CharSequence mSubText;
Joe Onorato46439ce2010-11-19 13:56:21 -0800920 private PendingIntent mContentIntent;
921 private RemoteViews mContentView;
922 private PendingIntent mDeleteIntent;
923 private PendingIntent mFullScreenIntent;
924 private CharSequence mTickerText;
925 private RemoteViews mTickerView;
926 private Bitmap mLargeIcon;
927 private Uri mSound;
928 private int mAudioStreamType;
929 private long[] mVibrate;
930 private int mLedArgb;
931 private int mLedOnMs;
932 private int mLedOffMs;
933 private int mDefaults;
934 private int mFlags;
Jeff Sharkey1c400132011-08-05 14:50:13 -0700935 private int mProgressMax;
936 private int mProgress;
937 private boolean mProgressIndeterminate;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500938 private ArrayList<String> mKindList = new ArrayList<String>(1);
939 private Bundle mExtras;
940 private int mPriority;
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400941 private ArrayList<Action> mActions = new ArrayList<Action>(3);
Daniel Sandlerb2a1c232012-03-24 10:37:28 -0500942 private boolean mCanHasIntruder;
943 private boolean mIntruderActionsShowText;
Joe Onorato46439ce2010-11-19 13:56:21 -0800944
Joe Onoratocb109a02011-01-18 17:57:41 -0800945 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500946 * Constructs a new Builder with the defaults:
Joe Onoratocb109a02011-01-18 17:57:41 -0800947 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500948
949 * <table>
950 * <tr><th align=right>priority</th>
951 * <td>{@link #PRIORITY_DEFAULT}</td></tr>
952 * <tr><th align=right>when</th>
953 * <td>now ({@link System#currentTimeMillis()})</td></tr>
954 * <tr><th align=right>audio stream</th>
955 * <td>{@link #STREAM_DEFAULT}</td></tr>
956 * </table>
Joe Onoratocb109a02011-01-18 17:57:41 -0800957 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500958
959 * @param context
960 * A {@link Context} that will be used by the Builder to construct the
961 * RemoteViews. The Context will not be held past the lifetime of this Builder
962 * object.
Joe Onoratocb109a02011-01-18 17:57:41 -0800963 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800964 public Builder(Context context) {
965 mContext = context;
Andy Stadler110988c2010-12-03 14:29:16 -0800966
967 // Set defaults to match the defaults of a Notification
Joe Onorato46439ce2010-11-19 13:56:21 -0800968 mWhen = System.currentTimeMillis();
Andy Stadler110988c2010-12-03 14:29:16 -0800969 mAudioStreamType = STREAM_DEFAULT;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500970 mPriority = PRIORITY_DEFAULT;
Joe Onorato46439ce2010-11-19 13:56:21 -0800971 }
972
Joe Onoratocb109a02011-01-18 17:57:41 -0800973 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500974 * Add a timestamp pertaining to the notification (usually the time the event occurred).
975 *
976
977 * @see Notification#when
Joe Onoratocb109a02011-01-18 17:57:41 -0800978 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800979 public Builder setWhen(long when) {
980 mWhen = when;
981 return this;
982 }
983
Joe Onoratocb109a02011-01-18 17:57:41 -0800984 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500985 * Set the small icon resource, which will be used to represent the notification in the
986 * status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -0800987 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500988
989 * The platform template for the expanded view will draw this icon in the left, unless a
990 * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small
991 * icon will be moved to the right-hand side.
992 *
993
994 * @param icon
995 * A resource ID in the application's package of the drawable to use.
996 * @see Notification#icon
Joe Onoratocb109a02011-01-18 17:57:41 -0800997 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800998 public Builder setSmallIcon(int icon) {
999 mSmallIcon = icon;
1000 return this;
1001 }
1002
Joe Onoratocb109a02011-01-18 17:57:41 -08001003 /**
1004 * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional
1005 * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable
1006 * LevelListDrawable}.
1007 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001008 * @param icon A resource ID in the application's package of the drawable to use.
Joe Onoratocb109a02011-01-18 17:57:41 -08001009 * @param level The level to use for the icon.
1010 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001011 * @see Notification#icon
1012 * @see Notification#iconLevel
Joe Onoratocb109a02011-01-18 17:57:41 -08001013 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001014 public Builder setSmallIcon(int icon, int level) {
1015 mSmallIcon = icon;
1016 mSmallIconLevel = level;
1017 return this;
1018 }
1019
Joe Onoratocb109a02011-01-18 17:57:41 -08001020 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001021 * Set the first line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001022 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001023 public Builder setContentTitle(CharSequence title) {
1024 mContentTitle = title;
1025 return this;
1026 }
1027
Joe Onoratocb109a02011-01-18 17:57:41 -08001028 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001029 * Set the second line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001030 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001031 public Builder setContentText(CharSequence text) {
1032 mContentText = text;
1033 return this;
1034 }
1035
Joe Onoratocb109a02011-01-18 17:57:41 -08001036 /**
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001037 * Set the third line of text in the platform notification template.
1038 * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the same location in the standard template.
1039 */
1040 public Builder setSubText(CharSequence text) {
1041 mSubText = text;
1042 return this;
1043 }
1044
1045 /**
Joe Onoratocb109a02011-01-18 17:57:41 -08001046 * Set the large number at the right-hand side of the notification. This is
1047 * equivalent to setContentInfo, although it might show the number in a different
1048 * font size for readability.
1049 */
Joe Onorato8595a3d2010-11-19 18:12:07 -08001050 public Builder setNumber(int number) {
1051 mNumber = number;
1052 return this;
1053 }
1054
Joe Onoratocb109a02011-01-18 17:57:41 -08001055 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001056 * A small piece of additional information pertaining to this notification.
1057 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001058 * The platform template will draw this on the last line of the notification, at the far
1059 * right (to the right of a smallIcon if it has been placed there).
Joe Onoratocb109a02011-01-18 17:57:41 -08001060 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001061 public Builder setContentInfo(CharSequence info) {
1062 mContentInfo = info;
1063 return this;
1064 }
1065
Joe Onoratocb109a02011-01-18 17:57:41 -08001066 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001067 * Set the progress this notification represents.
1068 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001069 * The platform template will represent this using a {@link ProgressBar}.
Jeff Sharkey1c400132011-08-05 14:50:13 -07001070 */
1071 public Builder setProgress(int max, int progress, boolean indeterminate) {
1072 mProgressMax = max;
1073 mProgress = progress;
1074 mProgressIndeterminate = indeterminate;
1075 return this;
1076 }
1077
1078 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001079 * Supply a custom RemoteViews to use instead of the platform template.
1080 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001081 * @see Notification#contentView
Joe Onoratocb109a02011-01-18 17:57:41 -08001082 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001083 public Builder setContent(RemoteViews views) {
1084 mContentView = views;
1085 return this;
1086 }
1087
Joe Onoratocb109a02011-01-18 17:57:41 -08001088 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001089 * Supply a {@link PendingIntent} to be sent when the notification is clicked.
1090 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001091 * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you
1092 * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use
1093 * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)}
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001094 * to assign PendingIntents to individual views in that custom layout (i.e., to create
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001095 * clickable buttons inside the notification view).
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001096 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001097 * @see Notification#contentIntent Notification.contentIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001098 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001099 public Builder setContentIntent(PendingIntent intent) {
1100 mContentIntent = intent;
1101 return this;
1102 }
1103
Joe Onoratocb109a02011-01-18 17:57:41 -08001104 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001105 * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user.
1106 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001107 * @see Notification#deleteIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001108 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001109 public Builder setDeleteIntent(PendingIntent intent) {
1110 mDeleteIntent = intent;
1111 return this;
1112 }
1113
Joe Onoratocb109a02011-01-18 17:57:41 -08001114 /**
1115 * An intent to launch instead of posting the notification to the status bar.
1116 * Only for use with extremely high-priority notifications demanding the user's
1117 * <strong>immediate</strong> attention, such as an incoming phone call or
1118 * alarm clock that the user has explicitly set to a particular time.
1119 * If this facility is used for something else, please give the user an option
1120 * to turn it off and use a normal notification, as this can be extremely
1121 * disruptive.
1122 *
1123 * @param intent The pending intent to launch.
1124 * @param highPriority Passing true will cause this notification to be sent
1125 * even if other notifications are suppressed.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001126 *
1127 * @see Notification#fullScreenIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001128 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001129 public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
1130 mFullScreenIntent = intent;
1131 setFlag(FLAG_HIGH_PRIORITY, highPriority);
1132 return this;
1133 }
1134
Joe Onoratocb109a02011-01-18 17:57:41 -08001135 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001136 * Set the "ticker" text which is displayed in the status bar when the notification first
Joe Onoratocb109a02011-01-18 17:57:41 -08001137 * arrives.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001138 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001139 * @see Notification#tickerText
Joe Onoratocb109a02011-01-18 17:57:41 -08001140 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001141 public Builder setTicker(CharSequence tickerText) {
1142 mTickerText = tickerText;
1143 return this;
1144 }
1145
Joe Onoratocb109a02011-01-18 17:57:41 -08001146 /**
1147 * Set the text that is displayed in the status bar when the notification first
1148 * arrives, and also a RemoteViews object that may be displayed instead on some
1149 * devices.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001150 *
1151 * @see Notification#tickerText
1152 * @see Notification#tickerView
Joe Onoratocb109a02011-01-18 17:57:41 -08001153 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001154 public Builder setTicker(CharSequence tickerText, RemoteViews views) {
1155 mTickerText = tickerText;
1156 mTickerView = views;
1157 return this;
1158 }
1159
Joe Onoratocb109a02011-01-18 17:57:41 -08001160 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001161 * Add a large icon to the notification (and the ticker on some devices).
1162 *
1163 * In the platform template, this image will be shown on the left of the notification view
1164 * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side).
1165 *
1166 * @see Notification#largeIcon
Joe Onoratocb109a02011-01-18 17:57:41 -08001167 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001168 public Builder setLargeIcon(Bitmap icon) {
1169 mLargeIcon = icon;
1170 return this;
1171 }
1172
Joe Onoratocb109a02011-01-18 17:57:41 -08001173 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001174 * Set the sound to play.
1175 *
1176 * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications.
1177 *
1178 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001179 */
Joe Onorato52f80cd2010-11-21 15:34:48 -08001180 public Builder setSound(Uri sound) {
1181 mSound = sound;
1182 mAudioStreamType = STREAM_DEFAULT;
1183 return this;
1184 }
1185
Joe Onoratocb109a02011-01-18 17:57:41 -08001186 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001187 * Set the sound to play, along with a specific stream on which to play it.
Joe Onoratocb109a02011-01-18 17:57:41 -08001188 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001189 * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants.
1190 *
1191 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001192 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001193 public Builder setSound(Uri sound, int streamType) {
1194 mSound = sound;
1195 mAudioStreamType = streamType;
1196 return this;
1197 }
1198
Joe Onoratocb109a02011-01-18 17:57:41 -08001199 /**
1200 * Set the vibration pattern to use.
1201 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001202
1203 * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the
1204 * <code>pattern</code> parameter.
1205 *
1206
1207 * @see Notification#vibrate
Joe Onoratocb109a02011-01-18 17:57:41 -08001208 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001209 public Builder setVibrate(long[] pattern) {
1210 mVibrate = pattern;
1211 return this;
1212 }
1213
Joe Onoratocb109a02011-01-18 17:57:41 -08001214 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001215 * Set the desired color for the indicator LED on the device, as well as the
1216 * blink duty cycle (specified in milliseconds).
1217 *
1218
1219 * Not all devices will honor all (or even any) of these values.
1220 *
1221
1222 * @see Notification#ledARGB
1223 * @see Notification#ledOnMS
1224 * @see Notification#ledOffMS
Joe Onoratocb109a02011-01-18 17:57:41 -08001225 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001226 public Builder setLights(int argb, int onMs, int offMs) {
1227 mLedArgb = argb;
1228 mLedOnMs = onMs;
1229 mLedOffMs = offMs;
Joe Onorato46439ce2010-11-19 13:56:21 -08001230 return this;
1231 }
1232
Joe Onoratocb109a02011-01-18 17:57:41 -08001233 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001234 * Set whether this is an "ongoing" notification.
Joe Onoratocb109a02011-01-18 17:57:41 -08001235 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001236
1237 * Ongoing notifications cannot be dismissed by the user, so your application or service
1238 * must take care of canceling them.
1239 *
1240
1241 * They are typically used to indicate a background task that the user is actively engaged
1242 * with (e.g., playing music) or is pending in some way and therefore occupying the device
1243 * (e.g., a file download, sync operation, active network connection).
1244 *
1245
1246 * @see Notification#FLAG_ONGOING_EVENT
1247 * @see Service#setForeground(boolean)
Joe Onoratocb109a02011-01-18 17:57:41 -08001248 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001249 public Builder setOngoing(boolean ongoing) {
1250 setFlag(FLAG_ONGOING_EVENT, ongoing);
1251 return this;
1252 }
1253
Joe Onoratocb109a02011-01-18 17:57:41 -08001254 /**
1255 * Set this flag if you would only like the sound, vibrate
1256 * and ticker to be played if the notification is not already showing.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001257 *
1258 * @see Notification#FLAG_ONLY_ALERT_ONCE
Joe Onoratocb109a02011-01-18 17:57:41 -08001259 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001260 public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
1261 setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
1262 return this;
1263 }
1264
Joe Onoratocb109a02011-01-18 17:57:41 -08001265 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001266 * Make this notification automatically dismissed when the user touches it. The
1267 * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens.
1268 *
1269 * @see Notification#FLAG_AUTO_CANCEL
Joe Onoratocb109a02011-01-18 17:57:41 -08001270 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001271 public Builder setAutoCancel(boolean autoCancel) {
Joe Onorato281d83f2011-01-04 17:13:10 -08001272 setFlag(FLAG_AUTO_CANCEL, autoCancel);
Joe Onorato46439ce2010-11-19 13:56:21 -08001273 return this;
1274 }
1275
Joe Onoratocb109a02011-01-18 17:57:41 -08001276 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001277 * Set which notification properties will be inherited from system defaults.
Joe Onoratocb109a02011-01-18 17:57:41 -08001278 * <p>
1279 * The value should be one or more of the following fields combined with
1280 * bitwise-or:
1281 * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}.
1282 * <p>
1283 * For all default values, use {@link #DEFAULT_ALL}.
1284 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001285 public Builder setDefaults(int defaults) {
1286 mDefaults = defaults;
1287 return this;
1288 }
1289
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001290 /**
1291 * Set the priority of this notification.
1292 *
1293 * @see Notification#priority
1294 */
1295 public Builder setPriority(int pri) {
1296 mPriority = pri;
1297 return this;
1298 }
1299
1300 /**
1301 * Add a kind (category) to this notification. Optional.
1302 *
1303 * @see Notification#kind
1304 */
1305 public Builder addKind(String k) {
1306 mKindList.add(k);
1307 return this;
1308 }
1309
1310 /**
1311 * Add metadata to this notification.
1312 *
1313 * A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's
1314 * current contents are copied into the Notification each time {@link #getNotification()} is
1315 * called.
1316 *
1317 * @see Notification#extras
1318 * @hide
1319 */
1320 public Builder setExtras(Bundle bag) {
1321 mExtras = bag;
1322 return this;
1323 }
1324
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001325 /**
1326 * Add an action to this notification. Actions are typically displayed by
1327 * the system as a button adjacent to the notification content.
1328 *
1329 * @param icon Resource ID of a drawable that represents the action.
1330 * @param title Text describing the action.
1331 * @param intent PendingIntent to be fired when the action is invoked.
1332 */
1333 public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
1334 mActions.add(new Action(icon, title, intent));
1335 return this;
1336 }
1337
Daniel Sandlerb2a1c232012-03-24 10:37:28 -05001338 /**
1339 * Specify whether this notification should pop up as an
1340 * "intruder alert" (a small window that shares the screen with the
1341 * current activity). This sort of notification is (as the name implies)
1342 * very intrusive, so use it sparingly for notifications that require
1343 * the user's attention.
1344 *
1345 * Notes:
1346 * <ul>
1347 * <li>Intruder alerts only show when the screen is on.</li>
1348 * <li>Intruder alerts take precedence over fullScreenIntents.</li>
1349 * </ul>
1350 *
1351 * @param intrude Whether to pop up an intruder alert (default false).
1352 */
1353 public Builder setUsesIntruderAlert(boolean intrude) {
1354 mCanHasIntruder = intrude;
1355 return this;
1356 }
1357
1358 /**
1359 * Control text on intruder alert action buttons. By default, action
1360 * buttons in intruders do not show textual labels.
1361 *
1362 * @param showActionText Whether to show text labels beneath action
1363 * icons (default false).
1364 */
1365 public Builder setIntruderActionsShowText(boolean showActionText) {
1366 mIntruderActionsShowText = showActionText;
1367 return this;
1368 }
1369
Joe Onorato46439ce2010-11-19 13:56:21 -08001370 private void setFlag(int mask, boolean value) {
1371 if (value) {
1372 mFlags |= mask;
1373 } else {
1374 mFlags &= ~mask;
1375 }
1376 }
1377
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001378 private RemoteViews applyStandardTemplate(int resId) {
Joe Onorato561d3852010-11-20 18:09:34 -08001379 RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001380 boolean hasLine3 = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001381 boolean hasLine2 = false;
1382 int smallIconImageViewId = R.id.icon;
1383 if (mLargeIcon != null) {
1384 contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
1385 smallIconImageViewId = R.id.right_icon;
1386 }
Joe Onorato561d3852010-11-20 18:09:34 -08001387 if (mSmallIcon != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001388 contentView.setImageViewResource(smallIconImageViewId, mSmallIcon);
1389 contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001390 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001391 contentView.setViewVisibility(smallIconImageViewId, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001392 }
1393 if (mContentTitle != null) {
1394 contentView.setTextViewText(R.id.title, mContentTitle);
1395 }
1396 if (mContentText != null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001397 contentView.setTextViewText(
1398 (mSubText != null) ? R.id.text2 : R.id.text,
1399 mContentText);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001400 hasLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001401 }
1402 if (mContentInfo != null) {
1403 contentView.setTextViewText(R.id.info, mContentInfo);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001404 contentView.setViewVisibility(R.id.info, View.VISIBLE);
1405 hasLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001406 } else if (mNumber > 0) {
Daniel Sandlerebce0112011-06-16 16:44:51 -04001407 final int tooBig = mContext.getResources().getInteger(
1408 R.integer.status_bar_notification_info_maxnum);
1409 if (mNumber > tooBig) {
1410 contentView.setTextViewText(R.id.info, mContext.getResources().getString(
1411 R.string.status_bar_notification_info_overflow));
Joe Onorato059a2f82011-01-04 10:27:01 -08001412 } else {
1413 NumberFormat f = NumberFormat.getIntegerInstance();
1414 contentView.setTextViewText(R.id.info, f.format(mNumber));
1415 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001416 contentView.setViewVisibility(R.id.info, View.VISIBLE);
1417 hasLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001418 } else {
1419 contentView.setViewVisibility(R.id.info, View.GONE);
1420 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001421
1422 if (mSubText != null) {
1423 contentView.setTextViewText(R.id.text, mSubText);
1424 contentView.setViewVisibility(R.id.text2, View.VISIBLE);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001425 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001426 contentView.setViewVisibility(R.id.text2, View.GONE);
1427 if (mProgressMax != 0 || mProgressIndeterminate) {
1428 contentView.setProgressBar(
1429 R.id.progress, mProgressMax, mProgress, mProgressIndeterminate);
1430 contentView.setViewVisibility(R.id.progress, View.VISIBLE);
1431 } else {
1432 contentView.setViewVisibility(R.id.progress, View.GONE);
1433 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001434 }
Joe Onorato561d3852010-11-20 18:09:34 -08001435 if (mWhen != 0) {
1436 contentView.setLong(R.id.time, "setTime", mWhen);
1437 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001438 contentView.setViewVisibility(R.id.line3, hasLine3 ? View.VISIBLE : View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001439 return contentView;
1440 }
1441
Joe Onorato46439ce2010-11-19 13:56:21 -08001442 private RemoteViews makeContentView() {
1443 if (mContentView != null) {
1444 return mContentView;
1445 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001446 return applyStandardTemplate(R.layout.status_bar_latest_event_content); // no more special large_icon flavor
Joe Onorato46439ce2010-11-19 13:56:21 -08001447 }
1448 }
1449
1450 private RemoteViews makeTickerView() {
1451 if (mTickerView != null) {
1452 return mTickerView;
1453 } else {
Joe Onorato561d3852010-11-20 18:09:34 -08001454 if (mContentView == null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001455 return applyStandardTemplate(mLargeIcon == null
Joe Onorato561d3852010-11-20 18:09:34 -08001456 ? R.layout.status_bar_latest_event_ticker
1457 : R.layout.status_bar_latest_event_ticker_large_icon);
1458 } else {
1459 return null;
1460 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001461 }
1462 }
1463
Daniel Sandlerb2a1c232012-03-24 10:37:28 -05001464 private RemoteViews makeIntruderView(boolean showLabels) {
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001465 RemoteViews intruderView = new RemoteViews(mContext.getPackageName(),
1466 R.layout.notification_intruder_content);
1467 if (mLargeIcon != null) {
1468 intruderView.setImageViewBitmap(R.id.icon, mLargeIcon);
1469 intruderView.setViewVisibility(R.id.icon, View.VISIBLE);
1470 } else if (mSmallIcon != 0) {
1471 intruderView.setImageViewResource(R.id.icon, mSmallIcon);
1472 intruderView.setViewVisibility(R.id.icon, View.VISIBLE);
1473 } else {
1474 intruderView.setViewVisibility(R.id.icon, View.GONE);
1475 }
1476 if (mContentTitle != null) {
1477 intruderView.setTextViewText(R.id.title, mContentTitle);
1478 }
1479 if (mContentText != null) {
1480 intruderView.setTextViewText(R.id.text, mContentText);
1481 }
1482 if (mActions.size() > 0) {
1483 intruderView.setViewVisibility(R.id.actions, View.VISIBLE);
1484 int N = mActions.size();
1485 if (N>3) N=3;
1486 final int[] BUTTONS = { R.id.action0, R.id.action1, R.id.action2 };
1487 for (int i=0; i<N; i++) {
1488 final Action action = mActions.get(i);
1489 final int buttonId = BUTTONS[i];
1490
1491 intruderView.setViewVisibility(buttonId, View.VISIBLE);
Daniel Sandlerb2a1c232012-03-24 10:37:28 -05001492 intruderView.setTextViewText(buttonId, showLabels ? action.title : null);
1493 intruderView.setTextViewCompoundDrawables(buttonId, 0, action.icon, 0, 0);
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001494 intruderView.setContentDescription(buttonId, action.title);
1495 intruderView.setOnClickPendingIntent(buttonId, action.actionIntent);
1496 }
1497 } else {
1498 intruderView.setViewVisibility(R.id.actions, View.GONE);
1499 }
1500 return intruderView;
1501 }
1502
Joe Onoratocb109a02011-01-18 17:57:41 -08001503 /**
1504 * Combine all of the options that have been set and return a new {@link Notification}
1505 * object.
1506 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001507 public Notification getNotification() {
1508 Notification n = new Notification();
1509 n.when = mWhen;
1510 n.icon = mSmallIcon;
1511 n.iconLevel = mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08001512 n.number = mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08001513 n.contentView = makeContentView();
1514 n.contentIntent = mContentIntent;
1515 n.deleteIntent = mDeleteIntent;
1516 n.fullScreenIntent = mFullScreenIntent;
1517 n.tickerText = mTickerText;
1518 n.tickerView = makeTickerView();
1519 n.largeIcon = mLargeIcon;
1520 n.sound = mSound;
1521 n.audioStreamType = mAudioStreamType;
1522 n.vibrate = mVibrate;
1523 n.ledARGB = mLedArgb;
1524 n.ledOnMS = mLedOnMs;
1525 n.ledOffMS = mLedOffMs;
1526 n.defaults = mDefaults;
1527 n.flags = mFlags;
Daniel Sandlerb2a1c232012-03-24 10:37:28 -05001528 if (mCanHasIntruder) {
1529 n.intruderView = makeIntruderView(mIntruderActionsShowText);
1530 }
Joe Onorato8d0b6552010-11-22 16:09:29 -08001531 if (mLedOnMs != 0 && mLedOffMs != 0) {
1532 n.flags |= FLAG_SHOW_LIGHTS;
1533 }
1534 if ((mDefaults & DEFAULT_LIGHTS) != 0) {
1535 n.flags |= FLAG_SHOW_LIGHTS;
1536 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001537 if (mKindList.size() > 0) {
1538 n.kind = new String[mKindList.size()];
1539 mKindList.toArray(n.kind);
1540 } else {
1541 n.kind = null;
1542 }
1543 n.priority = mPriority;
1544 n.extras = mExtras != null ? new Bundle(mExtras) : null;
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001545 if (mActions.size() > 0) {
1546 n.actions = new Action[mActions.size()];
1547 mActions.toArray(n.actions);
1548 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001549 return n;
1550 }
1551 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001552
1553 /**
1554 * @hide because this API is still very rough
1555 *
1556 * This is a "rebuilder": It consumes a Builder object and modifies its output.
1557 *
1558 * This represents the "big picture" style notification, with a large Bitmap atop the usual notification.
1559 *
1560 * Usage:
1561 * <pre class="prettyprint">
1562 * Notification noti = new Notification.BigPictureStyle(
1563 * new Notification.Builder()
1564 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
1565 * .setContentText(subject)
1566 * .setSmallIcon(R.drawable.new_mail)
1567 * .setLargeIcon(aBitmap))
1568 * .bigPicture(aBigBitmap)
1569 * .build();
1570 * </pre>
1571 */
1572 public static class BigPictureStyle {
1573 private Builder mBuilder;
1574 private Bitmap mPicture;
1575
1576 public BigPictureStyle(Builder builder) {
1577 mBuilder = builder;
1578 }
1579
1580 public BigPictureStyle bigPicture(Bitmap b) {
1581 mPicture = b;
1582 return this;
1583 }
1584
1585 private RemoteViews makeBigContentView() {
1586 RemoteViews contentView = mBuilder.applyStandardTemplate(R.layout.notification_template_big_picture);
1587
1588 contentView.setImageViewBitmap(R.id.big_picture, mPicture);
1589
1590 return contentView;
1591 }
1592
1593 public Notification build() {
1594 Notification wip = mBuilder.getNotification();
1595 wip.bigContentView = makeBigContentView();
1596 return wip;
1597 }
1598 }
1599
1600 /**
1601 * @hide because this API is still very rough
1602 *
1603 * This is a "rebuilder": It consumes a Builder object and modifies its output.
1604 *
1605 * This represents the "big text" style notification, with more area for the main content text to be read in its entirety.
1606 *
1607 * Usage:
1608 * <pre class="prettyprint">
1609 * Notification noti = new Notification.BigPictureStyle(
1610 * new Notification.Builder()
1611 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
1612 * .setContentText(subject)
1613 * .setSmallIcon(R.drawable.new_mail)
1614 * .setLargeIcon(aBitmap))
1615 * .bigText(aVeryLongString)
1616 * .build();
1617 * </pre>
1618 */
1619 public static class BigTextStyle {
1620 private Builder mBuilder;
1621 private CharSequence mBigText;
1622
1623 public BigTextStyle(Builder builder) {
1624 mBuilder = builder;
1625 }
1626
1627 public BigTextStyle bigText(CharSequence cs) {
1628 mBigText = cs;
1629 return this;
1630 }
1631
1632 private RemoteViews makeBigContentView() {
1633 RemoteViews contentView = mBuilder.applyStandardTemplate(R.layout.status_bar_latest_event_content);
1634
1635 contentView.setTextViewText(R.id.big_text, mBigText);
1636 contentView.setViewVisibility(R.id.big_text, View.VISIBLE);
1637 contentView.setTextViewText(R.id.text, ""); // XXX: what do do with this spot?
1638
1639 return contentView;
1640 }
1641
1642 public Notification build() {
1643 Notification wip = mBuilder.getNotification();
1644 wip.bigContentView = makeBigContentView();
1645 return wip;
1646 }
1647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648}