blob: 36d26359675af4ed1c261f30950243521856ac9e [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;
Joe Onorato46439ce2010-11-19 13:56:21 -08001314
Joe Onoratocb109a02011-01-18 17:57:41 -08001315 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001316 * Constructs a new Builder with the defaults:
Joe Onoratocb109a02011-01-18 17:57:41 -08001317 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001318
1319 * <table>
1320 * <tr><th align=right>priority</th>
1321 * <td>{@link #PRIORITY_DEFAULT}</td></tr>
1322 * <tr><th align=right>when</th>
1323 * <td>now ({@link System#currentTimeMillis()})</td></tr>
1324 * <tr><th align=right>audio stream</th>
1325 * <td>{@link #STREAM_DEFAULT}</td></tr>
1326 * </table>
Joe Onoratocb109a02011-01-18 17:57:41 -08001327 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001328
1329 * @param context
1330 * A {@link Context} that will be used by the Builder to construct the
1331 * RemoteViews. The Context will not be held past the lifetime of this Builder
1332 * object.
Joe Onoratocb109a02011-01-18 17:57:41 -08001333 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001334 public Builder(Context context) {
1335 mContext = context;
Andy Stadler110988c2010-12-03 14:29:16 -08001336
1337 // Set defaults to match the defaults of a Notification
Joe Onorato46439ce2010-11-19 13:56:21 -08001338 mWhen = System.currentTimeMillis();
Andy Stadler110988c2010-12-03 14:29:16 -08001339 mAudioStreamType = STREAM_DEFAULT;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001340 mPriority = PRIORITY_DEFAULT;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01001341
1342 // TODO: Decide on targetSdk from calling app whether to use quantum theme.
1343 mQuantumTheme = true;
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001344
1345 // TODO: Decide on targetSdk from calling app whether to instantiate the processor at
1346 // all.
1347 mLegacyNotificationUtil = LegacyNotificationUtil.getInstance();
Joe Onorato46439ce2010-11-19 13:56:21 -08001348 }
1349
Joe Onoratocb109a02011-01-18 17:57:41 -08001350 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001351 * Add a timestamp pertaining to the notification (usually the time the event occurred).
Daniel Sandler0c890492012-09-12 17:23:10 -07001352 * It will be shown in the notification content view by default; use
1353 * {@link Builder#setShowWhen(boolean) setShowWhen} to control this.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001354 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001355 * @see Notification#when
Joe Onoratocb109a02011-01-18 17:57:41 -08001356 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001357 public Builder setWhen(long when) {
1358 mWhen = when;
1359 return this;
1360 }
1361
Joe Onoratocb109a02011-01-18 17:57:41 -08001362 /**
Daniel Sandler0c890492012-09-12 17:23:10 -07001363 * Control whether the timestamp set with {@link Builder#setWhen(long) setWhen} is shown
1364 * in the content view.
1365 */
1366 public Builder setShowWhen(boolean show) {
1367 mShowWhen = show;
1368 return this;
1369 }
1370
1371 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001372 * Show the {@link Notification#when} field as a stopwatch.
Joe Malin8d40d042012-11-05 11:36:40 -08001373 *
1374 * Instead of presenting <code>when</code> as a timestamp, the notification will show an
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001375 * automatically updating display of the minutes and seconds since <code>when</code>.
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001376 *
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001377 * Useful when showing an elapsed time (like an ongoing phone call).
1378 *
1379 * @see android.widget.Chronometer
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001380 * @see Notification#when
1381 */
1382 public Builder setUsesChronometer(boolean b) {
1383 mUseChronometer = b;
1384 return this;
1385 }
1386
1387 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001388 * Set the small icon resource, which will be used to represent the notification in the
1389 * status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -08001390 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001391
1392 * The platform template for the expanded view will draw this icon in the left, unless a
1393 * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small
1394 * icon will be moved to the right-hand side.
1395 *
1396
1397 * @param icon
1398 * A resource ID in the application's package of the drawable to use.
1399 * @see Notification#icon
Joe Onoratocb109a02011-01-18 17:57:41 -08001400 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001401 public Builder setSmallIcon(int icon) {
1402 mSmallIcon = icon;
1403 return this;
1404 }
1405
Joe Onoratocb109a02011-01-18 17:57:41 -08001406 /**
1407 * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional
1408 * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable
1409 * LevelListDrawable}.
1410 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001411 * @param icon A resource ID in the application's package of the drawable to use.
Joe Onoratocb109a02011-01-18 17:57:41 -08001412 * @param level The level to use for the icon.
1413 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001414 * @see Notification#icon
1415 * @see Notification#iconLevel
Joe Onoratocb109a02011-01-18 17:57:41 -08001416 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001417 public Builder setSmallIcon(int icon, int level) {
1418 mSmallIcon = icon;
1419 mSmallIconLevel = level;
1420 return this;
1421 }
1422
Joe Onoratocb109a02011-01-18 17:57:41 -08001423 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001424 * Set the first line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001425 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001426 public Builder setContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001427 mContentTitle = safeCharSequence(title);
Joe Onorato46439ce2010-11-19 13:56:21 -08001428 return this;
1429 }
1430
Joe Onoratocb109a02011-01-18 17:57:41 -08001431 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001432 * Set the second line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001433 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001434 public Builder setContentText(CharSequence text) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001435 mContentText = safeCharSequence(text);
Joe Onorato46439ce2010-11-19 13:56:21 -08001436 return this;
1437 }
1438
Joe Onoratocb109a02011-01-18 17:57:41 -08001439 /**
Joe Malin8d40d042012-11-05 11:36:40 -08001440 * Set the third line of text in the platform notification template.
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001441 * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the
1442 * same location in the standard template.
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001443 */
1444 public Builder setSubText(CharSequence text) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001445 mSubText = safeCharSequence(text);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001446 return this;
1447 }
1448
1449 /**
Joe Onoratocb109a02011-01-18 17:57:41 -08001450 * Set the large number at the right-hand side of the notification. This is
1451 * equivalent to setContentInfo, although it might show the number in a different
1452 * font size for readability.
1453 */
Joe Onorato8595a3d2010-11-19 18:12:07 -08001454 public Builder setNumber(int number) {
1455 mNumber = number;
1456 return this;
1457 }
1458
Joe Onoratocb109a02011-01-18 17:57:41 -08001459 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001460 * A small piece of additional information pertaining to this notification.
1461 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001462 * The platform template will draw this on the last line of the notification, at the far
1463 * right (to the right of a smallIcon if it has been placed there).
Joe Onoratocb109a02011-01-18 17:57:41 -08001464 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001465 public Builder setContentInfo(CharSequence info) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001466 mContentInfo = safeCharSequence(info);
Joe Onorato46439ce2010-11-19 13:56:21 -08001467 return this;
1468 }
1469
Joe Onoratocb109a02011-01-18 17:57:41 -08001470 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001471 * Set the progress this notification represents.
1472 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001473 * The platform template will represent this using a {@link ProgressBar}.
Jeff Sharkey1c400132011-08-05 14:50:13 -07001474 */
1475 public Builder setProgress(int max, int progress, boolean indeterminate) {
1476 mProgressMax = max;
1477 mProgress = progress;
1478 mProgressIndeterminate = indeterminate;
1479 return this;
1480 }
1481
1482 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001483 * Supply a custom RemoteViews to use instead of the platform template.
1484 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001485 * @see Notification#contentView
Joe Onoratocb109a02011-01-18 17:57:41 -08001486 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001487 public Builder setContent(RemoteViews views) {
1488 mContentView = views;
1489 return this;
1490 }
1491
Joe Onoratocb109a02011-01-18 17:57:41 -08001492 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001493 * Supply a {@link PendingIntent} to be sent when the notification is clicked.
1494 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001495 * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you
1496 * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use
1497 * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)}
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001498 * to assign PendingIntents to individual views in that custom layout (i.e., to create
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001499 * clickable buttons inside the notification view).
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001500 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001501 * @see Notification#contentIntent Notification.contentIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001502 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001503 public Builder setContentIntent(PendingIntent intent) {
1504 mContentIntent = intent;
1505 return this;
1506 }
1507
Joe Onoratocb109a02011-01-18 17:57:41 -08001508 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001509 * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user.
1510 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001511 * @see Notification#deleteIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001512 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001513 public Builder setDeleteIntent(PendingIntent intent) {
1514 mDeleteIntent = intent;
1515 return this;
1516 }
1517
Joe Onoratocb109a02011-01-18 17:57:41 -08001518 /**
1519 * An intent to launch instead of posting the notification to the status bar.
1520 * Only for use with extremely high-priority notifications demanding the user's
1521 * <strong>immediate</strong> attention, such as an incoming phone call or
1522 * alarm clock that the user has explicitly set to a particular time.
1523 * If this facility is used for something else, please give the user an option
1524 * to turn it off and use a normal notification, as this can be extremely
1525 * disruptive.
1526 *
1527 * @param intent The pending intent to launch.
1528 * @param highPriority Passing true will cause this notification to be sent
1529 * even if other notifications are suppressed.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001530 *
1531 * @see Notification#fullScreenIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001532 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001533 public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
1534 mFullScreenIntent = intent;
1535 setFlag(FLAG_HIGH_PRIORITY, highPriority);
1536 return this;
1537 }
1538
Joe Onoratocb109a02011-01-18 17:57:41 -08001539 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001540 * Set the "ticker" text which is displayed in the status bar when the notification first
Joe Onoratocb109a02011-01-18 17:57:41 -08001541 * arrives.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001542 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001543 * @see Notification#tickerText
Joe Onoratocb109a02011-01-18 17:57:41 -08001544 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001545 public Builder setTicker(CharSequence tickerText) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001546 mTickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08001547 return this;
1548 }
1549
Joe Onoratocb109a02011-01-18 17:57:41 -08001550 /**
1551 * Set the text that is displayed in the status bar when the notification first
1552 * arrives, and also a RemoteViews object that may be displayed instead on some
1553 * devices.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001554 *
1555 * @see Notification#tickerText
1556 * @see Notification#tickerView
Joe Onoratocb109a02011-01-18 17:57:41 -08001557 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001558 public Builder setTicker(CharSequence tickerText, RemoteViews views) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001559 mTickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08001560 mTickerView = views;
1561 return this;
1562 }
1563
Joe Onoratocb109a02011-01-18 17:57:41 -08001564 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001565 * Add a large icon to the notification (and the ticker on some devices).
1566 *
1567 * In the platform template, this image will be shown on the left of the notification view
1568 * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side).
1569 *
1570 * @see Notification#largeIcon
Joe Onoratocb109a02011-01-18 17:57:41 -08001571 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001572 public Builder setLargeIcon(Bitmap icon) {
1573 mLargeIcon = icon;
1574 return this;
1575 }
1576
Joe Onoratocb109a02011-01-18 17:57:41 -08001577 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001578 * Set the sound to play.
1579 *
1580 * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications.
1581 *
1582 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001583 */
Joe Onorato52f80cd2010-11-21 15:34:48 -08001584 public Builder setSound(Uri sound) {
1585 mSound = sound;
1586 mAudioStreamType = STREAM_DEFAULT;
1587 return this;
1588 }
1589
Joe Onoratocb109a02011-01-18 17:57:41 -08001590 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001591 * Set the sound to play, along with a specific stream on which to play it.
Joe Onoratocb109a02011-01-18 17:57:41 -08001592 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001593 * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants.
1594 *
1595 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001596 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001597 public Builder setSound(Uri sound, int streamType) {
1598 mSound = sound;
1599 mAudioStreamType = streamType;
1600 return this;
1601 }
1602
Joe Onoratocb109a02011-01-18 17:57:41 -08001603 /**
1604 * Set the vibration pattern to use.
1605 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001606
1607 * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the
1608 * <code>pattern</code> parameter.
1609 *
1610
1611 * @see Notification#vibrate
Joe Onoratocb109a02011-01-18 17:57:41 -08001612 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001613 public Builder setVibrate(long[] pattern) {
1614 mVibrate = pattern;
1615 return this;
1616 }
1617
Joe Onoratocb109a02011-01-18 17:57:41 -08001618 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001619 * Set the desired color for the indicator LED on the device, as well as the
1620 * blink duty cycle (specified in milliseconds).
1621 *
1622
1623 * Not all devices will honor all (or even any) of these values.
1624 *
1625
1626 * @see Notification#ledARGB
1627 * @see Notification#ledOnMS
1628 * @see Notification#ledOffMS
Joe Onoratocb109a02011-01-18 17:57:41 -08001629 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001630 public Builder setLights(int argb, int onMs, int offMs) {
1631 mLedArgb = argb;
1632 mLedOnMs = onMs;
1633 mLedOffMs = offMs;
Joe Onorato46439ce2010-11-19 13:56:21 -08001634 return this;
1635 }
1636
Joe Onoratocb109a02011-01-18 17:57:41 -08001637 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001638 * Set whether this is an "ongoing" notification.
Joe Onoratocb109a02011-01-18 17:57:41 -08001639 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001640
1641 * Ongoing notifications cannot be dismissed by the user, so your application or service
1642 * must take care of canceling them.
1643 *
1644
1645 * They are typically used to indicate a background task that the user is actively engaged
1646 * with (e.g., playing music) or is pending in some way and therefore occupying the device
1647 * (e.g., a file download, sync operation, active network connection).
1648 *
1649
1650 * @see Notification#FLAG_ONGOING_EVENT
1651 * @see Service#setForeground(boolean)
Joe Onoratocb109a02011-01-18 17:57:41 -08001652 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001653 public Builder setOngoing(boolean ongoing) {
1654 setFlag(FLAG_ONGOING_EVENT, ongoing);
1655 return this;
1656 }
1657
Joe Onoratocb109a02011-01-18 17:57:41 -08001658 /**
1659 * Set this flag if you would only like the sound, vibrate
1660 * and ticker to be played if the notification is not already showing.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001661 *
1662 * @see Notification#FLAG_ONLY_ALERT_ONCE
Joe Onoratocb109a02011-01-18 17:57:41 -08001663 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001664 public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
1665 setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
1666 return this;
1667 }
1668
Joe Onoratocb109a02011-01-18 17:57:41 -08001669 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001670 * Make this notification automatically dismissed when the user touches it. The
1671 * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens.
1672 *
1673 * @see Notification#FLAG_AUTO_CANCEL
Joe Onoratocb109a02011-01-18 17:57:41 -08001674 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001675 public Builder setAutoCancel(boolean autoCancel) {
Joe Onorato281d83f2011-01-04 17:13:10 -08001676 setFlag(FLAG_AUTO_CANCEL, autoCancel);
Joe Onorato46439ce2010-11-19 13:56:21 -08001677 return this;
1678 }
1679
Joe Onoratocb109a02011-01-18 17:57:41 -08001680 /**
Griff Hazendfcb0802014-02-11 12:00:00 -08001681 * Set whether or not this notification should not bridge to other devices.
1682 *
1683 * <p>Some notifications can be bridged to other devices for remote display.
1684 * This hint can be set to recommend this notification not be bridged.
1685 */
1686 public Builder setLocalOnly(boolean localOnly) {
1687 setFlag(FLAG_LOCAL_ONLY, localOnly);
1688 return this;
1689 }
1690
1691 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001692 * Set which notification properties will be inherited from system defaults.
Joe Onoratocb109a02011-01-18 17:57:41 -08001693 * <p>
1694 * The value should be one or more of the following fields combined with
1695 * bitwise-or:
1696 * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}.
1697 * <p>
1698 * For all default values, use {@link #DEFAULT_ALL}.
1699 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001700 public Builder setDefaults(int defaults) {
1701 mDefaults = defaults;
1702 return this;
1703 }
1704
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001705 /**
1706 * Set the priority of this notification.
1707 *
1708 * @see Notification#priority
1709 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001710 public Builder setPriority(@Priority int pri) {
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001711 mPriority = pri;
1712 return this;
1713 }
Joe Malin8d40d042012-11-05 11:36:40 -08001714
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001715 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -04001716 * Set the notification category.
Joe Malin8d40d042012-11-05 11:36:40 -08001717 *
John Spurlockfd7f1e02014-03-18 16:41:57 -04001718 * @see Notification#category
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001719 */
John Spurlockfd7f1e02014-03-18 16:41:57 -04001720 public Builder setCategory(String category) {
1721 mCategory = category;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001722 return this;
1723 }
1724
1725 /**
Griff Hazen720042b2014-02-24 15:46:56 -08001726 * Merge additional metadata into this notification.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001727 *
Griff Hazen720042b2014-02-24 15:46:56 -08001728 * <p>Values within the Bundle will replace existing extras values in this Builder.
1729 *
1730 * @see Notification#extras
1731 */
1732 public Builder addExtras(Bundle bag) {
1733 if (mExtras == null) {
1734 mExtras = new Bundle(bag);
1735 } else {
1736 mExtras.putAll(bag);
1737 }
1738 return this;
1739 }
1740
1741 /**
1742 * Set metadata for this notification.
1743 *
1744 * <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 -04001745 * current contents are copied into the Notification each time {@link #build()} is
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001746 * called.
1747 *
Griff Hazen720042b2014-02-24 15:46:56 -08001748 * <p>Replaces any existing extras values with those from the provided Bundle.
1749 * Use {@link #addExtras} to merge in metadata instead.
1750 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001751 * @see Notification#extras
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001752 */
1753 public Builder setExtras(Bundle bag) {
1754 mExtras = bag;
1755 return this;
1756 }
1757
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001758 /**
Griff Hazen720042b2014-02-24 15:46:56 -08001759 * Get the current metadata Bundle used by this notification Builder.
1760 *
1761 * <p>The returned Bundle is shared with this Builder.
1762 *
1763 * <p>The current contents of this Bundle are copied into the Notification each time
1764 * {@link #build()} is called.
1765 *
1766 * @see Notification#extras
1767 */
1768 public Bundle getExtras() {
1769 if (mExtras == null) {
1770 mExtras = new Bundle();
1771 }
1772 return mExtras;
1773 }
1774
1775 /**
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001776 * Add an action to this notification. Actions are typically displayed by
1777 * the system as a button adjacent to the notification content.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04001778 * <p>
1779 * Every action must have an icon (32dp square and matching the
1780 * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo
1781 * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}.
1782 * <p>
1783 * A notification in its expanded form can display up to 3 actions, from left to right in
1784 * the order they were added. Actions will not be displayed when the notification is
1785 * collapsed, however, so be sure that any essential functions may be accessed by the user
1786 * in some other way (for example, in the Activity pointed to by {@link #contentIntent}).
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001787 *
1788 * @param icon Resource ID of a drawable that represents the action.
1789 * @param title Text describing the action.
1790 * @param intent PendingIntent to be fired when the action is invoked.
1791 */
1792 public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001793 mActions.add(new Action(icon, safeCharSequence(title), intent));
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001794 return this;
1795 }
1796
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001797 /**
1798 * Add a rich notification style to be applied at build time.
1799 *
1800 * @param style Object responsible for modifying the notification style.
1801 */
1802 public Builder setStyle(Style style) {
1803 if (mStyle != style) {
1804 mStyle = style;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07001805 if (mStyle != null) {
1806 mStyle.setBuilder(this);
1807 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001808 }
1809 return this;
1810 }
1811
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001812 /**
1813 * Specify the value of {@link #visibility}.
1814
1815 * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default),
1816 * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}.
1817 *
1818 * @return The same Builder.
1819 */
1820 public Builder setVisibility(int visibility) {
1821 mVisibility = visibility;
1822 return this;
1823 }
1824
1825 /**
1826 * Supply a replacement Notification whose contents should be shown in insecure contexts
1827 * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}.
1828 * @param n A replacement notification, presumably with some or all info redacted.
1829 * @return The same Builder.
1830 */
1831 public Builder setPublicVersion(Notification n) {
1832 mPublicVersion = n;
1833 return this;
1834 }
1835
Joe Onorato46439ce2010-11-19 13:56:21 -08001836 private void setFlag(int mask, boolean value) {
1837 if (value) {
1838 mFlags |= mask;
1839 } else {
1840 mFlags &= ~mask;
1841 }
1842 }
1843
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001844 private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
Joe Onorato561d3852010-11-20 18:09:34 -08001845 RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001846 boolean showLine3 = false;
1847 boolean showLine2 = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001848 int smallIconImageViewId = R.id.icon;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01001849 if (!mQuantumTheme && mPriority < PRIORITY_LOW) {
Daniel Sandlere95658c2012-05-10 00:33:54 -04001850 contentView.setInt(R.id.icon,
1851 "setBackgroundResource", R.drawable.notification_template_icon_low_bg);
1852 contentView.setInt(R.id.status_bar_latest_event_content,
1853 "setBackgroundResource", R.drawable.notification_bg_low);
1854 }
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001855 if (mLargeIcon != null) {
1856 contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
1857 processLegacyLargeIcon(mLargeIcon, contentView);
1858 smallIconImageViewId = R.id.right_icon;
1859 }
Joe Onorato561d3852010-11-20 18:09:34 -08001860 if (mSmallIcon != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001861 contentView.setImageViewResource(smallIconImageViewId, mSmallIcon);
1862 contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001863 if (mLargeIcon != null) {
1864 processLegacySmallIcon(mSmallIcon, smallIconImageViewId, contentView);
1865 } else {
1866 processLegacyLargeIcon(mSmallIcon, contentView);
1867 }
1868
Jeff Sharkey1c400132011-08-05 14:50:13 -07001869 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001870 contentView.setViewVisibility(smallIconImageViewId, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001871 }
1872 if (mContentTitle != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001873 contentView.setTextViewText(R.id.title, processLegacyText(mContentTitle));
Joe Onorato561d3852010-11-20 18:09:34 -08001874 }
1875 if (mContentText != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001876 contentView.setTextViewText(R.id.text, processLegacyText(mContentText));
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001877 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001878 }
1879 if (mContentInfo != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001880 contentView.setTextViewText(R.id.info, processLegacyText(mContentInfo));
Jeff Sharkey1c400132011-08-05 14:50:13 -07001881 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001882 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001883 } else if (mNumber > 0) {
Daniel Sandlerebce0112011-06-16 16:44:51 -04001884 final int tooBig = mContext.getResources().getInteger(
1885 R.integer.status_bar_notification_info_maxnum);
1886 if (mNumber > tooBig) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001887 contentView.setTextViewText(R.id.info, processLegacyText(
1888 mContext.getResources().getString(
1889 R.string.status_bar_notification_info_overflow)));
Joe Onorato059a2f82011-01-04 10:27:01 -08001890 } else {
1891 NumberFormat f = NumberFormat.getIntegerInstance();
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001892 contentView.setTextViewText(R.id.info, processLegacyText(f.format(mNumber)));
Joe Onorato059a2f82011-01-04 10:27:01 -08001893 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001894 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001895 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001896 } else {
1897 contentView.setViewVisibility(R.id.info, View.GONE);
1898 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001899
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001900 // Need to show three lines?
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001901 if (mSubText != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001902 contentView.setTextViewText(R.id.text, processLegacyText(mSubText));
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001903 if (mContentText != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01001904 contentView.setTextViewText(R.id.text2, processLegacyText(mContentText));
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001905 contentView.setViewVisibility(R.id.text2, View.VISIBLE);
1906 showLine2 = true;
1907 } else {
1908 contentView.setViewVisibility(R.id.text2, View.GONE);
1909 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001910 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001911 contentView.setViewVisibility(R.id.text2, View.GONE);
1912 if (mProgressMax != 0 || mProgressIndeterminate) {
1913 contentView.setProgressBar(
1914 R.id.progress, mProgressMax, mProgress, mProgressIndeterminate);
1915 contentView.setViewVisibility(R.id.progress, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001916 showLine2 = true;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001917 } else {
1918 contentView.setViewVisibility(R.id.progress, View.GONE);
1919 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001920 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001921 if (showLine2) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001922 if (fitIn1U) {
1923 // need to shrink all the type to make sure everything fits
1924 final Resources res = mContext.getResources();
1925 final float subTextSize = res.getDimensionPixelSize(
1926 R.dimen.notification_subtext_size);
1927 contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize);
1928 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001929 // vertical centering
1930 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
1931 }
1932
Daniel Sandler0c890492012-09-12 17:23:10 -07001933 if (mWhen != 0 && mShowWhen) {
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001934 if (mUseChronometer) {
1935 contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
1936 contentView.setLong(R.id.chronometer, "setBase",
1937 mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
1938 contentView.setBoolean(R.id.chronometer, "setStarted", true);
1939 } else {
1940 contentView.setViewVisibility(R.id.time, View.VISIBLE);
1941 contentView.setLong(R.id.time, "setTime", mWhen);
1942 }
Daniel Sandler0c890492012-09-12 17:23:10 -07001943 } else {
1944 contentView.setViewVisibility(R.id.time, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001945 }
Daniel Sandler0c890492012-09-12 17:23:10 -07001946
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001947 contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001948 contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001949 return contentView;
1950 }
1951
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001952 private RemoteViews applyStandardTemplateWithActions(int layoutId) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001953 RemoteViews big = applyStandardTemplate(layoutId, false);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001954
1955 int N = mActions.size();
1956 if (N > 0) {
Chris Wrend6297db2012-05-03 16:20:13 -04001957 // Log.d("Notification", "has actions: " + mContentText);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001958 big.setViewVisibility(R.id.actions, View.VISIBLE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001959 big.setViewVisibility(R.id.action_divider, View.VISIBLE);
Daniel Sandler8680bf82012-05-15 16:52:52 -04001960 if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS;
Chris Wren2c22eb02012-05-08 09:49:13 -04001961 big.removeAllViews(R.id.actions);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001962 for (int i=0; i<N; i++) {
1963 final RemoteViews button = generateActionButton(mActions.get(i));
Chris Wrend6297db2012-05-03 16:20:13 -04001964 //Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001965 big.addView(R.id.actions, button);
1966 }
1967 }
1968 return big;
1969 }
1970
Joe Onorato46439ce2010-11-19 13:56:21 -08001971 private RemoteViews makeContentView() {
1972 if (mContentView != null) {
1973 return mContentView;
1974 } else {
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01001975 return applyStandardTemplate(getBaseLayoutResource(), true); // no more special large_icon flavor
Joe Onorato46439ce2010-11-19 13:56:21 -08001976 }
1977 }
1978
1979 private RemoteViews makeTickerView() {
1980 if (mTickerView != null) {
1981 return mTickerView;
1982 } else {
Joe Onorato561d3852010-11-20 18:09:34 -08001983 if (mContentView == null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001984 return applyStandardTemplate(mLargeIcon == null
Joe Onorato561d3852010-11-20 18:09:34 -08001985 ? R.layout.status_bar_latest_event_ticker
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001986 : R.layout.status_bar_latest_event_ticker_large_icon, true);
Joe Onorato561d3852010-11-20 18:09:34 -08001987 } else {
1988 return null;
1989 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001990 }
1991 }
1992
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001993 private RemoteViews makeBigContentView() {
1994 if (mActions.size() == 0) return null;
1995
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01001996 return applyStandardTemplateWithActions(getBigBaseLayoutResource());
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001997 }
1998
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01001999 private RemoteViews makeHeadsUpContentView() {
Chris Wren8fd39ec2014-02-27 17:43:26 -05002000 if (mActions.size() == 0) return null;
2001
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002002 return applyStandardTemplateWithActions(getBigBaseLayoutResource());
Chris Wren8fd39ec2014-02-27 17:43:26 -05002003 }
2004
2005
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002006 private RemoteViews generateActionButton(Action action) {
Daniel Sandler8680bf82012-05-15 16:52:52 -04002007 final boolean tombstone = (action.actionIntent == null);
Joe Malin8d40d042012-11-05 11:36:40 -08002008 RemoteViews button = new RemoteViews(mContext.getPackageName(),
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002009 tombstone ? getActionTombstoneLayoutResource()
2010 : getActionLayoutResource());
Chris Wren8749ac8a2013-12-03 14:31:01 -05002011 button.setTextViewCompoundDrawablesRelative(R.id.action0, action.icon, 0, 0, 0);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002012 button.setTextViewText(R.id.action0, processLegacyText(action.title));
Daniel Sandler8680bf82012-05-15 16:52:52 -04002013 if (!tombstone) {
Daniel Sandlere5518842012-05-10 16:20:40 -04002014 button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
Daniel Sandlere5518842012-05-10 16:20:40 -04002015 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002016 button.setContentDescription(R.id.action0, action.title);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002017 processLegacyAction(action, button);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002018 return button;
2019 }
2020
Joe Onoratocb109a02011-01-18 17:57:41 -08002021 /**
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002022 * @return Whether we are currently building a notification from a legacy (an app that
2023 * doesn't create quantum notifications by itself) app.
2024 */
2025 private boolean isLegacy() {
2026 return mLegacyNotificationUtil != null;
2027 }
2028
2029 private void processLegacyAction(Action action, RemoteViews button) {
2030 if (isLegacy()) {
2031 if (mLegacyNotificationUtil.isGrayscale(mContext, action.icon)) {
2032 button.setTextViewCompoundDrawablesRelativeColorFilter(R.id.action0, 0,
2033 mContext.getResources().getColor(
2034 R.color.notification_action_legacy_color_filter),
2035 PorterDuff.Mode.MULTIPLY);
2036 }
2037 }
2038 }
2039
2040 private CharSequence processLegacyText(CharSequence charSequence) {
2041 if (isLegacy()) {
2042 return mLegacyNotificationUtil.invertCharSequenceColors(charSequence);
2043 } else {
2044 return charSequence;
2045 }
2046 }
2047
2048 private void processLegacyLargeIcon(int largeIconId, RemoteViews contentView) {
2049 if (isLegacy()) {
2050 processLegacyLargeIcon(
2051 mLegacyNotificationUtil.isGrayscale(mContext, largeIconId),
2052 contentView);
2053 }
2054 }
2055
2056 private void processLegacyLargeIcon(Bitmap largeIcon, RemoteViews contentView) {
2057 if (isLegacy()) {
2058 processLegacyLargeIcon(
2059 mLegacyNotificationUtil.isGrayscale(largeIcon),
2060 contentView);
2061 }
2062 }
2063
2064 private void processLegacyLargeIcon(boolean isGrayscale, RemoteViews contentView) {
2065 if (isLegacy() && isGrayscale) {
2066 contentView.setInt(R.id.icon, "setBackgroundResource",
2067 R.drawable.notification_icon_legacy_bg_inset);
2068 }
2069 }
2070
2071 private void processLegacySmallIcon(int smallIconDrawableId, int smallIconImageViewId,
2072 RemoteViews contentView) {
2073 if (isLegacy()) {
2074 if (mLegacyNotificationUtil.isGrayscale(mContext, smallIconDrawableId)) {
2075 contentView.setDrawableParameters(smallIconImageViewId, false, -1,
2076 mContext.getResources().getColor(
2077 R.color.notification_action_legacy_color_filter),
2078 PorterDuff.Mode.MULTIPLY, -1);
2079 }
2080 }
2081 }
2082
2083 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002084 * Apply the unstyled operations and return a new {@link Notification} object.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002085 * @hide
Joe Onoratocb109a02011-01-18 17:57:41 -08002086 */
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002087 public Notification buildUnstyled() {
Joe Onorato46439ce2010-11-19 13:56:21 -08002088 Notification n = new Notification();
2089 n.when = mWhen;
2090 n.icon = mSmallIcon;
2091 n.iconLevel = mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08002092 n.number = mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08002093 n.contentView = makeContentView();
2094 n.contentIntent = mContentIntent;
2095 n.deleteIntent = mDeleteIntent;
2096 n.fullScreenIntent = mFullScreenIntent;
2097 n.tickerText = mTickerText;
2098 n.tickerView = makeTickerView();
2099 n.largeIcon = mLargeIcon;
2100 n.sound = mSound;
2101 n.audioStreamType = mAudioStreamType;
2102 n.vibrate = mVibrate;
2103 n.ledARGB = mLedArgb;
2104 n.ledOnMS = mLedOnMs;
2105 n.ledOffMS = mLedOffMs;
2106 n.defaults = mDefaults;
2107 n.flags = mFlags;
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002108 n.bigContentView = makeBigContentView();
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002109 n.headsUpContentView = makeHeadsUpContentView();
Daniel Sandler26c13432013-04-04 11:01:04 -04002110 if (mLedOnMs != 0 || mLedOffMs != 0) {
Joe Onorato8d0b6552010-11-22 16:09:29 -08002111 n.flags |= FLAG_SHOW_LIGHTS;
2112 }
2113 if ((mDefaults & DEFAULT_LIGHTS) != 0) {
2114 n.flags |= FLAG_SHOW_LIGHTS;
2115 }
John Spurlockfd7f1e02014-03-18 16:41:57 -04002116 n.category = mCategory;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002117 n.priority = mPriority;
Daniel Sandlera0a938c2012-03-15 08:42:37 -04002118 if (mActions.size() > 0) {
2119 n.actions = new Action[mActions.size()];
2120 mActions.toArray(n.actions);
2121 }
Dan Sandler0bf2ed82013-12-21 23:33:41 -06002122 n.visibility = mVisibility;
2123
2124 if (mPublicVersion != null) {
2125 n.publicVersion = new Notification();
2126 mPublicVersion.cloneInto(n.publicVersion, true);
2127 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002128
Joe Onorato46439ce2010-11-19 13:56:21 -08002129 return n;
2130 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002131
2132 /**
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002133 * Capture, in the provided bundle, semantic information used in the construction of
2134 * this Notification object.
2135 * @hide
2136 */
Griff Hazen720042b2014-02-24 15:46:56 -08002137 public void populateExtras(Bundle extras) {
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002138 // Store original information used in the construction of this object
2139 extras.putCharSequence(EXTRA_TITLE, mContentTitle);
2140 extras.putCharSequence(EXTRA_TEXT, mContentText);
2141 extras.putCharSequence(EXTRA_SUB_TEXT, mSubText);
2142 extras.putCharSequence(EXTRA_INFO_TEXT, mContentInfo);
2143 extras.putInt(EXTRA_SMALL_ICON, mSmallIcon);
2144 extras.putInt(EXTRA_PROGRESS, mProgress);
2145 extras.putInt(EXTRA_PROGRESS_MAX, mProgressMax);
2146 extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mProgressIndeterminate);
2147 extras.putBoolean(EXTRA_SHOW_CHRONOMETER, mUseChronometer);
2148 extras.putBoolean(EXTRA_SHOW_WHEN, mShowWhen);
John Spurlockac08a472013-06-10 11:37:08 -04002149 if (mLargeIcon != null) {
2150 extras.putParcelable(EXTRA_LARGE_ICON, mLargeIcon);
2151 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002152 }
2153
2154 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002155 * @deprecated Use {@link #build()} instead.
2156 */
2157 @Deprecated
2158 public Notification getNotification() {
2159 return build();
2160 }
2161
2162 /**
2163 * Combine all of the options that have been set and return a new {@link Notification}
2164 * object.
2165 */
2166 public Notification build() {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002167 Notification n = buildUnstyled();
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002168
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002169 if (mStyle != null) {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002170 n = mStyle.buildStyled(n);
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002171 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002172
2173 n.extras = mExtras != null ? new Bundle(mExtras) : new Bundle();
2174
Griff Hazen720042b2014-02-24 15:46:56 -08002175 populateExtras(n.extras);
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002176 if (mStyle != null) {
2177 mStyle.addExtras(n.extras);
2178 }
2179
2180 return n;
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002181 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002182
2183 /**
2184 * Apply this Builder to an existing {@link Notification} object.
2185 *
2186 * @hide
2187 */
2188 public Notification buildInto(Notification n) {
Daniel Sandler1a497d32013-04-18 14:52:45 -04002189 build().cloneInto(n, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002190 return n;
2191 }
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002192
2193
2194 private int getBaseLayoutResource() {
2195 return mQuantumTheme
2196 ? R.layout.notification_template_quantum_base
2197 : R.layout.notification_template_base;
2198 }
2199
2200 private int getBigBaseLayoutResource() {
2201 return mQuantumTheme
2202 ? R.layout.notification_template_quantum_big_base
2203 : R.layout.notification_template_big_base;
2204 }
2205
2206 private int getBigPictureLayoutResource() {
2207 return mQuantumTheme
2208 ? R.layout.notification_template_quantum_big_picture
2209 : R.layout.notification_template_big_picture;
2210 }
2211
2212 private int getBigTextLayoutResource() {
2213 return mQuantumTheme
2214 ? R.layout.notification_template_quantum_big_text
2215 : R.layout.notification_template_big_text;
2216 }
2217
2218 private int getInboxLayoutResource() {
2219 return mQuantumTheme
2220 ? R.layout.notification_template_quantum_inbox
2221 : R.layout.notification_template_inbox;
2222 }
2223
2224 private int getActionLayoutResource() {
2225 return mQuantumTheme
2226 ? R.layout.notification_quantum_action
2227 : R.layout.notification_action;
2228 }
2229
2230 private int getActionTombstoneLayoutResource() {
2231 return mQuantumTheme
2232 ? R.layout.notification_quantum_action_tombstone
2233 : R.layout.notification_action_tombstone;
2234 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002235 }
2236
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002237 /**
2238 * An object that can apply a rich notification style to a {@link Notification.Builder}
2239 * object.
2240 */
Griff Hazendfcb0802014-02-11 12:00:00 -08002241 public static abstract class Style {
Chris Wrend6297db2012-05-03 16:20:13 -04002242 private CharSequence mBigContentTitle;
2243 private CharSequence mSummaryText = null;
Daniel Sandler619738c2012-06-07 16:33:08 -04002244 private boolean mSummaryTextSet = false;
Chris Wrend6297db2012-05-03 16:20:13 -04002245
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002246 protected Builder mBuilder;
2247
Chris Wrend6297db2012-05-03 16:20:13 -04002248 /**
2249 * Overrides ContentTitle in the big form of the template.
2250 * This defaults to the value passed to setContentTitle().
2251 */
2252 protected void internalSetBigContentTitle(CharSequence title) {
2253 mBigContentTitle = title;
2254 }
2255
2256 /**
2257 * Set the first line of text after the detail section in the big form of the template.
2258 */
2259 protected void internalSetSummaryText(CharSequence cs) {
2260 mSummaryText = cs;
Daniel Sandler619738c2012-06-07 16:33:08 -04002261 mSummaryTextSet = true;
Chris Wrend6297db2012-05-03 16:20:13 -04002262 }
2263
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002264 public void setBuilder(Builder builder) {
2265 if (mBuilder != builder) {
2266 mBuilder = builder;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07002267 if (mBuilder != null) {
2268 mBuilder.setStyle(this);
2269 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002270 }
2271 }
2272
Chris Wrend6297db2012-05-03 16:20:13 -04002273 protected void checkBuilder() {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002274 if (mBuilder == null) {
2275 throw new IllegalArgumentException("Style requires a valid Builder object");
2276 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002277 }
Chris Wrend6297db2012-05-03 16:20:13 -04002278
2279 protected RemoteViews getStandardView(int layoutId) {
2280 checkBuilder();
2281
2282 if (mBigContentTitle != null) {
2283 mBuilder.setContentTitle(mBigContentTitle);
2284 }
2285
Chris Wrend6297db2012-05-03 16:20:13 -04002286 RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId);
2287
Chris Wrend6297db2012-05-03 16:20:13 -04002288 if (mBigContentTitle != null && mBigContentTitle.equals("")) {
2289 contentView.setViewVisibility(R.id.line1, View.GONE);
Chris Wren67dc9a02012-05-16 01:03:20 -04002290 } else {
2291 contentView.setViewVisibility(R.id.line1, View.VISIBLE);
Chris Wrend6297db2012-05-03 16:20:13 -04002292 }
2293
Daniel Sandler619738c2012-06-07 16:33:08 -04002294 // The last line defaults to the subtext, but can be replaced by mSummaryText
2295 final CharSequence overflowText =
2296 mSummaryTextSet ? mSummaryText
2297 : mBuilder.mSubText;
2298 if (overflowText != null) {
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002299 contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(overflowText));
Daniel Sandler619738c2012-06-07 16:33:08 -04002300 contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002301 contentView.setViewVisibility(R.id.line3, View.VISIBLE);
Daniel Sandler916ad912012-06-13 12:17:07 -04002302 } else {
2303 contentView.setViewVisibility(R.id.overflow_divider, View.GONE);
2304 contentView.setViewVisibility(R.id.line3, View.GONE);
Chris Wrend6297db2012-05-03 16:20:13 -04002305 }
2306
2307 return contentView;
2308 }
2309
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002310 /**
2311 * @hide
2312 */
2313 public void addExtras(Bundle extras) {
2314 if (mSummaryTextSet) {
2315 extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText);
2316 }
2317 if (mBigContentTitle != null) {
2318 extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle);
2319 }
Chris Wren91ad5632013-06-05 15:05:57 -04002320 extras.putString(EXTRA_TEMPLATE, this.getClass().getName());
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002321 }
2322
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002323 /**
2324 * @hide
2325 */
2326 public abstract Notification buildStyled(Notification wip);
2327
2328 /**
2329 * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is
2330 * attached to.
2331 *
2332 * @return the fully constructed Notification.
2333 */
2334 public Notification build() {
2335 checkBuilder();
2336 return mBuilder.build();
2337 }
Joe Onorato46439ce2010-11-19 13:56:21 -08002338 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002339
2340 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002341 * Helper class for generating large-format notifications that include a large image attachment.
Joe Malin8d40d042012-11-05 11:36:40 -08002342 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002343 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002344 * <pre class="prettyprint">
2345 * Notification noti = new Notification.BigPictureStyle(
2346 * new Notification.Builder()
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002347 * .setContentTitle(&quot;New photo from &quot; + sender.toString())
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002348 * .setContentText(subject)
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002349 * .setSmallIcon(R.drawable.new_post)
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002350 * .setLargeIcon(aBitmap))
2351 * .bigPicture(aBigBitmap)
2352 * .build();
2353 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002354 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002355 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002356 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002357 public static class BigPictureStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002358 private Bitmap mPicture;
Chris Wren3745a3d2012-05-22 15:11:52 -04002359 private Bitmap mBigLargeIcon;
2360 private boolean mBigLargeIconSet = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002361
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002362 public BigPictureStyle() {
2363 }
2364
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002365 public BigPictureStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002366 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002367 }
2368
Chris Wrend6297db2012-05-03 16:20:13 -04002369 /**
2370 * Overrides ContentTitle in the big form of the template.
2371 * This defaults to the value passed to setContentTitle().
2372 */
2373 public BigPictureStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002374 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002375 return this;
2376 }
2377
2378 /**
2379 * Set the first line of text after the detail section in the big form of the template.
2380 */
2381 public BigPictureStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002382 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002383 return this;
2384 }
2385
Chris Wren0bd664d2012-08-01 13:56:56 -04002386 /**
2387 * Provide the bitmap to be used as the payload for the BigPicture notification.
2388 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002389 public BigPictureStyle bigPicture(Bitmap b) {
2390 mPicture = b;
2391 return this;
2392 }
2393
Chris Wren3745a3d2012-05-22 15:11:52 -04002394 /**
Chris Wren3745a3d2012-05-22 15:11:52 -04002395 * Override the large icon when the big notification is shown.
2396 */
2397 public BigPictureStyle bigLargeIcon(Bitmap b) {
2398 mBigLargeIconSet = true;
2399 mBigLargeIcon = b;
2400 return this;
2401 }
2402
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002403 private RemoteViews makeBigContentView() {
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002404 RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource());
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002405
2406 contentView.setImageViewBitmap(R.id.big_picture, mPicture);
2407
2408 return contentView;
2409 }
2410
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002411 /**
2412 * @hide
2413 */
2414 public void addExtras(Bundle extras) {
2415 super.addExtras(extras);
2416
2417 if (mBigLargeIconSet) {
2418 extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon);
2419 }
2420 extras.putParcelable(EXTRA_PICTURE, mPicture);
2421 }
2422
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002423 /**
2424 * @hide
2425 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002426 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002427 public Notification buildStyled(Notification wip) {
Chris Wren3745a3d2012-05-22 15:11:52 -04002428 if (mBigLargeIconSet ) {
2429 mBuilder.mLargeIcon = mBigLargeIcon;
2430 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002431 wip.bigContentView = makeBigContentView();
2432 return wip;
2433 }
2434 }
2435
2436 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002437 * Helper class for generating large-format notifications that include a lot of text.
Joe Malin8d40d042012-11-05 11:36:40 -08002438 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002439 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002440 * <pre class="prettyprint">
Daniel Sandler87682782012-11-07 14:04:42 -05002441 * Notification noti = new Notification.BigTextStyle(
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002442 * new Notification.Builder()
2443 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
2444 * .setContentText(subject)
2445 * .setSmallIcon(R.drawable.new_mail)
2446 * .setLargeIcon(aBitmap))
2447 * .bigText(aVeryLongString)
2448 * .build();
2449 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002450 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002451 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002452 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002453 public static class BigTextStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002454 private CharSequence mBigText;
2455
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002456 public BigTextStyle() {
2457 }
2458
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002459 public BigTextStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002460 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002461 }
2462
Chris Wrend6297db2012-05-03 16:20:13 -04002463 /**
2464 * Overrides ContentTitle in the big form of the template.
2465 * This defaults to the value passed to setContentTitle().
2466 */
2467 public BigTextStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002468 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002469 return this;
2470 }
2471
2472 /**
2473 * Set the first line of text after the detail section in the big form of the template.
2474 */
2475 public BigTextStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002476 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002477 return this;
2478 }
2479
Chris Wren0bd664d2012-08-01 13:56:56 -04002480 /**
2481 * Provide the longer text to be displayed in the big form of the
2482 * template in place of the content text.
2483 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002484 public BigTextStyle bigText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002485 mBigText = safeCharSequence(cs);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002486 return this;
2487 }
2488
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002489 /**
2490 * @hide
2491 */
2492 public void addExtras(Bundle extras) {
2493 super.addExtras(extras);
2494
2495 extras.putCharSequence(EXTRA_TEXT, mBigText);
2496 }
2497
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002498 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04002499 // Remove the content text so line3 only shows if you have a summary
2500 final boolean hadThreeLines = (mBuilder.mContentText != null && mBuilder.mSubText != null);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002501 mBuilder.mContentText = null;
Daniel Sandler916ad912012-06-13 12:17:07 -04002502
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002503 RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource());
Joe Malin8d40d042012-11-05 11:36:40 -08002504
Daniel Sandler619738c2012-06-07 16:33:08 -04002505 if (hadThreeLines) {
2506 // vertical centering
2507 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
2508 }
2509
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002510 contentView.setTextViewText(R.id.big_text, mBuilder.processLegacyText(mBigText));
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002511 contentView.setViewVisibility(R.id.big_text, View.VISIBLE);
Chris Wren3c5f92432012-05-04 16:31:17 -04002512 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002513
2514 return contentView;
2515 }
2516
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002517 /**
2518 * @hide
2519 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002520 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002521 public Notification buildStyled(Notification wip) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002522 wip.bigContentView = makeBigContentView();
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002523
2524 wip.extras.putCharSequence(EXTRA_TEXT, mBigText);
2525
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002526 return wip;
2527 }
2528 }
Daniel Sandler879c5e02012-04-17 16:46:51 -04002529
2530 /**
2531 * Helper class for generating large-format notifications that include a list of (up to 5) strings.
Joe Malin8d40d042012-11-05 11:36:40 -08002532 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04002533 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
2534 * <pre class="prettyprint">
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002535 * Notification noti = new Notification.InboxStyle(
Daniel Sandler879c5e02012-04-17 16:46:51 -04002536 * new Notification.Builder()
Chris Wrend6297db2012-05-03 16:20:13 -04002537 * .setContentTitle(&quot;5 New mails from &quot; + sender.toString())
Daniel Sandler879c5e02012-04-17 16:46:51 -04002538 * .setContentText(subject)
2539 * .setSmallIcon(R.drawable.new_mail)
2540 * .setLargeIcon(aBitmap))
2541 * .addLine(str1)
2542 * .addLine(str2)
Chris Wrend6297db2012-05-03 16:20:13 -04002543 * .setContentTitle("")
2544 * .setSummaryText(&quot;+3 more&quot;)
Daniel Sandler879c5e02012-04-17 16:46:51 -04002545 * .build();
2546 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002547 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04002548 * @see Notification#bigContentView
2549 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002550 public static class InboxStyle extends Style {
Daniel Sandler879c5e02012-04-17 16:46:51 -04002551 private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5);
2552
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002553 public InboxStyle() {
2554 }
2555
Daniel Sandler879c5e02012-04-17 16:46:51 -04002556 public InboxStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002557 setBuilder(builder);
Daniel Sandler879c5e02012-04-17 16:46:51 -04002558 }
2559
Chris Wrend6297db2012-05-03 16:20:13 -04002560 /**
2561 * Overrides ContentTitle in the big form of the template.
2562 * This defaults to the value passed to setContentTitle().
2563 */
2564 public InboxStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002565 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002566 return this;
2567 }
2568
2569 /**
2570 * Set the first line of text after the detail section in the big form of the template.
2571 */
2572 public InboxStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002573 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002574 return this;
2575 }
2576
Chris Wren0bd664d2012-08-01 13:56:56 -04002577 /**
2578 * Append a line to the digest section of the Inbox notification.
2579 */
Daniel Sandler879c5e02012-04-17 16:46:51 -04002580 public InboxStyle addLine(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002581 mTexts.add(safeCharSequence(cs));
Daniel Sandler879c5e02012-04-17 16:46:51 -04002582 return this;
2583 }
2584
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002585 /**
2586 * @hide
2587 */
2588 public void addExtras(Bundle extras) {
2589 super.addExtras(extras);
2590 CharSequence[] a = new CharSequence[mTexts.size()];
2591 extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a));
2592 }
2593
Daniel Sandler879c5e02012-04-17 16:46:51 -04002594 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04002595 // Remove the content text so line3 disappears unless you have a summary
2596 mBuilder.mContentText = null;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01002597 RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource());
Daniel Sandler619738c2012-06-07 16:33:08 -04002598
Chris Wrend6297db2012-05-03 16:20:13 -04002599 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandler879c5e02012-04-17 16:46:51 -04002600
Chris Wrend6297db2012-05-03 16:20:13 -04002601 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 -04002602 R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6};
Chris Wrend6297db2012-05-03 16:20:13 -04002603
Chris Wren4ed80d52012-05-17 09:30:03 -04002604 // Make sure all rows are gone in case we reuse a view.
2605 for (int rowId : rowIds) {
2606 contentView.setViewVisibility(rowId, View.GONE);
2607 }
2608
Chris Wren683ab002012-09-20 10:35:54 -04002609
Daniel Sandler879c5e02012-04-17 16:46:51 -04002610 int i=0;
2611 while (i < mTexts.size() && i < rowIds.length) {
2612 CharSequence str = mTexts.get(i);
2613 if (str != null && !str.equals("")) {
2614 contentView.setViewVisibility(rowIds[i], View.VISIBLE);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01002615 contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str));
Daniel Sandler879c5e02012-04-17 16:46:51 -04002616 }
2617 i++;
2618 }
2619
Chris Wren683ab002012-09-20 10:35:54 -04002620 contentView.setViewVisibility(R.id.inbox_end_pad,
2621 mTexts.size() > 0 ? View.VISIBLE : View.GONE);
2622
2623 contentView.setViewVisibility(R.id.inbox_more,
2624 mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE);
Chris Wren29bb6d92012-05-17 18:09:42 -04002625
Daniel Sandler879c5e02012-04-17 16:46:51 -04002626 return contentView;
2627 }
2628
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002629 /**
2630 * @hide
2631 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002632 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002633 public Notification buildStyled(Notification wip) {
Daniel Sandler879c5e02012-04-17 16:46:51 -04002634 wip.bigContentView = makeBigContentView();
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002635
Daniel Sandler879c5e02012-04-17 16:46:51 -04002636 return wip;
2637 }
2638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002639}