blob: caade703acb4bb9a4d98d18059980d2a42493dba [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;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040023import android.content.res.Resources;
Joe Onoratoef1e7762010-09-17 18:38:38 -040024import android.graphics.Bitmap;
Jeff Sharkey098d5802012-04-26 17:30:34 -070025import android.media.AudioManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.net.Uri;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050027import android.os.Bundle;
Daniel Sandlera0a938c2012-03-15 08:42:37 -040028import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.Parcel;
30import android.os.Parcelable;
Daniel Sandlera2985ed2012-04-03 16:42:00 -040031import android.os.SystemClock;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.text.TextUtils;
Daniel Sandlera0a938c2012-03-15 08:42:37 -040033import android.util.IntProperty;
Daniel Sandler96fd7c12012-03-30 16:37:36 -040034import android.util.Log;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040035import android.util.Slog;
36import 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
Andy Stadler110988c2010-12-03 14:29:16 -080041import java.text.NumberFormat;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050042import java.util.ArrayList;
Joe Onorato561d3852010-11-20 18:09:34 -080043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044/**
45 * A class that represents how a persistent notification is to be presented to
46 * the user using the {@link android.app.NotificationManager}.
47 *
Joe Onoratocb109a02011-01-18 17:57:41 -080048 * <p>The {@link Notification.Builder Notification.Builder} has been added to make it
49 * easier to construct Notifications.</p>
50 *
Joe Fernandez558459f2011-10-13 16:47:36 -070051 * <div class="special reference">
52 * <h3>Developer Guides</h3>
53 * <p>For a guide to creating notifications, read the
54 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a>
55 * developer guide.</p>
56 * </div>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 */
58public class Notification implements Parcelable
59{
60 /**
61 * Use all default values (where applicable).
62 */
63 public static final int DEFAULT_ALL = ~0;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 /**
66 * Use the default notification sound. This will ignore any given
67 * {@link #sound}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050068 *
69
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050071 */
72
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 public static final int DEFAULT_SOUND = 1;
74
75 /**
76 * Use the default notification vibrate. This will ignore any given
Daniel Sandler2561b0b2012-02-13 21:04:12 -050077 * {@link #vibrate}. Using phone vibration requires the
Scott Mainb8b36452009-04-26 15:50:49 -070078 * {@link android.Manifest.permission#VIBRATE VIBRATE} permission.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050079 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050081 */
82
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 public static final int DEFAULT_VIBRATE = 2;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 /**
86 * Use the default notification lights. This will ignore the
87 * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or
88 * {@link #ledOnMS}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050089 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050091 */
92
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 public static final int DEFAULT_LIGHTS = 4;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -050096 * A timestamp related to this notification, in milliseconds since the epoch.
97 *
98 * Default value: {@link System#currentTimeMillis() Now}.
99 *
100 * Choose a timestamp that will be most relevant to the user. For most finite events, this
101 * corresponds to the time the event happened (or will happen, in the case of events that have
102 * yet to occur but about which the user is being informed). Indefinite events should be
103 * timestamped according to when the activity began.
104 *
105 * Some examples:
106 *
107 * <ul>
108 * <li>Notification of a new chat message should be stamped when the message was received.</li>
109 * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li>
110 * <li>Notification of a completed file download should be stamped when the download finished.</li>
111 * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li>
112 * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
113 * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time.
114 * </ul>
115 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 */
117 public long when;
118
119 /**
120 * The resource id of a drawable to use as the icon in the status bar.
Daniel Sandlerd952dae2011-02-07 16:33:36 -0500121 * This is required; notifications with an invalid icon resource will not be shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 */
123 public int icon;
124
125 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800126 * If the icon in the status bar is to have more than one level, you can set this. Otherwise,
127 * leave it at its default value of 0.
128 *
129 * @see android.widget.ImageView#setImageLevel
130 * @see android.graphics.drawable#setLevel
131 */
132 public int iconLevel;
133
134 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500135 * The number of events that this notification represents. For example, in a new mail
136 * notification, this could be the number of unread messages.
137 *
138 * The system may or may not use this field to modify the appearance of the notification. For
139 * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was
140 * superimposed over the icon in the status bar. Starting with
141 * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by
142 * {@link Notification.Builder} has displayed the number in the expanded notification view.
143 *
144 * If the number is 0 or negative, it is never shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 */
146 public int number;
147
148 /**
149 * The intent to execute when the expanded status entry is clicked. If
150 * this is an activity, it must include the
151 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -0800152 * that you take care of task management as described in the
153 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
Dianne Hackborn6ceca582012-01-10 15:24:26 -0800154 * Stack</a> document. In particular, make sure to read the notification section
155 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling
156 * Notifications</a> for the correct ways to launch an application from a
157 * notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 */
159 public PendingIntent contentIntent;
160
161 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500162 * The intent to execute when the notification is explicitly dismissed by the user, either with
163 * the "Clear All" button or by swiping it away individually.
164 *
165 * This probably shouldn't be launching an activity since several of those will be sent
166 * at the same time.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 */
168 public PendingIntent deleteIntent;
169
170 /**
Dianne Hackborn170bae72010-09-03 15:14:28 -0700171 * An intent to launch instead of posting the notification to the status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -0800172 *
173 * @see Notification.Builder#setFullScreenIntent
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400174 */
175 public PendingIntent fullScreenIntent;
176
177 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 * Text to scroll across the screen when this item is added to
Joe Onoratoef1e7762010-09-17 18:38:38 -0400179 * the status bar on large and smaller devices.
180 *
Joe Onorato46439ce2010-11-19 13:56:21 -0800181 * @see #tickerView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 */
183 public CharSequence tickerText;
184
185 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800186 * The view to show as the ticker in the status bar when the notification
187 * is posted.
Joe Onoratoef1e7762010-09-17 18:38:38 -0400188 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800189 public RemoteViews tickerView;
Joe Onoratoef1e7762010-09-17 18:38:38 -0400190
191 /**
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400192 * The view that will represent this notification in the expanded status bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 */
194 public RemoteViews contentView;
195
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400196 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -0400197 * A large-format version of {@link #contentView}, giving the Notification an
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400198 * opportunity to show more detail. The system UI may choose to show this
199 * instead of the normal content view at its discretion.
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400200 */
201 public RemoteViews bigContentView;
202
203 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800204 * The bitmap that may escape the bounds of the panel and bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800206 public Bitmap largeIcon;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207
208 /**
209 * The sound to play.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500210 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 * <p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500212 * To play the default notification sound, see {@link #defaults}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 * </p>
214 */
215 public Uri sound;
216
217 /**
218 * Use this constant as the value for audioStreamType to request that
219 * the default stream type for notifications be used. Currently the
Jeff Sharkey098d5802012-04-26 17:30:34 -0700220 * default stream type is {@link AudioManager#STREAM_NOTIFICATION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 */
222 public static final int STREAM_DEFAULT = -1;
223
224 /**
225 * The audio stream type to use when playing the sound.
226 * Should be one of the STREAM_ constants from
227 * {@link android.media.AudioManager}.
228 */
229 public int audioStreamType = STREAM_DEFAULT;
230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500232 * The pattern with which to vibrate.
233 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 * <p>
235 * To vibrate the default pattern, see {@link #defaults}.
236 * </p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500237 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 * @see android.os.Vibrator#vibrate(long[],int)
239 */
240 public long[] vibrate;
241
242 /**
243 * The color of the led. The hardware will do its best approximation.
244 *
245 * @see #FLAG_SHOW_LIGHTS
246 * @see #flags
247 */
248 public int ledARGB;
249
250 /**
251 * The number of milliseconds for the LED to be on while it's flashing.
252 * The hardware will do its best approximation.
253 *
254 * @see #FLAG_SHOW_LIGHTS
255 * @see #flags
256 */
257 public int ledOnMS;
258
259 /**
260 * The number of milliseconds for the LED to be off while it's flashing.
261 * The hardware will do its best approximation.
262 *
263 * @see #FLAG_SHOW_LIGHTS
264 * @see #flags
265 */
266 public int ledOffMS;
267
268 /**
269 * Specifies which values should be taken from the defaults.
270 * <p>
271 * To set, OR the desired from {@link #DEFAULT_SOUND},
272 * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default
273 * values, use {@link #DEFAULT_ALL}.
274 * </p>
275 */
276 public int defaults;
277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 /**
279 * Bit to be bitwise-ored into the {@link #flags} field that should be
280 * set if you want the LED on for this notification.
281 * <ul>
282 * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB
283 * or 0 for both ledOnMS and ledOffMS.</li>
284 * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li>
285 * <li>To flash the LED, pass the number of milliseconds that it should
286 * be on and off to ledOnMS and ledOffMS.</li>
287 * </ul>
288 * <p>
289 * Since hardware varies, you are not guaranteed that any of the values
290 * you pass are honored exactly. Use the system defaults (TODO) if possible
291 * because they will be set to values that work on any given hardware.
292 * <p>
293 * The alpha channel must be set for forward compatibility.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500294 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 */
296 public static final int FLAG_SHOW_LIGHTS = 0x00000001;
297
298 /**
299 * Bit to be bitwise-ored into the {@link #flags} field that should be
300 * set if this notification is in reference to something that is ongoing,
301 * like a phone call. It should not be set if this notification is in
302 * reference to something that happened at a particular point in time,
303 * like a missed phone call.
304 */
305 public static final int FLAG_ONGOING_EVENT = 0x00000002;
306
307 /**
308 * Bit to be bitwise-ored into the {@link #flags} field that if set,
Scott Mainb8b36452009-04-26 15:50:49 -0700309 * the audio will be repeated until the notification is
310 * cancelled or the notification window is opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 */
312 public static final int FLAG_INSISTENT = 0x00000004;
313
314 /**
315 * Bit to be bitwise-ored into the {@link #flags} field that should be
316 * set if you want the sound and/or vibration play each time the
317 * notification is sent, even if it has not been canceled before that.
318 */
319 public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008;
320
321 /**
322 * Bit to be bitwise-ored into the {@link #flags} field that should be
323 * set if the notification should be canceled when it is clicked by the
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500324 * user. On tablets, the
325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 */
327 public static final int FLAG_AUTO_CANCEL = 0x00000010;
328
329 /**
330 * Bit to be bitwise-ored into the {@link #flags} field that should be
331 * set if the notification should not be canceled when the user clicks
332 * the Clear all button.
333 */
334 public static final int FLAG_NO_CLEAR = 0x00000020;
335
Dianne Hackbornd8a43f62009-08-17 23:33:56 -0700336 /**
337 * Bit to be bitwise-ored into the {@link #flags} field that should be
338 * set if this notification represents a currently running service. This
339 * will normally be set for you by {@link Service#startForeground}.
340 */
341 public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;
342
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400343 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500344 * Obsolete flag indicating high-priority notifications; use the priority field instead.
345 *
346 * @deprecated Use {@link #priority} with a positive value.
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400347 */
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500348 public static final int FLAG_HIGH_PRIORITY = 0x00000080;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 public int flags;
351
352 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500353 * Default notification {@link #priority}. If your application does not prioritize its own
354 * notifications, use this value for all notifications.
355 */
356 public static final int PRIORITY_DEFAULT = 0;
357
358 /**
359 * Lower {@link #priority}, for items that are less important. The UI may choose to show these
360 * items smaller, or at a different position in the list, compared with your app's
361 * {@link #PRIORITY_DEFAULT} items.
362 */
363 public static final int PRIORITY_LOW = -1;
364
365 /**
366 * Lowest {@link #priority}; these items might not be shown to the user except under special
367 * circumstances, such as detailed notification logs.
368 */
369 public static final int PRIORITY_MIN = -2;
370
371 /**
372 * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to
373 * show these items larger, or at a different position in notification lists, compared with
374 * your app's {@link #PRIORITY_DEFAULT} items.
375 */
376 public static final int PRIORITY_HIGH = 1;
377
378 /**
379 * Highest {@link #priority}, for your application's most important items that require the
380 * user's prompt attention or input.
381 */
382 public static final int PRIORITY_MAX = 2;
383
384 /**
385 * Relative priority for this notification.
386 *
387 * Priority is an indication of how much of the user's valuable attention should be consumed by
388 * this notification. Low-priority notifications may be hidden from the user in certain
389 * situations, while the user might be interrupted for a higher-priority notification. The
390 * system will make a determination about how to interpret notification priority as described in
391 * MUMBLE MUMBLE.
392 */
393 public int priority;
394
395 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400396 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500397 * Notification type: incoming call (voice or video) or similar synchronous communication request.
398 */
399 public static final String KIND_CALL = "android.call";
400
401 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400402 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500403 * Notification type: incoming direct message (SMS, instant message, etc.).
404 */
405 public static final String KIND_MESSAGE = "android.message";
406
407 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400408 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500409 * Notification type: asynchronous bulk message (email).
410 */
411 public static final String KIND_EMAIL = "android.email";
412
413 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400414 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500415 * Notification type: calendar event.
416 */
417 public static final String KIND_EVENT = "android.event";
418
419 /**
Daniel Sandlera90513d2012-06-04 02:11:17 -0400420 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500421 * Notification type: promotion or advertisement.
422 */
423 public static final String KIND_PROMO = "android.promo";
424
425 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400426 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500427 * If this notification matches of one or more special types (see the <code>KIND_*</code>
428 * constants), add them here, best match first.
429 */
430 public String[] kind;
431
432 /**
433 * Extra key for people values (type TBD).
434 *
435 * @hide
436 */
437 public static final String EXTRA_PEOPLE = "android.people";
438
439 private Bundle extras;
440
441 /**
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400442 * Structure to encapsulate an "action", including title and icon, that can be attached to a Notification.
443 * @hide
444 */
445 private static class Action implements Parcelable {
446 public int icon;
447 public CharSequence title;
448 public PendingIntent actionIntent;
449 @SuppressWarnings("unused")
450 public Action() { }
451 private Action(Parcel in) {
452 icon = in.readInt();
453 title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
454 if (in.readInt() == 1) {
455 actionIntent = PendingIntent.CREATOR.createFromParcel(in);
456 }
457 }
458 public Action(int icon_, CharSequence title_, PendingIntent intent_) {
459 this.icon = icon_;
460 this.title = title_;
461 this.actionIntent = intent_;
462 }
463 @Override
464 public Action clone() {
465 return new Action(
466 this.icon,
467 this.title.toString(),
468 this.actionIntent // safe to alias
469 );
470 }
471 @Override
472 public int describeContents() {
473 return 0;
474 }
475 @Override
476 public void writeToParcel(Parcel out, int flags) {
477 out.writeInt(icon);
478 TextUtils.writeToParcel(title, out, flags);
479 if (actionIntent != null) {
480 out.writeInt(1);
481 actionIntent.writeToParcel(out, flags);
482 } else {
483 out.writeInt(0);
484 }
485 }
486 public static final Parcelable.Creator<Action> CREATOR
487 = new Parcelable.Creator<Action>() {
488 public Action createFromParcel(Parcel in) {
489 return new Action(in);
490 }
491 public Action[] newArray(int size) {
492 return new Action[size];
493 }
494 };
495 }
496
497 private Action[] actions;
498
499 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500500 * Constructs a Notification object with default values.
Joe Onorato46439ce2010-11-19 13:56:21 -0800501 * You might want to consider using {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 */
503 public Notification()
504 {
505 this.when = System.currentTimeMillis();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500506 this.priority = PRIORITY_DEFAULT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 }
508
509 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 * @hide
511 */
512 public Notification(Context context, int icon, CharSequence tickerText, long when,
513 CharSequence contentTitle, CharSequence contentText, Intent contentIntent)
514 {
515 this.when = when;
516 this.icon = icon;
517 this.tickerText = tickerText;
518 setLatestEventInfo(context, contentTitle, contentText,
519 PendingIntent.getActivity(context, 0, contentIntent, 0));
520 }
521
522 /**
523 * Constructs a Notification object with the information needed to
524 * have a status bar icon without the standard expanded view.
525 *
526 * @param icon The resource id of the icon to put in the status bar.
527 * @param tickerText The text that flows by in the status bar when the notification first
528 * activates.
529 * @param when The time to show in the time field. In the System.currentTimeMillis
530 * timebase.
Joe Onorato46439ce2010-11-19 13:56:21 -0800531 *
532 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800534 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 public Notification(int icon, CharSequence tickerText, long when)
536 {
537 this.icon = icon;
538 this.tickerText = tickerText;
539 this.when = when;
540 }
541
542 /**
543 * Unflatten the notification from a parcel.
544 */
545 public Notification(Parcel parcel)
546 {
547 int version = parcel.readInt();
548
549 when = parcel.readLong();
550 icon = parcel.readInt();
551 number = parcel.readInt();
552 if (parcel.readInt() != 0) {
553 contentIntent = PendingIntent.CREATOR.createFromParcel(parcel);
554 }
555 if (parcel.readInt() != 0) {
556 deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel);
557 }
558 if (parcel.readInt() != 0) {
559 tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
560 }
561 if (parcel.readInt() != 0) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800562 tickerView = RemoteViews.CREATOR.createFromParcel(parcel);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400563 }
564 if (parcel.readInt() != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 contentView = RemoteViews.CREATOR.createFromParcel(parcel);
566 }
Joe Onorato561d3852010-11-20 18:09:34 -0800567 if (parcel.readInt() != 0) {
568 largeIcon = Bitmap.CREATOR.createFromParcel(parcel);
569 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 defaults = parcel.readInt();
571 flags = parcel.readInt();
572 if (parcel.readInt() != 0) {
573 sound = Uri.CREATOR.createFromParcel(parcel);
574 }
575
576 audioStreamType = parcel.readInt();
577 vibrate = parcel.createLongArray();
578 ledARGB = parcel.readInt();
579 ledOnMS = parcel.readInt();
580 ledOffMS = parcel.readInt();
581 iconLevel = parcel.readInt();
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400582
583 if (parcel.readInt() != 0) {
584 fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel);
585 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500586
587 priority = parcel.readInt();
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400588
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500589 kind = parcel.createStringArray(); // may set kind to null
590
591 if (parcel.readInt() != 0) {
592 extras = parcel.readBundle();
593 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400594
595 actions = parcel.createTypedArray(Action.CREATOR);
596 if (parcel.readInt() != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400597 bigContentView = RemoteViews.CREATOR.createFromParcel(parcel);
598 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 }
600
Andy Stadler110988c2010-12-03 14:29:16 -0800601 @Override
Joe Onorato18e69df2010-05-17 22:26:12 -0700602 public Notification clone() {
603 Notification that = new Notification();
604
605 that.when = this.when;
606 that.icon = this.icon;
607 that.number = this.number;
608
609 // PendingIntents are global, so there's no reason (or way) to clone them.
610 that.contentIntent = this.contentIntent;
611 that.deleteIntent = this.deleteIntent;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400612 that.fullScreenIntent = this.fullScreenIntent;
Joe Onorato18e69df2010-05-17 22:26:12 -0700613
614 if (this.tickerText != null) {
615 that.tickerText = this.tickerText.toString();
616 }
Joe Onorato46439ce2010-11-19 13:56:21 -0800617 if (this.tickerView != null) {
618 that.tickerView = this.tickerView.clone();
Joe Onoratoef1e7762010-09-17 18:38:38 -0400619 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700620 if (this.contentView != null) {
621 that.contentView = this.contentView.clone();
622 }
Joe Onorato561d3852010-11-20 18:09:34 -0800623 if (this.largeIcon != null) {
624 that.largeIcon = Bitmap.createBitmap(this.largeIcon);
625 }
Jozef BABJAKa8b91832011-02-22 08:05:08 +0100626 that.iconLevel = this.iconLevel;
Joe Onorato18e69df2010-05-17 22:26:12 -0700627 that.sound = this.sound; // android.net.Uri is immutable
628 that.audioStreamType = this.audioStreamType;
629
630 final long[] vibrate = this.vibrate;
631 if (vibrate != null) {
632 final int N = vibrate.length;
633 final long[] vib = that.vibrate = new long[N];
634 System.arraycopy(vibrate, 0, vib, 0, N);
635 }
636
637 that.ledARGB = this.ledARGB;
638 that.ledOnMS = this.ledOnMS;
639 that.ledOffMS = this.ledOffMS;
640 that.defaults = this.defaults;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500641
Joe Onorato18e69df2010-05-17 22:26:12 -0700642 that.flags = this.flags;
643
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500644 that.priority = this.priority;
645
646 final String[] thiskind = this.kind;
647 if (thiskind != null) {
648 final int N = thiskind.length;
649 final String[] thatkind = that.kind = new String[N];
650 System.arraycopy(thiskind, 0, thatkind, 0, N);
651 }
652
653 if (this.extras != null) {
654 that.extras = new Bundle(this.extras);
655
656 }
657
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400658 that.actions = new Action[this.actions.length];
659 for(int i=0; i<this.actions.length; i++) {
660 that.actions[i] = this.actions[i].clone();
661 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400662 if (this.bigContentView != null) {
663 that.bigContentView = this.bigContentView.clone();
664 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400665
Joe Onorato18e69df2010-05-17 22:26:12 -0700666 return that;
667 }
668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 public int describeContents() {
670 return 0;
671 }
672
673 /**
674 * Flatten this notification from a parcel.
675 */
676 public void writeToParcel(Parcel parcel, int flags)
677 {
678 parcel.writeInt(1);
679
680 parcel.writeLong(when);
681 parcel.writeInt(icon);
682 parcel.writeInt(number);
683 if (contentIntent != null) {
684 parcel.writeInt(1);
685 contentIntent.writeToParcel(parcel, 0);
686 } else {
687 parcel.writeInt(0);
688 }
689 if (deleteIntent != null) {
690 parcel.writeInt(1);
691 deleteIntent.writeToParcel(parcel, 0);
692 } else {
693 parcel.writeInt(0);
694 }
695 if (tickerText != null) {
696 parcel.writeInt(1);
697 TextUtils.writeToParcel(tickerText, parcel, flags);
698 } else {
699 parcel.writeInt(0);
700 }
Joe Onorato46439ce2010-11-19 13:56:21 -0800701 if (tickerView != null) {
Joe Onoratoef1e7762010-09-17 18:38:38 -0400702 parcel.writeInt(1);
Joe Onorato46439ce2010-11-19 13:56:21 -0800703 tickerView.writeToParcel(parcel, 0);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400704 } else {
705 parcel.writeInt(0);
706 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 if (contentView != null) {
708 parcel.writeInt(1);
709 contentView.writeToParcel(parcel, 0);
710 } else {
711 parcel.writeInt(0);
712 }
Joe Onorato561d3852010-11-20 18:09:34 -0800713 if (largeIcon != null) {
714 parcel.writeInt(1);
715 largeIcon.writeToParcel(parcel, 0);
716 } else {
717 parcel.writeInt(0);
718 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719
720 parcel.writeInt(defaults);
721 parcel.writeInt(this.flags);
722
723 if (sound != null) {
724 parcel.writeInt(1);
725 sound.writeToParcel(parcel, 0);
726 } else {
727 parcel.writeInt(0);
728 }
729 parcel.writeInt(audioStreamType);
730 parcel.writeLongArray(vibrate);
731 parcel.writeInt(ledARGB);
732 parcel.writeInt(ledOnMS);
733 parcel.writeInt(ledOffMS);
734 parcel.writeInt(iconLevel);
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400735
736 if (fullScreenIntent != null) {
737 parcel.writeInt(1);
738 fullScreenIntent.writeToParcel(parcel, 0);
739 } else {
740 parcel.writeInt(0);
741 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500742
743 parcel.writeInt(priority);
744
745 parcel.writeStringArray(kind); // ok for null
746
747 if (extras != null) {
748 parcel.writeInt(1);
749 extras.writeToParcel(parcel, 0);
750 } else {
751 parcel.writeInt(0);
752 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400753
754 parcel.writeTypedArray(actions, 0);
755
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400756 if (bigContentView != null) {
757 parcel.writeInt(1);
758 bigContentView.writeToParcel(parcel, 0);
759 } else {
760 parcel.writeInt(0);
761 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 }
763
764 /**
765 * Parcelable.Creator that instantiates Notification objects
766 */
767 public static final Parcelable.Creator<Notification> CREATOR
768 = new Parcelable.Creator<Notification>()
769 {
770 public Notification createFromParcel(Parcel parcel)
771 {
772 return new Notification(parcel);
773 }
774
775 public Notification[] newArray(int size)
776 {
777 return new Notification[size];
778 }
779 };
780
781 /**
782 * Sets the {@link #contentView} field to be a view with the standard "Latest Event"
783 * layout.
784 *
785 * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields
786 * in the view.</p>
787 * @param context The context for your application / activity.
788 * @param contentTitle The title that goes in the expanded entry.
789 * @param contentText The text that goes in the expanded entry.
790 * @param contentIntent The intent to launch when the user clicks the expanded notification.
791 * If this is an activity, it must include the
792 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -0800793 * that you take care of task management as described in the
794 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
795 * Stack</a> document.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500796 *
Joe Onorato46439ce2010-11-19 13:56:21 -0800797 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800799 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 public void setLatestEventInfo(Context context,
801 CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) {
Daniel Sandlercde8aae2012-04-04 23:40:22 -0400802 // TODO: rewrite this to use Builder
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 RemoteViews contentView = new RemoteViews(context.getPackageName(),
Daniel Sandler96fd7c12012-03-30 16:37:36 -0400804 R.layout.notification_template_base);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 if (this.icon != 0) {
Joe Onorato561d3852010-11-20 18:09:34 -0800806 contentView.setImageViewResource(R.id.icon, this.icon);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 }
Daniel Sandlere95658c2012-05-10 00:33:54 -0400808 if (priority < PRIORITY_LOW) {
809 contentView.setInt(R.id.icon,
810 "setBackgroundResource", R.drawable.notification_template_icon_low_bg);
811 contentView.setInt(R.id.status_bar_latest_event_content,
812 "setBackgroundResource", R.drawable.notification_bg_low);
813 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 if (contentTitle != null) {
Joe Onorato561d3852010-11-20 18:09:34 -0800815 contentView.setTextViewText(R.id.title, contentTitle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 }
817 if (contentText != null) {
Joe Onorato561d3852010-11-20 18:09:34 -0800818 contentView.setTextViewText(R.id.text, contentText);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 }
820 if (this.when != 0) {
Daniel Sandlercde8aae2012-04-04 23:40:22 -0400821 contentView.setViewVisibility(R.id.time, View.VISIBLE);
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 }
Daniel Sandlerb4b22232012-04-30 10:38:31 -0400824 if (this.number != 0) {
825 NumberFormat f = NumberFormat.getIntegerInstance();
826 contentView.setTextViewText(R.id.info, f.format(this.number));
827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828
829 this.contentView = contentView;
830 this.contentIntent = contentIntent;
831 }
832
833 @Override
834 public String toString() {
835 StringBuilder sb = new StringBuilder();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500836 sb.append("Notification(pri=");
837 sb.append(priority);
838 sb.append(" contentView=");
Joe Onoratoc9596d62011-01-12 17:03:11 -0800839 if (contentView != null) {
840 sb.append(contentView.getPackage());
841 sb.append("/0x");
842 sb.append(Integer.toHexString(contentView.getLayoutId()));
843 } else {
844 sb.append("null");
845 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500846 // TODO(dsandler): defaults take precedence over local values, so reorder the branches below
Joe Onoratoc9596d62011-01-12 17:03:11 -0800847 sb.append(" vibrate=");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 if (this.vibrate != null) {
849 int N = this.vibrate.length-1;
850 sb.append("[");
851 for (int i=0; i<N; i++) {
852 sb.append(this.vibrate[i]);
853 sb.append(',');
854 }
Simon Schoar8cf97d92009-06-10 22:08:37 +0200855 if (N != -1) {
856 sb.append(this.vibrate[N]);
857 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 sb.append("]");
859 } else if ((this.defaults & DEFAULT_VIBRATE) != 0) {
860 sb.append("default");
861 } else {
862 sb.append("null");
863 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500864 sb.append(" sound=");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 if (this.sound != null) {
866 sb.append(this.sound.toString());
867 } else if ((this.defaults & DEFAULT_SOUND) != 0) {
868 sb.append("default");
869 } else {
870 sb.append("null");
871 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500872 sb.append(" defaults=0x");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 sb.append(Integer.toHexString(this.defaults));
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500874 sb.append(" flags=0x");
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400875 sb.append(Integer.toHexString(this.flags));
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500876 sb.append(" kind=[");
877 if (this.kind == null) {
878 sb.append("null");
879 } else {
880 for (int i=0; i<this.kind.length; i++) {
881 if (i>0) sb.append(",");
882 sb.append(this.kind[i]);
883 }
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400884 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400885 sb.append("]");
886 if (actions != null) {
887 sb.append(" ");
888 sb.append(actions.length);
889 sb.append(" action");
890 if (actions.length > 1) sb.append("s");
891 }
892 sb.append(")");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 return sb.toString();
894 }
Joe Onorato46439ce2010-11-19 13:56:21 -0800895
Joe Onoratocb109a02011-01-18 17:57:41 -0800896 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500897 * Builder class for {@link Notification} objects.
898 *
899 * Provides a convenient way to set the various fields of a {@link Notification} and generate
900 * content views using the platform's notification layout template.
901 *
902 * Example:
903 *
904 * <pre class="prettyprint">
905 * Notification noti = new Notification.Builder()
906 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
907 * .setContentText(subject)
908 * .setSmallIcon(R.drawable.new_mail)
909 * .setLargeIcon(aBitmap)
Chris Wrenfbd96ba2012-05-01 12:03:58 -0400910 * .build();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500911 * </pre>
Joe Onoratocb109a02011-01-18 17:57:41 -0800912 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800913 public static class Builder {
Daniel Sandler8680bf82012-05-15 16:52:52 -0400914 private static final int MAX_ACTION_BUTTONS = 2;
915
Joe Onorato46439ce2010-11-19 13:56:21 -0800916 private Context mContext;
917
918 private long mWhen;
919 private int mSmallIcon;
920 private int mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -0800921 private int mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -0800922 private CharSequence mContentTitle;
923 private CharSequence mContentText;
924 private CharSequence mContentInfo;
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400925 private CharSequence mSubText;
Joe Onorato46439ce2010-11-19 13:56:21 -0800926 private PendingIntent mContentIntent;
927 private RemoteViews mContentView;
928 private PendingIntent mDeleteIntent;
929 private PendingIntent mFullScreenIntent;
930 private CharSequence mTickerText;
931 private RemoteViews mTickerView;
932 private Bitmap mLargeIcon;
933 private Uri mSound;
934 private int mAudioStreamType;
935 private long[] mVibrate;
936 private int mLedArgb;
937 private int mLedOnMs;
938 private int mLedOffMs;
939 private int mDefaults;
940 private int mFlags;
Jeff Sharkey1c400132011-08-05 14:50:13 -0700941 private int mProgressMax;
942 private int mProgress;
943 private boolean mProgressIndeterminate;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500944 private ArrayList<String> mKindList = new ArrayList<String>(1);
945 private Bundle mExtras;
946 private int mPriority;
Daniel Sandler8680bf82012-05-15 16:52:52 -0400947 private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS);
Daniel Sandlera2985ed2012-04-03 16:42:00 -0400948 private boolean mUseChronometer;
Chris Wrenfbd96ba2012-05-01 12:03:58 -0400949 private Style mStyle;
Joe Onorato46439ce2010-11-19 13:56:21 -0800950
Joe Onoratocb109a02011-01-18 17:57:41 -0800951 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500952 * Constructs a new Builder with the defaults:
Joe Onoratocb109a02011-01-18 17:57:41 -0800953 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500954
955 * <table>
956 * <tr><th align=right>priority</th>
957 * <td>{@link #PRIORITY_DEFAULT}</td></tr>
958 * <tr><th align=right>when</th>
959 * <td>now ({@link System#currentTimeMillis()})</td></tr>
960 * <tr><th align=right>audio stream</th>
961 * <td>{@link #STREAM_DEFAULT}</td></tr>
962 * </table>
Joe Onoratocb109a02011-01-18 17:57:41 -0800963 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500964
965 * @param context
966 * A {@link Context} that will be used by the Builder to construct the
967 * RemoteViews. The Context will not be held past the lifetime of this Builder
968 * object.
Joe Onoratocb109a02011-01-18 17:57:41 -0800969 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800970 public Builder(Context context) {
971 mContext = context;
Andy Stadler110988c2010-12-03 14:29:16 -0800972
973 // Set defaults to match the defaults of a Notification
Joe Onorato46439ce2010-11-19 13:56:21 -0800974 mWhen = System.currentTimeMillis();
Andy Stadler110988c2010-12-03 14:29:16 -0800975 mAudioStreamType = STREAM_DEFAULT;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500976 mPriority = PRIORITY_DEFAULT;
Joe Onorato46439ce2010-11-19 13:56:21 -0800977 }
978
Joe Onoratocb109a02011-01-18 17:57:41 -0800979 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500980 * Add a timestamp pertaining to the notification (usually the time the event occurred).
981 *
982
983 * @see Notification#when
Joe Onoratocb109a02011-01-18 17:57:41 -0800984 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800985 public Builder setWhen(long when) {
986 mWhen = when;
987 return this;
988 }
989
Joe Onoratocb109a02011-01-18 17:57:41 -0800990 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400991 * Show the {@link Notification#when} field as a stopwatch.
992 *
993 * Instead of presenting <code>when</code> as a timestamp, the notification will show an
994 * automatically updating display of the minutes and seconds since <code>when</code>.
Daniel Sandlera2985ed2012-04-03 16:42:00 -0400995 *
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400996 * Useful when showing an elapsed time (like an ongoing phone call).
997 *
998 * @see android.widget.Chronometer
Daniel Sandlera2985ed2012-04-03 16:42:00 -0400999 * @see Notification#when
1000 */
1001 public Builder setUsesChronometer(boolean b) {
1002 mUseChronometer = b;
1003 return this;
1004 }
1005
1006 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001007 * Set the small icon resource, which will be used to represent the notification in the
1008 * status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -08001009 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001010
1011 * The platform template for the expanded view will draw this icon in the left, unless a
1012 * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small
1013 * icon will be moved to the right-hand side.
1014 *
1015
1016 * @param icon
1017 * A resource ID in the application's package of the drawable to use.
1018 * @see Notification#icon
Joe Onoratocb109a02011-01-18 17:57:41 -08001019 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001020 public Builder setSmallIcon(int icon) {
1021 mSmallIcon = icon;
1022 return this;
1023 }
1024
Joe Onoratocb109a02011-01-18 17:57:41 -08001025 /**
1026 * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional
1027 * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable
1028 * LevelListDrawable}.
1029 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001030 * @param icon A resource ID in the application's package of the drawable to use.
Joe Onoratocb109a02011-01-18 17:57:41 -08001031 * @param level The level to use for the icon.
1032 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001033 * @see Notification#icon
1034 * @see Notification#iconLevel
Joe Onoratocb109a02011-01-18 17:57:41 -08001035 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001036 public Builder setSmallIcon(int icon, int level) {
1037 mSmallIcon = icon;
1038 mSmallIconLevel = level;
1039 return this;
1040 }
1041
Joe Onoratocb109a02011-01-18 17:57:41 -08001042 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001043 * Set the first line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001044 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001045 public Builder setContentTitle(CharSequence title) {
1046 mContentTitle = title;
1047 return this;
1048 }
1049
Joe Onoratocb109a02011-01-18 17:57:41 -08001050 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001051 * Set the second line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001052 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001053 public Builder setContentText(CharSequence text) {
1054 mContentText = text;
1055 return this;
1056 }
1057
Joe Onoratocb109a02011-01-18 17:57:41 -08001058 /**
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001059 * Set the third line of text in the platform notification template.
1060 * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the same location in the standard template.
1061 */
1062 public Builder setSubText(CharSequence text) {
1063 mSubText = text;
1064 return this;
1065 }
1066
1067 /**
Joe Onoratocb109a02011-01-18 17:57:41 -08001068 * Set the large number at the right-hand side of the notification. This is
1069 * equivalent to setContentInfo, although it might show the number in a different
1070 * font size for readability.
1071 */
Joe Onorato8595a3d2010-11-19 18:12:07 -08001072 public Builder setNumber(int number) {
1073 mNumber = number;
1074 return this;
1075 }
1076
Joe Onoratocb109a02011-01-18 17:57:41 -08001077 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001078 * A small piece of additional information pertaining to this notification.
1079 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001080 * The platform template will draw this on the last line of the notification, at the far
1081 * right (to the right of a smallIcon if it has been placed there).
Joe Onoratocb109a02011-01-18 17:57:41 -08001082 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001083 public Builder setContentInfo(CharSequence info) {
1084 mContentInfo = info;
1085 return this;
1086 }
1087
Joe Onoratocb109a02011-01-18 17:57:41 -08001088 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001089 * Set the progress this notification represents.
1090 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001091 * The platform template will represent this using a {@link ProgressBar}.
Jeff Sharkey1c400132011-08-05 14:50:13 -07001092 */
1093 public Builder setProgress(int max, int progress, boolean indeterminate) {
1094 mProgressMax = max;
1095 mProgress = progress;
1096 mProgressIndeterminate = indeterminate;
1097 return this;
1098 }
1099
1100 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001101 * Supply a custom RemoteViews to use instead of the platform template.
1102 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001103 * @see Notification#contentView
Joe Onoratocb109a02011-01-18 17:57:41 -08001104 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001105 public Builder setContent(RemoteViews views) {
1106 mContentView = views;
1107 return this;
1108 }
1109
Joe Onoratocb109a02011-01-18 17:57:41 -08001110 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001111 * Supply a {@link PendingIntent} to be sent when the notification is clicked.
1112 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001113 * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you
1114 * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use
1115 * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)}
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001116 * to assign PendingIntents to individual views in that custom layout (i.e., to create
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001117 * clickable buttons inside the notification view).
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001118 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001119 * @see Notification#contentIntent Notification.contentIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001120 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001121 public Builder setContentIntent(PendingIntent intent) {
1122 mContentIntent = intent;
1123 return this;
1124 }
1125
Joe Onoratocb109a02011-01-18 17:57:41 -08001126 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001127 * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user.
1128 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001129 * @see Notification#deleteIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001130 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001131 public Builder setDeleteIntent(PendingIntent intent) {
1132 mDeleteIntent = intent;
1133 return this;
1134 }
1135
Joe Onoratocb109a02011-01-18 17:57:41 -08001136 /**
1137 * An intent to launch instead of posting the notification to the status bar.
1138 * Only for use with extremely high-priority notifications demanding the user's
1139 * <strong>immediate</strong> attention, such as an incoming phone call or
1140 * alarm clock that the user has explicitly set to a particular time.
1141 * If this facility is used for something else, please give the user an option
1142 * to turn it off and use a normal notification, as this can be extremely
1143 * disruptive.
1144 *
1145 * @param intent The pending intent to launch.
1146 * @param highPriority Passing true will cause this notification to be sent
1147 * even if other notifications are suppressed.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001148 *
1149 * @see Notification#fullScreenIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001150 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001151 public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
1152 mFullScreenIntent = intent;
1153 setFlag(FLAG_HIGH_PRIORITY, highPriority);
1154 return this;
1155 }
1156
Joe Onoratocb109a02011-01-18 17:57:41 -08001157 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001158 * Set the "ticker" text which is displayed in the status bar when the notification first
Joe Onoratocb109a02011-01-18 17:57:41 -08001159 * arrives.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001160 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001161 * @see Notification#tickerText
Joe Onoratocb109a02011-01-18 17:57:41 -08001162 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001163 public Builder setTicker(CharSequence tickerText) {
1164 mTickerText = tickerText;
1165 return this;
1166 }
1167
Joe Onoratocb109a02011-01-18 17:57:41 -08001168 /**
1169 * Set the text that is displayed in the status bar when the notification first
1170 * arrives, and also a RemoteViews object that may be displayed instead on some
1171 * devices.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001172 *
1173 * @see Notification#tickerText
1174 * @see Notification#tickerView
Joe Onoratocb109a02011-01-18 17:57:41 -08001175 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001176 public Builder setTicker(CharSequence tickerText, RemoteViews views) {
1177 mTickerText = tickerText;
1178 mTickerView = views;
1179 return this;
1180 }
1181
Joe Onoratocb109a02011-01-18 17:57:41 -08001182 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001183 * Add a large icon to the notification (and the ticker on some devices).
1184 *
1185 * In the platform template, this image will be shown on the left of the notification view
1186 * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side).
1187 *
1188 * @see Notification#largeIcon
Joe Onoratocb109a02011-01-18 17:57:41 -08001189 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001190 public Builder setLargeIcon(Bitmap icon) {
1191 mLargeIcon = icon;
1192 return this;
1193 }
1194
Joe Onoratocb109a02011-01-18 17:57:41 -08001195 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001196 * Set the sound to play.
1197 *
1198 * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications.
1199 *
1200 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001201 */
Joe Onorato52f80cd2010-11-21 15:34:48 -08001202 public Builder setSound(Uri sound) {
1203 mSound = sound;
1204 mAudioStreamType = STREAM_DEFAULT;
1205 return this;
1206 }
1207
Joe Onoratocb109a02011-01-18 17:57:41 -08001208 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001209 * Set the sound to play, along with a specific stream on which to play it.
Joe Onoratocb109a02011-01-18 17:57:41 -08001210 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001211 * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants.
1212 *
1213 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001214 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001215 public Builder setSound(Uri sound, int streamType) {
1216 mSound = sound;
1217 mAudioStreamType = streamType;
1218 return this;
1219 }
1220
Joe Onoratocb109a02011-01-18 17:57:41 -08001221 /**
1222 * Set the vibration pattern to use.
1223 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001224
1225 * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the
1226 * <code>pattern</code> parameter.
1227 *
1228
1229 * @see Notification#vibrate
Joe Onoratocb109a02011-01-18 17:57:41 -08001230 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001231 public Builder setVibrate(long[] pattern) {
1232 mVibrate = pattern;
1233 return this;
1234 }
1235
Joe Onoratocb109a02011-01-18 17:57:41 -08001236 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001237 * Set the desired color for the indicator LED on the device, as well as the
1238 * blink duty cycle (specified in milliseconds).
1239 *
1240
1241 * Not all devices will honor all (or even any) of these values.
1242 *
1243
1244 * @see Notification#ledARGB
1245 * @see Notification#ledOnMS
1246 * @see Notification#ledOffMS
Joe Onoratocb109a02011-01-18 17:57:41 -08001247 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001248 public Builder setLights(int argb, int onMs, int offMs) {
1249 mLedArgb = argb;
1250 mLedOnMs = onMs;
1251 mLedOffMs = offMs;
Joe Onorato46439ce2010-11-19 13:56:21 -08001252 return this;
1253 }
1254
Joe Onoratocb109a02011-01-18 17:57:41 -08001255 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001256 * Set whether this is an "ongoing" notification.
Joe Onoratocb109a02011-01-18 17:57:41 -08001257 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001258
1259 * Ongoing notifications cannot be dismissed by the user, so your application or service
1260 * must take care of canceling them.
1261 *
1262
1263 * They are typically used to indicate a background task that the user is actively engaged
1264 * with (e.g., playing music) or is pending in some way and therefore occupying the device
1265 * (e.g., a file download, sync operation, active network connection).
1266 *
1267
1268 * @see Notification#FLAG_ONGOING_EVENT
1269 * @see Service#setForeground(boolean)
Joe Onoratocb109a02011-01-18 17:57:41 -08001270 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001271 public Builder setOngoing(boolean ongoing) {
1272 setFlag(FLAG_ONGOING_EVENT, ongoing);
1273 return this;
1274 }
1275
Joe Onoratocb109a02011-01-18 17:57:41 -08001276 /**
1277 * Set this flag if you would only like the sound, vibrate
1278 * and ticker to be played if the notification is not already showing.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001279 *
1280 * @see Notification#FLAG_ONLY_ALERT_ONCE
Joe Onoratocb109a02011-01-18 17:57:41 -08001281 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001282 public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
1283 setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
1284 return this;
1285 }
1286
Joe Onoratocb109a02011-01-18 17:57:41 -08001287 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001288 * Make this notification automatically dismissed when the user touches it. The
1289 * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens.
1290 *
1291 * @see Notification#FLAG_AUTO_CANCEL
Joe Onoratocb109a02011-01-18 17:57:41 -08001292 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001293 public Builder setAutoCancel(boolean autoCancel) {
Joe Onorato281d83f2011-01-04 17:13:10 -08001294 setFlag(FLAG_AUTO_CANCEL, autoCancel);
Joe Onorato46439ce2010-11-19 13:56:21 -08001295 return this;
1296 }
1297
Joe Onoratocb109a02011-01-18 17:57:41 -08001298 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001299 * Set which notification properties will be inherited from system defaults.
Joe Onoratocb109a02011-01-18 17:57:41 -08001300 * <p>
1301 * The value should be one or more of the following fields combined with
1302 * bitwise-or:
1303 * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}.
1304 * <p>
1305 * For all default values, use {@link #DEFAULT_ALL}.
1306 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001307 public Builder setDefaults(int defaults) {
1308 mDefaults = defaults;
1309 return this;
1310 }
1311
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001312 /**
1313 * Set the priority of this notification.
1314 *
1315 * @see Notification#priority
1316 */
1317 public Builder setPriority(int pri) {
1318 mPriority = pri;
1319 return this;
1320 }
1321
1322 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001323 * @hide
1324 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001325 * Add a kind (category) to this notification. Optional.
1326 *
1327 * @see Notification#kind
1328 */
1329 public Builder addKind(String k) {
1330 mKindList.add(k);
1331 return this;
1332 }
1333
1334 /**
1335 * Add metadata to this notification.
1336 *
1337 * A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001338 * current contents are copied into the Notification each time {@link #build()} is
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001339 * called.
1340 *
1341 * @see Notification#extras
1342 * @hide
1343 */
1344 public Builder setExtras(Bundle bag) {
1345 mExtras = bag;
1346 return this;
1347 }
1348
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001349 /**
1350 * Add an action to this notification. Actions are typically displayed by
1351 * the system as a button adjacent to the notification content.
1352 *
1353 * @param icon Resource ID of a drawable that represents the action.
1354 * @param title Text describing the action.
1355 * @param intent PendingIntent to be fired when the action is invoked.
1356 */
1357 public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
1358 mActions.add(new Action(icon, title, intent));
1359 return this;
1360 }
1361
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001362 /**
1363 * Add a rich notification style to be applied at build time.
1364 *
1365 * @param style Object responsible for modifying the notification style.
1366 */
1367 public Builder setStyle(Style style) {
1368 if (mStyle != style) {
1369 mStyle = style;
1370 mStyle.setBuilder(this);
1371 }
1372 return this;
1373 }
1374
Joe Onorato46439ce2010-11-19 13:56:21 -08001375 private void setFlag(int mask, boolean value) {
1376 if (value) {
1377 mFlags |= mask;
1378 } else {
1379 mFlags &= ~mask;
1380 }
1381 }
1382
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001383 private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
Joe Onorato561d3852010-11-20 18:09:34 -08001384 RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001385 boolean showLine3 = false;
1386 boolean showLine2 = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001387 int smallIconImageViewId = R.id.icon;
1388 if (mLargeIcon != null) {
1389 contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
1390 smallIconImageViewId = R.id.right_icon;
1391 }
Daniel Sandlere95658c2012-05-10 00:33:54 -04001392 if (mPriority < PRIORITY_LOW) {
1393 contentView.setInt(R.id.icon,
1394 "setBackgroundResource", R.drawable.notification_template_icon_low_bg);
1395 contentView.setInt(R.id.status_bar_latest_event_content,
1396 "setBackgroundResource", R.drawable.notification_bg_low);
1397 }
Joe Onorato561d3852010-11-20 18:09:34 -08001398 if (mSmallIcon != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001399 contentView.setImageViewResource(smallIconImageViewId, mSmallIcon);
1400 contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001401 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001402 contentView.setViewVisibility(smallIconImageViewId, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001403 }
1404 if (mContentTitle != null) {
1405 contentView.setTextViewText(R.id.title, mContentTitle);
1406 }
1407 if (mContentText != null) {
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001408 contentView.setTextViewText(R.id.text, mContentText);
1409 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001410 }
1411 if (mContentInfo != null) {
1412 contentView.setTextViewText(R.id.info, mContentInfo);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001413 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001414 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001415 } else if (mNumber > 0) {
Daniel Sandlerebce0112011-06-16 16:44:51 -04001416 final int tooBig = mContext.getResources().getInteger(
1417 R.integer.status_bar_notification_info_maxnum);
1418 if (mNumber > tooBig) {
1419 contentView.setTextViewText(R.id.info, mContext.getResources().getString(
1420 R.string.status_bar_notification_info_overflow));
Joe Onorato059a2f82011-01-04 10:27:01 -08001421 } else {
1422 NumberFormat f = NumberFormat.getIntegerInstance();
1423 contentView.setTextViewText(R.id.info, f.format(mNumber));
1424 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001425 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001426 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001427 } else {
1428 contentView.setViewVisibility(R.id.info, View.GONE);
1429 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001430
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001431 // Need to show three lines?
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001432 if (mSubText != null) {
1433 contentView.setTextViewText(R.id.text, mSubText);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001434 if (mContentText != null) {
1435 contentView.setTextViewText(R.id.text2, mContentText);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001436 contentView.setViewVisibility(R.id.text2, View.VISIBLE);
1437 showLine2 = true;
1438 } else {
1439 contentView.setViewVisibility(R.id.text2, View.GONE);
1440 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001441 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001442 contentView.setViewVisibility(R.id.text2, View.GONE);
1443 if (mProgressMax != 0 || mProgressIndeterminate) {
1444 contentView.setProgressBar(
1445 R.id.progress, mProgressMax, mProgress, mProgressIndeterminate);
1446 contentView.setViewVisibility(R.id.progress, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001447 showLine2 = true;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001448 } else {
1449 contentView.setViewVisibility(R.id.progress, View.GONE);
1450 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001451 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001452 if (showLine2) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001453 if (fitIn1U) {
1454 // need to shrink all the type to make sure everything fits
1455 final Resources res = mContext.getResources();
1456 final float subTextSize = res.getDimensionPixelSize(
1457 R.dimen.notification_subtext_size);
1458 contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize);
1459 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001460 // vertical centering
1461 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
1462 }
1463
Joe Onorato561d3852010-11-20 18:09:34 -08001464 if (mWhen != 0) {
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001465 if (mUseChronometer) {
1466 contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
1467 contentView.setLong(R.id.chronometer, "setBase",
1468 mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
1469 contentView.setBoolean(R.id.chronometer, "setStarted", true);
1470 } else {
1471 contentView.setViewVisibility(R.id.time, View.VISIBLE);
1472 contentView.setLong(R.id.time, "setTime", mWhen);
1473 }
Joe Onorato561d3852010-11-20 18:09:34 -08001474 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001475 contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001476 contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001477 return contentView;
1478 }
1479
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001480 private RemoteViews applyStandardTemplateWithActions(int layoutId) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001481 RemoteViews big = applyStandardTemplate(layoutId, false);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001482
1483 int N = mActions.size();
1484 if (N > 0) {
Chris Wrend6297db2012-05-03 16:20:13 -04001485 // Log.d("Notification", "has actions: " + mContentText);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001486 big.setViewVisibility(R.id.actions, View.VISIBLE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001487 big.setViewVisibility(R.id.action_divider, View.VISIBLE);
Daniel Sandler8680bf82012-05-15 16:52:52 -04001488 if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS;
Chris Wren2c22eb02012-05-08 09:49:13 -04001489 big.removeAllViews(R.id.actions);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001490 for (int i=0; i<N; i++) {
1491 final RemoteViews button = generateActionButton(mActions.get(i));
Chris Wrend6297db2012-05-03 16:20:13 -04001492 //Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001493 big.addView(R.id.actions, button);
1494 }
1495 }
1496 return big;
1497 }
1498
Joe Onorato46439ce2010-11-19 13:56:21 -08001499 private RemoteViews makeContentView() {
1500 if (mContentView != null) {
1501 return mContentView;
1502 } else {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001503 return applyStandardTemplate(R.layout.notification_template_base, true); // no more special large_icon flavor
Joe Onorato46439ce2010-11-19 13:56:21 -08001504 }
1505 }
1506
1507 private RemoteViews makeTickerView() {
1508 if (mTickerView != null) {
1509 return mTickerView;
1510 } else {
Joe Onorato561d3852010-11-20 18:09:34 -08001511 if (mContentView == null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001512 return applyStandardTemplate(mLargeIcon == null
Joe Onorato561d3852010-11-20 18:09:34 -08001513 ? R.layout.status_bar_latest_event_ticker
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001514 : R.layout.status_bar_latest_event_ticker_large_icon, true);
Joe Onorato561d3852010-11-20 18:09:34 -08001515 } else {
1516 return null;
1517 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001518 }
1519 }
1520
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001521 private RemoteViews makeBigContentView() {
1522 if (mActions.size() == 0) return null;
1523
Chris Wrenb023bf82012-04-23 16:05:42 -04001524 return applyStandardTemplateWithActions(R.layout.notification_template_big_base);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001525 }
1526
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001527 private RemoteViews generateActionButton(Action action) {
Daniel Sandler8680bf82012-05-15 16:52:52 -04001528 final boolean tombstone = (action.actionIntent == null);
1529 RemoteViews button = new RemoteViews(mContext.getPackageName(),
1530 tombstone ? R.layout.notification_action_tombstone
1531 : R.layout.notification_action);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001532 button.setTextViewCompoundDrawables(R.id.action0, action.icon, 0, 0, 0);
1533 button.setTextViewText(R.id.action0, action.title);
Daniel Sandler8680bf82012-05-15 16:52:52 -04001534 if (!tombstone) {
Daniel Sandlere5518842012-05-10 16:20:40 -04001535 button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
Daniel Sandlere5518842012-05-10 16:20:40 -04001536 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001537 button.setContentDescription(R.id.action0, action.title);
1538 return button;
1539 }
1540
Joe Onoratocb109a02011-01-18 17:57:41 -08001541 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001542 * Apply the unstyled operations and return a new {@link Notification} object.
Joe Onoratocb109a02011-01-18 17:57:41 -08001543 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001544 private Notification buildUnstyled() {
Joe Onorato46439ce2010-11-19 13:56:21 -08001545 Notification n = new Notification();
1546 n.when = mWhen;
1547 n.icon = mSmallIcon;
1548 n.iconLevel = mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08001549 n.number = mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08001550 n.contentView = makeContentView();
1551 n.contentIntent = mContentIntent;
1552 n.deleteIntent = mDeleteIntent;
1553 n.fullScreenIntent = mFullScreenIntent;
1554 n.tickerText = mTickerText;
1555 n.tickerView = makeTickerView();
1556 n.largeIcon = mLargeIcon;
1557 n.sound = mSound;
1558 n.audioStreamType = mAudioStreamType;
1559 n.vibrate = mVibrate;
1560 n.ledARGB = mLedArgb;
1561 n.ledOnMS = mLedOnMs;
1562 n.ledOffMS = mLedOffMs;
1563 n.defaults = mDefaults;
1564 n.flags = mFlags;
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001565 n.bigContentView = makeBigContentView();
Joe Onorato8d0b6552010-11-22 16:09:29 -08001566 if (mLedOnMs != 0 && mLedOffMs != 0) {
1567 n.flags |= FLAG_SHOW_LIGHTS;
1568 }
1569 if ((mDefaults & DEFAULT_LIGHTS) != 0) {
1570 n.flags |= FLAG_SHOW_LIGHTS;
1571 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001572 if (mKindList.size() > 0) {
1573 n.kind = new String[mKindList.size()];
1574 mKindList.toArray(n.kind);
1575 } else {
1576 n.kind = null;
1577 }
1578 n.priority = mPriority;
1579 n.extras = mExtras != null ? new Bundle(mExtras) : null;
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001580 if (mActions.size() > 0) {
1581 n.actions = new Action[mActions.size()];
1582 mActions.toArray(n.actions);
1583 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001584 return n;
1585 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001586
1587 /**
1588 * @deprecated Use {@link #build()} instead.
1589 */
1590 @Deprecated
1591 public Notification getNotification() {
1592 return build();
1593 }
1594
1595 /**
1596 * Combine all of the options that have been set and return a new {@link Notification}
1597 * object.
1598 */
1599 public Notification build() {
1600 if (mStyle != null) {
1601 return mStyle.build();
1602 } else {
1603 return buildUnstyled();
1604 }
1605 }
1606 }
1607
1608
1609 /**
1610 * An object that can apply a rich notification style to a {@link Notification.Builder}
1611 * object.
1612 */
Chris Wrend6297db2012-05-03 16:20:13 -04001613 public static abstract class Style
1614 {
1615 private CharSequence mBigContentTitle;
1616 private CharSequence mSummaryText = null;
Daniel Sandler619738c2012-06-07 16:33:08 -04001617 private boolean mSummaryTextSet = false;
Chris Wrend6297db2012-05-03 16:20:13 -04001618
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001619 protected Builder mBuilder;
1620
Chris Wrend6297db2012-05-03 16:20:13 -04001621 /**
1622 * Overrides ContentTitle in the big form of the template.
1623 * This defaults to the value passed to setContentTitle().
1624 */
1625 protected void internalSetBigContentTitle(CharSequence title) {
1626 mBigContentTitle = title;
1627 }
1628
1629 /**
1630 * Set the first line of text after the detail section in the big form of the template.
1631 */
1632 protected void internalSetSummaryText(CharSequence cs) {
1633 mSummaryText = cs;
Daniel Sandler619738c2012-06-07 16:33:08 -04001634 mSummaryTextSet = true;
Chris Wrend6297db2012-05-03 16:20:13 -04001635 }
1636
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001637 public void setBuilder(Builder builder) {
1638 if (mBuilder != builder) {
1639 mBuilder = builder;
1640 mBuilder.setStyle(this);
1641 }
1642 }
1643
Chris Wrend6297db2012-05-03 16:20:13 -04001644 protected void checkBuilder() {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001645 if (mBuilder == null) {
1646 throw new IllegalArgumentException("Style requires a valid Builder object");
1647 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001648 }
Chris Wrend6297db2012-05-03 16:20:13 -04001649
1650 protected RemoteViews getStandardView(int layoutId) {
1651 checkBuilder();
1652
1653 if (mBigContentTitle != null) {
1654 mBuilder.setContentTitle(mBigContentTitle);
1655 }
1656
Chris Wrend6297db2012-05-03 16:20:13 -04001657 RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId);
1658
Chris Wrend6297db2012-05-03 16:20:13 -04001659 if (mBigContentTitle != null && mBigContentTitle.equals("")) {
1660 contentView.setViewVisibility(R.id.line1, View.GONE);
Chris Wren67dc9a02012-05-16 01:03:20 -04001661 } else {
1662 contentView.setViewVisibility(R.id.line1, View.VISIBLE);
Chris Wrend6297db2012-05-03 16:20:13 -04001663 }
1664
Daniel Sandler619738c2012-06-07 16:33:08 -04001665 // The last line defaults to the subtext, but can be replaced by mSummaryText
1666 final CharSequence overflowText =
1667 mSummaryTextSet ? mSummaryText
1668 : mBuilder.mSubText;
1669 if (overflowText != null) {
1670 contentView.setTextViewText(R.id.text, overflowText);
1671 contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001672 contentView.setViewVisibility(R.id.line3, View.VISIBLE);
Chris Wrend6297db2012-05-03 16:20:13 -04001673 }
1674
1675 return contentView;
1676 }
1677
1678 public abstract Notification build();
Joe Onorato46439ce2010-11-19 13:56:21 -08001679 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001680
1681 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001682 * Helper class for generating large-format notifications that include a large image attachment.
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001683 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001684 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001685 * <pre class="prettyprint">
1686 * Notification noti = new Notification.BigPictureStyle(
1687 * new Notification.Builder()
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001688 * .setContentTitle(&quot;New photo from &quot; + sender.toString())
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001689 * .setContentText(subject)
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001690 * .setSmallIcon(R.drawable.new_post)
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001691 * .setLargeIcon(aBitmap))
1692 * .bigPicture(aBigBitmap)
1693 * .build();
1694 * </pre>
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001695 *
1696 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001697 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001698 public static class BigPictureStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001699 private Bitmap mPicture;
Chris Wren3745a3d2012-05-22 15:11:52 -04001700 private Bitmap mBigLargeIcon;
1701 private boolean mBigLargeIconSet = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001702
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001703 public BigPictureStyle() {
1704 }
1705
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001706 public BigPictureStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001707 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001708 }
1709
Chris Wrend6297db2012-05-03 16:20:13 -04001710 /**
1711 * Overrides ContentTitle in the big form of the template.
1712 * This defaults to the value passed to setContentTitle().
1713 */
1714 public BigPictureStyle setBigContentTitle(CharSequence title) {
1715 internalSetBigContentTitle(title);
1716 return this;
1717 }
1718
1719 /**
1720 * Set the first line of text after the detail section in the big form of the template.
1721 */
1722 public BigPictureStyle setSummaryText(CharSequence cs) {
1723 internalSetSummaryText(cs);
1724 return this;
1725 }
1726
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001727 public BigPictureStyle bigPicture(Bitmap b) {
1728 mPicture = b;
1729 return this;
1730 }
1731
Chris Wren3745a3d2012-05-22 15:11:52 -04001732 /**
1733 * @hide
1734 * Override the large icon when the big notification is shown.
1735 */
1736 public BigPictureStyle bigLargeIcon(Bitmap b) {
1737 mBigLargeIconSet = true;
1738 mBigLargeIcon = b;
1739 return this;
1740 }
1741
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001742 private RemoteViews makeBigContentView() {
Chris Wrend6297db2012-05-03 16:20:13 -04001743 RemoteViews contentView = getStandardView(R.layout.notification_template_big_picture);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001744
1745 contentView.setImageViewBitmap(R.id.big_picture, mPicture);
1746
1747 return contentView;
1748 }
1749
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001750 @Override
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001751 public Notification build() {
Chris Wrend6297db2012-05-03 16:20:13 -04001752 checkBuilder();
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001753 Notification wip = mBuilder.buildUnstyled();
Chris Wren3745a3d2012-05-22 15:11:52 -04001754 if (mBigLargeIconSet ) {
1755 mBuilder.mLargeIcon = mBigLargeIcon;
1756 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001757 wip.bigContentView = makeBigContentView();
1758 return wip;
1759 }
1760 }
1761
1762 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001763 * Helper class for generating large-format notifications that include a lot of text.
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001764 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001765 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001766 * <pre class="prettyprint">
1767 * Notification noti = new Notification.BigPictureStyle(
1768 * new Notification.Builder()
1769 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
1770 * .setContentText(subject)
1771 * .setSmallIcon(R.drawable.new_mail)
1772 * .setLargeIcon(aBitmap))
1773 * .bigText(aVeryLongString)
1774 * .build();
1775 * </pre>
Daniel Sandler4dfbe832012-04-11 14:51:46 -04001776 *
1777 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001778 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001779 public static class BigTextStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001780 private CharSequence mBigText;
1781
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001782 public BigTextStyle() {
1783 }
1784
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001785 public BigTextStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001786 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001787 }
1788
Chris Wrend6297db2012-05-03 16:20:13 -04001789 /**
1790 * Overrides ContentTitle in the big form of the template.
1791 * This defaults to the value passed to setContentTitle().
1792 */
1793 public BigTextStyle setBigContentTitle(CharSequence title) {
1794 internalSetBigContentTitle(title);
1795 return this;
1796 }
1797
1798 /**
1799 * Set the first line of text after the detail section in the big form of the template.
1800 */
1801 public BigTextStyle setSummaryText(CharSequence cs) {
1802 internalSetSummaryText(cs);
1803 return this;
1804 }
1805
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001806 public BigTextStyle bigText(CharSequence cs) {
1807 mBigText = cs;
1808 return this;
1809 }
1810
1811 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04001812 // Remove the content text so line3 only shows if you have a summary
1813 final boolean hadThreeLines = (mBuilder.mContentText != null && mBuilder.mSubText != null);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001814 mBuilder.mContentText = null;
Chris Wrend6297db2012-05-03 16:20:13 -04001815 RemoteViews contentView = getStandardView(R.layout.notification_template_big_text);
Daniel Sandler619738c2012-06-07 16:33:08 -04001816
1817 if (hadThreeLines) {
1818 // vertical centering
1819 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
1820 }
1821
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001822 contentView.setTextViewText(R.id.big_text, mBigText);
1823 contentView.setViewVisibility(R.id.big_text, View.VISIBLE);
Chris Wren3c5f92432012-05-04 16:31:17 -04001824 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001825
1826 return contentView;
1827 }
1828
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001829 @Override
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001830 public Notification build() {
Chris Wrend6297db2012-05-03 16:20:13 -04001831 checkBuilder();
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001832 Notification wip = mBuilder.buildUnstyled();
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001833 wip.bigContentView = makeBigContentView();
1834 return wip;
1835 }
1836 }
Daniel Sandler879c5e02012-04-17 16:46:51 -04001837
1838 /**
1839 * Helper class for generating large-format notifications that include a list of (up to 5) strings.
1840 *
1841 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
1842 * <pre class="prettyprint">
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001843 * Notification noti = new Notification.InboxStyle(
Daniel Sandler879c5e02012-04-17 16:46:51 -04001844 * new Notification.Builder()
Chris Wrend6297db2012-05-03 16:20:13 -04001845 * .setContentTitle(&quot;5 New mails from &quot; + sender.toString())
Daniel Sandler879c5e02012-04-17 16:46:51 -04001846 * .setContentText(subject)
1847 * .setSmallIcon(R.drawable.new_mail)
1848 * .setLargeIcon(aBitmap))
1849 * .addLine(str1)
1850 * .addLine(str2)
Chris Wrend6297db2012-05-03 16:20:13 -04001851 * .setContentTitle("")
1852 * .setSummaryText(&quot;+3 more&quot;)
Daniel Sandler879c5e02012-04-17 16:46:51 -04001853 * .build();
1854 * </pre>
1855 *
1856 * @see Notification#bigContentView
1857 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001858 public static class InboxStyle extends Style {
Daniel Sandler879c5e02012-04-17 16:46:51 -04001859 private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5);
1860
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001861 public InboxStyle() {
1862 }
1863
Daniel Sandler879c5e02012-04-17 16:46:51 -04001864 public InboxStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001865 setBuilder(builder);
Daniel Sandler879c5e02012-04-17 16:46:51 -04001866 }
1867
Chris Wrend6297db2012-05-03 16:20:13 -04001868 /**
1869 * Overrides ContentTitle in the big form of the template.
1870 * This defaults to the value passed to setContentTitle().
1871 */
1872 public InboxStyle setBigContentTitle(CharSequence title) {
1873 internalSetBigContentTitle(title);
1874 return this;
1875 }
1876
1877 /**
1878 * Set the first line of text after the detail section in the big form of the template.
1879 */
1880 public InboxStyle setSummaryText(CharSequence cs) {
1881 internalSetSummaryText(cs);
1882 return this;
1883 }
1884
Daniel Sandler879c5e02012-04-17 16:46:51 -04001885 public InboxStyle addLine(CharSequence cs) {
1886 mTexts.add(cs);
1887 return this;
1888 }
1889
1890 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04001891 // Remove the content text so line3 disappears unless you have a summary
1892 mBuilder.mContentText = null;
Chris Wrend6297db2012-05-03 16:20:13 -04001893 RemoteViews contentView = getStandardView(R.layout.notification_template_inbox);
Daniel Sandler619738c2012-06-07 16:33:08 -04001894
Chris Wrend6297db2012-05-03 16:20:13 -04001895 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandler879c5e02012-04-17 16:46:51 -04001896
Chris Wrend6297db2012-05-03 16:20:13 -04001897 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 -04001898 R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6};
Chris Wrend6297db2012-05-03 16:20:13 -04001899
Chris Wren4ed80d52012-05-17 09:30:03 -04001900 // Make sure all rows are gone in case we reuse a view.
1901 for (int rowId : rowIds) {
1902 contentView.setViewVisibility(rowId, View.GONE);
1903 }
1904
Daniel Sandler879c5e02012-04-17 16:46:51 -04001905 int i=0;
1906 while (i < mTexts.size() && i < rowIds.length) {
1907 CharSequence str = mTexts.get(i);
1908 if (str != null && !str.equals("")) {
1909 contentView.setViewVisibility(rowIds[i], View.VISIBLE);
1910 contentView.setTextViewText(rowIds[i], str);
1911 }
1912 i++;
1913 }
1914
Chris Wren29bb6d92012-05-17 18:09:42 -04001915 if (mTexts.size() > rowIds.length) {
1916 contentView.setViewVisibility(R.id.inbox_more, View.VISIBLE);
1917 } else {
1918 contentView.setViewVisibility(R.id.inbox_more, View.GONE);
1919 }
1920
Daniel Sandler879c5e02012-04-17 16:46:51 -04001921 return contentView;
1922 }
1923
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001924 @Override
Daniel Sandler879c5e02012-04-17 16:46:51 -04001925 public Notification build() {
Chris Wrend6297db2012-05-03 16:20:13 -04001926 checkBuilder();
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001927 Notification wip = mBuilder.buildUnstyled();
Daniel Sandler879c5e02012-04-17 16:46:51 -04001928 wip.bigContentView = makeBigContentView();
1929 return wip;
1930 }
1931 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932}