blob: e606194b3e438c9af9fe67a78c51c253b2a15555 [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.content.Context;
20import android.content.Intent;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040021import android.content.res.Resources;
Joe Onoratoef1e7762010-09-17 18:38:38 -040022import android.graphics.Bitmap;
Jeff Sharkey098d5802012-04-26 17:30:34 -070023import android.media.AudioManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.net.Uri;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040025import android.os.BadParcelableException;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050026import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.os.Parcel;
28import android.os.Parcelable;
Daniel Sandlera2985ed2012-04-03 16:42:00 -040029import android.os.SystemClock;
Jeff Sharkey6d515712012-09-20 16:06:08 -070030import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.text.TextUtils;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040032import android.util.Log;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040033import android.util.TypedValue;
Joe Onorato8595a3d2010-11-19 18:12:07 -080034import android.view.View;
Jeff Sharkey1c400132011-08-05 14:50:13 -070035import android.widget.ProgressBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.widget.RemoteViews;
37
Griff Hazen959591e2014-05-15 22:26:18 -070038import com.android.internal.R;
39
Andy Stadler110988c2010-12-03 14:29:16 -080040import java.text.NumberFormat;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050041import java.util.ArrayList;
Griff Hazen5cadc3b2014-05-20 09:55:39 -070042import java.util.Collections;
Joe Onorato561d3852010-11-20 18:09:34 -080043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044/**
45 * A class that represents how a persistent notification is to be presented to
46 * the user using the {@link android.app.NotificationManager}.
47 *
Joe Onoratocb109a02011-01-18 17:57:41 -080048 * <p>The {@link Notification.Builder Notification.Builder} has been added to make it
49 * easier to construct Notifications.</p>
50 *
Joe Fernandez558459f2011-10-13 16:47:36 -070051 * <div class="special reference">
52 * <h3>Developer Guides</h3>
53 * <p>For a guide to creating notifications, read the
54 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a>
55 * developer guide.</p>
56 * </div>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 */
58public class Notification implements Parcelable
59{
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040060 private static final String TAG = "Notification";
61
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 /**
63 * Use all default values (where applicable).
64 */
65 public static final int DEFAULT_ALL = ~0;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 /**
68 * Use the default notification sound. This will ignore any given
69 * {@link #sound}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050070 *
71
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050073 */
74
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 public static final int DEFAULT_SOUND = 1;
76
77 /**
78 * Use the default notification vibrate. This will ignore any given
Daniel Sandler2561b0b2012-02-13 21:04:12 -050079 * {@link #vibrate}. Using phone vibration requires the
Scott Mainb8b36452009-04-26 15:50:49 -070080 * {@link android.Manifest.permission#VIBRATE VIBRATE} permission.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050081 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050083 */
84
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 public static final int DEFAULT_VIBRATE = 2;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 /**
88 * Use the default notification lights. This will ignore the
89 * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or
90 * {@link #ledOnMS}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -050091 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -050093 */
94
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 public static final int DEFAULT_LIGHTS = 4;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -050098 * A timestamp related to this notification, in milliseconds since the epoch.
Joe Malin8d40d042012-11-05 11:36:40 -080099 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500100 * Default value: {@link System#currentTimeMillis() Now}.
101 *
102 * Choose a timestamp that will be most relevant to the user. For most finite events, this
103 * corresponds to the time the event happened (or will happen, in the case of events that have
104 * yet to occur but about which the user is being informed). Indefinite events should be
Joe Malin8d40d042012-11-05 11:36:40 -0800105 * timestamped according to when the activity began.
106 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500107 * Some examples:
Joe Malin8d40d042012-11-05 11:36:40 -0800108 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500109 * <ul>
110 * <li>Notification of a new chat message should be stamped when the message was received.</li>
111 * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li>
112 * <li>Notification of a completed file download should be stamped when the download finished.</li>
113 * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li>
114 * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
115 * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time.
Joe Malin8d40d042012-11-05 11:36:40 -0800116 * </ul>
117 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 */
119 public long when;
120
121 /**
122 * The resource id of a drawable to use as the icon in the status bar.
Daniel Sandlerd952dae2011-02-07 16:33:36 -0500123 * This is required; notifications with an invalid icon resource will not be shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 */
125 public int icon;
126
127 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800128 * If the icon in the status bar is to have more than one level, you can set this. Otherwise,
129 * leave it at its default value of 0.
130 *
131 * @see android.widget.ImageView#setImageLevel
Griff Hazen959591e2014-05-15 22:26:18 -0700132 * @see android.graphics.drawable.Drawable#setLevel
Joe Onorato46439ce2010-11-19 13:56:21 -0800133 */
134 public int iconLevel;
135
136 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500137 * The number of events that this notification represents. For example, in a new mail
138 * notification, this could be the number of unread messages.
Joe Malin8d40d042012-11-05 11:36:40 -0800139 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500140 * The system may or may not use this field to modify the appearance of the notification. For
141 * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was
142 * superimposed over the icon in the status bar. Starting with
143 * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by
144 * {@link Notification.Builder} has displayed the number in the expanded notification view.
Joe Malin8d40d042012-11-05 11:36:40 -0800145 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500146 * If the number is 0 or negative, it is never shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 */
148 public int number;
149
150 /**
151 * The intent to execute when the expanded status entry is clicked. If
152 * this is an activity, it must include the
153 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -0800154 * that you take care of task management as described in the
155 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
Dianne Hackborn6ceca582012-01-10 15:24:26 -0800156 * Stack</a> document. In particular, make sure to read the notification section
157 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling
158 * Notifications</a> for the correct ways to launch an application from a
159 * notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 */
161 public PendingIntent contentIntent;
162
163 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500164 * The intent to execute when the notification is explicitly dismissed by the user, either with
165 * the "Clear All" button or by swiping it away individually.
166 *
167 * This probably shouldn't be launching an activity since several of those will be sent
168 * at the same time.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 */
170 public PendingIntent deleteIntent;
171
172 /**
Dianne Hackborn170bae72010-09-03 15:14:28 -0700173 * An intent to launch instead of posting the notification to the status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -0800174 *
175 * @see Notification.Builder#setFullScreenIntent
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400176 */
177 public PendingIntent fullScreenIntent;
178
179 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 * Text to scroll across the screen when this item is added to
Joe Onoratoef1e7762010-09-17 18:38:38 -0400181 * the status bar on large and smaller devices.
182 *
Joe Onorato46439ce2010-11-19 13:56:21 -0800183 * @see #tickerView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 */
185 public CharSequence tickerText;
186
187 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800188 * The view to show as the ticker in the status bar when the notification
189 * is posted.
Joe Onoratoef1e7762010-09-17 18:38:38 -0400190 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800191 public RemoteViews tickerView;
Joe Onoratoef1e7762010-09-17 18:38:38 -0400192
193 /**
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400194 * The view that will represent this notification in the expanded status bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 */
196 public RemoteViews contentView;
197
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400198 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -0400199 * A large-format version of {@link #contentView}, giving the Notification an
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400200 * opportunity to show more detail. The system UI may choose to show this
201 * instead of the normal content view at its discretion.
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400202 */
203 public RemoteViews bigContentView;
204
205 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800206 * The bitmap that may escape the bounds of the panel and bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800208 public Bitmap largeIcon;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209
210 /**
211 * The sound to play.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500212 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 * <p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500214 * To play the default notification sound, see {@link #defaults}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 * </p>
216 */
217 public Uri sound;
218
219 /**
220 * Use this constant as the value for audioStreamType to request that
221 * the default stream type for notifications be used. Currently the
Jeff Sharkey098d5802012-04-26 17:30:34 -0700222 * default stream type is {@link AudioManager#STREAM_NOTIFICATION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 */
224 public static final int STREAM_DEFAULT = -1;
225
226 /**
227 * The audio stream type to use when playing the sound.
228 * Should be one of the STREAM_ constants from
229 * {@link android.media.AudioManager}.
230 */
231 public int audioStreamType = STREAM_DEFAULT;
232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500234 * The pattern with which to vibrate.
235 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 * <p>
237 * To vibrate the default pattern, see {@link #defaults}.
238 * </p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500239 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 * @see android.os.Vibrator#vibrate(long[],int)
241 */
242 public long[] vibrate;
243
244 /**
245 * The color of the led. The hardware will do its best approximation.
246 *
247 * @see #FLAG_SHOW_LIGHTS
248 * @see #flags
249 */
250 public int ledARGB;
251
252 /**
253 * The number of milliseconds for the LED to be on while it's flashing.
254 * The hardware will do its best approximation.
255 *
256 * @see #FLAG_SHOW_LIGHTS
257 * @see #flags
258 */
259 public int ledOnMS;
260
261 /**
262 * The number of milliseconds for the LED to be off while it's flashing.
263 * The hardware will do its best approximation.
264 *
265 * @see #FLAG_SHOW_LIGHTS
266 * @see #flags
267 */
268 public int ledOffMS;
269
270 /**
271 * Specifies which values should be taken from the defaults.
272 * <p>
273 * To set, OR the desired from {@link #DEFAULT_SOUND},
274 * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default
275 * values, use {@link #DEFAULT_ALL}.
276 * </p>
277 */
278 public int defaults;
279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 /**
281 * Bit to be bitwise-ored into the {@link #flags} field that should be
282 * set if you want the LED on for this notification.
283 * <ul>
284 * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB
285 * or 0 for both ledOnMS and ledOffMS.</li>
286 * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li>
287 * <li>To flash the LED, pass the number of milliseconds that it should
288 * be on and off to ledOnMS and ledOffMS.</li>
289 * </ul>
290 * <p>
291 * Since hardware varies, you are not guaranteed that any of the values
292 * you pass are honored exactly. Use the system defaults (TODO) if possible
293 * because they will be set to values that work on any given hardware.
294 * <p>
295 * The alpha channel must be set for forward compatibility.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500296 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 */
298 public static final int FLAG_SHOW_LIGHTS = 0x00000001;
299
300 /**
301 * Bit to be bitwise-ored into the {@link #flags} field that should be
302 * set if this notification is in reference to something that is ongoing,
303 * like a phone call. It should not be set if this notification is in
304 * reference to something that happened at a particular point in time,
305 * like a missed phone call.
306 */
307 public static final int FLAG_ONGOING_EVENT = 0x00000002;
308
309 /**
310 * Bit to be bitwise-ored into the {@link #flags} field that if set,
Scott Mainb8b36452009-04-26 15:50:49 -0700311 * the audio will be repeated until the notification is
312 * cancelled or the notification window is opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 */
314 public static final int FLAG_INSISTENT = 0x00000004;
315
316 /**
317 * Bit to be bitwise-ored into the {@link #flags} field that should be
Griff Hazen293977b2014-04-28 08:37:20 -0700318 * set if you would only like the sound, vibrate and ticker to be played
319 * if the notification was not already showing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 */
321 public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008;
322
323 /**
324 * Bit to be bitwise-ored into the {@link #flags} field that should be
325 * set if the notification should be canceled when it is clicked by the
Daniel Sandler8aa9ae62012-12-04 23:31:47 -0500326 * user.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 */
329 public static final int FLAG_AUTO_CANCEL = 0x00000010;
330
331 /**
332 * Bit to be bitwise-ored into the {@link #flags} field that should be
333 * set if the notification should not be canceled when the user clicks
334 * the Clear all button.
335 */
336 public static final int FLAG_NO_CLEAR = 0x00000020;
337
Dianne Hackbornd8a43f62009-08-17 23:33:56 -0700338 /**
339 * Bit to be bitwise-ored into the {@link #flags} field that should be
340 * set if this notification represents a currently running service. This
341 * will normally be set for you by {@link Service#startForeground}.
342 */
343 public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;
344
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400345 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500346 * Obsolete flag indicating high-priority notifications; use the priority field instead.
Joe Malin8d40d042012-11-05 11:36:40 -0800347 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500348 * @deprecated Use {@link #priority} with a positive value.
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400349 */
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500350 public static final int FLAG_HIGH_PRIORITY = 0x00000080;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400351
Griff Hazendfcb0802014-02-11 12:00:00 -0800352 /**
353 * Bit to be bitswise-ored into the {@link #flags} field that should be
354 * set if this notification is relevant to the current device only
355 * and it is not recommended that it bridge to other devices.
356 */
357 public static final int FLAG_LOCAL_ONLY = 0x00000100;
358
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700359 /**
360 * Bit to be bitswise-ored into the {@link #flags} field that should be
361 * set if this notification is the group summary for a group of notifications.
362 * Grouped notifications may display in a cluster or stack on devices which
363 * support such rendering. Requires a group key also be set using {@link Builder#setGroup}.
364 */
365 public static final int FLAG_GROUP_SUMMARY = 0x00000200;
366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 public int flags;
368
369 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500370 * Default notification {@link #priority}. If your application does not prioritize its own
371 * notifications, use this value for all notifications.
372 */
373 public static final int PRIORITY_DEFAULT = 0;
374
375 /**
376 * Lower {@link #priority}, for items that are less important. The UI may choose to show these
377 * items smaller, or at a different position in the list, compared with your app's
378 * {@link #PRIORITY_DEFAULT} items.
379 */
380 public static final int PRIORITY_LOW = -1;
381
382 /**
383 * Lowest {@link #priority}; these items might not be shown to the user except under special
384 * circumstances, such as detailed notification logs.
385 */
386 public static final int PRIORITY_MIN = -2;
387
388 /**
389 * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to
390 * show these items larger, or at a different position in notification lists, compared with
391 * your app's {@link #PRIORITY_DEFAULT} items.
392 */
393 public static final int PRIORITY_HIGH = 1;
394
395 /**
396 * Highest {@link #priority}, for your application's most important items that require the
397 * user's prompt attention or input.
398 */
399 public static final int PRIORITY_MAX = 2;
400
401 /**
402 * Relative priority for this notification.
Joe Malin8d40d042012-11-05 11:36:40 -0800403 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500404 * Priority is an indication of how much of the user's valuable attention should be consumed by
405 * this notification. Low-priority notifications may be hidden from the user in certain
406 * situations, while the user might be interrupted for a higher-priority notification. The
Daniel Sandler6738eee2012-11-16 12:03:32 -0500407 * system will make a determination about how to interpret this priority when presenting
408 * the notification.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500409 */
410 public int priority;
Joe Malin8d40d042012-11-05 11:36:40 -0800411
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500412 /**
John Spurlockcf44a122014-03-24 11:02:36 -0400413 * Notification category: incoming call (voice or video) or similar synchronous communication request.
Griff Hazened0c87e2014-05-05 15:15:12 -0700414 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500415 */
John Spurlockcf44a122014-03-24 11:02:36 -0400416 public static final String CATEGORY_CALL = "call";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500417
418 /**
John Spurlockcf44a122014-03-24 11:02:36 -0400419 * Notification category: incoming direct message (SMS, instant message, etc.).
Griff Hazened0c87e2014-05-05 15:15:12 -0700420 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500421 */
John Spurlockcf44a122014-03-24 11:02:36 -0400422 public static final String CATEGORY_MESSAGE = "msg";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500423
424 /**
John Spurlockcf44a122014-03-24 11:02:36 -0400425 * Notification category: asynchronous bulk message (email).
Griff Hazened0c87e2014-05-05 15:15:12 -0700426 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500427 */
John Spurlockcf44a122014-03-24 11:02:36 -0400428 public static final String CATEGORY_EMAIL = "email";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500429
430 /**
John Spurlockcf44a122014-03-24 11:02:36 -0400431 * Notification category: calendar event.
Griff Hazened0c87e2014-05-05 15:15:12 -0700432 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500433 */
John Spurlockcf44a122014-03-24 11:02:36 -0400434 public static final String CATEGORY_EVENT = "event";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500435
436 /**
John Spurlockcf44a122014-03-24 11:02:36 -0400437 * Notification category: promotion or advertisement.
Griff Hazened0c87e2014-05-05 15:15:12 -0700438 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500439 */
John Spurlockcf44a122014-03-24 11:02:36 -0400440 public static final String CATEGORY_PROMO = "promo";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500441
442 /**
John Spurlockcf44a122014-03-24 11:02:36 -0400443 * Notification category: alarm or timer.
Griff Hazened0c87e2014-05-05 15:15:12 -0700444 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500445 */
John Spurlockcf44a122014-03-24 11:02:36 -0400446 public static final String CATEGORY_ALARM = "alarm";
447
448 /**
449 * Notification category: progress of a long-running background operation.
Griff Hazened0c87e2014-05-05 15:15:12 -0700450 * @hide
John Spurlockcf44a122014-03-24 11:02:36 -0400451 */
452 public static final String CATEGORY_PROGRESS = "progress";
453
454 /**
455 * Notification category: social network or sharing update.
Griff Hazened0c87e2014-05-05 15:15:12 -0700456 * @hide
John Spurlockcf44a122014-03-24 11:02:36 -0400457 */
458 public static final String CATEGORY_SOCIAL = "social";
459
460 /**
461 * Notification category: error in background operation or authentication status.
Griff Hazened0c87e2014-05-05 15:15:12 -0700462 * @hide
John Spurlockcf44a122014-03-24 11:02:36 -0400463 */
464 public static final String CATEGORY_ERROR = "err";
465
466 /**
467 * Notification category: media transport control for playback.
Griff Hazened0c87e2014-05-05 15:15:12 -0700468 * @hide
John Spurlockcf44a122014-03-24 11:02:36 -0400469 */
470 public static final String CATEGORY_TRANSPORT = "transport";
471
472 /**
473 * Notification category: system or device status update. Reserved for system use.
Griff Hazened0c87e2014-05-05 15:15:12 -0700474 * @hide
John Spurlockcf44a122014-03-24 11:02:36 -0400475 */
476 public static final String CATEGORY_SYSTEM = "sys";
477
478 /**
479 * Notification category: indication of running background service.
Griff Hazened0c87e2014-05-05 15:15:12 -0700480 * @hide
John Spurlockcf44a122014-03-24 11:02:36 -0400481 */
482 public static final String CATEGORY_SERVICE = "service";
483
484 /**
485 * Notification category: a specific, timely recommendation for a single thing.
486 * For example, a news app might want to recommend a news story it believes the user will
487 * want to read next.
Griff Hazened0c87e2014-05-05 15:15:12 -0700488 * @hide
John Spurlockcf44a122014-03-24 11:02:36 -0400489 */
490 public static final String CATEGORY_RECOMMENDATION = "recommendation";
491
492 /**
493 * Notification category: ongoing information about device or contextual status.
Griff Hazened0c87e2014-05-05 15:15:12 -0700494 * @hide
John Spurlockcf44a122014-03-24 11:02:36 -0400495 */
496 public static final String CATEGORY_STATUS = "status";
497
498 /**
499 * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants)
500 * that best describes this Notification. May be used by the system for ranking and filtering.
Griff Hazened0c87e2014-05-05 15:15:12 -0700501 * @hide
John Spurlockcf44a122014-03-24 11:02:36 -0400502 */
503 public String category;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500504
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700505 private String mGroupKey;
506
507 /**
508 * Get the key used to group this notification into a cluster or stack
509 * with other notifications on devices which support such rendering.
510 */
511 public String getGroup() {
512 return mGroupKey;
513 }
514
515 private String mSortKey;
516
517 /**
518 * Get a sort key that orders this notification among other notifications from the
519 * same package. This can be useful if an external sort was already applied and an app
520 * would like to preserve this. Notifications will be sorted lexicographically using this
521 * value, although providing different priorities in addition to providing sort key may
522 * cause this value to be ignored.
523 *
524 * <p>This sort key can also be used to order members of a notification group. See
525 * {@link Builder#setGroup}.
526 *
527 * @see String#compareTo(String)
528 */
529 public String getSortKey() {
530 return mSortKey;
531 }
532
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500533 /**
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400534 * Additional semantic data to be carried around with this Notification.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400535 * <p>
536 * The extras keys defined here are intended to capture the original inputs to {@link Builder}
537 * APIs, and are intended to be used by
538 * {@link android.service.notification.NotificationListenerService} implementations to extract
539 * detailed information from notification objects.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500540 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400541 public Bundle extras = new Bundle();
542
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400543 /**
544 * {@link #extras} key: this is the title of the notification,
545 * as supplied to {@link Builder#setContentTitle(CharSequence)}.
546 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500547 public static final String EXTRA_TITLE = "android.title";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400548
549 /**
550 * {@link #extras} key: this is the title of the notification when shown in expanded form,
551 * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}.
552 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400553 public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400554
555 /**
556 * {@link #extras} key: this is the main text payload, as supplied to
557 * {@link Builder#setContentText(CharSequence)}.
558 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500559 public static final String EXTRA_TEXT = "android.text";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400560
561 /**
562 * {@link #extras} key: this is a third line of text, as supplied to
563 * {@link Builder#setSubText(CharSequence)}.
564 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400565 public static final String EXTRA_SUB_TEXT = "android.subText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400566
567 /**
568 * {@link #extras} key: this is a small piece of additional text as supplied to
569 * {@link Builder#setContentInfo(CharSequence)}.
570 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400571 public static final String EXTRA_INFO_TEXT = "android.infoText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400572
573 /**
574 * {@link #extras} key: this is a line of summary information intended to be shown
575 * alongside expanded notifications, as supplied to (e.g.)
576 * {@link BigTextStyle#setSummaryText(CharSequence)}.
577 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400578 public static final String EXTRA_SUMMARY_TEXT = "android.summaryText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400579
580 /**
581 * {@link #extras} key: this is the resource ID of the notification's main small icon, as
582 * supplied to {@link Builder#setSmallIcon(int)}.
583 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500584 public static final String EXTRA_SMALL_ICON = "android.icon";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400585
586 /**
587 * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the
588 * notification payload, as
589 * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}.
590 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400591 public static final String EXTRA_LARGE_ICON = "android.largeIcon";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400592
593 /**
594 * {@link #extras} key: this is a bitmap to be used instead of the one from
595 * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is
596 * shown in its expanded form, as supplied to
597 * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}.
598 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400599 public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400600
601 /**
602 * {@link #extras} key: this is the progress value supplied to
603 * {@link Builder#setProgress(int, int, boolean)}.
604 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400605 public static final String EXTRA_PROGRESS = "android.progress";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400606
607 /**
608 * {@link #extras} key: this is the maximum value supplied to
609 * {@link Builder#setProgress(int, int, boolean)}.
610 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400611 public static final String EXTRA_PROGRESS_MAX = "android.progressMax";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400612
613 /**
614 * {@link #extras} key: whether the progress bar is indeterminate, supplied to
615 * {@link Builder#setProgress(int, int, boolean)}.
616 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400617 public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400618
619 /**
620 * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically
621 * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to
622 * {@link Builder#setUsesChronometer(boolean)}.
623 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400624 public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400625
626 /**
627 * {@link #extras} key: whether {@link #when} should be shown,
628 * as supplied to {@link Builder#setShowWhen(boolean)}.
629 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400630 public static final String EXTRA_SHOW_WHEN = "android.showWhen";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400631
632 /**
633 * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded
634 * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}.
635 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400636 public static final String EXTRA_PICTURE = "android.picture";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400637
638 /**
639 * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded
640 * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}.
641 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400642 public static final String EXTRA_TEXT_LINES = "android.textLines";
643
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400644 /**
645 * {@link #extras} key: An array of people that this notification relates to, specified
646 * by contacts provider contact URI.
647 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400648 public static final String EXTRA_PEOPLE = "android.people";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500649
650 /**
Scott Greenwald9a05b312013-06-28 00:37:54 -0400651 * @hide
652 * Extra added by NotificationManagerService to indicate whether a NotificationScorer
653 * modified the Notifications's score.
654 */
655 public static final String EXTRA_SCORE_MODIFIED = "android.scoreModified";
656
657 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400658 * Not used.
Chris Wren51c75102013-07-16 20:49:17 -0400659 * @hide
660 */
661 public static final String EXTRA_AS_HEADS_UP = "headsup";
662
663 /**
John Spurlockcf44a122014-03-24 11:02:36 -0400664 * Allow certain system-generated notifications to appear before the device is provisioned.
665 * Only available to notifications coming from the android package.
666 * @hide
667 */
668 public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup";
669
670 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400671 * Value for {@link #EXTRA_AS_HEADS_UP}.
Chris Wren51c75102013-07-16 20:49:17 -0400672 * @hide
673 */
674 public static final int HEADS_UP_NEVER = 0;
675
676 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400677 * Default value for {@link #EXTRA_AS_HEADS_UP}.
Chris Wren51c75102013-07-16 20:49:17 -0400678 * @hide
679 */
680 public static final int HEADS_UP_ALLOWED = 1;
681
682 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400683 * Value for {@link #EXTRA_AS_HEADS_UP}.
Chris Wren51c75102013-07-16 20:49:17 -0400684 * @hide
685 */
686 public static final int HEADS_UP_REQUESTED = 2;
687
688 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400689 * Structure to encapsulate a named action that can be shown as part of this notification.
690 * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is
691 * selected by the user.
692 * <p>
Griff Hazen959591e2014-05-15 22:26:18 -0700693 * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)}
694 * or {@link Notification.Builder#addAction(Notification.Action)}
695 * to attach actions.
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400696 */
Daniel Sandlerea2a3172013-02-20 22:24:20 -0500697 public static class Action implements Parcelable {
Griff Hazen959591e2014-05-15 22:26:18 -0700698 private final Bundle mExtras;
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700699 private RemoteInput[] mRemoteInputs;
Griff Hazen959591e2014-05-15 22:26:18 -0700700
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400701 /**
702 * Small icon representing the action.
703 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400704 public int icon;
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700705
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400706 /**
707 * Title of the action.
708 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400709 public CharSequence title;
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700710
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400711 /**
712 * Intent to send when the user invokes this action. May be null, in which case the action
713 * may be rendered in a disabled presentation by the system UI.
714 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400715 public PendingIntent actionIntent;
Griff Hazen959591e2014-05-15 22:26:18 -0700716
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400717 private Action(Parcel in) {
718 icon = in.readInt();
719 title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
720 if (in.readInt() == 1) {
721 actionIntent = PendingIntent.CREATOR.createFromParcel(in);
722 }
Griff Hazen959591e2014-05-15 22:26:18 -0700723 mExtras = in.readBundle();
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700724 mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR);
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400725 }
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700726
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400727 /**
Griff Hazen959591e2014-05-15 22:26:18 -0700728 * Use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)}.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400729 */
730 public Action(int icon, CharSequence title, PendingIntent intent) {
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700731 this(icon, title, intent, new Bundle(), null);
Griff Hazen959591e2014-05-15 22:26:18 -0700732 }
733
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700734 private Action(int icon, CharSequence title, PendingIntent intent, Bundle extras,
735 RemoteInput[] remoteInputs) {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400736 this.icon = icon;
737 this.title = title;
738 this.actionIntent = intent;
Griff Hazen959591e2014-05-15 22:26:18 -0700739 this.mExtras = extras != null ? extras : new Bundle();
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700740 this.mRemoteInputs = remoteInputs;
Griff Hazen959591e2014-05-15 22:26:18 -0700741 }
742
743 /**
744 * Get additional metadata carried around with this Action.
745 */
746 public Bundle getExtras() {
747 return mExtras;
748 }
749
750 /**
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700751 * Get the list of inputs to be collected from the user when this action is sent.
752 * May return null if no remote inputs were added.
753 */
754 public RemoteInput[] getRemoteInputs() {
755 return mRemoteInputs;
756 }
757
758 /**
Griff Hazen959591e2014-05-15 22:26:18 -0700759 * Builder class for {@link Action} objects.
760 */
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700761 public static final class Builder {
Griff Hazen959591e2014-05-15 22:26:18 -0700762 private final int mIcon;
763 private final CharSequence mTitle;
764 private final PendingIntent mIntent;
765 private final Bundle mExtras;
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700766 private ArrayList<RemoteInput> mRemoteInputs;
Griff Hazen959591e2014-05-15 22:26:18 -0700767
768 /**
769 * Construct a new builder for {@link Action} object.
770 * @param icon icon to show for this action
771 * @param title the title of the action
772 * @param intent the {@link PendingIntent} to fire when users trigger this action
773 */
774 public Builder(int icon, CharSequence title, PendingIntent intent) {
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700775 this(icon, title, intent, new Bundle(), null);
Griff Hazen959591e2014-05-15 22:26:18 -0700776 }
777
778 /**
779 * Construct a new builder for {@link Action} object using the fields from an
780 * {@link Action}.
781 * @param action the action to read fields from.
782 */
783 public Builder(Action action) {
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700784 this(action.icon, action.title, action.actionIntent, new Bundle(action.mExtras),
785 action.getRemoteInputs());
Griff Hazen959591e2014-05-15 22:26:18 -0700786 }
787
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700788 private Builder(int icon, CharSequence title, PendingIntent intent, Bundle extras,
789 RemoteInput[] remoteInputs) {
Griff Hazen959591e2014-05-15 22:26:18 -0700790 mIcon = icon;
791 mTitle = title;
792 mIntent = intent;
793 mExtras = extras;
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700794 if (remoteInputs != null) {
795 mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length);
796 Collections.addAll(mRemoteInputs, remoteInputs);
797 }
Griff Hazen959591e2014-05-15 22:26:18 -0700798 }
799
800 /**
801 * Merge additional metadata into this builder.
802 *
803 * <p>Values within the Bundle will replace existing extras values in this Builder.
804 *
805 * @see Notification.Action#extras
806 */
807 public Builder addExtras(Bundle extras) {
808 if (extras != null) {
809 mExtras.putAll(extras);
810 }
811 return this;
812 }
813
814 /**
815 * Get the metadata Bundle used by this Builder.
816 *
817 * <p>The returned Bundle is shared with this Builder.
818 */
819 public Bundle getExtras() {
820 return mExtras;
821 }
822
823 /**
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700824 * Add an input to be collected from the user when this action is sent.
825 * Response values can be retrieved from the fired intent by using the
826 * {@link RemoteInput#getResultsFromIntent} function.
827 * @param remoteInput a {@link RemoteInput} to add to the action
828 * @return this object for method chaining
829 */
830 public Builder addRemoteInput(RemoteInput remoteInput) {
831 if (mRemoteInputs == null) {
832 mRemoteInputs = new ArrayList<RemoteInput>();
833 }
834 mRemoteInputs.add(remoteInput);
835 return this;
836 }
837
838 /**
839 * Apply an extender to this action builder. Extenders may be used to add
840 * metadata or change options on this builder.
841 */
842 public Builder apply(Extender extender) {
843 extender.applyTo(this);
844 return this;
845 }
846
847 /**
848 * Extender interface for use with {@link #apply}. Extenders may be used to add
849 * metadata or change options on this builder.
850 */
851 public interface Extender {
852 /**
853 * Apply this extender to a notification action builder.
854 * @param builder the builder to be modified.
855 * @return the build object for chaining.
856 */
857 public Builder applyTo(Builder builder);
858 }
859
860 /**
Griff Hazen959591e2014-05-15 22:26:18 -0700861 * Combine all of the options that have been set and return a new {@link Action}
862 * object.
863 * @return the built action
864 */
865 public Action build() {
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700866 RemoteInput[] remoteInputs = mRemoteInputs != null
867 ? mRemoteInputs.toArray(new RemoteInput[mRemoteInputs.size()]) : null;
868 return new Action(mIcon, mTitle, mIntent, mExtras, remoteInputs);
Griff Hazen959591e2014-05-15 22:26:18 -0700869 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400870 }
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400871
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400872 @Override
873 public Action clone() {
874 return new Action(
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700875 icon,
876 title,
877 actionIntent, // safe to alias
878 new Bundle(mExtras),
879 getRemoteInputs());
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400880 }
881 @Override
882 public int describeContents() {
883 return 0;
884 }
885 @Override
886 public void writeToParcel(Parcel out, int flags) {
887 out.writeInt(icon);
888 TextUtils.writeToParcel(title, out, flags);
889 if (actionIntent != null) {
890 out.writeInt(1);
891 actionIntent.writeToParcel(out, flags);
892 } else {
893 out.writeInt(0);
894 }
Griff Hazen959591e2014-05-15 22:26:18 -0700895 out.writeBundle(mExtras);
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700896 out.writeTypedArray(mRemoteInputs, flags);
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400897 }
Griff Hazen959591e2014-05-15 22:26:18 -0700898 public static final Parcelable.Creator<Action> CREATOR =
899 new Parcelable.Creator<Action>() {
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400900 public Action createFromParcel(Parcel in) {
901 return new Action(in);
902 }
903 public Action[] newArray(int size) {
904 return new Action[size];
905 }
906 };
907 }
908
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400909 /**
910 * Array of all {@link Action} structures attached to this notification by
911 * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of
912 * {@link android.service.notification.NotificationListenerService} that provide an alternative
913 * interface for invoking actions.
914 */
Daniel Sandlerea2a3172013-02-20 22:24:20 -0500915 public Action[] actions;
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400916
917 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500918 * Constructs a Notification object with default values.
Joe Onorato46439ce2010-11-19 13:56:21 -0800919 * You might want to consider using {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 */
921 public Notification()
922 {
923 this.when = System.currentTimeMillis();
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500924 this.priority = PRIORITY_DEFAULT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 }
926
927 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 * @hide
929 */
930 public Notification(Context context, int icon, CharSequence tickerText, long when,
931 CharSequence contentTitle, CharSequence contentText, Intent contentIntent)
932 {
933 this.when = when;
934 this.icon = icon;
935 this.tickerText = tickerText;
936 setLatestEventInfo(context, contentTitle, contentText,
937 PendingIntent.getActivity(context, 0, contentIntent, 0));
938 }
939
940 /**
941 * Constructs a Notification object with the information needed to
942 * have a status bar icon without the standard expanded view.
943 *
944 * @param icon The resource id of the icon to put in the status bar.
945 * @param tickerText The text that flows by in the status bar when the notification first
946 * activates.
947 * @param when The time to show in the time field. In the System.currentTimeMillis
948 * timebase.
Joe Onorato46439ce2010-11-19 13:56:21 -0800949 *
950 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 */
Joe Onorato46439ce2010-11-19 13:56:21 -0800952 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 public Notification(int icon, CharSequence tickerText, long when)
954 {
955 this.icon = icon;
956 this.tickerText = tickerText;
957 this.when = when;
958 }
959
960 /**
961 * Unflatten the notification from a parcel.
962 */
963 public Notification(Parcel parcel)
964 {
965 int version = parcel.readInt();
966
967 when = parcel.readLong();
968 icon = parcel.readInt();
969 number = parcel.readInt();
970 if (parcel.readInt() != 0) {
971 contentIntent = PendingIntent.CREATOR.createFromParcel(parcel);
972 }
973 if (parcel.readInt() != 0) {
974 deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel);
975 }
976 if (parcel.readInt() != 0) {
977 tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
978 }
979 if (parcel.readInt() != 0) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800980 tickerView = RemoteViews.CREATOR.createFromParcel(parcel);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400981 }
982 if (parcel.readInt() != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 contentView = RemoteViews.CREATOR.createFromParcel(parcel);
984 }
Joe Onorato561d3852010-11-20 18:09:34 -0800985 if (parcel.readInt() != 0) {
986 largeIcon = Bitmap.CREATOR.createFromParcel(parcel);
987 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 defaults = parcel.readInt();
989 flags = parcel.readInt();
990 if (parcel.readInt() != 0) {
991 sound = Uri.CREATOR.createFromParcel(parcel);
992 }
993
994 audioStreamType = parcel.readInt();
995 vibrate = parcel.createLongArray();
996 ledARGB = parcel.readInt();
997 ledOnMS = parcel.readInt();
998 ledOffMS = parcel.readInt();
999 iconLevel = parcel.readInt();
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001000
1001 if (parcel.readInt() != 0) {
1002 fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel);
1003 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001004
1005 priority = parcel.readInt();
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001006
John Spurlockcf44a122014-03-24 11:02:36 -04001007 category = parcel.readString();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001008
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001009 mGroupKey = parcel.readString();
1010
1011 mSortKey = parcel.readString();
1012
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001013 extras = parcel.readBundle(); // may be null
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001014
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001015 actions = parcel.createTypedArray(Action.CREATOR); // may be null
1016
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001017 if (parcel.readInt() != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001018 bigContentView = RemoteViews.CREATOR.createFromParcel(parcel);
1019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 }
1021
Andy Stadler110988c2010-12-03 14:29:16 -08001022 @Override
Joe Onorato18e69df2010-05-17 22:26:12 -07001023 public Notification clone() {
1024 Notification that = new Notification();
Daniel Sandler1a497d32013-04-18 14:52:45 -04001025 cloneInto(that, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001026 return that;
1027 }
Joe Onorato18e69df2010-05-17 22:26:12 -07001028
Daniel Sandler1a497d32013-04-18 14:52:45 -04001029 /**
1030 * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members
1031 * of this into that.
1032 * @hide
1033 */
1034 public void cloneInto(Notification that, boolean heavy) {
Joe Onorato18e69df2010-05-17 22:26:12 -07001035 that.when = this.when;
1036 that.icon = this.icon;
1037 that.number = this.number;
1038
1039 // PendingIntents are global, so there's no reason (or way) to clone them.
1040 that.contentIntent = this.contentIntent;
1041 that.deleteIntent = this.deleteIntent;
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001042 that.fullScreenIntent = this.fullScreenIntent;
Joe Onorato18e69df2010-05-17 22:26:12 -07001043
1044 if (this.tickerText != null) {
1045 that.tickerText = this.tickerText.toString();
1046 }
Daniel Sandler1a497d32013-04-18 14:52:45 -04001047 if (heavy && this.tickerView != null) {
Joe Onorato46439ce2010-11-19 13:56:21 -08001048 that.tickerView = this.tickerView.clone();
Joe Onoratoef1e7762010-09-17 18:38:38 -04001049 }
Daniel Sandler1a497d32013-04-18 14:52:45 -04001050 if (heavy && this.contentView != null) {
Joe Onorato18e69df2010-05-17 22:26:12 -07001051 that.contentView = this.contentView.clone();
1052 }
Daniel Sandler1a497d32013-04-18 14:52:45 -04001053 if (heavy && this.largeIcon != null) {
Joe Onorato561d3852010-11-20 18:09:34 -08001054 that.largeIcon = Bitmap.createBitmap(this.largeIcon);
1055 }
Jozef BABJAKa8b91832011-02-22 08:05:08 +01001056 that.iconLevel = this.iconLevel;
Joe Onorato18e69df2010-05-17 22:26:12 -07001057 that.sound = this.sound; // android.net.Uri is immutable
1058 that.audioStreamType = this.audioStreamType;
1059
1060 final long[] vibrate = this.vibrate;
1061 if (vibrate != null) {
1062 final int N = vibrate.length;
1063 final long[] vib = that.vibrate = new long[N];
1064 System.arraycopy(vibrate, 0, vib, 0, N);
1065 }
1066
1067 that.ledARGB = this.ledARGB;
1068 that.ledOnMS = this.ledOnMS;
1069 that.ledOffMS = this.ledOffMS;
1070 that.defaults = this.defaults;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001071
Joe Onorato18e69df2010-05-17 22:26:12 -07001072 that.flags = this.flags;
1073
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001074 that.priority = this.priority;
Joe Malin8d40d042012-11-05 11:36:40 -08001075
John Spurlockcf44a122014-03-24 11:02:36 -04001076 that.category = this.category;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001077
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001078 that.mGroupKey = this.mGroupKey;
1079
1080 that.mSortKey = this.mSortKey;
1081
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001082 if (this.extras != null) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001083 try {
1084 that.extras = new Bundle(this.extras);
1085 // will unparcel
1086 that.extras.size();
1087 } catch (BadParcelableException e) {
1088 Log.e(TAG, "could not unparcel extras from notification: " + this, e);
1089 that.extras = null;
1090 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001091 }
1092
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001093 if (this.actions != null) {
1094 that.actions = new Action[this.actions.length];
1095 for(int i=0; i<this.actions.length; i++) {
1096 that.actions[i] = this.actions[i].clone();
1097 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001098 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001099
Daniel Sandler1a497d32013-04-18 14:52:45 -04001100 if (heavy && this.bigContentView != null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001101 that.bigContentView = this.bigContentView.clone();
1102 }
Daniel Sandler1a497d32013-04-18 14:52:45 -04001103
1104 if (!heavy) {
1105 that.lightenPayload(); // will clean out extras
1106 }
1107 }
1108
1109 /**
1110 * Removes heavyweight parts of the Notification object for archival or for sending to
1111 * listeners when the full contents are not necessary.
1112 * @hide
1113 */
1114 public final void lightenPayload() {
1115 tickerView = null;
1116 contentView = null;
1117 bigContentView = null;
1118 largeIcon = null;
1119 if (extras != null) {
1120 extras.remove(Notification.EXTRA_LARGE_ICON);
1121 extras.remove(Notification.EXTRA_LARGE_ICON_BIG);
1122 extras.remove(Notification.EXTRA_PICTURE);
1123 }
Joe Onorato18e69df2010-05-17 22:26:12 -07001124 }
1125
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001126 /**
1127 * Make sure this CharSequence is safe to put into a bundle, which basically
1128 * means it had better not be some custom Parcelable implementation.
1129 * @hide
1130 */
1131 public static CharSequence safeCharSequence(CharSequence cs) {
1132 if (cs instanceof Parcelable) {
1133 Log.e(TAG, "warning: " + cs.getClass().getCanonicalName()
1134 + " instance is a custom Parcelable and not allowed in Notification");
1135 return cs.toString();
1136 }
1137
1138 return cs;
1139 }
1140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 public int describeContents() {
1142 return 0;
1143 }
1144
1145 /**
1146 * Flatten this notification from a parcel.
1147 */
1148 public void writeToParcel(Parcel parcel, int flags)
1149 {
1150 parcel.writeInt(1);
1151
1152 parcel.writeLong(when);
1153 parcel.writeInt(icon);
1154 parcel.writeInt(number);
1155 if (contentIntent != null) {
1156 parcel.writeInt(1);
1157 contentIntent.writeToParcel(parcel, 0);
1158 } else {
1159 parcel.writeInt(0);
1160 }
1161 if (deleteIntent != null) {
1162 parcel.writeInt(1);
1163 deleteIntent.writeToParcel(parcel, 0);
1164 } else {
1165 parcel.writeInt(0);
1166 }
1167 if (tickerText != null) {
1168 parcel.writeInt(1);
1169 TextUtils.writeToParcel(tickerText, parcel, flags);
1170 } else {
1171 parcel.writeInt(0);
1172 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001173 if (tickerView != null) {
Joe Onoratoef1e7762010-09-17 18:38:38 -04001174 parcel.writeInt(1);
Joe Onorato46439ce2010-11-19 13:56:21 -08001175 tickerView.writeToParcel(parcel, 0);
Joe Onoratoef1e7762010-09-17 18:38:38 -04001176 } else {
1177 parcel.writeInt(0);
1178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 if (contentView != null) {
1180 parcel.writeInt(1);
1181 contentView.writeToParcel(parcel, 0);
1182 } else {
1183 parcel.writeInt(0);
1184 }
Joe Onorato561d3852010-11-20 18:09:34 -08001185 if (largeIcon != null) {
1186 parcel.writeInt(1);
1187 largeIcon.writeToParcel(parcel, 0);
1188 } else {
1189 parcel.writeInt(0);
1190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191
1192 parcel.writeInt(defaults);
1193 parcel.writeInt(this.flags);
1194
1195 if (sound != null) {
1196 parcel.writeInt(1);
1197 sound.writeToParcel(parcel, 0);
1198 } else {
1199 parcel.writeInt(0);
1200 }
1201 parcel.writeInt(audioStreamType);
1202 parcel.writeLongArray(vibrate);
1203 parcel.writeInt(ledARGB);
1204 parcel.writeInt(ledOnMS);
1205 parcel.writeInt(ledOffMS);
1206 parcel.writeInt(iconLevel);
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001207
1208 if (fullScreenIntent != null) {
1209 parcel.writeInt(1);
1210 fullScreenIntent.writeToParcel(parcel, 0);
1211 } else {
1212 parcel.writeInt(0);
1213 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001214
1215 parcel.writeInt(priority);
Joe Malin8d40d042012-11-05 11:36:40 -08001216
John Spurlockcf44a122014-03-24 11:02:36 -04001217 parcel.writeString(category);
Joe Malin8d40d042012-11-05 11:36:40 -08001218
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001219 parcel.writeString(mGroupKey);
1220
1221 parcel.writeString(mSortKey);
1222
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001223 parcel.writeBundle(extras); // null ok
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001224
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001225 parcel.writeTypedArray(actions, 0); // null ok
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001226
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001227 if (bigContentView != null) {
1228 parcel.writeInt(1);
1229 bigContentView.writeToParcel(parcel, 0);
1230 } else {
1231 parcel.writeInt(0);
1232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 }
1234
1235 /**
1236 * Parcelable.Creator that instantiates Notification objects
1237 */
1238 public static final Parcelable.Creator<Notification> CREATOR
1239 = new Parcelable.Creator<Notification>()
1240 {
1241 public Notification createFromParcel(Parcel parcel)
1242 {
1243 return new Notification(parcel);
1244 }
1245
1246 public Notification[] newArray(int size)
1247 {
1248 return new Notification[size];
1249 }
1250 };
1251
1252 /**
1253 * Sets the {@link #contentView} field to be a view with the standard "Latest Event"
1254 * layout.
1255 *
1256 * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields
1257 * in the view.</p>
1258 * @param context The context for your application / activity.
1259 * @param contentTitle The title that goes in the expanded entry.
1260 * @param contentText The text that goes in the expanded entry.
1261 * @param contentIntent The intent to launch when the user clicks the expanded notification.
1262 * If this is an activity, it must include the
1263 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -08001264 * that you take care of task management as described in the
1265 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
1266 * Stack</a> document.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001267 *
Joe Onorato46439ce2010-11-19 13:56:21 -08001268 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001270 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 public void setLatestEventInfo(Context context,
1272 CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001273 Notification.Builder builder = new Notification.Builder(context);
1274
1275 // First, ensure that key pieces of information that may have been set directly
1276 // are preserved
1277 builder.setWhen(this.when);
1278 builder.setSmallIcon(this.icon);
1279 builder.setPriority(this.priority);
1280 builder.setTicker(this.tickerText);
1281 builder.setNumber(this.number);
1282 builder.mFlags = this.flags;
1283 builder.setSound(this.sound, this.audioStreamType);
1284 builder.setDefaults(this.defaults);
1285 builder.setVibrate(this.vibrate);
1286
1287 // now apply the latestEventInfo fields
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 if (contentTitle != null) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001289 builder.setContentTitle(contentTitle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001290 }
1291 if (contentText != null) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001292 builder.setContentText(contentText);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001294 builder.setContentIntent(contentIntent);
1295 builder.buildInto(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 }
1297
1298 @Override
1299 public String toString() {
1300 StringBuilder sb = new StringBuilder();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001301 sb.append("Notification(pri=");
1302 sb.append(priority);
1303 sb.append(" contentView=");
Joe Onoratoc9596d62011-01-12 17:03:11 -08001304 if (contentView != null) {
1305 sb.append(contentView.getPackage());
1306 sb.append("/0x");
1307 sb.append(Integer.toHexString(contentView.getLayoutId()));
1308 } else {
1309 sb.append("null");
1310 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001311 // TODO(dsandler): defaults take precedence over local values, so reorder the branches below
Joe Onoratoc9596d62011-01-12 17:03:11 -08001312 sb.append(" vibrate=");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001313 if ((this.defaults & DEFAULT_VIBRATE) != 0) {
1314 sb.append("default");
1315 } else if (this.vibrate != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 int N = this.vibrate.length-1;
1317 sb.append("[");
1318 for (int i=0; i<N; i++) {
1319 sb.append(this.vibrate[i]);
1320 sb.append(',');
1321 }
Simon Schoar8cf97d92009-06-10 22:08:37 +02001322 if (N != -1) {
1323 sb.append(this.vibrate[N]);
1324 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001325 sb.append("]");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 } else {
1327 sb.append("null");
1328 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001329 sb.append(" sound=");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001330 if ((this.defaults & DEFAULT_SOUND) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 sb.append("default");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001332 } else if (this.sound != null) {
1333 sb.append(this.sound.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 } else {
1335 sb.append("null");
1336 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001337 sb.append(" defaults=0x");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 sb.append(Integer.toHexString(this.defaults));
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001339 sb.append(" flags=0x");
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001340 sb.append(Integer.toHexString(this.flags));
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001341 if (this.category != null) {
1342 sb.append(" category=");
1343 sb.append(this.category);
1344 }
1345 if (this.mGroupKey != null) {
1346 sb.append(" groupKey=");
1347 sb.append(this.mGroupKey);
1348 }
1349 if (this.mSortKey != null) {
1350 sb.append(" sortKey=");
1351 sb.append(this.mSortKey);
1352 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001353 if (actions != null) {
1354 sb.append(" ");
1355 sb.append(actions.length);
1356 sb.append(" action");
1357 if (actions.length > 1) sb.append("s");
1358 }
1359 sb.append(")");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 return sb.toString();
1361 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001362
Jeff Sharkey6d515712012-09-20 16:06:08 -07001363 /** {@hide} */
1364 public void setUser(UserHandle user) {
Amith Yamasaniecbd68b2012-11-02 12:17:19 -07001365 if (user.getIdentifier() == UserHandle.USER_ALL) {
1366 user = UserHandle.OWNER;
1367 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07001368 if (tickerView != null) {
1369 tickerView.setUser(user);
1370 }
1371 if (contentView != null) {
1372 contentView.setUser(user);
1373 }
1374 if (bigContentView != null) {
1375 bigContentView.setUser(user);
1376 }
1377 }
1378
Joe Onoratocb109a02011-01-18 17:57:41 -08001379 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001380 * Builder class for {@link Notification} objects.
Joe Malin8d40d042012-11-05 11:36:40 -08001381 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001382 * Provides a convenient way to set the various fields of a {@link Notification} and generate
Scott Main183bf112012-08-13 19:12:13 -07001383 * content views using the platform's notification layout template. If your app supports
1384 * versions of Android as old as API level 4, you can instead use
1385 * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder},
1386 * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support
1387 * library</a>.
Joe Malin8d40d042012-11-05 11:36:40 -08001388 *
Scott Main183bf112012-08-13 19:12:13 -07001389 * <p>Example:
Joe Malin8d40d042012-11-05 11:36:40 -08001390 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001391 * <pre class="prettyprint">
Scott Main183bf112012-08-13 19:12:13 -07001392 * Notification noti = new Notification.Builder(mContext)
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001393 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
1394 * .setContentText(subject)
1395 * .setSmallIcon(R.drawable.new_mail)
1396 * .setLargeIcon(aBitmap)
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001397 * .build();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001398 * </pre>
Joe Onoratocb109a02011-01-18 17:57:41 -08001399 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001400 public static class Builder {
Daniel Sandler602ad1c2012-06-12 16:06:27 -04001401 private static final int MAX_ACTION_BUTTONS = 3;
Daniel Sandler8680bf82012-05-15 16:52:52 -04001402
Joe Onorato46439ce2010-11-19 13:56:21 -08001403 private Context mContext;
1404
1405 private long mWhen;
1406 private int mSmallIcon;
1407 private int mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08001408 private int mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08001409 private CharSequence mContentTitle;
1410 private CharSequence mContentText;
1411 private CharSequence mContentInfo;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001412 private CharSequence mSubText;
Joe Onorato46439ce2010-11-19 13:56:21 -08001413 private PendingIntent mContentIntent;
1414 private RemoteViews mContentView;
1415 private PendingIntent mDeleteIntent;
1416 private PendingIntent mFullScreenIntent;
1417 private CharSequence mTickerText;
1418 private RemoteViews mTickerView;
1419 private Bitmap mLargeIcon;
1420 private Uri mSound;
1421 private int mAudioStreamType;
1422 private long[] mVibrate;
1423 private int mLedArgb;
1424 private int mLedOnMs;
1425 private int mLedOffMs;
1426 private int mDefaults;
1427 private int mFlags;
Jeff Sharkey1c400132011-08-05 14:50:13 -07001428 private int mProgressMax;
1429 private int mProgress;
1430 private boolean mProgressIndeterminate;
John Spurlockcf44a122014-03-24 11:02:36 -04001431 private String mCategory;
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001432 private String mGroupKey;
1433 private String mSortKey;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001434 private Bundle mExtras;
1435 private int mPriority;
Daniel Sandler8680bf82012-05-15 16:52:52 -04001436 private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS);
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001437 private boolean mUseChronometer;
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001438 private Style mStyle;
Daniel Sandler0c890492012-09-12 17:23:10 -07001439 private boolean mShowWhen = true;
Joe Onorato46439ce2010-11-19 13:56:21 -08001440
Joe Onoratocb109a02011-01-18 17:57:41 -08001441 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001442 * Constructs a new Builder with the defaults:
Joe Onoratocb109a02011-01-18 17:57:41 -08001443 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001444
1445 * <table>
1446 * <tr><th align=right>priority</th>
1447 * <td>{@link #PRIORITY_DEFAULT}</td></tr>
1448 * <tr><th align=right>when</th>
1449 * <td>now ({@link System#currentTimeMillis()})</td></tr>
1450 * <tr><th align=right>audio stream</th>
1451 * <td>{@link #STREAM_DEFAULT}</td></tr>
1452 * </table>
Joe Onoratocb109a02011-01-18 17:57:41 -08001453 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001454
1455 * @param context
1456 * A {@link Context} that will be used by the Builder to construct the
1457 * RemoteViews. The Context will not be held past the lifetime of this Builder
1458 * object.
Joe Onoratocb109a02011-01-18 17:57:41 -08001459 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001460 public Builder(Context context) {
1461 mContext = context;
Andy Stadler110988c2010-12-03 14:29:16 -08001462
1463 // Set defaults to match the defaults of a Notification
Joe Onorato46439ce2010-11-19 13:56:21 -08001464 mWhen = System.currentTimeMillis();
Andy Stadler110988c2010-12-03 14:29:16 -08001465 mAudioStreamType = STREAM_DEFAULT;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001466 mPriority = PRIORITY_DEFAULT;
Joe Onorato46439ce2010-11-19 13:56:21 -08001467 }
1468
Joe Onoratocb109a02011-01-18 17:57:41 -08001469 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001470 * Add a timestamp pertaining to the notification (usually the time the event occurred).
Daniel Sandler0c890492012-09-12 17:23:10 -07001471 * It will be shown in the notification content view by default; use
Griff Hazen50c11652014-05-16 09:46:31 -07001472 * {@link #setShowWhen(boolean) setShowWhen} to control this.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001473 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001474 * @see Notification#when
Joe Onoratocb109a02011-01-18 17:57:41 -08001475 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001476 public Builder setWhen(long when) {
1477 mWhen = when;
1478 return this;
1479 }
1480
Joe Onoratocb109a02011-01-18 17:57:41 -08001481 /**
Griff Hazen50c11652014-05-16 09:46:31 -07001482 * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown
Daniel Sandler0c890492012-09-12 17:23:10 -07001483 * in the content view.
1484 */
1485 public Builder setShowWhen(boolean show) {
1486 mShowWhen = show;
1487 return this;
1488 }
1489
1490 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001491 * Show the {@link Notification#when} field as a stopwatch.
Joe Malin8d40d042012-11-05 11:36:40 -08001492 *
1493 * Instead of presenting <code>when</code> as a timestamp, the notification will show an
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001494 * automatically updating display of the minutes and seconds since <code>when</code>.
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001495 *
Daniel Sandlerd33b8032012-05-10 11:41:48 -04001496 * Useful when showing an elapsed time (like an ongoing phone call).
1497 *
1498 * @see android.widget.Chronometer
Daniel Sandlera2985ed2012-04-03 16:42:00 -04001499 * @see Notification#when
1500 */
1501 public Builder setUsesChronometer(boolean b) {
1502 mUseChronometer = b;
1503 return this;
1504 }
1505
1506 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001507 * Set the small icon resource, which will be used to represent the notification in the
1508 * status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -08001509 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001510
1511 * The platform template for the expanded view will draw this icon in the left, unless a
1512 * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small
1513 * icon will be moved to the right-hand side.
1514 *
1515
1516 * @param icon
1517 * A resource ID in the application's package of the drawable to use.
1518 * @see Notification#icon
Joe Onoratocb109a02011-01-18 17:57:41 -08001519 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001520 public Builder setSmallIcon(int icon) {
1521 mSmallIcon = icon;
1522 return this;
1523 }
1524
Joe Onoratocb109a02011-01-18 17:57:41 -08001525 /**
1526 * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional
1527 * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable
1528 * LevelListDrawable}.
1529 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001530 * @param icon A resource ID in the application's package of the drawable to use.
Joe Onoratocb109a02011-01-18 17:57:41 -08001531 * @param level The level to use for the icon.
1532 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001533 * @see Notification#icon
1534 * @see Notification#iconLevel
Joe Onoratocb109a02011-01-18 17:57:41 -08001535 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001536 public Builder setSmallIcon(int icon, int level) {
1537 mSmallIcon = icon;
1538 mSmallIconLevel = level;
1539 return this;
1540 }
1541
Joe Onoratocb109a02011-01-18 17:57:41 -08001542 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001543 * Set the first line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001544 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001545 public Builder setContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001546 mContentTitle = safeCharSequence(title);
Joe Onorato46439ce2010-11-19 13:56:21 -08001547 return this;
1548 }
1549
Joe Onoratocb109a02011-01-18 17:57:41 -08001550 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001551 * Set the second line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08001552 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001553 public Builder setContentText(CharSequence text) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001554 mContentText = safeCharSequence(text);
Joe Onorato46439ce2010-11-19 13:56:21 -08001555 return this;
1556 }
1557
Joe Onoratocb109a02011-01-18 17:57:41 -08001558 /**
Joe Malin8d40d042012-11-05 11:36:40 -08001559 * Set the third line of text in the platform notification template.
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001560 * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the
1561 * same location in the standard template.
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001562 */
1563 public Builder setSubText(CharSequence text) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001564 mSubText = safeCharSequence(text);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001565 return this;
1566 }
1567
1568 /**
Joe Onoratocb109a02011-01-18 17:57:41 -08001569 * Set the large number at the right-hand side of the notification. This is
1570 * equivalent to setContentInfo, although it might show the number in a different
1571 * font size for readability.
1572 */
Joe Onorato8595a3d2010-11-19 18:12:07 -08001573 public Builder setNumber(int number) {
1574 mNumber = number;
1575 return this;
1576 }
1577
Joe Onoratocb109a02011-01-18 17:57:41 -08001578 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001579 * A small piece of additional information pertaining to this notification.
1580 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001581 * The platform template will draw this on the last line of the notification, at the far
1582 * right (to the right of a smallIcon if it has been placed there).
Joe Onoratocb109a02011-01-18 17:57:41 -08001583 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001584 public Builder setContentInfo(CharSequence info) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001585 mContentInfo = safeCharSequence(info);
Joe Onorato46439ce2010-11-19 13:56:21 -08001586 return this;
1587 }
1588
Joe Onoratocb109a02011-01-18 17:57:41 -08001589 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001590 * Set the progress this notification represents.
1591 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001592 * The platform template will represent this using a {@link ProgressBar}.
Jeff Sharkey1c400132011-08-05 14:50:13 -07001593 */
1594 public Builder setProgress(int max, int progress, boolean indeterminate) {
1595 mProgressMax = max;
1596 mProgress = progress;
1597 mProgressIndeterminate = indeterminate;
1598 return this;
1599 }
1600
1601 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001602 * Supply a custom RemoteViews to use instead of the platform template.
1603 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001604 * @see Notification#contentView
Joe Onoratocb109a02011-01-18 17:57:41 -08001605 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001606 public Builder setContent(RemoteViews views) {
1607 mContentView = views;
1608 return this;
1609 }
1610
Joe Onoratocb109a02011-01-18 17:57:41 -08001611 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001612 * Supply a {@link PendingIntent} to be sent when the notification is clicked.
1613 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001614 * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you
1615 * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use
1616 * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)}
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001617 * to assign PendingIntents to individual views in that custom layout (i.e., to create
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001618 * clickable buttons inside the notification view).
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001619 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001620 * @see Notification#contentIntent Notification.contentIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001621 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001622 public Builder setContentIntent(PendingIntent intent) {
1623 mContentIntent = intent;
1624 return this;
1625 }
1626
Joe Onoratocb109a02011-01-18 17:57:41 -08001627 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001628 * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user.
1629 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001630 * @see Notification#deleteIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001631 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001632 public Builder setDeleteIntent(PendingIntent intent) {
1633 mDeleteIntent = intent;
1634 return this;
1635 }
1636
Joe Onoratocb109a02011-01-18 17:57:41 -08001637 /**
1638 * An intent to launch instead of posting the notification to the status bar.
1639 * Only for use with extremely high-priority notifications demanding the user's
1640 * <strong>immediate</strong> attention, such as an incoming phone call or
1641 * alarm clock that the user has explicitly set to a particular time.
1642 * If this facility is used for something else, please give the user an option
1643 * to turn it off and use a normal notification, as this can be extremely
1644 * disruptive.
1645 *
1646 * @param intent The pending intent to launch.
1647 * @param highPriority Passing true will cause this notification to be sent
1648 * even if other notifications are suppressed.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001649 *
1650 * @see Notification#fullScreenIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08001651 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001652 public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
1653 mFullScreenIntent = intent;
1654 setFlag(FLAG_HIGH_PRIORITY, highPriority);
1655 return this;
1656 }
1657
Joe Onoratocb109a02011-01-18 17:57:41 -08001658 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001659 * Set the "ticker" text which is displayed in the status bar when the notification first
Joe Onoratocb109a02011-01-18 17:57:41 -08001660 * arrives.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001661 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001662 * @see Notification#tickerText
Joe Onoratocb109a02011-01-18 17:57:41 -08001663 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001664 public Builder setTicker(CharSequence tickerText) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001665 mTickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08001666 return this;
1667 }
1668
Joe Onoratocb109a02011-01-18 17:57:41 -08001669 /**
1670 * Set the text that is displayed in the status bar when the notification first
1671 * arrives, and also a RemoteViews object that may be displayed instead on some
1672 * devices.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001673 *
1674 * @see Notification#tickerText
1675 * @see Notification#tickerView
Joe Onoratocb109a02011-01-18 17:57:41 -08001676 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001677 public Builder setTicker(CharSequence tickerText, RemoteViews views) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001678 mTickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08001679 mTickerView = views;
1680 return this;
1681 }
1682
Joe Onoratocb109a02011-01-18 17:57:41 -08001683 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001684 * Add a large icon to the notification (and the ticker on some devices).
1685 *
1686 * In the platform template, this image will be shown on the left of the notification view
1687 * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side).
1688 *
1689 * @see Notification#largeIcon
Joe Onoratocb109a02011-01-18 17:57:41 -08001690 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001691 public Builder setLargeIcon(Bitmap icon) {
1692 mLargeIcon = icon;
1693 return this;
1694 }
1695
Joe Onoratocb109a02011-01-18 17:57:41 -08001696 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001697 * Set the sound to play.
1698 *
1699 * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications.
1700 *
1701 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001702 */
Joe Onorato52f80cd2010-11-21 15:34:48 -08001703 public Builder setSound(Uri sound) {
1704 mSound = sound;
1705 mAudioStreamType = STREAM_DEFAULT;
1706 return this;
1707 }
1708
Joe Onoratocb109a02011-01-18 17:57:41 -08001709 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001710 * Set the sound to play, along with a specific stream on which to play it.
Joe Onoratocb109a02011-01-18 17:57:41 -08001711 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001712 * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants.
1713 *
1714 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08001715 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001716 public Builder setSound(Uri sound, int streamType) {
1717 mSound = sound;
1718 mAudioStreamType = streamType;
1719 return this;
1720 }
1721
Joe Onoratocb109a02011-01-18 17:57:41 -08001722 /**
1723 * Set the vibration pattern to use.
1724 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001725
1726 * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the
1727 * <code>pattern</code> parameter.
1728 *
1729
1730 * @see Notification#vibrate
Joe Onoratocb109a02011-01-18 17:57:41 -08001731 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001732 public Builder setVibrate(long[] pattern) {
1733 mVibrate = pattern;
1734 return this;
1735 }
1736
Joe Onoratocb109a02011-01-18 17:57:41 -08001737 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001738 * Set the desired color for the indicator LED on the device, as well as the
1739 * blink duty cycle (specified in milliseconds).
1740 *
1741
1742 * Not all devices will honor all (or even any) of these values.
1743 *
1744
1745 * @see Notification#ledARGB
1746 * @see Notification#ledOnMS
1747 * @see Notification#ledOffMS
Joe Onoratocb109a02011-01-18 17:57:41 -08001748 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001749 public Builder setLights(int argb, int onMs, int offMs) {
1750 mLedArgb = argb;
1751 mLedOnMs = onMs;
1752 mLedOffMs = offMs;
Joe Onorato46439ce2010-11-19 13:56:21 -08001753 return this;
1754 }
1755
Joe Onoratocb109a02011-01-18 17:57:41 -08001756 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001757 * Set whether this is an "ongoing" notification.
Joe Onoratocb109a02011-01-18 17:57:41 -08001758 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001759
1760 * Ongoing notifications cannot be dismissed by the user, so your application or service
1761 * must take care of canceling them.
1762 *
1763
1764 * They are typically used to indicate a background task that the user is actively engaged
1765 * with (e.g., playing music) or is pending in some way and therefore occupying the device
1766 * (e.g., a file download, sync operation, active network connection).
1767 *
1768
1769 * @see Notification#FLAG_ONGOING_EVENT
1770 * @see Service#setForeground(boolean)
Joe Onoratocb109a02011-01-18 17:57:41 -08001771 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001772 public Builder setOngoing(boolean ongoing) {
1773 setFlag(FLAG_ONGOING_EVENT, ongoing);
1774 return this;
1775 }
1776
Joe Onoratocb109a02011-01-18 17:57:41 -08001777 /**
1778 * Set this flag if you would only like the sound, vibrate
1779 * and ticker to be played if the notification is not already showing.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001780 *
1781 * @see Notification#FLAG_ONLY_ALERT_ONCE
Joe Onoratocb109a02011-01-18 17:57:41 -08001782 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001783 public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
1784 setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
1785 return this;
1786 }
1787
Joe Onoratocb109a02011-01-18 17:57:41 -08001788 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001789 * Make this notification automatically dismissed when the user touches it. The
1790 * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens.
1791 *
1792 * @see Notification#FLAG_AUTO_CANCEL
Joe Onoratocb109a02011-01-18 17:57:41 -08001793 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001794 public Builder setAutoCancel(boolean autoCancel) {
Joe Onorato281d83f2011-01-04 17:13:10 -08001795 setFlag(FLAG_AUTO_CANCEL, autoCancel);
Joe Onorato46439ce2010-11-19 13:56:21 -08001796 return this;
1797 }
1798
Joe Onoratocb109a02011-01-18 17:57:41 -08001799 /**
Griff Hazendfcb0802014-02-11 12:00:00 -08001800 * Set whether or not this notification should not bridge to other devices.
1801 *
1802 * <p>Some notifications can be bridged to other devices for remote display.
1803 * This hint can be set to recommend this notification not be bridged.
1804 */
1805 public Builder setLocalOnly(boolean localOnly) {
1806 setFlag(FLAG_LOCAL_ONLY, localOnly);
1807 return this;
1808 }
1809
1810 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001811 * Set which notification properties will be inherited from system defaults.
Joe Onoratocb109a02011-01-18 17:57:41 -08001812 * <p>
1813 * The value should be one or more of the following fields combined with
1814 * bitwise-or:
1815 * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}.
1816 * <p>
1817 * For all default values, use {@link #DEFAULT_ALL}.
1818 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001819 public Builder setDefaults(int defaults) {
1820 mDefaults = defaults;
1821 return this;
1822 }
1823
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001824 /**
1825 * Set the priority of this notification.
1826 *
1827 * @see Notification#priority
1828 */
1829 public Builder setPriority(int pri) {
1830 mPriority = pri;
1831 return this;
1832 }
Joe Malin8d40d042012-11-05 11:36:40 -08001833
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001834 /**
John Spurlockcf44a122014-03-24 11:02:36 -04001835 * Set the notification category.
Joe Malin8d40d042012-11-05 11:36:40 -08001836 *
John Spurlockcf44a122014-03-24 11:02:36 -04001837 * @see Notification#category
Griff Hazened0c87e2014-05-05 15:15:12 -07001838 * @hide
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001839 */
John Spurlockcf44a122014-03-24 11:02:36 -04001840 public Builder setCategory(String category) {
1841 mCategory = category;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001842 return this;
1843 }
1844
1845 /**
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001846 * Set this notification to be part of a group of notifications sharing the same key.
1847 * Grouped notifications may display in a cluster or stack on devices which
1848 * support such rendering.
1849 *
1850 * <p>To make this notification the summary for its group, also call
1851 * {@link #setGroupSummary}. A sort order can be specified for group members by using
1852 * {@link #setSortKey}.
1853 * @param groupKey The group key of the group.
1854 * @return this object for method chaining
1855 */
1856 public Builder setGroup(String groupKey) {
1857 mGroupKey = groupKey;
1858 return this;
1859 }
1860
1861 /**
1862 * Set this notification to be the group summary for a group of notifications.
1863 * Grouped notifications may display in a cluster or stack on devices which
1864 * support such rendering. Requires a group key also be set using {@link #setGroup}.
1865 * @param isGroupSummary Whether this notification should be a group summary.
1866 * @return this object for method chaining
1867 */
1868 public Builder setGroupSummary(boolean isGroupSummary) {
1869 setFlag(FLAG_GROUP_SUMMARY, isGroupSummary);
1870 return this;
1871 }
1872
1873 /**
1874 * Set a sort key that orders this notification among other notifications from the
1875 * same package. This can be useful if an external sort was already applied and an app
1876 * would like to preserve this. Notifications will be sorted lexicographically using this
1877 * value, although providing different priorities in addition to providing sort key may
1878 * cause this value to be ignored.
1879 *
1880 * <p>This sort key can also be used to order members of a notification group. See
Griff Hazen9e1379f2014-05-20 12:50:51 -07001881 * {@link #setGroup}.
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001882 *
1883 * @see String#compareTo(String)
1884 */
1885 public Builder setSortKey(String sortKey) {
1886 mSortKey = sortKey;
1887 return this;
1888 }
1889
1890 /**
Griff Hazen720042b2014-02-24 15:46:56 -08001891 * Merge additional metadata into this notification.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001892 *
Griff Hazen720042b2014-02-24 15:46:56 -08001893 * <p>Values within the Bundle will replace existing extras values in this Builder.
1894 *
1895 * @see Notification#extras
1896 */
Griff Hazen959591e2014-05-15 22:26:18 -07001897 public Builder addExtras(Bundle extras) {
1898 if (extras != null) {
1899 if (mExtras == null) {
1900 mExtras = new Bundle(extras);
1901 } else {
1902 mExtras.putAll(extras);
1903 }
Griff Hazen720042b2014-02-24 15:46:56 -08001904 }
1905 return this;
1906 }
1907
1908 /**
1909 * Set metadata for this notification.
1910 *
1911 * <p>A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001912 * current contents are copied into the Notification each time {@link #build()} is
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001913 * called.
1914 *
Griff Hazen720042b2014-02-24 15:46:56 -08001915 * <p>Replaces any existing extras values with those from the provided Bundle.
1916 * Use {@link #addExtras} to merge in metadata instead.
1917 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001918 * @see Notification#extras
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001919 */
Griff Hazen959591e2014-05-15 22:26:18 -07001920 public Builder setExtras(Bundle extras) {
1921 mExtras = extras;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001922 return this;
1923 }
1924
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001925 /**
Griff Hazen720042b2014-02-24 15:46:56 -08001926 * Get the current metadata Bundle used by this notification Builder.
1927 *
1928 * <p>The returned Bundle is shared with this Builder.
1929 *
1930 * <p>The current contents of this Bundle are copied into the Notification each time
1931 * {@link #build()} is called.
1932 *
1933 * @see Notification#extras
1934 */
1935 public Bundle getExtras() {
1936 if (mExtras == null) {
1937 mExtras = new Bundle();
1938 }
1939 return mExtras;
1940 }
1941
1942 /**
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001943 * Add an action to this notification. Actions are typically displayed by
1944 * the system as a button adjacent to the notification content.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04001945 * <p>
1946 * Every action must have an icon (32dp square and matching the
1947 * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo
1948 * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}.
1949 * <p>
1950 * A notification in its expanded form can display up to 3 actions, from left to right in
1951 * the order they were added. Actions will not be displayed when the notification is
1952 * collapsed, however, so be sure that any essential functions may be accessed by the user
1953 * in some other way (for example, in the Activity pointed to by {@link #contentIntent}).
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001954 *
1955 * @param icon Resource ID of a drawable that represents the action.
1956 * @param title Text describing the action.
1957 * @param intent PendingIntent to be fired when the action is invoked.
1958 */
1959 public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001960 mActions.add(new Action(icon, safeCharSequence(title), intent));
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001961 return this;
1962 }
1963
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001964 /**
Griff Hazen959591e2014-05-15 22:26:18 -07001965 * Add an action to this notification. Actions are typically displayed by
1966 * the system as a button adjacent to the notification content.
1967 * <p>
1968 * Every action must have an icon (32dp square and matching the
1969 * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo
1970 * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}.
1971 * <p>
1972 * A notification in its expanded form can display up to 3 actions, from left to right in
1973 * the order they were added. Actions will not be displayed when the notification is
1974 * collapsed, however, so be sure that any essential functions may be accessed by the user
1975 * in some other way (for example, in the Activity pointed to by {@link #contentIntent}).
1976 *
1977 * @param action The action to add.
1978 */
1979 public Builder addAction(Action action) {
1980 mActions.add(action);
1981 return this;
1982 }
1983
1984 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001985 * Add a rich notification style to be applied at build time.
1986 *
1987 * @param style Object responsible for modifying the notification style.
1988 */
1989 public Builder setStyle(Style style) {
1990 if (mStyle != style) {
1991 mStyle = style;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07001992 if (mStyle != null) {
1993 mStyle.setBuilder(this);
1994 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04001995 }
1996 return this;
1997 }
1998
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001999 /**
2000 * Apply an extender to this notification builder. Extenders may be used to add
2001 * metadata or change options on this builder.
2002 */
2003 public Builder apply(Extender extender) {
2004 extender.applyTo(this);
2005 return this;
2006 }
2007
2008 /**
2009 * Extender interface for use with {@link #apply}. Extenders may be used to add
2010 * metadata or change options on this builder.
2011 */
2012 public interface Extender {
2013 /**
2014 * Apply this extender to a notification builder.
2015 * @param builder the builder to be modified.
2016 * @return the build object for chaining.
2017 */
2018 public Builder applyTo(Builder builder);
2019 }
2020
Joe Onorato46439ce2010-11-19 13:56:21 -08002021 private void setFlag(int mask, boolean value) {
2022 if (value) {
2023 mFlags |= mask;
2024 } else {
2025 mFlags &= ~mask;
2026 }
2027 }
2028
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002029 private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
Joe Onorato561d3852010-11-20 18:09:34 -08002030 RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002031 boolean showLine3 = false;
2032 boolean showLine2 = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002033 int smallIconImageViewId = R.id.icon;
2034 if (mLargeIcon != null) {
2035 contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
2036 smallIconImageViewId = R.id.right_icon;
2037 }
Daniel Sandlere95658c2012-05-10 00:33:54 -04002038 if (mPriority < PRIORITY_LOW) {
2039 contentView.setInt(R.id.icon,
2040 "setBackgroundResource", R.drawable.notification_template_icon_low_bg);
2041 contentView.setInt(R.id.status_bar_latest_event_content,
2042 "setBackgroundResource", R.drawable.notification_bg_low);
2043 }
Joe Onorato561d3852010-11-20 18:09:34 -08002044 if (mSmallIcon != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002045 contentView.setImageViewResource(smallIconImageViewId, mSmallIcon);
2046 contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE);
Jeff Sharkey1c400132011-08-05 14:50:13 -07002047 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002048 contentView.setViewVisibility(smallIconImageViewId, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08002049 }
2050 if (mContentTitle != null) {
2051 contentView.setTextViewText(R.id.title, mContentTitle);
2052 }
2053 if (mContentText != null) {
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002054 contentView.setTextViewText(R.id.text, mContentText);
2055 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08002056 }
2057 if (mContentInfo != null) {
2058 contentView.setTextViewText(R.id.info, mContentInfo);
Jeff Sharkey1c400132011-08-05 14:50:13 -07002059 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002060 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08002061 } else if (mNumber > 0) {
Daniel Sandlerebce0112011-06-16 16:44:51 -04002062 final int tooBig = mContext.getResources().getInteger(
2063 R.integer.status_bar_notification_info_maxnum);
2064 if (mNumber > tooBig) {
2065 contentView.setTextViewText(R.id.info, mContext.getResources().getString(
2066 R.string.status_bar_notification_info_overflow));
Joe Onorato059a2f82011-01-04 10:27:01 -08002067 } else {
2068 NumberFormat f = NumberFormat.getIntegerInstance();
2069 contentView.setTextViewText(R.id.info, f.format(mNumber));
2070 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07002071 contentView.setViewVisibility(R.id.info, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002072 showLine3 = true;
Joe Onorato561d3852010-11-20 18:09:34 -08002073 } else {
2074 contentView.setViewVisibility(R.id.info, View.GONE);
2075 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002076
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002077 // Need to show three lines?
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002078 if (mSubText != null) {
2079 contentView.setTextViewText(R.id.text, mSubText);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002080 if (mContentText != null) {
2081 contentView.setTextViewText(R.id.text2, mContentText);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002082 contentView.setViewVisibility(R.id.text2, View.VISIBLE);
2083 showLine2 = true;
2084 } else {
2085 contentView.setViewVisibility(R.id.text2, View.GONE);
2086 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07002087 } else {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002088 contentView.setViewVisibility(R.id.text2, View.GONE);
2089 if (mProgressMax != 0 || mProgressIndeterminate) {
2090 contentView.setProgressBar(
2091 R.id.progress, mProgressMax, mProgress, mProgressIndeterminate);
2092 contentView.setViewVisibility(R.id.progress, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002093 showLine2 = true;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002094 } else {
2095 contentView.setViewVisibility(R.id.progress, View.GONE);
2096 }
Jeff Sharkey1c400132011-08-05 14:50:13 -07002097 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002098 if (showLine2) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002099 if (fitIn1U) {
2100 // need to shrink all the type to make sure everything fits
2101 final Resources res = mContext.getResources();
2102 final float subTextSize = res.getDimensionPixelSize(
2103 R.dimen.notification_subtext_size);
2104 contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize);
2105 }
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002106 // vertical centering
2107 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
2108 }
2109
Daniel Sandler0c890492012-09-12 17:23:10 -07002110 if (mWhen != 0 && mShowWhen) {
Daniel Sandlera2985ed2012-04-03 16:42:00 -04002111 if (mUseChronometer) {
2112 contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
2113 contentView.setLong(R.id.chronometer, "setBase",
2114 mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
2115 contentView.setBoolean(R.id.chronometer, "setStarted", true);
2116 } else {
2117 contentView.setViewVisibility(R.id.time, View.VISIBLE);
2118 contentView.setLong(R.id.time, "setTime", mWhen);
2119 }
Daniel Sandler0c890492012-09-12 17:23:10 -07002120 } else {
2121 contentView.setViewVisibility(R.id.time, View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08002122 }
Daniel Sandler0c890492012-09-12 17:23:10 -07002123
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002124 contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002125 contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE);
Joe Onorato561d3852010-11-20 18:09:34 -08002126 return contentView;
2127 }
2128
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002129 private RemoteViews applyStandardTemplateWithActions(int layoutId) {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002130 RemoteViews big = applyStandardTemplate(layoutId, false);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002131
2132 int N = mActions.size();
2133 if (N > 0) {
Chris Wrend6297db2012-05-03 16:20:13 -04002134 // Log.d("Notification", "has actions: " + mContentText);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002135 big.setViewVisibility(R.id.actions, View.VISIBLE);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002136 big.setViewVisibility(R.id.action_divider, View.VISIBLE);
Daniel Sandler8680bf82012-05-15 16:52:52 -04002137 if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS;
Chris Wren2c22eb02012-05-08 09:49:13 -04002138 big.removeAllViews(R.id.actions);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002139 for (int i=0; i<N; i++) {
2140 final RemoteViews button = generateActionButton(mActions.get(i));
Chris Wrend6297db2012-05-03 16:20:13 -04002141 //Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002142 big.addView(R.id.actions, button);
2143 }
2144 }
2145 return big;
2146 }
2147
Joe Onorato46439ce2010-11-19 13:56:21 -08002148 private RemoteViews makeContentView() {
2149 if (mContentView != null) {
2150 return mContentView;
2151 } else {
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002152 return applyStandardTemplate(R.layout.notification_template_base, true); // no more special large_icon flavor
Joe Onorato46439ce2010-11-19 13:56:21 -08002153 }
2154 }
2155
2156 private RemoteViews makeTickerView() {
2157 if (mTickerView != null) {
2158 return mTickerView;
2159 } else {
Joe Onorato561d3852010-11-20 18:09:34 -08002160 if (mContentView == null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002161 return applyStandardTemplate(mLargeIcon == null
Joe Onorato561d3852010-11-20 18:09:34 -08002162 ? R.layout.status_bar_latest_event_ticker
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002163 : R.layout.status_bar_latest_event_ticker_large_icon, true);
Joe Onorato561d3852010-11-20 18:09:34 -08002164 } else {
2165 return null;
2166 }
Joe Onorato46439ce2010-11-19 13:56:21 -08002167 }
2168 }
2169
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002170 private RemoteViews makeBigContentView() {
2171 if (mActions.size() == 0) return null;
2172
Chris Wrenb023bf82012-04-23 16:05:42 -04002173 return applyStandardTemplateWithActions(R.layout.notification_template_big_base);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002174 }
2175
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002176 private RemoteViews generateActionButton(Action action) {
Daniel Sandler8680bf82012-05-15 16:52:52 -04002177 final boolean tombstone = (action.actionIntent == null);
Joe Malin8d40d042012-11-05 11:36:40 -08002178 RemoteViews button = new RemoteViews(mContext.getPackageName(),
Daniel Sandler8680bf82012-05-15 16:52:52 -04002179 tombstone ? R.layout.notification_action_tombstone
2180 : R.layout.notification_action);
Chris Wrenbe63a952013-12-03 14:31:01 -05002181 button.setTextViewCompoundDrawablesRelative(R.id.action0, action.icon, 0, 0, 0);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002182 button.setTextViewText(R.id.action0, action.title);
Daniel Sandler8680bf82012-05-15 16:52:52 -04002183 if (!tombstone) {
Daniel Sandlere5518842012-05-10 16:20:40 -04002184 button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
Daniel Sandlere5518842012-05-10 16:20:40 -04002185 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002186 button.setContentDescription(R.id.action0, action.title);
2187 return button;
2188 }
2189
Joe Onoratocb109a02011-01-18 17:57:41 -08002190 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002191 * Apply the unstyled operations and return a new {@link Notification} object.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002192 * @hide
Joe Onoratocb109a02011-01-18 17:57:41 -08002193 */
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002194 public Notification buildUnstyled() {
Joe Onorato46439ce2010-11-19 13:56:21 -08002195 Notification n = new Notification();
2196 n.when = mWhen;
2197 n.icon = mSmallIcon;
2198 n.iconLevel = mSmallIconLevel;
Joe Onorato8595a3d2010-11-19 18:12:07 -08002199 n.number = mNumber;
Joe Onorato46439ce2010-11-19 13:56:21 -08002200 n.contentView = makeContentView();
2201 n.contentIntent = mContentIntent;
2202 n.deleteIntent = mDeleteIntent;
2203 n.fullScreenIntent = mFullScreenIntent;
2204 n.tickerText = mTickerText;
2205 n.tickerView = makeTickerView();
2206 n.largeIcon = mLargeIcon;
2207 n.sound = mSound;
2208 n.audioStreamType = mAudioStreamType;
2209 n.vibrate = mVibrate;
2210 n.ledARGB = mLedArgb;
2211 n.ledOnMS = mLedOnMs;
2212 n.ledOffMS = mLedOffMs;
2213 n.defaults = mDefaults;
2214 n.flags = mFlags;
Daniel Sandler96fd7c12012-03-30 16:37:36 -04002215 n.bigContentView = makeBigContentView();
Daniel Sandler26c13432013-04-04 11:01:04 -04002216 if (mLedOnMs != 0 || mLedOffMs != 0) {
Joe Onorato8d0b6552010-11-22 16:09:29 -08002217 n.flags |= FLAG_SHOW_LIGHTS;
2218 }
2219 if ((mDefaults & DEFAULT_LIGHTS) != 0) {
2220 n.flags |= FLAG_SHOW_LIGHTS;
2221 }
John Spurlockcf44a122014-03-24 11:02:36 -04002222 n.category = mCategory;
Griff Hazen5cadc3b2014-05-20 09:55:39 -07002223 n.mGroupKey = mGroupKey;
2224 n.mSortKey = mSortKey;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002225 n.priority = mPriority;
Daniel Sandlera0a938c2012-03-15 08:42:37 -04002226 if (mActions.size() > 0) {
2227 n.actions = new Action[mActions.size()];
2228 mActions.toArray(n.actions);
2229 }
Joe Onorato46439ce2010-11-19 13:56:21 -08002230 return n;
2231 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002232
2233 /**
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002234 * Capture, in the provided bundle, semantic information used in the construction of
2235 * this Notification object.
2236 * @hide
2237 */
Griff Hazen720042b2014-02-24 15:46:56 -08002238 public void populateExtras(Bundle extras) {
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002239 // Store original information used in the construction of this object
2240 extras.putCharSequence(EXTRA_TITLE, mContentTitle);
2241 extras.putCharSequence(EXTRA_TEXT, mContentText);
2242 extras.putCharSequence(EXTRA_SUB_TEXT, mSubText);
2243 extras.putCharSequence(EXTRA_INFO_TEXT, mContentInfo);
2244 extras.putInt(EXTRA_SMALL_ICON, mSmallIcon);
2245 extras.putInt(EXTRA_PROGRESS, mProgress);
2246 extras.putInt(EXTRA_PROGRESS_MAX, mProgressMax);
2247 extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mProgressIndeterminate);
2248 extras.putBoolean(EXTRA_SHOW_CHRONOMETER, mUseChronometer);
2249 extras.putBoolean(EXTRA_SHOW_WHEN, mShowWhen);
John Spurlockac08a472013-06-10 11:37:08 -04002250 if (mLargeIcon != null) {
2251 extras.putParcelable(EXTRA_LARGE_ICON, mLargeIcon);
2252 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002253 }
2254
2255 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002256 * @deprecated Use {@link #build()} instead.
2257 */
2258 @Deprecated
2259 public Notification getNotification() {
2260 return build();
2261 }
2262
2263 /**
2264 * Combine all of the options that have been set and return a new {@link Notification}
2265 * object.
2266 */
2267 public Notification build() {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002268 Notification n = buildUnstyled();
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002269
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002270 if (mStyle != null) {
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002271 n = mStyle.buildStyled(n);
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002272 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002273
2274 n.extras = mExtras != null ? new Bundle(mExtras) : new Bundle();
2275
Griff Hazen720042b2014-02-24 15:46:56 -08002276 populateExtras(n.extras);
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002277 if (mStyle != null) {
2278 mStyle.addExtras(n.extras);
2279 }
2280
2281 return n;
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002282 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002283
2284 /**
2285 * Apply this Builder to an existing {@link Notification} object.
2286 *
2287 * @hide
2288 */
2289 public Notification buildInto(Notification n) {
Daniel Sandler1a497d32013-04-18 14:52:45 -04002290 build().cloneInto(n, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002291 return n;
2292 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002293 }
2294
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002295 /**
2296 * An object that can apply a rich notification style to a {@link Notification.Builder}
2297 * object.
2298 */
Griff Hazendfcb0802014-02-11 12:00:00 -08002299 public static abstract class Style {
Chris Wrend6297db2012-05-03 16:20:13 -04002300 private CharSequence mBigContentTitle;
2301 private CharSequence mSummaryText = null;
Daniel Sandler619738c2012-06-07 16:33:08 -04002302 private boolean mSummaryTextSet = false;
Chris Wrend6297db2012-05-03 16:20:13 -04002303
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002304 protected Builder mBuilder;
2305
Chris Wrend6297db2012-05-03 16:20:13 -04002306 /**
2307 * Overrides ContentTitle in the big form of the template.
2308 * This defaults to the value passed to setContentTitle().
2309 */
2310 protected void internalSetBigContentTitle(CharSequence title) {
2311 mBigContentTitle = title;
2312 }
2313
2314 /**
2315 * Set the first line of text after the detail section in the big form of the template.
2316 */
2317 protected void internalSetSummaryText(CharSequence cs) {
2318 mSummaryText = cs;
Daniel Sandler619738c2012-06-07 16:33:08 -04002319 mSummaryTextSet = true;
Chris Wrend6297db2012-05-03 16:20:13 -04002320 }
2321
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002322 public void setBuilder(Builder builder) {
2323 if (mBuilder != builder) {
2324 mBuilder = builder;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07002325 if (mBuilder != null) {
2326 mBuilder.setStyle(this);
2327 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002328 }
2329 }
2330
Chris Wrend6297db2012-05-03 16:20:13 -04002331 protected void checkBuilder() {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002332 if (mBuilder == null) {
2333 throw new IllegalArgumentException("Style requires a valid Builder object");
2334 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002335 }
Chris Wrend6297db2012-05-03 16:20:13 -04002336
2337 protected RemoteViews getStandardView(int layoutId) {
2338 checkBuilder();
2339
2340 if (mBigContentTitle != null) {
2341 mBuilder.setContentTitle(mBigContentTitle);
2342 }
2343
Chris Wrend6297db2012-05-03 16:20:13 -04002344 RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId);
2345
Chris Wrend6297db2012-05-03 16:20:13 -04002346 if (mBigContentTitle != null && mBigContentTitle.equals("")) {
2347 contentView.setViewVisibility(R.id.line1, View.GONE);
Chris Wren67dc9a02012-05-16 01:03:20 -04002348 } else {
2349 contentView.setViewVisibility(R.id.line1, View.VISIBLE);
Chris Wrend6297db2012-05-03 16:20:13 -04002350 }
2351
Daniel Sandler619738c2012-06-07 16:33:08 -04002352 // The last line defaults to the subtext, but can be replaced by mSummaryText
2353 final CharSequence overflowText =
2354 mSummaryTextSet ? mSummaryText
2355 : mBuilder.mSubText;
2356 if (overflowText != null) {
2357 contentView.setTextViewText(R.id.text, overflowText);
2358 contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE);
Daniel Sandler9f7936a2012-05-21 16:14:28 -04002359 contentView.setViewVisibility(R.id.line3, View.VISIBLE);
Daniel Sandler916ad912012-06-13 12:17:07 -04002360 } else {
2361 contentView.setViewVisibility(R.id.overflow_divider, View.GONE);
2362 contentView.setViewVisibility(R.id.line3, View.GONE);
Chris Wrend6297db2012-05-03 16:20:13 -04002363 }
2364
2365 return contentView;
2366 }
2367
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002368 /**
2369 * @hide
2370 */
2371 public void addExtras(Bundle extras) {
2372 if (mSummaryTextSet) {
2373 extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText);
2374 }
2375 if (mBigContentTitle != null) {
2376 extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle);
2377 }
2378 }
2379
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002380 /**
2381 * @hide
2382 */
2383 public abstract Notification buildStyled(Notification wip);
2384
2385 /**
2386 * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is
2387 * attached to.
2388 *
2389 * @return the fully constructed Notification.
2390 */
2391 public Notification build() {
2392 checkBuilder();
2393 return mBuilder.build();
2394 }
Joe Onorato46439ce2010-11-19 13:56:21 -08002395 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002396
2397 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002398 * Helper class for generating large-format notifications that include a large image attachment.
Joe Malin8d40d042012-11-05 11:36:40 -08002399 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002400 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002401 * <pre class="prettyprint">
2402 * Notification noti = new Notification.BigPictureStyle(
2403 * new Notification.Builder()
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002404 * .setContentTitle(&quot;New photo from &quot; + sender.toString())
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002405 * .setContentText(subject)
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002406 * .setSmallIcon(R.drawable.new_post)
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002407 * .setLargeIcon(aBitmap))
2408 * .bigPicture(aBigBitmap)
2409 * .build();
2410 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002411 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002412 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002413 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002414 public static class BigPictureStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002415 private Bitmap mPicture;
Chris Wren3745a3d2012-05-22 15:11:52 -04002416 private Bitmap mBigLargeIcon;
2417 private boolean mBigLargeIconSet = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002418
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002419 public BigPictureStyle() {
2420 }
2421
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002422 public BigPictureStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002423 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002424 }
2425
Chris Wrend6297db2012-05-03 16:20:13 -04002426 /**
2427 * Overrides ContentTitle in the big form of the template.
2428 * This defaults to the value passed to setContentTitle().
2429 */
2430 public BigPictureStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002431 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002432 return this;
2433 }
2434
2435 /**
2436 * Set the first line of text after the detail section in the big form of the template.
2437 */
2438 public BigPictureStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002439 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002440 return this;
2441 }
2442
Chris Wren0bd664d2012-08-01 13:56:56 -04002443 /**
2444 * Provide the bitmap to be used as the payload for the BigPicture notification.
2445 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002446 public BigPictureStyle bigPicture(Bitmap b) {
2447 mPicture = b;
2448 return this;
2449 }
2450
Chris Wren3745a3d2012-05-22 15:11:52 -04002451 /**
Chris Wren3745a3d2012-05-22 15:11:52 -04002452 * Override the large icon when the big notification is shown.
2453 */
2454 public BigPictureStyle bigLargeIcon(Bitmap b) {
2455 mBigLargeIconSet = true;
2456 mBigLargeIcon = b;
2457 return this;
2458 }
2459
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002460 private RemoteViews makeBigContentView() {
Chris Wrend6297db2012-05-03 16:20:13 -04002461 RemoteViews contentView = getStandardView(R.layout.notification_template_big_picture);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002462
2463 contentView.setImageViewBitmap(R.id.big_picture, mPicture);
2464
2465 return contentView;
2466 }
2467
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002468 /**
2469 * @hide
2470 */
2471 public void addExtras(Bundle extras) {
2472 super.addExtras(extras);
2473
2474 if (mBigLargeIconSet) {
2475 extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon);
2476 }
2477 extras.putParcelable(EXTRA_PICTURE, mPicture);
2478 }
2479
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002480 /**
2481 * @hide
2482 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002483 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002484 public Notification buildStyled(Notification wip) {
Chris Wren3745a3d2012-05-22 15:11:52 -04002485 if (mBigLargeIconSet ) {
2486 mBuilder.mLargeIcon = mBigLargeIcon;
2487 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002488 wip.bigContentView = makeBigContentView();
2489 return wip;
2490 }
2491 }
2492
2493 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002494 * Helper class for generating large-format notifications that include a lot of text.
Joe Malin8d40d042012-11-05 11:36:40 -08002495 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002496 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002497 * <pre class="prettyprint">
Daniel Sandler87682782012-11-07 14:04:42 -05002498 * Notification noti = new Notification.BigTextStyle(
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002499 * new Notification.Builder()
2500 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
2501 * .setContentText(subject)
2502 * .setSmallIcon(R.drawable.new_mail)
2503 * .setLargeIcon(aBitmap))
2504 * .bigText(aVeryLongString)
2505 * .build();
2506 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002507 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04002508 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002509 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002510 public static class BigTextStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002511 private CharSequence mBigText;
2512
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002513 public BigTextStyle() {
2514 }
2515
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002516 public BigTextStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002517 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002518 }
2519
Chris Wrend6297db2012-05-03 16:20:13 -04002520 /**
2521 * Overrides ContentTitle in the big form of the template.
2522 * This defaults to the value passed to setContentTitle().
2523 */
2524 public BigTextStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002525 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002526 return this;
2527 }
2528
2529 /**
2530 * Set the first line of text after the detail section in the big form of the template.
2531 */
2532 public BigTextStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002533 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002534 return this;
2535 }
2536
Chris Wren0bd664d2012-08-01 13:56:56 -04002537 /**
2538 * Provide the longer text to be displayed in the big form of the
2539 * template in place of the content text.
2540 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002541 public BigTextStyle bigText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002542 mBigText = safeCharSequence(cs);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002543 return this;
2544 }
2545
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002546 /**
2547 * @hide
2548 */
2549 public void addExtras(Bundle extras) {
2550 super.addExtras(extras);
2551
2552 extras.putCharSequence(EXTRA_TEXT, mBigText);
2553 }
2554
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002555 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04002556 // Remove the content text so line3 only shows if you have a summary
2557 final boolean hadThreeLines = (mBuilder.mContentText != null && mBuilder.mSubText != null);
Daniel Sandler6387d2f2012-05-22 13:44:09 -04002558 mBuilder.mContentText = null;
Daniel Sandler916ad912012-06-13 12:17:07 -04002559
Chris Wrend6297db2012-05-03 16:20:13 -04002560 RemoteViews contentView = getStandardView(R.layout.notification_template_big_text);
Joe Malin8d40d042012-11-05 11:36:40 -08002561
Daniel Sandler619738c2012-06-07 16:33:08 -04002562 if (hadThreeLines) {
2563 // vertical centering
2564 contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
2565 }
2566
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002567 contentView.setTextViewText(R.id.big_text, mBigText);
2568 contentView.setViewVisibility(R.id.big_text, View.VISIBLE);
Chris Wren3c5f92432012-05-04 16:31:17 -04002569 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002570
2571 return contentView;
2572 }
2573
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002574 /**
2575 * @hide
2576 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002577 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002578 public Notification buildStyled(Notification wip) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002579 wip.bigContentView = makeBigContentView();
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002580
2581 wip.extras.putCharSequence(EXTRA_TEXT, mBigText);
2582
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002583 return wip;
2584 }
2585 }
Daniel Sandler879c5e02012-04-17 16:46:51 -04002586
2587 /**
2588 * Helper class for generating large-format notifications that include a list of (up to 5) strings.
Joe Malin8d40d042012-11-05 11:36:40 -08002589 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04002590 * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
2591 * <pre class="prettyprint">
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002592 * Notification noti = new Notification.InboxStyle(
Daniel Sandler879c5e02012-04-17 16:46:51 -04002593 * new Notification.Builder()
Chris Wrend6297db2012-05-03 16:20:13 -04002594 * .setContentTitle(&quot;5 New mails from &quot; + sender.toString())
Daniel Sandler879c5e02012-04-17 16:46:51 -04002595 * .setContentText(subject)
2596 * .setSmallIcon(R.drawable.new_mail)
2597 * .setLargeIcon(aBitmap))
2598 * .addLine(str1)
2599 * .addLine(str2)
Chris Wrend6297db2012-05-03 16:20:13 -04002600 * .setContentTitle("")
2601 * .setSummaryText(&quot;+3 more&quot;)
Daniel Sandler879c5e02012-04-17 16:46:51 -04002602 * .build();
2603 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08002604 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04002605 * @see Notification#bigContentView
2606 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002607 public static class InboxStyle extends Style {
Daniel Sandler879c5e02012-04-17 16:46:51 -04002608 private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5);
2609
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002610 public InboxStyle() {
2611 }
2612
Daniel Sandler879c5e02012-04-17 16:46:51 -04002613 public InboxStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002614 setBuilder(builder);
Daniel Sandler879c5e02012-04-17 16:46:51 -04002615 }
2616
Chris Wrend6297db2012-05-03 16:20:13 -04002617 /**
2618 * Overrides ContentTitle in the big form of the template.
2619 * This defaults to the value passed to setContentTitle().
2620 */
2621 public InboxStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002622 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04002623 return this;
2624 }
2625
2626 /**
2627 * Set the first line of text after the detail section in the big form of the template.
2628 */
2629 public InboxStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002630 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04002631 return this;
2632 }
2633
Chris Wren0bd664d2012-08-01 13:56:56 -04002634 /**
2635 * Append a line to the digest section of the Inbox notification.
2636 */
Daniel Sandler879c5e02012-04-17 16:46:51 -04002637 public InboxStyle addLine(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002638 mTexts.add(safeCharSequence(cs));
Daniel Sandler879c5e02012-04-17 16:46:51 -04002639 return this;
2640 }
2641
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002642 /**
2643 * @hide
2644 */
2645 public void addExtras(Bundle extras) {
2646 super.addExtras(extras);
2647 CharSequence[] a = new CharSequence[mTexts.size()];
2648 extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a));
2649 }
2650
Daniel Sandler879c5e02012-04-17 16:46:51 -04002651 private RemoteViews makeBigContentView() {
Daniel Sandler619738c2012-06-07 16:33:08 -04002652 // Remove the content text so line3 disappears unless you have a summary
2653 mBuilder.mContentText = null;
Chris Wrend6297db2012-05-03 16:20:13 -04002654 RemoteViews contentView = getStandardView(R.layout.notification_template_inbox);
Daniel Sandler619738c2012-06-07 16:33:08 -04002655
Chris Wrend6297db2012-05-03 16:20:13 -04002656 contentView.setViewVisibility(R.id.text2, View.GONE);
Daniel Sandler879c5e02012-04-17 16:46:51 -04002657
Chris Wrend6297db2012-05-03 16:20:13 -04002658 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 -04002659 R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6};
Chris Wrend6297db2012-05-03 16:20:13 -04002660
Chris Wren4ed80d52012-05-17 09:30:03 -04002661 // Make sure all rows are gone in case we reuse a view.
2662 for (int rowId : rowIds) {
2663 contentView.setViewVisibility(rowId, View.GONE);
2664 }
2665
Chris Wren683ab002012-09-20 10:35:54 -04002666
Daniel Sandler879c5e02012-04-17 16:46:51 -04002667 int i=0;
2668 while (i < mTexts.size() && i < rowIds.length) {
2669 CharSequence str = mTexts.get(i);
2670 if (str != null && !str.equals("")) {
2671 contentView.setViewVisibility(rowIds[i], View.VISIBLE);
2672 contentView.setTextViewText(rowIds[i], str);
2673 }
2674 i++;
2675 }
2676
Chris Wren683ab002012-09-20 10:35:54 -04002677 contentView.setViewVisibility(R.id.inbox_end_pad,
2678 mTexts.size() > 0 ? View.VISIBLE : View.GONE);
2679
2680 contentView.setViewVisibility(R.id.inbox_more,
2681 mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE);
Chris Wren29bb6d92012-05-17 18:09:42 -04002682
Daniel Sandler879c5e02012-04-17 16:46:51 -04002683 return contentView;
2684 }
2685
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002686 /**
2687 * @hide
2688 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002689 @Override
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002690 public Notification buildStyled(Notification wip) {
Daniel Sandler879c5e02012-04-17 16:46:51 -04002691 wip.bigContentView = makeBigContentView();
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05002692
Daniel Sandler879c5e02012-04-17 16:46:51 -04002693 return wip;
2694 }
2695 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696}