blob: 1e96ebf3d1c50fc9913e533f83e563b02773d972 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Andy Stadler110988c2010-12-03 14:29:16 -080019import com.android.internal.R;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.Context;
22import android.content.Intent;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040023import android.content.res.Resources;
Joe Onoratoef1e7762010-09-17 18:38:38 -040024import android.graphics.Bitmap;
Jeff Sharkey098d5802012-04-26 17:30:34 -070025import android.media.AudioManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.net.Uri;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040027import android.os.BadParcelableException;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050028import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.Parcel;
30import android.os.Parcelable;
Daniel Sandlera2985ed2012-04-03 16:42:00 -040031import android.os.SystemClock;
Jeff Sharkey6d515712012-09-20 16:06:08 -070032import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.text.TextUtils;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040034import android.util.Log;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040035import android.util.TypedValue;
Joe Onorato8595a3d2010-11-19 18:12:07 -080036import android.view.View;
Jeff Sharkey1c400132011-08-05 14:50:13 -070037import android.widget.ProgressBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.widget.RemoteViews;
39
Andy Stadler110988c2010-12-03 14:29:16 -080040import java.text.NumberFormat;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050041import java.util.ArrayList;
Joe Onorato561d3852010-11-20 18:09:34 -080042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043/**
44 * A class that represents how a persistent notification is to be presented to
45 * the user using the {@link android.app.NotificationManager}.
46 *
Joe Onoratocb109a02011-01-18 17:57:41 -080047 * <p>The {@link Notification.Builder Notification.Builder} has been added to make it
48 * easier to construct Notifications.</p>
49 *
Joe Fernandez558459f2011-10-13 16:47:36 -070050 * <div class="special reference">
51 * <h3>Developer Guides</h3>
52 * <p>For a guide to creating notifications, read the
53 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a>
54 * developer guide.</p>
55 * </div>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 */
57public class Notification implements Parcelable
58{
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040059 private static final String TAG = "Notification";
60
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 /**
62 * Use all default values (where applicable).
63 */
64 public static final int DEFAULT_ALL = ~0;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 /**
67 * Use the default notification sound. This will ignore any given
68 * {@link #sound}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050069 *
70
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050072 */
73
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 public static final int DEFAULT_SOUND = 1;
75
76 /**
77 * Use the default notification vibrate. This will ignore any given
Daniel Sandler2561b0b2012-02-13 21:04:12 -050078 * {@link #vibrate}. Using phone vibration requires the
Scott Mainb8b36452009-04-26 15:50:49 -070079 * {@link android.Manifest.permission#VIBRATE VIBRATE} permission.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050080 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050082 */
83
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 public static final int DEFAULT_VIBRATE = 2;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 /**
87 * Use the default notification lights. This will ignore the
88 * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or
89 * {@link #ledOnMS}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050090 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050092 */
93
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 public static final int DEFAULT_LIGHTS = 4;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -050097 * A timestamp related to this notification, in milliseconds since the epoch.
Joe Malin8d40d042012-11-05 11:36:40 -080098 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -050099 * Default value: {@link System#currentTimeMillis() Now}.
100 *
101 * Choose a timestamp that will be most relevant to the user. For most finite events, this
102 * corresponds to the time the event happened (or will happen, in the case of events that have
103 * yet to occur but about which the user is being informed). Indefinite events should be
Joe Malin8d40d042012-11-05 11:36:40 -0800104 * timestamped according to when the activity began.
105 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500106 * Some examples:
Joe Malin8d40d042012-11-05 11:36:40 -0800107 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500108 * <ul>
109 * <li>Notification of a new chat message should be stamped when the message was received.</li>
110 * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li>
111 * <li>Notification of a completed file download should be stamped when the download finished.</li>
112 * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li>
113 * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
114 * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time.
Joe Malin8d40d042012-11-05 11:36:40 -0800115 * </ul>
116 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 */
118 public long when;
119
120 /**
121 * The resource id of a drawable to use as the icon in the status bar.
Daniel Sandlerd952dae2011-02-07 16:33:36 -0500122 * This is required; notifications with an invalid icon resource will not be shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 */
124 public int icon;
125
126 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800127 * If the icon in the status bar is to have more than one level, you can set this. Otherwise,
128 * leave it at its default value of 0.
129 *
130 * @see android.widget.ImageView#setImageLevel
131 * @see android.graphics.drawable#setLevel
132 */
133 public int iconLevel;
134
135 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500136 * The number of events that this notification represents. For example, in a new mail
137 * notification, this could be the number of unread messages.
Joe Malin8d40d042012-11-05 11:36:40 -0800138 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500139 * The system may or may not use this field to modify the appearance of the notification. For
140 * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was
141 * superimposed over the icon in the status bar. Starting with
142 * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by
143 * {@link Notification.Builder} has displayed the number in the expanded notification view.
Joe Malin8d40d042012-11-05 11:36:40 -0800144 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500145 * If the number is 0 or negative, it is never shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 */
147 public int number;
148
149 /**
150 * The intent to execute when the expanded status entry is clicked. If
151 * this is an activity, it must include the
152 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -0800153 * that you take care of task management as described in the
154 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
Dianne Hackborn6ceca582012-01-10 15:24:26 -0800155 * Stack</a> document. In particular, make sure to read the notification section
156 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling
157 * Notifications</a> for the correct ways to launch an application from a
158 * notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 */
160 public PendingIntent contentIntent;
161
162 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500163 * The intent to execute when the notification is explicitly dismissed by the user, either with
164 * the "Clear All" button or by swiping it away individually.
165 *
166 * This probably shouldn't be launching an activity since several of those will be sent
167 * at the same time.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 */
169 public PendingIntent deleteIntent;
170
171 /**
Dianne Hackborn170bae72010-09-03 15:14:28 -0700172 * An intent to launch instead of posting the notification to the status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -0800173 *
174 * @see Notification.Builder#setFullScreenIntent
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400175 */
176 public PendingIntent fullScreenIntent;
177
178 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 * Text to scroll across the screen when this item is added to
Joe Onoratoef1e7762010-09-17 18:38:38 -0400180 * the status bar on large and smaller devices.
181 *
Joe Onorato46439ce2010-11-19 13:56:21 -0800182 * @see #tickerView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 */
184 public CharSequence tickerText;
185
186 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800187 * The view to show as the ticker in the status bar when the notification
188 * is posted.
Joe Onoratoef1e7762010-09-17 18:38:38 -0400189 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800190 public RemoteViews tickerView;
Joe Onoratoef1e7762010-09-17 18:38:38 -0400191
192 /**
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400193 * The view that will represent this notification in the expanded status bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 */
195 public RemoteViews contentView;
196
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400197 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -0400198 * A large-format version of {@link #contentView}, giving the Notification an
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400199 * opportunity to show more detail. The system UI may choose to show this
200 * instead of the normal content view at its discretion.
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400201 */
202 public RemoteViews bigContentView;
203
204 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800205 * The bitmap that may escape the bounds of the panel and bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800207 public Bitmap largeIcon;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208
209 /**
210 * The sound to play.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500211 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 * <p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500213 * To play the default notification sound, see {@link #defaults}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 * </p>
215 */
216 public Uri sound;
217
218 /**
219 * Use this constant as the value for audioStreamType to request that
220 * the default stream type for notifications be used. Currently the
Jeff Sharkey098d5802012-04-26 17:30:34 -0700221 * default stream type is {@link AudioManager#STREAM_NOTIFICATION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 */
223 public static final int STREAM_DEFAULT = -1;
224
225 /**
226 * The audio stream type to use when playing the sound.
227 * Should be one of the STREAM_ constants from
228 * {@link android.media.AudioManager}.
229 */
230 public int audioStreamType = STREAM_DEFAULT;
231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500233 * The pattern with which to vibrate.
234 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 * <p>
236 * To vibrate the default pattern, see {@link #defaults}.
237 * </p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500238 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 * @see android.os.Vibrator#vibrate(long[],int)
240 */
241 public long[] vibrate;
242
243 /**
244 * The color of the led. The hardware will do its best approximation.
245 *
246 * @see #FLAG_SHOW_LIGHTS
247 * @see #flags
248 */
249 public int ledARGB;
250
251 /**
252 * The number of milliseconds for the LED to be on while it's flashing.
253 * The hardware will do its best approximation.
254 *
255 * @see #FLAG_SHOW_LIGHTS
256 * @see #flags
257 */
258 public int ledOnMS;
259
260 /**
261 * The number of milliseconds for the LED to be off while it's flashing.
262 * The hardware will do its best approximation.
263 *
264 * @see #FLAG_SHOW_LIGHTS
265 * @see #flags
266 */
267 public int ledOffMS;
268
269 /**
270 * Specifies which values should be taken from the defaults.
271 * <p>
272 * To set, OR the desired from {@link #DEFAULT_SOUND},
273 * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default
274 * values, use {@link #DEFAULT_ALL}.
275 * </p>
276 */
277 public int defaults;
278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 /**
280 * Bit to be bitwise-ored into the {@link #flags} field that should be
281 * set if you want the LED on for this notification.
282 * <ul>
283 * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB
284 * or 0 for both ledOnMS and ledOffMS.</li>
285 * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li>
286 * <li>To flash the LED, pass the number of milliseconds that it should
287 * be on and off to ledOnMS and ledOffMS.</li>
288 * </ul>
289 * <p>
290 * Since hardware varies, you are not guaranteed that any of the values
291 * you pass are honored exactly. Use the system defaults (TODO) if possible
292 * because they will be set to values that work on any given hardware.
293 * <p>
294 * The alpha channel must be set for forward compatibility.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500295 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 */
297 public static final int FLAG_SHOW_LIGHTS = 0x00000001;
298
299 /**
300 * Bit to be bitwise-ored into the {@link #flags} field that should be
301 * set if this notification is in reference to something that is ongoing,
302 * like a phone call. It should not be set if this notification is in
303 * reference to something that happened at a particular point in time,
304 * like a missed phone call.
305 */
306 public static final int FLAG_ONGOING_EVENT = 0x00000002;
307
308 /**
309 * Bit to be bitwise-ored into the {@link #flags} field that if set,
Scott Mainb8b36452009-04-26 15:50:49 -0700310 * the audio will be repeated until the notification is
311 * cancelled or the notification window is opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 */
313 public static final int FLAG_INSISTENT = 0x00000004;
314
315 /**
316 * Bit to be bitwise-ored into the {@link #flags} field that should be
317 * set if you want the sound and/or vibration play each time the
318 * notification is sent, even if it has not been canceled before that.
319 */
320 public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008;
321
322 /**
323 * Bit to be bitwise-ored into the {@link #flags} field that should be
324 * set if the notification should be canceled when it is clicked by the
Daniel Sandler8aa9ae62012-12-04 23:31:47 -0500325 * user.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 */
328 public static final int FLAG_AUTO_CANCEL = 0x00000010;
329
330 /**
331 * Bit to be bitwise-ored into the {@link #flags} field that should be
332 * set if the notification should not be canceled when the user clicks
333 * the Clear all button.
334 */
335 public static final int FLAG_NO_CLEAR = 0x00000020;
336
Dianne Hackbornd8a43f62009-08-17 23:33:56 -0700337 /**
338 * Bit to be bitwise-ored into the {@link #flags} field that should be
339 * set if this notification represents a currently running service. This
340 * will normally be set for you by {@link Service#startForeground}.
341 */
342 public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;
343
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400344 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500345 * Obsolete flag indicating high-priority notifications; use the priority field instead.
Joe Malin8d40d042012-11-05 11:36:40 -0800346 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500347 * @deprecated Use {@link #priority} with a positive value.
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400348 */
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500349 public static final int FLAG_HIGH_PRIORITY = 0x00000080;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400350
Griff Hazendfcb0802014-02-11 12:00:00 -0800351 /**
352 * Bit to be bitswise-ored into the {@link #flags} field that should be
353 * set if this notification is relevant to the current device only
354 * and it is not recommended that it bridge to other devices.
355 */
356 public static final int FLAG_LOCAL_ONLY = 0x00000100;
357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 public int flags;
359
360 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500361 * Default notification {@link #priority}. If your application does not prioritize its own
362 * notifications, use this value for all notifications.
363 */
364 public static final int PRIORITY_DEFAULT = 0;
365
366 /**
367 * Lower {@link #priority}, for items that are less important. The UI may choose to show these
368 * items smaller, or at a different position in the list, compared with your app's
369 * {@link #PRIORITY_DEFAULT} items.
370 */
371 public static final int PRIORITY_LOW = -1;
372
373 /**
374 * Lowest {@link #priority}; these items might not be shown to the user except under special
375 * circumstances, such as detailed notification logs.
376 */
377 public static final int PRIORITY_MIN = -2;
378
379 /**
380 * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to
381 * show these items larger, or at a different position in notification lists, compared with
382 * your app's {@link #PRIORITY_DEFAULT} items.
383 */
384 public static final int PRIORITY_HIGH = 1;
385
386 /**
387 * Highest {@link #priority}, for your application's most important items that require the
388 * user's prompt attention or input.
389 */
390 public static final int PRIORITY_MAX = 2;
391
392 /**
393 * Relative priority for this notification.
Joe Malin8d40d042012-11-05 11:36:40 -0800394 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500395 * Priority is an indication of how much of the user's valuable attention should be consumed by
396 * this notification. Low-priority notifications may be hidden from the user in certain
397 * situations, while the user might be interrupted for a higher-priority notification. The
Daniel Sandler6738eee2012-11-16 12:03:32 -0500398 * system will make a determination about how to interpret this priority when presenting
399 * the notification.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500400 */
401 public int priority;
Joe Malin8d40d042012-11-05 11:36:40 -0800402
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500403 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400404 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500405 * Notification type: incoming call (voice or video) or similar synchronous communication request.
406 */
407 public static final String KIND_CALL = "android.call";
408
409 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400410 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500411 * Notification type: incoming direct message (SMS, instant message, etc.).
412 */
413 public static final String KIND_MESSAGE = "android.message";
414
415 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400416 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500417 * Notification type: asynchronous bulk message (email).
418 */
419 public static final String KIND_EMAIL = "android.email";
420
421 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400422 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500423 * Notification type: calendar event.
424 */
425 public static final String KIND_EVENT = "android.event";
426
427 /**
Daniel Sandlera90513d2012-06-04 02:11:17 -0400428 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500429 * Notification type: promotion or advertisement.
430 */
431 public static final String KIND_PROMO = "android.promo";
432
433 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -0400434 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500435 * If this notification matches of one or more special types (see the <code>KIND_*</code>
436 * constants), add them here, best match first.
437 */
438 public String[] kind;
439
440 /**
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400441 * Additional semantic data to be carried around with this Notification.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400442 * <p>
443 * The extras keys defined here are intended to capture the original inputs to {@link Builder}
444 * APIs, and are intended to be used by
445 * {@link android.service.notification.NotificationListenerService} implementations to extract
446 * detailed information from notification objects.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500447 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400448 public Bundle extras = new Bundle();
449
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400450 /**
451 * {@link #extras} key: this is the title of the notification,
452 * as supplied to {@link Builder#setContentTitle(CharSequence)}.
453 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500454 public static final String EXTRA_TITLE = "android.title";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400455
456 /**
457 * {@link #extras} key: this is the title of the notification when shown in expanded form,
458 * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}.
459 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400460 public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400461
462 /**
463 * {@link #extras} key: this is the main text payload, as supplied to
464 * {@link Builder#setContentText(CharSequence)}.
465 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500466 public static final String EXTRA_TEXT = "android.text";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400467
468 /**
469 * {@link #extras} key: this is a third line of text, as supplied to
470 * {@link Builder#setSubText(CharSequence)}.
471 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400472 public static final String EXTRA_SUB_TEXT = "android.subText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400473
474 /**
475 * {@link #extras} key: this is a small piece of additional text as supplied to
476 * {@link Builder#setContentInfo(CharSequence)}.
477 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400478 public static final String EXTRA_INFO_TEXT = "android.infoText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400479
480 /**
481 * {@link #extras} key: this is a line of summary information intended to be shown
482 * alongside expanded notifications, as supplied to (e.g.)
483 * {@link BigTextStyle#setSummaryText(CharSequence)}.
484 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400485 public static final String EXTRA_SUMMARY_TEXT = "android.summaryText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400486
487 /**
488 * {@link #extras} key: this is the resource ID of the notification's main small icon, as
489 * supplied to {@link Builder#setSmallIcon(int)}.
490 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500491 public static final String EXTRA_SMALL_ICON = "android.icon";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400492
493 /**
494 * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the
495 * notification payload, as
496 * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}.
497 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400498 public static final String EXTRA_LARGE_ICON = "android.largeIcon";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400499
500 /**
501 * {@link #extras} key: this is a bitmap to be used instead of the one from
502 * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is
503 * shown in its expanded form, as supplied to
504 * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}.
505 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400506 public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400507
508 /**
509 * {@link #extras} key: this is the progress value supplied to
510 * {@link Builder#setProgress(int, int, boolean)}.
511 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400512 public static final String EXTRA_PROGRESS = "android.progress";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400513
514 /**
515 * {@link #extras} key: this is the maximum value supplied to
516 * {@link Builder#setProgress(int, int, boolean)}.
517 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400518 public static final String EXTRA_PROGRESS_MAX = "android.progressMax";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400519
520 /**
521 * {@link #extras} key: whether the progress bar is indeterminate, supplied to
522 * {@link Builder#setProgress(int, int, boolean)}.
523 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400524 public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400525
526 /**
527 * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically
528 * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to
529 * {@link Builder#setUsesChronometer(boolean)}.
530 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400531 public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400532
533 /**
534 * {@link #extras} key: whether {@link #when} should be shown,
535 * as supplied to {@link Builder#setShowWhen(boolean)}.
536 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400537 public static final String EXTRA_SHOW_WHEN = "android.showWhen";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400538
539 /**
540 * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded
541 * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}.
542 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400543 public static final String EXTRA_PICTURE = "android.picture";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400544
545 /**
546 * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded
547 * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}.
548 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400549 public static final String EXTRA_TEXT_LINES = "android.textLines";
550
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400551 /**
552 * {@link #extras} key: An array of people that this notification relates to, specified
553 * by contacts provider contact URI.
554 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400555 public static final String EXTRA_PEOPLE = "android.people";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500556
557 /**
Scott Greenwald9a05b312013-06-28 00:37:54 -0400558 * @hide
559 * Extra added by NotificationManagerService to indicate whether a NotificationScorer
560 * modified the Notifications's score.
561 */
562 public static final String EXTRA_SCORE_MODIFIED = "android.scoreModified";
563
564 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400565 * Not used.
Chris Wren51c75102013-07-16 20:49:17 -0400566 * @hide
567 */
568 public static final String EXTRA_AS_HEADS_UP = "headsup";
569
570 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400571 * Value for {@link #EXTRA_AS_HEADS_UP}.
Chris Wren51c75102013-07-16 20:49:17 -0400572 * @hide
573 */
574 public static final int HEADS_UP_NEVER = 0;
575
576 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400577 * Default value for {@link #EXTRA_AS_HEADS_UP}.
Chris Wren51c75102013-07-16 20:49:17 -0400578 * @hide
579 */
580 public static final int HEADS_UP_ALLOWED = 1;
581
582 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400583 * Value for {@link #EXTRA_AS_HEADS_UP}.
Chris Wren51c75102013-07-16 20:49:17 -0400584 * @hide
585 */
586 public static final int HEADS_UP_REQUESTED = 2;
587
588 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400589 * Structure to encapsulate a named action that can be shown as part of this notification.
590 * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is
591 * selected by the user.
592 * <p>
593 * Apps should use {@link Builder#addAction(int, CharSequence, PendingIntent)} to create and
594 * attach actions.
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400595 */
Daniel Sandlerea2a3172013-02-20 22:24:20 -0500596 public static class Action implements Parcelable {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400597 /**
598 * Small icon representing the action.
599 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400600 public int icon;
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400601 /**
602 * Title of the action.
603 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400604 public CharSequence title;
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400605 /**
606 * Intent to send when the user invokes this action. May be null, in which case the action
607 * may be rendered in a disabled presentation by the system UI.
608 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400609 public PendingIntent actionIntent;
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400610
611 private Action() { }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400612 private Action(Parcel in) {
613 icon = in.readInt();
614 title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
615 if (in.readInt() == 1) {
616 actionIntent = PendingIntent.CREATOR.createFromParcel(in);
617 }
618 }
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400619 /**
620 * Use {@link Builder#addAction(int, CharSequence, PendingIntent)}.
621 */
622 public Action(int icon, CharSequence title, PendingIntent intent) {
623 this.icon = icon;
624 this.title = title;
625 this.actionIntent = intent;
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400626 }
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400627
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400628 @Override
629 public Action clone() {
630 return new Action(
631 this.icon,
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400632 this.title,
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400633 this.actionIntent // safe to alias
634 );
635 }
636 @Override
637 public int describeContents() {
638 return 0;
639 }
640 @Override
641 public void writeToParcel(Parcel out, int flags) {
642 out.writeInt(icon);
643 TextUtils.writeToParcel(title, out, flags);
644 if (actionIntent != null) {
645 out.writeInt(1);
646 actionIntent.writeToParcel(out, flags);
647 } else {
648 out.writeInt(0);
649 }
650 }
651 public static final Parcelable.Creator<Action> CREATOR
652 = new Parcelable.Creator<Action>() {
653 public Action createFromParcel(Parcel in) {
654 return new Action(in);
655 }
656 public Action[] newArray(int size) {
657 return new Action[size];
658 }
659 };
660 }
661
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400662 /**
663 * Array of all {@link Action} structures attached to this notification by
664 * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of
665 * {@link android.service.notification.NotificationListenerService} that provide an alternative
666 * interface for invoking actions.
667 */
Daniel Sandlerea2a3172013-02-20 22:24:20 -0500668 public Action[] actions;
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400669
670 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500671 * Constructs a Notification object with default values.
Joe Onorato46439ce2010-11-19 13:56:21 -0800672 * You might want to consider using {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 */
674 public Notification()
675 {
676 this.when = System.currentTimeMillis();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500677 this.priority = PRIORITY_DEFAULT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 }
679
680 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 * @hide
682 */
683 public Notification(Context context, int icon, CharSequence tickerText, long when,
684 CharSequence contentTitle, CharSequence contentText, Intent contentIntent)
685 {
686 this.when = when;
687 this.icon = icon;
688 this.tickerText = tickerText;
689 setLatestEventInfo(context, contentTitle, contentText,
690 PendingIntent.getActivity(context, 0, contentIntent, 0));
691 }
692
693 /**
694 * Constructs a Notification object with the information needed to
695 * have a status bar icon without the standard expanded view.
696 *
697 * @param icon The resource id of the icon to put in the status bar.
698 * @param tickerText The text that flows by in the status bar when the notification first
699 * activates.
700 * @param when The time to show in the time field. In the System.currentTimeMillis
701 * timebase.
Joe Onorato46439ce2010-11-19 13:56:21 -0800702 *
703 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800705 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706 public Notification(int icon, CharSequence tickerText, long when)
707 {
708 this.icon = icon;
709 this.tickerText = tickerText;
710 this.when = when;
711 }
712
713 /**
714 * Unflatten the notification from a parcel.
715 */
716 public Notification(Parcel parcel)
717 {
718 int version = parcel.readInt();
719
720 when = parcel.readLong();
721 icon = parcel.readInt();
722 number = parcel.readInt();
723 if (parcel.readInt() != 0) {
724 contentIntent = PendingIntent.CREATOR.createFromParcel(parcel);
725 }
726 if (parcel.readInt() != 0) {
727 deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel);
728 }
729 if (parcel.readInt() != 0) {
730 tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
731 }
732 if (parcel.readInt() != 0) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800733 tickerView = RemoteViews.CREATOR.createFromParcel(parcel);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400734 }
735 if (parcel.readInt() != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 contentView = RemoteViews.CREATOR.createFromParcel(parcel);
737 }
Joe Onorato561d3852010-11-20 18:09:34 -0800738 if (parcel.readInt() != 0) {
739 largeIcon = Bitmap.CREATOR.createFromParcel(parcel);
740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 defaults = parcel.readInt();
742 flags = parcel.readInt();
743 if (parcel.readInt() != 0) {
744 sound = Uri.CREATOR.createFromParcel(parcel);
745 }
746
747 audioStreamType = parcel.readInt();
748 vibrate = parcel.createLongArray();
749 ledARGB = parcel.readInt();
750 ledOnMS = parcel.readInt();
751 ledOffMS = parcel.readInt();
752 iconLevel = parcel.readInt();
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400753
754 if (parcel.readInt() != 0) {
755 fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel);
756 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500757
758 priority = parcel.readInt();
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400759
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500760 kind = parcel.createStringArray(); // may set kind to null
761
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500762 extras = parcel.readBundle(); // may be null
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400763
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500764 actions = parcel.createTypedArray(Action.CREATOR); // may be null
765
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400766 if (parcel.readInt() != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400767 bigContentView = RemoteViews.CREATOR.createFromParcel(parcel);
768 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 }
770
Andy Stadler110988c2010-12-03 14:29:16 -0800771 @Override
Joe Onorato18e69df2010-05-17 22:26:12 -0700772 public Notification clone() {
773 Notification that = new Notification();
Daniel Sandler1a497d32013-04-18 14:52:45 -0400774 cloneInto(that, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500775 return that;
776 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700777
Daniel Sandler1a497d32013-04-18 14:52:45 -0400778 /**
779 * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members
780 * of this into that.
781 * @hide
782 */
783 public void cloneInto(Notification that, boolean heavy) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700784 that.when = this.when;
785 that.icon = this.icon;
786 that.number = this.number;
787
788 // PendingIntents are global, so there's no reason (or way) to clone them.
789 that.contentIntent = this.contentIntent;
790 that.deleteIntent = this.deleteIntent;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400791 that.fullScreenIntent = this.fullScreenIntent;
Joe Onorato18e69df2010-05-17 22:26:12 -0700792
793 if (this.tickerText != null) {
794 that.tickerText = this.tickerText.toString();
795 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400796 if (heavy && this.tickerView != null) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800797 that.tickerView = this.tickerView.clone();
Joe Onoratoef1e7762010-09-17 18:38:38 -0400798 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400799 if (heavy && this.contentView != null) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700800 that.contentView = this.contentView.clone();
801 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400802 if (heavy && this.largeIcon != null) {
Joe Onorato561d3852010-11-20 18:09:34 -0800803 that.largeIcon = Bitmap.createBitmap(this.largeIcon);
804 }
Jozef BABJAKa8b91832011-02-22 08:05:08 +0100805 that.iconLevel = this.iconLevel;
Joe Onorato18e69df2010-05-17 22:26:12 -0700806 that.sound = this.sound; // android.net.Uri is immutable
807 that.audioStreamType = this.audioStreamType;
808
809 final long[] vibrate = this.vibrate;
810 if (vibrate != null) {
811 final int N = vibrate.length;
812 final long[] vib = that.vibrate = new long[N];
813 System.arraycopy(vibrate, 0, vib, 0, N);
814 }
815
816 that.ledARGB = this.ledARGB;
817 that.ledOnMS = this.ledOnMS;
818 that.ledOffMS = this.ledOffMS;
819 that.defaults = this.defaults;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500820
Joe Onorato18e69df2010-05-17 22:26:12 -0700821 that.flags = this.flags;
822
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500823 that.priority = this.priority;
Joe Malin8d40d042012-11-05 11:36:40 -0800824
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500825 final String[] thiskind = this.kind;
826 if (thiskind != null) {
827 final int N = thiskind.length;
828 final String[] thatkind = that.kind = new String[N];
829 System.arraycopy(thiskind, 0, thatkind, 0, N);
830 }
831
832 if (this.extras != null) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -0400833 try {
834 that.extras = new Bundle(this.extras);
835 // will unparcel
836 that.extras.size();
837 } catch (BadParcelableException e) {
838 Log.e(TAG, "could not unparcel extras from notification: " + this, e);
839 that.extras = null;
840 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500841 }
842
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500843 if (this.actions != null) {
844 that.actions = new Action[this.actions.length];
845 for(int i=0; i<this.actions.length; i++) {
846 that.actions[i] = this.actions[i].clone();
847 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400848 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500849
Daniel Sandler1a497d32013-04-18 14:52:45 -0400850 if (heavy && this.bigContentView != null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400851 that.bigContentView = this.bigContentView.clone();
852 }
Daniel Sandler1a497d32013-04-18 14:52:45 -0400853
854 if (!heavy) {
855 that.lightenPayload(); // will clean out extras
856 }
857 }
858
859 /**
860 * Removes heavyweight parts of the Notification object for archival or for sending to
861 * listeners when the full contents are not necessary.
862 * @hide
863 */
864 public final void lightenPayload() {
865 tickerView = null;
866 contentView = null;
867 bigContentView = null;
868 largeIcon = null;
869 if (extras != null) {
870 extras.remove(Notification.EXTRA_LARGE_ICON);
871 extras.remove(Notification.EXTRA_LARGE_ICON_BIG);
872 extras.remove(Notification.EXTRA_PICTURE);
873 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700874 }
875
Daniel Sandlerdcbaf662013-04-26 16:23:09 -0400876 /**
877 * Make sure this CharSequence is safe to put into a bundle, which basically
878 * means it had better not be some custom Parcelable implementation.
879 * @hide
880 */
881 public static CharSequence safeCharSequence(CharSequence cs) {
882 if (cs instanceof Parcelable) {
883 Log.e(TAG, "warning: " + cs.getClass().getCanonicalName()
884 + " instance is a custom Parcelable and not allowed in Notification");
885 return cs.toString();
886 }
887
888 return cs;
889 }
890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 public int describeContents() {
892 return 0;
893 }
894
895 /**
896 * Flatten this notification from a parcel.
897 */
898 public void writeToParcel(Parcel parcel, int flags)
899 {
900 parcel.writeInt(1);
901
902 parcel.writeLong(when);
903 parcel.writeInt(icon);
904 parcel.writeInt(number);
905 if (contentIntent != null) {
906 parcel.writeInt(1);
907 contentIntent.writeToParcel(parcel, 0);
908 } else {
909 parcel.writeInt(0);
910 }
911 if (deleteIntent != null) {
912 parcel.writeInt(1);
913 deleteIntent.writeToParcel(parcel, 0);
914 } else {
915 parcel.writeInt(0);
916 }
917 if (tickerText != null) {
918 parcel.writeInt(1);
919 TextUtils.writeToParcel(tickerText, parcel, flags);
920 } else {
921 parcel.writeInt(0);
922 }
Joe Onorato46439ce2010-11-19 13:56:21 -0800923 if (tickerView != null) {
Joe Onoratoef1e7762010-09-17 18:38:38 -0400924 parcel.writeInt(1);
Joe Onorato46439ce2010-11-19 13:56:21 -0800925 tickerView.writeToParcel(parcel, 0);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400926 } else {
927 parcel.writeInt(0);
928 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 if (contentView != null) {
930 parcel.writeInt(1);
931 contentView.writeToParcel(parcel, 0);
932 } else {
933 parcel.writeInt(0);
934 }
Joe Onorato561d3852010-11-20 18:09:34 -0800935 if (largeIcon != null) {
936 parcel.writeInt(1);
937 largeIcon.writeToParcel(parcel, 0);
938 } else {
939 parcel.writeInt(0);
940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941
942 parcel.writeInt(defaults);
943 parcel.writeInt(this.flags);
944
945 if (sound != null) {
946 parcel.writeInt(1);
947 sound.writeToParcel(parcel, 0);
948 } else {
949 parcel.writeInt(0);
950 }
951 parcel.writeInt(audioStreamType);
952 parcel.writeLongArray(vibrate);
953 parcel.writeInt(ledARGB);
954 parcel.writeInt(ledOnMS);
955 parcel.writeInt(ledOffMS);
956 parcel.writeInt(iconLevel);
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400957
958 if (fullScreenIntent != null) {
959 parcel.writeInt(1);
960 fullScreenIntent.writeToParcel(parcel, 0);
961 } else {
962 parcel.writeInt(0);
963 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500964
965 parcel.writeInt(priority);
Joe Malin8d40d042012-11-05 11:36:40 -0800966
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500967 parcel.writeStringArray(kind); // ok for null
Joe Malin8d40d042012-11-05 11:36:40 -0800968
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500969 parcel.writeBundle(extras); // null ok
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400970
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500971 parcel.writeTypedArray(actions, 0); // null ok
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400972
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400973 if (bigContentView != null) {
974 parcel.writeInt(1);
975 bigContentView.writeToParcel(parcel, 0);
976 } else {
977 parcel.writeInt(0);
978 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 }
980
981 /**
982 * Parcelable.Creator that instantiates Notification objects
983 */
984 public static final Parcelable.Creator<Notification> CREATOR
985 = new Parcelable.Creator<Notification>()
986 {
987 public Notification createFromParcel(Parcel parcel)
988 {
989 return new Notification(parcel);
990 }
991
992 public Notification[] newArray(int size)
993 {
994 return new Notification[size];
995 }
996 };
997
998 /**
999 * Sets the {@link #contentView} field to be a view with the standard "Latest Event"
1000 * layout.
1001 *
1002 * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields
1003 * in the view.</p>
1004 * @param context The context for your application / activity.
1005 * @param contentTitle The title that goes in the expanded entry.
1006 * @param contentText The text that goes in the expanded entry.
1007 * @param contentIntent The intent to launch when the user clicks the expanded notification.
1008 * If this is an activity, it must include the
1009 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -08001010 * that you take care of task management as described in the
1011 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
1012 * Stack</a> document.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001013 *
Joe Onorato46439ce2010-11-19 13:56:21 -08001014 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001015 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001016 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 public void setLatestEventInfo(Context context,
1018 CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001019 Notification.Builder builder = new Notification.Builder(context);
1020
1021 // First, ensure that key pieces of information that may have been set directly
1022 // are preserved
1023 builder.setWhen(this.when);
1024 builder.setSmallIcon(this.icon);
1025 builder.setPriority(this.priority);
1026 builder.setTicker(this.tickerText);
1027 builder.setNumber(this.number);
1028 builder.mFlags = this.flags;
1029 builder.setSound(this.sound, this.audioStreamType);
1030 builder.setDefaults(this.defaults);
1031 builder.setVibrate(this.vibrate);
1032
1033 // now apply the latestEventInfo fields
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 if (contentTitle != null) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001035 builder.setContentTitle(contentTitle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 }
1037 if (contentText != null) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001038 builder.setContentText(contentText);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001040 builder.setContentIntent(contentIntent);
1041 builder.buildInto(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 }
1043
1044 @Override
1045 public String toString() {
1046 StringBuilder sb = new StringBuilder();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001047 sb.append("Notification(pri=");
1048 sb.append(priority);
1049 sb.append(" contentView=");
Joe Onoratoc9596d62011-01-12 17:03:11 -08001050 if (contentView != null) {
1051 sb.append(contentView.getPackage());
1052 sb.append("/0x");
1053 sb.append(Integer.toHexString(contentView.getLayoutId()));
1054 } else {
1055 sb.append("null");
1056 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001057 // TODO(dsandler): defaults take precedence over local values, so reorder the branches below
Joe Onoratoc9596d62011-01-12 17:03:11 -08001058 sb.append(" vibrate=");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001059 if ((this.defaults & DEFAULT_VIBRATE) != 0) {
1060 sb.append("default");
1061 } else if (this.vibrate != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 int N = this.vibrate.length-1;
1063 sb.append("[");
1064 for (int i=0; i<N; i++) {
1065 sb.append(this.vibrate[i]);
1066 sb.append(',');
1067 }
Simon Schoar8cf97d92009-06-10 22:08:37 +02001068 if (N != -1) {
1069 sb.append(this.vibrate[N]);
1070 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 sb.append("]");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 } else {
1073 sb.append("null");
1074 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001075 sb.append(" sound=");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001076 if ((this.defaults & DEFAULT_SOUND) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 sb.append("default");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001078 } else if (this.sound != null) {
1079 sb.append(this.sound.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 } else {
1081 sb.append("null");
1082 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001083 sb.append(" defaults=0x");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 sb.append(Integer.toHexString(this.defaults));
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001085 sb.append(" flags=0x");
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001086 sb.append(Integer.toHexString(this.flags));
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001087 sb.append(" kind=[");
1088 if (this.kind == null) {
1089 sb.append("null");
1090 } else {
1091 for (int i=0; i<this.kind.length; i++) {
1092 if (i>0) sb.append(",");
1093 sb.append(this.kind[i]);
1094 }
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001095 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001096 sb.append("]");
1097 if (actions != null) {
1098 sb.append(" ");
1099 sb.append(actions.length);
1100 sb.append(" action");
1101 if (actions.length > 1) sb.append("s");
1102 }
1103 sb.append(")");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 return sb.toString();
1105 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001106
Jeff Sharkey6d515712012-09-20 16:06:08 -07001107 /** {@hide} */
1108 public void setUser(UserHandle user) {
Amith Yamasaniecbd68b2012-11-02 12:17:19 -07001109 if (user.getIdentifier() == UserHandle.USER_ALL) {
1110 user = UserHandle.OWNER;
1111 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07001112 if (tickerView != null) {
1113 tickerView.setUser(user);
1114 }
1115 if (contentView != null) {
1116 contentView.setUser(user);
1117 }
1118 if (bigContentView != null) {
1119 bigContentView.setUser(user);
1120 }
1121 }
1122
Joe Onoratocb109a02011-01-18 17:57:41 -08001123 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001124 * Builder class for {@link Notification} objects.
Joe Malin8d40d042012-11-05 11:36:40 -08001125 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001126 * Provides a convenient way to set the various fields of a {@link Notification} and generate
Scott Main183bf112012-08-13 19:12:13 -07001127 * content views using the platform's notification layout template. If your app supports
1128 * versions of Android as old as API level 4, you can instead use
1129 * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder},
1130 * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support
1131 * library</a>.
Joe Malin8d40d042012-11-05 11:36:40 -08001132 *
Scott Main183bf112012-08-13 19:12:13 -07001133 * <p>Example:
Joe Malin8d40d042012-11-05 11:36:40 -08001134 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001135 * <pre class="prettyprint">
Scott Main183bf112012-08-13 19:12:13 -07001136 * Notification noti = new Notification.Builder(mContext)
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001137 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
1138 * .setContentText(subject)
1139 * .setSmallIcon(R.drawable.new_mail)
1140 * .setLargeIcon(aBitmap)
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001141 * .build();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001142 * </pre>
Joe Onoratocb109a02011-01-18 17:57:41 -08001143 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001144 public static class Builder {
Daniel Sandler602ad1c2012-06-12 16:06:27 -04001145 private static final int MAX_ACTION_BUTTONS = 3;
Daniel Sandler8680bf82012-05-15 16:52:52 -04001146
Joe Onorato46439ce2010-11-19 13:56:21 -08001147 private Context mContext;
1148
1149 private long mWhen;
1150 private int mSmallIcon;
1151 private int mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08001152 private int mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08001153 private CharSequence mContentTitle;
1154 private CharSequence mContentText;
1155 private CharSequence mContentInfo;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001156 private CharSequence mSubText;
Joe Onorato46439ce2010-11-19 13:56:21 -08001157 private PendingIntent mContentIntent;
1158 private RemoteViews mContentView;
1159 private PendingIntent mDeleteIntent;
1160 private PendingIntent mFullScreenIntent;
1161 private CharSequence mTickerText;
1162 private RemoteViews mTickerView;
1163 private Bitmap mLargeIcon;
1164 private Uri mSound;
1165 private int mAudioStreamType;
1166 private long[] mVibrate;
1167 private int mLedArgb;
1168 private int mLedOnMs;
1169 private int mLedOffMs;
1170 private int mDefaults;
1171 private int mFlags;
Jeff Sharkey1c400132011-08-05 14:50:13 -07001172 private int mProgressMax;
1173 private int mProgress;
1174 private boolean mProgressIndeterminate;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001175 private ArrayList<String> mKindList = new ArrayList<String>(1);
1176 private Bundle mExtras;
1177 private int mPriority;
Daniel Sandler8680bf82012-05-15 16:52:52 -04001178 private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS);
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001179 private boolean mUseChronometer;
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001180 private Style mStyle;
Daniel Sandler0c890492012-09-12 17:23:10 -07001181 private boolean mShowWhen = true;
Joe Onorato46439ce2010-11-19 13:56:21 -08001182
Joe Onoratocb109a02011-01-18 17:57:41 -08001183 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001184 * Constructs a new Builder with the defaults:
Joe Onoratocb109a02011-01-18 17:57:41 -08001185 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001186
1187 * <table>
1188 * <tr><th align=right>priority</th>
1189 * <td>{@link #PRIORITY_DEFAULT}</td></tr>
1190 * <tr><th align=right>when</th>
1191 * <td>now ({@link System#currentTimeMillis()})</td></tr>
1192 * <tr><th align=right>audio stream</th>
1193 * <td>{@link #STREAM_DEFAULT}</td></tr>
1194 * </table>
Joe Onoratocb109a02011-01-18 17:57:41 -08001195 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001196
1197 * @param context
1198 * A {@link Context} that will be used by the Builder to construct the
1199 * RemoteViews. The Context will not be held past the lifetime of this Builder
1200 * object.
Joe Onoratocb109a02011-01-18 17:57:41 -08001201 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001202 public Builder(Context context) {
1203 mContext = context;
Andy Stadler110988c2010-12-03 14:29:16 -08001204
1205 // Set defaults to match the defaults of a Notification
Joe Onorato46439ce2010-11-19 13:56:21 -08001206 mWhen = System.currentTimeMillis();
Andy Stadler110988c2010-12-03 14:29:16 -08001207 mAudioStreamType = STREAM_DEFAULT;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001208 mPriority = PRIORITY_DEFAULT;
Joe Onorato46439ce2010-11-19 13:56:21 -08001209 }
1210
Joe Onoratocb109a02011-01-18 17:57:41 -08001211 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001212 * Add a timestamp pertaining to the notification (usually the time the event occurred).
Daniel Sandler0c890492012-09-12 17:23:10 -07001213 * It will be shown in the notification content view by default; use
1214 * {@link Builder#setShowWhen(boolean) setShowWhen} to control this.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001215 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001216 * @see Notification#when
Joe Onoratocb109a02011-01-18 17:57:41 -08001217 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001218 public Builder setWhen(long when) {
1219 mWhen = when;
1220 return this;
1221 }
1222
Joe Onoratocb109a02011-01-18 17:57:41 -08001223 /**
Daniel Sandler0c890492012-09-12 17:23:10 -07001224 * Control whether the timestamp set with {@link Builder#setWhen(long) setWhen} is shown
1225 * in the content view.
1226 */
1227 public Builder setShowWhen(boolean show) {
1228 mShowWhen = show;
1229 return this;
1230 }
1231
1232 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001233 * Show the {@link Notification#when} field as a stopwatch.
Joe Malin8d40d042012-11-05 11:36:40 -08001234 *
1235 * Instead of presenting <code>when</code> as a timestamp, the notification will show an
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001236 * automatically updating display of the minutes and seconds since <code>when</code>.
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001237 *
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001238 * Useful when showing an elapsed time (like an ongoing phone call).
1239 *
1240 * @see android.widget.Chronometer
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001241 * @see Notification#when
1242 */
1243 public Builder setUsesChronometer(boolean b) {
1244 mUseChronometer = b;
1245 return this;
1246 }
1247
1248 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001249 * Set the small icon resource, which will be used to represent the notification in the
1250 * status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -08001251 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001252
1253 * The platform template for the expanded view will draw this icon in the left, unless a
1254 * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small
1255 * icon will be moved to the right-hand side.
1256 *
1257
1258 * @param icon
1259 * A resource ID in the application's package of the drawable to use.
1260 * @see Notification#icon
Joe Onoratocb109a02011-01-18 17:57:41 -08001261 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001262 public Builder setSmallIcon(int icon) {
1263 mSmallIcon = icon;
1264 return this;
1265 }
1266
Joe Onoratocb109a02011-01-18 17:57:41 -08001267 /**
1268 * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional
1269 * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable
1270 * LevelListDrawable}.
1271 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001272 * @param icon A resource ID in the application's package of the drawable to use.
Joe Onoratocb109a02011-01-18 17:57:41 -08001273 * @param level The level to use for the icon.
1274 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001275 * @see Notification#icon
1276 * @see Notification#iconLevel
Joe Onoratocb109a02011-01-18 17:57:41 -08001277 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001278 public Builder setSmallIcon(int icon, int level) {
1279 mSmallIcon = icon;
1280 mSmallIconLevel = level;
1281 return this;
1282 }
1283
Joe Onoratocb109a02011-01-18 17:57:41 -08001284 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001285 * Set the first line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001286 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001287 public Builder setContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001288 mContentTitle = safeCharSequence(title);
Joe Onorato46439ce2010-11-19 13:56:21 -08001289 return this;
1290 }
1291
Joe Onoratocb109a02011-01-18 17:57:41 -08001292 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001293 * Set the second line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001294 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001295 public Builder setContentText(CharSequence text) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001296 mContentText = safeCharSequence(text);
Joe Onorato46439ce2010-11-19 13:56:21 -08001297 return this;
1298 }
1299
Joe Onoratocb109a02011-01-18 17:57:41 -08001300 /**
Joe Malin8d40d042012-11-05 11:36:40 -08001301 * Set the third line of text in the platform notification template.
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001302 * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the
1303 * same location in the standard template.
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001304 */
1305 public Builder setSubText(CharSequence text) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001306 mSubText = safeCharSequence(text);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001307 return this;
1308 }
1309
1310 /**
Joe Onoratocb109a02011-01-18 17:57:41 -08001311 * Set the large number at the right-hand side of the notification. This is
1312 * equivalent to setContentInfo, although it might show the number in a different
1313 * font size for readability.
1314 */
Joe Onorato8595a3d2010-11-19 18:12:07 -08001315 public Builder setNumber(int number) {
1316 mNumber = number;
1317 return this;
1318 }
1319
Joe Onoratocb109a02011-01-18 17:57:41 -08001320 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001321 * A small piece of additional information pertaining to this notification.
1322 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001323 * The platform template will draw this on the last line of the notification, at the far
1324 * right (to the right of a smallIcon if it has been placed there).
Joe Onoratocb109a02011-01-18 17:57:41 -08001325 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001326 public Builder setContentInfo(CharSequence info) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001327 mContentInfo = safeCharSequence(info);
Joe Onorato46439ce2010-11-19 13:56:21 -08001328 return this;
1329 }
1330
Joe Onoratocb109a02011-01-18 17:57:41 -08001331 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001332 * Set the progress this notification represents.
1333 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001334 * The platform template will represent this using a {@link ProgressBar}.
Jeff Sharkey1c400132011-08-05 14:50:13 -07001335 */
1336 public Builder setProgress(int max, int progress, boolean indeterminate) {
1337 mProgressMax = max;
1338 mProgress = progress;
1339 mProgressIndeterminate = indeterminate;
1340 return this;
1341 }
1342
1343 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001344 * Supply a custom RemoteViews to use instead of the platform template.
1345 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001346 * @see Notification#contentView
Joe Onoratocb109a02011-01-18 17:57:41 -08001347 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001348 public Builder setContent(RemoteViews views) {
1349 mContentView = views;
1350 return this;
1351 }
1352
Joe Onoratocb109a02011-01-18 17:57:41 -08001353 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001354 * Supply a {@link PendingIntent} to be sent when the notification is clicked.
1355 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001356 * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you
1357 * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use
1358 * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)}
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001359 * to assign PendingIntents to individual views in that custom layout (i.e., to create
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001360 * clickable buttons inside the notification view).
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001361 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001362 * @see Notification#contentIntent Notification.contentIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001363 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001364 public Builder setContentIntent(PendingIntent intent) {
1365 mContentIntent = intent;
1366 return this;
1367 }
1368
Joe Onoratocb109a02011-01-18 17:57:41 -08001369 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001370 * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user.
1371 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001372 * @see Notification#deleteIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001373 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001374 public Builder setDeleteIntent(PendingIntent intent) {
1375 mDeleteIntent = intent;
1376 return this;
1377 }
1378
Joe Onoratocb109a02011-01-18 17:57:41 -08001379 /**
1380 * An intent to launch instead of posting the notification to the status bar.
1381 * Only for use with extremely high-priority notifications demanding the user's
1382 * <strong>immediate</strong> attention, such as an incoming phone call or
1383 * alarm clock that the user has explicitly set to a particular time.
1384 * If this facility is used for something else, please give the user an option
1385 * to turn it off and use a normal notification, as this can be extremely
1386 * disruptive.
1387 *
1388 * @param intent The pending intent to launch.
1389 * @param highPriority Passing true will cause this notification to be sent
1390 * even if other notifications are suppressed.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001391 *
1392 * @see Notification#fullScreenIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001393 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001394 public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
1395 mFullScreenIntent = intent;
1396 setFlag(FLAG_HIGH_PRIORITY, highPriority);
1397 return this;
1398 }
1399
Joe Onoratocb109a02011-01-18 17:57:41 -08001400 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001401 * Set the "ticker" text which is displayed in the status bar when the notification first
Joe Onoratocb109a02011-01-18 17:57:41 -08001402 * arrives.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001403 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001404 * @see Notification#tickerText
Joe Onoratocb109a02011-01-18 17:57:41 -08001405 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001406 public Builder setTicker(CharSequence tickerText) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001407 mTickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08001408 return this;
1409 }
1410
Joe Onoratocb109a02011-01-18 17:57:41 -08001411 /**
1412 * Set the text that is displayed in the status bar when the notification first
1413 * arrives, and also a RemoteViews object that may be displayed instead on some
1414 * devices.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001415 *
1416 * @see Notification#tickerText
1417 * @see Notification#tickerView
Joe Onoratocb109a02011-01-18 17:57:41 -08001418 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001419 public Builder setTicker(CharSequence tickerText, RemoteViews views) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001420 mTickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08001421 mTickerView = views;
1422 return this;
1423 }
1424
Joe Onoratocb109a02011-01-18 17:57:41 -08001425 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001426 * Add a large icon to the notification (and the ticker on some devices).
1427 *
1428 * In the platform template, this image will be shown on the left of the notification view
1429 * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side).
1430 *
1431 * @see Notification#largeIcon
Joe Onoratocb109a02011-01-18 17:57:41 -08001432 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001433 public Builder setLargeIcon(Bitmap icon) {
1434 mLargeIcon = icon;
1435 return this;
1436 }
1437
Joe Onoratocb109a02011-01-18 17:57:41 -08001438 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001439 * Set the sound to play.
1440 *
1441 * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications.
1442 *
1443 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001444 */
Joe Onorato52f80cd2010-11-21 15:34:48 -08001445 public Builder setSound(Uri sound) {
1446 mSound = sound;
1447 mAudioStreamType = STREAM_DEFAULT;
1448 return this;
1449 }
1450
Joe Onoratocb109a02011-01-18 17:57:41 -08001451 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001452 * Set the sound to play, along with a specific stream on which to play it.
Joe Onoratocb109a02011-01-18 17:57:41 -08001453 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001454 * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants.
1455 *
1456 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001457 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001458 public Builder setSound(Uri sound, int streamType) {
1459 mSound = sound;
1460 mAudioStreamType = streamType;
1461 return this;
1462 }
1463
Joe Onoratocb109a02011-01-18 17:57:41 -08001464 /**
1465 * Set the vibration pattern to use.
1466 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001467
1468 * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the
1469 * <code>pattern</code> parameter.
1470 *
1471
1472 * @see Notification#vibrate
Joe Onoratocb109a02011-01-18 17:57:41 -08001473 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001474 public Builder setVibrate(long[] pattern) {
1475 mVibrate = pattern;
1476 return this;
1477 }
1478
Joe Onoratocb109a02011-01-18 17:57:41 -08001479 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001480 * Set the desired color for the indicator LED on the device, as well as the
1481 * blink duty cycle (specified in milliseconds).
1482 *
1483
1484 * Not all devices will honor all (or even any) of these values.
1485 *
1486
1487 * @see Notification#ledARGB
1488 * @see Notification#ledOnMS
1489 * @see Notification#ledOffMS
Joe Onoratocb109a02011-01-18 17:57:41 -08001490 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001491 public Builder setLights(int argb, int onMs, int offMs) {
1492 mLedArgb = argb;
1493 mLedOnMs = onMs;
1494 mLedOffMs = offMs;
Joe Onorato46439ce2010-11-19 13:56:21 -08001495 return this;
1496 }
1497
Joe Onoratocb109a02011-01-18 17:57:41 -08001498 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001499 * Set whether this is an "ongoing" notification.
Joe Onoratocb109a02011-01-18 17:57:41 -08001500 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001501
1502 * Ongoing notifications cannot be dismissed by the user, so your application or service
1503 * must take care of canceling them.
1504 *
1505
1506 * They are typically used to indicate a background task that the user is actively engaged
1507 * with (e.g., playing music) or is pending in some way and therefore occupying the device
1508 * (e.g., a file download, sync operation, active network connection).
1509 *
1510
1511 * @see Notification#FLAG_ONGOING_EVENT
1512 * @see Service#setForeground(boolean)
Joe Onoratocb109a02011-01-18 17:57:41 -08001513 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001514 public Builder setOngoing(boolean ongoing) {
1515 setFlag(FLAG_ONGOING_EVENT, ongoing);
1516 return this;
1517 }
1518
Joe Onoratocb109a02011-01-18 17:57:41 -08001519 /**
1520 * Set this flag if you would only like the sound, vibrate
1521 * and ticker to be played if the notification is not already showing.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001522 *
1523 * @see Notification#FLAG_ONLY_ALERT_ONCE
Joe Onoratocb109a02011-01-18 17:57:41 -08001524 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001525 public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
1526 setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
1527 return this;
1528 }
1529
Joe Onoratocb109a02011-01-18 17:57:41 -08001530 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001531 * Make this notification automatically dismissed when the user touches it. The
1532 * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens.
1533 *
1534 * @see Notification#FLAG_AUTO_CANCEL
Joe Onoratocb109a02011-01-18 17:57:41 -08001535 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001536 public Builder setAutoCancel(boolean autoCancel) {
Joe Onorato281d83f2011-01-04 17:13:10 -08001537 setFlag(FLAG_AUTO_CANCEL, autoCancel);
Joe Onorato46439ce2010-11-19 13:56:21 -08001538 return this;
1539 }
1540
Joe Onoratocb109a02011-01-18 17:57:41 -08001541 /**
Griff Hazendfcb0802014-02-11 12:00:00 -08001542 * Set whether or not this notification should not bridge to other devices.
1543 *
1544 * <p>Some notifications can be bridged to other devices for remote display.
1545 * This hint can be set to recommend this notification not be bridged.
1546 */
1547 public Builder setLocalOnly(boolean localOnly) {
1548 setFlag(FLAG_LOCAL_ONLY, localOnly);
1549 return this;
1550 }
1551
1552 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001553 * Set which notification properties will be inherited from system defaults.
Joe Onoratocb109a02011-01-18 17:57:41 -08001554 * <p>
1555 * The value should be one or more of the following fields combined with
1556 * bitwise-or:
1557 * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}.
1558 * <p>
1559 * For all default values, use {@link #DEFAULT_ALL}.
1560 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001561 public Builder setDefaults(int defaults) {
1562 mDefaults = defaults;
1563 return this;
1564 }
1565
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001566 /**
1567 * Set the priority of this notification.
1568 *
1569 * @see Notification#priority
1570 */
1571 public Builder setPriority(int pri) {
1572 mPriority = pri;
1573 return this;
1574 }
Joe Malin8d40d042012-11-05 11:36:40 -08001575
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001576 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001577 * @hide
Joe Malin8d40d042012-11-05 11:36:40 -08001578 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001579 * Add a kind (category) to this notification. Optional.
Joe Malin8d40d042012-11-05 11:36:40 -08001580 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001581 * @see Notification#kind
1582 */
1583 public Builder addKind(String k) {
1584 mKindList.add(k);
1585 return this;
1586 }
1587
1588 /**
1589 * Add metadata to this notification.
1590 *
1591 * A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001592 * current contents are copied into the Notification each time {@link #build()} is
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001593 * called.
1594 *
1595 * @see Notification#extras
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001596 */
1597 public Builder setExtras(Bundle bag) {
1598 mExtras = bag;
1599 return this;
1600 }
1601
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001602 /**
1603 * Add an action to this notification. Actions are typically displayed by
1604 * the system as a button adjacent to the notification content.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04001605 * <p>
1606 * Every action must have an icon (32dp square and matching the
1607 * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo
1608 * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}.
1609 * <p>
1610 * A notification in its expanded form can display up to 3 actions, from left to right in
1611 * the order they were added. Actions will not be displayed when the notification is
1612 * collapsed, however, so be sure that any essential functions may be accessed by the user
1613 * in some other way (for example, in the Activity pointed to by {@link #contentIntent}).
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001614 *
1615 * @param icon Resource ID of a drawable that represents the action.
1616 * @param title Text describing the action.
1617 * @param intent PendingIntent to be fired when the action is invoked.
1618 */
1619 public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001620 mActions.add(new Action(icon, safeCharSequence(title), intent));
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001621 return this;
1622 }
1623
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001624 /**
1625 * Add a rich notification style to be applied at build time.
1626 *
1627 * @param style Object responsible for modifying the notification style.
1628 */
1629 public Builder setStyle(Style style) {
1630 if (mStyle != style) {
1631 mStyle = style;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07001632 if (mStyle != null) {
1633 mStyle.setBuilder(this);
1634 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001635 }
1636 return this;
1637 }
1638
Joe Onorato46439ce2010-11-19 13:56:21 -08001639 private void setFlag(int mask, boolean value) {
1640 if (value) {
1641 mFlags |= mask;
1642 } else {
1643 mFlags &= ~mask;
1644 }
1645 }
1646
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001647 private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
Joe Onorato561d3852010-11-20 18:09:34 -08001648 RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001649 boolean showLine3 = false;
1650 boolean showLine2 = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001651 int smallIconImageViewId = R.id.icon;
1652 if (mLargeIcon != null) {
1653 contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
1654 smallIconImageViewId = R.id.right_icon;
1655 }
Daniel Sandlere95658c2012-05-10 00:33:54 -04001656 if (mPriority < PRIORITY_LOW) {
1657 contentView.setInt(R.id.icon,
1658 "setBackgroundResource", R.drawable.notification_template_icon_low_bg);
1659 contentView.setInt(R.id.status_bar_latest_event_content,
1660 "setBackgroundResource", R.drawable.notification_bg_low);
1661 }
Joe Onorato561d3852010-11-20 18:09:34 -08001662 if (mSmallIcon != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001663 contentView.setImageViewResource(smallIconImageViewId, mSmallIcon);
1664 contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001665 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001666 contentView.setViewVisibility(smallIconImageViewId, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001667 }
1668 if (mContentTitle != null) {
1669 contentView.setTextViewText(R.id.title, mContentTitle);
1670 }
1671 if (mContentText != null) {
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001672 contentView.setTextViewText(R.id.text, mContentText);
1673 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001674 }
1675 if (mContentInfo != null) {
1676 contentView.setTextViewText(R.id.info, mContentInfo);
Jeff Sharkey1c400132011-08-05 14:50:13 -07001677 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001678 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001679 } else if (mNumber > 0) {
Daniel Sandlerebce0112011-06-16 16:44:51 -04001680 final int tooBig = mContext.getResources().getInteger(
1681 R.integer.status_bar_notification_info_maxnum);
1682 if (mNumber > tooBig) {
1683 contentView.setTextViewText(R.id.info, mContext.getResources().getString(
1684 R.string.status_bar_notification_info_overflow));
Joe Onorato059a2f82011-01-04 10:27:01 -08001685 } else {
1686 NumberFormat f = NumberFormat.getIntegerInstance();
1687 contentView.setTextViewText(R.id.info, f.format(mNumber));
1688 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001689 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001690 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08001691 } else {
1692 contentView.setViewVisibility(R.id.info, View.GONE);
1693 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001694
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001695 // Need to show three lines?
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001696 if (mSubText != null) {
1697 contentView.setTextViewText(R.id.text, mSubText);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001698 if (mContentText != null) {
1699 contentView.setTextViewText(R.id.text2, mContentText);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001700 contentView.setViewVisibility(R.id.text2, View.VISIBLE);
1701 showLine2 = true;
1702 } else {
1703 contentView.setViewVisibility(R.id.text2, View.GONE);
1704 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001705 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001706 contentView.setViewVisibility(R.id.text2, View.GONE);
1707 if (mProgressMax != 0 || mProgressIndeterminate) {
1708 contentView.setProgressBar(
1709 R.id.progress, mProgressMax, mProgress, mProgressIndeterminate);
1710 contentView.setViewVisibility(R.id.progress, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001711 showLine2 = true;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001712 } else {
1713 contentView.setViewVisibility(R.id.progress, View.GONE);
1714 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07001715 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001716 if (showLine2) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001717 if (fitIn1U) {
1718 // need to shrink all the type to make sure everything fits
1719 final Resources res = mContext.getResources();
1720 final float subTextSize = res.getDimensionPixelSize(
1721 R.dimen.notification_subtext_size);
1722 contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize);
1723 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001724 // vertical centering
1725 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
1726 }
1727
Daniel Sandler0c890492012-09-12 17:23:10 -07001728 if (mWhen != 0 && mShowWhen) {
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001729 if (mUseChronometer) {
1730 contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
1731 contentView.setLong(R.id.chronometer, "setBase",
1732 mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
1733 contentView.setBoolean(R.id.chronometer, "setStarted", true);
1734 } else {
1735 contentView.setViewVisibility(R.id.time, View.VISIBLE);
1736 contentView.setLong(R.id.time, "setTime", mWhen);
1737 }
Daniel Sandler0c890492012-09-12 17:23:10 -07001738 } else {
1739 contentView.setViewVisibility(R.id.time, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001740 }
Daniel Sandler0c890492012-09-12 17:23:10 -07001741
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001742 contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001743 contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08001744 return contentView;
1745 }
1746
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001747 private RemoteViews applyStandardTemplateWithActions(int layoutId) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001748 RemoteViews big = applyStandardTemplate(layoutId, false);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001749
1750 int N = mActions.size();
1751 if (N > 0) {
Chris Wrend6297db2012-05-03 16:20:13 -04001752 // Log.d("Notification", "has actions: " + mContentText);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001753 big.setViewVisibility(R.id.actions, View.VISIBLE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001754 big.setViewVisibility(R.id.action_divider, View.VISIBLE);
Daniel Sandler8680bf82012-05-15 16:52:52 -04001755 if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS;
Chris Wren2c22eb02012-05-08 09:49:13 -04001756 big.removeAllViews(R.id.actions);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001757 for (int i=0; i<N; i++) {
1758 final RemoteViews button = generateActionButton(mActions.get(i));
Chris Wrend6297db2012-05-03 16:20:13 -04001759 //Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001760 big.addView(R.id.actions, button);
1761 }
1762 }
1763 return big;
1764 }
1765
Joe Onorato46439ce2010-11-19 13:56:21 -08001766 private RemoteViews makeContentView() {
1767 if (mContentView != null) {
1768 return mContentView;
1769 } else {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001770 return applyStandardTemplate(R.layout.notification_template_base, true); // no more special large_icon flavor
Joe Onorato46439ce2010-11-19 13:56:21 -08001771 }
1772 }
1773
1774 private RemoteViews makeTickerView() {
1775 if (mTickerView != null) {
1776 return mTickerView;
1777 } else {
Joe Onorato561d3852010-11-20 18:09:34 -08001778 if (mContentView == null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001779 return applyStandardTemplate(mLargeIcon == null
Joe Onorato561d3852010-11-20 18:09:34 -08001780 ? R.layout.status_bar_latest_event_ticker
Daniel Sandler6387d2f2012-05-22 13:44:09 -04001781 : R.layout.status_bar_latest_event_ticker_large_icon, true);
Joe Onorato561d3852010-11-20 18:09:34 -08001782 } else {
1783 return null;
1784 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001785 }
1786 }
1787
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001788 private RemoteViews makeBigContentView() {
1789 if (mActions.size() == 0) return null;
1790
Chris Wrenb023bf82012-04-23 16:05:42 -04001791 return applyStandardTemplateWithActions(R.layout.notification_template_big_base);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001792 }
1793
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001794 private RemoteViews generateActionButton(Action action) {
Daniel Sandler8680bf82012-05-15 16:52:52 -04001795 final boolean tombstone = (action.actionIntent == null);
Joe Malin8d40d042012-11-05 11:36:40 -08001796 RemoteViews button = new RemoteViews(mContext.getPackageName(),
Daniel Sandler8680bf82012-05-15 16:52:52 -04001797 tombstone ? R.layout.notification_action_tombstone
1798 : R.layout.notification_action);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001799 button.setTextViewCompoundDrawables(R.id.action0, action.icon, 0, 0, 0);
1800 button.setTextViewText(R.id.action0, action.title);
Daniel Sandler8680bf82012-05-15 16:52:52 -04001801 if (!tombstone) {
Daniel Sandlere5518842012-05-10 16:20:40 -04001802 button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
Daniel Sandlere5518842012-05-10 16:20:40 -04001803 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001804 button.setContentDescription(R.id.action0, action.title);
1805 return button;
1806 }
1807
Joe Onoratocb109a02011-01-18 17:57:41 -08001808 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001809 * Apply the unstyled operations and return a new {@link Notification} object.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04001810 * @hide
Joe Onoratocb109a02011-01-18 17:57:41 -08001811 */
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04001812 public Notification buildUnstyled() {
Joe Onorato46439ce2010-11-19 13:56:21 -08001813 Notification n = new Notification();
1814 n.when = mWhen;
1815 n.icon = mSmallIcon;
1816 n.iconLevel = mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08001817 n.number = mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08001818 n.contentView = makeContentView();
1819 n.contentIntent = mContentIntent;
1820 n.deleteIntent = mDeleteIntent;
1821 n.fullScreenIntent = mFullScreenIntent;
1822 n.tickerText = mTickerText;
1823 n.tickerView = makeTickerView();
1824 n.largeIcon = mLargeIcon;
1825 n.sound = mSound;
1826 n.audioStreamType = mAudioStreamType;
1827 n.vibrate = mVibrate;
1828 n.ledARGB = mLedArgb;
1829 n.ledOnMS = mLedOnMs;
1830 n.ledOffMS = mLedOffMs;
1831 n.defaults = mDefaults;
1832 n.flags = mFlags;
Daniel Sandler96fd7c12012-03-30 16:37:36 -04001833 n.bigContentView = makeBigContentView();
Daniel Sandler26c13432013-04-04 11:01:04 -04001834 if (mLedOnMs != 0 || mLedOffMs != 0) {
Joe Onorato8d0b6552010-11-22 16:09:29 -08001835 n.flags |= FLAG_SHOW_LIGHTS;
1836 }
1837 if ((mDefaults & DEFAULT_LIGHTS) != 0) {
1838 n.flags |= FLAG_SHOW_LIGHTS;
1839 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001840 if (mKindList.size() > 0) {
1841 n.kind = new String[mKindList.size()];
1842 mKindList.toArray(n.kind);
1843 } else {
1844 n.kind = null;
1845 }
1846 n.priority = mPriority;
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001847 if (mActions.size() > 0) {
1848 n.actions = new Action[mActions.size()];
1849 mActions.toArray(n.actions);
1850 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001851
Joe Onorato46439ce2010-11-19 13:56:21 -08001852 return n;
1853 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001854
1855 /**
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001856 * Capture, in the provided bundle, semantic information used in the construction of
1857 * this Notification object.
1858 * @hide
1859 */
1860 public void addExtras(Bundle extras) {
1861 // Store original information used in the construction of this object
1862 extras.putCharSequence(EXTRA_TITLE, mContentTitle);
1863 extras.putCharSequence(EXTRA_TEXT, mContentText);
1864 extras.putCharSequence(EXTRA_SUB_TEXT, mSubText);
1865 extras.putCharSequence(EXTRA_INFO_TEXT, mContentInfo);
1866 extras.putInt(EXTRA_SMALL_ICON, mSmallIcon);
1867 extras.putInt(EXTRA_PROGRESS, mProgress);
1868 extras.putInt(EXTRA_PROGRESS_MAX, mProgressMax);
1869 extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mProgressIndeterminate);
1870 extras.putBoolean(EXTRA_SHOW_CHRONOMETER, mUseChronometer);
1871 extras.putBoolean(EXTRA_SHOW_WHEN, mShowWhen);
John Spurlockac08a472013-06-10 11:37:08 -04001872 if (mLargeIcon != null) {
1873 extras.putParcelable(EXTRA_LARGE_ICON, mLargeIcon);
1874 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001875 }
1876
1877 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001878 * @deprecated Use {@link #build()} instead.
1879 */
1880 @Deprecated
1881 public Notification getNotification() {
1882 return build();
1883 }
1884
1885 /**
1886 * Combine all of the options that have been set and return a new {@link Notification}
1887 * object.
1888 */
1889 public Notification build() {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04001890 Notification n = buildUnstyled();
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001891
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001892 if (mStyle != null) {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04001893 n = mStyle.buildStyled(n);
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001894 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001895
1896 n.extras = mExtras != null ? new Bundle(mExtras) : new Bundle();
1897
1898 addExtras(n.extras);
1899 if (mStyle != null) {
1900 mStyle.addExtras(n.extras);
1901 }
1902
1903 return n;
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001904 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001905
1906 /**
1907 * Apply this Builder to an existing {@link Notification} object.
1908 *
1909 * @hide
1910 */
1911 public Notification buildInto(Notification n) {
Daniel Sandler1a497d32013-04-18 14:52:45 -04001912 build().cloneInto(n, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001913 return n;
1914 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001915 }
1916
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001917 /**
1918 * An object that can apply a rich notification style to a {@link Notification.Builder}
1919 * object.
1920 */
Griff Hazendfcb0802014-02-11 12:00:00 -08001921 public static abstract class Style {
Chris Wrend6297db2012-05-03 16:20:13 -04001922 private CharSequence mBigContentTitle;
1923 private CharSequence mSummaryText = null;
Daniel Sandler619738c2012-06-07 16:33:08 -04001924 private boolean mSummaryTextSet = false;
Chris Wrend6297db2012-05-03 16:20:13 -04001925
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001926 protected Builder mBuilder;
1927
Chris Wrend6297db2012-05-03 16:20:13 -04001928 /**
1929 * Overrides ContentTitle in the big form of the template.
1930 * This defaults to the value passed to setContentTitle().
1931 */
1932 protected void internalSetBigContentTitle(CharSequence title) {
1933 mBigContentTitle = title;
1934 }
1935
1936 /**
1937 * Set the first line of text after the detail section in the big form of the template.
1938 */
1939 protected void internalSetSummaryText(CharSequence cs) {
1940 mSummaryText = cs;
Daniel Sandler619738c2012-06-07 16:33:08 -04001941 mSummaryTextSet = true;
Chris Wrend6297db2012-05-03 16:20:13 -04001942 }
1943
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001944 public void setBuilder(Builder builder) {
1945 if (mBuilder != builder) {
1946 mBuilder = builder;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07001947 if (mBuilder != null) {
1948 mBuilder.setStyle(this);
1949 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001950 }
1951 }
1952
Chris Wrend6297db2012-05-03 16:20:13 -04001953 protected void checkBuilder() {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001954 if (mBuilder == null) {
1955 throw new IllegalArgumentException("Style requires a valid Builder object");
1956 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001957 }
Chris Wrend6297db2012-05-03 16:20:13 -04001958
1959 protected RemoteViews getStandardView(int layoutId) {
1960 checkBuilder();
1961
1962 if (mBigContentTitle != null) {
1963 mBuilder.setContentTitle(mBigContentTitle);
1964 }
1965
Chris Wrend6297db2012-05-03 16:20:13 -04001966 RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId);
1967
Chris Wrend6297db2012-05-03 16:20:13 -04001968 if (mBigContentTitle != null && mBigContentTitle.equals("")) {
1969 contentView.setViewVisibility(R.id.line1, View.GONE);
Chris Wren67dc9a02012-05-16 01:03:20 -04001970 } else {
1971 contentView.setViewVisibility(R.id.line1, View.VISIBLE);
Chris Wrend6297db2012-05-03 16:20:13 -04001972 }
1973
Daniel Sandler619738c2012-06-07 16:33:08 -04001974 // The last line defaults to the subtext, but can be replaced by mSummaryText
1975 final CharSequence overflowText =
1976 mSummaryTextSet ? mSummaryText
1977 : mBuilder.mSubText;
1978 if (overflowText != null) {
1979 contentView.setTextViewText(R.id.text, overflowText);
1980 contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04001981 contentView.setViewVisibility(R.id.line3, View.VISIBLE);
Daniel Sandler916ad912012-06-13 12:17:07 -04001982 } else {
1983 contentView.setViewVisibility(R.id.overflow_divider, View.GONE);
1984 contentView.setViewVisibility(R.id.line3, View.GONE);
Chris Wrend6297db2012-05-03 16:20:13 -04001985 }
1986
1987 return contentView;
1988 }
1989
Daniel Sandlerf45564e2013-04-15 15:05:08 -04001990 /**
1991 * @hide
1992 */
1993 public void addExtras(Bundle extras) {
1994 if (mSummaryTextSet) {
1995 extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText);
1996 }
1997 if (mBigContentTitle != null) {
1998 extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle);
1999 }
2000 }
2001
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002002 /**
2003 * @hide
2004 */
2005 public abstract Notification buildStyled(Notification wip);
2006
2007 /**
2008 * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is
2009 * attached to.
2010 *
2011 * @return the fully constructed Notification.
2012 */
2013 public Notification build() {
2014 checkBuilder();
2015 return mBuilder.build();
2016 }
Joe Onorato46439ce2010-11-19 13:56:21 -08002017 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002018
2019 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002020 * Helper class for generating large-format notifications that include a large image attachment.
Joe Malin8d40d042012-11-05 11:36:40 -08002021 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002022 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002023 * <pre class="prettyprint">
2024 * Notification noti = new Notification.BigPictureStyle(
2025 * new Notification.Builder()
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002026 * .setContentTitle(&quot;New photo from &quot; + sender.toString())
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002027 * .setContentText(subject)
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002028 * .setSmallIcon(R.drawable.new_post)
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002029 * .setLargeIcon(aBitmap))
2030 * .bigPicture(aBigBitmap)
2031 * .build();
2032 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002033 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002034 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002035 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002036 public static class BigPictureStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002037 private Bitmap mPicture;
Chris Wren3745a3d2012-05-22 15:11:52 -04002038 private Bitmap mBigLargeIcon;
2039 private boolean mBigLargeIconSet = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002040
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002041 public BigPictureStyle() {
2042 }
2043
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002044 public BigPictureStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002045 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002046 }
2047
Chris Wrend6297db2012-05-03 16:20:13 -04002048 /**
2049 * Overrides ContentTitle in the big form of the template.
2050 * This defaults to the value passed to setContentTitle().
2051 */
2052 public BigPictureStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002053 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002054 return this;
2055 }
2056
2057 /**
2058 * Set the first line of text after the detail section in the big form of the template.
2059 */
2060 public BigPictureStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002061 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002062 return this;
2063 }
2064
Chris Wren0bd664d2012-08-01 13:56:56 -04002065 /**
2066 * Provide the bitmap to be used as the payload for the BigPicture notification.
2067 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002068 public BigPictureStyle bigPicture(Bitmap b) {
2069 mPicture = b;
2070 return this;
2071 }
2072
Chris Wren3745a3d2012-05-22 15:11:52 -04002073 /**
Chris Wren3745a3d2012-05-22 15:11:52 -04002074 * Override the large icon when the big notification is shown.
2075 */
2076 public BigPictureStyle bigLargeIcon(Bitmap b) {
2077 mBigLargeIconSet = true;
2078 mBigLargeIcon = b;
2079 return this;
2080 }
2081
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002082 private RemoteViews makeBigContentView() {
Chris Wrend6297db2012-05-03 16:20:13 -04002083 RemoteViews contentView = getStandardView(R.layout.notification_template_big_picture);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002084
2085 contentView.setImageViewBitmap(R.id.big_picture, mPicture);
2086
2087 return contentView;
2088 }
2089
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002090 /**
2091 * @hide
2092 */
2093 public void addExtras(Bundle extras) {
2094 super.addExtras(extras);
2095
2096 if (mBigLargeIconSet) {
2097 extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon);
2098 }
2099 extras.putParcelable(EXTRA_PICTURE, mPicture);
2100 }
2101
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002102 /**
2103 * @hide
2104 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002105 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002106 public Notification buildStyled(Notification wip) {
Chris Wren3745a3d2012-05-22 15:11:52 -04002107 if (mBigLargeIconSet ) {
2108 mBuilder.mLargeIcon = mBigLargeIcon;
2109 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002110 wip.bigContentView = makeBigContentView();
2111 return wip;
2112 }
2113 }
2114
2115 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002116 * Helper class for generating large-format notifications that include a lot of text.
Joe Malin8d40d042012-11-05 11:36:40 -08002117 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002118 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002119 * <pre class="prettyprint">
Daniel Sandler87682782012-11-07 14:04:42 -05002120 * Notification noti = new Notification.BigTextStyle(
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002121 * new Notification.Builder()
2122 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
2123 * .setContentText(subject)
2124 * .setSmallIcon(R.drawable.new_mail)
2125 * .setLargeIcon(aBitmap))
2126 * .bigText(aVeryLongString)
2127 * .build();
2128 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002129 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002130 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002131 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002132 public static class BigTextStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002133 private CharSequence mBigText;
2134
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002135 public BigTextStyle() {
2136 }
2137
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002138 public BigTextStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002139 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002140 }
2141
Chris Wrend6297db2012-05-03 16:20:13 -04002142 /**
2143 * Overrides ContentTitle in the big form of the template.
2144 * This defaults to the value passed to setContentTitle().
2145 */
2146 public BigTextStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002147 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002148 return this;
2149 }
2150
2151 /**
2152 * Set the first line of text after the detail section in the big form of the template.
2153 */
2154 public BigTextStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002155 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002156 return this;
2157 }
2158
Chris Wren0bd664d2012-08-01 13:56:56 -04002159 /**
2160 * Provide the longer text to be displayed in the big form of the
2161 * template in place of the content text.
2162 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002163 public BigTextStyle bigText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002164 mBigText = safeCharSequence(cs);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002165 return this;
2166 }
2167
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002168 /**
2169 * @hide
2170 */
2171 public void addExtras(Bundle extras) {
2172 super.addExtras(extras);
2173
2174 extras.putCharSequence(EXTRA_TEXT, mBigText);
2175 }
2176
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002177 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04002178 // Remove the content text so line3 only shows if you have a summary
2179 final boolean hadThreeLines = (mBuilder.mContentText != null && mBuilder.mSubText != null);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002180 mBuilder.mContentText = null;
Daniel Sandler916ad912012-06-13 12:17:07 -04002181
Chris Wrend6297db2012-05-03 16:20:13 -04002182 RemoteViews contentView = getStandardView(R.layout.notification_template_big_text);
Joe Malin8d40d042012-11-05 11:36:40 -08002183
Daniel Sandler619738c2012-06-07 16:33:08 -04002184 if (hadThreeLines) {
2185 // vertical centering
2186 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
2187 }
2188
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002189 contentView.setTextViewText(R.id.big_text, mBigText);
2190 contentView.setViewVisibility(R.id.big_text, View.VISIBLE);
Chris Wren3c5f92432012-05-04 16:31:17 -04002191 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002192
2193 return contentView;
2194 }
2195
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002196 /**
2197 * @hide
2198 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002199 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002200 public Notification buildStyled(Notification wip) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002201 wip.bigContentView = makeBigContentView();
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002202
2203 wip.extras.putCharSequence(EXTRA_TEXT, mBigText);
2204
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002205 return wip;
2206 }
2207 }
Daniel Sandler879c5e02012-04-17 16:46:51 -04002208
2209 /**
2210 * Helper class for generating large-format notifications that include a list of (up to 5) strings.
Joe Malin8d40d042012-11-05 11:36:40 -08002211 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04002212 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
2213 * <pre class="prettyprint">
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002214 * Notification noti = new Notification.InboxStyle(
Daniel Sandler879c5e02012-04-17 16:46:51 -04002215 * new Notification.Builder()
Chris Wrend6297db2012-05-03 16:20:13 -04002216 * .setContentTitle(&quot;5 New mails from &quot; + sender.toString())
Daniel Sandler879c5e02012-04-17 16:46:51 -04002217 * .setContentText(subject)
2218 * .setSmallIcon(R.drawable.new_mail)
2219 * .setLargeIcon(aBitmap))
2220 * .addLine(str1)
2221 * .addLine(str2)
Chris Wrend6297db2012-05-03 16:20:13 -04002222 * .setContentTitle("")
2223 * .setSummaryText(&quot;+3 more&quot;)
Daniel Sandler879c5e02012-04-17 16:46:51 -04002224 * .build();
2225 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002226 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04002227 * @see Notification#bigContentView
2228 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002229 public static class InboxStyle extends Style {
Daniel Sandler879c5e02012-04-17 16:46:51 -04002230 private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5);
2231
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002232 public InboxStyle() {
2233 }
2234
Daniel Sandler879c5e02012-04-17 16:46:51 -04002235 public InboxStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002236 setBuilder(builder);
Daniel Sandler879c5e02012-04-17 16:46:51 -04002237 }
2238
Chris Wrend6297db2012-05-03 16:20:13 -04002239 /**
2240 * Overrides ContentTitle in the big form of the template.
2241 * This defaults to the value passed to setContentTitle().
2242 */
2243 public InboxStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002244 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002245 return this;
2246 }
2247
2248 /**
2249 * Set the first line of text after the detail section in the big form of the template.
2250 */
2251 public InboxStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002252 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002253 return this;
2254 }
2255
Chris Wren0bd664d2012-08-01 13:56:56 -04002256 /**
2257 * Append a line to the digest section of the Inbox notification.
2258 */
Daniel Sandler879c5e02012-04-17 16:46:51 -04002259 public InboxStyle addLine(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002260 mTexts.add(safeCharSequence(cs));
Daniel Sandler879c5e02012-04-17 16:46:51 -04002261 return this;
2262 }
2263
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002264 /**
2265 * @hide
2266 */
2267 public void addExtras(Bundle extras) {
2268 super.addExtras(extras);
2269 CharSequence[] a = new CharSequence[mTexts.size()];
2270 extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a));
2271 }
2272
Daniel Sandler879c5e02012-04-17 16:46:51 -04002273 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04002274 // Remove the content text so line3 disappears unless you have a summary
2275 mBuilder.mContentText = null;
Chris Wrend6297db2012-05-03 16:20:13 -04002276 RemoteViews contentView = getStandardView(R.layout.notification_template_inbox);
Daniel Sandler619738c2012-06-07 16:33:08 -04002277
Chris Wrend6297db2012-05-03 16:20:13 -04002278 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandler879c5e02012-04-17 16:46:51 -04002279
Chris Wrend6297db2012-05-03 16:20:13 -04002280 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 -04002281 R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6};
Chris Wrend6297db2012-05-03 16:20:13 -04002282
Chris Wren4ed80d52012-05-17 09:30:03 -04002283 // Make sure all rows are gone in case we reuse a view.
2284 for (int rowId : rowIds) {
2285 contentView.setViewVisibility(rowId, View.GONE);
2286 }
2287
Chris Wren683ab002012-09-20 10:35:54 -04002288
Daniel Sandler879c5e02012-04-17 16:46:51 -04002289 int i=0;
2290 while (i < mTexts.size() && i < rowIds.length) {
2291 CharSequence str = mTexts.get(i);
2292 if (str != null && !str.equals("")) {
2293 contentView.setViewVisibility(rowIds[i], View.VISIBLE);
2294 contentView.setTextViewText(rowIds[i], str);
2295 }
2296 i++;
2297 }
2298
Chris Wren683ab002012-09-20 10:35:54 -04002299 contentView.setViewVisibility(R.id.inbox_end_pad,
2300 mTexts.size() > 0 ? View.VISIBLE : View.GONE);
2301
2302 contentView.setViewVisibility(R.id.inbox_more,
2303 mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE);
Chris Wren29bb6d92012-05-17 18:09:42 -04002304
Daniel Sandler879c5e02012-04-17 16:46:51 -04002305 return contentView;
2306 }
2307
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002308 /**
2309 * @hide
2310 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002311 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002312 public Notification buildStyled(Notification wip) {
Daniel Sandler879c5e02012-04-17 16:46:51 -04002313 wip.bigContentView = makeBigContentView();
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002314
Daniel Sandler879c5e02012-04-17 16:46:51 -04002315 return wip;
2316 }
2317 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318}