blob: fe629f6742859c44c301a10292f276ce00b63337 [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;
Jorim Jaggi5c2d8462014-03-21 17:37:00 +010020import com.android.internal.util.LegacyNotificationUtil;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021
Tor Norbyed9273d62013-05-30 15:59:53 -070022import android.annotation.IntDef;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
24import android.content.Intent;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040025import android.content.res.Resources;
Joe Onoratoef1e7762010-09-17 18:38:38 -040026import android.graphics.Bitmap;
Jorim Jaggi5c2d8462014-03-21 17:37:00 +010027import android.graphics.PorterDuff;
Jeff Sharkey098d5802012-04-26 17:30:34 -070028import android.media.AudioManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.net.Uri;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040030import android.os.BadParcelableException;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050031import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.Parcel;
33import android.os.Parcelable;
Daniel Sandlera2985ed2012-04-03 16:42:00 -040034import android.os.SystemClock;
Jeff Sharkey6d515712012-09-20 16:06:08 -070035import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.text.TextUtils;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040037import android.util.Log;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040038import android.util.TypedValue;
Joe Onorato8595a3d2010-11-19 18:12:07 -080039import android.view.View;
Jeff Sharkey1c400132011-08-05 14:50:13 -070040import android.widget.ProgressBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.widget.RemoteViews;
42
Tor Norbyed9273d62013-05-30 15:59:53 -070043import java.lang.annotation.Retention;
44import java.lang.annotation.RetentionPolicy;
Andy Stadler110988c2010-12-03 14:29:16 -080045import java.text.NumberFormat;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050046import java.util.ArrayList;
Joe Onorato561d3852010-11-20 18:09:34 -080047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048/**
49 * A class that represents how a persistent notification is to be presented to
50 * the user using the {@link android.app.NotificationManager}.
51 *
Joe Onoratocb109a02011-01-18 17:57:41 -080052 * <p>The {@link Notification.Builder Notification.Builder} has been added to make it
53 * easier to construct Notifications.</p>
54 *
Joe Fernandez558459f2011-10-13 16:47:36 -070055 * <div class="special reference">
56 * <h3>Developer Guides</h3>
57 * <p>For a guide to creating notifications, read the
58 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a>
59 * developer guide.</p>
60 * </div>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 */
62public class Notification implements Parcelable
63{
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040064 private static final String TAG = "Notification";
65
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 /**
67 * Use all default values (where applicable).
68 */
69 public static final int DEFAULT_ALL = ~0;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 /**
72 * Use the default notification sound. This will ignore any given
73 * {@link #sound}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050074 *
75
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050077 */
78
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 public static final int DEFAULT_SOUND = 1;
80
81 /**
82 * Use the default notification vibrate. This will ignore any given
Daniel Sandler2561b0b2012-02-13 21:04:12 -050083 * {@link #vibrate}. Using phone vibration requires the
Scott Mainb8b36452009-04-26 15:50:49 -070084 * {@link android.Manifest.permission#VIBRATE VIBRATE} permission.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050085 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050087 */
88
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 public static final int DEFAULT_VIBRATE = 2;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 /**
92 * Use the default notification lights. This will ignore the
93 * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or
94 * {@link #ledOnMS}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050095 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050097 */
98
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 public static final int DEFAULT_LIGHTS = 4;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500102 * A timestamp related to this notification, in milliseconds since the epoch.
Joe Malin8d40d042012-11-05 11:36:40 -0800103 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500104 * Default value: {@link System#currentTimeMillis() Now}.
105 *
106 * Choose a timestamp that will be most relevant to the user. For most finite events, this
107 * corresponds to the time the event happened (or will happen, in the case of events that have
108 * yet to occur but about which the user is being informed). Indefinite events should be
Joe Malin8d40d042012-11-05 11:36:40 -0800109 * timestamped according to when the activity began.
110 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500111 * Some examples:
Joe Malin8d40d042012-11-05 11:36:40 -0800112 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500113 * <ul>
114 * <li>Notification of a new chat message should be stamped when the message was received.</li>
115 * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li>
116 * <li>Notification of a completed file download should be stamped when the download finished.</li>
117 * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li>
118 * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
119 * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time.
Joe Malin8d40d042012-11-05 11:36:40 -0800120 * </ul>
121 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 */
123 public long when;
124
125 /**
126 * The resource id of a drawable to use as the icon in the status bar.
Daniel Sandlerd952dae2011-02-07 16:33:36 -0500127 * This is required; notifications with an invalid icon resource will not be shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 */
129 public int icon;
130
131 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800132 * If the icon in the status bar is to have more than one level, you can set this. Otherwise,
133 * leave it at its default value of 0.
134 *
135 * @see android.widget.ImageView#setImageLevel
136 * @see android.graphics.drawable#setLevel
137 */
138 public int iconLevel;
139
140 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500141 * The number of events that this notification represents. For example, in a new mail
142 * notification, this could be the number of unread messages.
Joe Malin8d40d042012-11-05 11:36:40 -0800143 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500144 * The system may or may not use this field to modify the appearance of the notification. For
145 * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was
146 * superimposed over the icon in the status bar. Starting with
147 * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by
148 * {@link Notification.Builder} has displayed the number in the expanded notification view.
Joe Malin8d40d042012-11-05 11:36:40 -0800149 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500150 * If the number is 0 or negative, it is never shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 */
152 public int number;
153
154 /**
155 * The intent to execute when the expanded status entry is clicked. If
156 * this is an activity, it must include the
157 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -0800158 * that you take care of task management as described in the
159 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
Dianne Hackborn6ceca582012-01-10 15:24:26 -0800160 * Stack</a> document. In particular, make sure to read the notification section
161 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling
162 * Notifications</a> for the correct ways to launch an application from a
163 * notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 */
165 public PendingIntent contentIntent;
166
167 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500168 * The intent to execute when the notification is explicitly dismissed by the user, either with
169 * the "Clear All" button or by swiping it away individually.
170 *
171 * This probably shouldn't be launching an activity since several of those will be sent
172 * at the same time.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 */
174 public PendingIntent deleteIntent;
175
176 /**
Dianne Hackborn170bae72010-09-03 15:14:28 -0700177 * An intent to launch instead of posting the notification to the status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -0800178 *
179 * @see Notification.Builder#setFullScreenIntent
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400180 */
181 public PendingIntent fullScreenIntent;
182
183 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 * Text to scroll across the screen when this item is added to
Joe Onoratoef1e7762010-09-17 18:38:38 -0400185 * the status bar on large and smaller devices.
186 *
Joe Onorato46439ce2010-11-19 13:56:21 -0800187 * @see #tickerView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 */
189 public CharSequence tickerText;
190
191 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800192 * The view to show as the ticker in the status bar when the notification
193 * is posted.
Joe Onoratoef1e7762010-09-17 18:38:38 -0400194 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800195 public RemoteViews tickerView;
Joe Onoratoef1e7762010-09-17 18:38:38 -0400196
197 /**
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400198 * The view that will represent this notification in the expanded status bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 */
200 public RemoteViews contentView;
201
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400202 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -0400203 * A large-format version of {@link #contentView}, giving the Notification an
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400204 * opportunity to show more detail. The system UI may choose to show this
205 * instead of the normal content view at its discretion.
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400206 */
207 public RemoteViews bigContentView;
208
Chris Wren8fd39ec2014-02-27 17:43:26 -0500209
210 /**
211 * @hide
212 * A medium-format version of {@link #contentView}, giving the Notification an
213 * opportunity to add action buttons to contentView. The system UI may
214 * choose to show this as a popup notification at its discretion.
215 */
216 public RemoteViews headsUpContentView;
217
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400218 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800219 * The bitmap that may escape the bounds of the panel and bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800221 public Bitmap largeIcon;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222
223 /**
224 * The sound to play.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500225 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 * <p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500227 * To play the default notification sound, see {@link #defaults}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 * </p>
229 */
230 public Uri sound;
231
232 /**
233 * Use this constant as the value for audioStreamType to request that
234 * the default stream type for notifications be used. Currently the
Jeff Sharkey098d5802012-04-26 17:30:34 -0700235 * default stream type is {@link AudioManager#STREAM_NOTIFICATION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 */
237 public static final int STREAM_DEFAULT = -1;
238
239 /**
240 * The audio stream type to use when playing the sound.
241 * Should be one of the STREAM_ constants from
242 * {@link android.media.AudioManager}.
243 */
244 public int audioStreamType = STREAM_DEFAULT;
245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500247 * The pattern with which to vibrate.
248 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 * <p>
250 * To vibrate the default pattern, see {@link #defaults}.
251 * </p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500252 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 * @see android.os.Vibrator#vibrate(long[],int)
254 */
255 public long[] vibrate;
256
257 /**
258 * The color of the led. The hardware will do its best approximation.
259 *
260 * @see #FLAG_SHOW_LIGHTS
261 * @see #flags
262 */
263 public int ledARGB;
264
265 /**
266 * The number of milliseconds for the LED to be on while it's flashing.
267 * The hardware will do its best approximation.
268 *
269 * @see #FLAG_SHOW_LIGHTS
270 * @see #flags
271 */
272 public int ledOnMS;
273
274 /**
275 * The number of milliseconds for the LED to be off while it's flashing.
276 * The hardware will do its best approximation.
277 *
278 * @see #FLAG_SHOW_LIGHTS
279 * @see #flags
280 */
281 public int ledOffMS;
282
283 /**
284 * Specifies which values should be taken from the defaults.
285 * <p>
286 * To set, OR the desired from {@link #DEFAULT_SOUND},
287 * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default
288 * values, use {@link #DEFAULT_ALL}.
289 * </p>
290 */
291 public int defaults;
292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 /**
294 * Bit to be bitwise-ored into the {@link #flags} field that should be
295 * set if you want the LED on for this notification.
296 * <ul>
297 * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB
298 * or 0 for both ledOnMS and ledOffMS.</li>
299 * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li>
300 * <li>To flash the LED, pass the number of milliseconds that it should
301 * be on and off to ledOnMS and ledOffMS.</li>
302 * </ul>
303 * <p>
304 * Since hardware varies, you are not guaranteed that any of the values
305 * you pass are honored exactly. Use the system defaults (TODO) if possible
306 * because they will be set to values that work on any given hardware.
307 * <p>
308 * The alpha channel must be set for forward compatibility.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500309 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 */
311 public static final int FLAG_SHOW_LIGHTS = 0x00000001;
312
313 /**
314 * Bit to be bitwise-ored into the {@link #flags} field that should be
315 * set if this notification is in reference to something that is ongoing,
316 * like a phone call. It should not be set if this notification is in
317 * reference to something that happened at a particular point in time,
318 * like a missed phone call.
319 */
320 public static final int FLAG_ONGOING_EVENT = 0x00000002;
321
322 /**
323 * Bit to be bitwise-ored into the {@link #flags} field that if set,
Scott Mainb8b36452009-04-26 15:50:49 -0700324 * the audio will be repeated until the notification is
325 * cancelled or the notification window is opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 */
327 public static final int FLAG_INSISTENT = 0x00000004;
328
329 /**
330 * Bit to be bitwise-ored into the {@link #flags} field that should be
331 * set if you want the sound and/or vibration play each time the
332 * notification is sent, even if it has not been canceled before that.
333 */
334 public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008;
335
336 /**
337 * Bit to be bitwise-ored into the {@link #flags} field that should be
338 * set if the notification should be canceled when it is clicked by the
Daniel Sandler8aa9ae62012-12-04 23:31:47 -0500339 * user.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 */
342 public static final int FLAG_AUTO_CANCEL = 0x00000010;
343
344 /**
345 * Bit to be bitwise-ored into the {@link #flags} field that should be
346 * set if the notification should not be canceled when the user clicks
347 * the Clear all button.
348 */
349 public static final int FLAG_NO_CLEAR = 0x00000020;
350
Dianne Hackbornd8a43f62009-08-17 23:33:56 -0700351 /**
352 * Bit to be bitwise-ored into the {@link #flags} field that should be
353 * set if this notification represents a currently running service. This
354 * will normally be set for you by {@link Service#startForeground}.
355 */
356 public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;
357
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400358 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500359 * Obsolete flag indicating high-priority notifications; use the priority field instead.
Joe Malin8d40d042012-11-05 11:36:40 -0800360 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500361 * @deprecated Use {@link #priority} with a positive value.
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400362 */
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500363 public static final int FLAG_HIGH_PRIORITY = 0x00000080;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400364
Griff Hazendfcb0802014-02-11 12:00:00 -0800365 /**
366 * Bit to be bitswise-ored into the {@link #flags} field that should be
367 * set if this notification is relevant to the current device only
368 * and it is not recommended that it bridge to other devices.
369 */
370 public static final int FLAG_LOCAL_ONLY = 0x00000100;
371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 public int flags;
373
Tor Norbyed9273d62013-05-30 15:59:53 -0700374 /** @hide */
375 @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX})
376 @Retention(RetentionPolicy.SOURCE)
377 public @interface Priority {}
378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500380 * Default notification {@link #priority}. If your application does not prioritize its own
381 * notifications, use this value for all notifications.
382 */
383 public static final int PRIORITY_DEFAULT = 0;
384
385 /**
386 * Lower {@link #priority}, for items that are less important. The UI may choose to show these
387 * items smaller, or at a different position in the list, compared with your app's
388 * {@link #PRIORITY_DEFAULT} items.
389 */
390 public static final int PRIORITY_LOW = -1;
391
392 /**
393 * Lowest {@link #priority}; these items might not be shown to the user except under special
394 * circumstances, such as detailed notification logs.
395 */
396 public static final int PRIORITY_MIN = -2;
397
398 /**
399 * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to
400 * show these items larger, or at a different position in notification lists, compared with
401 * your app's {@link #PRIORITY_DEFAULT} items.
402 */
403 public static final int PRIORITY_HIGH = 1;
404
405 /**
406 * Highest {@link #priority}, for your application's most important items that require the
407 * user's prompt attention or input.
408 */
409 public static final int PRIORITY_MAX = 2;
410
411 /**
412 * Relative priority for this notification.
Joe Malin8d40d042012-11-05 11:36:40 -0800413 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500414 * Priority is an indication of how much of the user's valuable attention should be consumed by
415 * this notification. Low-priority notifications may be hidden from the user in certain
416 * situations, while the user might be interrupted for a higher-priority notification. The
Daniel Sandler6738eee2012-11-16 12:03:32 -0500417 * system will make a determination about how to interpret this priority when presenting
418 * the notification.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500419 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700420 @Priority
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500421 public int priority;
Joe Malin8d40d042012-11-05 11:36:40 -0800422
Dan Sandler0bf2ed82013-12-21 23:33:41 -0600423
424 /**
425 * Sphere of visibility of this notification, which affects how and when the SystemUI reveals
426 * the notification's presence and contents in untrusted situations (namely, on the secure
427 * lockscreen).
428 *
429 * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always
430 * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are
431 * shown in all situations, but the contents are only available if the device is unlocked for
432 * the appropriate user.
433 *
434 * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification
435 * can be read even in an "insecure" context (that is, above a secure lockscreen).
436 * To modify the public version of this notification—for example, to redact some portions—see
437 * {@link Builder#setPublicVersion(Notification)}.
438 *
439 * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon
440 * and ticker until the user has bypassed the lockscreen.
441 */
442 public int visibility;
443
444 public static final int VISIBILITY_PUBLIC = 1;
445 public static final int VISIBILITY_PRIVATE = 0;
446 public static final int VISIBILITY_SECRET = -1;
447
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500448 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400449 * Notification category: incoming call (voice or video) or similar synchronous communication request.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500450 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400451 public static final String CATEGORY_CALL = "call";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500452
453 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400454 * Notification category: incoming direct message (SMS, instant message, etc.).
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500455 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400456 public static final String CATEGORY_MESSAGE = "msg";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500457
458 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400459 * Notification category: asynchronous bulk message (email).
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500460 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400461 public static final String CATEGORY_EMAIL = "email";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500462
463 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400464 * Notification category: calendar event.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500465 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400466 public static final String CATEGORY_EVENT = "event";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500467
468 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400469 * Notification category: promotion or advertisement.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500470 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400471 public static final String CATEGORY_PROMO = "promo";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500472
473 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400474 * Notification category: alarm or timer.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500475 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400476 public static final String CATEGORY_ALARM = "alarm";
477
478 /**
479 * Notification category: progress of a long-running background operation.
480 */
481 public static final String CATEGORY_PROGRESS = "progress";
482
483 /**
484 * Notification category: social network or sharing update.
485 */
486 public static final String CATEGORY_SOCIAL = "social";
487
488 /**
489 * Notification category: error in background operation or authentication status.
490 */
491 public static final String CATEGORY_ERROR = "err";
492
493 /**
494 * Notification category: media transport control for playback.
495 */
496 public static final String CATEGORY_TRANSPORT = "transport";
497
498 /**
499 * Notification category: system or device status update. Reserved for system use.
500 */
501 public static final String CATEGORY_SYSTEM = "sys";
502
503 /**
504 * Notification category: indication of running background service.
505 */
506 public static final String CATEGORY_SERVICE = "service";
507
508 /**
John Spurlock0a69c8c2014-03-21 13:30:57 -0400509 * Notification category: a specific, timely recommendation for a single thing.
510 * For example, a news app might want to recommend a news story it believes the user will
511 * want to read next.
512 */
513 public static final String CATEGORY_RECOMMENDATION = "recommendation";
514
515 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400516 * Notification category: ongoing information about device or contextual status.
517 */
518 public static final String CATEGORY_STATUS = "status";
519
520 /**
521 * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants)
522 * that best describes this Notification. May be used by the system for ranking and filtering.
523 */
524 public String category;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500525
526 /**
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400527 * Additional semantic data to be carried around with this Notification.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400528 * <p>
529 * The extras keys defined here are intended to capture the original inputs to {@link Builder}
530 * APIs, and are intended to be used by
531 * {@link android.service.notification.NotificationListenerService} implementations to extract
532 * detailed information from notification objects.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500533 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400534 public Bundle extras = new Bundle();
535
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400536 /**
537 * {@link #extras} key: this is the title of the notification,
538 * as supplied to {@link Builder#setContentTitle(CharSequence)}.
539 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500540 public static final String EXTRA_TITLE = "android.title";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400541
542 /**
543 * {@link #extras} key: this is the title of the notification when shown in expanded form,
544 * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}.
545 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400546 public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400547
548 /**
549 * {@link #extras} key: this is the main text payload, as supplied to
550 * {@link Builder#setContentText(CharSequence)}.
551 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500552 public static final String EXTRA_TEXT = "android.text";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400553
554 /**
555 * {@link #extras} key: this is a third line of text, as supplied to
556 * {@link Builder#setSubText(CharSequence)}.
557 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400558 public static final String EXTRA_SUB_TEXT = "android.subText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400559
560 /**
561 * {@link #extras} key: this is a small piece of additional text as supplied to
562 * {@link Builder#setContentInfo(CharSequence)}.
563 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400564 public static final String EXTRA_INFO_TEXT = "android.infoText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400565
566 /**
567 * {@link #extras} key: this is a line of summary information intended to be shown
568 * alongside expanded notifications, as supplied to (e.g.)
569 * {@link BigTextStyle#setSummaryText(CharSequence)}.
570 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400571 public static final String EXTRA_SUMMARY_TEXT = "android.summaryText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400572
573 /**
574 * {@link #extras} key: this is the resource ID of the notification's main small icon, as
575 * supplied to {@link Builder#setSmallIcon(int)}.
576 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500577 public static final String EXTRA_SMALL_ICON = "android.icon";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400578
579 /**
580 * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the
581 * notification payload, as
582 * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}.
583 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400584 public static final String EXTRA_LARGE_ICON = "android.largeIcon";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400585
586 /**
587 * {@link #extras} key: this is a bitmap to be used instead of the one from
588 * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is
589 * shown in its expanded form, as supplied to
590 * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}.
591 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400592 public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400593
594 /**
595 * {@link #extras} key: this is the progress value supplied to
596 * {@link Builder#setProgress(int, int, boolean)}.
597 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400598 public static final String EXTRA_PROGRESS = "android.progress";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400599
600 /**
601 * {@link #extras} key: this is the maximum value supplied to
602 * {@link Builder#setProgress(int, int, boolean)}.
603 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400604 public static final String EXTRA_PROGRESS_MAX = "android.progressMax";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400605
606 /**
607 * {@link #extras} key: whether the progress bar is indeterminate, supplied to
608 * {@link Builder#setProgress(int, int, boolean)}.
609 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400610 public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400611
612 /**
613 * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically
614 * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to
615 * {@link Builder#setUsesChronometer(boolean)}.
616 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400617 public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400618
619 /**
620 * {@link #extras} key: whether {@link #when} should be shown,
621 * as supplied to {@link Builder#setShowWhen(boolean)}.
622 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400623 public static final String EXTRA_SHOW_WHEN = "android.showWhen";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400624
625 /**
626 * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded
627 * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}.
628 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400629 public static final String EXTRA_PICTURE = "android.picture";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400630
631 /**
632 * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded
633 * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}.
634 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400635 public static final String EXTRA_TEXT_LINES = "android.textLines";
Chris Wren91ad5632013-06-05 15:05:57 -0400636 public static final String EXTRA_TEMPLATE = "android.template";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400637
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400638 /**
639 * {@link #extras} key: An array of people that this notification relates to, specified
640 * by contacts provider contact URI.
641 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400642 public static final String EXTRA_PEOPLE = "android.people";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500643
644 /**
Scott Greenwald9a05b312013-06-28 00:37:54 -0400645 * @hide
646 * Extra added by NotificationManagerService to indicate whether a NotificationScorer
647 * modified the Notifications's score.
648 */
649 public static final String EXTRA_SCORE_MODIFIED = "android.scoreModified";
650
651 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400652 * Not used.
Chris Wren51c75102013-07-16 20:49:17 -0400653 * @hide
654 */
655 public static final String EXTRA_AS_HEADS_UP = "headsup";
656
657 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400658 * Allow certain system-generated notifications to appear before the device is provisioned.
659 * Only available to notifications coming from the android package.
660 * @hide
661 */
662 public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup";
663
664 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400665 * Value for {@link #EXTRA_AS_HEADS_UP}.
Chris Wren51c75102013-07-16 20:49:17 -0400666 * @hide
667 */
668 public static final int HEADS_UP_NEVER = 0;
669
670 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400671 * Default value for {@link #EXTRA_AS_HEADS_UP}.
Chris Wren51c75102013-07-16 20:49:17 -0400672 * @hide
673 */
674 public static final int HEADS_UP_ALLOWED = 1;
675
676 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400677 * Value for {@link #EXTRA_AS_HEADS_UP}.
Chris Wren51c75102013-07-16 20:49:17 -0400678 * @hide
679 */
680 public static final int HEADS_UP_REQUESTED = 2;
681
682 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400683 * Structure to encapsulate a named action that can be shown as part of this notification.
684 * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is
685 * selected by the user.
686 * <p>
687 * Apps should use {@link Builder#addAction(int, CharSequence, PendingIntent)} to create and
688 * attach actions.
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400689 */
Daniel Sandlerea2a3172013-02-20 22:24:20 -0500690 public static class Action implements Parcelable {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400691 /**
692 * Small icon representing the action.
693 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400694 public int icon;
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400695 /**
696 * Title of the action.
697 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400698 public CharSequence title;
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400699 /**
700 * Intent to send when the user invokes this action. May be null, in which case the action
701 * may be rendered in a disabled presentation by the system UI.
702 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400703 public PendingIntent actionIntent;
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400704
705 private Action() { }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400706 private Action(Parcel in) {
707 icon = in.readInt();
708 title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
709 if (in.readInt() == 1) {
710 actionIntent = PendingIntent.CREATOR.createFromParcel(in);
711 }
712 }
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400713 /**
714 * Use {@link Builder#addAction(int, CharSequence, PendingIntent)}.
715 */
716 public Action(int icon, CharSequence title, PendingIntent intent) {
717 this.icon = icon;
718 this.title = title;
719 this.actionIntent = intent;
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400720 }
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400721
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400722 @Override
723 public Action clone() {
724 return new Action(
725 this.icon,
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400726 this.title,
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400727 this.actionIntent // safe to alias
728 );
729 }
730 @Override
731 public int describeContents() {
732 return 0;
733 }
734 @Override
735 public void writeToParcel(Parcel out, int flags) {
736 out.writeInt(icon);
737 TextUtils.writeToParcel(title, out, flags);
738 if (actionIntent != null) {
739 out.writeInt(1);
740 actionIntent.writeToParcel(out, flags);
741 } else {
742 out.writeInt(0);
743 }
744 }
745 public static final Parcelable.Creator<Action> CREATOR
746 = new Parcelable.Creator<Action>() {
747 public Action createFromParcel(Parcel in) {
748 return new Action(in);
749 }
750 public Action[] newArray(int size) {
751 return new Action[size];
752 }
753 };
754 }
755
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400756 /**
757 * Array of all {@link Action} structures attached to this notification by
758 * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of
759 * {@link android.service.notification.NotificationListenerService} that provide an alternative
760 * interface for invoking actions.
761 */
Daniel Sandlerea2a3172013-02-20 22:24:20 -0500762 public Action[] actions;
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400763
764 /**
Dan Sandler0bf2ed82013-12-21 23:33:41 -0600765 * Replacement version of this notification whose content will be shown
766 * in an insecure context such as atop a secure keyguard. See {@link #visibility}
767 * and {@link #VISIBILITY_PUBLIC}.
768 */
769 public Notification publicVersion;
770
771 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500772 * Constructs a Notification object with default values.
Joe Onorato46439ce2010-11-19 13:56:21 -0800773 * You might want to consider using {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 */
775 public Notification()
776 {
777 this.when = System.currentTimeMillis();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500778 this.priority = PRIORITY_DEFAULT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 }
780
781 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 * @hide
783 */
784 public Notification(Context context, int icon, CharSequence tickerText, long when,
785 CharSequence contentTitle, CharSequence contentText, Intent contentIntent)
786 {
787 this.when = when;
788 this.icon = icon;
789 this.tickerText = tickerText;
790 setLatestEventInfo(context, contentTitle, contentText,
791 PendingIntent.getActivity(context, 0, contentIntent, 0));
792 }
793
794 /**
795 * Constructs a Notification object with the information needed to
796 * have a status bar icon without the standard expanded view.
797 *
798 * @param icon The resource id of the icon to put in the status bar.
799 * @param tickerText The text that flows by in the status bar when the notification first
800 * activates.
801 * @param when The time to show in the time field. In the System.currentTimeMillis
802 * timebase.
Joe Onorato46439ce2010-11-19 13:56:21 -0800803 *
804 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800806 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 public Notification(int icon, CharSequence tickerText, long when)
808 {
809 this.icon = icon;
810 this.tickerText = tickerText;
811 this.when = when;
812 }
813
814 /**
815 * Unflatten the notification from a parcel.
816 */
817 public Notification(Parcel parcel)
818 {
819 int version = parcel.readInt();
820
821 when = parcel.readLong();
822 icon = parcel.readInt();
823 number = parcel.readInt();
824 if (parcel.readInt() != 0) {
825 contentIntent = PendingIntent.CREATOR.createFromParcel(parcel);
826 }
827 if (parcel.readInt() != 0) {
828 deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel);
829 }
830 if (parcel.readInt() != 0) {
831 tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
832 }
833 if (parcel.readInt() != 0) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800834 tickerView = RemoteViews.CREATOR.createFromParcel(parcel);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400835 }
836 if (parcel.readInt() != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 contentView = RemoteViews.CREATOR.createFromParcel(parcel);
838 }
Joe Onorato561d3852010-11-20 18:09:34 -0800839 if (parcel.readInt() != 0) {
840 largeIcon = Bitmap.CREATOR.createFromParcel(parcel);
841 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 defaults = parcel.readInt();
843 flags = parcel.readInt();
844 if (parcel.readInt() != 0) {
845 sound = Uri.CREATOR.createFromParcel(parcel);
846 }
847
848 audioStreamType = parcel.readInt();
849 vibrate = parcel.createLongArray();
850 ledARGB = parcel.readInt();
851 ledOnMS = parcel.readInt();
852 ledOffMS = parcel.readInt();
853 iconLevel = parcel.readInt();
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400854
855 if (parcel.readInt() != 0) {
856 fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel);
857 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500858
859 priority = parcel.readInt();
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400860
John Spurlockfd7f1e02014-03-18 16:41:57 -0400861 category = parcel.readString();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500862
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500863 extras = parcel.readBundle(); // may be null
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400864
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500865 actions = parcel.createTypedArray(Action.CREATOR); // may be null
866
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400867 if (parcel.readInt() != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400868 bigContentView = RemoteViews.CREATOR.createFromParcel(parcel);
869 }
Dan Sandler0bf2ed82013-12-21 23:33:41 -0600870
Chris Wren8fd39ec2014-02-27 17:43:26 -0500871 if (parcel.readInt() != 0) {
872 headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel);
873 }
874
Dan Sandler0bf2ed82013-12-21 23:33:41 -0600875 visibility = parcel.readInt();
876
877 if (parcel.readInt() != 0) {
878 publicVersion = Notification.CREATOR.createFromParcel(parcel);
879 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 }
881
Andy Stadler110988c2010-12-03 14:29:16 -0800882 @Override
Joe Onorato18e69df2010-05-17 22:26:12 -0700883 public Notification clone() {
884 Notification that = new Notification();
Daniel Sandler1a497d32013-04-18 14:52:45 -0400885 cloneInto(that, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500886 return that;
887 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700888
Daniel Sandler1a497d32013-04-18 14:52:45 -0400889 /**
890 * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members
891 * of this into that.
892 * @hide
893 */
894 public void cloneInto(Notification that, boolean heavy) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700895 that.when = this.when;
896 that.icon = this.icon;
897 that.number = this.number;
898
899 // PendingIntents are global, so there's no reason (or way) to clone them.
900 that.contentIntent = this.contentIntent;
901 that.deleteIntent = this.deleteIntent;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400902 that.fullScreenIntent = this.fullScreenIntent;
Joe Onorato18e69df2010-05-17 22:26:12 -0700903
904 if (this.tickerText != null) {
905 that.tickerText = this.tickerText.toString();
906 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400907 if (heavy && this.tickerView != null) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800908 that.tickerView = this.tickerView.clone();
Joe Onoratoef1e7762010-09-17 18:38:38 -0400909 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400910 if (heavy && this.contentView != null) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700911 that.contentView = this.contentView.clone();
912 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400913 if (heavy && this.largeIcon != null) {
Joe Onorato561d3852010-11-20 18:09:34 -0800914 that.largeIcon = Bitmap.createBitmap(this.largeIcon);
915 }
Jozef BABJAKa8b91832011-02-22 08:05:08 +0100916 that.iconLevel = this.iconLevel;
Joe Onorato18e69df2010-05-17 22:26:12 -0700917 that.sound = this.sound; // android.net.Uri is immutable
918 that.audioStreamType = this.audioStreamType;
919
920 final long[] vibrate = this.vibrate;
921 if (vibrate != null) {
922 final int N = vibrate.length;
923 final long[] vib = that.vibrate = new long[N];
924 System.arraycopy(vibrate, 0, vib, 0, N);
925 }
926
927 that.ledARGB = this.ledARGB;
928 that.ledOnMS = this.ledOnMS;
929 that.ledOffMS = this.ledOffMS;
930 that.defaults = this.defaults;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500931
Joe Onorato18e69df2010-05-17 22:26:12 -0700932 that.flags = this.flags;
933
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500934 that.priority = this.priority;
Joe Malin8d40d042012-11-05 11:36:40 -0800935
John Spurlockfd7f1e02014-03-18 16:41:57 -0400936 that.category = this.category;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500937
938 if (this.extras != null) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -0400939 try {
940 that.extras = new Bundle(this.extras);
941 // will unparcel
942 that.extras.size();
943 } catch (BadParcelableException e) {
944 Log.e(TAG, "could not unparcel extras from notification: " + this, e);
945 that.extras = null;
946 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500947 }
948
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500949 if (this.actions != null) {
950 that.actions = new Action[this.actions.length];
951 for(int i=0; i<this.actions.length; i++) {
952 that.actions[i] = this.actions[i].clone();
953 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400954 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500955
Daniel Sandler1a497d32013-04-18 14:52:45 -0400956 if (heavy && this.bigContentView != null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400957 that.bigContentView = this.bigContentView.clone();
958 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400959
Chris Wren8fd39ec2014-02-27 17:43:26 -0500960 if (heavy && this.headsUpContentView != null) {
961 that.headsUpContentView = this.headsUpContentView.clone();
962 }
963
Dan Sandler0bf2ed82013-12-21 23:33:41 -0600964 that.visibility = this.visibility;
965
966 if (this.publicVersion != null) {
967 that.publicVersion = new Notification();
968 this.publicVersion.cloneInto(that.publicVersion, heavy);
969 }
970
Daniel Sandler1a497d32013-04-18 14:52:45 -0400971 if (!heavy) {
972 that.lightenPayload(); // will clean out extras
973 }
974 }
975
976 /**
977 * Removes heavyweight parts of the Notification object for archival or for sending to
978 * listeners when the full contents are not necessary.
979 * @hide
980 */
981 public final void lightenPayload() {
982 tickerView = null;
983 contentView = null;
984 bigContentView = null;
Chris Wren8fd39ec2014-02-27 17:43:26 -0500985 headsUpContentView = null;
Daniel Sandler1a497d32013-04-18 14:52:45 -0400986 largeIcon = null;
987 if (extras != null) {
988 extras.remove(Notification.EXTRA_LARGE_ICON);
989 extras.remove(Notification.EXTRA_LARGE_ICON_BIG);
990 extras.remove(Notification.EXTRA_PICTURE);
991 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700992 }
993
Daniel Sandlerdcbaf662013-04-26 16:23:09 -0400994 /**
995 * Make sure this CharSequence is safe to put into a bundle, which basically
996 * means it had better not be some custom Parcelable implementation.
997 * @hide
998 */
999 public static CharSequence safeCharSequence(CharSequence cs) {
1000 if (cs instanceof Parcelable) {
1001 Log.e(TAG, "warning: " + cs.getClass().getCanonicalName()
1002 + " instance is a custom Parcelable and not allowed in Notification");
1003 return cs.toString();
1004 }
1005
1006 return cs;
1007 }
1008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 public int describeContents() {
1010 return 0;
1011 }
1012
1013 /**
1014 * Flatten this notification from a parcel.
1015 */
1016 public void writeToParcel(Parcel parcel, int flags)
1017 {
1018 parcel.writeInt(1);
1019
1020 parcel.writeLong(when);
1021 parcel.writeInt(icon);
1022 parcel.writeInt(number);
1023 if (contentIntent != null) {
1024 parcel.writeInt(1);
1025 contentIntent.writeToParcel(parcel, 0);
1026 } else {
1027 parcel.writeInt(0);
1028 }
1029 if (deleteIntent != null) {
1030 parcel.writeInt(1);
1031 deleteIntent.writeToParcel(parcel, 0);
1032 } else {
1033 parcel.writeInt(0);
1034 }
1035 if (tickerText != null) {
1036 parcel.writeInt(1);
1037 TextUtils.writeToParcel(tickerText, parcel, flags);
1038 } else {
1039 parcel.writeInt(0);
1040 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001041 if (tickerView != null) {
Joe Onoratoef1e7762010-09-17 18:38:38 -04001042 parcel.writeInt(1);
Joe Onorato46439ce2010-11-19 13:56:21 -08001043 tickerView.writeToParcel(parcel, 0);
Joe Onoratoef1e7762010-09-17 18:38:38 -04001044 } else {
1045 parcel.writeInt(0);
1046 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 if (contentView != null) {
1048 parcel.writeInt(1);
1049 contentView.writeToParcel(parcel, 0);
1050 } else {
1051 parcel.writeInt(0);
1052 }
Joe Onorato561d3852010-11-20 18:09:34 -08001053 if (largeIcon != null) {
1054 parcel.writeInt(1);
1055 largeIcon.writeToParcel(parcel, 0);
1056 } else {
1057 parcel.writeInt(0);
1058 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059
1060 parcel.writeInt(defaults);
1061 parcel.writeInt(this.flags);
1062
1063 if (sound != null) {
1064 parcel.writeInt(1);
1065 sound.writeToParcel(parcel, 0);
1066 } else {
1067 parcel.writeInt(0);
1068 }
1069 parcel.writeInt(audioStreamType);
1070 parcel.writeLongArray(vibrate);
1071 parcel.writeInt(ledARGB);
1072 parcel.writeInt(ledOnMS);
1073 parcel.writeInt(ledOffMS);
1074 parcel.writeInt(iconLevel);
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001075
1076 if (fullScreenIntent != null) {
1077 parcel.writeInt(1);
1078 fullScreenIntent.writeToParcel(parcel, 0);
1079 } else {
1080 parcel.writeInt(0);
1081 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001082
1083 parcel.writeInt(priority);
Joe Malin8d40d042012-11-05 11:36:40 -08001084
John Spurlockfd7f1e02014-03-18 16:41:57 -04001085 parcel.writeString(category);
Joe Malin8d40d042012-11-05 11:36:40 -08001086
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001087 parcel.writeBundle(extras); // null ok
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001088
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001089 parcel.writeTypedArray(actions, 0); // null ok
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001090
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001091 if (bigContentView != null) {
1092 parcel.writeInt(1);
1093 bigContentView.writeToParcel(parcel, 0);
1094 } else {
1095 parcel.writeInt(0);
1096 }
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001097
Chris Wren8fd39ec2014-02-27 17:43:26 -05001098 if (headsUpContentView != null) {
1099 parcel.writeInt(1);
1100 headsUpContentView.writeToParcel(parcel, 0);
1101 } else {
1102 parcel.writeInt(0);
1103 }
1104
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001105 parcel.writeInt(visibility);
1106
1107 if (publicVersion != null) {
1108 parcel.writeInt(1);
1109 publicVersion.writeToParcel(parcel, 0);
1110 } else {
1111 parcel.writeInt(0);
1112 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 }
1114
1115 /**
1116 * Parcelable.Creator that instantiates Notification objects
1117 */
1118 public static final Parcelable.Creator<Notification> CREATOR
1119 = new Parcelable.Creator<Notification>()
1120 {
1121 public Notification createFromParcel(Parcel parcel)
1122 {
1123 return new Notification(parcel);
1124 }
1125
1126 public Notification[] newArray(int size)
1127 {
1128 return new Notification[size];
1129 }
1130 };
1131
1132 /**
1133 * Sets the {@link #contentView} field to be a view with the standard "Latest Event"
1134 * layout.
1135 *
1136 * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields
1137 * in the view.</p>
1138 * @param context The context for your application / activity.
1139 * @param contentTitle The title that goes in the expanded entry.
1140 * @param contentText The text that goes in the expanded entry.
1141 * @param contentIntent The intent to launch when the user clicks the expanded notification.
1142 * If this is an activity, it must include the
1143 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -08001144 * that you take care of task management as described in the
1145 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
1146 * Stack</a> document.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001147 *
Joe Onorato46439ce2010-11-19 13:56:21 -08001148 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001150 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 public void setLatestEventInfo(Context context,
1152 CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001153 Notification.Builder builder = new Notification.Builder(context);
1154
1155 // First, ensure that key pieces of information that may have been set directly
1156 // are preserved
1157 builder.setWhen(this.when);
1158 builder.setSmallIcon(this.icon);
1159 builder.setPriority(this.priority);
1160 builder.setTicker(this.tickerText);
1161 builder.setNumber(this.number);
1162 builder.mFlags = this.flags;
1163 builder.setSound(this.sound, this.audioStreamType);
1164 builder.setDefaults(this.defaults);
1165 builder.setVibrate(this.vibrate);
1166
1167 // now apply the latestEventInfo fields
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 if (contentTitle != null) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001169 builder.setContentTitle(contentTitle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 }
1171 if (contentText != null) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001172 builder.setContentText(contentText);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001174 builder.setContentIntent(contentIntent);
1175 builder.buildInto(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 }
1177
1178 @Override
1179 public String toString() {
1180 StringBuilder sb = new StringBuilder();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001181 sb.append("Notification(pri=");
1182 sb.append(priority);
1183 sb.append(" contentView=");
Joe Onoratoc9596d62011-01-12 17:03:11 -08001184 if (contentView != null) {
1185 sb.append(contentView.getPackage());
1186 sb.append("/0x");
1187 sb.append(Integer.toHexString(contentView.getLayoutId()));
1188 } else {
1189 sb.append("null");
1190 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001191 // TODO(dsandler): defaults take precedence over local values, so reorder the branches below
Joe Onoratoc9596d62011-01-12 17:03:11 -08001192 sb.append(" vibrate=");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001193 if ((this.defaults & DEFAULT_VIBRATE) != 0) {
1194 sb.append("default");
1195 } else if (this.vibrate != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001196 int N = this.vibrate.length-1;
1197 sb.append("[");
1198 for (int i=0; i<N; i++) {
1199 sb.append(this.vibrate[i]);
1200 sb.append(',');
1201 }
Simon Schoar8cf97d92009-06-10 22:08:37 +02001202 if (N != -1) {
1203 sb.append(this.vibrate[N]);
1204 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 sb.append("]");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 } else {
1207 sb.append("null");
1208 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001209 sb.append(" sound=");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001210 if ((this.defaults & DEFAULT_SOUND) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 sb.append("default");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001212 } else if (this.sound != null) {
1213 sb.append(this.sound.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 } else {
1215 sb.append("null");
1216 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001217 sb.append(" defaults=0x");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001218 sb.append(Integer.toHexString(this.defaults));
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001219 sb.append(" flags=0x");
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001220 sb.append(Integer.toHexString(this.flags));
John Spurlockfd7f1e02014-03-18 16:41:57 -04001221 sb.append(" category="); sb.append(this.category);
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001222 if (actions != null) {
1223 sb.append(" ");
1224 sb.append(actions.length);
1225 sb.append(" action");
1226 if (actions.length > 1) sb.append("s");
1227 }
1228 sb.append(")");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 return sb.toString();
1230 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001231
Jeff Sharkey6d515712012-09-20 16:06:08 -07001232 /** {@hide} */
1233 public void setUser(UserHandle user) {
Amith Yamasaniecbd68b2012-11-02 12:17:19 -07001234 if (user.getIdentifier() == UserHandle.USER_ALL) {
1235 user = UserHandle.OWNER;
1236 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07001237 if (tickerView != null) {
1238 tickerView.setUser(user);
1239 }
1240 if (contentView != null) {
1241 contentView.setUser(user);
1242 }
1243 if (bigContentView != null) {
1244 bigContentView.setUser(user);
1245 }
Chris Wren8fd39ec2014-02-27 17:43:26 -05001246 if (headsUpContentView != null) {
1247 headsUpContentView.setUser(user);
1248 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07001249 }
1250
Joe Onoratocb109a02011-01-18 17:57:41 -08001251 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001252 * Builder class for {@link Notification} objects.
Joe Malin8d40d042012-11-05 11:36:40 -08001253 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001254 * Provides a convenient way to set the various fields of a {@link Notification} and generate
Scott Main183bf112012-08-13 19:12:13 -07001255 * content views using the platform's notification layout template. If your app supports
1256 * versions of Android as old as API level 4, you can instead use
1257 * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder},
1258 * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support
1259 * library</a>.
Joe Malin8d40d042012-11-05 11:36:40 -08001260 *
Scott Main183bf112012-08-13 19:12:13 -07001261 * <p>Example:
Joe Malin8d40d042012-11-05 11:36:40 -08001262 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001263 * <pre class="prettyprint">
Scott Main183bf112012-08-13 19:12:13 -07001264 * Notification noti = new Notification.Builder(mContext)
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001265 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
1266 * .setContentText(subject)
1267 * .setSmallIcon(R.drawable.new_mail)
1268 * .setLargeIcon(aBitmap)
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001269 * .build();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001270 * </pre>
Joe Onoratocb109a02011-01-18 17:57:41 -08001271 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001272 public static class Builder {
Daniel Sandler602ad1c2012-06-12 16:06:27 -04001273 private static final int MAX_ACTION_BUTTONS = 3;
Daniel Sandler8680bf82012-05-15 16:52:52 -04001274
Joe Onorato46439ce2010-11-19 13:56:21 -08001275 private Context mContext;
1276
1277 private long mWhen;
1278 private int mSmallIcon;
1279 private int mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08001280 private int mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08001281 private CharSequence mContentTitle;
1282 private CharSequence mContentText;
1283 private CharSequence mContentInfo;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001284 private CharSequence mSubText;
Joe Onorato46439ce2010-11-19 13:56:21 -08001285 private PendingIntent mContentIntent;
1286 private RemoteViews mContentView;
1287 private PendingIntent mDeleteIntent;
1288 private PendingIntent mFullScreenIntent;
1289 private CharSequence mTickerText;
1290 private RemoteViews mTickerView;
1291 private Bitmap mLargeIcon;
1292 private Uri mSound;
1293 private int mAudioStreamType;
1294 private long[] mVibrate;
1295 private int mLedArgb;
1296 private int mLedOnMs;
1297 private int mLedOffMs;
1298 private int mDefaults;
1299 private int mFlags;
Jeff Sharkey1c400132011-08-05 14:50:13 -07001300 private int mProgressMax;
1301 private int mProgress;
1302 private boolean mProgressIndeterminate;
John Spurlockfd7f1e02014-03-18 16:41:57 -04001303 private String mCategory;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001304 private Bundle mExtras;
1305 private int mPriority;
Daniel Sandler8680bf82012-05-15 16:52:52 -04001306 private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS);
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001307 private boolean mUseChronometer;
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001308 private Style mStyle;
Daniel Sandler0c890492012-09-12 17:23:10 -07001309 private boolean mShowWhen = true;
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001310 private int mVisibility = VISIBILITY_PRIVATE;
1311 private Notification mPublicVersion = null;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01001312 private boolean mQuantumTheme;
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001313 private final LegacyNotificationUtil mLegacyNotificationUtil;
Chris Wrendde75302014-03-26 17:24:15 -04001314 private ArrayList<String> mPeople;
Joe Onorato46439ce2010-11-19 13:56:21 -08001315
Joe Onoratocb109a02011-01-18 17:57:41 -08001316 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001317 * Constructs a new Builder with the defaults:
Joe Onoratocb109a02011-01-18 17:57:41 -08001318 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001319
1320 * <table>
1321 * <tr><th align=right>priority</th>
1322 * <td>{@link #PRIORITY_DEFAULT}</td></tr>
1323 * <tr><th align=right>when</th>
1324 * <td>now ({@link System#currentTimeMillis()})</td></tr>
1325 * <tr><th align=right>audio stream</th>
1326 * <td>{@link #STREAM_DEFAULT}</td></tr>
1327 * </table>
Joe Onoratocb109a02011-01-18 17:57:41 -08001328 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001329
1330 * @param context
1331 * A {@link Context} that will be used by the Builder to construct the
1332 * RemoteViews. The Context will not be held past the lifetime of this Builder
1333 * object.
Joe Onoratocb109a02011-01-18 17:57:41 -08001334 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001335 public Builder(Context context) {
1336 mContext = context;
Andy Stadler110988c2010-12-03 14:29:16 -08001337
1338 // Set defaults to match the defaults of a Notification
Joe Onorato46439ce2010-11-19 13:56:21 -08001339 mWhen = System.currentTimeMillis();
Andy Stadler110988c2010-12-03 14:29:16 -08001340 mAudioStreamType = STREAM_DEFAULT;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001341 mPriority = PRIORITY_DEFAULT;
Chris Wrendde75302014-03-26 17:24:15 -04001342 mPeople = new ArrayList<String>();
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01001343
1344 // TODO: Decide on targetSdk from calling app whether to use quantum theme.
1345 mQuantumTheme = true;
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001346
1347 // TODO: Decide on targetSdk from calling app whether to instantiate the processor at
1348 // all.
1349 mLegacyNotificationUtil = LegacyNotificationUtil.getInstance();
Joe Onorato46439ce2010-11-19 13:56:21 -08001350 }
1351
Joe Onoratocb109a02011-01-18 17:57:41 -08001352 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001353 * Add a timestamp pertaining to the notification (usually the time the event occurred).
Daniel Sandler0c890492012-09-12 17:23:10 -07001354 * It will be shown in the notification content view by default; use
1355 * {@link Builder#setShowWhen(boolean) setShowWhen} to control this.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001356 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001357 * @see Notification#when
Joe Onoratocb109a02011-01-18 17:57:41 -08001358 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001359 public Builder setWhen(long when) {
1360 mWhen = when;
1361 return this;
1362 }
1363
Joe Onoratocb109a02011-01-18 17:57:41 -08001364 /**
Daniel Sandler0c890492012-09-12 17:23:10 -07001365 * Control whether the timestamp set with {@link Builder#setWhen(long) setWhen} is shown
1366 * in the content view.
1367 */
1368 public Builder setShowWhen(boolean show) {
1369 mShowWhen = show;
1370 return this;
1371 }
1372
1373 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001374 * Show the {@link Notification#when} field as a stopwatch.
Joe Malin8d40d042012-11-05 11:36:40 -08001375 *
1376 * Instead of presenting <code>when</code> as a timestamp, the notification will show an
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001377 * automatically updating display of the minutes and seconds since <code>when</code>.
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001378 *
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001379 * Useful when showing an elapsed time (like an ongoing phone call).
1380 *
1381 * @see android.widget.Chronometer
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001382 * @see Notification#when
1383 */
1384 public Builder setUsesChronometer(boolean b) {
1385 mUseChronometer = b;
1386 return this;
1387 }
1388
1389 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001390 * Set the small icon resource, which will be used to represent the notification in the
1391 * status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -08001392 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001393
1394 * The platform template for the expanded view will draw this icon in the left, unless a
1395 * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small
1396 * icon will be moved to the right-hand side.
1397 *
1398
1399 * @param icon
1400 * A resource ID in the application's package of the drawable to use.
1401 * @see Notification#icon
Joe Onoratocb109a02011-01-18 17:57:41 -08001402 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001403 public Builder setSmallIcon(int icon) {
1404 mSmallIcon = icon;
1405 return this;
1406 }
1407
Joe Onoratocb109a02011-01-18 17:57:41 -08001408 /**
1409 * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional
1410 * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable
1411 * LevelListDrawable}.
1412 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001413 * @param icon A resource ID in the application's package of the drawable to use.
Joe Onoratocb109a02011-01-18 17:57:41 -08001414 * @param level The level to use for the icon.
1415 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001416 * @see Notification#icon
1417 * @see Notification#iconLevel
Joe Onoratocb109a02011-01-18 17:57:41 -08001418 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001419 public Builder setSmallIcon(int icon, int level) {
1420 mSmallIcon = icon;
1421 mSmallIconLevel = level;
1422 return this;
1423 }
1424
Joe Onoratocb109a02011-01-18 17:57:41 -08001425 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001426 * Set the first line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001427 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001428 public Builder setContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001429 mContentTitle = safeCharSequence(title);
Joe Onorato46439ce2010-11-19 13:56:21 -08001430 return this;
1431 }
1432
Joe Onoratocb109a02011-01-18 17:57:41 -08001433 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001434 * Set the second line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001435 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001436 public Builder setContentText(CharSequence text) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001437 mContentText = safeCharSequence(text);
Joe Onorato46439ce2010-11-19 13:56:21 -08001438 return this;
1439 }
1440
Joe Onoratocb109a02011-01-18 17:57:41 -08001441 /**
Joe Malin8d40d042012-11-05 11:36:40 -08001442 * Set the third line of text in the platform notification template.
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001443 * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the
1444 * same location in the standard template.
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001445 */
1446 public Builder setSubText(CharSequence text) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001447 mSubText = safeCharSequence(text);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001448 return this;
1449 }
1450
1451 /**
Joe Onoratocb109a02011-01-18 17:57:41 -08001452 * Set the large number at the right-hand side of the notification. This is
1453 * equivalent to setContentInfo, although it might show the number in a different
1454 * font size for readability.
1455 */
Joe Onorato8595a3d2010-11-19 18:12:07 -08001456 public Builder setNumber(int number) {
1457 mNumber = number;
1458 return this;
1459 }
1460
Joe Onoratocb109a02011-01-18 17:57:41 -08001461 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001462 * A small piece of additional information pertaining to this notification.
1463 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001464 * The platform template will draw this on the last line of the notification, at the far
1465 * right (to the right of a smallIcon if it has been placed there).
Joe Onoratocb109a02011-01-18 17:57:41 -08001466 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001467 public Builder setContentInfo(CharSequence info) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001468 mContentInfo = safeCharSequence(info);
Joe Onorato46439ce2010-11-19 13:56:21 -08001469 return this;
1470 }
1471
Joe Onoratocb109a02011-01-18 17:57:41 -08001472 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001473 * Set the progress this notification represents.
1474 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001475 * The platform template will represent this using a {@link ProgressBar}.
Jeff Sharkey1c400132011-08-05 14:50:13 -07001476 */
1477 public Builder setProgress(int max, int progress, boolean indeterminate) {
1478 mProgressMax = max;
1479 mProgress = progress;
1480 mProgressIndeterminate = indeterminate;
1481 return this;
1482 }
1483
1484 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001485 * Supply a custom RemoteViews to use instead of the platform template.
1486 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001487 * @see Notification#contentView
Joe Onoratocb109a02011-01-18 17:57:41 -08001488 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001489 public Builder setContent(RemoteViews views) {
1490 mContentView = views;
1491 return this;
1492 }
1493
Joe Onoratocb109a02011-01-18 17:57:41 -08001494 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001495 * Supply a {@link PendingIntent} to be sent when the notification is clicked.
1496 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001497 * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you
1498 * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use
1499 * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)}
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001500 * to assign PendingIntents to individual views in that custom layout (i.e., to create
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001501 * clickable buttons inside the notification view).
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001502 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001503 * @see Notification#contentIntent Notification.contentIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001504 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001505 public Builder setContentIntent(PendingIntent intent) {
1506 mContentIntent = intent;
1507 return this;
1508 }
1509
Joe Onoratocb109a02011-01-18 17:57:41 -08001510 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001511 * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user.
1512 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001513 * @see Notification#deleteIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001514 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001515 public Builder setDeleteIntent(PendingIntent intent) {
1516 mDeleteIntent = intent;
1517 return this;
1518 }
1519
Joe Onoratocb109a02011-01-18 17:57:41 -08001520 /**
1521 * An intent to launch instead of posting the notification to the status bar.
1522 * Only for use with extremely high-priority notifications demanding the user's
1523 * <strong>immediate</strong> attention, such as an incoming phone call or
1524 * alarm clock that the user has explicitly set to a particular time.
1525 * If this facility is used for something else, please give the user an option
1526 * to turn it off and use a normal notification, as this can be extremely
1527 * disruptive.
1528 *
1529 * @param intent The pending intent to launch.
1530 * @param highPriority Passing true will cause this notification to be sent
1531 * even if other notifications are suppressed.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001532 *
1533 * @see Notification#fullScreenIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001534 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001535 public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
1536 mFullScreenIntent = intent;
1537 setFlag(FLAG_HIGH_PRIORITY, highPriority);
1538 return this;
1539 }
1540
Joe Onoratocb109a02011-01-18 17:57:41 -08001541 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001542 * Set the "ticker" text which is displayed in the status bar when the notification first
Joe Onoratocb109a02011-01-18 17:57:41 -08001543 * arrives.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001544 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001545 * @see Notification#tickerText
Joe Onoratocb109a02011-01-18 17:57:41 -08001546 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001547 public Builder setTicker(CharSequence tickerText) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001548 mTickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08001549 return this;
1550 }
1551
Joe Onoratocb109a02011-01-18 17:57:41 -08001552 /**
1553 * Set the text that is displayed in the status bar when the notification first
1554 * arrives, and also a RemoteViews object that may be displayed instead on some
1555 * devices.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001556 *
1557 * @see Notification#tickerText
1558 * @see Notification#tickerView
Joe Onoratocb109a02011-01-18 17:57:41 -08001559 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001560 public Builder setTicker(CharSequence tickerText, RemoteViews views) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001561 mTickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08001562 mTickerView = views;
1563 return this;
1564 }
1565
Joe Onoratocb109a02011-01-18 17:57:41 -08001566 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001567 * Add a large icon to the notification (and the ticker on some devices).
1568 *
1569 * In the platform template, this image will be shown on the left of the notification view
1570 * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side).
1571 *
1572 * @see Notification#largeIcon
Joe Onoratocb109a02011-01-18 17:57:41 -08001573 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001574 public Builder setLargeIcon(Bitmap icon) {
1575 mLargeIcon = icon;
1576 return this;
1577 }
1578
Joe Onoratocb109a02011-01-18 17:57:41 -08001579 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001580 * Set the sound to play.
1581 *
1582 * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications.
1583 *
1584 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001585 */
Joe Onorato52f80cd2010-11-21 15:34:48 -08001586 public Builder setSound(Uri sound) {
1587 mSound = sound;
1588 mAudioStreamType = STREAM_DEFAULT;
1589 return this;
1590 }
1591
Joe Onoratocb109a02011-01-18 17:57:41 -08001592 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001593 * Set the sound to play, along with a specific stream on which to play it.
Joe Onoratocb109a02011-01-18 17:57:41 -08001594 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001595 * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants.
1596 *
1597 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001598 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001599 public Builder setSound(Uri sound, int streamType) {
1600 mSound = sound;
1601 mAudioStreamType = streamType;
1602 return this;
1603 }
1604
Joe Onoratocb109a02011-01-18 17:57:41 -08001605 /**
1606 * Set the vibration pattern to use.
1607 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001608
1609 * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the
1610 * <code>pattern</code> parameter.
1611 *
1612
1613 * @see Notification#vibrate
Joe Onoratocb109a02011-01-18 17:57:41 -08001614 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001615 public Builder setVibrate(long[] pattern) {
1616 mVibrate = pattern;
1617 return this;
1618 }
1619
Joe Onoratocb109a02011-01-18 17:57:41 -08001620 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001621 * Set the desired color for the indicator LED on the device, as well as the
1622 * blink duty cycle (specified in milliseconds).
1623 *
1624
1625 * Not all devices will honor all (or even any) of these values.
1626 *
1627
1628 * @see Notification#ledARGB
1629 * @see Notification#ledOnMS
1630 * @see Notification#ledOffMS
Joe Onoratocb109a02011-01-18 17:57:41 -08001631 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001632 public Builder setLights(int argb, int onMs, int offMs) {
1633 mLedArgb = argb;
1634 mLedOnMs = onMs;
1635 mLedOffMs = offMs;
Joe Onorato46439ce2010-11-19 13:56:21 -08001636 return this;
1637 }
1638
Joe Onoratocb109a02011-01-18 17:57:41 -08001639 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001640 * Set whether this is an "ongoing" notification.
Joe Onoratocb109a02011-01-18 17:57:41 -08001641 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001642
1643 * Ongoing notifications cannot be dismissed by the user, so your application or service
1644 * must take care of canceling them.
1645 *
1646
1647 * They are typically used to indicate a background task that the user is actively engaged
1648 * with (e.g., playing music) or is pending in some way and therefore occupying the device
1649 * (e.g., a file download, sync operation, active network connection).
1650 *
1651
1652 * @see Notification#FLAG_ONGOING_EVENT
1653 * @see Service#setForeground(boolean)
Joe Onoratocb109a02011-01-18 17:57:41 -08001654 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001655 public Builder setOngoing(boolean ongoing) {
1656 setFlag(FLAG_ONGOING_EVENT, ongoing);
1657 return this;
1658 }
1659
Joe Onoratocb109a02011-01-18 17:57:41 -08001660 /**
1661 * Set this flag if you would only like the sound, vibrate
1662 * and ticker to be played if the notification is not already showing.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001663 *
1664 * @see Notification#FLAG_ONLY_ALERT_ONCE
Joe Onoratocb109a02011-01-18 17:57:41 -08001665 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001666 public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
1667 setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
1668 return this;
1669 }
1670
Joe Onoratocb109a02011-01-18 17:57:41 -08001671 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001672 * Make this notification automatically dismissed when the user touches it. The
1673 * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens.
1674 *
1675 * @see Notification#FLAG_AUTO_CANCEL
Joe Onoratocb109a02011-01-18 17:57:41 -08001676 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001677 public Builder setAutoCancel(boolean autoCancel) {
Joe Onorato281d83f2011-01-04 17:13:10 -08001678 setFlag(FLAG_AUTO_CANCEL, autoCancel);
Joe Onorato46439ce2010-11-19 13:56:21 -08001679 return this;
1680 }
1681
Joe Onoratocb109a02011-01-18 17:57:41 -08001682 /**
Griff Hazendfcb0802014-02-11 12:00:00 -08001683 * Set whether or not this notification should not bridge to other devices.
1684 *
1685 * <p>Some notifications can be bridged to other devices for remote display.
1686 * This hint can be set to recommend this notification not be bridged.
1687 */
1688 public Builder setLocalOnly(boolean localOnly) {
1689 setFlag(FLAG_LOCAL_ONLY, localOnly);
1690 return this;
1691 }
1692
1693 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001694 * Set which notification properties will be inherited from system defaults.
Joe Onoratocb109a02011-01-18 17:57:41 -08001695 * <p>
1696 * The value should be one or more of the following fields combined with
1697 * bitwise-or:
1698 * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}.
1699 * <p>
1700 * For all default values, use {@link #DEFAULT_ALL}.
1701 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001702 public Builder setDefaults(int defaults) {
1703 mDefaults = defaults;
1704 return this;
1705 }
1706
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001707 /**
1708 * Set the priority of this notification.
1709 *
1710 * @see Notification#priority
1711 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001712 public Builder setPriority(@Priority int pri) {
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001713 mPriority = pri;
1714 return this;
1715 }
Joe Malin8d40d042012-11-05 11:36:40 -08001716
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001717 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -04001718 * Set the notification category.
Joe Malin8d40d042012-11-05 11:36:40 -08001719 *
John Spurlockfd7f1e02014-03-18 16:41:57 -04001720 * @see Notification#category
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001721 */
John Spurlockfd7f1e02014-03-18 16:41:57 -04001722 public Builder setCategory(String category) {
1723 mCategory = category;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001724 return this;
1725 }
1726
1727 /**
Chris Wrendde75302014-03-26 17:24:15 -04001728 * Add a person that is relevant to this notification.
1729 *
1730 * @see Notification#EXTRA_PEOPLE
1731 */
1732 public Builder addPerson(String handle) {
1733 mPeople.add(handle);
1734 return this;
1735 }
1736
1737 /**
Griff Hazen720042b2014-02-24 15:46:56 -08001738 * Merge additional metadata into this notification.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001739 *
Griff Hazen720042b2014-02-24 15:46:56 -08001740 * <p>Values within the Bundle will replace existing extras values in this Builder.
1741 *
1742 * @see Notification#extras
1743 */
1744 public Builder addExtras(Bundle bag) {
1745 if (mExtras == null) {
1746 mExtras = new Bundle(bag);
1747 } else {
1748 mExtras.putAll(bag);
1749 }
1750 return this;
1751 }
1752
1753 /**
1754 * Set metadata for this notification.
1755 *
1756 * <p>A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001757 * current contents are copied into the Notification each time {@link #build()} is
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001758 * called.
1759 *
Griff Hazen720042b2014-02-24 15:46:56 -08001760 * <p>Replaces any existing extras values with those from the provided Bundle.
1761 * Use {@link #addExtras} to merge in metadata instead.
1762 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001763 * @see Notification#extras
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001764 */
1765 public Builder setExtras(Bundle bag) {
1766 mExtras = bag;
1767 return this;
1768 }
1769
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001770 /**
Griff Hazen720042b2014-02-24 15:46:56 -08001771 * Get the current metadata Bundle used by this notification Builder.
1772 *
1773 * <p>The returned Bundle is shared with this Builder.
1774 *
1775 * <p>The current contents of this Bundle are copied into the Notification each time
1776 * {@link #build()} is called.
1777 *
1778 * @see Notification#extras
1779 */
1780 public Bundle getExtras() {
1781 if (mExtras == null) {
1782 mExtras = new Bundle();
1783 }
1784 return mExtras;
1785 }
1786
1787 /**
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001788 * Add an action to this notification. Actions are typically displayed by
1789 * the system as a button adjacent to the notification content.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04001790 * <p>
1791 * Every action must have an icon (32dp square and matching the
1792 * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo
1793 * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}.
1794 * <p>
1795 * A notification in its expanded form can display up to 3 actions, from left to right in
1796 * the order they were added. Actions will not be displayed when the notification is
1797 * collapsed, however, so be sure that any essential functions may be accessed by the user
1798 * in some other way (for example, in the Activity pointed to by {@link #contentIntent}).
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001799 *
1800 * @param icon Resource ID of a drawable that represents the action.
1801 * @param title Text describing the action.
1802 * @param intent PendingIntent to be fired when the action is invoked.
1803 */
1804 public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001805 mActions.add(new Action(icon, safeCharSequence(title), intent));
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001806 return this;
1807 }
1808
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001809 /**
1810 * Add a rich notification style to be applied at build time.
1811 *
1812 * @param style Object responsible for modifying the notification style.
1813 */
1814 public Builder setStyle(Style style) {
1815 if (mStyle != style) {
1816 mStyle = style;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07001817 if (mStyle != null) {
1818 mStyle.setBuilder(this);
1819 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001820 }
1821 return this;
1822 }
1823
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001824 /**
1825 * Specify the value of {@link #visibility}.
1826
1827 * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default),
1828 * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}.
1829 *
1830 * @return The same Builder.
1831 */
1832 public Builder setVisibility(int visibility) {
1833 mVisibility = visibility;
1834 return this;
1835 }
1836
1837 /**
1838 * Supply a replacement Notification whose contents should be shown in insecure contexts
1839 * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}.
1840 * @param n A replacement notification, presumably with some or all info redacted.
1841 * @return The same Builder.
1842 */
1843 public Builder setPublicVersion(Notification n) {
1844 mPublicVersion = n;
1845 return this;
1846 }
1847
Joe Onorato46439ce2010-11-19 13:56:21 -08001848 private void setFlag(int mask, boolean value) {
1849 if (value) {
1850 mFlags |= mask;
1851 } else {
1852 mFlags &= ~mask;
1853 }
1854 }
1855
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001856 private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
Joe Onorato561d3852010-11-20 18:09:34 -08001857 RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001858 boolean showLine3 = false;
1859 boolean showLine2 = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001860 int smallIconImageViewId = R.id.icon;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01001861 if (!mQuantumTheme && mPriority < PRIORITY_LOW) {
Daniel Sandlere95658c2012-05-10 00:33:54 -04001862 contentView.setInt(R.id.icon,
1863 "setBackgroundResource", R.drawable.notification_template_icon_low_bg);
1864 contentView.setInt(R.id.status_bar_latest_event_content,
1865 "setBackgroundResource", R.drawable.notification_bg_low);
1866 }
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001867 if (mLargeIcon != null) {
1868 contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
1869 processLegacyLargeIcon(mLargeIcon, contentView);
1870 smallIconImageViewId = R.id.right_icon;
1871 }
Joe Onorato561d3852010-11-20 18:09:34 -08001872 if (mSmallIcon != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001873 contentView.setImageViewResource(smallIconImageViewId, mSmallIcon);
1874 contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001875 if (mLargeIcon != null) {
1876 processLegacySmallIcon(mSmallIcon, smallIconImageViewId, contentView);
1877 } else {
1878 processLegacyLargeIcon(mSmallIcon, contentView);
1879 }
1880
Jeff Sharkey1c400132011-08-05 14:50:13 -07001881 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001882 contentView.setViewVisibility(smallIconImageViewId, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001883 }
1884 if (mContentTitle != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001885 contentView.setTextViewText(R.id.title, processLegacyText(mContentTitle));
Joe Onorato561d3852010-11-20 18:09:34 -08001886 }
1887 if (mContentText != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001888 contentView.setTextViewText(R.id.text, processLegacyText(mContentText));
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001889 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001890 }
1891 if (mContentInfo != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001892 contentView.setTextViewText(R.id.info, processLegacyText(mContentInfo));
Jeff Sharkey1c400132011-08-05 14:50:13 -07001893 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001894 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001895 } else if (mNumber > 0) {
Daniel Sandlerebce0112011-06-16 16:44:51 -04001896 final int tooBig = mContext.getResources().getInteger(
1897 R.integer.status_bar_notification_info_maxnum);
1898 if (mNumber > tooBig) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001899 contentView.setTextViewText(R.id.info, processLegacyText(
1900 mContext.getResources().getString(
1901 R.string.status_bar_notification_info_overflow)));
Joe Onorato059a2f82011-01-04 10:27:01 -08001902 } else {
1903 NumberFormat f = NumberFormat.getIntegerInstance();
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001904 contentView.setTextViewText(R.id.info, processLegacyText(f.format(mNumber)));
Joe Onorato059a2f82011-01-04 10:27:01 -08001905 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001906 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001907 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001908 } else {
1909 contentView.setViewVisibility(R.id.info, View.GONE);
1910 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001911
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001912 // Need to show three lines?
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001913 if (mSubText != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001914 contentView.setTextViewText(R.id.text, processLegacyText(mSubText));
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001915 if (mContentText != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001916 contentView.setTextViewText(R.id.text2, processLegacyText(mContentText));
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001917 contentView.setViewVisibility(R.id.text2, View.VISIBLE);
1918 showLine2 = true;
1919 } else {
1920 contentView.setViewVisibility(R.id.text2, View.GONE);
1921 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001922 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001923 contentView.setViewVisibility(R.id.text2, View.GONE);
1924 if (mProgressMax != 0 || mProgressIndeterminate) {
1925 contentView.setProgressBar(
1926 R.id.progress, mProgressMax, mProgress, mProgressIndeterminate);
1927 contentView.setViewVisibility(R.id.progress, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001928 showLine2 = true;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001929 } else {
1930 contentView.setViewVisibility(R.id.progress, View.GONE);
1931 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001932 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001933 if (showLine2) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001934 if (fitIn1U) {
1935 // need to shrink all the type to make sure everything fits
1936 final Resources res = mContext.getResources();
1937 final float subTextSize = res.getDimensionPixelSize(
1938 R.dimen.notification_subtext_size);
1939 contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize);
1940 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001941 // vertical centering
1942 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
1943 }
1944
Daniel Sandler0c890492012-09-12 17:23:10 -07001945 if (mWhen != 0 && mShowWhen) {
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001946 if (mUseChronometer) {
1947 contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
1948 contentView.setLong(R.id.chronometer, "setBase",
1949 mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
1950 contentView.setBoolean(R.id.chronometer, "setStarted", true);
1951 } else {
1952 contentView.setViewVisibility(R.id.time, View.VISIBLE);
1953 contentView.setLong(R.id.time, "setTime", mWhen);
1954 }
Daniel Sandler0c890492012-09-12 17:23:10 -07001955 } else {
1956 contentView.setViewVisibility(R.id.time, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001957 }
Daniel Sandler0c890492012-09-12 17:23:10 -07001958
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001959 contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001960 contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001961 return contentView;
1962 }
1963
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001964 private RemoteViews applyStandardTemplateWithActions(int layoutId) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001965 RemoteViews big = applyStandardTemplate(layoutId, false);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001966
1967 int N = mActions.size();
1968 if (N > 0) {
Chris Wrend6297db2012-05-03 16:20:13 -04001969 // Log.d("Notification", "has actions: " + mContentText);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001970 big.setViewVisibility(R.id.actions, View.VISIBLE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001971 big.setViewVisibility(R.id.action_divider, View.VISIBLE);
Daniel Sandler8680bf82012-05-15 16:52:52 -04001972 if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS;
Chris Wren2c22eb02012-05-08 09:49:13 -04001973 big.removeAllViews(R.id.actions);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001974 for (int i=0; i<N; i++) {
1975 final RemoteViews button = generateActionButton(mActions.get(i));
Chris Wrend6297db2012-05-03 16:20:13 -04001976 //Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001977 big.addView(R.id.actions, button);
1978 }
1979 }
1980 return big;
1981 }
1982
Joe Onorato46439ce2010-11-19 13:56:21 -08001983 private RemoteViews makeContentView() {
1984 if (mContentView != null) {
1985 return mContentView;
1986 } else {
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01001987 return applyStandardTemplate(getBaseLayoutResource(), true); // no more special large_icon flavor
Joe Onorato46439ce2010-11-19 13:56:21 -08001988 }
1989 }
1990
1991 private RemoteViews makeTickerView() {
1992 if (mTickerView != null) {
1993 return mTickerView;
1994 } else {
Joe Onorato561d3852010-11-20 18:09:34 -08001995 if (mContentView == null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001996 return applyStandardTemplate(mLargeIcon == null
Joe Onorato561d3852010-11-20 18:09:34 -08001997 ? R.layout.status_bar_latest_event_ticker
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001998 : R.layout.status_bar_latest_event_ticker_large_icon, true);
Joe Onorato561d3852010-11-20 18:09:34 -08001999 } else {
2000 return null;
2001 }
Joe Onorato46439ce2010-11-19 13:56:21 -08002002 }
2003 }
2004
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002005 private RemoteViews makeBigContentView() {
2006 if (mActions.size() == 0) return null;
2007
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002008 return applyStandardTemplateWithActions(getBigBaseLayoutResource());
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002009 }
2010
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002011 private RemoteViews makeHeadsUpContentView() {
Chris Wren8fd39ec2014-02-27 17:43:26 -05002012 if (mActions.size() == 0) return null;
2013
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002014 return applyStandardTemplateWithActions(getBigBaseLayoutResource());
Chris Wren8fd39ec2014-02-27 17:43:26 -05002015 }
2016
2017
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002018 private RemoteViews generateActionButton(Action action) {
Daniel Sandler8680bf82012-05-15 16:52:52 -04002019 final boolean tombstone = (action.actionIntent == null);
Joe Malin8d40d042012-11-05 11:36:40 -08002020 RemoteViews button = new RemoteViews(mContext.getPackageName(),
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002021 tombstone ? getActionTombstoneLayoutResource()
2022 : getActionLayoutResource());
Chris Wren8749ac8a2013-12-03 14:31:01 -05002023 button.setTextViewCompoundDrawablesRelative(R.id.action0, action.icon, 0, 0, 0);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002024 button.setTextViewText(R.id.action0, processLegacyText(action.title));
Daniel Sandler8680bf82012-05-15 16:52:52 -04002025 if (!tombstone) {
Daniel Sandlere5518842012-05-10 16:20:40 -04002026 button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
Daniel Sandlere5518842012-05-10 16:20:40 -04002027 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002028 button.setContentDescription(R.id.action0, action.title);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002029 processLegacyAction(action, button);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002030 return button;
2031 }
2032
Joe Onoratocb109a02011-01-18 17:57:41 -08002033 /**
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002034 * @return Whether we are currently building a notification from a legacy (an app that
2035 * doesn't create quantum notifications by itself) app.
2036 */
2037 private boolean isLegacy() {
2038 return mLegacyNotificationUtil != null;
2039 }
2040
2041 private void processLegacyAction(Action action, RemoteViews button) {
2042 if (isLegacy()) {
2043 if (mLegacyNotificationUtil.isGrayscale(mContext, action.icon)) {
2044 button.setTextViewCompoundDrawablesRelativeColorFilter(R.id.action0, 0,
2045 mContext.getResources().getColor(
2046 R.color.notification_action_legacy_color_filter),
2047 PorterDuff.Mode.MULTIPLY);
2048 }
2049 }
2050 }
2051
2052 private CharSequence processLegacyText(CharSequence charSequence) {
2053 if (isLegacy()) {
2054 return mLegacyNotificationUtil.invertCharSequenceColors(charSequence);
2055 } else {
2056 return charSequence;
2057 }
2058 }
2059
2060 private void processLegacyLargeIcon(int largeIconId, RemoteViews contentView) {
2061 if (isLegacy()) {
2062 processLegacyLargeIcon(
2063 mLegacyNotificationUtil.isGrayscale(mContext, largeIconId),
2064 contentView);
2065 }
2066 }
2067
2068 private void processLegacyLargeIcon(Bitmap largeIcon, RemoteViews contentView) {
2069 if (isLegacy()) {
2070 processLegacyLargeIcon(
2071 mLegacyNotificationUtil.isGrayscale(largeIcon),
2072 contentView);
2073 }
2074 }
2075
2076 private void processLegacyLargeIcon(boolean isGrayscale, RemoteViews contentView) {
2077 if (isLegacy() && isGrayscale) {
2078 contentView.setInt(R.id.icon, "setBackgroundResource",
2079 R.drawable.notification_icon_legacy_bg_inset);
2080 }
2081 }
2082
2083 private void processLegacySmallIcon(int smallIconDrawableId, int smallIconImageViewId,
2084 RemoteViews contentView) {
2085 if (isLegacy()) {
2086 if (mLegacyNotificationUtil.isGrayscale(mContext, smallIconDrawableId)) {
2087 contentView.setDrawableParameters(smallIconImageViewId, false, -1,
2088 mContext.getResources().getColor(
2089 R.color.notification_action_legacy_color_filter),
2090 PorterDuff.Mode.MULTIPLY, -1);
2091 }
2092 }
2093 }
2094
2095 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002096 * Apply the unstyled operations and return a new {@link Notification} object.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002097 * @hide
Joe Onoratocb109a02011-01-18 17:57:41 -08002098 */
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002099 public Notification buildUnstyled() {
Joe Onorato46439ce2010-11-19 13:56:21 -08002100 Notification n = new Notification();
2101 n.when = mWhen;
2102 n.icon = mSmallIcon;
2103 n.iconLevel = mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08002104 n.number = mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08002105 n.contentView = makeContentView();
2106 n.contentIntent = mContentIntent;
2107 n.deleteIntent = mDeleteIntent;
2108 n.fullScreenIntent = mFullScreenIntent;
2109 n.tickerText = mTickerText;
2110 n.tickerView = makeTickerView();
2111 n.largeIcon = mLargeIcon;
2112 n.sound = mSound;
2113 n.audioStreamType = mAudioStreamType;
2114 n.vibrate = mVibrate;
2115 n.ledARGB = mLedArgb;
2116 n.ledOnMS = mLedOnMs;
2117 n.ledOffMS = mLedOffMs;
2118 n.defaults = mDefaults;
2119 n.flags = mFlags;
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002120 n.bigContentView = makeBigContentView();
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002121 n.headsUpContentView = makeHeadsUpContentView();
Daniel Sandler26c13432013-04-04 11:01:04 -04002122 if (mLedOnMs != 0 || mLedOffMs != 0) {
Joe Onorato8d0b6552010-11-22 16:09:29 -08002123 n.flags |= FLAG_SHOW_LIGHTS;
2124 }
2125 if ((mDefaults & DEFAULT_LIGHTS) != 0) {
2126 n.flags |= FLAG_SHOW_LIGHTS;
2127 }
John Spurlockfd7f1e02014-03-18 16:41:57 -04002128 n.category = mCategory;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002129 n.priority = mPriority;
Daniel Sandlera0a938c2012-03-15 08:42:37 -04002130 if (mActions.size() > 0) {
2131 n.actions = new Action[mActions.size()];
2132 mActions.toArray(n.actions);
2133 }
Dan Sandler0bf2ed82013-12-21 23:33:41 -06002134 n.visibility = mVisibility;
2135
2136 if (mPublicVersion != null) {
2137 n.publicVersion = new Notification();
2138 mPublicVersion.cloneInto(n.publicVersion, true);
2139 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002140
Joe Onorato46439ce2010-11-19 13:56:21 -08002141 return n;
2142 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002143
2144 /**
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002145 * Capture, in the provided bundle, semantic information used in the construction of
2146 * this Notification object.
2147 * @hide
2148 */
Griff Hazen720042b2014-02-24 15:46:56 -08002149 public void populateExtras(Bundle extras) {
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002150 // Store original information used in the construction of this object
2151 extras.putCharSequence(EXTRA_TITLE, mContentTitle);
2152 extras.putCharSequence(EXTRA_TEXT, mContentText);
2153 extras.putCharSequence(EXTRA_SUB_TEXT, mSubText);
2154 extras.putCharSequence(EXTRA_INFO_TEXT, mContentInfo);
2155 extras.putInt(EXTRA_SMALL_ICON, mSmallIcon);
2156 extras.putInt(EXTRA_PROGRESS, mProgress);
2157 extras.putInt(EXTRA_PROGRESS_MAX, mProgressMax);
2158 extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mProgressIndeterminate);
2159 extras.putBoolean(EXTRA_SHOW_CHRONOMETER, mUseChronometer);
2160 extras.putBoolean(EXTRA_SHOW_WHEN, mShowWhen);
John Spurlockac08a472013-06-10 11:37:08 -04002161 if (mLargeIcon != null) {
2162 extras.putParcelable(EXTRA_LARGE_ICON, mLargeIcon);
2163 }
Chris Wrendde75302014-03-26 17:24:15 -04002164 if (!mPeople.isEmpty()) {
2165 extras.putStringArray(EXTRA_PEOPLE, mPeople.toArray(new String[mPeople.size()]));
2166 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002167 }
2168
2169 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002170 * @deprecated Use {@link #build()} instead.
2171 */
2172 @Deprecated
2173 public Notification getNotification() {
2174 return build();
2175 }
2176
2177 /**
2178 * Combine all of the options that have been set and return a new {@link Notification}
2179 * object.
2180 */
2181 public Notification build() {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002182 Notification n = buildUnstyled();
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002183
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002184 if (mStyle != null) {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002185 n = mStyle.buildStyled(n);
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002186 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002187
2188 n.extras = mExtras != null ? new Bundle(mExtras) : new Bundle();
2189
Griff Hazen720042b2014-02-24 15:46:56 -08002190 populateExtras(n.extras);
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002191 if (mStyle != null) {
2192 mStyle.addExtras(n.extras);
2193 }
2194
2195 return n;
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002196 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002197
2198 /**
2199 * Apply this Builder to an existing {@link Notification} object.
2200 *
2201 * @hide
2202 */
2203 public Notification buildInto(Notification n) {
Daniel Sandler1a497d32013-04-18 14:52:45 -04002204 build().cloneInto(n, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002205 return n;
2206 }
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002207
2208
2209 private int getBaseLayoutResource() {
2210 return mQuantumTheme
2211 ? R.layout.notification_template_quantum_base
2212 : R.layout.notification_template_base;
2213 }
2214
2215 private int getBigBaseLayoutResource() {
2216 return mQuantumTheme
2217 ? R.layout.notification_template_quantum_big_base
2218 : R.layout.notification_template_big_base;
2219 }
2220
2221 private int getBigPictureLayoutResource() {
2222 return mQuantumTheme
2223 ? R.layout.notification_template_quantum_big_picture
2224 : R.layout.notification_template_big_picture;
2225 }
2226
2227 private int getBigTextLayoutResource() {
2228 return mQuantumTheme
2229 ? R.layout.notification_template_quantum_big_text
2230 : R.layout.notification_template_big_text;
2231 }
2232
2233 private int getInboxLayoutResource() {
2234 return mQuantumTheme
2235 ? R.layout.notification_template_quantum_inbox
2236 : R.layout.notification_template_inbox;
2237 }
2238
2239 private int getActionLayoutResource() {
2240 return mQuantumTheme
2241 ? R.layout.notification_quantum_action
2242 : R.layout.notification_action;
2243 }
2244
2245 private int getActionTombstoneLayoutResource() {
2246 return mQuantumTheme
2247 ? R.layout.notification_quantum_action_tombstone
2248 : R.layout.notification_action_tombstone;
2249 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002250 }
2251
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002252 /**
2253 * An object that can apply a rich notification style to a {@link Notification.Builder}
2254 * object.
2255 */
Griff Hazendfcb0802014-02-11 12:00:00 -08002256 public static abstract class Style {
Chris Wrend6297db2012-05-03 16:20:13 -04002257 private CharSequence mBigContentTitle;
2258 private CharSequence mSummaryText = null;
Daniel Sandler619738c2012-06-07 16:33:08 -04002259 private boolean mSummaryTextSet = false;
Chris Wrend6297db2012-05-03 16:20:13 -04002260
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002261 protected Builder mBuilder;
2262
Chris Wrend6297db2012-05-03 16:20:13 -04002263 /**
2264 * Overrides ContentTitle in the big form of the template.
2265 * This defaults to the value passed to setContentTitle().
2266 */
2267 protected void internalSetBigContentTitle(CharSequence title) {
2268 mBigContentTitle = title;
2269 }
2270
2271 /**
2272 * Set the first line of text after the detail section in the big form of the template.
2273 */
2274 protected void internalSetSummaryText(CharSequence cs) {
2275 mSummaryText = cs;
Daniel Sandler619738c2012-06-07 16:33:08 -04002276 mSummaryTextSet = true;
Chris Wrend6297db2012-05-03 16:20:13 -04002277 }
2278
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002279 public void setBuilder(Builder builder) {
2280 if (mBuilder != builder) {
2281 mBuilder = builder;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07002282 if (mBuilder != null) {
2283 mBuilder.setStyle(this);
2284 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002285 }
2286 }
2287
Chris Wrend6297db2012-05-03 16:20:13 -04002288 protected void checkBuilder() {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002289 if (mBuilder == null) {
2290 throw new IllegalArgumentException("Style requires a valid Builder object");
2291 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002292 }
Chris Wrend6297db2012-05-03 16:20:13 -04002293
2294 protected RemoteViews getStandardView(int layoutId) {
2295 checkBuilder();
2296
2297 if (mBigContentTitle != null) {
2298 mBuilder.setContentTitle(mBigContentTitle);
2299 }
2300
Chris Wrend6297db2012-05-03 16:20:13 -04002301 RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId);
2302
Chris Wrend6297db2012-05-03 16:20:13 -04002303 if (mBigContentTitle != null && mBigContentTitle.equals("")) {
2304 contentView.setViewVisibility(R.id.line1, View.GONE);
Chris Wren67dc9a02012-05-16 01:03:20 -04002305 } else {
2306 contentView.setViewVisibility(R.id.line1, View.VISIBLE);
Chris Wrend6297db2012-05-03 16:20:13 -04002307 }
2308
Daniel Sandler619738c2012-06-07 16:33:08 -04002309 // The last line defaults to the subtext, but can be replaced by mSummaryText
2310 final CharSequence overflowText =
2311 mSummaryTextSet ? mSummaryText
2312 : mBuilder.mSubText;
2313 if (overflowText != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002314 contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(overflowText));
Daniel Sandler619738c2012-06-07 16:33:08 -04002315 contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002316 contentView.setViewVisibility(R.id.line3, View.VISIBLE);
Daniel Sandler916ad912012-06-13 12:17:07 -04002317 } else {
2318 contentView.setViewVisibility(R.id.overflow_divider, View.GONE);
2319 contentView.setViewVisibility(R.id.line3, View.GONE);
Chris Wrend6297db2012-05-03 16:20:13 -04002320 }
2321
2322 return contentView;
2323 }
2324
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002325 /**
2326 * @hide
2327 */
2328 public void addExtras(Bundle extras) {
2329 if (mSummaryTextSet) {
2330 extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText);
2331 }
2332 if (mBigContentTitle != null) {
2333 extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle);
2334 }
Chris Wren91ad5632013-06-05 15:05:57 -04002335 extras.putString(EXTRA_TEMPLATE, this.getClass().getName());
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002336 }
2337
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002338 /**
2339 * @hide
2340 */
2341 public abstract Notification buildStyled(Notification wip);
2342
2343 /**
2344 * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is
2345 * attached to.
2346 *
2347 * @return the fully constructed Notification.
2348 */
2349 public Notification build() {
2350 checkBuilder();
2351 return mBuilder.build();
2352 }
Joe Onorato46439ce2010-11-19 13:56:21 -08002353 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002354
2355 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002356 * Helper class for generating large-format notifications that include a large image attachment.
Joe Malin8d40d042012-11-05 11:36:40 -08002357 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002358 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002359 * <pre class="prettyprint">
2360 * Notification noti = new Notification.BigPictureStyle(
2361 * new Notification.Builder()
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002362 * .setContentTitle(&quot;New photo from &quot; + sender.toString())
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002363 * .setContentText(subject)
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002364 * .setSmallIcon(R.drawable.new_post)
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002365 * .setLargeIcon(aBitmap))
2366 * .bigPicture(aBigBitmap)
2367 * .build();
2368 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002369 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002370 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002371 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002372 public static class BigPictureStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002373 private Bitmap mPicture;
Chris Wren3745a3d2012-05-22 15:11:52 -04002374 private Bitmap mBigLargeIcon;
2375 private boolean mBigLargeIconSet = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002376
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002377 public BigPictureStyle() {
2378 }
2379
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002380 public BigPictureStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002381 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002382 }
2383
Chris Wrend6297db2012-05-03 16:20:13 -04002384 /**
2385 * Overrides ContentTitle in the big form of the template.
2386 * This defaults to the value passed to setContentTitle().
2387 */
2388 public BigPictureStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002389 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002390 return this;
2391 }
2392
2393 /**
2394 * Set the first line of text after the detail section in the big form of the template.
2395 */
2396 public BigPictureStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002397 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002398 return this;
2399 }
2400
Chris Wren0bd664d2012-08-01 13:56:56 -04002401 /**
2402 * Provide the bitmap to be used as the payload for the BigPicture notification.
2403 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002404 public BigPictureStyle bigPicture(Bitmap b) {
2405 mPicture = b;
2406 return this;
2407 }
2408
Chris Wren3745a3d2012-05-22 15:11:52 -04002409 /**
Chris Wren3745a3d2012-05-22 15:11:52 -04002410 * Override the large icon when the big notification is shown.
2411 */
2412 public BigPictureStyle bigLargeIcon(Bitmap b) {
2413 mBigLargeIconSet = true;
2414 mBigLargeIcon = b;
2415 return this;
2416 }
2417
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002418 private RemoteViews makeBigContentView() {
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002419 RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource());
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002420
2421 contentView.setImageViewBitmap(R.id.big_picture, mPicture);
2422
2423 return contentView;
2424 }
2425
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002426 /**
2427 * @hide
2428 */
2429 public void addExtras(Bundle extras) {
2430 super.addExtras(extras);
2431
2432 if (mBigLargeIconSet) {
2433 extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon);
2434 }
2435 extras.putParcelable(EXTRA_PICTURE, mPicture);
2436 }
2437
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002438 /**
2439 * @hide
2440 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002441 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002442 public Notification buildStyled(Notification wip) {
Chris Wren3745a3d2012-05-22 15:11:52 -04002443 if (mBigLargeIconSet ) {
2444 mBuilder.mLargeIcon = mBigLargeIcon;
2445 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002446 wip.bigContentView = makeBigContentView();
2447 return wip;
2448 }
2449 }
2450
2451 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002452 * Helper class for generating large-format notifications that include a lot of text.
Joe Malin8d40d042012-11-05 11:36:40 -08002453 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002454 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002455 * <pre class="prettyprint">
Daniel Sandler87682782012-11-07 14:04:42 -05002456 * Notification noti = new Notification.BigTextStyle(
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002457 * new Notification.Builder()
2458 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
2459 * .setContentText(subject)
2460 * .setSmallIcon(R.drawable.new_mail)
2461 * .setLargeIcon(aBitmap))
2462 * .bigText(aVeryLongString)
2463 * .build();
2464 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002465 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002466 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002467 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002468 public static class BigTextStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002469 private CharSequence mBigText;
2470
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002471 public BigTextStyle() {
2472 }
2473
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002474 public BigTextStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002475 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002476 }
2477
Chris Wrend6297db2012-05-03 16:20:13 -04002478 /**
2479 * Overrides ContentTitle in the big form of the template.
2480 * This defaults to the value passed to setContentTitle().
2481 */
2482 public BigTextStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002483 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002484 return this;
2485 }
2486
2487 /**
2488 * Set the first line of text after the detail section in the big form of the template.
2489 */
2490 public BigTextStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002491 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002492 return this;
2493 }
2494
Chris Wren0bd664d2012-08-01 13:56:56 -04002495 /**
2496 * Provide the longer text to be displayed in the big form of the
2497 * template in place of the content text.
2498 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002499 public BigTextStyle bigText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002500 mBigText = safeCharSequence(cs);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002501 return this;
2502 }
2503
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002504 /**
2505 * @hide
2506 */
2507 public void addExtras(Bundle extras) {
2508 super.addExtras(extras);
2509
2510 extras.putCharSequence(EXTRA_TEXT, mBigText);
2511 }
2512
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002513 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04002514 // Remove the content text so line3 only shows if you have a summary
2515 final boolean hadThreeLines = (mBuilder.mContentText != null && mBuilder.mSubText != null);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002516 mBuilder.mContentText = null;
Daniel Sandler916ad912012-06-13 12:17:07 -04002517
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002518 RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource());
Joe Malin8d40d042012-11-05 11:36:40 -08002519
Daniel Sandler619738c2012-06-07 16:33:08 -04002520 if (hadThreeLines) {
2521 // vertical centering
2522 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
2523 }
2524
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002525 contentView.setTextViewText(R.id.big_text, mBuilder.processLegacyText(mBigText));
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002526 contentView.setViewVisibility(R.id.big_text, View.VISIBLE);
Chris Wren3c5f92432012-05-04 16:31:17 -04002527 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002528
2529 return contentView;
2530 }
2531
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002532 /**
2533 * @hide
2534 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002535 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002536 public Notification buildStyled(Notification wip) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002537 wip.bigContentView = makeBigContentView();
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002538
2539 wip.extras.putCharSequence(EXTRA_TEXT, mBigText);
2540
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002541 return wip;
2542 }
2543 }
Daniel Sandler879c5e02012-04-17 16:46:51 -04002544
2545 /**
2546 * Helper class for generating large-format notifications that include a list of (up to 5) strings.
Joe Malin8d40d042012-11-05 11:36:40 -08002547 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04002548 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
2549 * <pre class="prettyprint">
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002550 * Notification noti = new Notification.InboxStyle(
Daniel Sandler879c5e02012-04-17 16:46:51 -04002551 * new Notification.Builder()
Chris Wrend6297db2012-05-03 16:20:13 -04002552 * .setContentTitle(&quot;5 New mails from &quot; + sender.toString())
Daniel Sandler879c5e02012-04-17 16:46:51 -04002553 * .setContentText(subject)
2554 * .setSmallIcon(R.drawable.new_mail)
2555 * .setLargeIcon(aBitmap))
2556 * .addLine(str1)
2557 * .addLine(str2)
Chris Wrend6297db2012-05-03 16:20:13 -04002558 * .setContentTitle("")
2559 * .setSummaryText(&quot;+3 more&quot;)
Daniel Sandler879c5e02012-04-17 16:46:51 -04002560 * .build();
2561 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002562 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04002563 * @see Notification#bigContentView
2564 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002565 public static class InboxStyle extends Style {
Daniel Sandler879c5e02012-04-17 16:46:51 -04002566 private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5);
2567
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002568 public InboxStyle() {
2569 }
2570
Daniel Sandler879c5e02012-04-17 16:46:51 -04002571 public InboxStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002572 setBuilder(builder);
Daniel Sandler879c5e02012-04-17 16:46:51 -04002573 }
2574
Chris Wrend6297db2012-05-03 16:20:13 -04002575 /**
2576 * Overrides ContentTitle in the big form of the template.
2577 * This defaults to the value passed to setContentTitle().
2578 */
2579 public InboxStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002580 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002581 return this;
2582 }
2583
2584 /**
2585 * Set the first line of text after the detail section in the big form of the template.
2586 */
2587 public InboxStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002588 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002589 return this;
2590 }
2591
Chris Wren0bd664d2012-08-01 13:56:56 -04002592 /**
2593 * Append a line to the digest section of the Inbox notification.
2594 */
Daniel Sandler879c5e02012-04-17 16:46:51 -04002595 public InboxStyle addLine(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002596 mTexts.add(safeCharSequence(cs));
Daniel Sandler879c5e02012-04-17 16:46:51 -04002597 return this;
2598 }
2599
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002600 /**
2601 * @hide
2602 */
2603 public void addExtras(Bundle extras) {
2604 super.addExtras(extras);
2605 CharSequence[] a = new CharSequence[mTexts.size()];
2606 extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a));
2607 }
2608
Daniel Sandler879c5e02012-04-17 16:46:51 -04002609 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04002610 // Remove the content text so line3 disappears unless you have a summary
2611 mBuilder.mContentText = null;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002612 RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource());
Daniel Sandler619738c2012-06-07 16:33:08 -04002613
Chris Wrend6297db2012-05-03 16:20:13 -04002614 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandler879c5e02012-04-17 16:46:51 -04002615
Chris Wrend6297db2012-05-03 16:20:13 -04002616 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 -04002617 R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6};
Chris Wrend6297db2012-05-03 16:20:13 -04002618
Chris Wren4ed80d52012-05-17 09:30:03 -04002619 // Make sure all rows are gone in case we reuse a view.
2620 for (int rowId : rowIds) {
2621 contentView.setViewVisibility(rowId, View.GONE);
2622 }
2623
Chris Wren683ab002012-09-20 10:35:54 -04002624
Daniel Sandler879c5e02012-04-17 16:46:51 -04002625 int i=0;
2626 while (i < mTexts.size() && i < rowIds.length) {
2627 CharSequence str = mTexts.get(i);
2628 if (str != null && !str.equals("")) {
2629 contentView.setViewVisibility(rowIds[i], View.VISIBLE);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002630 contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str));
Daniel Sandler879c5e02012-04-17 16:46:51 -04002631 }
2632 i++;
2633 }
2634
Chris Wren683ab002012-09-20 10:35:54 -04002635 contentView.setViewVisibility(R.id.inbox_end_pad,
2636 mTexts.size() > 0 ? View.VISIBLE : View.GONE);
2637
2638 contentView.setViewVisibility(R.id.inbox_more,
2639 mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE);
Chris Wren29bb6d92012-05-17 18:09:42 -04002640
Daniel Sandler879c5e02012-04-17 16:46:51 -04002641 return contentView;
2642 }
2643
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002644 /**
2645 * @hide
2646 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002647 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002648 public Notification buildStyled(Notification wip) {
Daniel Sandler879c5e02012-04-17 16:46:51 -04002649 wip.bigContentView = makeBigContentView();
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002650
Daniel Sandler879c5e02012-04-17 16:46:51 -04002651 return wip;
2652 }
2653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002654}