blob: 88c89648f52e3f241249198bc81700cb21872ce7 [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
Tor Norbye80756e32015-03-02 09:39:27 -080019import android.annotation.ColorInt;
Tor Norbye7b9c9122013-05-30 16:48:33 -070020import android.annotation.DrawableRes;
Tor Norbyed9273d62013-05-30 15:59:53 -070021import android.annotation.IntDef;
Daniel Sandler01df1c62014-06-09 10:54:01 -040022import android.annotation.SdkConstant;
23import android.annotation.SdkConstant.SdkConstantType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.Context;
25import android.content.Intent;
Kenny Guy77320062014-08-27 21:37:15 +010026import android.content.pm.ApplicationInfo;
Selim Cinek65b2e7c2015-10-26 14:11:31 -070027import android.content.pm.PackageManager;
Christoph Studer4600f9b2014-07-22 22:44:43 +020028import android.content.pm.PackageManager.NameNotFoundException;
Jorim Jaggief72a192014-08-26 21:57:46 +020029import android.content.res.ColorStateList;
Joe Onoratoef1e7762010-09-17 18:38:38 -040030import android.graphics.Bitmap;
Kenny Guy8a0101b2014-05-08 23:34:12 +010031import android.graphics.Canvas;
Jorim Jaggi5c2d8462014-03-21 17:37:00 +010032import android.graphics.PorterDuff;
Kenny Guy8a0101b2014-05-08 23:34:12 +010033import android.graphics.drawable.Drawable;
Dan Sandlerd63f9322015-05-06 15:18:49 -040034import android.graphics.drawable.Icon;
John Spurlockc0650f022014-07-19 13:22:39 -040035import android.media.AudioAttributes;
Jeff Sharkey098d5802012-04-26 17:30:34 -070036import android.media.AudioManager;
Jeff Browndba34ba2014-06-24 20:46:03 -070037import android.media.session.MediaSession;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.net.Uri;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040039import android.os.BadParcelableException;
Christoph Studer239f8352014-08-25 15:13:18 +020040import android.os.Build;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050041import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.os.Parcel;
43import android.os.Parcelable;
Daniel Sandlera2985ed2012-04-03 16:42:00 -040044import android.os.SystemClock;
Jeff Sharkey6d515712012-09-20 16:06:08 -070045import android.os.UserHandle;
Selim Cinek60a54252016-02-26 17:03:25 -080046import android.text.SpannableStringBuilder;
47import android.text.Spanned;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.text.TextUtils;
Selim Cinek60a54252016-02-26 17:03:25 -080049import android.text.style.AbsoluteSizeSpan;
Selim Cinek89991a22016-03-07 19:51:54 -080050import android.text.style.CharacterStyle;
Selim Cinek60a54252016-02-26 17:03:25 -080051import android.text.style.RelativeSizeSpan;
52import android.text.style.TextAppearanceSpan;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040053import android.util.Log;
Dan Sandler50128532015-12-08 15:42:41 -050054import android.util.SparseArray;
Daniel Sandler9f7936a2012-05-21 16:14:28 -040055import android.util.TypedValue;
Griff Hazen61a9e862014-05-22 16:05:19 -070056import android.view.Gravity;
Selim Cinekea4bef72015-12-02 15:51:10 -080057import android.view.NotificationHeaderView;
Joe Onorato8595a3d2010-11-19 18:12:07 -080058import android.view.View;
Adrian Roos9b123cf2016-02-04 14:55:57 -080059import android.view.ViewGroup;
Jeff Sharkey1c400132011-08-05 14:50:13 -070060import android.widget.ProgressBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.widget.RemoteViews;
62
Griff Hazen959591e2014-05-15 22:26:18 -070063import com.android.internal.R;
Griff Hazenc091ba82014-05-16 10:13:26 -070064import com.android.internal.util.NotificationColorUtil;
Griff Hazen959591e2014-05-15 22:26:18 -070065
Tor Norbyed9273d62013-05-30 15:59:53 -070066import java.lang.annotation.Retention;
67import java.lang.annotation.RetentionPolicy;
Christoph Studer4600f9b2014-07-22 22:44:43 +020068import java.lang.reflect.Constructor;
Daniel Sandler2561b0b2012-02-13 21:04:12 -050069import java.util.ArrayList;
Griff Hazen61a9e862014-05-22 16:05:19 -070070import java.util.Arrays;
Griff Hazen5cadc3b2014-05-20 09:55:39 -070071import java.util.Collections;
Griff Hazen61a9e862014-05-22 16:05:19 -070072import java.util.List;
Dan Sandler50128532015-12-08 15:42:41 -050073import java.util.Set;
Joe Onorato561d3852010-11-20 18:09:34 -080074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075/**
76 * A class that represents how a persistent notification is to be presented to
77 * the user using the {@link android.app.NotificationManager}.
78 *
Joe Onoratocb109a02011-01-18 17:57:41 -080079 * <p>The {@link Notification.Builder Notification.Builder} has been added to make it
80 * easier to construct Notifications.</p>
81 *
Joe Fernandez558459f2011-10-13 16:47:36 -070082 * <div class="special reference">
83 * <h3>Developer Guides</h3>
84 * <p>For a guide to creating notifications, read the
85 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a>
86 * developer guide.</p>
87 * </div>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 */
89public class Notification implements Parcelable
90{
Daniel Sandlerdcbaf662013-04-26 16:23:09 -040091 private static final String TAG = "Notification";
92
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 /**
Daniel Sandler01df1c62014-06-09 10:54:01 -040094 * An activity that provides a user interface for adjusting notification preferences for its
95 * containing application. Optional but recommended for apps that post
96 * {@link android.app.Notification Notifications}.
97 */
98 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
99 public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES
100 = "android.intent.category.NOTIFICATION_PREFERENCES";
101
102 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 * Use all default values (where applicable).
104 */
105 public static final int DEFAULT_ALL = ~0;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 /**
108 * Use the default notification sound. This will ignore any given
109 * {@link #sound}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500110 *
Chris Wren47c20a12014-06-18 17:27:29 -0400111 * <p>
112 * A notification that is noisy is more likely to be presented as a heads-up notification.
113 * </p>
114 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500116 */
117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 public static final int DEFAULT_SOUND = 1;
119
120 /**
121 * Use the default notification vibrate. This will ignore any given
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500122 * {@link #vibrate}. Using phone vibration requires the
Scott Mainb8b36452009-04-26 15:50:49 -0700123 * {@link android.Manifest.permission#VIBRATE VIBRATE} permission.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500124 *
Chris Wren47c20a12014-06-18 17:27:29 -0400125 * <p>
126 * A notification that vibrates is more likely to be presented as a heads-up notification.
127 * </p>
128 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500130 */
131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 public static final int DEFAULT_VIBRATE = 2;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 /**
135 * Use the default notification lights. This will ignore the
136 * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or
137 * {@link #ledOnMS}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500138 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 * @see #defaults
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500140 */
141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 public static final int DEFAULT_LIGHTS = 4;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 /**
Christoph Studer535ec612014-09-03 15:47:47 +0200145 * Maximum length of CharSequences accepted by Builder and friends.
146 *
147 * <p>
148 * Avoids spamming the system with overly large strings such as full e-mails.
149 */
150 private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024;
151
152 /**
Adrian Roose458aa82015-12-08 16:17:19 -0800153 * Maximum entries of reply text that are accepted by Builder and friends.
154 */
155 private static final int MAX_REPLY_HISTORY = 5;
156
157 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500158 * A timestamp related to this notification, in milliseconds since the epoch.
Joe Malin8d40d042012-11-05 11:36:40 -0800159 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500160 * Default value: {@link System#currentTimeMillis() Now}.
161 *
162 * Choose a timestamp that will be most relevant to the user. For most finite events, this
163 * corresponds to the time the event happened (or will happen, in the case of events that have
164 * yet to occur but about which the user is being informed). Indefinite events should be
Joe Malin8d40d042012-11-05 11:36:40 -0800165 * timestamped according to when the activity began.
166 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500167 * Some examples:
Joe Malin8d40d042012-11-05 11:36:40 -0800168 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500169 * <ul>
170 * <li>Notification of a new chat message should be stamped when the message was received.</li>
171 * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li>
172 * <li>Notification of a completed file download should be stamped when the download finished.</li>
173 * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li>
174 * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
175 * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time.
Joe Malin8d40d042012-11-05 11:36:40 -0800176 * </ul>
177 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 */
179 public long when;
180
181 /**
182 * The resource id of a drawable to use as the icon in the status bar.
Dan Sandler86647982015-05-13 23:41:13 -0400183 *
184 * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 */
Dan Sandler86647982015-05-13 23:41:13 -0400186 @Deprecated
Tor Norbye7b9c9122013-05-30 16:48:33 -0700187 @DrawableRes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 public int icon;
189
190 /**
Joe Onorato46439ce2010-11-19 13:56:21 -0800191 * If the icon in the status bar is to have more than one level, you can set this. Otherwise,
192 * leave it at its default value of 0.
193 *
194 * @see android.widget.ImageView#setImageLevel
Griff Hazen959591e2014-05-15 22:26:18 -0700195 * @see android.graphics.drawable.Drawable#setLevel
Joe Onorato46439ce2010-11-19 13:56:21 -0800196 */
197 public int iconLevel;
198
199 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500200 * The number of events that this notification represents. For example, in a new mail
201 * notification, this could be the number of unread messages.
Joe Malin8d40d042012-11-05 11:36:40 -0800202 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500203 * The system may or may not use this field to modify the appearance of the notification. For
204 * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was
205 * superimposed over the icon in the status bar. Starting with
206 * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by
207 * {@link Notification.Builder} has displayed the number in the expanded notification view.
Joe Malin8d40d042012-11-05 11:36:40 -0800208 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500209 * If the number is 0 or negative, it is never shown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 */
211 public int number;
212
213 /**
214 * The intent to execute when the expanded status entry is clicked. If
215 * this is an activity, it must include the
216 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -0800217 * that you take care of task management as described in the
218 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
Dianne Hackborn6ceca582012-01-10 15:24:26 -0800219 * Stack</a> document. In particular, make sure to read the notification section
220 * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling
221 * Notifications</a> for the correct ways to launch an application from a
222 * notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 */
224 public PendingIntent contentIntent;
225
226 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500227 * The intent to execute when the notification is explicitly dismissed by the user, either with
228 * the "Clear All" button or by swiping it away individually.
229 *
230 * This probably shouldn't be launching an activity since several of those will be sent
231 * at the same time.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 */
233 public PendingIntent deleteIntent;
234
235 /**
Dianne Hackborn170bae72010-09-03 15:14:28 -0700236 * An intent to launch instead of posting the notification to the status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -0800237 *
Chris Wren47c20a12014-06-18 17:27:29 -0400238 * <p>
239 * The system UI may choose to display a heads-up notification, instead of
240 * launching this intent, while the user is using the device.
241 * </p>
242 *
Joe Onoratocb109a02011-01-18 17:57:41 -0800243 * @see Notification.Builder#setFullScreenIntent
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400244 */
245 public PendingIntent fullScreenIntent;
246
247 /**
Dan Sandler5fcdf6e2014-07-18 11:31:15 -0400248 * Text that summarizes this notification for accessibility services.
249 *
250 * As of the L release, this text is no longer shown on screen, but it is still useful to
251 * accessibility services (where it serves as an audible announcement of the notification's
252 * appearance).
Joe Onoratoef1e7762010-09-17 18:38:38 -0400253 *
Joe Onorato46439ce2010-11-19 13:56:21 -0800254 * @see #tickerView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 */
256 public CharSequence tickerText;
257
258 /**
Dan Sandler5fcdf6e2014-07-18 11:31:15 -0400259 * Formerly, a view showing the {@link #tickerText}.
260 *
261 * No longer displayed in the status bar as of API 21.
Joe Onoratoef1e7762010-09-17 18:38:38 -0400262 */
Dan Sandler5fcdf6e2014-07-18 11:31:15 -0400263 @Deprecated
Joe Onorato46439ce2010-11-19 13:56:21 -0800264 public RemoteViews tickerView;
Joe Onoratoef1e7762010-09-17 18:38:38 -0400265
266 /**
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400267 * The view that will represent this notification in the notification list (which is pulled
268 * down from the status bar).
269 *
Julia Reynoldsd4ea7412016-02-17 14:00:56 -0500270 * As of N, this field may be null. The notification view is determined by the inputs
271 * to {@link Notification.Builder}; a custom RemoteViews can optionally be
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400272 * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 */
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400274 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 public RemoteViews contentView;
276
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400277 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -0400278 * A large-format version of {@link #contentView}, giving the Notification an
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400279 * opportunity to show more detail. The system UI may choose to show this
280 * instead of the normal content view at its discretion.
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400281 *
Julia Reynoldsd4ea7412016-02-17 14:00:56 -0500282 * As of N, this field may be null. The expanded notification view is determined by the
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400283 * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be
284 * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}.
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400285 */
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400286 @Deprecated
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400287 public RemoteViews bigContentView;
288
Chris Wren8fd39ec2014-02-27 17:43:26 -0500289
290 /**
Chris Wren47c20a12014-06-18 17:27:29 -0400291 * A medium-format version of {@link #contentView}, providing the Notification an
292 * opportunity to add action buttons to contentView. At its discretion, the system UI may
293 * choose to show this as a heads-up notification, which will pop up so the user can see
294 * it without leaving their current activity.
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400295 *
Julia Reynoldsd4ea7412016-02-17 14:00:56 -0500296 * As of N, this field may be null. The heads-up notification view is determined by the
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400297 * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be
298 * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}.
Chris Wren8fd39ec2014-02-27 17:43:26 -0500299 */
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400300 @Deprecated
Chris Wren8fd39ec2014-02-27 17:43:26 -0500301 public RemoteViews headsUpContentView;
302
Daniel Sandlerf3b73432012-03-27 15:01:25 -0400303 /**
Dan Sandler86647982015-05-13 23:41:13 -0400304 * A large bitmap to be shown in the notification content area.
305 *
306 * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 */
Dan Sandler86647982015-05-13 23:41:13 -0400308 @Deprecated
Joe Onorato46439ce2010-11-19 13:56:21 -0800309 public Bitmap largeIcon;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310
311 /**
312 * The sound to play.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500313 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 * <p>
Chris Wren47c20a12014-06-18 17:27:29 -0400315 * A notification that is noisy is more likely to be presented as a heads-up notification.
316 * </p>
317 *
318 * <p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500319 * To play the default notification sound, see {@link #defaults}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 * </p>
321 */
322 public Uri sound;
323
324 /**
325 * Use this constant as the value for audioStreamType to request that
326 * the default stream type for notifications be used. Currently the
Jeff Sharkey098d5802012-04-26 17:30:34 -0700327 * default stream type is {@link AudioManager#STREAM_NOTIFICATION}.
John Spurlockc0650f022014-07-19 13:22:39 -0400328 *
329 * @deprecated Use {@link #audioAttributes} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 */
Jean-Michel Trivi81f871e2014-08-06 16:32:38 -0700331 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 public static final int STREAM_DEFAULT = -1;
333
334 /**
335 * The audio stream type to use when playing the sound.
336 * Should be one of the STREAM_ constants from
337 * {@link android.media.AudioManager}.
John Spurlockc0650f022014-07-19 13:22:39 -0400338 *
339 * @deprecated Use {@link #audioAttributes} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 */
Jean-Michel Trivi81f871e2014-08-06 16:32:38 -0700341 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 public int audioStreamType = STREAM_DEFAULT;
343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 /**
John Spurlockc0650f022014-07-19 13:22:39 -0400345 * The default value of {@link #audioAttributes}.
346 */
347 public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder()
348 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
349 .setUsage(AudioAttributes.USAGE_NOTIFICATION)
350 .build();
351
352 /**
353 * The {@link AudioAttributes audio attributes} to use when playing the sound.
354 */
355 public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT;
356
357 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500358 * The pattern with which to vibrate.
359 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 * <p>
361 * To vibrate the default pattern, see {@link #defaults}.
362 * </p>
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500363 *
Chris Wren47c20a12014-06-18 17:27:29 -0400364 * <p>
365 * A notification that vibrates is more likely to be presented as a heads-up notification.
366 * </p>
367 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 * @see android.os.Vibrator#vibrate(long[],int)
369 */
370 public long[] vibrate;
371
372 /**
373 * The color of the led. The hardware will do its best approximation.
374 *
375 * @see #FLAG_SHOW_LIGHTS
376 * @see #flags
377 */
Tor Norbye80756e32015-03-02 09:39:27 -0800378 @ColorInt
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 public int ledARGB;
380
381 /**
382 * The number of milliseconds for the LED to be on while it's flashing.
383 * The hardware will do its best approximation.
384 *
385 * @see #FLAG_SHOW_LIGHTS
386 * @see #flags
387 */
388 public int ledOnMS;
389
390 /**
391 * The number of milliseconds for the LED to be off while it's flashing.
392 * The hardware will do its best approximation.
393 *
394 * @see #FLAG_SHOW_LIGHTS
395 * @see #flags
396 */
397 public int ledOffMS;
398
399 /**
400 * Specifies which values should be taken from the defaults.
401 * <p>
402 * To set, OR the desired from {@link #DEFAULT_SOUND},
403 * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default
404 * values, use {@link #DEFAULT_ALL}.
405 * </p>
406 */
407 public int defaults;
408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 /**
410 * Bit to be bitwise-ored into the {@link #flags} field that should be
411 * set if you want the LED on for this notification.
412 * <ul>
413 * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB
414 * or 0 for both ledOnMS and ledOffMS.</li>
415 * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li>
416 * <li>To flash the LED, pass the number of milliseconds that it should
417 * be on and off to ledOnMS and ledOffMS.</li>
418 * </ul>
419 * <p>
420 * Since hardware varies, you are not guaranteed that any of the values
421 * you pass are honored exactly. Use the system defaults (TODO) if possible
422 * because they will be set to values that work on any given hardware.
423 * <p>
424 * The alpha channel must be set for forward compatibility.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500425 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 */
427 public static final int FLAG_SHOW_LIGHTS = 0x00000001;
428
429 /**
430 * Bit to be bitwise-ored into the {@link #flags} field that should be
431 * set if this notification is in reference to something that is ongoing,
432 * like a phone call. It should not be set if this notification is in
433 * reference to something that happened at a particular point in time,
434 * like a missed phone call.
435 */
436 public static final int FLAG_ONGOING_EVENT = 0x00000002;
437
438 /**
439 * Bit to be bitwise-ored into the {@link #flags} field that if set,
Scott Mainb8b36452009-04-26 15:50:49 -0700440 * the audio will be repeated until the notification is
441 * cancelled or the notification window is opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 */
443 public static final int FLAG_INSISTENT = 0x00000004;
444
445 /**
446 * Bit to be bitwise-ored into the {@link #flags} field that should be
Griff Hazen293977b2014-04-28 08:37:20 -0700447 * set if you would only like the sound, vibrate and ticker to be played
448 * if the notification was not already showing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 */
450 public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008;
451
452 /**
453 * Bit to be bitwise-ored into the {@link #flags} field that should be
454 * set if the notification should be canceled when it is clicked by the
Daniel Sandler8aa9ae62012-12-04 23:31:47 -0500455 * user.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 */
457 public static final int FLAG_AUTO_CANCEL = 0x00000010;
458
459 /**
460 * Bit to be bitwise-ored into the {@link #flags} field that should be
461 * set if the notification should not be canceled when the user clicks
462 * the Clear all button.
463 */
464 public static final int FLAG_NO_CLEAR = 0x00000020;
465
Dianne Hackbornd8a43f62009-08-17 23:33:56 -0700466 /**
467 * Bit to be bitwise-ored into the {@link #flags} field that should be
468 * set if this notification represents a currently running service. This
469 * will normally be set for you by {@link Service#startForeground}.
470 */
471 public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;
472
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400473 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500474 * Obsolete flag indicating high-priority notifications; use the priority field instead.
Joe Malin8d40d042012-11-05 11:36:40 -0800475 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500476 * @deprecated Use {@link #priority} with a positive value.
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400477 */
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500478 public static final int FLAG_HIGH_PRIORITY = 0x00000080;
Daniel Sandlere46cbd32010-06-17 10:35:26 -0400479
Griff Hazendfcb0802014-02-11 12:00:00 -0800480 /**
481 * Bit to be bitswise-ored into the {@link #flags} field that should be
482 * set if this notification is relevant to the current device only
483 * and it is not recommended that it bridge to other devices.
484 */
485 public static final int FLAG_LOCAL_ONLY = 0x00000100;
486
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700487 /**
488 * Bit to be bitswise-ored into the {@link #flags} field that should be
489 * set if this notification is the group summary for a group of notifications.
490 * Grouped notifications may display in a cluster or stack on devices which
491 * support such rendering. Requires a group key also be set using {@link Builder#setGroup}.
492 */
493 public static final int FLAG_GROUP_SUMMARY = 0x00000200;
494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 public int flags;
496
Tor Norbyed9273d62013-05-30 15:59:53 -0700497 /** @hide */
498 @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX})
499 @Retention(RetentionPolicy.SOURCE)
500 public @interface Priority {}
501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500503 * Default notification {@link #priority}. If your application does not prioritize its own
504 * notifications, use this value for all notifications.
505 */
506 public static final int PRIORITY_DEFAULT = 0;
507
508 /**
509 * Lower {@link #priority}, for items that are less important. The UI may choose to show these
510 * items smaller, or at a different position in the list, compared with your app's
511 * {@link #PRIORITY_DEFAULT} items.
512 */
513 public static final int PRIORITY_LOW = -1;
514
515 /**
516 * Lowest {@link #priority}; these items might not be shown to the user except under special
517 * circumstances, such as detailed notification logs.
518 */
519 public static final int PRIORITY_MIN = -2;
520
521 /**
522 * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to
523 * show these items larger, or at a different position in notification lists, compared with
524 * your app's {@link #PRIORITY_DEFAULT} items.
525 */
526 public static final int PRIORITY_HIGH = 1;
527
528 /**
529 * Highest {@link #priority}, for your application's most important items that require the
530 * user's prompt attention or input.
531 */
532 public static final int PRIORITY_MAX = 2;
533
534 /**
535 * Relative priority for this notification.
Joe Malin8d40d042012-11-05 11:36:40 -0800536 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500537 * Priority is an indication of how much of the user's valuable attention should be consumed by
538 * this notification. Low-priority notifications may be hidden from the user in certain
539 * situations, while the user might be interrupted for a higher-priority notification. The
Daniel Sandler6738eee2012-11-16 12:03:32 -0500540 * system will make a determination about how to interpret this priority when presenting
541 * the notification.
Chris Wren47c20a12014-06-18 17:27:29 -0400542 *
543 * <p>
544 * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented
545 * as a heads-up notification.
546 * </p>
547 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500548 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700549 @Priority
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500550 public int priority;
Joe Malin8d40d042012-11-05 11:36:40 -0800551
Dan Sandler26e81cf2014-05-06 10:01:27 -0400552 /**
553 * Accent color (an ARGB integer like the constants in {@link android.graphics.Color})
554 * to be applied by the standard Style templates when presenting this notification.
555 *
556 * The current template design constructs a colorful header image by overlaying the
557 * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are
558 * ignored.
559 */
Tor Norbye80756e32015-03-02 09:39:27 -0800560 @ColorInt
Dan Sandler26e81cf2014-05-06 10:01:27 -0400561 public int color = COLOR_DEFAULT;
562
563 /**
564 * Special value of {@link #color} telling the system not to decorate this notification with
565 * any special color but instead use default colors when presenting this notification.
566 */
Tor Norbye80756e32015-03-02 09:39:27 -0800567 @ColorInt
Dan Sandler26e81cf2014-05-06 10:01:27 -0400568 public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT
Dan Sandler0bf2ed82013-12-21 23:33:41 -0600569
570 /**
571 * Sphere of visibility of this notification, which affects how and when the SystemUI reveals
572 * the notification's presence and contents in untrusted situations (namely, on the secure
573 * lockscreen).
574 *
575 * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always
576 * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are
577 * shown in all situations, but the contents are only available if the device is unlocked for
578 * the appropriate user.
579 *
580 * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification
581 * can be read even in an "insecure" context (that is, above a secure lockscreen).
582 * To modify the public version of this notification—for example, to redact some portions—see
583 * {@link Builder#setPublicVersion(Notification)}.
584 *
585 * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon
586 * and ticker until the user has bypassed the lockscreen.
587 */
588 public int visibility;
589
Griff Hazenfc3922d2014-08-20 11:56:44 -0700590 /**
591 * Notification visibility: Show this notification in its entirety on all lockscreens.
592 *
593 * {@see #visibility}
594 */
Dan Sandler0bf2ed82013-12-21 23:33:41 -0600595 public static final int VISIBILITY_PUBLIC = 1;
Griff Hazenfc3922d2014-08-20 11:56:44 -0700596
597 /**
598 * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or
599 * private information on secure lockscreens.
600 *
601 * {@see #visibility}
602 */
Dan Sandler0bf2ed82013-12-21 23:33:41 -0600603 public static final int VISIBILITY_PRIVATE = 0;
Griff Hazenfc3922d2014-08-20 11:56:44 -0700604
605 /**
606 * Notification visibility: Do not reveal any part of this notification on a secure lockscreen.
607 *
608 * {@see #visibility}
609 */
Dan Sandler0bf2ed82013-12-21 23:33:41 -0600610 public static final int VISIBILITY_SECRET = -1;
611
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500612 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400613 * Notification category: incoming call (voice or video) or similar synchronous communication request.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500614 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400615 public static final String CATEGORY_CALL = "call";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500616
617 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400618 * Notification category: incoming direct message (SMS, instant message, etc.).
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500619 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400620 public static final String CATEGORY_MESSAGE = "msg";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500621
622 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400623 * Notification category: asynchronous bulk message (email).
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500624 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400625 public static final String CATEGORY_EMAIL = "email";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500626
627 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400628 * Notification category: calendar event.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500629 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400630 public static final String CATEGORY_EVENT = "event";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500631
632 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400633 * Notification category: promotion or advertisement.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500634 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400635 public static final String CATEGORY_PROMO = "promo";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500636
637 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400638 * Notification category: alarm or timer.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500639 */
John Spurlockfd7f1e02014-03-18 16:41:57 -0400640 public static final String CATEGORY_ALARM = "alarm";
641
642 /**
643 * Notification category: progress of a long-running background operation.
644 */
645 public static final String CATEGORY_PROGRESS = "progress";
646
647 /**
648 * Notification category: social network or sharing update.
649 */
650 public static final String CATEGORY_SOCIAL = "social";
651
652 /**
653 * Notification category: error in background operation or authentication status.
654 */
655 public static final String CATEGORY_ERROR = "err";
656
657 /**
658 * Notification category: media transport control for playback.
659 */
660 public static final String CATEGORY_TRANSPORT = "transport";
661
662 /**
663 * Notification category: system or device status update. Reserved for system use.
664 */
665 public static final String CATEGORY_SYSTEM = "sys";
666
667 /**
668 * Notification category: indication of running background service.
669 */
670 public static final String CATEGORY_SERVICE = "service";
671
672 /**
John Spurlock0a69c8c2014-03-21 13:30:57 -0400673 * Notification category: a specific, timely recommendation for a single thing.
674 * For example, a news app might want to recommend a news story it believes the user will
675 * want to read next.
676 */
677 public static final String CATEGORY_RECOMMENDATION = "recommendation";
678
679 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400680 * Notification category: ongoing information about device or contextual status.
681 */
682 public static final String CATEGORY_STATUS = "status";
683
684 /**
John Spurlock24d3dad2015-04-02 12:24:02 -0400685 * Notification category: user-scheduled reminder.
686 */
687 public static final String CATEGORY_REMINDER = "reminder";
688
689 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400690 * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants)
691 * that best describes this Notification. May be used by the system for ranking and filtering.
692 */
693 public String category;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500694
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700695 private String mGroupKey;
696
697 /**
698 * Get the key used to group this notification into a cluster or stack
699 * with other notifications on devices which support such rendering.
700 */
701 public String getGroup() {
702 return mGroupKey;
703 }
704
705 private String mSortKey;
706
707 /**
708 * Get a sort key that orders this notification among other notifications from the
709 * same package. This can be useful if an external sort was already applied and an app
710 * would like to preserve this. Notifications will be sorted lexicographically using this
711 * value, although providing different priorities in addition to providing sort key may
712 * cause this value to be ignored.
713 *
714 * <p>This sort key can also be used to order members of a notification group. See
715 * {@link Builder#setGroup}.
716 *
717 * @see String#compareTo(String)
718 */
719 public String getSortKey() {
720 return mSortKey;
721 }
722
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500723 /**
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400724 * Additional semantic data to be carried around with this Notification.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400725 * <p>
726 * The extras keys defined here are intended to capture the original inputs to {@link Builder}
727 * APIs, and are intended to be used by
728 * {@link android.service.notification.NotificationListenerService} implementations to extract
729 * detailed information from notification objects.
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500730 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400731 public Bundle extras = new Bundle();
732
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400733 /**
734 * {@link #extras} key: this is the title of the notification,
735 * as supplied to {@link Builder#setContentTitle(CharSequence)}.
736 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500737 public static final String EXTRA_TITLE = "android.title";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400738
739 /**
740 * {@link #extras} key: this is the title of the notification when shown in expanded form,
741 * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}.
742 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400743 public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400744
745 /**
746 * {@link #extras} key: this is the main text payload, as supplied to
747 * {@link Builder#setContentText(CharSequence)}.
748 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500749 public static final String EXTRA_TEXT = "android.text";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400750
751 /**
752 * {@link #extras} key: this is a third line of text, as supplied to
753 * {@link Builder#setSubText(CharSequence)}.
754 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400755 public static final String EXTRA_SUB_TEXT = "android.subText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400756
757 /**
Adrian Roose458aa82015-12-08 16:17:19 -0800758 * {@link #extras} key: this is the remote input history, as supplied to
759 * {@link Builder#setRemoteInputHistory(CharSequence[])}.
760 */
761 public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory";
762
763 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400764 * {@link #extras} key: this is a small piece of additional text as supplied to
765 * {@link Builder#setContentInfo(CharSequence)}.
766 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400767 public static final String EXTRA_INFO_TEXT = "android.infoText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400768
769 /**
770 * {@link #extras} key: this is a line of summary information intended to be shown
771 * alongside expanded notifications, as supplied to (e.g.)
772 * {@link BigTextStyle#setSummaryText(CharSequence)}.
773 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400774 public static final String EXTRA_SUMMARY_TEXT = "android.summaryText";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400775
776 /**
Christoph Studer4600f9b2014-07-22 22:44:43 +0200777 * {@link #extras} key: this is the longer text shown in the big form of a
778 * {@link BigTextStyle} notification, as supplied to
779 * {@link BigTextStyle#bigText(CharSequence)}.
780 */
781 public static final String EXTRA_BIG_TEXT = "android.bigText";
782
783 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400784 * {@link #extras} key: this is the resource ID of the notification's main small icon, as
785 * supplied to {@link Builder#setSmallIcon(int)}.
786 */
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -0500787 public static final String EXTRA_SMALL_ICON = "android.icon";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400788
789 /**
790 * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the
791 * notification payload, as
792 * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}.
793 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400794 public static final String EXTRA_LARGE_ICON = "android.largeIcon";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400795
796 /**
797 * {@link #extras} key: this is a bitmap to be used instead of the one from
798 * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is
799 * shown in its expanded form, as supplied to
800 * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}.
801 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400802 public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400803
804 /**
805 * {@link #extras} key: this is the progress value supplied to
806 * {@link Builder#setProgress(int, int, boolean)}.
807 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400808 public static final String EXTRA_PROGRESS = "android.progress";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400809
810 /**
811 * {@link #extras} key: this is the maximum value supplied to
812 * {@link Builder#setProgress(int, int, boolean)}.
813 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400814 public static final String EXTRA_PROGRESS_MAX = "android.progressMax";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400815
816 /**
817 * {@link #extras} key: whether the progress bar is indeterminate, supplied to
818 * {@link Builder#setProgress(int, int, boolean)}.
819 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400820 public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400821
822 /**
823 * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically
824 * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to
825 * {@link Builder#setUsesChronometer(boolean)}.
826 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400827 public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400828
829 /**
Selim Cinek81c23aa2016-02-25 16:23:13 -0800830 * {@link #extras} key: whether the chronometer set on the notification should count down
831 * instead of counting up. Is only relevant if key {@link #EXTRA_SHOW_CHRONOMETER} is present.
832 */
833 public static final String EXTRA_CHRONOMETER_COUNTS_DOWN = "android.chronometerCountsDown";
834
835 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400836 * {@link #extras} key: whether {@link #when} should be shown,
837 * as supplied to {@link Builder#setShowWhen(boolean)}.
838 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400839 public static final String EXTRA_SHOW_WHEN = "android.showWhen";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400840
841 /**
842 * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded
843 * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}.
844 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400845 public static final String EXTRA_PICTURE = "android.picture";
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400846
847 /**
848 * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded
849 * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}.
850 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400851 public static final String EXTRA_TEXT_LINES = "android.textLines";
Dan Sandler842dd772014-05-15 09:36:47 -0400852
853 /**
854 * {@link #extras} key: A string representing the name of the specific
855 * {@link android.app.Notification.Style} used to create this notification.
856 */
Chris Wren91ad5632013-06-05 15:05:57 -0400857 public static final String EXTRA_TEMPLATE = "android.template";
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400858
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400859 /**
Chris Wrene6c48932014-09-29 17:19:27 -0400860 * {@link #extras} key: A String array containing the people that this notification relates to,
861 * each of which was supplied to {@link Builder#addPerson(String)}.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400862 */
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400863 public static final String EXTRA_PEOPLE = "android.people";
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500864
865 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -0400866 * Allow certain system-generated notifications to appear before the device is provisioned.
867 * Only available to notifications coming from the android package.
868 * @hide
869 */
870 public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup";
871
872 /**
Jose Limae9e3b3b2014-05-18 23:44:50 -0700873 * {@link #extras} key: A
874 * {@link android.content.ContentUris content URI} pointing to an image that can be displayed
875 * in the background when the notification is selected. The URI must point to an image stream
876 * suitable for passing into
877 * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream)
878 * BitmapFactory.decodeStream}; all other content types will be ignored. The content provider
879 * URI used for this purpose must require no permissions to read the image data.
880 */
881 public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri";
882
883 /**
Dan Sandler842dd772014-05-15 09:36:47 -0400884 * {@link #extras} key: A
Jeff Browndba34ba2014-06-24 20:46:03 -0700885 * {@link android.media.session.MediaSession.Token} associated with a
Dan Sandler842dd772014-05-15 09:36:47 -0400886 * {@link android.app.Notification.MediaStyle} notification.
887 */
888 public static final String EXTRA_MEDIA_SESSION = "android.mediaSession";
889
890 /**
Bryan Mawhinneye191f902014-07-22 12:50:09 +0100891 * {@link #extras} key: the indices of actions to be shown in the compact view,
892 * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}.
893 */
894 public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions";
895
Christoph Studer943aa672014-08-03 20:31:16 +0200896 /**
Kenny Guy8942bcd2014-09-08 21:09:47 +0100897 * {@link #extras} key: the user that built the notification.
898 *
899 * @hide
900 */
901 public static final String EXTRA_ORIGINATING_USERID = "android.originatingUserId";
902
903 /**
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400904 * @hide
905 */
906 public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo";
907
Selim Cinek247fa012016-02-18 09:50:48 -0800908 /**
909 * @hide
910 */
911 public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView";
912
Dan Sandlerd63f9322015-05-06 15:18:49 -0400913 private Icon mSmallIcon;
914 private Icon mLargeIcon;
915
Chris Wren51c75102013-07-16 20:49:17 -0400916 /**
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400917 * Structure to encapsulate a named action that can be shown as part of this notification.
918 * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is
919 * selected by the user.
920 * <p>
Griff Hazen959591e2014-05-15 22:26:18 -0700921 * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)}
922 * or {@link Notification.Builder#addAction(Notification.Action)}
923 * to attach actions.
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400924 */
Daniel Sandlerea2a3172013-02-20 22:24:20 -0500925 public static class Action implements Parcelable {
Griff Hazen959591e2014-05-15 22:26:18 -0700926 private final Bundle mExtras;
Dan Sandler86647982015-05-13 23:41:13 -0400927 private Icon mIcon;
Griff Hazen61a9e862014-05-22 16:05:19 -0700928 private final RemoteInput[] mRemoteInputs;
Griff Hazen959591e2014-05-15 22:26:18 -0700929
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400930 /**
931 * Small icon representing the action.
Dan Sandler86647982015-05-13 23:41:13 -0400932 *
933 * @deprecated Use {@link Action#getIcon()} instead.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400934 */
Dan Sandler86647982015-05-13 23:41:13 -0400935 @Deprecated
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400936 public int icon;
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700937
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400938 /**
939 * Title of the action.
940 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400941 public CharSequence title;
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700942
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400943 /**
944 * Intent to send when the user invokes this action. May be null, in which case the action
945 * may be rendered in a disabled presentation by the system UI.
946 */
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400947 public PendingIntent actionIntent;
Griff Hazen959591e2014-05-15 22:26:18 -0700948
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400949 private Action(Parcel in) {
Dan Sandler86647982015-05-13 23:41:13 -0400950 if (in.readInt() != 0) {
951 mIcon = Icon.CREATOR.createFromParcel(in);
Dan Sandler68079d52015-07-22 10:45:30 -0400952 if (mIcon.getType() == Icon.TYPE_RESOURCE) {
953 icon = mIcon.getResId();
954 }
Dan Sandler86647982015-05-13 23:41:13 -0400955 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400956 title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
957 if (in.readInt() == 1) {
958 actionIntent = PendingIntent.CREATOR.createFromParcel(in);
959 }
Griff Hazen959591e2014-05-15 22:26:18 -0700960 mExtras = in.readBundle();
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700961 mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR);
Daniel Sandlera0a938c2012-03-15 08:42:37 -0400962 }
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700963
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400964 /**
Dan Sandler86647982015-05-13 23:41:13 -0400965 * @deprecated Use {@link android.app.Notification.Action.Builder}.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400966 */
Dan Sandler86647982015-05-13 23:41:13 -0400967 @Deprecated
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400968 public Action(int icon, CharSequence title, PendingIntent intent) {
Dan Sandler86647982015-05-13 23:41:13 -0400969 this(Icon.createWithResource("", icon), title, intent, new Bundle(), null);
Griff Hazen959591e2014-05-15 22:26:18 -0700970 }
971
Dan Sandler86647982015-05-13 23:41:13 -0400972 private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras,
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700973 RemoteInput[] remoteInputs) {
Dan Sandler86647982015-05-13 23:41:13 -0400974 this.mIcon = icon;
Gus Prevasf5bff46f2015-08-24 10:34:28 -0400975 if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) {
976 this.icon = icon.getResId();
977 }
Daniel Sandlercf1d39b2013-09-23 13:35:35 -0400978 this.title = title;
979 this.actionIntent = intent;
Griff Hazen959591e2014-05-15 22:26:18 -0700980 this.mExtras = extras != null ? extras : new Bundle();
Griff Hazen5cadc3b2014-05-20 09:55:39 -0700981 this.mRemoteInputs = remoteInputs;
Griff Hazen959591e2014-05-15 22:26:18 -0700982 }
983
984 /**
Dan Sandler86647982015-05-13 23:41:13 -0400985 * Return an icon representing the action.
986 */
987 public Icon getIcon() {
988 if (mIcon == null && icon != 0) {
989 // you snuck an icon in here without using the builder; let's try to keep it
990 mIcon = Icon.createWithResource("", icon);
991 }
992 return mIcon;
993 }
994
995 /**
Griff Hazen959591e2014-05-15 22:26:18 -0700996 * Get additional metadata carried around with this Action.
997 */
998 public Bundle getExtras() {
999 return mExtras;
1000 }
1001
1002 /**
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001003 * Get the list of inputs to be collected from the user when this action is sent.
1004 * May return null if no remote inputs were added.
1005 */
1006 public RemoteInput[] getRemoteInputs() {
1007 return mRemoteInputs;
1008 }
1009
1010 /**
Griff Hazen959591e2014-05-15 22:26:18 -07001011 * Builder class for {@link Action} objects.
1012 */
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001013 public static final class Builder {
Dan Sandler86647982015-05-13 23:41:13 -04001014 private final Icon mIcon;
Griff Hazen959591e2014-05-15 22:26:18 -07001015 private final CharSequence mTitle;
1016 private final PendingIntent mIntent;
1017 private final Bundle mExtras;
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001018 private ArrayList<RemoteInput> mRemoteInputs;
Griff Hazen959591e2014-05-15 22:26:18 -07001019
1020 /**
1021 * Construct a new builder for {@link Action} object.
1022 * @param icon icon to show for this action
1023 * @param title the title of the action
1024 * @param intent the {@link PendingIntent} to fire when users trigger this action
1025 */
Dan Sandler86647982015-05-13 23:41:13 -04001026 @Deprecated
Griff Hazen959591e2014-05-15 22:26:18 -07001027 public Builder(int icon, CharSequence title, PendingIntent intent) {
Dan Sandler86647982015-05-13 23:41:13 -04001028 this(Icon.createWithResource("", icon), title, intent, new Bundle(), null);
1029 }
1030
1031 /**
1032 * Construct a new builder for {@link Action} object.
1033 * @param icon icon to show for this action
1034 * @param title the title of the action
1035 * @param intent the {@link PendingIntent} to fire when users trigger this action
1036 */
1037 public Builder(Icon icon, CharSequence title, PendingIntent intent) {
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001038 this(icon, title, intent, new Bundle(), null);
Griff Hazen959591e2014-05-15 22:26:18 -07001039 }
1040
1041 /**
1042 * Construct a new builder for {@link Action} object using the fields from an
1043 * {@link Action}.
1044 * @param action the action to read fields from.
1045 */
1046 public Builder(Action action) {
Dan Sandler86647982015-05-13 23:41:13 -04001047 this(action.getIcon(), action.title, action.actionIntent, new Bundle(action.mExtras),
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001048 action.getRemoteInputs());
Griff Hazen959591e2014-05-15 22:26:18 -07001049 }
1050
Dan Sandler86647982015-05-13 23:41:13 -04001051 private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras,
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001052 RemoteInput[] remoteInputs) {
Griff Hazen959591e2014-05-15 22:26:18 -07001053 mIcon = icon;
1054 mTitle = title;
1055 mIntent = intent;
1056 mExtras = extras;
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001057 if (remoteInputs != null) {
1058 mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length);
1059 Collections.addAll(mRemoteInputs, remoteInputs);
1060 }
Griff Hazen959591e2014-05-15 22:26:18 -07001061 }
1062
1063 /**
1064 * Merge additional metadata into this builder.
1065 *
1066 * <p>Values within the Bundle will replace existing extras values in this Builder.
1067 *
1068 * @see Notification.Action#extras
1069 */
1070 public Builder addExtras(Bundle extras) {
1071 if (extras != null) {
1072 mExtras.putAll(extras);
1073 }
1074 return this;
1075 }
1076
1077 /**
1078 * Get the metadata Bundle used by this Builder.
1079 *
1080 * <p>The returned Bundle is shared with this Builder.
1081 */
1082 public Bundle getExtras() {
1083 return mExtras;
1084 }
1085
1086 /**
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001087 * Add an input to be collected from the user when this action is sent.
1088 * Response values can be retrieved from the fired intent by using the
1089 * {@link RemoteInput#getResultsFromIntent} function.
1090 * @param remoteInput a {@link RemoteInput} to add to the action
1091 * @return this object for method chaining
1092 */
1093 public Builder addRemoteInput(RemoteInput remoteInput) {
1094 if (mRemoteInputs == null) {
1095 mRemoteInputs = new ArrayList<RemoteInput>();
1096 }
1097 mRemoteInputs.add(remoteInput);
1098 return this;
1099 }
1100
1101 /**
1102 * Apply an extender to this action builder. Extenders may be used to add
1103 * metadata or change options on this builder.
1104 */
Griff Hazen61a9e862014-05-22 16:05:19 -07001105 public Builder extend(Extender extender) {
1106 extender.extend(this);
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001107 return this;
1108 }
1109
1110 /**
Griff Hazen959591e2014-05-15 22:26:18 -07001111 * Combine all of the options that have been set and return a new {@link Action}
1112 * object.
1113 * @return the built action
1114 */
1115 public Action build() {
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001116 RemoteInput[] remoteInputs = mRemoteInputs != null
1117 ? mRemoteInputs.toArray(new RemoteInput[mRemoteInputs.size()]) : null;
1118 return new Action(mIcon, mTitle, mIntent, mExtras, remoteInputs);
Griff Hazen959591e2014-05-15 22:26:18 -07001119 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001120 }
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04001121
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001122 @Override
1123 public Action clone() {
1124 return new Action(
Dan Sandler86647982015-05-13 23:41:13 -04001125 getIcon(),
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001126 title,
1127 actionIntent, // safe to alias
1128 new Bundle(mExtras),
1129 getRemoteInputs());
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001130 }
1131 @Override
1132 public int describeContents() {
1133 return 0;
1134 }
1135 @Override
1136 public void writeToParcel(Parcel out, int flags) {
Dan Sandler86647982015-05-13 23:41:13 -04001137 final Icon ic = getIcon();
1138 if (ic != null) {
1139 out.writeInt(1);
1140 ic.writeToParcel(out, 0);
1141 } else {
1142 out.writeInt(0);
1143 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001144 TextUtils.writeToParcel(title, out, flags);
1145 if (actionIntent != null) {
1146 out.writeInt(1);
1147 actionIntent.writeToParcel(out, flags);
1148 } else {
1149 out.writeInt(0);
1150 }
Griff Hazen959591e2014-05-15 22:26:18 -07001151 out.writeBundle(mExtras);
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001152 out.writeTypedArray(mRemoteInputs, flags);
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001153 }
Griff Hazen959591e2014-05-15 22:26:18 -07001154 public static final Parcelable.Creator<Action> CREATOR =
1155 new Parcelable.Creator<Action>() {
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001156 public Action createFromParcel(Parcel in) {
1157 return new Action(in);
1158 }
1159 public Action[] newArray(int size) {
1160 return new Action[size];
1161 }
1162 };
Griff Hazen61a9e862014-05-22 16:05:19 -07001163
1164 /**
1165 * Extender interface for use with {@link Builder#extend}. Extenders may be used to add
1166 * metadata or change options on an action builder.
1167 */
1168 public interface Extender {
1169 /**
1170 * Apply this extender to a notification action builder.
1171 * @param builder the builder to be modified.
1172 * @return the build object for chaining.
1173 */
1174 public Builder extend(Builder builder);
1175 }
1176
1177 /**
1178 * Wearable extender for notification actions. To add extensions to an action,
1179 * create a new {@link android.app.Notification.Action.WearableExtender} object using
1180 * the {@code WearableExtender()} constructor and apply it to a
1181 * {@link android.app.Notification.Action.Builder} using
1182 * {@link android.app.Notification.Action.Builder#extend}.
1183 *
1184 * <pre class="prettyprint">
1185 * Notification.Action action = new Notification.Action.Builder(
1186 * R.drawable.archive_all, "Archive all", actionIntent)
Griff Hazen14f57992014-05-26 09:07:14 -07001187 * .extend(new Notification.Action.WearableExtender()
Griff Hazen61a9e862014-05-22 16:05:19 -07001188 * .setAvailableOffline(false))
Griff Hazen14f57992014-05-26 09:07:14 -07001189 * .build();</pre>
Griff Hazen61a9e862014-05-22 16:05:19 -07001190 */
1191 public static final class WearableExtender implements Extender {
1192 /** Notification action extra which contains wearable extensions */
1193 private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS";
1194
Pete Gastaf6781d2014-10-07 15:17:05 -04001195 // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options.
Griff Hazen61a9e862014-05-22 16:05:19 -07001196 private static final String KEY_FLAGS = "flags";
Pete Gastaf6781d2014-10-07 15:17:05 -04001197 private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel";
1198 private static final String KEY_CONFIRM_LABEL = "confirmLabel";
1199 private static final String KEY_CANCEL_LABEL = "cancelLabel";
Griff Hazen61a9e862014-05-22 16:05:19 -07001200
1201 // Flags bitwise-ored to mFlags
1202 private static final int FLAG_AVAILABLE_OFFLINE = 0x1;
1203
1204 // Default value for flags integer
1205 private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE;
1206
1207 private int mFlags = DEFAULT_FLAGS;
1208
Pete Gastaf6781d2014-10-07 15:17:05 -04001209 private CharSequence mInProgressLabel;
1210 private CharSequence mConfirmLabel;
1211 private CharSequence mCancelLabel;
1212
Griff Hazen61a9e862014-05-22 16:05:19 -07001213 /**
1214 * Create a {@link android.app.Notification.Action.WearableExtender} with default
1215 * options.
1216 */
1217 public WearableExtender() {
1218 }
1219
1220 /**
1221 * Create a {@link android.app.Notification.Action.WearableExtender} by reading
1222 * wearable options present in an existing notification action.
1223 * @param action the notification action to inspect.
1224 */
1225 public WearableExtender(Action action) {
1226 Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS);
1227 if (wearableBundle != null) {
1228 mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS);
Pete Gastaf6781d2014-10-07 15:17:05 -04001229 mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL);
1230 mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL);
1231 mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL);
Griff Hazen61a9e862014-05-22 16:05:19 -07001232 }
1233 }
1234
1235 /**
1236 * Apply wearable extensions to a notification action that is being built. This is
1237 * typically called by the {@link android.app.Notification.Action.Builder#extend}
1238 * method of {@link android.app.Notification.Action.Builder}.
1239 */
1240 @Override
1241 public Action.Builder extend(Action.Builder builder) {
1242 Bundle wearableBundle = new Bundle();
1243
1244 if (mFlags != DEFAULT_FLAGS) {
1245 wearableBundle.putInt(KEY_FLAGS, mFlags);
1246 }
Pete Gastaf6781d2014-10-07 15:17:05 -04001247 if (mInProgressLabel != null) {
1248 wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel);
1249 }
1250 if (mConfirmLabel != null) {
1251 wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel);
1252 }
1253 if (mCancelLabel != null) {
1254 wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel);
1255 }
Griff Hazen61a9e862014-05-22 16:05:19 -07001256
1257 builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle);
1258 return builder;
1259 }
1260
1261 @Override
1262 public WearableExtender clone() {
1263 WearableExtender that = new WearableExtender();
1264 that.mFlags = this.mFlags;
Pete Gastaf6781d2014-10-07 15:17:05 -04001265 that.mInProgressLabel = this.mInProgressLabel;
1266 that.mConfirmLabel = this.mConfirmLabel;
1267 that.mCancelLabel = this.mCancelLabel;
Griff Hazen61a9e862014-05-22 16:05:19 -07001268 return that;
1269 }
1270
1271 /**
1272 * Set whether this action is available when the wearable device is not connected to
1273 * a companion device. The user can still trigger this action when the wearable device is
1274 * offline, but a visual hint will indicate that the action may not be available.
1275 * Defaults to true.
1276 */
1277 public WearableExtender setAvailableOffline(boolean availableOffline) {
1278 setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline);
1279 return this;
1280 }
1281
1282 /**
1283 * Get whether this action is available when the wearable device is not connected to
1284 * a companion device. The user can still trigger this action when the wearable device is
1285 * offline, but a visual hint will indicate that the action may not be available.
1286 * Defaults to true.
1287 */
1288 public boolean isAvailableOffline() {
1289 return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0;
1290 }
1291
1292 private void setFlag(int mask, boolean value) {
1293 if (value) {
1294 mFlags |= mask;
1295 } else {
1296 mFlags &= ~mask;
1297 }
1298 }
Pete Gastaf6781d2014-10-07 15:17:05 -04001299
1300 /**
1301 * Set a label to display while the wearable is preparing to automatically execute the
1302 * action. This is usually a 'ing' verb ending in ellipsis like "Sending..."
1303 *
1304 * @param label the label to display while the action is being prepared to execute
1305 * @return this object for method chaining
1306 */
1307 public WearableExtender setInProgressLabel(CharSequence label) {
1308 mInProgressLabel = label;
1309 return this;
1310 }
1311
1312 /**
1313 * Get the label to display while the wearable is preparing to automatically execute
1314 * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..."
1315 *
1316 * @return the label to display while the action is being prepared to execute
1317 */
1318 public CharSequence getInProgressLabel() {
1319 return mInProgressLabel;
1320 }
1321
1322 /**
1323 * Set a label to display to confirm that the action should be executed.
1324 * This is usually an imperative verb like "Send".
1325 *
1326 * @param label the label to confirm the action should be executed
1327 * @return this object for method chaining
1328 */
1329 public WearableExtender setConfirmLabel(CharSequence label) {
1330 mConfirmLabel = label;
1331 return this;
1332 }
1333
1334 /**
1335 * Get the label to display to confirm that the action should be executed.
1336 * This is usually an imperative verb like "Send".
1337 *
1338 * @return the label to confirm the action should be executed
1339 */
1340 public CharSequence getConfirmLabel() {
1341 return mConfirmLabel;
1342 }
1343
1344 /**
1345 * Set a label to display to cancel the action.
1346 * This is usually an imperative verb, like "Cancel".
1347 *
1348 * @param label the label to display to cancel the action
1349 * @return this object for method chaining
1350 */
1351 public WearableExtender setCancelLabel(CharSequence label) {
1352 mCancelLabel = label;
1353 return this;
1354 }
1355
1356 /**
1357 * Get the label to display to cancel the action.
1358 * This is usually an imperative verb like "Cancel".
1359 *
1360 * @return the label to display to cancel the action
1361 */
1362 public CharSequence getCancelLabel() {
1363 return mCancelLabel;
1364 }
Griff Hazen61a9e862014-05-22 16:05:19 -07001365 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001366 }
1367
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04001368 /**
1369 * Array of all {@link Action} structures attached to this notification by
1370 * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of
1371 * {@link android.service.notification.NotificationListenerService} that provide an alternative
1372 * interface for invoking actions.
1373 */
Daniel Sandlerea2a3172013-02-20 22:24:20 -05001374 public Action[] actions;
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001375
1376 /**
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001377 * Replacement version of this notification whose content will be shown
1378 * in an insecure context such as atop a secure keyguard. See {@link #visibility}
1379 * and {@link #VISIBILITY_PUBLIC}.
1380 */
1381 public Notification publicVersion;
1382
1383 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001384 * Constructs a Notification object with default values.
Joe Onorato46439ce2010-11-19 13:56:21 -08001385 * You might want to consider using {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 */
1387 public Notification()
1388 {
1389 this.when = System.currentTimeMillis();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001390 this.priority = PRIORITY_DEFAULT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 }
1392
1393 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 * @hide
1395 */
1396 public Notification(Context context, int icon, CharSequence tickerText, long when,
1397 CharSequence contentTitle, CharSequence contentText, Intent contentIntent)
1398 {
Chris Wren1ce4b6d2015-06-11 10:19:43 -04001399 new Builder(context)
1400 .setWhen(when)
1401 .setSmallIcon(icon)
1402 .setTicker(tickerText)
1403 .setContentTitle(contentTitle)
1404 .setContentText(contentText)
1405 .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0))
1406 .buildInto(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 }
1408
1409 /**
1410 * Constructs a Notification object with the information needed to
1411 * have a status bar icon without the standard expanded view.
1412 *
1413 * @param icon The resource id of the icon to put in the status bar.
1414 * @param tickerText The text that flows by in the status bar when the notification first
1415 * activates.
1416 * @param when The time to show in the time field. In the System.currentTimeMillis
1417 * timebase.
Joe Onorato46439ce2010-11-19 13:56:21 -08001418 *
1419 * @deprecated Use {@link Builder} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001421 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 public Notification(int icon, CharSequence tickerText, long when)
1423 {
1424 this.icon = icon;
1425 this.tickerText = tickerText;
1426 this.when = when;
1427 }
1428
1429 /**
1430 * Unflatten the notification from a parcel.
1431 */
1432 public Notification(Parcel parcel)
1433 {
1434 int version = parcel.readInt();
1435
1436 when = parcel.readLong();
Dan Sandler3936e7a2015-05-19 20:59:12 -04001437 if (parcel.readInt() != 0) {
1438 mSmallIcon = Icon.CREATOR.createFromParcel(parcel);
Dan Sandler4e787062015-06-17 15:09:48 -04001439 if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) {
1440 icon = mSmallIcon.getResId();
1441 }
Dan Sandler3936e7a2015-05-19 20:59:12 -04001442 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 number = parcel.readInt();
1444 if (parcel.readInt() != 0) {
1445 contentIntent = PendingIntent.CREATOR.createFromParcel(parcel);
1446 }
1447 if (parcel.readInt() != 0) {
1448 deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel);
1449 }
1450 if (parcel.readInt() != 0) {
1451 tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1452 }
1453 if (parcel.readInt() != 0) {
Joe Onorato46439ce2010-11-19 13:56:21 -08001454 tickerView = RemoteViews.CREATOR.createFromParcel(parcel);
Joe Onoratoef1e7762010-09-17 18:38:38 -04001455 }
1456 if (parcel.readInt() != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 contentView = RemoteViews.CREATOR.createFromParcel(parcel);
1458 }
Joe Onorato561d3852010-11-20 18:09:34 -08001459 if (parcel.readInt() != 0) {
Dan Sandlerd63f9322015-05-06 15:18:49 -04001460 mLargeIcon = Icon.CREATOR.createFromParcel(parcel);
Joe Onorato561d3852010-11-20 18:09:34 -08001461 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 defaults = parcel.readInt();
1463 flags = parcel.readInt();
1464 if (parcel.readInt() != 0) {
1465 sound = Uri.CREATOR.createFromParcel(parcel);
1466 }
1467
1468 audioStreamType = parcel.readInt();
John Spurlockc0650f022014-07-19 13:22:39 -04001469 if (parcel.readInt() != 0) {
1470 audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel);
1471 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001472 vibrate = parcel.createLongArray();
1473 ledARGB = parcel.readInt();
1474 ledOnMS = parcel.readInt();
1475 ledOffMS = parcel.readInt();
1476 iconLevel = parcel.readInt();
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001477
1478 if (parcel.readInt() != 0) {
1479 fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel);
1480 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001481
1482 priority = parcel.readInt();
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001483
John Spurlockfd7f1e02014-03-18 16:41:57 -04001484 category = parcel.readString();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001485
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001486 mGroupKey = parcel.readString();
1487
1488 mSortKey = parcel.readString();
1489
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001490 extras = parcel.readBundle(); // may be null
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001491
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001492 actions = parcel.createTypedArray(Action.CREATOR); // may be null
1493
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001494 if (parcel.readInt() != 0) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001495 bigContentView = RemoteViews.CREATOR.createFromParcel(parcel);
1496 }
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001497
Chris Wren8fd39ec2014-02-27 17:43:26 -05001498 if (parcel.readInt() != 0) {
1499 headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel);
1500 }
1501
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001502 visibility = parcel.readInt();
1503
1504 if (parcel.readInt() != 0) {
1505 publicVersion = Notification.CREATOR.createFromParcel(parcel);
1506 }
Dan Sandler26e81cf2014-05-06 10:01:27 -04001507
1508 color = parcel.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 }
1510
Andy Stadler110988c2010-12-03 14:29:16 -08001511 @Override
Joe Onorato18e69df2010-05-17 22:26:12 -07001512 public Notification clone() {
1513 Notification that = new Notification();
Daniel Sandler1a497d32013-04-18 14:52:45 -04001514 cloneInto(that, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001515 return that;
1516 }
Joe Onorato18e69df2010-05-17 22:26:12 -07001517
Daniel Sandler1a497d32013-04-18 14:52:45 -04001518 /**
1519 * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members
1520 * of this into that.
1521 * @hide
1522 */
1523 public void cloneInto(Notification that, boolean heavy) {
Joe Onorato18e69df2010-05-17 22:26:12 -07001524 that.when = this.when;
Dan Sandlerd63f9322015-05-06 15:18:49 -04001525 that.mSmallIcon = this.mSmallIcon;
Joe Onorato18e69df2010-05-17 22:26:12 -07001526 that.number = this.number;
1527
1528 // PendingIntents are global, so there's no reason (or way) to clone them.
1529 that.contentIntent = this.contentIntent;
1530 that.deleteIntent = this.deleteIntent;
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001531 that.fullScreenIntent = this.fullScreenIntent;
Joe Onorato18e69df2010-05-17 22:26:12 -07001532
1533 if (this.tickerText != null) {
1534 that.tickerText = this.tickerText.toString();
1535 }
Daniel Sandler1a497d32013-04-18 14:52:45 -04001536 if (heavy && this.tickerView != null) {
Joe Onorato46439ce2010-11-19 13:56:21 -08001537 that.tickerView = this.tickerView.clone();
Joe Onoratoef1e7762010-09-17 18:38:38 -04001538 }
Daniel Sandler1a497d32013-04-18 14:52:45 -04001539 if (heavy && this.contentView != null) {
Joe Onorato18e69df2010-05-17 22:26:12 -07001540 that.contentView = this.contentView.clone();
1541 }
Dan Sandlerd63f9322015-05-06 15:18:49 -04001542 if (heavy && this.mLargeIcon != null) {
1543 that.mLargeIcon = this.mLargeIcon;
Joe Onorato561d3852010-11-20 18:09:34 -08001544 }
Jozef BABJAKa8b91832011-02-22 08:05:08 +01001545 that.iconLevel = this.iconLevel;
Joe Onorato18e69df2010-05-17 22:26:12 -07001546 that.sound = this.sound; // android.net.Uri is immutable
1547 that.audioStreamType = this.audioStreamType;
John Spurlockc0650f022014-07-19 13:22:39 -04001548 if (this.audioAttributes != null) {
1549 that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build();
1550 }
Joe Onorato18e69df2010-05-17 22:26:12 -07001551
1552 final long[] vibrate = this.vibrate;
1553 if (vibrate != null) {
1554 final int N = vibrate.length;
1555 final long[] vib = that.vibrate = new long[N];
1556 System.arraycopy(vibrate, 0, vib, 0, N);
1557 }
1558
1559 that.ledARGB = this.ledARGB;
1560 that.ledOnMS = this.ledOnMS;
1561 that.ledOffMS = this.ledOffMS;
1562 that.defaults = this.defaults;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001563
Joe Onorato18e69df2010-05-17 22:26:12 -07001564 that.flags = this.flags;
1565
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001566 that.priority = this.priority;
Joe Malin8d40d042012-11-05 11:36:40 -08001567
John Spurlockfd7f1e02014-03-18 16:41:57 -04001568 that.category = this.category;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001569
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001570 that.mGroupKey = this.mGroupKey;
1571
1572 that.mSortKey = this.mSortKey;
1573
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001574 if (this.extras != null) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001575 try {
1576 that.extras = new Bundle(this.extras);
1577 // will unparcel
1578 that.extras.size();
1579 } catch (BadParcelableException e) {
1580 Log.e(TAG, "could not unparcel extras from notification: " + this, e);
1581 that.extras = null;
1582 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001583 }
1584
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001585 if (this.actions != null) {
1586 that.actions = new Action[this.actions.length];
1587 for(int i=0; i<this.actions.length; i++) {
1588 that.actions[i] = this.actions[i].clone();
1589 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001590 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001591
Daniel Sandler1a497d32013-04-18 14:52:45 -04001592 if (heavy && this.bigContentView != null) {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001593 that.bigContentView = this.bigContentView.clone();
1594 }
Daniel Sandler1a497d32013-04-18 14:52:45 -04001595
Chris Wren8fd39ec2014-02-27 17:43:26 -05001596 if (heavy && this.headsUpContentView != null) {
1597 that.headsUpContentView = this.headsUpContentView.clone();
1598 }
1599
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001600 that.visibility = this.visibility;
1601
1602 if (this.publicVersion != null) {
1603 that.publicVersion = new Notification();
1604 this.publicVersion.cloneInto(that.publicVersion, heavy);
1605 }
1606
Dan Sandler26e81cf2014-05-06 10:01:27 -04001607 that.color = this.color;
1608
Daniel Sandler1a497d32013-04-18 14:52:45 -04001609 if (!heavy) {
1610 that.lightenPayload(); // will clean out extras
1611 }
1612 }
1613
1614 /**
1615 * Removes heavyweight parts of the Notification object for archival or for sending to
1616 * listeners when the full contents are not necessary.
1617 * @hide
1618 */
1619 public final void lightenPayload() {
1620 tickerView = null;
1621 contentView = null;
1622 bigContentView = null;
Chris Wren8fd39ec2014-02-27 17:43:26 -05001623 headsUpContentView = null;
Dan Sandlerd63f9322015-05-06 15:18:49 -04001624 mLargeIcon = null;
Dan Sandler50128532015-12-08 15:42:41 -05001625 if (extras != null && !extras.isEmpty()) {
1626 final Set<String> keyset = extras.keySet();
1627 final int N = keyset.size();
1628 final String[] keys = keyset.toArray(new String[N]);
1629 for (int i=0; i<N; i++) {
1630 final String key = keys[i];
1631 final Object obj = extras.get(key);
1632 if (obj != null &&
1633 ( obj instanceof Parcelable
1634 || obj instanceof Parcelable[]
1635 || obj instanceof SparseArray
1636 || obj instanceof ArrayList)) {
1637 extras.remove(key);
1638 }
1639 }
Daniel Sandler1a497d32013-04-18 14:52:45 -04001640 }
Joe Onorato18e69df2010-05-17 22:26:12 -07001641 }
1642
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001643 /**
1644 * Make sure this CharSequence is safe to put into a bundle, which basically
1645 * means it had better not be some custom Parcelable implementation.
1646 * @hide
1647 */
1648 public static CharSequence safeCharSequence(CharSequence cs) {
Christoph Studer535ec612014-09-03 15:47:47 +02001649 if (cs == null) return cs;
1650 if (cs.length() > MAX_CHARSEQUENCE_LENGTH) {
1651 cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH);
1652 }
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001653 if (cs instanceof Parcelable) {
1654 Log.e(TAG, "warning: " + cs.getClass().getCanonicalName()
1655 + " instance is a custom Parcelable and not allowed in Notification");
1656 return cs.toString();
1657 }
Selim Cinek60a54252016-02-26 17:03:25 -08001658 return removeTextSizeSpans(cs);
1659 }
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001660
Selim Cinek60a54252016-02-26 17:03:25 -08001661 private static CharSequence removeTextSizeSpans(CharSequence charSequence) {
1662 if (charSequence instanceof Spanned) {
1663 Spanned ss = (Spanned) charSequence;
1664 Object[] spans = ss.getSpans(0, ss.length(), Object.class);
1665 SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString());
1666 for (Object span : spans) {
1667 Object resultSpan = span;
Selim Cinek89991a22016-03-07 19:51:54 -08001668 if (resultSpan instanceof CharacterStyle) {
1669 resultSpan = ((CharacterStyle) span).getUnderlying();
1670 }
1671 if (resultSpan instanceof TextAppearanceSpan) {
1672 TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan;
Selim Cinek60a54252016-02-26 17:03:25 -08001673 resultSpan = new TextAppearanceSpan(
1674 originalSpan.getFamily(),
1675 originalSpan.getTextStyle(),
1676 -1,
1677 originalSpan.getTextColor(),
1678 originalSpan.getLinkTextColor());
Selim Cinek89991a22016-03-07 19:51:54 -08001679 } else if (resultSpan instanceof RelativeSizeSpan
1680 || resultSpan instanceof AbsoluteSizeSpan) {
Selim Cinek60a54252016-02-26 17:03:25 -08001681 continue;
Selim Cinek89991a22016-03-07 19:51:54 -08001682 } else {
1683 resultSpan = span;
Selim Cinek60a54252016-02-26 17:03:25 -08001684 }
1685 builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span),
1686 ss.getSpanFlags(span));
1687 }
1688 return builder;
1689 }
1690 return charSequence;
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04001691 }
1692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 public int describeContents() {
1694 return 0;
1695 }
1696
1697 /**
Dan Sandler4e787062015-06-17 15:09:48 -04001698 * Flatten this notification into a parcel.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 */
1700 public void writeToParcel(Parcel parcel, int flags)
1701 {
1702 parcel.writeInt(1);
1703
1704 parcel.writeLong(when);
Dan Sandler4e787062015-06-17 15:09:48 -04001705 if (mSmallIcon == null && icon != 0) {
1706 // you snuck an icon in here without using the builder; let's try to keep it
1707 mSmallIcon = Icon.createWithResource("", icon);
1708 }
Dan Sandler3936e7a2015-05-19 20:59:12 -04001709 if (mSmallIcon != null) {
1710 parcel.writeInt(1);
1711 mSmallIcon.writeToParcel(parcel, 0);
1712 } else {
1713 parcel.writeInt(0);
1714 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001715 parcel.writeInt(number);
1716 if (contentIntent != null) {
1717 parcel.writeInt(1);
1718 contentIntent.writeToParcel(parcel, 0);
1719 } else {
1720 parcel.writeInt(0);
1721 }
1722 if (deleteIntent != null) {
1723 parcel.writeInt(1);
1724 deleteIntent.writeToParcel(parcel, 0);
1725 } else {
1726 parcel.writeInt(0);
1727 }
1728 if (tickerText != null) {
1729 parcel.writeInt(1);
1730 TextUtils.writeToParcel(tickerText, parcel, flags);
1731 } else {
1732 parcel.writeInt(0);
1733 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001734 if (tickerView != null) {
Joe Onoratoef1e7762010-09-17 18:38:38 -04001735 parcel.writeInt(1);
Joe Onorato46439ce2010-11-19 13:56:21 -08001736 tickerView.writeToParcel(parcel, 0);
Joe Onoratoef1e7762010-09-17 18:38:38 -04001737 } else {
1738 parcel.writeInt(0);
1739 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001740 if (contentView != null) {
1741 parcel.writeInt(1);
1742 contentView.writeToParcel(parcel, 0);
1743 } else {
1744 parcel.writeInt(0);
1745 }
Dan Sandlerd63f9322015-05-06 15:18:49 -04001746 if (mLargeIcon != null) {
Joe Onorato561d3852010-11-20 18:09:34 -08001747 parcel.writeInt(1);
Dan Sandlerd63f9322015-05-06 15:18:49 -04001748 mLargeIcon.writeToParcel(parcel, 0);
Joe Onorato561d3852010-11-20 18:09:34 -08001749 } else {
1750 parcel.writeInt(0);
1751 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001752
1753 parcel.writeInt(defaults);
1754 parcel.writeInt(this.flags);
1755
1756 if (sound != null) {
1757 parcel.writeInt(1);
1758 sound.writeToParcel(parcel, 0);
1759 } else {
1760 parcel.writeInt(0);
1761 }
1762 parcel.writeInt(audioStreamType);
John Spurlockc0650f022014-07-19 13:22:39 -04001763
1764 if (audioAttributes != null) {
1765 parcel.writeInt(1);
1766 audioAttributes.writeToParcel(parcel, 0);
1767 } else {
1768 parcel.writeInt(0);
1769 }
1770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 parcel.writeLongArray(vibrate);
1772 parcel.writeInt(ledARGB);
1773 parcel.writeInt(ledOnMS);
1774 parcel.writeInt(ledOffMS);
1775 parcel.writeInt(iconLevel);
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001776
1777 if (fullScreenIntent != null) {
1778 parcel.writeInt(1);
1779 fullScreenIntent.writeToParcel(parcel, 0);
1780 } else {
1781 parcel.writeInt(0);
1782 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001783
1784 parcel.writeInt(priority);
Joe Malin8d40d042012-11-05 11:36:40 -08001785
John Spurlockfd7f1e02014-03-18 16:41:57 -04001786 parcel.writeString(category);
Joe Malin8d40d042012-11-05 11:36:40 -08001787
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001788 parcel.writeString(mGroupKey);
1789
1790 parcel.writeString(mSortKey);
1791
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001792 parcel.writeBundle(extras); // null ok
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001793
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001794 parcel.writeTypedArray(actions, 0); // null ok
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001795
Daniel Sandlerf3b73432012-03-27 15:01:25 -04001796 if (bigContentView != null) {
1797 parcel.writeInt(1);
1798 bigContentView.writeToParcel(parcel, 0);
1799 } else {
1800 parcel.writeInt(0);
1801 }
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001802
Chris Wren8fd39ec2014-02-27 17:43:26 -05001803 if (headsUpContentView != null) {
1804 parcel.writeInt(1);
1805 headsUpContentView.writeToParcel(parcel, 0);
1806 } else {
1807 parcel.writeInt(0);
1808 }
1809
Dan Sandler0bf2ed82013-12-21 23:33:41 -06001810 parcel.writeInt(visibility);
1811
1812 if (publicVersion != null) {
1813 parcel.writeInt(1);
1814 publicVersion.writeToParcel(parcel, 0);
1815 } else {
1816 parcel.writeInt(0);
1817 }
Dan Sandler26e81cf2014-05-06 10:01:27 -04001818
1819 parcel.writeInt(color);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001820 }
1821
1822 /**
1823 * Parcelable.Creator that instantiates Notification objects
1824 */
1825 public static final Parcelable.Creator<Notification> CREATOR
1826 = new Parcelable.Creator<Notification>()
1827 {
1828 public Notification createFromParcel(Parcel parcel)
1829 {
1830 return new Notification(parcel);
1831 }
1832
1833 public Notification[] newArray(int size)
1834 {
1835 return new Notification[size];
1836 }
1837 };
1838
1839 /**
1840 * Sets the {@link #contentView} field to be a view with the standard "Latest Event"
1841 * layout.
1842 *
1843 * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields
1844 * in the view.</p>
1845 * @param context The context for your application / activity.
1846 * @param contentTitle The title that goes in the expanded entry.
1847 * @param contentText The text that goes in the expanded entry.
1848 * @param contentIntent The intent to launch when the user clicks the expanded notification.
1849 * If this is an activity, it must include the
1850 * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
Scott Main7aee61f2011-02-08 11:25:01 -08001851 * that you take care of task management as described in the
1852 * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
1853 * Stack</a> document.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001854 *
Joe Onorato46439ce2010-11-19 13:56:21 -08001855 * @deprecated Use {@link Builder} instead.
Chris Wrena05db382015-06-24 15:18:34 -04001856 * @removed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 */
Joe Onorato46439ce2010-11-19 13:56:21 -08001858 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001859 public void setLatestEventInfo(Context context,
1860 CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04001861 if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){
1862 Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.",
1863 new Throwable());
1864 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001865
Julia Reynoldsd9228f12015-10-20 10:37:27 -04001866 // ensure that any information already set directly is preserved
1867 final Notification.Builder builder = new Notification.Builder(context, this);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001868
1869 // now apply the latestEventInfo fields
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 if (contentTitle != null) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001871 builder.setContentTitle(contentTitle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001872 }
1873 if (contentText != null) {
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001874 builder.setContentText(contentText);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05001876 builder.setContentIntent(contentIntent);
Julia Reynoldsd9228f12015-10-20 10:37:27 -04001877
1878 builder.build(); // callers expect this notification to be ready to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 }
1880
Julia Reynoldsda303542015-11-23 14:00:20 -05001881 /**
1882 * @hide
1883 */
1884 public static void addFieldsFromContext(Context context, Notification notification) {
1885 if (notification.extras.getParcelable(EXTRA_BUILDER_APPLICATION_INFO) == null) {
1886 notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO,
1887 context.getApplicationInfo());
1888 }
1889 if (!notification.extras.containsKey(EXTRA_ORIGINATING_USERID)) {
1890 notification.extras.putInt(EXTRA_ORIGINATING_USERID, context.getUserId());
1891 }
1892 }
1893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001894 @Override
1895 public String toString() {
1896 StringBuilder sb = new StringBuilder();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001897 sb.append("Notification(pri=");
1898 sb.append(priority);
1899 sb.append(" contentView=");
Joe Onoratoc9596d62011-01-12 17:03:11 -08001900 if (contentView != null) {
1901 sb.append(contentView.getPackage());
1902 sb.append("/0x");
1903 sb.append(Integer.toHexString(contentView.getLayoutId()));
1904 } else {
1905 sb.append("null");
1906 }
1907 sb.append(" vibrate=");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001908 if ((this.defaults & DEFAULT_VIBRATE) != 0) {
1909 sb.append("default");
1910 } else if (this.vibrate != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 int N = this.vibrate.length-1;
1912 sb.append("[");
1913 for (int i=0; i<N; i++) {
1914 sb.append(this.vibrate[i]);
1915 sb.append(',');
1916 }
Simon Schoar8cf97d92009-06-10 22:08:37 +02001917 if (N != -1) {
1918 sb.append(this.vibrate[N]);
1919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001920 sb.append("]");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 } else {
1922 sb.append("null");
1923 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001924 sb.append(" sound=");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001925 if ((this.defaults & DEFAULT_SOUND) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 sb.append("default");
Daniel Sandler6738eee2012-11-16 12:03:32 -05001927 } else if (this.sound != null) {
1928 sb.append(this.sound.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 } else {
1930 sb.append("null");
1931 }
Chris Wren365b6d32015-07-16 10:39:26 -04001932 if (this.tickerText != null) {
1933 sb.append(" tick");
1934 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001935 sb.append(" defaults=0x");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001936 sb.append(Integer.toHexString(this.defaults));
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001937 sb.append(" flags=0x");
Daniel Sandlere46cbd32010-06-17 10:35:26 -04001938 sb.append(Integer.toHexString(this.flags));
Dan Sandler26e81cf2014-05-06 10:01:27 -04001939 sb.append(String.format(" color=0x%08x", this.color));
Griff Hazen5cadc3b2014-05-20 09:55:39 -07001940 if (this.category != null) {
1941 sb.append(" category=");
1942 sb.append(this.category);
1943 }
1944 if (this.mGroupKey != null) {
1945 sb.append(" groupKey=");
1946 sb.append(this.mGroupKey);
1947 }
1948 if (this.mSortKey != null) {
1949 sb.append(" sortKey=");
1950 sb.append(this.mSortKey);
1951 }
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001952 if (actions != null) {
Dan Sandler1b718782014-07-18 12:43:45 -04001953 sb.append(" actions=");
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001954 sb.append(actions.length);
Dan Sandler1b718782014-07-18 12:43:45 -04001955 }
1956 sb.append(" vis=");
1957 sb.append(visibilityToString(this.visibility));
1958 if (this.publicVersion != null) {
1959 sb.append(" publicVersion=");
1960 sb.append(publicVersion.toString());
Daniel Sandlera0a938c2012-03-15 08:42:37 -04001961 }
1962 sb.append(")");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 return sb.toString();
1964 }
Joe Onorato46439ce2010-11-19 13:56:21 -08001965
Dan Sandler1b718782014-07-18 12:43:45 -04001966 /**
1967 * {@hide}
1968 */
1969 public static String visibilityToString(int vis) {
1970 switch (vis) {
1971 case VISIBILITY_PRIVATE:
1972 return "PRIVATE";
1973 case VISIBILITY_PUBLIC:
1974 return "PUBLIC";
1975 case VISIBILITY_SECRET:
1976 return "SECRET";
1977 default:
1978 return "UNKNOWN(" + String.valueOf(vis) + ")";
1979 }
1980 }
1981
Joe Onoratocb109a02011-01-18 17:57:41 -08001982 /**
John Spurlock1d881a12015-03-18 19:21:54 -04001983 * {@hide}
1984 */
1985 public static String priorityToString(@Priority int pri) {
1986 switch (pri) {
1987 case PRIORITY_MIN:
1988 return "MIN";
1989 case PRIORITY_LOW:
1990 return "LOW";
1991 case PRIORITY_DEFAULT:
1992 return "DEFAULT";
1993 case PRIORITY_HIGH:
1994 return "HIGH";
1995 case PRIORITY_MAX:
1996 return "MAX";
1997 default:
1998 return "UNKNOWN(" + String.valueOf(pri) + ")";
1999 }
2000 }
2001
2002 /**
Dan Sandlerd63f9322015-05-06 15:18:49 -04002003 * The small icon representing this notification in the status bar and content view.
2004 *
2005 * @return the small icon representing this notification.
2006 *
2007 * @see Builder#getSmallIcon()
2008 * @see Builder#setSmallIcon(Icon)
2009 */
2010 public Icon getSmallIcon() {
2011 return mSmallIcon;
2012 }
2013
2014 /**
2015 * Used when notifying to clean up legacy small icons.
2016 * @hide
2017 */
2018 public void setSmallIcon(Icon icon) {
2019 mSmallIcon = icon;
2020 }
2021
2022 /**
2023 * The large icon shown in this notification's content view.
2024 * @see Builder#getLargeIcon()
2025 * @see Builder#setLargeIcon(Icon)
2026 */
2027 public Icon getLargeIcon() {
2028 return mLargeIcon;
2029 }
2030
2031 /**
Christoph Studer4600f9b2014-07-22 22:44:43 +02002032 * @hide
2033 */
Christoph Studerc8db24b2014-07-25 17:50:30 +02002034 public boolean isGroupSummary() {
2035 return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0;
2036 }
2037
2038 /**
2039 * @hide
2040 */
2041 public boolean isGroupChild() {
2042 return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0;
2043 }
2044
2045 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002046 * Builder class for {@link Notification} objects.
Joe Malin8d40d042012-11-05 11:36:40 -08002047 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002048 * Provides a convenient way to set the various fields of a {@link Notification} and generate
Scott Main183bf112012-08-13 19:12:13 -07002049 * content views using the platform's notification layout template. If your app supports
2050 * versions of Android as old as API level 4, you can instead use
2051 * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder},
2052 * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support
2053 * library</a>.
Joe Malin8d40d042012-11-05 11:36:40 -08002054 *
Scott Main183bf112012-08-13 19:12:13 -07002055 * <p>Example:
Joe Malin8d40d042012-11-05 11:36:40 -08002056 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002057 * <pre class="prettyprint">
Scott Main183bf112012-08-13 19:12:13 -07002058 * Notification noti = new Notification.Builder(mContext)
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002059 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
2060 * .setContentText(subject)
2061 * .setSmallIcon(R.drawable.new_mail)
2062 * .setLargeIcon(aBitmap)
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002063 * .build();
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002064 * </pre>
Joe Onoratocb109a02011-01-18 17:57:41 -08002065 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002066 public static class Builder {
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05002067 /**
2068 * @hide
2069 */
2070 public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT =
2071 "android.rebuild.contentViewActionCount";
2072 /**
2073 * @hide
2074 */
2075 public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT
2076 = "android.rebuild.bigViewActionCount";
2077 /**
2078 * @hide
2079 */
2080 public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT
2081 = "android.rebuild.hudViewActionCount";
2082
Daniel Sandler602ad1c2012-06-12 16:06:27 -04002083 private static final int MAX_ACTION_BUTTONS = 3;
Daniel Sandler8680bf82012-05-15 16:52:52 -04002084
Joe Onorato46439ce2010-11-19 13:56:21 -08002085 private Context mContext;
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002086 private Notification mN;
2087 private Bundle mUserExtras = new Bundle();
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002088 private Style mStyle;
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002089 private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS);
2090 private ArrayList<String> mPersonList = new ArrayList<String>();
2091 private NotificationColorUtil mColorUtil;
2092 private boolean mColorUtilInited = false;
Christoph Studer7ac80e62014-08-04 16:01:57 +02002093
2094 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002095 * Constructs a new Builder with the defaults:
Joe Onoratocb109a02011-01-18 17:57:41 -08002096 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002097
2098 * <table>
2099 * <tr><th align=right>priority</th>
2100 * <td>{@link #PRIORITY_DEFAULT}</td></tr>
2101 * <tr><th align=right>when</th>
2102 * <td>now ({@link System#currentTimeMillis()})</td></tr>
2103 * <tr><th align=right>audio stream</th>
2104 * <td>{@link #STREAM_DEFAULT}</td></tr>
2105 * </table>
Joe Onoratocb109a02011-01-18 17:57:41 -08002106 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002107
2108 * @param context
2109 * A {@link Context} that will be used by the Builder to construct the
2110 * RemoteViews. The Context will not be held past the lifetime of this Builder
2111 * object.
Joe Onoratocb109a02011-01-18 17:57:41 -08002112 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002113 public Builder(Context context) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002114 this(context, null);
Joe Onorato46439ce2010-11-19 13:56:21 -08002115 }
2116
Joe Onoratocb109a02011-01-18 17:57:41 -08002117 /**
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002118 * @hide
Christoph Studer4600f9b2014-07-22 22:44:43 +02002119 */
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002120 public Builder(Context context, Notification toAdopt) {
2121 mContext = context;
Christoph Studer4600f9b2014-07-22 22:44:43 +02002122
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002123 if (toAdopt == null) {
2124 mN = new Notification();
2125 mN.extras.putBoolean(EXTRA_SHOW_WHEN, true);
2126 mN.priority = PRIORITY_DEFAULT;
2127 mN.visibility = VISIBILITY_PRIVATE;
2128 } else {
2129 mN = toAdopt;
2130 if (mN.actions != null) {
2131 Collections.addAll(mActions, mN.actions);
Christoph Studer4600f9b2014-07-22 22:44:43 +02002132 }
2133
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002134 if (mN.extras.containsKey(EXTRA_PEOPLE)) {
2135 Collections.addAll(mPersonList, mN.extras.getStringArray(EXTRA_PEOPLE));
2136 }
2137
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002138 String templateClass = mN.extras.getString(EXTRA_TEMPLATE);
2139 if (!TextUtils.isEmpty(templateClass)) {
2140 final Class<? extends Style> styleClass
2141 = getNotificationStyleClass(templateClass);
2142 if (styleClass == null) {
2143 Log.d(TAG, "Unknown style class: " + templateClass);
2144 } else {
2145 try {
2146 final Constructor<? extends Style> ctor = styleClass.getConstructor();
2147 ctor.setAccessible(true);
2148 final Style style = ctor.newInstance();
2149 style.restoreFromExtras(mN.extras);
2150
2151 if (style != null) {
2152 setStyle(style);
2153 }
2154 } catch (Throwable t) {
2155 Log.e(TAG, "Could not create Style", t);
2156 }
2157 }
2158 }
2159
2160 }
2161 }
2162
2163 private NotificationColorUtil getColorUtil() {
2164 if (!mColorUtilInited) {
2165 mColorUtilInited = true;
2166 if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.LOLLIPOP) {
2167 mColorUtil = NotificationColorUtil.getInstance(mContext);
Christoph Studer4600f9b2014-07-22 22:44:43 +02002168 }
2169 }
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002170 return mColorUtil;
Christoph Studer4600f9b2014-07-22 22:44:43 +02002171 }
2172
2173 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002174 * Add a timestamp pertaining to the notification (usually the time the event occurred).
Daniel Sandler0c890492012-09-12 17:23:10 -07002175 * It will be shown in the notification content view by default; use
Griff Hazen50c11652014-05-16 09:46:31 -07002176 * {@link #setShowWhen(boolean) setShowWhen} to control this.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002177 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002178 * @see Notification#when
Joe Onoratocb109a02011-01-18 17:57:41 -08002179 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002180 public Builder setWhen(long when) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002181 mN.when = when;
Joe Onorato46439ce2010-11-19 13:56:21 -08002182 return this;
2183 }
2184
Joe Onoratocb109a02011-01-18 17:57:41 -08002185 /**
Griff Hazen50c11652014-05-16 09:46:31 -07002186 * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown
Daniel Sandler0c890492012-09-12 17:23:10 -07002187 * in the content view.
2188 */
2189 public Builder setShowWhen(boolean show) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002190 mN.extras.putBoolean(EXTRA_SHOW_WHEN, show);
Daniel Sandler0c890492012-09-12 17:23:10 -07002191 return this;
2192 }
2193
2194 /**
Daniel Sandlerd33b8032012-05-10 11:41:48 -04002195 * Show the {@link Notification#when} field as a stopwatch.
Joe Malin8d40d042012-11-05 11:36:40 -08002196 *
2197 * Instead of presenting <code>when</code> as a timestamp, the notification will show an
Daniel Sandlerd33b8032012-05-10 11:41:48 -04002198 * automatically updating display of the minutes and seconds since <code>when</code>.
Daniel Sandlera2985ed2012-04-03 16:42:00 -04002199 *
Daniel Sandlerd33b8032012-05-10 11:41:48 -04002200 * Useful when showing an elapsed time (like an ongoing phone call).
2201 *
Selim Cinek81c23aa2016-02-25 16:23:13 -08002202 * The counter can also be set to count down to <code>when</code> when using
2203 * {@link #setChronometerCountsDown(boolean)}.
2204 *
Daniel Sandlerd33b8032012-05-10 11:41:48 -04002205 * @see android.widget.Chronometer
Daniel Sandlera2985ed2012-04-03 16:42:00 -04002206 * @see Notification#when
Selim Cinek81c23aa2016-02-25 16:23:13 -08002207 * @see #setChronometerCountsDown(boolean)
Daniel Sandlera2985ed2012-04-03 16:42:00 -04002208 */
2209 public Builder setUsesChronometer(boolean b) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002210 mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b);
Daniel Sandlera2985ed2012-04-03 16:42:00 -04002211 return this;
2212 }
2213
2214 /**
Selim Cinek81c23aa2016-02-25 16:23:13 -08002215 * Sets the Chronometer to count down instead of counting up.
2216 *
2217 * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true.
2218 * If it isn't set the chronometer will count up.
2219 *
2220 * @see #setUsesChronometer(boolean)
2221 */
2222 public Builder setChronometerCountsDown(boolean countsDown) {
2223 mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN, countsDown);
2224 return this;
2225 }
2226
2227 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002228 * Set the small icon resource, which will be used to represent the notification in the
2229 * status bar.
Joe Onoratocb109a02011-01-18 17:57:41 -08002230 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002231
2232 * The platform template for the expanded view will draw this icon in the left, unless a
2233 * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small
2234 * icon will be moved to the right-hand side.
2235 *
2236
2237 * @param icon
2238 * A resource ID in the application's package of the drawable to use.
2239 * @see Notification#icon
Joe Onoratocb109a02011-01-18 17:57:41 -08002240 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07002241 public Builder setSmallIcon(@DrawableRes int icon) {
Dan Sandlerd63f9322015-05-06 15:18:49 -04002242 return setSmallIcon(icon != 0
2243 ? Icon.createWithResource(mContext, icon)
2244 : null);
Joe Onorato46439ce2010-11-19 13:56:21 -08002245 }
2246
Joe Onoratocb109a02011-01-18 17:57:41 -08002247 /**
2248 * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional
2249 * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable
2250 * LevelListDrawable}.
2251 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002252 * @param icon A resource ID in the application's package of the drawable to use.
Joe Onoratocb109a02011-01-18 17:57:41 -08002253 * @param level The level to use for the icon.
2254 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002255 * @see Notification#icon
2256 * @see Notification#iconLevel
Joe Onoratocb109a02011-01-18 17:57:41 -08002257 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07002258 public Builder setSmallIcon(@DrawableRes int icon, int level) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002259 mN.iconLevel = level;
Dan Sandlerd63f9322015-05-06 15:18:49 -04002260 return setSmallIcon(icon);
2261 }
2262
2263 /**
2264 * Set the small icon, which will be used to represent the notification in the
2265 * status bar and content view (unless overriden there by a
2266 * {@link #setLargeIcon(Bitmap) large icon}).
2267 *
2268 * @param icon An Icon object to use.
2269 * @see Notification#icon
2270 */
2271 public Builder setSmallIcon(Icon icon) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002272 mN.setSmallIcon(icon);
2273 if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) {
2274 mN.icon = icon.getResId();
2275 }
Joe Onorato46439ce2010-11-19 13:56:21 -08002276 return this;
2277 }
2278
Joe Onoratocb109a02011-01-18 17:57:41 -08002279 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002280 * Set the first line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08002281 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002282 public Builder setContentTitle(CharSequence title) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002283 mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title));
Joe Onorato46439ce2010-11-19 13:56:21 -08002284 return this;
2285 }
2286
Joe Onoratocb109a02011-01-18 17:57:41 -08002287 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002288 * Set the second line of text in the platform notification template.
Joe Onoratocb109a02011-01-18 17:57:41 -08002289 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002290 public Builder setContentText(CharSequence text) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002291 mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text));
Joe Onorato46439ce2010-11-19 13:56:21 -08002292 return this;
2293 }
2294
Joe Onoratocb109a02011-01-18 17:57:41 -08002295 /**
Joe Malin8d40d042012-11-05 11:36:40 -08002296 * Set the third line of text in the platform notification template.
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002297 * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the
2298 * same location in the standard template.
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002299 */
2300 public Builder setSubText(CharSequence text) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002301 mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text));
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002302 return this;
2303 }
2304
2305 /**
Adrian Roose458aa82015-12-08 16:17:19 -08002306 * Set the remote input history.
2307 *
2308 * This should be set to the most recent inputs that have been sent
2309 * through a {@link RemoteInput} of this Notification and cleared once the it is no
2310 * longer relevant (e.g. for chat notifications once the other party has responded).
2311 *
2312 * The most recent input must be stored at the 0 index, the second most recent at the
2313 * 1 index, etc. Note that the system will limit both how far back the inputs will be shown
2314 * and how much of each individual input is shown.
2315 *
2316 * <p>Note: The reply text will only be shown on notifications that have least one action
2317 * with a {@code RemoteInput}.</p>
2318 */
2319 public Builder setRemoteInputHistory(CharSequence[] text) {
2320 if (text == null) {
2321 mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null);
2322 } else {
2323 final int N = Math.min(MAX_REPLY_HISTORY, text.length);
2324 CharSequence[] safe = new CharSequence[N];
2325 for (int i = 0; i < N; i++) {
2326 safe[i] = safeCharSequence(text[i]);
2327 }
2328 mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe);
2329 }
2330 return this;
2331 }
2332
2333 /**
Joe Onoratocb109a02011-01-18 17:57:41 -08002334 * Set the large number at the right-hand side of the notification. This is
2335 * equivalent to setContentInfo, although it might show the number in a different
2336 * font size for readability.
2337 */
Joe Onorato8595a3d2010-11-19 18:12:07 -08002338 public Builder setNumber(int number) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002339 mN.number = number;
Joe Onorato8595a3d2010-11-19 18:12:07 -08002340 return this;
2341 }
2342
Joe Onoratocb109a02011-01-18 17:57:41 -08002343 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002344 * A small piece of additional information pertaining to this notification.
2345 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002346 * The platform template will draw this on the last line of the notification, at the far
2347 * right (to the right of a smallIcon if it has been placed there).
Joe Onoratocb109a02011-01-18 17:57:41 -08002348 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002349 public Builder setContentInfo(CharSequence info) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002350 mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info));
Joe Onorato46439ce2010-11-19 13:56:21 -08002351 return this;
2352 }
2353
Joe Onoratocb109a02011-01-18 17:57:41 -08002354 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002355 * Set the progress this notification represents.
2356 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002357 * The platform template will represent this using a {@link ProgressBar}.
Jeff Sharkey1c400132011-08-05 14:50:13 -07002358 */
2359 public Builder setProgress(int max, int progress, boolean indeterminate) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002360 mN.extras.putInt(EXTRA_PROGRESS, progress);
2361 mN.extras.putInt(EXTRA_PROGRESS_MAX, max);
2362 mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate);
Jeff Sharkey1c400132011-08-05 14:50:13 -07002363 return this;
2364 }
2365
2366 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002367 * Supply a custom RemoteViews to use instead of the platform template.
2368 *
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002369 * Use {@link #setCustomContentView(RemoteViews)} instead.
Joe Onoratocb109a02011-01-18 17:57:41 -08002370 */
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002371 @Deprecated
Joe Onorato46439ce2010-11-19 13:56:21 -08002372 public Builder setContent(RemoteViews views) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002373 return setCustomContentView(views);
2374 }
2375
2376 /**
2377 * Supply custom RemoteViews to use instead of the platform template.
2378 *
2379 * This will override the layout that would otherwise be constructed by this Builder
2380 * object.
2381 */
2382 public Builder setCustomContentView(RemoteViews contentView) {
2383 mN.contentView = contentView;
2384 return this;
2385 }
2386
2387 /**
2388 * Supply custom RemoteViews to use instead of the platform template in the expanded form.
2389 *
2390 * This will override the expanded layout that would otherwise be constructed by this
2391 * Builder object.
2392 */
2393 public Builder setCustomBigContentView(RemoteViews contentView) {
2394 mN.bigContentView = contentView;
2395 return this;
2396 }
2397
2398 /**
2399 * Supply custom RemoteViews to use instead of the platform template in the heads up dialog.
2400 *
2401 * This will override the heads-up layout that would otherwise be constructed by this
2402 * Builder object.
2403 */
2404 public Builder setCustomHeadsUpContentView(RemoteViews contentView) {
2405 mN.headsUpContentView = contentView;
Joe Onorato46439ce2010-11-19 13:56:21 -08002406 return this;
2407 }
2408
Joe Onoratocb109a02011-01-18 17:57:41 -08002409 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002410 * Supply a {@link PendingIntent} to be sent when the notification is clicked.
2411 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002412 * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you
2413 * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use
2414 * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)}
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002415 * to assign PendingIntents to individual views in that custom layout (i.e., to create
Daniel Sandlerf3b73432012-03-27 15:01:25 -04002416 * clickable buttons inside the notification view).
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002417 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002418 * @see Notification#contentIntent Notification.contentIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08002419 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002420 public Builder setContentIntent(PendingIntent intent) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002421 mN.contentIntent = intent;
Joe Onorato46439ce2010-11-19 13:56:21 -08002422 return this;
2423 }
2424
Joe Onoratocb109a02011-01-18 17:57:41 -08002425 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002426 * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user.
2427 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002428 * @see Notification#deleteIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08002429 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002430 public Builder setDeleteIntent(PendingIntent intent) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002431 mN.deleteIntent = intent;
Joe Onorato46439ce2010-11-19 13:56:21 -08002432 return this;
2433 }
2434
Joe Onoratocb109a02011-01-18 17:57:41 -08002435 /**
2436 * An intent to launch instead of posting the notification to the status bar.
2437 * Only for use with extremely high-priority notifications demanding the user's
2438 * <strong>immediate</strong> attention, such as an incoming phone call or
2439 * alarm clock that the user has explicitly set to a particular time.
2440 * If this facility is used for something else, please give the user an option
2441 * to turn it off and use a normal notification, as this can be extremely
2442 * disruptive.
2443 *
Chris Wren47c20a12014-06-18 17:27:29 -04002444 * <p>
2445 * The system UI may choose to display a heads-up notification, instead of
2446 * launching this intent, while the user is using the device.
2447 * </p>
2448 *
Joe Onoratocb109a02011-01-18 17:57:41 -08002449 * @param intent The pending intent to launch.
2450 * @param highPriority Passing true will cause this notification to be sent
2451 * even if other notifications are suppressed.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002452 *
2453 * @see Notification#fullScreenIntent
Joe Onoratocb109a02011-01-18 17:57:41 -08002454 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002455 public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002456 mN.fullScreenIntent = intent;
Joe Onorato46439ce2010-11-19 13:56:21 -08002457 setFlag(FLAG_HIGH_PRIORITY, highPriority);
2458 return this;
2459 }
2460
Joe Onoratocb109a02011-01-18 17:57:41 -08002461 /**
Dan Sandler5fcdf6e2014-07-18 11:31:15 -04002462 * Set the "ticker" text which is sent to accessibility services.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002463 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002464 * @see Notification#tickerText
Joe Onoratocb109a02011-01-18 17:57:41 -08002465 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002466 public Builder setTicker(CharSequence tickerText) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002467 mN.tickerText = safeCharSequence(tickerText);
Joe Onorato46439ce2010-11-19 13:56:21 -08002468 return this;
2469 }
2470
Joe Onoratocb109a02011-01-18 17:57:41 -08002471 /**
Dan Sandler5fcdf6e2014-07-18 11:31:15 -04002472 * Obsolete version of {@link #setTicker(CharSequence)}.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002473 *
Joe Onoratocb109a02011-01-18 17:57:41 -08002474 */
Dan Sandler5fcdf6e2014-07-18 11:31:15 -04002475 @Deprecated
Joe Onorato46439ce2010-11-19 13:56:21 -08002476 public Builder setTicker(CharSequence tickerText, RemoteViews views) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002477 setTicker(tickerText);
2478 // views is ignored
Joe Onorato46439ce2010-11-19 13:56:21 -08002479 return this;
2480 }
2481
Joe Onoratocb109a02011-01-18 17:57:41 -08002482 /**
Dan Sandlerd63f9322015-05-06 15:18:49 -04002483 * Add a large icon to the notification content view.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002484 *
2485 * In the platform template, this image will be shown on the left of the notification view
Dan Sandlerd63f9322015-05-06 15:18:49 -04002486 * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small
2487 * badge atop the large icon).
Dan Sandler08a04c12015-05-06 15:18:49 -04002488 */
Dan Sandlerd63f9322015-05-06 15:18:49 -04002489 public Builder setLargeIcon(Bitmap b) {
2490 return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null);
2491 }
2492
2493 /**
2494 * Add a large icon to the notification content view.
2495 *
2496 * In the platform template, this image will be shown on the left of the notification view
2497 * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small
2498 * badge atop the large icon).
2499 */
2500 public Builder setLargeIcon(Icon icon) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002501 mN.mLargeIcon = icon;
2502 mN.extras.putParcelable(EXTRA_LARGE_ICON, icon);
Joe Onorato46439ce2010-11-19 13:56:21 -08002503 return this;
2504 }
2505
Joe Onoratocb109a02011-01-18 17:57:41 -08002506 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002507 * Set the sound to play.
2508 *
John Spurlockc0650f022014-07-19 13:22:39 -04002509 * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes}
2510 * for notifications.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002511 *
Chris Wren47c20a12014-06-18 17:27:29 -04002512 * <p>
2513 * A notification that is noisy is more likely to be presented as a heads-up notification.
2514 * </p>
2515 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002516 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08002517 */
Joe Onorato52f80cd2010-11-21 15:34:48 -08002518 public Builder setSound(Uri sound) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002519 mN.sound = sound;
2520 mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT;
Joe Onorato52f80cd2010-11-21 15:34:48 -08002521 return this;
2522 }
2523
Joe Onoratocb109a02011-01-18 17:57:41 -08002524 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002525 * Set the sound to play, along with a specific stream on which to play it.
Joe Onoratocb109a02011-01-18 17:57:41 -08002526 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002527 * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants.
2528 *
Chris Wren47c20a12014-06-18 17:27:29 -04002529 * <p>
2530 * A notification that is noisy is more likely to be presented as a heads-up notification.
2531 * </p>
John Spurlockc0650f022014-07-19 13:22:39 -04002532 * @deprecated use {@link #setSound(Uri, AudioAttributes)} instead.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002533 * @see Notification#sound
Joe Onoratocb109a02011-01-18 17:57:41 -08002534 */
Jean-Michel Trivi81f871e2014-08-06 16:32:38 -07002535 @Deprecated
Joe Onorato46439ce2010-11-19 13:56:21 -08002536 public Builder setSound(Uri sound, int streamType) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002537 mN.sound = sound;
2538 mN.audioStreamType = streamType;
Joe Onorato46439ce2010-11-19 13:56:21 -08002539 return this;
2540 }
2541
Joe Onoratocb109a02011-01-18 17:57:41 -08002542 /**
John Spurlockc0650f022014-07-19 13:22:39 -04002543 * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to
2544 * use during playback.
2545 *
2546 * <p>
2547 * A notification that is noisy is more likely to be presented as a heads-up notification.
2548 * </p>
2549 *
2550 * @see Notification#sound
2551 */
2552 public Builder setSound(Uri sound, AudioAttributes audioAttributes) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002553 mN.sound = sound;
2554 mN.audioAttributes = audioAttributes;
John Spurlockc0650f022014-07-19 13:22:39 -04002555 return this;
2556 }
2557
2558 /**
Joe Onoratocb109a02011-01-18 17:57:41 -08002559 * Set the vibration pattern to use.
2560 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002561 * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the
2562 * <code>pattern</code> parameter.
2563 *
Chris Wren47c20a12014-06-18 17:27:29 -04002564 * <p>
2565 * A notification that vibrates is more likely to be presented as a heads-up notification.
2566 * </p>
2567 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002568 * @see Notification#vibrate
Joe Onoratocb109a02011-01-18 17:57:41 -08002569 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002570 public Builder setVibrate(long[] pattern) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002571 mN.vibrate = pattern;
Joe Onorato46439ce2010-11-19 13:56:21 -08002572 return this;
2573 }
2574
Joe Onoratocb109a02011-01-18 17:57:41 -08002575 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002576 * Set the desired color for the indicator LED on the device, as well as the
2577 * blink duty cycle (specified in milliseconds).
2578 *
2579
2580 * Not all devices will honor all (or even any) of these values.
2581 *
2582
2583 * @see Notification#ledARGB
2584 * @see Notification#ledOnMS
2585 * @see Notification#ledOffMS
Joe Onoratocb109a02011-01-18 17:57:41 -08002586 */
Tor Norbye80756e32015-03-02 09:39:27 -08002587 public Builder setLights(@ColorInt int argb, int onMs, int offMs) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002588 mN.ledARGB = argb;
2589 mN.ledOnMS = onMs;
2590 mN.ledOffMS = offMs;
Julia Reynolds10ee1fc2015-11-09 11:04:55 -05002591 if (onMs != 0 || offMs != 0) {
2592 mN.flags |= FLAG_SHOW_LIGHTS;
2593 }
Joe Onorato46439ce2010-11-19 13:56:21 -08002594 return this;
2595 }
2596
Joe Onoratocb109a02011-01-18 17:57:41 -08002597 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002598 * Set whether this is an "ongoing" notification.
Joe Onoratocb109a02011-01-18 17:57:41 -08002599 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002600
2601 * Ongoing notifications cannot be dismissed by the user, so your application or service
2602 * must take care of canceling them.
2603 *
2604
2605 * They are typically used to indicate a background task that the user is actively engaged
2606 * with (e.g., playing music) or is pending in some way and therefore occupying the device
2607 * (e.g., a file download, sync operation, active network connection).
2608 *
2609
2610 * @see Notification#FLAG_ONGOING_EVENT
2611 * @see Service#setForeground(boolean)
Joe Onoratocb109a02011-01-18 17:57:41 -08002612 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002613 public Builder setOngoing(boolean ongoing) {
2614 setFlag(FLAG_ONGOING_EVENT, ongoing);
2615 return this;
2616 }
2617
Joe Onoratocb109a02011-01-18 17:57:41 -08002618 /**
2619 * Set this flag if you would only like the sound, vibrate
2620 * and ticker to be played if the notification is not already showing.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002621 *
2622 * @see Notification#FLAG_ONLY_ALERT_ONCE
Joe Onoratocb109a02011-01-18 17:57:41 -08002623 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002624 public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
2625 setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
2626 return this;
2627 }
2628
Joe Onoratocb109a02011-01-18 17:57:41 -08002629 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002630 * Make this notification automatically dismissed when the user touches it. The
2631 * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens.
2632 *
2633 * @see Notification#FLAG_AUTO_CANCEL
Joe Onoratocb109a02011-01-18 17:57:41 -08002634 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002635 public Builder setAutoCancel(boolean autoCancel) {
Joe Onorato281d83f2011-01-04 17:13:10 -08002636 setFlag(FLAG_AUTO_CANCEL, autoCancel);
Joe Onorato46439ce2010-11-19 13:56:21 -08002637 return this;
2638 }
2639
Joe Onoratocb109a02011-01-18 17:57:41 -08002640 /**
Griff Hazendfcb0802014-02-11 12:00:00 -08002641 * Set whether or not this notification should not bridge to other devices.
2642 *
2643 * <p>Some notifications can be bridged to other devices for remote display.
2644 * This hint can be set to recommend this notification not be bridged.
2645 */
2646 public Builder setLocalOnly(boolean localOnly) {
2647 setFlag(FLAG_LOCAL_ONLY, localOnly);
2648 return this;
2649 }
2650
2651 /**
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002652 * Set which notification properties will be inherited from system defaults.
Joe Onoratocb109a02011-01-18 17:57:41 -08002653 * <p>
2654 * The value should be one or more of the following fields combined with
2655 * bitwise-or:
2656 * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}.
2657 * <p>
2658 * For all default values, use {@link #DEFAULT_ALL}.
2659 */
Joe Onorato46439ce2010-11-19 13:56:21 -08002660 public Builder setDefaults(int defaults) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002661 mN.defaults = defaults;
Joe Onorato46439ce2010-11-19 13:56:21 -08002662 return this;
2663 }
2664
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002665 /**
2666 * Set the priority of this notification.
2667 *
2668 * @see Notification#priority
2669 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002670 public Builder setPriority(@Priority int pri) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002671 mN.priority = pri;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002672 return this;
2673 }
Joe Malin8d40d042012-11-05 11:36:40 -08002674
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002675 /**
John Spurlockfd7f1e02014-03-18 16:41:57 -04002676 * Set the notification category.
Joe Malin8d40d042012-11-05 11:36:40 -08002677 *
John Spurlockfd7f1e02014-03-18 16:41:57 -04002678 * @see Notification#category
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002679 */
John Spurlockfd7f1e02014-03-18 16:41:57 -04002680 public Builder setCategory(String category) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002681 mN.category = category;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002682 return this;
2683 }
2684
2685 /**
Chris Wrendde75302014-03-26 17:24:15 -04002686 * Add a person that is relevant to this notification.
2687 *
Chris Wrene6c48932014-09-29 17:19:27 -04002688 * <P>
2689 * Depending on user preferences, this annotation may allow the notification to pass
2690 * through interruption filters, and to appear more prominently in the user interface.
2691 * </P>
2692 *
2693 * <P>
2694 * The person should be specified by the {@code String} representation of a
2695 * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}.
2696 * </P>
2697 *
2698 * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema
2699 * URIs. The path part of these URIs must exist in the contacts database, in the
2700 * appropriate column, or the reference will be discarded as invalid. Telephone schema
2701 * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}.
2702 * </P>
2703 *
2704 * @param uri A URI for the person.
Chris Wrendde75302014-03-26 17:24:15 -04002705 * @see Notification#EXTRA_PEOPLE
2706 */
Chris Wrene6c48932014-09-29 17:19:27 -04002707 public Builder addPerson(String uri) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002708 mPersonList.add(uri);
Chris Wrendde75302014-03-26 17:24:15 -04002709 return this;
2710 }
2711
2712 /**
Griff Hazen5cadc3b2014-05-20 09:55:39 -07002713 * Set this notification to be part of a group of notifications sharing the same key.
2714 * Grouped notifications may display in a cluster or stack on devices which
2715 * support such rendering.
2716 *
2717 * <p>To make this notification the summary for its group, also call
2718 * {@link #setGroupSummary}. A sort order can be specified for group members by using
2719 * {@link #setSortKey}.
2720 * @param groupKey The group key of the group.
2721 * @return this object for method chaining
2722 */
2723 public Builder setGroup(String groupKey) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002724 mN.mGroupKey = groupKey;
Griff Hazen5cadc3b2014-05-20 09:55:39 -07002725 return this;
2726 }
2727
2728 /**
2729 * Set this notification to be the group summary for a group of notifications.
2730 * Grouped notifications may display in a cluster or stack on devices which
2731 * support such rendering. Requires a group key also be set using {@link #setGroup}.
2732 * @param isGroupSummary Whether this notification should be a group summary.
2733 * @return this object for method chaining
2734 */
2735 public Builder setGroupSummary(boolean isGroupSummary) {
2736 setFlag(FLAG_GROUP_SUMMARY, isGroupSummary);
2737 return this;
2738 }
2739
2740 /**
2741 * Set a sort key that orders this notification among other notifications from the
2742 * same package. This can be useful if an external sort was already applied and an app
2743 * would like to preserve this. Notifications will be sorted lexicographically using this
2744 * value, although providing different priorities in addition to providing sort key may
2745 * cause this value to be ignored.
2746 *
2747 * <p>This sort key can also be used to order members of a notification group. See
Griff Hazen9e1379f2014-05-20 12:50:51 -07002748 * {@link #setGroup}.
Griff Hazen5cadc3b2014-05-20 09:55:39 -07002749 *
2750 * @see String#compareTo(String)
2751 */
2752 public Builder setSortKey(String sortKey) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002753 mN.mSortKey = sortKey;
Griff Hazen5cadc3b2014-05-20 09:55:39 -07002754 return this;
2755 }
2756
2757 /**
Griff Hazen720042b2014-02-24 15:46:56 -08002758 * Merge additional metadata into this notification.
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002759 *
Griff Hazen720042b2014-02-24 15:46:56 -08002760 * <p>Values within the Bundle will replace existing extras values in this Builder.
2761 *
2762 * @see Notification#extras
2763 */
Griff Hazen959591e2014-05-15 22:26:18 -07002764 public Builder addExtras(Bundle extras) {
2765 if (extras != null) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002766 mUserExtras.putAll(extras);
Griff Hazen720042b2014-02-24 15:46:56 -08002767 }
2768 return this;
2769 }
2770
2771 /**
2772 * Set metadata for this notification.
2773 *
2774 * <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 -04002775 * current contents are copied into the Notification each time {@link #build()} is
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002776 * called.
2777 *
Griff Hazen720042b2014-02-24 15:46:56 -08002778 * <p>Replaces any existing extras values with those from the provided Bundle.
2779 * Use {@link #addExtras} to merge in metadata instead.
2780 *
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002781 * @see Notification#extras
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002782 */
Griff Hazen959591e2014-05-15 22:26:18 -07002783 public Builder setExtras(Bundle extras) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002784 if (extras != null) {
2785 mUserExtras = extras;
2786 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05002787 return this;
2788 }
2789
Daniel Sandlera0a938c2012-03-15 08:42:37 -04002790 /**
Griff Hazen720042b2014-02-24 15:46:56 -08002791 * Get the current metadata Bundle used by this notification Builder.
2792 *
2793 * <p>The returned Bundle is shared with this Builder.
2794 *
2795 * <p>The current contents of this Bundle are copied into the Notification each time
2796 * {@link #build()} is called.
2797 *
2798 * @see Notification#extras
2799 */
2800 public Bundle getExtras() {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002801 return mUserExtras;
2802 }
2803
2804 private Bundle getAllExtras() {
2805 final Bundle saveExtras = (Bundle) mUserExtras.clone();
2806 saveExtras.putAll(mN.extras);
2807 return saveExtras;
Griff Hazen720042b2014-02-24 15:46:56 -08002808 }
2809
2810 /**
Daniel Sandlera0a938c2012-03-15 08:42:37 -04002811 * Add an action to this notification. Actions are typically displayed by
2812 * the system as a button adjacent to the notification content.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04002813 * <p>
2814 * Every action must have an icon (32dp square and matching the
2815 * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo
2816 * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}.
2817 * <p>
2818 * A notification in its expanded form can display up to 3 actions, from left to right in
2819 * the order they were added. Actions will not be displayed when the notification is
2820 * collapsed, however, so be sure that any essential functions may be accessed by the user
2821 * in some other way (for example, in the Activity pointed to by {@link #contentIntent}).
Daniel Sandlera0a938c2012-03-15 08:42:37 -04002822 *
2823 * @param icon Resource ID of a drawable that represents the action.
2824 * @param title Text describing the action.
2825 * @param intent PendingIntent to be fired when the action is invoked.
Dan Sandler86647982015-05-13 23:41:13 -04002826 *
2827 * @deprecated Use {@link #addAction(Action)} instead.
Daniel Sandlera0a938c2012-03-15 08:42:37 -04002828 */
Dan Sandler86647982015-05-13 23:41:13 -04002829 @Deprecated
Daniel Sandlera0a938c2012-03-15 08:42:37 -04002830 public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04002831 mActions.add(new Action(icon, safeCharSequence(title), intent));
Daniel Sandlera0a938c2012-03-15 08:42:37 -04002832 return this;
2833 }
2834
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002835 /**
Griff Hazen959591e2014-05-15 22:26:18 -07002836 * Add an action to this notification. Actions are typically displayed by
2837 * the system as a button adjacent to the notification content.
2838 * <p>
2839 * Every action must have an icon (32dp square and matching the
2840 * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo
2841 * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}.
2842 * <p>
2843 * A notification in its expanded form can display up to 3 actions, from left to right in
2844 * the order they were added. Actions will not be displayed when the notification is
2845 * collapsed, however, so be sure that any essential functions may be accessed by the user
2846 * in some other way (for example, in the Activity pointed to by {@link #contentIntent}).
2847 *
2848 * @param action The action to add.
2849 */
2850 public Builder addAction(Action action) {
2851 mActions.add(action);
2852 return this;
2853 }
2854
2855 /**
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002856 * Alter the complete list of actions attached to this notification.
2857 * @see #addAction(Action).
2858 *
2859 * @param actions
2860 * @return
2861 */
2862 public Builder setActions(Action... actions) {
2863 mActions.clear();
2864 for (int i = 0; i < actions.length; i++) {
2865 mActions.add(actions[i]);
2866 }
2867 return this;
2868 }
2869
2870 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002871 * Add a rich notification style to be applied at build time.
2872 *
2873 * @param style Object responsible for modifying the notification style.
2874 */
2875 public Builder setStyle(Style style) {
2876 if (mStyle != style) {
2877 mStyle = style;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07002878 if (mStyle != null) {
2879 mStyle.setBuilder(this);
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002880 mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName());
2881 } else {
2882 mN.extras.remove(EXTRA_TEMPLATE);
Daniel Sandlerc08dea22012-06-28 08:35:24 -07002883 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04002884 }
2885 return this;
2886 }
2887
Dan Sandler0bf2ed82013-12-21 23:33:41 -06002888 /**
2889 * Specify the value of {@link #visibility}.
Griff Hazenb720abe2014-05-20 13:15:30 -07002890 *
Dan Sandler0bf2ed82013-12-21 23:33:41 -06002891 * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default),
2892 * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}.
2893 *
2894 * @return The same Builder.
2895 */
2896 public Builder setVisibility(int visibility) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002897 mN.visibility = visibility;
Dan Sandler0bf2ed82013-12-21 23:33:41 -06002898 return this;
2899 }
2900
2901 /**
2902 * Supply a replacement Notification whose contents should be shown in insecure contexts
2903 * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}.
2904 * @param n A replacement notification, presumably with some or all info redacted.
2905 * @return The same Builder.
2906 */
2907 public Builder setPublicVersion(Notification n) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002908 if (n != null) {
2909 mN.publicVersion = new Notification();
2910 n.cloneInto(mN.publicVersion, /*heavy=*/ true);
2911 } else {
2912 mN.publicVersion = null;
2913 }
Dan Sandler0bf2ed82013-12-21 23:33:41 -06002914 return this;
2915 }
2916
Griff Hazenb720abe2014-05-20 13:15:30 -07002917 /**
Griff Hazen5cadc3b2014-05-20 09:55:39 -07002918 * Apply an extender to this notification builder. Extenders may be used to add
2919 * metadata or change options on this builder.
2920 */
Griff Hazen61a9e862014-05-22 16:05:19 -07002921 public Builder extend(Extender extender) {
2922 extender.extend(this);
Griff Hazen5cadc3b2014-05-20 09:55:39 -07002923 return this;
2924 }
2925
Dan Sandler4e787062015-06-17 15:09:48 -04002926 /**
2927 * @hide
2928 */
2929 public void setFlag(int mask, boolean value) {
Joe Onorato46439ce2010-11-19 13:56:21 -08002930 if (value) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002931 mN.flags |= mask;
Joe Onorato46439ce2010-11-19 13:56:21 -08002932 } else {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002933 mN.flags &= ~mask;
Joe Onorato46439ce2010-11-19 13:56:21 -08002934 }
2935 }
2936
Dan Sandler26e81cf2014-05-06 10:01:27 -04002937 /**
2938 * Sets {@link Notification#color}.
2939 *
2940 * @param argb The accent color to use
2941 *
2942 * @return The same Builder.
2943 */
Tor Norbye80756e32015-03-02 09:39:27 -08002944 public Builder setColor(@ColorInt int argb) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04002945 mN.color = argb;
Julia Reynolds10ee1fc2015-11-09 11:04:55 -05002946 sanitizeColor();
Dan Sandler26e81cf2014-05-06 10:01:27 -04002947 return this;
2948 }
2949
Jorim Jaggid05aa3e2014-08-28 17:52:27 +02002950 private Drawable getProfileBadgeDrawable() {
Christoph Studer7ac80e62014-08-04 16:01:57 +02002951 // Note: This assumes that the current user can read the profile badge of the
2952 // originating user.
Selim Cineke6ff9462016-01-15 15:07:06 -08002953 return mContext.getPackageManager().getUserBadgeForDensityNoBackground(
Julia Reynoldsda303542015-11-23 14:00:20 -05002954 new UserHandle(mContext.getUserId()), 0);
Jorim Jaggid05aa3e2014-08-28 17:52:27 +02002955 }
2956
2957 private Bitmap getProfileBadge() {
2958 Drawable badge = getProfileBadgeDrawable();
Kenny Guy8a0101b2014-05-08 23:34:12 +01002959 if (badge == null) {
2960 return null;
2961 }
Jorim Jaggid05aa3e2014-08-28 17:52:27 +02002962 final int size = mContext.getResources().getDimensionPixelSize(
2963 R.dimen.notification_badge_size);
2964 Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Kenny Guy8a0101b2014-05-08 23:34:12 +01002965 Canvas canvas = new Canvas(bitmap);
Jorim Jaggid05aa3e2014-08-28 17:52:27 +02002966 badge.setBounds(0, 0, size, size);
Kenny Guy8a0101b2014-05-08 23:34:12 +01002967 badge.draw(canvas);
2968 return bitmap;
2969 }
2970
Selim Cinekc848c3a2016-01-13 15:27:30 -08002971 private void bindProfileBadge(RemoteViews contentView) {
Kenny Guy98193ea2014-07-24 19:54:37 +01002972 Bitmap profileBadge = getProfileBadge();
2973
Kenny Guy98193ea2014-07-24 19:54:37 +01002974 if (profileBadge != null) {
Selim Cinekc848c3a2016-01-13 15:27:30 -08002975 contentView.setImageViewBitmap(R.id.profile_badge, profileBadge);
2976 contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE);
Kenny Guy98193ea2014-07-24 19:54:37 +01002977 }
Kenny Guy98193ea2014-07-24 19:54:37 +01002978 }
2979
Christoph Studerfe718432014-09-01 18:21:18 +02002980 private void resetStandardTemplate(RemoteViews contentView) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08002981 resetNotificationHeader(contentView);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07002982 resetContentMargins(contentView);
Christoph Studerfe718432014-09-01 18:21:18 +02002983 contentView.setViewVisibility(R.id.right_icon, View.GONE);
Selim Cinek860b6da2015-12-16 19:02:19 -08002984 contentView.setViewVisibility(R.id.title, View.GONE);
Christoph Studerfe718432014-09-01 18:21:18 +02002985 contentView.setTextViewText(R.id.title, null);
Selim Cinek41598732016-01-11 16:58:37 -08002986 contentView.setViewVisibility(R.id.text, View.GONE);
Christoph Studerfe718432014-09-01 18:21:18 +02002987 contentView.setTextViewText(R.id.text, null);
Selim Cinek29603462015-11-17 19:04:39 -08002988 contentView.setViewVisibility(R.id.text_line_1, View.GONE);
Selim Cinek41598732016-01-11 16:58:37 -08002989 contentView.setTextViewText(R.id.text_line_1, null);
Christoph Studerfe718432014-09-01 18:21:18 +02002990 contentView.setViewVisibility(R.id.progress, View.GONE);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07002991 }
2992
Selim Cinekeaa29ca2015-11-23 13:51:13 -08002993 /**
2994 * Resets the notification header to its original state
2995 */
2996 private void resetNotificationHeader(RemoteViews contentView) {
Selim Cinek65b2e7c2015-10-26 14:11:31 -07002997 contentView.setImageViewResource(R.id.icon, 0);
Selim Cinek7b836392015-12-04 20:02:59 -08002998 contentView.setBoolean(R.id.notification_header, "setExpanded", false);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07002999 contentView.setTextViewText(R.id.app_name_text, null);
Christoph Studerca1db712014-09-10 17:31:33 +02003000 contentView.setViewVisibility(R.id.chronometer, View.GONE);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003001 contentView.setViewVisibility(R.id.header_sub_text, View.GONE);
Selim Cinek29603462015-11-17 19:04:39 -08003002 contentView.setViewVisibility(R.id.header_content_info, View.GONE);
Selim Cinek29603462015-11-17 19:04:39 -08003003 contentView.setViewVisibility(R.id.sub_text_divider, View.GONE);
3004 contentView.setViewVisibility(R.id.content_info_divider, View.GONE);
3005 contentView.setViewVisibility(R.id.time_divider, View.GONE);
Selim Cinekc848c3a2016-01-13 15:27:30 -08003006 contentView.setImageViewIcon(R.id.profile_badge, null);
3007 contentView.setViewVisibility(R.id.profile_badge, View.GONE);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003008 }
3009
3010 private void resetContentMargins(RemoteViews contentView) {
3011 contentView.setViewLayoutMarginEnd(R.id.line1, 0);
Selim Cinekc848c3a2016-01-13 15:27:30 -08003012 contentView.setViewLayoutMarginEnd(R.id.text, 0);
Christoph Studerfe718432014-09-01 18:21:18 +02003013 }
3014
Jorim Jaggi445d3c02014-08-19 22:33:42 +02003015 private RemoteViews applyStandardTemplate(int resId) {
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02003016 return applyStandardTemplate(resId, true /* hasProgress */);
3017 }
3018
3019 /**
3020 * @param hasProgress whether the progress bar should be shown and set
3021 */
3022 private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) {
Kenny Guy77320062014-08-27 21:37:15 +01003023 RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId);
Dan Sandler539aad42014-08-04 00:43:39 -04003024
Christoph Studerfe718432014-09-01 18:21:18 +02003025 resetStandardTemplate(contentView);
3026
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003027 final Bundle ex = mN.extras;
Dan Sandler190d58d2014-05-15 09:33:39 -04003028
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003029 bindNotificationHeader(contentView);
3030 bindLargeIcon(contentView);
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003031 if (ex.getCharSequence(EXTRA_TITLE) != null) {
Selim Cinek860b6da2015-12-16 19:02:19 -08003032 contentView.setViewVisibility(R.id.title, View.VISIBLE);
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003033 contentView.setTextViewText(R.id.title,
3034 processLegacyText(ex.getCharSequence(EXTRA_TITLE)));
Joe Onorato561d3852010-11-20 18:09:34 -08003035 }
Selim Cinek29603462015-11-17 19:04:39 -08003036 boolean showProgress = handleProgressBar(hasProgress, contentView, ex);
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003037 if (ex.getCharSequence(EXTRA_TEXT) != null) {
Selim Cinek41598732016-01-11 16:58:37 -08003038 int textId = showProgress ? com.android.internal.R.id.text_line_1
3039 : com.android.internal.R.id.text;
3040 contentView.setTextViewText(textId, processLegacyText(
3041 ex.getCharSequence(EXTRA_TEXT)));
3042 contentView.setViewVisibility(textId, View.VISIBLE);
Joe Onorato561d3852010-11-20 18:09:34 -08003043 }
Selim Cinekc848c3a2016-01-13 15:27:30 -08003044
Selim Cinek860b6da2015-12-16 19:02:19 -08003045 setContentMinHeight(contentView, showProgress || mN.mLargeIcon != null);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003046
Selim Cinek29603462015-11-17 19:04:39 -08003047 return contentView;
3048 }
3049
Selim Cinek860b6da2015-12-16 19:02:19 -08003050 /**
3051 * @param remoteView the remote view to update the minheight in
3052 * @param hasMinHeight does it have a mimHeight
3053 * @hide
3054 */
3055 void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) {
3056 int minHeight = 0;
3057 if (hasMinHeight) {
3058 // we need to set the minHeight of the notification
3059 minHeight = mContext.getResources().getDimensionPixelSize(
3060 com.android.internal.R.dimen.notification_min_content_height);
3061 }
3062 remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight);
3063 }
3064
Selim Cinek29603462015-11-17 19:04:39 -08003065 private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) {
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003066 final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0);
3067 final int progress = ex.getInt(EXTRA_PROGRESS, 0);
3068 final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE);
3069 if (hasProgress && (max != 0 || ind)) {
Selim Cinek29603462015-11-17 19:04:39 -08003070 contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003071 contentView.setProgressBar(
Selim Cinek29603462015-11-17 19:04:39 -08003072 R.id.progress, max, progress, ind);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003073 contentView.setProgressBackgroundTintList(
3074 R.id.progress, ColorStateList.valueOf(mContext.getColor(
3075 R.color.notification_progress_background_color)));
Selim Cinek29603462015-11-17 19:04:39 -08003076 if (mN.color != COLOR_DEFAULT) {
3077 ColorStateList colorStateList = ColorStateList.valueOf(mN.color);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003078 contentView.setProgressTintList(R.id.progress, colorStateList);
3079 contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003080 }
Selim Cinek29603462015-11-17 19:04:39 -08003081 return true;
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003082 } else {
3083 contentView.setViewVisibility(R.id.progress, View.GONE);
Selim Cinek29603462015-11-17 19:04:39 -08003084 return false;
Jeff Sharkey1c400132011-08-05 14:50:13 -07003085 }
Joe Onorato561d3852010-11-20 18:09:34 -08003086 }
3087
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003088 private void bindLargeIcon(RemoteViews contentView) {
3089 if (mN.mLargeIcon != null) {
3090 contentView.setViewVisibility(R.id.right_icon, View.VISIBLE);
3091 contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon);
3092 processLargeLegacyIcon(mN.mLargeIcon, contentView);
3093 int endMargin = mContext.getResources().getDimensionPixelSize(
3094 R.dimen.notification_content_picture_margin);
3095 contentView.setViewLayoutMarginEnd(R.id.line1, endMargin);
Selim Cinekc848c3a2016-01-13 15:27:30 -08003096 contentView.setViewLayoutMarginEnd(R.id.text, endMargin);
Selim Cinek29603462015-11-17 19:04:39 -08003097 contentView.setViewLayoutMarginEnd(R.id.progress, endMargin);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003098 }
3099 }
3100
3101 private void bindNotificationHeader(RemoteViews contentView) {
3102 bindSmallIcon(contentView);
3103 bindHeaderAppName(contentView);
Selim Cinek03d0d652015-11-13 13:18:09 -05003104 bindHeaderSubText(contentView);
Selim Cinek29603462015-11-17 19:04:39 -08003105 bindContentInfo(contentView);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003106 bindHeaderChronometerAndTime(contentView);
3107 bindExpandButton(contentView);
Selim Cinekc848c3a2016-01-13 15:27:30 -08003108 bindProfileBadge(contentView);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003109 }
3110
Selim Cinek29603462015-11-17 19:04:39 -08003111 private void bindContentInfo(RemoteViews contentView) {
3112 boolean visible = false;
3113 if (mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) {
3114 contentView.setTextViewText(R.id.header_content_info,
3115 processLegacyText(mN.extras.getCharSequence(EXTRA_INFO_TEXT)));
3116 contentView.setViewVisibility(R.id.header_content_info, View.VISIBLE);
3117 visible = true;
3118 } else if (mN.number > 0) {
3119 final int tooBig = mContext.getResources().getInteger(
3120 R.integer.status_bar_notification_info_maxnum);
3121 if (mN.number > tooBig) {
3122 contentView.setTextViewText(R.id.header_content_info, processLegacyText(
3123 mContext.getResources().getString(
3124 R.string.status_bar_notification_info_overflow)));
3125 } else {
3126 contentView.setTextViewText(R.id.header_content_info,
3127 processLegacyText(String.valueOf(mN.number)));
3128 }
3129 contentView.setViewVisibility(R.id.header_content_info, View.VISIBLE);
3130 visible = true;
3131 }
3132 if (visible) {
3133 contentView.setViewVisibility(R.id.content_info_divider, View.VISIBLE);
3134 }
3135 }
3136
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003137 private void bindExpandButton(RemoteViews contentView) {
3138 contentView.setDrawableParameters(R.id.expand_button, false, -1, resolveColor(),
3139 PorterDuff.Mode.SRC_ATOP, -1);
Selim Cinekea4bef72015-12-02 15:51:10 -08003140 contentView.setInt(R.id.notification_header, "setOriginalNotificationColor",
3141 resolveColor());
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003142 }
3143
3144 private void bindHeaderChronometerAndTime(RemoteViews contentView) {
3145 if (showsTimeOrChronometer()) {
Selim Cinek29603462015-11-17 19:04:39 -08003146 contentView.setViewVisibility(R.id.time_divider, View.VISIBLE);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003147 if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) {
3148 contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
3149 contentView.setLong(R.id.chronometer, "setBase",
3150 mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
3151 contentView.setBoolean(R.id.chronometer, "setStarted", true);
Selim Cinek81c23aa2016-02-25 16:23:13 -08003152 boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN);
3153 contentView.setChronometerCountsDown(R.id.chronometer, countsDown);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003154 } else {
3155 contentView.setViewVisibility(R.id.time, View.VISIBLE);
3156 contentView.setLong(R.id.time, "setTime", mN.when);
3157 }
3158 }
3159 }
3160
Selim Cinek03d0d652015-11-13 13:18:09 -05003161 private void bindHeaderSubText(RemoteViews contentView) {
3162 CharSequence subText = mN.extras.getCharSequence(EXTRA_SUB_TEXT);
3163 if (subText == null && mStyle != null && mStyle.mSummaryTextSet
3164 && mStyle.hasSummaryInHeader()) {
3165 subText = mStyle.mSummaryText;
3166 }
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003167 if (subText != null) {
3168 // TODO: Remove the span entirely to only have the string with propper formating.
3169 contentView.setTextViewText(R.id.header_sub_text, processLegacyText(subText));
3170 contentView.setViewVisibility(R.id.header_sub_text, View.VISIBLE);
Selim Cinek29603462015-11-17 19:04:39 -08003171 contentView.setViewVisibility(R.id.sub_text_divider, View.VISIBLE);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003172 }
3173 }
3174
3175 private void bindHeaderAppName(RemoteViews contentView) {
3176 PackageManager packageManager = mContext.getPackageManager();
3177 ApplicationInfo info = null;
3178 try {
3179 info = packageManager.getApplicationInfo(mContext.getApplicationInfo().packageName,
3180 0);
3181 } catch (final NameNotFoundException e) {
3182 return;
3183 }
3184 CharSequence appName = info != null ? packageManager.getApplicationLabel(info)
3185 : null;
3186 if (TextUtils.isEmpty(appName)) {
3187 return;
3188 }
3189 contentView.setTextViewText(R.id.app_name_text, appName);
Selim Cinekaef485a2016-02-05 10:31:20 -08003190 contentView.setTextColor(R.id.app_name_text, resolveColor());
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003191 }
3192
3193 private void bindSmallIcon(RemoteViews contentView) {
3194 contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon);
3195 processSmallIconColor(mN.mSmallIcon, contentView);
3196 }
3197
Jorim Jaggi445d3c02014-08-19 22:33:42 +02003198 /**
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02003199 * @return true if the built notification will show the time or the chronometer; false
3200 * otherwise
3201 */
3202 private boolean showsTimeOrChronometer() {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003203 return mN.when != 0 && mN.extras.getBoolean(EXTRA_SHOW_WHEN);
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02003204 }
3205
Christoph Studerfe718432014-09-01 18:21:18 +02003206 private void resetStandardTemplateWithActions(RemoteViews big) {
3207 big.setViewVisibility(R.id.actions, View.GONE);
Christoph Studerfe718432014-09-01 18:21:18 +02003208 big.removeAllViews(R.id.actions);
Adrian Roose458aa82015-12-08 16:17:19 -08003209
3210 big.setViewVisibility(R.id.notification_material_reply_container, View.GONE);
3211 big.setTextViewText(R.id.notification_material_reply_text_1, null);
3212
3213 big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE);
3214 big.setTextViewText(R.id.notification_material_reply_text_2, null);
3215 big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE);
3216 big.setTextViewText(R.id.notification_material_reply_text_3, null);
Christoph Studerfe718432014-09-01 18:21:18 +02003217 }
3218
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003219 private RemoteViews applyStandardTemplateWithActions(int layoutId) {
Jorim Jaggi445d3c02014-08-19 22:33:42 +02003220 RemoteViews big = applyStandardTemplate(layoutId);
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003221
Christoph Studerfe718432014-09-01 18:21:18 +02003222 resetStandardTemplateWithActions(big);
3223
Adrian Roose458aa82015-12-08 16:17:19 -08003224 boolean validRemoteInput = false;
3225
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003226 int N = mActions.size();
3227 if (N > 0) {
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003228 big.setViewVisibility(R.id.actions, View.VISIBLE);
Daniel Sandler8680bf82012-05-15 16:52:52 -04003229 if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS;
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003230 for (int i=0; i<N; i++) {
Adrian Roose458aa82015-12-08 16:17:19 -08003231 Action action = mActions.get(i);
3232 validRemoteInput |= hasValidRemoteInput(action);
3233
3234 final RemoteViews button = generateActionButton(action);
Adrian Roos9b123cf2016-02-04 14:55:57 -08003235 if (i == N - 1) {
3236 button.setViewLayoutWidth(com.android.internal.R.id.action0,
3237 ViewGroup.LayoutParams.MATCH_PARENT);
3238 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003239 big.addView(R.id.actions, button);
3240 }
3241 }
Adrian Roose458aa82015-12-08 16:17:19 -08003242
3243 CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY);
3244 if (validRemoteInput && replyText != null
3245 && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) {
3246 big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE);
3247 big.setTextViewText(R.id.notification_material_reply_text_1, replyText[0]);
3248
3249 if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) {
3250 big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE);
3251 big.setTextViewText(R.id.notification_material_reply_text_2, replyText[1]);
3252
3253 if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) {
3254 big.setViewVisibility(
3255 R.id.notification_material_reply_text_3, View.VISIBLE);
3256 big.setTextViewText(R.id.notification_material_reply_text_3, replyText[2]);
3257 }
3258 }
3259 }
3260
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003261 return big;
3262 }
3263
Adrian Roose458aa82015-12-08 16:17:19 -08003264 private boolean hasValidRemoteInput(Action action) {
3265 if (TextUtils.isEmpty(action.title) || action.actionIntent == null) {
3266 // Weird actions
3267 return false;
3268 }
3269
3270 RemoteInput[] remoteInputs = action.getRemoteInputs();
3271 if (remoteInputs == null) {
3272 return false;
3273 }
3274
3275 for (RemoteInput r : remoteInputs) {
3276 CharSequence[] choices = r.getChoices();
3277 if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) {
3278 return true;
3279 }
3280 }
3281 return false;
3282 }
3283
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003284 /**
3285 * Construct a RemoteViews for the final 1U notification layout. In order:
3286 * 1. Custom contentView from the caller
3287 * 2. Style's proposed content view
3288 * 3. Standard template view
3289 */
Julia Reynolds3b848122016-02-26 10:45:32 -05003290 public RemoteViews createContentView() {
Selim Cinek593610c2016-02-16 18:42:57 -08003291 if (mN.contentView != null && (mStyle == null || !mStyle.displayCustomViewInline())) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003292 return mN.contentView;
3293 } else if (mStyle != null) {
3294 final RemoteViews styleView = mStyle.makeContentView();
3295 if (styleView != null) {
3296 return styleView;
3297 }
Joe Onorato46439ce2010-11-19 13:56:21 -08003298 }
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003299 return applyStandardTemplate(getBaseLayoutResource());
Joe Onorato46439ce2010-11-19 13:56:21 -08003300 }
3301
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003302 /**
3303 * Construct a RemoteViews for the final big notification layout.
3304 */
Julia Reynolds3b848122016-02-26 10:45:32 -05003305 public RemoteViews createBigContentView() {
Selim Cinek850a8542015-11-11 11:48:36 -05003306 RemoteViews result = null;
Selim Cinek593610c2016-02-16 18:42:57 -08003307 if (mN.bigContentView != null
3308 && (mStyle == null || !mStyle.displayCustomViewInline())) {
Julia Reynolds089e3e42015-11-18 09:59:57 -05003309 return mN.bigContentView;
3310 } else if (mStyle != null) {
Selim Cinek850a8542015-11-11 11:48:36 -05003311 result = mStyle.makeBigContentView();
Selim Cinek90dcf6d2015-11-18 20:24:13 -08003312 hideLine1Text(result);
Selim Cinekcc10bfb2016-02-10 16:24:21 -08003313 } else if (mActions.size() != 0) {
3314 result = applyStandardTemplateWithActions(getBigBaseLayoutResource());
Selim Cinek850a8542015-11-11 11:48:36 -05003315 }
3316 adaptNotificationHeaderForBigContentView(result);
3317 return result;
3318 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003319
Selim Cinekeaa29ca2015-11-23 13:51:13 -08003320 /**
3321 * Construct a RemoteViews for the final notification header only
3322 *
3323 * @hide
3324 */
3325 public RemoteViews makeNotificationHeader() {
3326 RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(),
3327 R.layout.notification_template_header);
3328 resetNotificationHeader(header);
3329 bindNotificationHeader(header);
3330 return header;
3331 }
3332
Selim Cinek29603462015-11-17 19:04:39 -08003333 private void hideLine1Text(RemoteViews result) {
Selim Cinekcc10bfb2016-02-10 16:24:21 -08003334 if (result != null) {
3335 result.setViewVisibility(R.id.text_line_1, View.GONE);
3336 }
Selim Cinek29603462015-11-17 19:04:39 -08003337 }
3338
Selim Cinek850a8542015-11-11 11:48:36 -05003339 private void adaptNotificationHeaderForBigContentView(RemoteViews result) {
Selim Cinekcc10bfb2016-02-10 16:24:21 -08003340 if (result != null) {
3341 result.setBoolean(R.id.notification_header, "setExpanded", true);
3342 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003343 }
3344
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003345 /**
3346 * Construct a RemoteViews for the final heads-up notification layout.
3347 */
Julia Reynolds3b848122016-02-26 10:45:32 -05003348 public RemoteViews createHeadsUpContentView() {
Selim Cinek593610c2016-02-16 18:42:57 -08003349 if (mN.headsUpContentView != null
3350 && (mStyle == null || !mStyle.displayCustomViewInline())) {
Julia Reynolds089e3e42015-11-18 09:59:57 -05003351 return mN.headsUpContentView;
3352 } else if (mStyle != null) {
3353 final RemoteViews styleView = mStyle.makeHeadsUpContentView();
3354 if (styleView != null) {
3355 return styleView;
3356 }
3357 } else if (mActions.size() == 0) {
3358 return null;
3359 }
3360
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003361 return applyStandardTemplateWithActions(getBigBaseLayoutResource());
Chris Wren8fd39ec2014-02-27 17:43:26 -05003362 }
3363
Selim Cinek624c02db2015-12-14 21:00:02 -08003364 /**
3365 * Construct a RemoteViews for the display in public contexts like on the lockscreen.
3366 *
3367 * @hide
3368 */
3369 public RemoteViews makePublicContentView() {
3370 if (mN.publicVersion != null) {
3371 final Builder builder = recoverBuilder(mContext, mN.publicVersion);
Julia Reynolds3b848122016-02-26 10:45:32 -05003372 return builder.createContentView();
Selim Cinek624c02db2015-12-14 21:00:02 -08003373 }
3374 Bundle savedBundle = mN.extras;
3375 Style style = mStyle;
3376 mStyle = null;
3377 Icon largeIcon = mN.mLargeIcon;
3378 mN.mLargeIcon = null;
3379 Bundle publicExtras = new Bundle();
3380 publicExtras.putBoolean(EXTRA_SHOW_WHEN,
3381 savedBundle.getBoolean(EXTRA_SHOW_WHEN));
3382 publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER,
3383 savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER));
Selim Cinek81c23aa2016-02-25 16:23:13 -08003384 publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN,
3385 savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN));
Selim Cinek624c02db2015-12-14 21:00:02 -08003386 publicExtras.putCharSequence(EXTRA_TITLE,
3387 mContext.getString(R.string.notification_hidden_text));
3388 mN.extras = publicExtras;
3389 final RemoteViews publicView = applyStandardTemplate(getBaseLayoutResource());
3390 mN.extras = savedBundle;
3391 mN.mLargeIcon = largeIcon;
3392 mStyle = style;
3393 return publicView;
3394 }
3395
3396
Chris Wren8fd39ec2014-02-27 17:43:26 -05003397
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003398 private RemoteViews generateActionButton(Action action) {
Daniel Sandler8680bf82012-05-15 16:52:52 -04003399 final boolean tombstone = (action.actionIntent == null);
Selim Cinekf33b1112015-07-15 17:45:11 -07003400 RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(),
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003401 tombstone ? getActionTombstoneLayoutResource()
3402 : getActionLayoutResource());
Dan Sandler68079d52015-07-22 10:45:30 -04003403 final Icon ai = action.getIcon();
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01003404 button.setTextViewText(R.id.action0, processLegacyText(action.title));
Daniel Sandler8680bf82012-05-15 16:52:52 -04003405 if (!tombstone) {
Daniel Sandlere5518842012-05-10 16:20:40 -04003406 button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
Daniel Sandlere5518842012-05-10 16:20:40 -04003407 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003408 button.setContentDescription(R.id.action0, action.title);
Adrian Roosfe84e1f2015-11-04 15:55:39 -08003409 if (action.mRemoteInputs != null) {
3410 button.setRemoteInputs(R.id.action0, action.mRemoteInputs);
3411 }
3412 if (mN.color != COLOR_DEFAULT) {
3413 button.setTextColor(R.id.action0, mN.color);
3414 }
Daniel Sandler96fd7c12012-03-30 16:37:36 -04003415 return button;
3416 }
3417
Joe Onoratocb109a02011-01-18 17:57:41 -08003418 /**
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01003419 * @return Whether we are currently building a notification from a legacy (an app that
Alan Viverette3cb07a462014-06-06 14:19:53 -07003420 * doesn't create material notifications by itself) app.
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01003421 */
3422 private boolean isLegacy() {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003423 return getColorUtil() != null;
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01003424 }
3425
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01003426 private CharSequence processLegacyText(CharSequence charSequence) {
3427 if (isLegacy()) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003428 return getColorUtil().invertCharSequenceColors(charSequence);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01003429 } else {
3430 return charSequence;
3431 }
3432 }
3433
Dan Sandler26e81cf2014-05-06 10:01:27 -04003434 /**
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003435 * Apply any necessariy colors to the small icon
Dan Sandler26e81cf2014-05-06 10:01:27 -04003436 */
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003437 private void processSmallIconColor(Icon smallIcon, RemoteViews contentView) {
Selim Cinekea4bef72015-12-02 15:51:10 -08003438 boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon);
3439 if (colorable) {
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003440 contentView.setDrawableParameters(R.id.icon, false, -1, resolveColor(),
Jorim Jaggi92df1f22014-12-16 19:44:41 +01003441 PorterDuff.Mode.SRC_ATOP, -1);
Selim Cinekea4bef72015-12-02 15:51:10 -08003442
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01003443 }
Selim Cinekea4bef72015-12-02 15:51:10 -08003444 contentView.setInt(R.id.notification_header, "setOriginalIconColor",
3445 colorable ? resolveColor() : NotificationHeaderView.NO_COLOR);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01003446 }
3447
Dan Sandler26e81cf2014-05-06 10:01:27 -04003448 /**
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003449 * Make the largeIcon dark if it's a fake smallIcon (that is,
Dan Sandler26e81cf2014-05-06 10:01:27 -04003450 * if it's grayscale).
3451 */
3452 // TODO: also check bounds, transparency, that sort of thing.
Dan Sandlerd63f9322015-05-06 15:18:49 -04003453 private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) {
3454 if (largeIcon != null && isLegacy()
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003455 && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) {
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003456 // resolve color will fall back to the default when legacy
3457 contentView.setDrawableParameters(R.id.icon, false, -1, resolveColor(),
Dan Sandler190d58d2014-05-15 09:33:39 -04003458 PorterDuff.Mode.SRC_ATOP, -1);
Jorim Jaggi92df1f22014-12-16 19:44:41 +01003459 }
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01003460 }
3461
Julia Reynolds10ee1fc2015-11-09 11:04:55 -05003462 private void sanitizeColor() {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003463 if (mN.color != COLOR_DEFAULT) {
3464 mN.color |= 0xFF000000; // no alpha for custom colors
Jorim Jaggi74419312014-06-10 20:57:21 +02003465 }
Jorim Jaggi74419312014-06-10 20:57:21 +02003466 }
3467
Selim Cinek5bf069a2015-11-10 19:14:27 -05003468 int resolveColor() {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003469 if (mN.color == COLOR_DEFAULT) {
Selim Cinek65b2e7c2015-10-26 14:11:31 -07003470 return mContext.getColor(R.color.notification_icon_default_color);
Dan Sandler26e81cf2014-05-06 10:01:27 -04003471 }
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003472 return mN.color;
Dan Sandler26e81cf2014-05-06 10:01:27 -04003473 }
3474
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01003475 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003476 * Apply the unstyled operations and return a new {@link Notification} object.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04003477 * @hide
Joe Onoratocb109a02011-01-18 17:57:41 -08003478 */
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04003479 public Notification buildUnstyled() {
Daniel Sandlera0a938c2012-03-15 08:42:37 -04003480 if (mActions.size() > 0) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003481 mN.actions = new Action[mActions.size()];
3482 mActions.toArray(mN.actions);
Daniel Sandlera0a938c2012-03-15 08:42:37 -04003483 }
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003484 if (!mPersonList.isEmpty()) {
3485 mN.extras.putStringArray(EXTRA_PEOPLE,
3486 mPersonList.toArray(new String[mPersonList.size()]));
Dan Sandler0bf2ed82013-12-21 23:33:41 -06003487 }
Selim Cinek247fa012016-02-18 09:50:48 -08003488 if (mN.bigContentView != null || mN.contentView != null
3489 || mN.headsUpContentView != null) {
3490 mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true);
3491 }
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003492 return mN;
Joe Onorato46439ce2010-11-19 13:56:21 -08003493 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003494
Julia Reynolds3b848122016-02-26 10:45:32 -05003495 /**
3496 * Creates a Builder from an existing notification so further changes can be made.
3497 * @param context The context for your application / activity.
3498 * @param n The notification to create a Builder from.
3499 */
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003500 public static Notification.Builder recoverBuilder(Context context, Notification n) {
Christoph Studer4600f9b2014-07-22 22:44:43 +02003501 // Re-create notification context so we can access app resources.
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003502 ApplicationInfo applicationInfo = n.extras.getParcelable(
3503 EXTRA_BUILDER_APPLICATION_INFO);
Christoph Studer4600f9b2014-07-22 22:44:43 +02003504 Context builderContext;
Julia Reynoldsda303542015-11-23 14:00:20 -05003505 if (applicationInfo != null) {
3506 try {
3507 builderContext = context.createApplicationContext(applicationInfo,
3508 Context.CONTEXT_RESTRICTED);
3509 } catch (NameNotFoundException e) {
3510 Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found");
3511 builderContext = context; // try with our context
3512 }
3513 } else {
3514 builderContext = context; // try with given context
Christoph Studer4600f9b2014-07-22 22:44:43 +02003515 }
3516
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003517 return new Builder(builderContext, n);
Christoph Studer4600f9b2014-07-22 22:44:43 +02003518 }
3519
3520 private static Class<? extends Style> getNotificationStyleClass(String templateClass) {
Selim Cinek593610c2016-02-16 18:42:57 -08003521 Class<? extends Style>[] classes = new Class[] {
3522 BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class,
Selim Cinek03eb3b72016-02-18 10:39:45 -08003523 DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class };
Christoph Studer4600f9b2014-07-22 22:44:43 +02003524 for (Class<? extends Style> innerClass : classes) {
3525 if (templateClass.equals(innerClass.getName())) {
3526 return innerClass;
3527 }
3528 }
3529 return null;
3530 }
3531
Daniel Sandlerf45564e2013-04-15 15:05:08 -04003532 /**
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003533 * @deprecated Use {@link #build()} instead.
3534 */
3535 @Deprecated
3536 public Notification getNotification() {
3537 return build();
3538 }
3539
3540 /**
3541 * Combine all of the options that have been set and return a new {@link Notification}
3542 * object.
3543 */
3544 public Notification build() {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003545 // first, add any extras from the calling code
3546 if (mUserExtras != null) {
3547 mN.extras = getAllExtras();
Jorim Jaggia0d58ae2015-06-03 11:48:13 -07003548 }
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003549
3550 // lazy stuff from mContext; see comment in Builder(Context, Notification)
Julia Reynoldsda303542015-11-23 14:00:20 -05003551 Notification.addFieldsFromContext(mContext, mN);
Christoph Studer943aa672014-08-03 20:31:16 +02003552
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003553 buildUnstyled();
Daniel Sandlerf45564e2013-04-15 15:05:08 -04003554
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003555 if (mStyle != null) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003556 mStyle.buildStyled(mN);
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003557 }
Daniel Sandlerf45564e2013-04-15 15:05:08 -04003558
Adrian Roos5081c0d2016-02-26 16:04:19 -08003559 if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N
3560 && (mStyle == null || !mStyle.displayCustomViewInline())) {
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003561 if (mN.contentView == null) {
Julia Reynolds3b848122016-02-26 10:45:32 -05003562 mN.contentView = createContentView();
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003563 mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT,
3564 mN.contentView.getSequenceNumber());
3565 }
3566 if (mN.bigContentView == null) {
Julia Reynolds3b848122016-02-26 10:45:32 -05003567 mN.bigContentView = createBigContentView();
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003568 if (mN.bigContentView != null) {
3569 mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT,
3570 mN.bigContentView.getSequenceNumber());
3571 }
3572 }
3573 if (mN.headsUpContentView == null) {
Julia Reynolds3b848122016-02-26 10:45:32 -05003574 mN.headsUpContentView = createHeadsUpContentView();
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003575 if (mN.headsUpContentView != null) {
3576 mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT,
3577 mN.headsUpContentView.getSequenceNumber());
3578 }
3579 }
3580 }
3581
Julia Reynolds4c0c2022016-02-02 15:11:59 -05003582 if ((mN.defaults & DEFAULT_LIGHTS) != 0) {
3583 mN.flags |= FLAG_SHOW_LIGHTS;
3584 }
3585
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003586 return mN;
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003587 }
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05003588
3589 /**
3590 * Apply this Builder to an existing {@link Notification} object.
3591 *
3592 * @hide
3593 */
3594 public Notification buildInto(Notification n) {
Daniel Sandler1a497d32013-04-18 14:52:45 -04003595 build().cloneInto(n, true);
Daniel Sandlerbe6e7e02013-02-01 17:49:11 -05003596 return n;
3597 }
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003598
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003599 /**
Adrian Roos184bfe022016-03-03 13:41:44 -08003600 * Removes RemoteViews that were created for compatibility from {@param n}, if they did not
3601 * change.
3602 *
3603 * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}.
3604 *
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003605 * @hide
3606 */
Adrian Roos184bfe022016-03-03 13:41:44 -08003607 public static Notification maybeCloneStrippedForDelivery(Notification n) {
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003608 String templateClass = n.extras.getString(EXTRA_TEMPLATE);
Adrian Roos184bfe022016-03-03 13:41:44 -08003609
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003610 // Only strip views for known Styles because we won't know how to
3611 // re-create them otherwise.
Adrian Roos184bfe022016-03-03 13:41:44 -08003612 if (!TextUtils.isEmpty(templateClass)
3613 && getNotificationStyleClass(templateClass) == null) {
3614 return n;
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003615 }
Adrian Roos184bfe022016-03-03 13:41:44 -08003616
3617 // Only strip unmodified BuilderRemoteViews.
3618 boolean stripContentView = n.contentView instanceof BuilderRemoteViews &&
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003619 n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) ==
Adrian Roos184bfe022016-03-03 13:41:44 -08003620 n.contentView.getSequenceNumber();
3621 boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews &&
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003622 n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) ==
Adrian Roos184bfe022016-03-03 13:41:44 -08003623 n.bigContentView.getSequenceNumber();
3624 boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews &&
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003625 n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) ==
Adrian Roos184bfe022016-03-03 13:41:44 -08003626 n.headsUpContentView.getSequenceNumber();
3627
3628 // Nothing to do here, no need to clone.
3629 if (!stripContentView && !stripBigContentView && !stripHeadsUpContentView) {
3630 return n;
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003631 }
Adrian Roos184bfe022016-03-03 13:41:44 -08003632
3633 Notification clone = n.clone();
3634 if (stripContentView) {
3635 clone.contentView = null;
3636 clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT);
3637 }
3638 if (stripBigContentView) {
3639 clone.bigContentView = null;
3640 clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT);
3641 }
3642 if (stripHeadsUpContentView) {
3643 clone.headsUpContentView = null;
3644 clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT);
3645 }
3646 return clone;
Julia Reynoldsd4ea7412016-02-17 14:00:56 -05003647 }
3648
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003649 private int getBaseLayoutResource() {
Alan Viverette3cb07a462014-06-06 14:19:53 -07003650 return R.layout.notification_template_material_base;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003651 }
3652
3653 private int getBigBaseLayoutResource() {
Alan Viverette3cb07a462014-06-06 14:19:53 -07003654 return R.layout.notification_template_material_big_base;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003655 }
3656
3657 private int getBigPictureLayoutResource() {
Alan Viverette3cb07a462014-06-06 14:19:53 -07003658 return R.layout.notification_template_material_big_picture;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003659 }
3660
3661 private int getBigTextLayoutResource() {
Jorim Jaggi445d3c02014-08-19 22:33:42 +02003662 return R.layout.notification_template_material_big_text;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003663 }
3664
3665 private int getInboxLayoutResource() {
Alan Viverette3cb07a462014-06-06 14:19:53 -07003666 return R.layout.notification_template_material_inbox;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003667 }
3668
3669 private int getActionLayoutResource() {
Alan Viverette3cb07a462014-06-06 14:19:53 -07003670 return R.layout.notification_material_action;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003671 }
3672
3673 private int getActionTombstoneLayoutResource() {
Alan Viverette3cb07a462014-06-06 14:19:53 -07003674 return R.layout.notification_material_action_tombstone;
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003675 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003676 }
3677
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003678 /**
3679 * An object that can apply a rich notification style to a {@link Notification.Builder}
3680 * object.
3681 */
Griff Hazendfcb0802014-02-11 12:00:00 -08003682 public static abstract class Style {
Chris Wrend6297db2012-05-03 16:20:13 -04003683 private CharSequence mBigContentTitle;
Jorim Jaggi457a10d2014-09-08 16:18:23 +02003684
3685 /**
3686 * @hide
3687 */
3688 protected CharSequence mSummaryText = null;
3689
3690 /**
3691 * @hide
3692 */
3693 protected boolean mSummaryTextSet = false;
Chris Wrend6297db2012-05-03 16:20:13 -04003694
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003695 protected Builder mBuilder;
3696
Chris Wrend6297db2012-05-03 16:20:13 -04003697 /**
3698 * Overrides ContentTitle in the big form of the template.
3699 * This defaults to the value passed to setContentTitle().
3700 */
3701 protected void internalSetBigContentTitle(CharSequence title) {
3702 mBigContentTitle = title;
3703 }
3704
3705 /**
3706 * Set the first line of text after the detail section in the big form of the template.
3707 */
3708 protected void internalSetSummaryText(CharSequence cs) {
3709 mSummaryText = cs;
Daniel Sandler619738c2012-06-07 16:33:08 -04003710 mSummaryTextSet = true;
Chris Wrend6297db2012-05-03 16:20:13 -04003711 }
3712
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003713 public void setBuilder(Builder builder) {
3714 if (mBuilder != builder) {
3715 mBuilder = builder;
Daniel Sandlerc08dea22012-06-28 08:35:24 -07003716 if (mBuilder != null) {
3717 mBuilder.setStyle(this);
3718 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003719 }
3720 }
3721
Chris Wrend6297db2012-05-03 16:20:13 -04003722 protected void checkBuilder() {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003723 if (mBuilder == null) {
3724 throw new IllegalArgumentException("Style requires a valid Builder object");
3725 }
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003726 }
Chris Wrend6297db2012-05-03 16:20:13 -04003727
3728 protected RemoteViews getStandardView(int layoutId) {
3729 checkBuilder();
3730
Christoph Studer4600f9b2014-07-22 22:44:43 +02003731 // Nasty.
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003732 CharSequence oldBuilderContentTitle =
3733 mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE);
Chris Wrend6297db2012-05-03 16:20:13 -04003734 if (mBigContentTitle != null) {
3735 mBuilder.setContentTitle(mBigContentTitle);
3736 }
3737
Chris Wrend6297db2012-05-03 16:20:13 -04003738 RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId);
3739
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003740 mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle);
Christoph Studer4600f9b2014-07-22 22:44:43 +02003741
Chris Wrend6297db2012-05-03 16:20:13 -04003742 if (mBigContentTitle != null && mBigContentTitle.equals("")) {
3743 contentView.setViewVisibility(R.id.line1, View.GONE);
Chris Wren67dc9a02012-05-16 01:03:20 -04003744 } else {
3745 contentView.setViewVisibility(R.id.line1, View.VISIBLE);
Chris Wrend6297db2012-05-03 16:20:13 -04003746 }
3747
Chris Wrend6297db2012-05-03 16:20:13 -04003748 return contentView;
3749 }
3750
Daniel Sandlerf45564e2013-04-15 15:05:08 -04003751 /**
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003752 * Construct a Style-specific RemoteViews for the final 1U notification layout.
3753 * The default implementation has nothing additional to add.
3754 * @hide
3755 */
3756 public RemoteViews makeContentView() {
3757 return null;
3758 }
3759
3760 /**
3761 * Construct a Style-specific RemoteViews for the final big notification layout.
3762 * @hide
3763 */
3764 public RemoteViews makeBigContentView() {
3765 return null;
3766 }
3767
3768 /**
3769 * Construct a Style-specific RemoteViews for the final HUN layout.
3770 * @hide
3771 */
3772 public RemoteViews makeHeadsUpContentView() {
3773 return null;
3774 }
3775
3776 /**
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003777 * Apply any style-specific extras to this notification before shipping it out.
Daniel Sandlerf45564e2013-04-15 15:05:08 -04003778 * @hide
3779 */
3780 public void addExtras(Bundle extras) {
3781 if (mSummaryTextSet) {
3782 extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText);
3783 }
3784 if (mBigContentTitle != null) {
3785 extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle);
3786 }
Chris Wren91ad5632013-06-05 15:05:57 -04003787 extras.putString(EXTRA_TEMPLATE, this.getClass().getName());
Daniel Sandlerf45564e2013-04-15 15:05:08 -04003788 }
3789
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04003790 /**
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003791 * Reconstruct the internal state of this Style object from extras.
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04003792 * @hide
3793 */
Christoph Studer4600f9b2014-07-22 22:44:43 +02003794 protected void restoreFromExtras(Bundle extras) {
3795 if (extras.containsKey(EXTRA_SUMMARY_TEXT)) {
3796 mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT);
3797 mSummaryTextSet = true;
3798 }
3799 if (extras.containsKey(EXTRA_TITLE_BIG)) {
3800 mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG);
3801 }
3802 }
3803
3804
3805 /**
3806 * @hide
3807 */
3808 public Notification buildStyled(Notification wip) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003809 addExtras(wip.extras);
Christoph Studer4600f9b2014-07-22 22:44:43 +02003810 return wip;
3811 }
3812
Daniel Sandler0ec46202015-06-24 01:27:05 -04003813 /**
3814 * @hide
3815 */
Jorim Jaggia0d58ae2015-06-03 11:48:13 -07003816 public void purgeResources() {}
3817
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04003818 /**
3819 * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is
3820 * attached to.
3821 *
3822 * @return the fully constructed Notification.
3823 */
3824 public Notification build() {
3825 checkBuilder();
3826 return mBuilder.build();
3827 }
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02003828
3829 /**
3830 * @hide
3831 * @return true if the style positions the progress bar on the second line; false if the
3832 * style hides the progress bar
3833 */
3834 protected boolean hasProgress() {
3835 return true;
3836 }
Selim Cinek03d0d652015-11-13 13:18:09 -05003837
3838 /**
3839 * @hide
3840 * @return Whether we should put the summary be put into the notification header
3841 */
3842 public boolean hasSummaryInHeader() {
3843 return true;
3844 }
Selim Cinek593610c2016-02-16 18:42:57 -08003845
3846 /**
3847 * @hide
3848 * @return Whether custom content views are displayed inline in the style
3849 */
3850 public boolean displayCustomViewInline() {
3851 return false;
3852 }
Joe Onorato46439ce2010-11-19 13:56:21 -08003853 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003854
3855 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04003856 * Helper class for generating large-format notifications that include a large image attachment.
Joe Malin8d40d042012-11-05 11:36:40 -08003857 *
Robert Ly91c5ce32014-06-08 15:37:00 -07003858 * Here's how you'd set the <code>BigPictureStyle</code> on a notification:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003859 * <pre class="prettyprint">
Robert Ly91c5ce32014-06-08 15:37:00 -07003860 * Notification notif = new Notification.Builder(mContext)
3861 * .setContentTitle(&quot;New photo from &quot; + sender.toString())
3862 * .setContentText(subject)
3863 * .setSmallIcon(R.drawable.new_post)
3864 * .setLargeIcon(aBitmap)
3865 * .setStyle(new Notification.BigPictureStyle()
3866 * .bigPicture(aBigBitmap))
3867 * .build();
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003868 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08003869 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04003870 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003871 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003872 public static class BigPictureStyle extends Style {
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003873 private Bitmap mPicture;
Dan Sandlerd63f9322015-05-06 15:18:49 -04003874 private Icon mBigLargeIcon;
Chris Wren3745a3d2012-05-22 15:11:52 -04003875 private boolean mBigLargeIconSet = false;
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003876
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003877 public BigPictureStyle() {
3878 }
3879
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003880 public BigPictureStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003881 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003882 }
3883
Chris Wrend6297db2012-05-03 16:20:13 -04003884 /**
3885 * Overrides ContentTitle in the big form of the template.
3886 * This defaults to the value passed to setContentTitle().
3887 */
3888 public BigPictureStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04003889 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04003890 return this;
3891 }
3892
3893 /**
3894 * Set the first line of text after the detail section in the big form of the template.
3895 */
3896 public BigPictureStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04003897 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04003898 return this;
3899 }
3900
Chris Wren0bd664d2012-08-01 13:56:56 -04003901 /**
3902 * Provide the bitmap to be used as the payload for the BigPicture notification.
3903 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003904 public BigPictureStyle bigPicture(Bitmap b) {
3905 mPicture = b;
3906 return this;
3907 }
3908
Chris Wren3745a3d2012-05-22 15:11:52 -04003909 /**
Chris Wren3745a3d2012-05-22 15:11:52 -04003910 * Override the large icon when the big notification is shown.
3911 */
3912 public BigPictureStyle bigLargeIcon(Bitmap b) {
Dan Sandlerd63f9322015-05-06 15:18:49 -04003913 return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null);
3914 }
3915
3916 /**
3917 * Override the large icon when the big notification is shown.
3918 */
3919 public BigPictureStyle bigLargeIcon(Icon icon) {
Chris Wren3745a3d2012-05-22 15:11:52 -04003920 mBigLargeIconSet = true;
Dan Sandlerd63f9322015-05-06 15:18:49 -04003921 mBigLargeIcon = icon;
Chris Wren3745a3d2012-05-22 15:11:52 -04003922 return this;
3923 }
3924
Riley Andrews0394a0c2015-11-03 23:36:52 -08003925 /** @hide */
3926 public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10);
3927
Daniel Sandler0ec46202015-06-24 01:27:05 -04003928 /**
3929 * @hide
3930 */
Jorim Jaggia0d58ae2015-06-03 11:48:13 -07003931 @Override
3932 public void purgeResources() {
3933 super.purgeResources();
Riley Andrews8cee7c12015-11-01 23:36:04 -08003934 if (mPicture != null &&
3935 mPicture.isMutable() &&
Riley Andrews0394a0c2015-11-03 23:36:52 -08003936 mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) {
Jorim Jaggia0d58ae2015-06-03 11:48:13 -07003937 mPicture = mPicture.createAshmemBitmap();
3938 }
3939 if (mBigLargeIcon != null) {
3940 mBigLargeIcon.convertToAshmem();
3941 }
3942 }
Christoph Studer5c510ee2014-12-15 16:32:27 +01003943
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003944 /**
3945 * @hide
3946 */
3947 public RemoteViews makeBigContentView() {
3948 // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet
Christoph Studer5c510ee2014-12-15 16:32:27 +01003949 // This covers the following cases:
3950 // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003951 // mN.mLargeIcon
3952 // 2. !mBigLargeIconSet -> mN.mLargeIcon applies
Dan Sandlerd63f9322015-05-06 15:18:49 -04003953 Icon oldLargeIcon = null;
Christoph Studer5c510ee2014-12-15 16:32:27 +01003954 if (mBigLargeIconSet) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003955 oldLargeIcon = mBuilder.mN.mLargeIcon;
3956 mBuilder.mN.mLargeIcon = mBigLargeIcon;
Christoph Studer5c510ee2014-12-15 16:32:27 +01003957 }
3958
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01003959 RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource());
Selim Cinek03d0d652015-11-13 13:18:09 -05003960 if (mSummaryTextSet) {
3961 contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(mSummaryText));
Selim Cinekc848c3a2016-01-13 15:27:30 -08003962 contentView.setViewVisibility(R.id.text, View.VISIBLE);
Selim Cinek03d0d652015-11-13 13:18:09 -05003963 }
Selim Cinek860b6da2015-12-16 19:02:19 -08003964 mBuilder.setContentMinHeight(contentView, mBuilder.mN.mLargeIcon != null);
Selim Cinek53e64a42015-11-16 10:40:56 -08003965
Christoph Studer5c510ee2014-12-15 16:32:27 +01003966 if (mBigLargeIconSet) {
Julia Reynoldsd9228f12015-10-20 10:37:27 -04003967 mBuilder.mN.mLargeIcon = oldLargeIcon;
Christoph Studer5c510ee2014-12-15 16:32:27 +01003968 }
3969
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003970 contentView.setImageViewBitmap(R.id.big_picture, mPicture);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04003971 return contentView;
3972 }
3973
Daniel Sandlerf45564e2013-04-15 15:05:08 -04003974 /**
3975 * @hide
3976 */
3977 public void addExtras(Bundle extras) {
3978 super.addExtras(extras);
3979
3980 if (mBigLargeIconSet) {
3981 extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon);
3982 }
3983 extras.putParcelable(EXTRA_PICTURE, mPicture);
3984 }
3985
Daniel Sandlercf1d39b2013-09-23 13:35:35 -04003986 /**
3987 * @hide
3988 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04003989 @Override
Christoph Studer4600f9b2014-07-22 22:44:43 +02003990 protected void restoreFromExtras(Bundle extras) {
3991 super.restoreFromExtras(extras);
3992
3993 if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) {
Christoph Studer5c510ee2014-12-15 16:32:27 +01003994 mBigLargeIconSet = true;
Christoph Studer4600f9b2014-07-22 22:44:43 +02003995 mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG);
Chris Wren3745a3d2012-05-22 15:11:52 -04003996 }
Christoph Studer4600f9b2014-07-22 22:44:43 +02003997 mPicture = extras.getParcelable(EXTRA_PICTURE);
3998 }
Selim Cinek03d0d652015-11-13 13:18:09 -05003999
4000 /**
4001 * @hide
4002 */
4003 @Override
4004 public boolean hasSummaryInHeader() {
4005 return false;
4006 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004007 }
4008
4009 /**
Daniel Sandler4dfbe832012-04-11 14:51:46 -04004010 * Helper class for generating large-format notifications that include a lot of text.
Joe Malin8d40d042012-11-05 11:36:40 -08004011 *
Robert Ly91c5ce32014-06-08 15:37:00 -07004012 * Here's how you'd set the <code>BigTextStyle</code> on a notification:
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004013 * <pre class="prettyprint">
Robert Ly91c5ce32014-06-08 15:37:00 -07004014 * Notification notif = new Notification.Builder(mContext)
4015 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
4016 * .setContentText(subject)
4017 * .setSmallIcon(R.drawable.new_mail)
4018 * .setLargeIcon(aBitmap)
4019 * .setStyle(new Notification.BigTextStyle()
4020 * .bigText(aVeryLongString))
4021 * .build();
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004022 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08004023 *
Daniel Sandler4dfbe832012-04-11 14:51:46 -04004024 * @see Notification#bigContentView
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004025 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04004026 public static class BigTextStyle extends Style {
Jorim Jaggi457a10d2014-09-08 16:18:23 +02004027
4028 private static final int MAX_LINES = 13;
Selim Cinek3a2c4b92015-12-17 17:01:17 -08004029 private static final int LINES_CONSUMED_BY_ACTIONS = 4;
Jorim Jaggi457a10d2014-09-08 16:18:23 +02004030
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004031 private CharSequence mBigText;
4032
Chris Wrenfbd96ba2012-05-01 12:03:58 -04004033 public BigTextStyle() {
4034 }
4035
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004036 public BigTextStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04004037 setBuilder(builder);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004038 }
4039
Chris Wrend6297db2012-05-03 16:20:13 -04004040 /**
4041 * Overrides ContentTitle in the big form of the template.
4042 * This defaults to the value passed to setContentTitle().
4043 */
4044 public BigTextStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04004045 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04004046 return this;
4047 }
4048
4049 /**
4050 * Set the first line of text after the detail section in the big form of the template.
4051 */
4052 public BigTextStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04004053 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04004054 return this;
4055 }
4056
Chris Wren0bd664d2012-08-01 13:56:56 -04004057 /**
4058 * Provide the longer text to be displayed in the big form of the
4059 * template in place of the content text.
4060 */
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004061 public BigTextStyle bigText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04004062 mBigText = safeCharSequence(cs);
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004063 return this;
4064 }
4065
Daniel Sandlerf45564e2013-04-15 15:05:08 -04004066 /**
4067 * @hide
4068 */
4069 public void addExtras(Bundle extras) {
4070 super.addExtras(extras);
4071
Christoph Studer4600f9b2014-07-22 22:44:43 +02004072 extras.putCharSequence(EXTRA_BIG_TEXT, mBigText);
4073 }
4074
4075 /**
4076 * @hide
4077 */
4078 @Override
4079 protected void restoreFromExtras(Bundle extras) {
4080 super.restoreFromExtras(extras);
4081
4082 mBigText = extras.getCharSequence(EXTRA_BIG_TEXT);
Daniel Sandlerf45564e2013-04-15 15:05:08 -04004083 }
4084
Julia Reynoldsd9228f12015-10-20 10:37:27 -04004085 /**
4086 * @hide
4087 */
4088 public RemoteViews makeBigContentView() {
Christoph Studer4600f9b2014-07-22 22:44:43 +02004089
4090 // Nasty
Julia Reynoldsd9228f12015-10-20 10:37:27 -04004091 CharSequence oldBuilderContentText =
4092 mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT);
4093 mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null);
Daniel Sandler916ad912012-06-13 12:17:07 -04004094
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01004095 RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource());
Joe Malin8d40d042012-11-05 11:36:40 -08004096
Julia Reynoldsd9228f12015-10-20 10:37:27 -04004097 mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText);
Christoph Studer4600f9b2014-07-22 22:44:43 +02004098
Selim Cinek3a2c4b92015-12-17 17:01:17 -08004099 CharSequence bigTextText = mBuilder.processLegacyText(mBigText);
4100 contentView.setTextViewText(R.id.big_text, bigTextText);
4101 contentView.setViewVisibility(R.id.big_text,
4102 TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE);
Jorim Jaggi457a10d2014-09-08 16:18:23 +02004103 contentView.setInt(R.id.big_text, "setMaxLines", calculateMaxLines());
Selim Cinek4fb12d32015-11-19 18:10:48 -08004104 contentView.setBoolean(R.id.big_text, "setHasImage", mBuilder.mN.mLargeIcon != null);
4105
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004106 return contentView;
4107 }
4108
Jorim Jaggi457a10d2014-09-08 16:18:23 +02004109 private int calculateMaxLines() {
4110 int lineCount = MAX_LINES;
4111 boolean hasActions = mBuilder.mActions.size() > 0;
Jorim Jaggi457a10d2014-09-08 16:18:23 +02004112 if (hasActions) {
4113 lineCount -= LINES_CONSUMED_BY_ACTIONS;
4114 }
Jorim Jaggi457a10d2014-09-08 16:18:23 +02004115 return lineCount;
4116 }
Daniel Sandlerf3b73432012-03-27 15:01:25 -04004117 }
Daniel Sandler879c5e02012-04-17 16:46:51 -04004118
4119 /**
4120 * Helper class for generating large-format notifications that include a list of (up to 5) strings.
Joe Malin8d40d042012-11-05 11:36:40 -08004121 *
Robert Ly91c5ce32014-06-08 15:37:00 -07004122 * Here's how you'd set the <code>InboxStyle</code> on a notification:
Daniel Sandler879c5e02012-04-17 16:46:51 -04004123 * <pre class="prettyprint">
Robert Ly91c5ce32014-06-08 15:37:00 -07004124 * Notification notif = new Notification.Builder(mContext)
4125 * .setContentTitle(&quot;5 New mails from &quot; + sender.toString())
4126 * .setContentText(subject)
4127 * .setSmallIcon(R.drawable.new_mail)
4128 * .setLargeIcon(aBitmap)
4129 * .setStyle(new Notification.InboxStyle()
4130 * .addLine(str1)
4131 * .addLine(str2)
4132 * .setContentTitle(&quot;&quot;)
4133 * .setSummaryText(&quot;+3 more&quot;))
4134 * .build();
Daniel Sandler879c5e02012-04-17 16:46:51 -04004135 * </pre>
Joe Malin8d40d042012-11-05 11:36:40 -08004136 *
Daniel Sandler879c5e02012-04-17 16:46:51 -04004137 * @see Notification#bigContentView
4138 */
Chris Wrenfbd96ba2012-05-01 12:03:58 -04004139 public static class InboxStyle extends Style {
Daniel Sandler879c5e02012-04-17 16:46:51 -04004140 private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5);
4141
Chris Wrenfbd96ba2012-05-01 12:03:58 -04004142 public InboxStyle() {
4143 }
4144
Daniel Sandler879c5e02012-04-17 16:46:51 -04004145 public InboxStyle(Builder builder) {
Chris Wrenfbd96ba2012-05-01 12:03:58 -04004146 setBuilder(builder);
Daniel Sandler879c5e02012-04-17 16:46:51 -04004147 }
4148
Chris Wrend6297db2012-05-03 16:20:13 -04004149 /**
4150 * Overrides ContentTitle in the big form of the template.
4151 * This defaults to the value passed to setContentTitle().
4152 */
4153 public InboxStyle setBigContentTitle(CharSequence title) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04004154 internalSetBigContentTitle(safeCharSequence(title));
Chris Wrend6297db2012-05-03 16:20:13 -04004155 return this;
4156 }
4157
4158 /**
4159 * Set the first line of text after the detail section in the big form of the template.
4160 */
4161 public InboxStyle setSummaryText(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04004162 internalSetSummaryText(safeCharSequence(cs));
Chris Wrend6297db2012-05-03 16:20:13 -04004163 return this;
4164 }
4165
Chris Wren0bd664d2012-08-01 13:56:56 -04004166 /**
4167 * Append a line to the digest section of the Inbox notification.
4168 */
Daniel Sandler879c5e02012-04-17 16:46:51 -04004169 public InboxStyle addLine(CharSequence cs) {
Daniel Sandlerdcbaf662013-04-26 16:23:09 -04004170 mTexts.add(safeCharSequence(cs));
Daniel Sandler879c5e02012-04-17 16:46:51 -04004171 return this;
4172 }
4173
Daniel Sandlerf45564e2013-04-15 15:05:08 -04004174 /**
4175 * @hide
4176 */
4177 public void addExtras(Bundle extras) {
4178 super.addExtras(extras);
Christoph Studer4600f9b2014-07-22 22:44:43 +02004179
Daniel Sandlerf45564e2013-04-15 15:05:08 -04004180 CharSequence[] a = new CharSequence[mTexts.size()];
4181 extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a));
4182 }
4183
Christoph Studer4600f9b2014-07-22 22:44:43 +02004184 /**
4185 * @hide
4186 */
4187 @Override
4188 protected void restoreFromExtras(Bundle extras) {
4189 super.restoreFromExtras(extras);
4190
4191 mTexts.clear();
4192 if (extras.containsKey(EXTRA_TEXT_LINES)) {
4193 Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES));
4194 }
4195 }
4196
Julia Reynoldsd9228f12015-10-20 10:37:27 -04004197 /**
4198 * @hide
4199 */
4200 public RemoteViews makeBigContentView() {
Selim Cinekc848c3a2016-01-13 15:27:30 -08004201 // Remove the content text so it disappears unless you have a summary
Christoph Studer4600f9b2014-07-22 22:44:43 +02004202 // Nasty
Julia Reynoldsd9228f12015-10-20 10:37:27 -04004203 CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT);
4204 mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null);
Christoph Studer4600f9b2014-07-22 22:44:43 +02004205
Jorim Jaggi39fa59f2014-02-25 15:38:45 +01004206 RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource());
Daniel Sandler619738c2012-06-07 16:33:08 -04004207
Julia Reynoldsd9228f12015-10-20 10:37:27 -04004208 mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText);
Christoph Studer4600f9b2014-07-22 22:44:43 +02004209
Chris Wrend6297db2012-05-03 16:20:13 -04004210 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 -04004211 R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6};
Chris Wrend6297db2012-05-03 16:20:13 -04004212
Chris Wren4ed80d52012-05-17 09:30:03 -04004213 // Make sure all rows are gone in case we reuse a view.
4214 for (int rowId : rowIds) {
4215 contentView.setViewVisibility(rowId, View.GONE);
4216 }
4217
Jorim Jaggi445d3c02014-08-19 22:33:42 +02004218 final boolean largeText =
4219 mBuilder.mContext.getResources().getConfiguration().fontScale > 1f;
4220 final float subTextSize = mBuilder.mContext.getResources().getDimensionPixelSize(
4221 R.dimen.notification_subtext_size);
Daniel Sandler879c5e02012-04-17 16:46:51 -04004222 int i=0;
Selim Cinek9d9fc6e2015-11-12 15:49:14 -05004223 final float density = mBuilder.mContext.getResources().getDisplayMetrics().density;
4224 int topPadding = (int) (5 * density);
Selim Cinekc0fac722016-03-07 19:57:06 -08004225 int bottomPadding = mBuilder.mContext.getResources().getDimensionPixelSize(
4226 com.android.internal.R.dimen.notification_content_margin_bottom);
Selim Cinek247fa012016-02-18 09:50:48 -08004227 boolean first = true;
Daniel Sandler879c5e02012-04-17 16:46:51 -04004228 while (i < mTexts.size() && i < rowIds.length) {
4229 CharSequence str = mTexts.get(i);
4230 if (str != null && !str.equals("")) {
4231 contentView.setViewVisibility(rowIds[i], View.VISIBLE);
Jorim Jaggi5c2d8462014-03-21 17:37:00 +01004232 contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str));
Jorim Jaggi445d3c02014-08-19 22:33:42 +02004233 if (largeText) {
4234 contentView.setTextViewTextSize(rowIds[i], TypedValue.COMPLEX_UNIT_PX,
4235 subTextSize);
4236 }
Selim Cinek9d9fc6e2015-11-12 15:49:14 -05004237 contentView.setViewPadding(rowIds[i], 0, topPadding, 0,
4238 i == rowIds.length - 1 || i == mTexts.size() - 1 ? bottomPadding : 0);
Selim Cinek247fa012016-02-18 09:50:48 -08004239 handleInboxImageMargin(contentView, rowIds[i], first);
4240 first = false;
Daniel Sandler879c5e02012-04-17 16:46:51 -04004241 }
4242 i++;
4243 }
Kenny Guy98193ea2014-07-24 19:54:37 +01004244
Selim Cinek1e0bf612015-11-20 15:57:26 -08004245
Daniel Sandler879c5e02012-04-17 16:46:51 -04004246 return contentView;
4247 }
Selim Cinek1e0bf612015-11-20 15:57:26 -08004248
Selim Cinek247fa012016-02-18 09:50:48 -08004249 private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first) {
Selim Cinek1e0bf612015-11-20 15:57:26 -08004250 int endMargin = 0;
Selim Cinek247fa012016-02-18 09:50:48 -08004251 if (first) {
4252 final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0);
4253 final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE);
4254 boolean hasProgress = max != 0 || ind;
4255 if (mBuilder.mN.mLargeIcon != null && !hasProgress) {
4256 endMargin = mBuilder.mContext.getResources().getDimensionPixelSize(
4257 R.dimen.notification_content_picture_margin);
4258 }
Selim Cinek1e0bf612015-11-20 15:57:26 -08004259 }
4260 contentView.setViewLayoutMarginEnd(id, endMargin);
4261 }
Daniel Sandler879c5e02012-04-17 16:46:51 -04004262 }
Dan Sandler842dd772014-05-15 09:36:47 -04004263
4264 /**
4265 * Notification style for media playback notifications.
4266 *
4267 * In the expanded form, {@link Notification#bigContentView}, up to 5
4268 * {@link Notification.Action}s specified with
Dan Sandler86647982015-05-13 23:41:13 -04004269 * {@link Notification.Builder#addAction(Action) addAction} will be
Dan Sandler842dd772014-05-15 09:36:47 -04004270 * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to
4271 * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be
4272 * treated as album artwork.
4273 *
4274 * Unlike the other styles provided here, MediaStyle can also modify the standard-size
4275 * {@link Notification#contentView}; by providing action indices to
Christoph Studerfde6f4d2014-12-12 13:23:26 +01004276 * {@link #setShowActionsInCompactView(int...)} you can promote up to 3 actions to be displayed
Dan Sandler842dd772014-05-15 09:36:47 -04004277 * in the standard view alongside the usual content.
4278 *
Bryan Mawhinney6be8de32014-07-18 10:35:12 +01004279 * Notifications created with MediaStyle will have their category set to
4280 * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different
4281 * category using {@link Notification.Builder#setCategory(String) setCategory()}.
4282 *
Jeff Browndba34ba2014-06-24 20:46:03 -07004283 * Finally, if you attach a {@link android.media.session.MediaSession.Token} using
4284 * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)},
Dan Sandler842dd772014-05-15 09:36:47 -04004285 * the System UI can identify this as a notification representing an active media session
4286 * and respond accordingly (by showing album artwork in the lockscreen, for example).
4287 *
4288 * To use this style with your Notification, feed it to
4289 * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so:
4290 * <pre class="prettyprint">
4291 * Notification noti = new Notification.Builder()
4292 * .setSmallIcon(R.drawable.ic_stat_player)
Christoph Studere935fe92014-11-24 14:18:06 +01004293 * .setContentTitle(&quot;Track title&quot;)
4294 * .setContentText(&quot;Artist - Album&quot;)
4295 * .setLargeIcon(albumArtBitmap))
Bryan Mawhinney6be8de32014-07-18 10:35:12 +01004296 * .setStyle(<b>new Notification.MediaStyle()</b>
4297 * .setMediaSession(mySession))
Dan Sandler842dd772014-05-15 09:36:47 -04004298 * .build();
4299 * </pre>
4300 *
4301 * @see Notification#bigContentView
4302 */
4303 public static class MediaStyle extends Style {
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004304 static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3;
Dan Sandler842dd772014-05-15 09:36:47 -04004305 static final int MAX_MEDIA_BUTTONS = 5;
4306
4307 private int[] mActionsToShowInCompact = null;
Jeff Browndba34ba2014-06-24 20:46:03 -07004308 private MediaSession.Token mToken;
Dan Sandler842dd772014-05-15 09:36:47 -04004309
4310 public MediaStyle() {
4311 }
4312
4313 public MediaStyle(Builder builder) {
4314 setBuilder(builder);
4315 }
4316
4317 /**
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004318 * Request up to 3 actions (by index in the order of addition) to be shown in the compact
Dan Sandler842dd772014-05-15 09:36:47 -04004319 * notification view.
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004320 *
4321 * @param actions the indices of the actions to show in the compact notification view
Dan Sandler842dd772014-05-15 09:36:47 -04004322 */
4323 public MediaStyle setShowActionsInCompactView(int...actions) {
4324 mActionsToShowInCompact = actions;
4325 return this;
4326 }
4327
4328 /**
Jeff Browndba34ba2014-06-24 20:46:03 -07004329 * Attach a {@link android.media.session.MediaSession.Token} to this Notification
4330 * to provide additional playback information and control to the SystemUI.
Dan Sandler842dd772014-05-15 09:36:47 -04004331 */
Jeff Browndba34ba2014-06-24 20:46:03 -07004332 public MediaStyle setMediaSession(MediaSession.Token token) {
Dan Sandler842dd772014-05-15 09:36:47 -04004333 mToken = token;
4334 return this;
4335 }
4336
Christoph Studer4600f9b2014-07-22 22:44:43 +02004337 /**
4338 * @hide
4339 */
Dan Sandler842dd772014-05-15 09:36:47 -04004340 @Override
4341 public Notification buildStyled(Notification wip) {
Christoph Studer4600f9b2014-07-22 22:44:43 +02004342 super.buildStyled(wip);
Bryan Mawhinney6be8de32014-07-18 10:35:12 +01004343 if (wip.category == null) {
4344 wip.category = Notification.CATEGORY_TRANSPORT;
4345 }
Dan Sandler842dd772014-05-15 09:36:47 -04004346 return wip;
4347 }
4348
Christoph Studer4600f9b2014-07-22 22:44:43 +02004349 /**
4350 * @hide
4351 */
4352 @Override
Julia Reynoldsd9228f12015-10-20 10:37:27 -04004353 public RemoteViews makeContentView() {
4354 return makeMediaContentView();
Christoph Studer4600f9b2014-07-22 22:44:43 +02004355 }
4356
4357 /**
4358 * @hide
4359 */
4360 @Override
Julia Reynoldsd9228f12015-10-20 10:37:27 -04004361 public RemoteViews makeBigContentView() {
4362 return makeMediaBigContentView();
Christoph Studer4600f9b2014-07-22 22:44:43 +02004363 }
4364
Selim Cinekcc10bfb2016-02-10 16:24:21 -08004365 /**
4366 * @hide
4367 */
4368 @Override
4369 public RemoteViews makeHeadsUpContentView() {
4370 RemoteViews expanded = makeMediaBigContentView();
4371 return expanded != null ? expanded : makeMediaContentView();
4372 }
4373
Dan Sandler842dd772014-05-15 09:36:47 -04004374 /** @hide */
4375 @Override
4376 public void addExtras(Bundle extras) {
4377 super.addExtras(extras);
4378
4379 if (mToken != null) {
4380 extras.putParcelable(EXTRA_MEDIA_SESSION, mToken);
4381 }
Bryan Mawhinneye191f902014-07-22 12:50:09 +01004382 if (mActionsToShowInCompact != null) {
4383 extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact);
4384 }
Dan Sandler842dd772014-05-15 09:36:47 -04004385 }
4386
Christoph Studer4600f9b2014-07-22 22:44:43 +02004387 /**
4388 * @hide
4389 */
4390 @Override
4391 protected void restoreFromExtras(Bundle extras) {
4392 super.restoreFromExtras(extras);
4393
4394 if (extras.containsKey(EXTRA_MEDIA_SESSION)) {
4395 mToken = extras.getParcelable(EXTRA_MEDIA_SESSION);
4396 }
4397 if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) {
4398 mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS);
4399 }
4400 }
4401
Selim Cinek5bf069a2015-11-10 19:14:27 -05004402 private RemoteViews generateMediaActionButton(Action action, int color) {
Dan Sandler842dd772014-05-15 09:36:47 -04004403 final boolean tombstone = (action.actionIntent == null);
Selim Cinekf33b1112015-07-15 17:45:11 -07004404 RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(),
Alan Viverette3cb07a462014-06-06 14:19:53 -07004405 R.layout.notification_material_media_action);
Dan Sandler68079d52015-07-22 10:45:30 -04004406 button.setImageViewIcon(R.id.action0, action.getIcon());
Selim Cinek5bf069a2015-11-10 19:14:27 -05004407 button.setDrawableParameters(R.id.action0, false, -1, color, PorterDuff.Mode.SRC_ATOP,
4408 -1);
Dan Sandler842dd772014-05-15 09:36:47 -04004409 if (!tombstone) {
4410 button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
4411 }
4412 button.setContentDescription(R.id.action0, action.title);
4413 return button;
4414 }
4415
4416 private RemoteViews makeMediaContentView() {
4417 RemoteViews view = mBuilder.applyStandardTemplate(
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004418 R.layout.notification_template_material_media, false /* hasProgress */);
Dan Sandler842dd772014-05-15 09:36:47 -04004419
4420 final int numActions = mBuilder.mActions.size();
4421 final int N = mActionsToShowInCompact == null
4422 ? 0
4423 : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT);
4424 if (N > 0) {
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004425 view.removeAllViews(com.android.internal.R.id.media_actions);
Dan Sandler842dd772014-05-15 09:36:47 -04004426 for (int i = 0; i < N; i++) {
4427 if (i >= numActions) {
4428 throw new IllegalArgumentException(String.format(
4429 "setShowActionsInCompactView: action %d out of bounds (max %d)",
4430 i, numActions - 1));
4431 }
4432
4433 final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]);
Selim Cinek5bf069a2015-11-10 19:14:27 -05004434 final RemoteViews button = generateMediaActionButton(action,
4435 mBuilder.resolveColor());
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004436 view.addView(com.android.internal.R.id.media_actions, button);
Dan Sandler842dd772014-05-15 09:36:47 -04004437 }
4438 }
Selim Cinekfdc738f2016-01-27 20:04:27 -08004439 handleImage(view);
4440 // handle the content margin
Selim Cinek247fa012016-02-18 09:50:48 -08004441 int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize(
4442 R.dimen.notification_content_margin_end);;
Selim Cinekfdc738f2016-01-27 20:04:27 -08004443 if (mBuilder.mN.mLargeIcon != null) {
Selim Cinek247fa012016-02-18 09:50:48 -08004444 endMargin += mBuilder.mContext.getResources().getDimensionPixelSize(
4445 R.dimen.notification_content_picture_margin);
Selim Cinekfdc738f2016-01-27 20:04:27 -08004446 }
4447 view.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin);
Dan Sandler842dd772014-05-15 09:36:47 -04004448 return view;
4449 }
4450
4451 private RemoteViews makeMediaBigContentView() {
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004452 final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS);
Selim Cinekcc10bfb2016-02-10 16:24:21 -08004453 // Dont add an expanded view if there is no more content to be revealed
4454 int actionsInCompact = mActionsToShowInCompact == null
4455 ? 0
4456 : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT);
4457 if (mBuilder.mN.mLargeIcon == null && actionCount <= actionsInCompact) {
4458 return null;
4459 }
Selim Cinek5bf069a2015-11-10 19:14:27 -05004460 RemoteViews big = mBuilder.applyStandardTemplate(
4461 R.layout.notification_template_material_big_media,
4462 false);
Dan Sandler842dd772014-05-15 09:36:47 -04004463
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004464 if (actionCount > 0) {
4465 big.removeAllViews(com.android.internal.R.id.media_actions);
4466 for (int i = 0; i < actionCount; i++) {
Selim Cinek5bf069a2015-11-10 19:14:27 -05004467 final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i),
4468 mBuilder.resolveColor());
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004469 big.addView(com.android.internal.R.id.media_actions, button);
Dan Sandler842dd772014-05-15 09:36:47 -04004470 }
4471 }
Selim Cinek5bf069a2015-11-10 19:14:27 -05004472 handleImage(big);
Dan Sandler842dd772014-05-15 09:36:47 -04004473 return big;
4474 }
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004475
Selim Cinek5bf069a2015-11-10 19:14:27 -05004476 private void handleImage(RemoteViews contentView) {
4477 if (mBuilder.mN.mLargeIcon != null) {
4478 contentView.setViewLayoutMarginEnd(R.id.line1, 0);
Selim Cinekc848c3a2016-01-13 15:27:30 -08004479 contentView.setViewLayoutMarginEnd(R.id.text, 0);
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004480 }
4481 }
4482
Jorim Jaggi17ee3ec2014-08-29 03:47:31 +02004483 /**
4484 * @hide
4485 */
4486 @Override
4487 protected boolean hasProgress() {
4488 return false;
4489 }
Dan Sandler842dd772014-05-15 09:36:47 -04004490 }
Griff Hazen61a9e862014-05-22 16:05:19 -07004491
Selim Cinek593610c2016-02-16 18:42:57 -08004492 /**
4493 * Notification style for custom views that are decorated by the system
4494 *
4495 * <p>Instead of providing a notification that is completely custom, a developer can set this
4496 * style and still obtain system decorations like the notification header with the expand
4497 * affordance and actions.
4498 *
4499 * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)},
4500 * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and
4501 * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the
4502 * corresponding custom views to display.
4503 *
4504 * To use this style with your Notification, feed it to
4505 * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so:
4506 * <pre class="prettyprint">
4507 * Notification noti = new Notification.Builder()
4508 * .setSmallIcon(R.drawable.ic_stat_player)
4509 * .setLargeIcon(albumArtBitmap))
4510 * .setCustomContentView(contentView);
4511 * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>)
4512 * .build();
4513 * </pre>
4514 */
4515 public static class DecoratedCustomViewStyle extends Style {
4516
4517 public DecoratedCustomViewStyle() {
4518 }
4519
4520 public DecoratedCustomViewStyle(Builder builder) {
4521 setBuilder(builder);
4522 }
4523
4524 /**
4525 * @hide
4526 */
4527 public boolean displayCustomViewInline() {
4528 return true;
4529 }
4530
4531 /**
4532 * @hide
4533 */
4534 @Override
4535 public RemoteViews makeContentView() {
4536 return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView);
4537 }
4538
4539 /**
4540 * @hide
4541 */
4542 @Override
4543 public RemoteViews makeBigContentView() {
4544 return makeDecoratedBigContentView();
4545 }
4546
4547 /**
4548 * @hide
4549 */
4550 @Override
4551 public RemoteViews makeHeadsUpContentView() {
4552 return makeDecoratedHeadsUpContentView();
4553 }
4554
Selim Cinek593610c2016-02-16 18:42:57 -08004555 private RemoteViews makeDecoratedHeadsUpContentView() {
4556 RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null
4557 ? mBuilder.mN.contentView
4558 : mBuilder.mN.headsUpContentView;
4559 if (mBuilder.mActions.size() == 0) {
4560 return makeStandardTemplateWithCustomContent(headsUpContentView);
4561 }
4562 RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions(
4563 mBuilder.getBigBaseLayoutResource());
Selim Cinek247fa012016-02-18 09:50:48 -08004564 buildIntoRemoteViewContent(remoteViews, headsUpContentView);
Selim Cinek593610c2016-02-16 18:42:57 -08004565 return remoteViews;
4566 }
4567
Selim Cinek593610c2016-02-16 18:42:57 -08004568 private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) {
4569 RemoteViews remoteViews = mBuilder.applyStandardTemplate(
4570 mBuilder.getBaseLayoutResource());
Selim Cinek247fa012016-02-18 09:50:48 -08004571 buildIntoRemoteViewContent(remoteViews, customContent);
Selim Cinek593610c2016-02-16 18:42:57 -08004572 return remoteViews;
4573 }
4574
Selim Cinek593610c2016-02-16 18:42:57 -08004575 private RemoteViews makeDecoratedBigContentView() {
4576 RemoteViews bigContentView = mBuilder.mN.bigContentView == null
4577 ? mBuilder.mN.contentView
4578 : mBuilder.mN.bigContentView;
4579 if (mBuilder.mActions.size() == 0) {
4580 return makeStandardTemplateWithCustomContent(bigContentView);
4581 }
4582 RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions(
4583 mBuilder.getBigBaseLayoutResource());
Selim Cinek247fa012016-02-18 09:50:48 -08004584 buildIntoRemoteViewContent(remoteViews, bigContentView);
Selim Cinek593610c2016-02-16 18:42:57 -08004585 return remoteViews;
4586 }
Selim Cinek247fa012016-02-18 09:50:48 -08004587
4588 private void buildIntoRemoteViewContent(RemoteViews remoteViews,
4589 RemoteViews customContent) {
4590 remoteViews.removeAllViews(R.id.notification_main_column);
Adrian Roos5081c0d2016-02-26 16:04:19 -08004591 // Need to clone customContent before adding, because otherwise it can no longer be
4592 // parceled independently of remoteViews.
4593 if (customContent != null) {
4594 customContent = customContent.clone();
4595 }
Selim Cinek247fa012016-02-18 09:50:48 -08004596 remoteViews.addView(R.id.notification_main_column, customContent);
4597 // also update the end margin if there is an image
4598 int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize(
4599 R.dimen.notification_content_margin_end);
4600 if (mBuilder.mN.mLargeIcon != null) {
4601 endMargin += mBuilder.mContext.getResources().getDimensionPixelSize(
4602 R.dimen.notification_content_picture_margin);
4603 }
4604 remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin);
4605 }
Selim Cinek593610c2016-02-16 18:42:57 -08004606 }
4607
Selim Cinek03eb3b72016-02-18 10:39:45 -08004608 /**
4609 * Notification style for media custom views that are decorated by the system
4610 *
4611 * <p>Instead of providing a media notification that is completely custom, a developer can set
4612 * this style and still obtain system decorations like the notification header with the expand
4613 * affordance and actions.
4614 *
4615 * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)},
4616 * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and
4617 * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the
4618 * corresponding custom views to display.
4619 *
4620 * To use this style with your Notification, feed it to
4621 * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so:
4622 * <pre class="prettyprint">
4623 * Notification noti = new Notification.Builder()
4624 * .setSmallIcon(R.drawable.ic_stat_player)
4625 * .setLargeIcon(albumArtBitmap))
4626 * .setCustomContentView(contentView);
4627 * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b>
4628 * .setMediaSession(mySession))
4629 * .build();
4630 * </pre>
4631 *
4632 * @see android.app.Notification.DecoratedCustomViewStyle
4633 * @see android.app.Notification.MediaStyle
4634 */
4635 public static class DecoratedMediaCustomViewStyle extends MediaStyle {
4636
4637 public DecoratedMediaCustomViewStyle() {
4638 }
4639
4640 public DecoratedMediaCustomViewStyle(Builder builder) {
4641 setBuilder(builder);
4642 }
4643
4644 /**
4645 * @hide
4646 */
4647 public boolean displayCustomViewInline() {
4648 return true;
4649 }
4650
4651 /**
4652 * @hide
4653 */
4654 @Override
4655 public RemoteViews makeContentView() {
4656 RemoteViews remoteViews = super.makeContentView();
4657 return buildIntoRemoteView(remoteViews, R.id.notification_content_container,
4658 mBuilder.mN.contentView);
4659 }
4660
4661 /**
4662 * @hide
4663 */
4664 @Override
4665 public RemoteViews makeBigContentView() {
4666 RemoteViews customRemoteView = mBuilder.mN.bigContentView != null
4667 ? mBuilder.mN.bigContentView
4668 : mBuilder.mN.contentView;
4669 return makeBigContentViewWithCustomContent(customRemoteView);
4670 }
4671
4672 private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) {
4673 RemoteViews remoteViews = super.makeBigContentView();
4674 if (remoteViews != null) {
4675 return buildIntoRemoteView(remoteViews, R.id.notification_main_column,
4676 customRemoteView);
4677 } else if (customRemoteView != mBuilder.mN.contentView){
4678 remoteViews = super.makeContentView();
4679 return buildIntoRemoteView(remoteViews, R.id.notification_content_container,
4680 customRemoteView);
4681 } else {
4682 return null;
4683 }
4684 }
4685
4686 /**
4687 * @hide
4688 */
4689 @Override
4690 public RemoteViews makeHeadsUpContentView() {
4691 RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null
4692 ? mBuilder.mN.headsUpContentView
4693 : mBuilder.mN.contentView;
4694 return makeBigContentViewWithCustomContent(customRemoteView);
4695 }
4696
4697 private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id,
4698 RemoteViews customContent) {
4699 remoteViews.removeAllViews(id);
Adrian Roos5081c0d2016-02-26 16:04:19 -08004700 // Need to clone customContent before adding, because otherwise it can no longer be
4701 // parceled independently of remoteViews.
4702 if (customContent != null) {
4703 customContent = customContent.clone();
4704 }
Selim Cinek03eb3b72016-02-18 10:39:45 -08004705 remoteViews.addView(id, customContent);
4706 return remoteViews;
4707 }
4708 }
4709
Christoph Studer4600f9b2014-07-22 22:44:43 +02004710 // When adding a new Style subclass here, don't forget to update
4711 // Builder.getNotificationStyleClass.
4712
Griff Hazen61a9e862014-05-22 16:05:19 -07004713 /**
4714 * Extender interface for use with {@link Builder#extend}. Extenders may be used to add
4715 * metadata or change options on a notification builder.
4716 */
4717 public interface Extender {
4718 /**
4719 * Apply this extender to a notification builder.
4720 * @param builder the builder to be modified.
4721 * @return the build object for chaining.
4722 */
4723 public Builder extend(Builder builder);
4724 }
4725
4726 /**
4727 * Helper class to add wearable extensions to notifications.
4728 * <p class="note"> See
4729 * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications
4730 * for Android Wear</a> for more information on how to use this class.
4731 * <p>
4732 * To create a notification with wearable extensions:
4733 * <ol>
4734 * <li>Create a {@link android.app.Notification.Builder}, setting any desired
4735 * properties.
4736 * <li>Create a {@link android.app.Notification.WearableExtender}.
4737 * <li>Set wearable-specific properties using the
4738 * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}.
4739 * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a
4740 * notification.
4741 * <li>Post the notification to the notification system with the
4742 * {@code NotificationManager.notify(...)} methods.
4743 * </ol>
4744 *
4745 * <pre class="prettyprint">
4746 * Notification notif = new Notification.Builder(mContext)
4747 * .setContentTitle(&quot;New mail from &quot; + sender.toString())
4748 * .setContentText(subject)
4749 * .setSmallIcon(R.drawable.new_mail)
4750 * .extend(new Notification.WearableExtender()
4751 * .setContentIcon(R.drawable.new_mail))
4752 * .build();
4753 * NotificationManager notificationManger =
4754 * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
4755 * notificationManger.notify(0, notif);</pre>
4756 *
4757 * <p>Wearable extensions can be accessed on an existing notification by using the
4758 * {@code WearableExtender(Notification)} constructor,
4759 * and then using the {@code get} methods to access values.
4760 *
4761 * <pre class="prettyprint">
4762 * Notification.WearableExtender wearableExtender = new Notification.WearableExtender(
4763 * notification);
Griff Hazen14f57992014-05-26 09:07:14 -07004764 * List&lt;Notification&gt; pages = wearableExtender.getPages();</pre>
Griff Hazen61a9e862014-05-22 16:05:19 -07004765 */
4766 public static final class WearableExtender implements Extender {
4767 /**
4768 * Sentinel value for an action index that is unset.
4769 */
4770 public static final int UNSET_ACTION_INDEX = -1;
4771
4772 /**
4773 * Size value for use with {@link #setCustomSizePreset} to show this notification with
4774 * default sizing.
4775 * <p>For custom display notifications created using {@link #setDisplayIntent},
Paul Soulosaa4f4bf2015-08-04 11:59:45 -07004776 * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based
Griff Hazen61a9e862014-05-22 16:05:19 -07004777 * on their content.
4778 */
4779 public static final int SIZE_DEFAULT = 0;
4780
4781 /**
4782 * Size value for use with {@link #setCustomSizePreset} to show this notification
4783 * with an extra small size.
4784 * <p>This value is only applicable for custom display notifications created using
4785 * {@link #setDisplayIntent}.
4786 */
4787 public static final int SIZE_XSMALL = 1;
4788
4789 /**
4790 * Size value for use with {@link #setCustomSizePreset} to show this notification
4791 * with a small size.
4792 * <p>This value is only applicable for custom display notifications created using
4793 * {@link #setDisplayIntent}.
4794 */
4795 public static final int SIZE_SMALL = 2;
4796
4797 /**
4798 * Size value for use with {@link #setCustomSizePreset} to show this notification
4799 * with a medium size.
4800 * <p>This value is only applicable for custom display notifications created using
4801 * {@link #setDisplayIntent}.
4802 */
4803 public static final int SIZE_MEDIUM = 3;
4804
4805 /**
4806 * Size value for use with {@link #setCustomSizePreset} to show this notification
4807 * with a large size.
4808 * <p>This value is only applicable for custom display notifications created using
4809 * {@link #setDisplayIntent}.
4810 */
4811 public static final int SIZE_LARGE = 4;
4812
Griff Hazend5f11f92014-05-27 15:40:09 -07004813 /**
4814 * Size value for use with {@link #setCustomSizePreset} to show this notification
4815 * full screen.
4816 * <p>This value is only applicable for custom display notifications created using
4817 * {@link #setDisplayIntent}.
4818 */
4819 public static final int SIZE_FULL_SCREEN = 5;
4820
Griff Hazen5f2edfc2014-09-29 16:28:44 -07004821 /**
4822 * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a
4823 * short amount of time when this notification is displayed on the screen. This
4824 * is the default value.
4825 */
4826 public static final int SCREEN_TIMEOUT_SHORT = 0;
4827
4828 /**
4829 * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on
4830 * for a longer amount of time when this notification is displayed on the screen.
4831 */
4832 public static final int SCREEN_TIMEOUT_LONG = -1;
4833
Griff Hazen61a9e862014-05-22 16:05:19 -07004834 /** Notification extra which contains wearable extensions */
4835 private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS";
4836
Pete Gastaf6781d2014-10-07 15:17:05 -04004837 // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options.
Griff Hazen61a9e862014-05-22 16:05:19 -07004838 private static final String KEY_ACTIONS = "actions";
4839 private static final String KEY_FLAGS = "flags";
4840 private static final String KEY_DISPLAY_INTENT = "displayIntent";
4841 private static final String KEY_PAGES = "pages";
4842 private static final String KEY_BACKGROUND = "background";
4843 private static final String KEY_CONTENT_ICON = "contentIcon";
4844 private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity";
4845 private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex";
4846 private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset";
4847 private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight";
4848 private static final String KEY_GRAVITY = "gravity";
Griff Hazen5f2edfc2014-09-29 16:28:44 -07004849 private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout";
Griff Hazen61a9e862014-05-22 16:05:19 -07004850
4851 // Flags bitwise-ored to mFlags
4852 private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1;
4853 private static final int FLAG_HINT_HIDE_ICON = 1 << 1;
4854 private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2;
4855 private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3;
Griff Hazen5f2edfc2014-09-29 16:28:44 -07004856 private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4;
Griff Hazen61a9e862014-05-22 16:05:19 -07004857
4858 // Default value for flags integer
4859 private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE;
4860
4861 private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END;
4862 private static final int DEFAULT_GRAVITY = Gravity.BOTTOM;
4863
4864 private ArrayList<Action> mActions = new ArrayList<Action>();
4865 private int mFlags = DEFAULT_FLAGS;
4866 private PendingIntent mDisplayIntent;
4867 private ArrayList<Notification> mPages = new ArrayList<Notification>();
4868 private Bitmap mBackground;
4869 private int mContentIcon;
4870 private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY;
4871 private int mContentActionIndex = UNSET_ACTION_INDEX;
4872 private int mCustomSizePreset = SIZE_DEFAULT;
4873 private int mCustomContentHeight;
4874 private int mGravity = DEFAULT_GRAVITY;
Griff Hazen5f2edfc2014-09-29 16:28:44 -07004875 private int mHintScreenTimeout;
Griff Hazen61a9e862014-05-22 16:05:19 -07004876
4877 /**
4878 * Create a {@link android.app.Notification.WearableExtender} with default
4879 * options.
4880 */
4881 public WearableExtender() {
4882 }
4883
4884 public WearableExtender(Notification notif) {
4885 Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS);
4886 if (wearableBundle != null) {
4887 List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS);
4888 if (actions != null) {
4889 mActions.addAll(actions);
4890 }
4891
4892 mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS);
4893 mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT);
4894
4895 Notification[] pages = getNotificationArrayFromBundle(
4896 wearableBundle, KEY_PAGES);
4897 if (pages != null) {
4898 Collections.addAll(mPages, pages);
4899 }
4900
4901 mBackground = wearableBundle.getParcelable(KEY_BACKGROUND);
4902 mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON);
4903 mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY,
4904 DEFAULT_CONTENT_ICON_GRAVITY);
4905 mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX,
4906 UNSET_ACTION_INDEX);
4907 mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET,
4908 SIZE_DEFAULT);
4909 mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT);
4910 mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY);
Griff Hazen5f2edfc2014-09-29 16:28:44 -07004911 mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT);
Griff Hazen61a9e862014-05-22 16:05:19 -07004912 }
4913 }
4914
4915 /**
4916 * Apply wearable extensions to a notification that is being built. This is typically
4917 * called by the {@link android.app.Notification.Builder#extend} method of
4918 * {@link android.app.Notification.Builder}.
4919 */
4920 @Override
4921 public Notification.Builder extend(Notification.Builder builder) {
4922 Bundle wearableBundle = new Bundle();
4923
4924 if (!mActions.isEmpty()) {
4925 wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions);
4926 }
4927 if (mFlags != DEFAULT_FLAGS) {
4928 wearableBundle.putInt(KEY_FLAGS, mFlags);
4929 }
4930 if (mDisplayIntent != null) {
4931 wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent);
4932 }
4933 if (!mPages.isEmpty()) {
4934 wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray(
4935 new Notification[mPages.size()]));
4936 }
4937 if (mBackground != null) {
4938 wearableBundle.putParcelable(KEY_BACKGROUND, mBackground);
4939 }
4940 if (mContentIcon != 0) {
4941 wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon);
4942 }
4943 if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) {
4944 wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity);
4945 }
4946 if (mContentActionIndex != UNSET_ACTION_INDEX) {
4947 wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX,
4948 mContentActionIndex);
4949 }
4950 if (mCustomSizePreset != SIZE_DEFAULT) {
4951 wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset);
4952 }
4953 if (mCustomContentHeight != 0) {
4954 wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight);
4955 }
4956 if (mGravity != DEFAULT_GRAVITY) {
4957 wearableBundle.putInt(KEY_GRAVITY, mGravity);
4958 }
Griff Hazen5f2edfc2014-09-29 16:28:44 -07004959 if (mHintScreenTimeout != 0) {
4960 wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout);
4961 }
Griff Hazen61a9e862014-05-22 16:05:19 -07004962
4963 builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle);
4964 return builder;
4965 }
4966
4967 @Override
4968 public WearableExtender clone() {
4969 WearableExtender that = new WearableExtender();
4970 that.mActions = new ArrayList<Action>(this.mActions);
4971 that.mFlags = this.mFlags;
4972 that.mDisplayIntent = this.mDisplayIntent;
4973 that.mPages = new ArrayList<Notification>(this.mPages);
4974 that.mBackground = this.mBackground;
4975 that.mContentIcon = this.mContentIcon;
4976 that.mContentIconGravity = this.mContentIconGravity;
4977 that.mContentActionIndex = this.mContentActionIndex;
4978 that.mCustomSizePreset = this.mCustomSizePreset;
4979 that.mCustomContentHeight = this.mCustomContentHeight;
4980 that.mGravity = this.mGravity;
Griff Hazen5f2edfc2014-09-29 16:28:44 -07004981 that.mHintScreenTimeout = this.mHintScreenTimeout;
Griff Hazen61a9e862014-05-22 16:05:19 -07004982 return that;
4983 }
4984
4985 /**
4986 * Add a wearable action to this notification.
4987 *
4988 * <p>When wearable actions are added using this method, the set of actions that
4989 * show on a wearable device splits from devices that only show actions added
4990 * using {@link android.app.Notification.Builder#addAction}. This allows for customization
4991 * of which actions display on different devices.
4992 *
4993 * @param action the action to add to this notification
4994 * @return this object for method chaining
4995 * @see android.app.Notification.Action
4996 */
4997 public WearableExtender addAction(Action action) {
4998 mActions.add(action);
4999 return this;
5000 }
5001
5002 /**
5003 * Adds wearable actions to this notification.
5004 *
5005 * <p>When wearable actions are added using this method, the set of actions that
5006 * show on a wearable device splits from devices that only show actions added
5007 * using {@link android.app.Notification.Builder#addAction}. This allows for customization
5008 * of which actions display on different devices.
5009 *
5010 * @param actions the actions to add to this notification
5011 * @return this object for method chaining
5012 * @see android.app.Notification.Action
5013 */
5014 public WearableExtender addActions(List<Action> actions) {
5015 mActions.addAll(actions);
5016 return this;
5017 }
5018
5019 /**
5020 * Clear all wearable actions present on this builder.
5021 * @return this object for method chaining.
5022 * @see #addAction
5023 */
5024 public WearableExtender clearActions() {
5025 mActions.clear();
5026 return this;
5027 }
5028
5029 /**
5030 * Get the wearable actions present on this notification.
5031 */
5032 public List<Action> getActions() {
5033 return mActions;
5034 }
5035
5036 /**
5037 * Set an intent to launch inside of an activity view when displaying
Griff Hazen14f57992014-05-26 09:07:14 -07005038 * this notification. The {@link PendingIntent} provided should be for an activity.
5039 *
5040 * <pre class="prettyprint">
5041 * Intent displayIntent = new Intent(context, MyDisplayActivity.class);
5042 * PendingIntent displayPendingIntent = PendingIntent.getActivity(context,
5043 * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT);
5044 * Notification notif = new Notification.Builder(context)
5045 * .extend(new Notification.WearableExtender()
5046 * .setDisplayIntent(displayPendingIntent)
5047 * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM))
5048 * .build();</pre>
5049 *
5050 * <p>The activity to launch needs to allow embedding, must be exported, and
Griff Hazen831ca9d2014-06-17 00:38:38 -07005051 * should have an empty task affinity. It is also recommended to use the device
5052 * default light theme.
Griff Hazen14f57992014-05-26 09:07:14 -07005053 *
5054 * <p>Example AndroidManifest.xml entry:
5055 * <pre class="prettyprint">
5056 * &lt;activity android:name=&quot;com.example.MyDisplayActivity&quot;
5057 * android:exported=&quot;true&quot;
5058 * android:allowEmbedded=&quot;true&quot;
Griff Hazen831ca9d2014-06-17 00:38:38 -07005059 * android:taskAffinity=&quot;&quot;
5060 * android:theme=&quot;@android:style/Theme.DeviceDefault.Light&quot; /&gt;</pre>
Griff Hazen61a9e862014-05-22 16:05:19 -07005061 *
5062 * @param intent the {@link PendingIntent} for an activity
5063 * @return this object for method chaining
5064 * @see android.app.Notification.WearableExtender#getDisplayIntent
5065 */
5066 public WearableExtender setDisplayIntent(PendingIntent intent) {
5067 mDisplayIntent = intent;
5068 return this;
5069 }
5070
5071 /**
5072 * Get the intent to launch inside of an activity view when displaying this
5073 * notification. This {@code PendingIntent} should be for an activity.
5074 */
5075 public PendingIntent getDisplayIntent() {
5076 return mDisplayIntent;
5077 }
5078
5079 /**
5080 * Add an additional page of content to display with this notification. The current
5081 * notification forms the first page, and pages added using this function form
5082 * subsequent pages. This field can be used to separate a notification into multiple
5083 * sections.
5084 *
5085 * @param page the notification to add as another page
5086 * @return this object for method chaining
5087 * @see android.app.Notification.WearableExtender#getPages
5088 */
5089 public WearableExtender addPage(Notification page) {
5090 mPages.add(page);
5091 return this;
5092 }
5093
5094 /**
5095 * Add additional pages of content to display with this notification. The current
5096 * notification forms the first page, and pages added using this function form
5097 * subsequent pages. This field can be used to separate a notification into multiple
5098 * sections.
5099 *
5100 * @param pages a list of notifications
5101 * @return this object for method chaining
5102 * @see android.app.Notification.WearableExtender#getPages
5103 */
5104 public WearableExtender addPages(List<Notification> pages) {
5105 mPages.addAll(pages);
5106 return this;
5107 }
5108
5109 /**
5110 * Clear all additional pages present on this builder.
5111 * @return this object for method chaining.
5112 * @see #addPage
5113 */
5114 public WearableExtender clearPages() {
5115 mPages.clear();
5116 return this;
5117 }
5118
5119 /**
5120 * Get the array of additional pages of content for displaying this notification. The
5121 * current notification forms the first page, and elements within this array form
5122 * subsequent pages. This field can be used to separate a notification into multiple
5123 * sections.
5124 * @return the pages for this notification
5125 */
5126 public List<Notification> getPages() {
5127 return mPages;
5128 }
5129
5130 /**
5131 * Set a background image to be displayed behind the notification content.
5132 * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background
5133 * will work with any notification style.
5134 *
5135 * @param background the background bitmap
5136 * @return this object for method chaining
5137 * @see android.app.Notification.WearableExtender#getBackground
5138 */
5139 public WearableExtender setBackground(Bitmap background) {
5140 mBackground = background;
5141 return this;
5142 }
5143
5144 /**
5145 * Get a background image to be displayed behind the notification content.
5146 * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background
5147 * will work with any notification style.
5148 *
5149 * @return the background image
5150 * @see android.app.Notification.WearableExtender#setBackground
5151 */
5152 public Bitmap getBackground() {
5153 return mBackground;
5154 }
5155
5156 /**
5157 * Set an icon that goes with the content of this notification.
5158 */
5159 public WearableExtender setContentIcon(int icon) {
5160 mContentIcon = icon;
5161 return this;
5162 }
5163
5164 /**
5165 * Get an icon that goes with the content of this notification.
5166 */
5167 public int getContentIcon() {
5168 return mContentIcon;
5169 }
5170
5171 /**
5172 * Set the gravity that the content icon should have within the notification display.
5173 * Supported values include {@link android.view.Gravity#START} and
5174 * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}.
5175 * @see #setContentIcon
5176 */
5177 public WearableExtender setContentIconGravity(int contentIconGravity) {
5178 mContentIconGravity = contentIconGravity;
5179 return this;
5180 }
5181
5182 /**
5183 * Get the gravity that the content icon should have within the notification display.
5184 * Supported values include {@link android.view.Gravity#START} and
5185 * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}.
5186 * @see #getContentIcon
5187 */
5188 public int getContentIconGravity() {
5189 return mContentIconGravity;
5190 }
5191
5192 /**
5193 * Set an action from this notification's actions to be clickable with the content of
Griff Hazen14f57992014-05-26 09:07:14 -07005194 * this notification. This action will no longer display separately from the
5195 * notification's content.
5196 *
Griff Hazenca48d352014-05-28 22:37:13 -07005197 * <p>For notifications with multiple pages, child pages can also have content actions
Griff Hazen14f57992014-05-26 09:07:14 -07005198 * set, although the list of available actions comes from the main notification and not
5199 * from the child page's notification.
5200 *
5201 * @param actionIndex The index of the action to hoist onto the current notification page.
5202 * If wearable actions were added to the main notification, this index
5203 * will apply to that list, otherwise it will apply to the regular
5204 * actions list.
Griff Hazen61a9e862014-05-22 16:05:19 -07005205 */
5206 public WearableExtender setContentAction(int actionIndex) {
5207 mContentActionIndex = actionIndex;
5208 return this;
5209 }
5210
5211 /**
Griff Hazenca48d352014-05-28 22:37:13 -07005212 * Get the index of the notification action, if any, that was specified as being clickable
5213 * with the content of this notification. This action will no longer display separately
Griff Hazen14f57992014-05-26 09:07:14 -07005214 * from the notification's content.
Griff Hazen61a9e862014-05-22 16:05:19 -07005215 *
Griff Hazenca48d352014-05-28 22:37:13 -07005216 * <p>For notifications with multiple pages, child pages can also have content actions
Griff Hazen14f57992014-05-26 09:07:14 -07005217 * set, although the list of available actions comes from the main notification and not
5218 * from the child page's notification.
5219 *
5220 * <p>If wearable specific actions were added to the main notification, this index will
5221 * apply to that list, otherwise it will apply to the regular actions list.
Griff Hazenca48d352014-05-28 22:37:13 -07005222 *
5223 * @return the action index or {@link #UNSET_ACTION_INDEX} if no action was selected.
Griff Hazen61a9e862014-05-22 16:05:19 -07005224 */
5225 public int getContentAction() {
5226 return mContentActionIndex;
5227 }
5228
5229 /**
5230 * Set the gravity that this notification should have within the available viewport space.
5231 * Supported values include {@link android.view.Gravity#TOP},
5232 * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}.
5233 * The default value is {@link android.view.Gravity#BOTTOM}.
5234 */
5235 public WearableExtender setGravity(int gravity) {
5236 mGravity = gravity;
5237 return this;
5238 }
5239
5240 /**
5241 * Get the gravity that this notification should have within the available viewport space.
5242 * Supported values include {@link android.view.Gravity#TOP},
5243 * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}.
5244 * The default value is {@link android.view.Gravity#BOTTOM}.
5245 */
5246 public int getGravity() {
5247 return mGravity;
5248 }
5249
5250 /**
5251 * Set the custom size preset for the display of this notification out of the available
5252 * presets found in {@link android.app.Notification.WearableExtender}, e.g.
5253 * {@link #SIZE_LARGE}.
5254 * <p>Some custom size presets are only applicable for custom display notifications created
5255 * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the
5256 * documentation for the preset in question. See also
5257 * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}.
5258 */
5259 public WearableExtender setCustomSizePreset(int sizePreset) {
5260 mCustomSizePreset = sizePreset;
5261 return this;
5262 }
5263
5264 /**
5265 * Get the custom size preset for the display of this notification out of the available
5266 * presets found in {@link android.app.Notification.WearableExtender}, e.g.
5267 * {@link #SIZE_LARGE}.
5268 * <p>Some custom size presets are only applicable for custom display notifications created
5269 * using {@link #setDisplayIntent}. Check the documentation for the preset in question.
5270 * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}.
5271 */
5272 public int getCustomSizePreset() {
5273 return mCustomSizePreset;
5274 }
5275
5276 /**
5277 * Set the custom height in pixels for the display of this notification's content.
5278 * <p>This option is only available for custom display notifications created
5279 * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also
5280 * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and
5281 * {@link #getCustomContentHeight}.
5282 */
5283 public WearableExtender setCustomContentHeight(int height) {
5284 mCustomContentHeight = height;
5285 return this;
5286 }
5287
5288 /**
5289 * Get the custom height in pixels for the display of this notification's content.
5290 * <p>This option is only available for custom display notifications created
5291 * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and
5292 * {@link #setCustomContentHeight}.
5293 */
5294 public int getCustomContentHeight() {
5295 return mCustomContentHeight;
5296 }
5297
5298 /**
5299 * Set whether the scrolling position for the contents of this notification should start
5300 * at the bottom of the contents instead of the top when the contents are too long to
5301 * display within the screen. Default is false (start scroll at the top).
5302 */
5303 public WearableExtender setStartScrollBottom(boolean startScrollBottom) {
5304 setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom);
5305 return this;
5306 }
5307
5308 /**
5309 * Get whether the scrolling position for the contents of this notification should start
5310 * at the bottom of the contents instead of the top when the contents are too long to
5311 * display within the screen. Default is false (start scroll at the top).
5312 */
5313 public boolean getStartScrollBottom() {
5314 return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0;
5315 }
5316
5317 /**
5318 * Set whether the content intent is available when the wearable device is not connected
5319 * to a companion device. The user can still trigger this intent when the wearable device
5320 * is offline, but a visual hint will indicate that the content intent may not be available.
5321 * Defaults to true.
5322 */
5323 public WearableExtender setContentIntentAvailableOffline(
5324 boolean contentIntentAvailableOffline) {
5325 setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline);
5326 return this;
5327 }
5328
5329 /**
5330 * Get whether the content intent is available when the wearable device is not connected
5331 * to a companion device. The user can still trigger this intent when the wearable device
5332 * is offline, but a visual hint will indicate that the content intent may not be available.
5333 * Defaults to true.
5334 */
5335 public boolean getContentIntentAvailableOffline() {
5336 return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0;
5337 }
5338
5339 /**
5340 * Set a hint that this notification's icon should not be displayed.
5341 * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise.
5342 * @return this object for method chaining
5343 */
5344 public WearableExtender setHintHideIcon(boolean hintHideIcon) {
5345 setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon);
5346 return this;
5347 }
5348
5349 /**
5350 * Get a hint that this notification's icon should not be displayed.
5351 * @return {@code true} if this icon should not be displayed, false otherwise.
5352 * The default value is {@code false} if this was never set.
5353 */
5354 public boolean getHintHideIcon() {
5355 return (mFlags & FLAG_HINT_HIDE_ICON) != 0;
5356 }
5357
5358 /**
5359 * Set a visual hint that only the background image of this notification should be
5360 * displayed, and other semantic content should be hidden. This hint is only applicable
5361 * to sub-pages added using {@link #addPage}.
5362 */
5363 public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) {
5364 setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly);
5365 return this;
5366 }
5367
5368 /**
5369 * Get a visual hint that only the background image of this notification should be
5370 * displayed, and other semantic content should be hidden. This hint is only applicable
5371 * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}.
5372 */
5373 public boolean getHintShowBackgroundOnly() {
5374 return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0;
5375 }
5376
Griff Hazen5f2edfc2014-09-29 16:28:44 -07005377 /**
Griff Hazen9c5be4e2014-11-17 17:47:50 -08005378 * Set a hint that this notification's background should not be clipped if possible,
5379 * and should instead be resized to fully display on the screen, retaining the aspect
5380 * ratio of the image. This can be useful for images like barcodes or qr codes.
Griff Hazen5f2edfc2014-09-29 16:28:44 -07005381 * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible.
5382 * @return this object for method chaining
5383 */
5384 public WearableExtender setHintAvoidBackgroundClipping(
5385 boolean hintAvoidBackgroundClipping) {
5386 setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping);
5387 return this;
5388 }
5389
5390 /**
Griff Hazen9c5be4e2014-11-17 17:47:50 -08005391 * Get a hint that this notification's background should not be clipped if possible,
5392 * and should instead be resized to fully display on the screen, retaining the aspect
5393 * ratio of the image. This can be useful for images like barcodes or qr codes.
Griff Hazen5f2edfc2014-09-29 16:28:44 -07005394 * @return {@code true} if it's ok if the background is clipped on the screen, false
5395 * otherwise. The default value is {@code false} if this was never set.
5396 */
5397 public boolean getHintAvoidBackgroundClipping() {
5398 return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0;
5399 }
5400
5401 /**
5402 * Set a hint that the screen should remain on for at least this duration when
5403 * this notification is displayed on the screen.
5404 * @param timeout The requested screen timeout in milliseconds. Can also be either
5405 * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}.
5406 * @return this object for method chaining
5407 */
5408 public WearableExtender setHintScreenTimeout(int timeout) {
5409 mHintScreenTimeout = timeout;
5410 return this;
5411 }
5412
5413 /**
5414 * Get the duration, in milliseconds, that the screen should remain on for
5415 * when this notification is displayed.
5416 * @return the duration in milliseconds if > 0, or either one of the sentinel values
5417 * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}.
5418 */
5419 public int getHintScreenTimeout() {
5420 return mHintScreenTimeout;
5421 }
5422
Griff Hazen61a9e862014-05-22 16:05:19 -07005423 private void setFlag(int mask, boolean value) {
5424 if (value) {
5425 mFlags |= mask;
5426 } else {
5427 mFlags &= ~mask;
5428 }
5429 }
5430 }
5431
5432 /**
Zhen Yu Song9d5528b2014-11-14 15:34:39 -08005433 * <p>Helper class to add Android Auto extensions to notifications. To create a notification
5434 * with car extensions:
5435 *
5436 * <ol>
5437 * <li>Create an {@link Notification.Builder}, setting any desired
5438 * properties.
5439 * <li>Create a {@link CarExtender}.
5440 * <li>Set car-specific properties using the {@code add} and {@code set} methods of
5441 * {@link CarExtender}.
5442 * <li>Call {@link Notification.Builder#extend(Notification.Extender)}
5443 * to apply the extensions to a notification.
5444 * </ol>
5445 *
5446 * <pre class="prettyprint">
5447 * Notification notification = new Notification.Builder(context)
5448 * ...
5449 * .extend(new CarExtender()
5450 * .set*(...))
5451 * .build();
5452 * </pre>
5453 *
5454 * <p>Car extensions can be accessed on an existing notification by using the
5455 * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods
5456 * to access values.
5457 */
5458 public static final class CarExtender implements Extender {
5459 private static final String TAG = "CarExtender";
5460
5461 private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS";
5462 private static final String EXTRA_LARGE_ICON = "large_icon";
5463 private static final String EXTRA_CONVERSATION = "car_conversation";
5464 private static final String EXTRA_COLOR = "app_color";
5465
5466 private Bitmap mLargeIcon;
5467 private UnreadConversation mUnreadConversation;
5468 private int mColor = Notification.COLOR_DEFAULT;
5469
5470 /**
5471 * Create a {@link CarExtender} with default options.
5472 */
5473 public CarExtender() {
5474 }
5475
5476 /**
5477 * Create a {@link CarExtender} from the CarExtender options of an existing Notification.
5478 *
5479 * @param notif The notification from which to copy options.
5480 */
5481 public CarExtender(Notification notif) {
5482 Bundle carBundle = notif.extras == null ?
5483 null : notif.extras.getBundle(EXTRA_CAR_EXTENDER);
5484 if (carBundle != null) {
5485 mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON);
5486 mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT);
5487
5488 Bundle b = carBundle.getBundle(EXTRA_CONVERSATION);
5489 mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b);
5490 }
5491 }
5492
5493 /**
5494 * Apply car extensions to a notification that is being built. This is typically called by
5495 * the {@link Notification.Builder#extend(Notification.Extender)}
5496 * method of {@link Notification.Builder}.
5497 */
5498 @Override
5499 public Notification.Builder extend(Notification.Builder builder) {
5500 Bundle carExtensions = new Bundle();
5501
5502 if (mLargeIcon != null) {
5503 carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon);
5504 }
5505 if (mColor != Notification.COLOR_DEFAULT) {
5506 carExtensions.putInt(EXTRA_COLOR, mColor);
5507 }
5508
5509 if (mUnreadConversation != null) {
5510 Bundle b = mUnreadConversation.getBundleForUnreadConversation();
5511 carExtensions.putBundle(EXTRA_CONVERSATION, b);
5512 }
5513
5514 builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions);
5515 return builder;
5516 }
5517
5518 /**
5519 * Sets the accent color to use when Android Auto presents the notification.
5520 *
5521 * Android Auto uses the color set with {@link Notification.Builder#setColor(int)}
5522 * to accent the displayed notification. However, not all colors are acceptable in an
5523 * automotive setting. This method can be used to override the color provided in the
5524 * notification in such a situation.
5525 */
Tor Norbye80756e32015-03-02 09:39:27 -08005526 public CarExtender setColor(@ColorInt int color) {
Zhen Yu Song9d5528b2014-11-14 15:34:39 -08005527 mColor = color;
5528 return this;
5529 }
5530
5531 /**
5532 * Gets the accent color.
5533 *
Julia Reynoldsd9228f12015-10-20 10:37:27 -04005534 * @see #setColor
Zhen Yu Song9d5528b2014-11-14 15:34:39 -08005535 */
Tor Norbye80756e32015-03-02 09:39:27 -08005536 @ColorInt
Zhen Yu Song9d5528b2014-11-14 15:34:39 -08005537 public int getColor() {
5538 return mColor;
5539 }
5540
5541 /**
5542 * Sets the large icon of the car notification.
5543 *
5544 * If no large icon is set in the extender, Android Auto will display the icon
5545 * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)}
5546 *
5547 * @param largeIcon The large icon to use in the car notification.
5548 * @return This object for method chaining.
5549 */
5550 public CarExtender setLargeIcon(Bitmap largeIcon) {
5551 mLargeIcon = largeIcon;
5552 return this;
5553 }
5554
5555 /**
5556 * Gets the large icon used in this car notification, or null if no icon has been set.
5557 *
5558 * @return The large icon for the car notification.
5559 * @see CarExtender#setLargeIcon
5560 */
5561 public Bitmap getLargeIcon() {
5562 return mLargeIcon;
5563 }
5564
5565 /**
5566 * Sets the unread conversation in a message notification.
5567 *
5568 * @param unreadConversation The unread part of the conversation this notification conveys.
5569 * @return This object for method chaining.
5570 */
5571 public CarExtender setUnreadConversation(UnreadConversation unreadConversation) {
5572 mUnreadConversation = unreadConversation;
5573 return this;
5574 }
5575
5576 /**
5577 * Returns the unread conversation conveyed by this notification.
5578 * @see #setUnreadConversation(UnreadConversation)
5579 */
5580 public UnreadConversation getUnreadConversation() {
5581 return mUnreadConversation;
5582 }
5583
5584 /**
5585 * A class which holds the unread messages from a conversation.
5586 */
5587 public static class UnreadConversation {
5588 private static final String KEY_AUTHOR = "author";
5589 private static final String KEY_TEXT = "text";
5590 private static final String KEY_MESSAGES = "messages";
5591 private static final String KEY_REMOTE_INPUT = "remote_input";
5592 private static final String KEY_ON_REPLY = "on_reply";
5593 private static final String KEY_ON_READ = "on_read";
5594 private static final String KEY_PARTICIPANTS = "participants";
5595 private static final String KEY_TIMESTAMP = "timestamp";
5596
5597 private final String[] mMessages;
5598 private final RemoteInput mRemoteInput;
5599 private final PendingIntent mReplyPendingIntent;
5600 private final PendingIntent mReadPendingIntent;
5601 private final String[] mParticipants;
5602 private final long mLatestTimestamp;
5603
5604 UnreadConversation(String[] messages, RemoteInput remoteInput,
5605 PendingIntent replyPendingIntent, PendingIntent readPendingIntent,
5606 String[] participants, long latestTimestamp) {
5607 mMessages = messages;
5608 mRemoteInput = remoteInput;
5609 mReadPendingIntent = readPendingIntent;
5610 mReplyPendingIntent = replyPendingIntent;
5611 mParticipants = participants;
5612 mLatestTimestamp = latestTimestamp;
5613 }
5614
5615 /**
5616 * Gets the list of messages conveyed by this notification.
5617 */
5618 public String[] getMessages() {
5619 return mMessages;
5620 }
5621
5622 /**
5623 * Gets the remote input that will be used to convey the response to a message list, or
5624 * null if no such remote input exists.
5625 */
5626 public RemoteInput getRemoteInput() {
5627 return mRemoteInput;
5628 }
5629
5630 /**
5631 * Gets the pending intent that will be triggered when the user replies to this
5632 * notification.
5633 */
5634 public PendingIntent getReplyPendingIntent() {
5635 return mReplyPendingIntent;
5636 }
5637
5638 /**
5639 * Gets the pending intent that Android Auto will send after it reads aloud all messages
5640 * in this object's message list.
5641 */
5642 public PendingIntent getReadPendingIntent() {
5643 return mReadPendingIntent;
5644 }
5645
5646 /**
5647 * Gets the participants in the conversation.
5648 */
5649 public String[] getParticipants() {
5650 return mParticipants;
5651 }
5652
5653 /**
5654 * Gets the firs participant in the conversation.
5655 */
5656 public String getParticipant() {
5657 return mParticipants.length > 0 ? mParticipants[0] : null;
5658 }
5659
5660 /**
5661 * Gets the timestamp of the conversation.
5662 */
5663 public long getLatestTimestamp() {
5664 return mLatestTimestamp;
5665 }
5666
5667 Bundle getBundleForUnreadConversation() {
5668 Bundle b = new Bundle();
5669 String author = null;
5670 if (mParticipants != null && mParticipants.length > 1) {
5671 author = mParticipants[0];
5672 }
5673 Parcelable[] messages = new Parcelable[mMessages.length];
5674 for (int i = 0; i < messages.length; i++) {
5675 Bundle m = new Bundle();
5676 m.putString(KEY_TEXT, mMessages[i]);
5677 m.putString(KEY_AUTHOR, author);
5678 messages[i] = m;
5679 }
5680 b.putParcelableArray(KEY_MESSAGES, messages);
5681 if (mRemoteInput != null) {
5682 b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput);
5683 }
5684 b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent);
5685 b.putParcelable(KEY_ON_READ, mReadPendingIntent);
5686 b.putStringArray(KEY_PARTICIPANTS, mParticipants);
5687 b.putLong(KEY_TIMESTAMP, mLatestTimestamp);
5688 return b;
5689 }
5690
5691 static UnreadConversation getUnreadConversationFromBundle(Bundle b) {
5692 if (b == null) {
5693 return null;
5694 }
5695 Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES);
5696 String[] messages = null;
5697 if (parcelableMessages != null) {
5698 String[] tmp = new String[parcelableMessages.length];
5699 boolean success = true;
5700 for (int i = 0; i < tmp.length; i++) {
5701 if (!(parcelableMessages[i] instanceof Bundle)) {
5702 success = false;
5703 break;
5704 }
5705 tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT);
5706 if (tmp[i] == null) {
5707 success = false;
5708 break;
5709 }
5710 }
5711 if (success) {
5712 messages = tmp;
5713 } else {
5714 return null;
5715 }
5716 }
5717
5718 PendingIntent onRead = b.getParcelable(KEY_ON_READ);
5719 PendingIntent onReply = b.getParcelable(KEY_ON_REPLY);
5720
5721 RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT);
5722
5723 String[] participants = b.getStringArray(KEY_PARTICIPANTS);
5724 if (participants == null || participants.length != 1) {
5725 return null;
5726 }
5727
5728 return new UnreadConversation(messages,
5729 remoteInput,
5730 onReply,
5731 onRead,
5732 participants, b.getLong(KEY_TIMESTAMP));
5733 }
5734 };
5735
5736 /**
5737 * Builder class for {@link CarExtender.UnreadConversation} objects.
5738 */
5739 public static class Builder {
5740 private final List<String> mMessages = new ArrayList<String>();
5741 private final String mParticipant;
5742 private RemoteInput mRemoteInput;
5743 private PendingIntent mReadPendingIntent;
5744 private PendingIntent mReplyPendingIntent;
5745 private long mLatestTimestamp;
5746
5747 /**
5748 * Constructs a new builder for {@link CarExtender.UnreadConversation}.
5749 *
5750 * @param name The name of the other participant in the conversation.
5751 */
5752 public Builder(String name) {
5753 mParticipant = name;
5754 }
5755
5756 /**
5757 * Appends a new unread message to the list of messages for this conversation.
5758 *
5759 * The messages should be added from oldest to newest.
5760 *
5761 * @param message The text of the new unread message.
5762 * @return This object for method chaining.
5763 */
5764 public Builder addMessage(String message) {
5765 mMessages.add(message);
5766 return this;
5767 }
5768
5769 /**
5770 * Sets the pending intent and remote input which will convey the reply to this
5771 * notification.
5772 *
5773 * @param pendingIntent The pending intent which will be triggered on a reply.
5774 * @param remoteInput The remote input parcelable which will carry the reply.
5775 * @return This object for method chaining.
5776 *
5777 * @see CarExtender.UnreadConversation#getRemoteInput
5778 * @see CarExtender.UnreadConversation#getReplyPendingIntent
5779 */
5780 public Builder setReplyAction(
5781 PendingIntent pendingIntent, RemoteInput remoteInput) {
5782 mRemoteInput = remoteInput;
5783 mReplyPendingIntent = pendingIntent;
5784
5785 return this;
5786 }
5787
5788 /**
5789 * Sets the pending intent that will be sent once the messages in this notification
5790 * are read.
5791 *
5792 * @param pendingIntent The pending intent to use.
5793 * @return This object for method chaining.
5794 */
5795 public Builder setReadPendingIntent(PendingIntent pendingIntent) {
5796 mReadPendingIntent = pendingIntent;
5797 return this;
5798 }
5799
5800 /**
5801 * Sets the timestamp of the most recent message in an unread conversation.
5802 *
5803 * If a messaging notification has been posted by your application and has not
5804 * yet been cancelled, posting a later notification with the same id and tag
5805 * but without a newer timestamp may result in Android Auto not displaying a
5806 * heads up notification for the later notification.
5807 *
5808 * @param timestamp The timestamp of the most recent message in the conversation.
5809 * @return This object for method chaining.
5810 */
5811 public Builder setLatestTimestamp(long timestamp) {
5812 mLatestTimestamp = timestamp;
5813 return this;
5814 }
5815
5816 /**
5817 * Builds a new unread conversation object.
5818 *
5819 * @return The new unread conversation object.
5820 */
5821 public UnreadConversation build() {
5822 String[] messages = mMessages.toArray(new String[mMessages.size()]);
5823 String[] participants = { mParticipant };
5824 return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent,
5825 mReadPendingIntent, participants, mLatestTimestamp);
5826 }
5827 }
5828 }
5829
5830 /**
Griff Hazen61a9e862014-05-22 16:05:19 -07005831 * Get an array of Notification objects from a parcelable array bundle field.
5832 * Update the bundle to have a typed array so fetches in the future don't need
5833 * to do an array copy.
5834 */
5835 private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) {
5836 Parcelable[] array = bundle.getParcelableArray(key);
5837 if (array instanceof Notification[] || array == null) {
5838 return (Notification[]) array;
5839 }
5840 Notification[] typedArray = Arrays.copyOf(array, array.length,
5841 Notification[].class);
5842 bundle.putParcelableArray(key, typedArray);
5843 return typedArray;
5844 }
Christoph Studer4600f9b2014-07-22 22:44:43 +02005845
5846 private static class BuilderRemoteViews extends RemoteViews {
5847 public BuilderRemoteViews(Parcel parcel) {
5848 super(parcel);
5849 }
5850
Kenny Guy77320062014-08-27 21:37:15 +01005851 public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) {
5852 super(appInfo, layoutId);
Christoph Studer4600f9b2014-07-22 22:44:43 +02005853 }
5854
5855 @Override
5856 public BuilderRemoteViews clone() {
5857 Parcel p = Parcel.obtain();
5858 writeToParcel(p, 0);
5859 p.setDataPosition(0);
5860 BuilderRemoteViews brv = new BuilderRemoteViews(p);
5861 p.recycle();
5862 return brv;
5863 }
5864 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005865}