The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.app; |
| 18 | |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 20 | import android.annotation.DrawableRes; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 21 | import android.annotation.IntDef; |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 22 | import android.annotation.SdkConstant; |
| 23 | import android.annotation.SdkConstant.SdkConstantType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 26 | import android.content.pm.ApplicationInfo; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 27 | import android.content.pm.PackageManager.NameNotFoundException; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 28 | import android.content.res.ColorStateList; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 29 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 30 | import android.graphics.Canvas; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 31 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 32 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 33 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 34 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 35 | import android.media.AudioManager; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 36 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 38 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 39 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 40 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.os.Parcel; |
| 42 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 43 | import android.os.SystemClock; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 44 | import android.os.UserHandle; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 45 | import android.text.SpannableStringBuilder; |
| 46 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 48 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 49 | import android.text.style.CharacterStyle; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 50 | import android.text.style.RelativeSizeSpan; |
| 51 | import android.text.style.TextAppearanceSpan; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 52 | import android.util.Log; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 53 | import android.util.SparseArray; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 54 | import android.util.TypedValue; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 55 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 56 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 57 | import android.view.View; |
Adrian Roos | 9b123cf | 2016-02-04 14:55:57 -0800 | [diff] [blame] | 58 | import android.view.ViewGroup; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 59 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.widget.RemoteViews; |
| 61 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 62 | import com.android.internal.R; |
Griff Hazen | c091ba8 | 2014-05-16 10:13:26 -0700 | [diff] [blame] | 63 | import com.android.internal.util.NotificationColorUtil; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 64 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 65 | import java.lang.annotation.Retention; |
| 66 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 67 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 68 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 69 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 70 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 71 | import java.util.List; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 72 | import java.util.Set; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 73 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | /** |
| 75 | * A class that represents how a persistent notification is to be presented to |
| 76 | * the user using the {@link android.app.NotificationManager}. |
| 77 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 78 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 79 | * easier to construct Notifications.</p> |
| 80 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 81 | * <div class="special reference"> |
| 82 | * <h3>Developer Guides</h3> |
| 83 | * <p>For a guide to creating notifications, read the |
| 84 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 85 | * developer guide.</p> |
| 86 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | */ |
| 88 | public class Notification implements Parcelable |
| 89 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 90 | private static final String TAG = "Notification"; |
| 91 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 93 | * An activity that provides a user interface for adjusting notification preferences for its |
| 94 | * containing application. Optional but recommended for apps that post |
| 95 | * {@link android.app.Notification Notifications}. |
| 96 | */ |
| 97 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 98 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 99 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 100 | |
| 101 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | * Use all default values (where applicable). |
| 103 | */ |
| 104 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | /** |
| 107 | * Use the default notification sound. This will ignore any given |
| 108 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 109 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 110 | * <p> |
| 111 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 112 | * </p> |
| 113 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 115 | */ |
| 116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | public static final int DEFAULT_SOUND = 1; |
| 118 | |
| 119 | /** |
| 120 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 121 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 122 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 123 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 124 | * <p> |
| 125 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 126 | * </p> |
| 127 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 129 | */ |
| 130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | /** |
| 134 | * Use the default notification lights. This will ignore the |
| 135 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 136 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 137 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 139 | */ |
| 140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 144 | * Maximum length of CharSequences accepted by Builder and friends. |
| 145 | * |
| 146 | * <p> |
| 147 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 148 | */ |
| 149 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 150 | |
| 151 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 152 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 153 | */ |
| 154 | private static final int MAX_REPLY_HISTORY = 5; |
| 155 | |
| 156 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 157 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 158 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 159 | * Default value: {@link System#currentTimeMillis() Now}. |
| 160 | * |
| 161 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 162 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 163 | * yet to occur but about which the user is being informed). Indefinite events should be |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 164 | * timestamped according to when the activity began. |
| 165 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 166 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 167 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 168 | * <ul> |
| 169 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 170 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 171 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 172 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 173 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 174 | * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 175 | * </ul> |
| 176 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame^] | 177 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 178 | * anymore by default and must be opted into by using |
| 179 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | */ |
| 181 | public long when; |
| 182 | |
| 183 | /** |
| 184 | * The resource id of a drawable to use as the icon in the status bar. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 185 | * |
| 186 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 188 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 189 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | public int icon; |
| 191 | |
| 192 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 193 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 194 | * leave it at its default value of 0. |
| 195 | * |
| 196 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 197 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 198 | */ |
| 199 | public int iconLevel; |
| 200 | |
| 201 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 202 | * The number of events that this notification represents. For example, in a new mail |
| 203 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 204 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 205 | * The system may or may not use this field to modify the appearance of the notification. For |
| 206 | * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was |
| 207 | * superimposed over the icon in the status bar. Starting with |
| 208 | * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by |
| 209 | * {@link Notification.Builder} has displayed the number in the expanded notification view. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 210 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 211 | * If the number is 0 or negative, it is never shown. |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 212 | * |
| 213 | * @deprecated this number is not shown anymore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | */ |
| 215 | public int number; |
| 216 | |
| 217 | /** |
| 218 | * The intent to execute when the expanded status entry is clicked. If |
| 219 | * this is an activity, it must include the |
| 220 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 221 | * that you take care of task management as described in the |
| 222 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
Dianne Hackborn | 6ceca58 | 2012-01-10 15:24:26 -0800 | [diff] [blame] | 223 | * Stack</a> document. In particular, make sure to read the notification section |
| 224 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 225 | * Notifications</a> for the correct ways to launch an application from a |
| 226 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | */ |
| 228 | public PendingIntent contentIntent; |
| 229 | |
| 230 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 231 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 232 | * the "Clear All" button or by swiping it away individually. |
| 233 | * |
| 234 | * This probably shouldn't be launching an activity since several of those will be sent |
| 235 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | */ |
| 237 | public PendingIntent deleteIntent; |
| 238 | |
| 239 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 240 | * An intent to launch instead of posting the notification to the status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 241 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 242 | * <p> |
| 243 | * The system UI may choose to display a heads-up notification, instead of |
| 244 | * launching this intent, while the user is using the device. |
| 245 | * </p> |
| 246 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 247 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 248 | */ |
| 249 | public PendingIntent fullScreenIntent; |
| 250 | |
| 251 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 252 | * Text that summarizes this notification for accessibility services. |
| 253 | * |
| 254 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 255 | * accessibility services (where it serves as an audible announcement of the notification's |
| 256 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 257 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 258 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | */ |
| 260 | public CharSequence tickerText; |
| 261 | |
| 262 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 263 | * Formerly, a view showing the {@link #tickerText}. |
| 264 | * |
| 265 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 266 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 267 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 268 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 269 | |
| 270 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 271 | * The view that will represent this notification in the notification list (which is pulled |
| 272 | * down from the status bar). |
| 273 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 274 | * As of N, this field may be null. The notification view is determined by the inputs |
| 275 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 276 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 278 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | public RemoteViews contentView; |
| 280 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 281 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 282 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 283 | * opportunity to show more detail. The system UI may choose to show this |
| 284 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 285 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 286 | * As of N, this field may be null. The expanded notification view is determined by the |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 287 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 288 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 289 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 290 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 291 | public RemoteViews bigContentView; |
| 292 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 293 | |
| 294 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 295 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 296 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 297 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 298 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 299 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 300 | * As of N, this field may be null. The heads-up notification view is determined by the |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 301 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 302 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 303 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 304 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 305 | public RemoteViews headsUpContentView; |
| 306 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 307 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 308 | * A large bitmap to be shown in the notification content area. |
| 309 | * |
| 310 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 312 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 313 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | |
| 315 | /** |
| 316 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 317 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 319 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 320 | * </p> |
| 321 | * |
| 322 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 323 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | * </p> |
| 325 | */ |
| 326 | public Uri sound; |
| 327 | |
| 328 | /** |
| 329 | * Use this constant as the value for audioStreamType to request that |
| 330 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 331 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 332 | * |
| 333 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 335 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | public static final int STREAM_DEFAULT = -1; |
| 337 | |
| 338 | /** |
| 339 | * The audio stream type to use when playing the sound. |
| 340 | * Should be one of the STREAM_ constants from |
| 341 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 342 | * |
| 343 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 345 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | public int audioStreamType = STREAM_DEFAULT; |
| 347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 349 | * The default value of {@link #audioAttributes}. |
| 350 | */ |
| 351 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 352 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 353 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 354 | .build(); |
| 355 | |
| 356 | /** |
| 357 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
| 358 | */ |
| 359 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 360 | |
| 361 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 362 | * The pattern with which to vibrate. |
| 363 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | * <p> |
| 365 | * To vibrate the default pattern, see {@link #defaults}. |
| 366 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 367 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 368 | * <p> |
| 369 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 370 | * </p> |
| 371 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | * @see android.os.Vibrator#vibrate(long[],int) |
| 373 | */ |
| 374 | public long[] vibrate; |
| 375 | |
| 376 | /** |
| 377 | * The color of the led. The hardware will do its best approximation. |
| 378 | * |
| 379 | * @see #FLAG_SHOW_LIGHTS |
| 380 | * @see #flags |
| 381 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 382 | @ColorInt |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | public int ledARGB; |
| 384 | |
| 385 | /** |
| 386 | * The number of milliseconds for the LED to be on while it's flashing. |
| 387 | * The hardware will do its best approximation. |
| 388 | * |
| 389 | * @see #FLAG_SHOW_LIGHTS |
| 390 | * @see #flags |
| 391 | */ |
| 392 | public int ledOnMS; |
| 393 | |
| 394 | /** |
| 395 | * The number of milliseconds for the LED to be off while it's flashing. |
| 396 | * The hardware will do its best approximation. |
| 397 | * |
| 398 | * @see #FLAG_SHOW_LIGHTS |
| 399 | * @see #flags |
| 400 | */ |
| 401 | public int ledOffMS; |
| 402 | |
| 403 | /** |
| 404 | * Specifies which values should be taken from the defaults. |
| 405 | * <p> |
| 406 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 407 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 408 | * values, use {@link #DEFAULT_ALL}. |
| 409 | * </p> |
| 410 | */ |
| 411 | public int defaults; |
| 412 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | /** |
| 414 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 415 | * set if you want the LED on for this notification. |
| 416 | * <ul> |
| 417 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 418 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 419 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 420 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 421 | * be on and off to ledOnMS and ledOffMS.</li> |
| 422 | * </ul> |
| 423 | * <p> |
| 424 | * Since hardware varies, you are not guaranteed that any of the values |
| 425 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 426 | * because they will be set to values that work on any given hardware. |
| 427 | * <p> |
| 428 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 429 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | */ |
| 431 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 432 | |
| 433 | /** |
| 434 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 435 | * set if this notification is in reference to something that is ongoing, |
| 436 | * like a phone call. It should not be set if this notification is in |
| 437 | * reference to something that happened at a particular point in time, |
| 438 | * like a missed phone call. |
| 439 | */ |
| 440 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 441 | |
| 442 | /** |
| 443 | * Bit to be bitwise-ored into the {@link #flags} field that if set, |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 444 | * the audio will be repeated until the notification is |
| 445 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | */ |
| 447 | public static final int FLAG_INSISTENT = 0x00000004; |
| 448 | |
| 449 | /** |
| 450 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
Griff Hazen | 293977b | 2014-04-28 08:37:20 -0700 | [diff] [blame] | 451 | * set if you would only like the sound, vibrate and ticker to be played |
| 452 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | */ |
| 454 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 455 | |
| 456 | /** |
| 457 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 458 | * set if the notification should be canceled when it is clicked by the |
Daniel Sandler | 8aa9ae6 | 2012-12-04 23:31:47 -0500 | [diff] [blame] | 459 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | */ |
| 461 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 462 | |
| 463 | /** |
| 464 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 465 | * set if the notification should not be canceled when the user clicks |
| 466 | * the Clear all button. |
| 467 | */ |
| 468 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 469 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 470 | /** |
| 471 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 472 | * set if this notification represents a currently running service. This |
| 473 | * will normally be set for you by {@link Service#startForeground}. |
| 474 | */ |
| 475 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 476 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 477 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 478 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 479 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 480 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 481 | */ |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 482 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 483 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 484 | /** |
| 485 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 486 | * set if this notification is relevant to the current device only |
| 487 | * and it is not recommended that it bridge to other devices. |
| 488 | */ |
| 489 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 490 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 491 | /** |
| 492 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 493 | * set if this notification is the group summary for a group of notifications. |
| 494 | * Grouped notifications may display in a cluster or stack on devices which |
| 495 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 496 | */ |
| 497 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | public int flags; |
| 500 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 501 | /** @hide */ |
| 502 | @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX}) |
| 503 | @Retention(RetentionPolicy.SOURCE) |
| 504 | public @interface Priority {} |
| 505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 507 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 508 | * notifications, use this value for all notifications. |
| 509 | */ |
| 510 | public static final int PRIORITY_DEFAULT = 0; |
| 511 | |
| 512 | /** |
| 513 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 514 | * items smaller, or at a different position in the list, compared with your app's |
| 515 | * {@link #PRIORITY_DEFAULT} items. |
| 516 | */ |
| 517 | public static final int PRIORITY_LOW = -1; |
| 518 | |
| 519 | /** |
| 520 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 521 | * circumstances, such as detailed notification logs. |
| 522 | */ |
| 523 | public static final int PRIORITY_MIN = -2; |
| 524 | |
| 525 | /** |
| 526 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 527 | * show these items larger, or at a different position in notification lists, compared with |
| 528 | * your app's {@link #PRIORITY_DEFAULT} items. |
| 529 | */ |
| 530 | public static final int PRIORITY_HIGH = 1; |
| 531 | |
| 532 | /** |
| 533 | * Highest {@link #priority}, for your application's most important items that require the |
| 534 | * user's prompt attention or input. |
| 535 | */ |
| 536 | public static final int PRIORITY_MAX = 2; |
| 537 | |
| 538 | /** |
| 539 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 540 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 541 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 542 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 543 | * situations, while the user might be interrupted for a higher-priority notification. The |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 544 | * system will make a determination about how to interpret this priority when presenting |
| 545 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 546 | * |
| 547 | * <p> |
| 548 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 549 | * as a heads-up notification. |
| 550 | * </p> |
| 551 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 552 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 553 | @Priority |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 554 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 555 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 556 | /** |
| 557 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 558 | * to be applied by the standard Style templates when presenting this notification. |
| 559 | * |
| 560 | * The current template design constructs a colorful header image by overlaying the |
| 561 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 562 | * ignored. |
| 563 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 564 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 565 | public int color = COLOR_DEFAULT; |
| 566 | |
| 567 | /** |
| 568 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 569 | * any special color but instead use default colors when presenting this notification. |
| 570 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 571 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 572 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 573 | |
| 574 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 575 | * Special value of {@link #color} used as a place holder for an invalid color. |
| 576 | */ |
| 577 | @ColorInt |
| 578 | private static final int COLOR_INVALID = 1; |
| 579 | |
| 580 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 581 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 582 | * the notification's presence and contents in untrusted situations (namely, on the secure |
| 583 | * lockscreen). |
| 584 | * |
| 585 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 586 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 587 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 588 | * the appropriate user. |
| 589 | * |
| 590 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 591 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 592 | * To modify the public version of this notification—for example, to redact some portions—see |
| 593 | * {@link Builder#setPublicVersion(Notification)}. |
| 594 | * |
| 595 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 596 | * and ticker until the user has bypassed the lockscreen. |
| 597 | */ |
| 598 | public int visibility; |
| 599 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 600 | /** |
| 601 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 602 | * |
| 603 | * {@see #visibility} |
| 604 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 605 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 606 | |
| 607 | /** |
| 608 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 609 | * private information on secure lockscreens. |
| 610 | * |
| 611 | * {@see #visibility} |
| 612 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 613 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 614 | |
| 615 | /** |
| 616 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 617 | * |
| 618 | * {@see #visibility} |
| 619 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 620 | public static final int VISIBILITY_SECRET = -1; |
| 621 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 622 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 623 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 624 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 625 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 626 | |
| 627 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 628 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 629 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 630 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 631 | |
| 632 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 633 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 634 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 635 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 636 | |
| 637 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 638 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 639 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 640 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 641 | |
| 642 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 643 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 644 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 645 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 646 | |
| 647 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 648 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 649 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 650 | public static final String CATEGORY_ALARM = "alarm"; |
| 651 | |
| 652 | /** |
| 653 | * Notification category: progress of a long-running background operation. |
| 654 | */ |
| 655 | public static final String CATEGORY_PROGRESS = "progress"; |
| 656 | |
| 657 | /** |
| 658 | * Notification category: social network or sharing update. |
| 659 | */ |
| 660 | public static final String CATEGORY_SOCIAL = "social"; |
| 661 | |
| 662 | /** |
| 663 | * Notification category: error in background operation or authentication status. |
| 664 | */ |
| 665 | public static final String CATEGORY_ERROR = "err"; |
| 666 | |
| 667 | /** |
| 668 | * Notification category: media transport control for playback. |
| 669 | */ |
| 670 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 671 | |
| 672 | /** |
| 673 | * Notification category: system or device status update. Reserved for system use. |
| 674 | */ |
| 675 | public static final String CATEGORY_SYSTEM = "sys"; |
| 676 | |
| 677 | /** |
| 678 | * Notification category: indication of running background service. |
| 679 | */ |
| 680 | public static final String CATEGORY_SERVICE = "service"; |
| 681 | |
| 682 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 683 | * Notification category: a specific, timely recommendation for a single thing. |
| 684 | * For example, a news app might want to recommend a news story it believes the user will |
| 685 | * want to read next. |
| 686 | */ |
| 687 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 688 | |
| 689 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 690 | * Notification category: ongoing information about device or contextual status. |
| 691 | */ |
| 692 | public static final String CATEGORY_STATUS = "status"; |
| 693 | |
| 694 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 695 | * Notification category: user-scheduled reminder. |
| 696 | */ |
| 697 | public static final String CATEGORY_REMINDER = "reminder"; |
| 698 | |
| 699 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 700 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 701 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 702 | */ |
| 703 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 704 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 705 | private String mGroupKey; |
| 706 | |
| 707 | /** |
| 708 | * Get the key used to group this notification into a cluster or stack |
| 709 | * with other notifications on devices which support such rendering. |
| 710 | */ |
| 711 | public String getGroup() { |
| 712 | return mGroupKey; |
| 713 | } |
| 714 | |
| 715 | private String mSortKey; |
| 716 | |
| 717 | /** |
| 718 | * Get a sort key that orders this notification among other notifications from the |
| 719 | * same package. This can be useful if an external sort was already applied and an app |
| 720 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 721 | * value, although providing different priorities in addition to providing sort key may |
| 722 | * cause this value to be ignored. |
| 723 | * |
| 724 | * <p>This sort key can also be used to order members of a notification group. See |
| 725 | * {@link Builder#setGroup}. |
| 726 | * |
| 727 | * @see String#compareTo(String) |
| 728 | */ |
| 729 | public String getSortKey() { |
| 730 | return mSortKey; |
| 731 | } |
| 732 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 733 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 734 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 735 | * <p> |
| 736 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 737 | * APIs, and are intended to be used by |
| 738 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 739 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 740 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 741 | public Bundle extras = new Bundle(); |
| 742 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 743 | /** |
| 744 | * {@link #extras} key: this is the title of the notification, |
| 745 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 746 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 747 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 748 | |
| 749 | /** |
| 750 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 751 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 752 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 753 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 754 | |
| 755 | /** |
| 756 | * {@link #extras} key: this is the main text payload, as supplied to |
| 757 | * {@link Builder#setContentText(CharSequence)}. |
| 758 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 759 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 760 | |
| 761 | /** |
| 762 | * {@link #extras} key: this is a third line of text, as supplied to |
| 763 | * {@link Builder#setSubText(CharSequence)}. |
| 764 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 765 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 766 | |
| 767 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 768 | * {@link #extras} key: this is the remote input history, as supplied to |
| 769 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
| 770 | */ |
| 771 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 772 | |
| 773 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 774 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 775 | * {@link Builder#setContentInfo(CharSequence)}. |
| 776 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 777 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 778 | |
| 779 | /** |
| 780 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 781 | * alongside expanded notifications, as supplied to (e.g.) |
| 782 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 783 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 784 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 785 | |
| 786 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 787 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 788 | * {@link BigTextStyle} notification, as supplied to |
| 789 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 790 | */ |
| 791 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 792 | |
| 793 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 794 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 795 | * supplied to {@link Builder#setSmallIcon(int)}. |
| 796 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 797 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 798 | |
| 799 | /** |
| 800 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 801 | * notification payload, as |
| 802 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
| 803 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 804 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 805 | |
| 806 | /** |
| 807 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 808 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 809 | * shown in its expanded form, as supplied to |
| 810 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 811 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 812 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 813 | |
| 814 | /** |
| 815 | * {@link #extras} key: this is the progress value supplied to |
| 816 | * {@link Builder#setProgress(int, int, boolean)}. |
| 817 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 818 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 819 | |
| 820 | /** |
| 821 | * {@link #extras} key: this is the maximum value supplied to |
| 822 | * {@link Builder#setProgress(int, int, boolean)}. |
| 823 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 824 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 825 | |
| 826 | /** |
| 827 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 828 | * {@link Builder#setProgress(int, int, boolean)}. |
| 829 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 830 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 831 | |
| 832 | /** |
| 833 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 834 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 835 | * {@link Builder#setUsesChronometer(boolean)}. |
| 836 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 837 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 838 | |
| 839 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 840 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 841 | * instead of counting up. Is only relevant if key {@link #EXTRA_SHOW_CHRONOMETER} is present. |
| 842 | */ |
| 843 | public static final String EXTRA_CHRONOMETER_COUNTS_DOWN = "android.chronometerCountsDown"; |
| 844 | |
| 845 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 846 | * {@link #extras} key: whether {@link #when} should be shown, |
| 847 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 848 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 849 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 850 | |
| 851 | /** |
| 852 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 853 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 854 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 855 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 856 | |
| 857 | /** |
| 858 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 859 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 860 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 861 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 862 | |
| 863 | /** |
| 864 | * {@link #extras} key: A string representing the name of the specific |
| 865 | * {@link android.app.Notification.Style} used to create this notification. |
| 866 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 867 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 868 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 869 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 870 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 871 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 872 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 873 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 874 | |
| 875 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 876 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 877 | * Only available to notifications coming from the android package. |
| 878 | * @hide |
| 879 | */ |
| 880 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 881 | |
| 882 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 883 | * {@link #extras} key: A |
| 884 | * {@link android.content.ContentUris content URI} pointing to an image that can be displayed |
| 885 | * in the background when the notification is selected. The URI must point to an image stream |
| 886 | * suitable for passing into |
| 887 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
| 888 | * BitmapFactory.decodeStream}; all other content types will be ignored. The content provider |
| 889 | * URI used for this purpose must require no permissions to read the image data. |
| 890 | */ |
| 891 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 892 | |
| 893 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 894 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 895 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 896 | * {@link android.app.Notification.MediaStyle} notification. |
| 897 | */ |
| 898 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 899 | |
| 900 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 901 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 902 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 903 | */ |
| 904 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 905 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 906 | /** |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 907 | * {@link #extras} key: the user that built the notification. |
| 908 | * |
| 909 | * @hide |
| 910 | */ |
| 911 | public static final String EXTRA_ORIGINATING_USERID = "android.originatingUserId"; |
| 912 | |
| 913 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 914 | * @hide |
| 915 | */ |
| 916 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 917 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 918 | /** |
| 919 | * @hide |
| 920 | */ |
| 921 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 922 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 923 | private Icon mSmallIcon; |
| 924 | private Icon mLargeIcon; |
| 925 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 926 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 927 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 928 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 929 | * selected by the user. |
| 930 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 931 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 932 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 933 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 934 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 935 | public static class Action implements Parcelable { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 936 | private final Bundle mExtras; |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 937 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 938 | private final RemoteInput[] mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 939 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 940 | /** |
| 941 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 942 | * |
| 943 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 944 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 945 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 946 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 947 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 948 | /** |
| 949 | * Title of the action. |
| 950 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 951 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 952 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 953 | /** |
| 954 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 955 | * may be rendered in a disabled presentation by the system UI. |
| 956 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 957 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 958 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 959 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 960 | if (in.readInt() != 0) { |
| 961 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 962 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 963 | icon = mIcon.getResId(); |
| 964 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 965 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 966 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 967 | if (in.readInt() == 1) { |
| 968 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 969 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 970 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 971 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 972 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 973 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 974 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 975 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 976 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 977 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 978 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 979 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 980 | } |
| 981 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 982 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 983 | RemoteInput[] remoteInputs) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 984 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 985 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 986 | this.icon = icon.getResId(); |
| 987 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 988 | this.title = title; |
| 989 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 990 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 991 | this.mRemoteInputs = remoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 995 | * Return an icon representing the action. |
| 996 | */ |
| 997 | public Icon getIcon() { |
| 998 | if (mIcon == null && icon != 0) { |
| 999 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1000 | mIcon = Icon.createWithResource("", icon); |
| 1001 | } |
| 1002 | return mIcon; |
| 1003 | } |
| 1004 | |
| 1005 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1006 | * Get additional metadata carried around with this Action. |
| 1007 | */ |
| 1008 | public Bundle getExtras() { |
| 1009 | return mExtras; |
| 1010 | } |
| 1011 | |
| 1012 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1013 | * Get the list of inputs to be collected from the user when this action is sent. |
| 1014 | * May return null if no remote inputs were added. |
| 1015 | */ |
| 1016 | public RemoteInput[] getRemoteInputs() { |
| 1017 | return mRemoteInputs; |
| 1018 | } |
| 1019 | |
| 1020 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1021 | * Builder class for {@link Action} objects. |
| 1022 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1023 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1024 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1025 | private final CharSequence mTitle; |
| 1026 | private final PendingIntent mIntent; |
| 1027 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1028 | private ArrayList<RemoteInput> mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1029 | |
| 1030 | /** |
| 1031 | * Construct a new builder for {@link Action} object. |
| 1032 | * @param icon icon to show for this action |
| 1033 | * @param title the title of the action |
| 1034 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1035 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1036 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1037 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1038 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null); |
| 1039 | } |
| 1040 | |
| 1041 | /** |
| 1042 | * Construct a new builder for {@link Action} object. |
| 1043 | * @param icon icon to show for this action |
| 1044 | * @param title the title of the action |
| 1045 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1046 | */ |
| 1047 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1048 | this(icon, title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * Construct a new builder for {@link Action} object using the fields from an |
| 1053 | * {@link Action}. |
| 1054 | * @param action the action to read fields from. |
| 1055 | */ |
| 1056 | public Builder(Action action) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1057 | this(action.getIcon(), action.title, action.actionIntent, new Bundle(action.mExtras), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1058 | action.getRemoteInputs()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1061 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1062 | RemoteInput[] remoteInputs) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1063 | mIcon = icon; |
| 1064 | mTitle = title; |
| 1065 | mIntent = intent; |
| 1066 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1067 | if (remoteInputs != null) { |
| 1068 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1069 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1070 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | /** |
| 1074 | * Merge additional metadata into this builder. |
| 1075 | * |
| 1076 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1077 | * |
| 1078 | * @see Notification.Action#extras |
| 1079 | */ |
| 1080 | public Builder addExtras(Bundle extras) { |
| 1081 | if (extras != null) { |
| 1082 | mExtras.putAll(extras); |
| 1083 | } |
| 1084 | return this; |
| 1085 | } |
| 1086 | |
| 1087 | /** |
| 1088 | * Get the metadata Bundle used by this Builder. |
| 1089 | * |
| 1090 | * <p>The returned Bundle is shared with this Builder. |
| 1091 | */ |
| 1092 | public Bundle getExtras() { |
| 1093 | return mExtras; |
| 1094 | } |
| 1095 | |
| 1096 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1097 | * Add an input to be collected from the user when this action is sent. |
| 1098 | * Response values can be retrieved from the fired intent by using the |
| 1099 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1100 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1101 | * @return this object for method chaining |
| 1102 | */ |
| 1103 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1104 | if (mRemoteInputs == null) { |
| 1105 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1106 | } |
| 1107 | mRemoteInputs.add(remoteInput); |
| 1108 | return this; |
| 1109 | } |
| 1110 | |
| 1111 | /** |
| 1112 | * Apply an extender to this action builder. Extenders may be used to add |
| 1113 | * metadata or change options on this builder. |
| 1114 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1115 | public Builder extend(Extender extender) { |
| 1116 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1117 | return this; |
| 1118 | } |
| 1119 | |
| 1120 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1121 | * Combine all of the options that have been set and return a new {@link Action} |
| 1122 | * object. |
| 1123 | * @return the built action |
| 1124 | */ |
| 1125 | public Action build() { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1126 | RemoteInput[] remoteInputs = mRemoteInputs != null |
| 1127 | ? mRemoteInputs.toArray(new RemoteInput[mRemoteInputs.size()]) : null; |
| 1128 | return new Action(mIcon, mTitle, mIntent, mExtras, remoteInputs); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1129 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1130 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1131 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1132 | @Override |
| 1133 | public Action clone() { |
| 1134 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1135 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1136 | title, |
| 1137 | actionIntent, // safe to alias |
| 1138 | new Bundle(mExtras), |
| 1139 | getRemoteInputs()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1140 | } |
| 1141 | @Override |
| 1142 | public int describeContents() { |
| 1143 | return 0; |
| 1144 | } |
| 1145 | @Override |
| 1146 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1147 | final Icon ic = getIcon(); |
| 1148 | if (ic != null) { |
| 1149 | out.writeInt(1); |
| 1150 | ic.writeToParcel(out, 0); |
| 1151 | } else { |
| 1152 | out.writeInt(0); |
| 1153 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1154 | TextUtils.writeToParcel(title, out, flags); |
| 1155 | if (actionIntent != null) { |
| 1156 | out.writeInt(1); |
| 1157 | actionIntent.writeToParcel(out, flags); |
| 1158 | } else { |
| 1159 | out.writeInt(0); |
| 1160 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1161 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1162 | out.writeTypedArray(mRemoteInputs, flags); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1163 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1164 | public static final Parcelable.Creator<Action> CREATOR = |
| 1165 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1166 | public Action createFromParcel(Parcel in) { |
| 1167 | return new Action(in); |
| 1168 | } |
| 1169 | public Action[] newArray(int size) { |
| 1170 | return new Action[size]; |
| 1171 | } |
| 1172 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1173 | |
| 1174 | /** |
| 1175 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1176 | * metadata or change options on an action builder. |
| 1177 | */ |
| 1178 | public interface Extender { |
| 1179 | /** |
| 1180 | * Apply this extender to a notification action builder. |
| 1181 | * @param builder the builder to be modified. |
| 1182 | * @return the build object for chaining. |
| 1183 | */ |
| 1184 | public Builder extend(Builder builder); |
| 1185 | } |
| 1186 | |
| 1187 | /** |
| 1188 | * Wearable extender for notification actions. To add extensions to an action, |
| 1189 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1190 | * the {@code WearableExtender()} constructor and apply it to a |
| 1191 | * {@link android.app.Notification.Action.Builder} using |
| 1192 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1193 | * |
| 1194 | * <pre class="prettyprint"> |
| 1195 | * Notification.Action action = new Notification.Action.Builder( |
| 1196 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1197 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1198 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1199 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1200 | */ |
| 1201 | public static final class WearableExtender implements Extender { |
| 1202 | /** Notification action extra which contains wearable extensions */ |
| 1203 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1204 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1205 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1206 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1207 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1208 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1209 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1210 | |
| 1211 | // Flags bitwise-ored to mFlags |
| 1212 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
| 1213 | |
| 1214 | // Default value for flags integer |
| 1215 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1216 | |
| 1217 | private int mFlags = DEFAULT_FLAGS; |
| 1218 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1219 | private CharSequence mInProgressLabel; |
| 1220 | private CharSequence mConfirmLabel; |
| 1221 | private CharSequence mCancelLabel; |
| 1222 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1223 | /** |
| 1224 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1225 | * options. |
| 1226 | */ |
| 1227 | public WearableExtender() { |
| 1228 | } |
| 1229 | |
| 1230 | /** |
| 1231 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1232 | * wearable options present in an existing notification action. |
| 1233 | * @param action the notification action to inspect. |
| 1234 | */ |
| 1235 | public WearableExtender(Action action) { |
| 1236 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1237 | if (wearableBundle != null) { |
| 1238 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1239 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1240 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1241 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | /** |
| 1246 | * Apply wearable extensions to a notification action that is being built. This is |
| 1247 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1248 | * method of {@link android.app.Notification.Action.Builder}. |
| 1249 | */ |
| 1250 | @Override |
| 1251 | public Action.Builder extend(Action.Builder builder) { |
| 1252 | Bundle wearableBundle = new Bundle(); |
| 1253 | |
| 1254 | if (mFlags != DEFAULT_FLAGS) { |
| 1255 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1256 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1257 | if (mInProgressLabel != null) { |
| 1258 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1259 | } |
| 1260 | if (mConfirmLabel != null) { |
| 1261 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1262 | } |
| 1263 | if (mCancelLabel != null) { |
| 1264 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1265 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1266 | |
| 1267 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1268 | return builder; |
| 1269 | } |
| 1270 | |
| 1271 | @Override |
| 1272 | public WearableExtender clone() { |
| 1273 | WearableExtender that = new WearableExtender(); |
| 1274 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1275 | that.mInProgressLabel = this.mInProgressLabel; |
| 1276 | that.mConfirmLabel = this.mConfirmLabel; |
| 1277 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1278 | return that; |
| 1279 | } |
| 1280 | |
| 1281 | /** |
| 1282 | * Set whether this action is available when the wearable device is not connected to |
| 1283 | * a companion device. The user can still trigger this action when the wearable device is |
| 1284 | * offline, but a visual hint will indicate that the action may not be available. |
| 1285 | * Defaults to true. |
| 1286 | */ |
| 1287 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1288 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1289 | return this; |
| 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * Get whether this action is available when the wearable device is not connected to |
| 1294 | * a companion device. The user can still trigger this action when the wearable device is |
| 1295 | * offline, but a visual hint will indicate that the action may not be available. |
| 1296 | * Defaults to true. |
| 1297 | */ |
| 1298 | public boolean isAvailableOffline() { |
| 1299 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1300 | } |
| 1301 | |
| 1302 | private void setFlag(int mask, boolean value) { |
| 1303 | if (value) { |
| 1304 | mFlags |= mask; |
| 1305 | } else { |
| 1306 | mFlags &= ~mask; |
| 1307 | } |
| 1308 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1309 | |
| 1310 | /** |
| 1311 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1312 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1313 | * |
| 1314 | * @param label the label to display while the action is being prepared to execute |
| 1315 | * @return this object for method chaining |
| 1316 | */ |
| 1317 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1318 | mInProgressLabel = label; |
| 1319 | return this; |
| 1320 | } |
| 1321 | |
| 1322 | /** |
| 1323 | * Get the label to display while the wearable is preparing to automatically execute |
| 1324 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1325 | * |
| 1326 | * @return the label to display while the action is being prepared to execute |
| 1327 | */ |
| 1328 | public CharSequence getInProgressLabel() { |
| 1329 | return mInProgressLabel; |
| 1330 | } |
| 1331 | |
| 1332 | /** |
| 1333 | * Set a label to display to confirm that the action should be executed. |
| 1334 | * This is usually an imperative verb like "Send". |
| 1335 | * |
| 1336 | * @param label the label to confirm the action should be executed |
| 1337 | * @return this object for method chaining |
| 1338 | */ |
| 1339 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1340 | mConfirmLabel = label; |
| 1341 | return this; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * Get the label to display to confirm that the action should be executed. |
| 1346 | * This is usually an imperative verb like "Send". |
| 1347 | * |
| 1348 | * @return the label to confirm the action should be executed |
| 1349 | */ |
| 1350 | public CharSequence getConfirmLabel() { |
| 1351 | return mConfirmLabel; |
| 1352 | } |
| 1353 | |
| 1354 | /** |
| 1355 | * Set a label to display to cancel the action. |
| 1356 | * This is usually an imperative verb, like "Cancel". |
| 1357 | * |
| 1358 | * @param label the label to display to cancel the action |
| 1359 | * @return this object for method chaining |
| 1360 | */ |
| 1361 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1362 | mCancelLabel = label; |
| 1363 | return this; |
| 1364 | } |
| 1365 | |
| 1366 | /** |
| 1367 | * Get the label to display to cancel the action. |
| 1368 | * This is usually an imperative verb like "Cancel". |
| 1369 | * |
| 1370 | * @return the label to display to cancel the action |
| 1371 | */ |
| 1372 | public CharSequence getCancelLabel() { |
| 1373 | return mCancelLabel; |
| 1374 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1375 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1376 | } |
| 1377 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1378 | /** |
| 1379 | * Array of all {@link Action} structures attached to this notification by |
| 1380 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 1381 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 1382 | * interface for invoking actions. |
| 1383 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1384 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1385 | |
| 1386 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1387 | * Replacement version of this notification whose content will be shown |
| 1388 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 1389 | * and {@link #VISIBILITY_PUBLIC}. |
| 1390 | */ |
| 1391 | public Notification publicVersion; |
| 1392 | |
| 1393 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1394 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1395 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1396 | */ |
| 1397 | public Notification() |
| 1398 | { |
| 1399 | this.when = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1400 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | * @hide |
| 1405 | */ |
| 1406 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 1407 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 1408 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1409 | new Builder(context) |
| 1410 | .setWhen(when) |
| 1411 | .setSmallIcon(icon) |
| 1412 | .setTicker(tickerText) |
| 1413 | .setContentTitle(contentTitle) |
| 1414 | .setContentText(contentText) |
| 1415 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 1416 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | /** |
| 1420 | * Constructs a Notification object with the information needed to |
| 1421 | * have a status bar icon without the standard expanded view. |
| 1422 | * |
| 1423 | * @param icon The resource id of the icon to put in the status bar. |
| 1424 | * @param tickerText The text that flows by in the status bar when the notification first |
| 1425 | * activates. |
| 1426 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 1427 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1428 | * |
| 1429 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1430 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1431 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | public Notification(int icon, CharSequence tickerText, long when) |
| 1433 | { |
| 1434 | this.icon = icon; |
| 1435 | this.tickerText = tickerText; |
| 1436 | this.when = when; |
| 1437 | } |
| 1438 | |
| 1439 | /** |
| 1440 | * Unflatten the notification from a parcel. |
| 1441 | */ |
| 1442 | public Notification(Parcel parcel) |
| 1443 | { |
| 1444 | int version = parcel.readInt(); |
| 1445 | |
| 1446 | when = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1447 | if (parcel.readInt() != 0) { |
| 1448 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1449 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1450 | icon = mSmallIcon.getResId(); |
| 1451 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1452 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | number = parcel.readInt(); |
| 1454 | if (parcel.readInt() != 0) { |
| 1455 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1456 | } |
| 1457 | if (parcel.readInt() != 0) { |
| 1458 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1459 | } |
| 1460 | if (parcel.readInt() != 0) { |
| 1461 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1462 | } |
| 1463 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1464 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1465 | } |
| 1466 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1468 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1469 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1470 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1471 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | defaults = parcel.readInt(); |
| 1473 | flags = parcel.readInt(); |
| 1474 | if (parcel.readInt() != 0) { |
| 1475 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 1476 | } |
| 1477 | |
| 1478 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1479 | if (parcel.readInt() != 0) { |
| 1480 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 1481 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | vibrate = parcel.createLongArray(); |
| 1483 | ledARGB = parcel.readInt(); |
| 1484 | ledOnMS = parcel.readInt(); |
| 1485 | ledOffMS = parcel.readInt(); |
| 1486 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1487 | |
| 1488 | if (parcel.readInt() != 0) { |
| 1489 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1490 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1491 | |
| 1492 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1493 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1494 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1495 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1496 | mGroupKey = parcel.readString(); |
| 1497 | |
| 1498 | mSortKey = parcel.readString(); |
| 1499 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1500 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1501 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1502 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 1503 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1504 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1505 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1506 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1507 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1508 | if (parcel.readInt() != 0) { |
| 1509 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1510 | } |
| 1511 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1512 | visibility = parcel.readInt(); |
| 1513 | |
| 1514 | if (parcel.readInt() != 0) { |
| 1515 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 1516 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1517 | |
| 1518 | color = parcel.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1521 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1522 | public Notification clone() { |
| 1523 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1524 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1525 | return that; |
| 1526 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1527 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1528 | /** |
| 1529 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 1530 | * of this into that. |
| 1531 | * @hide |
| 1532 | */ |
| 1533 | public void cloneInto(Notification that, boolean heavy) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1534 | that.when = this.when; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1535 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1536 | that.number = this.number; |
| 1537 | |
| 1538 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 1539 | that.contentIntent = this.contentIntent; |
| 1540 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1541 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1542 | |
| 1543 | if (this.tickerText != null) { |
| 1544 | that.tickerText = this.tickerText.toString(); |
| 1545 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1546 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1547 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1548 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1549 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1550 | that.contentView = this.contentView.clone(); |
| 1551 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1552 | if (heavy && this.mLargeIcon != null) { |
| 1553 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1554 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 1555 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1556 | that.sound = this.sound; // android.net.Uri is immutable |
| 1557 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1558 | if (this.audioAttributes != null) { |
| 1559 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 1560 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1561 | |
| 1562 | final long[] vibrate = this.vibrate; |
| 1563 | if (vibrate != null) { |
| 1564 | final int N = vibrate.length; |
| 1565 | final long[] vib = that.vibrate = new long[N]; |
| 1566 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 1567 | } |
| 1568 | |
| 1569 | that.ledARGB = this.ledARGB; |
| 1570 | that.ledOnMS = this.ledOnMS; |
| 1571 | that.ledOffMS = this.ledOffMS; |
| 1572 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1573 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1574 | that.flags = this.flags; |
| 1575 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1576 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1577 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1578 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1579 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1580 | that.mGroupKey = this.mGroupKey; |
| 1581 | |
| 1582 | that.mSortKey = this.mSortKey; |
| 1583 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1584 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1585 | try { |
| 1586 | that.extras = new Bundle(this.extras); |
| 1587 | // will unparcel |
| 1588 | that.extras.size(); |
| 1589 | } catch (BadParcelableException e) { |
| 1590 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 1591 | that.extras = null; |
| 1592 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1593 | } |
| 1594 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1595 | if (this.actions != null) { |
| 1596 | that.actions = new Action[this.actions.length]; |
| 1597 | for(int i=0; i<this.actions.length; i++) { |
| 1598 | that.actions[i] = this.actions[i].clone(); |
| 1599 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1600 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1601 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1602 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1603 | that.bigContentView = this.bigContentView.clone(); |
| 1604 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1605 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1606 | if (heavy && this.headsUpContentView != null) { |
| 1607 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 1608 | } |
| 1609 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1610 | that.visibility = this.visibility; |
| 1611 | |
| 1612 | if (this.publicVersion != null) { |
| 1613 | that.publicVersion = new Notification(); |
| 1614 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 1615 | } |
| 1616 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1617 | that.color = this.color; |
| 1618 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1619 | if (!heavy) { |
| 1620 | that.lightenPayload(); // will clean out extras |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | /** |
| 1625 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 1626 | * listeners when the full contents are not necessary. |
| 1627 | * @hide |
| 1628 | */ |
| 1629 | public final void lightenPayload() { |
| 1630 | tickerView = null; |
| 1631 | contentView = null; |
| 1632 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1633 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1634 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 1635 | if (extras != null && !extras.isEmpty()) { |
| 1636 | final Set<String> keyset = extras.keySet(); |
| 1637 | final int N = keyset.size(); |
| 1638 | final String[] keys = keyset.toArray(new String[N]); |
| 1639 | for (int i=0; i<N; i++) { |
| 1640 | final String key = keys[i]; |
| 1641 | final Object obj = extras.get(key); |
| 1642 | if (obj != null && |
| 1643 | ( obj instanceof Parcelable |
| 1644 | || obj instanceof Parcelable[] |
| 1645 | || obj instanceof SparseArray |
| 1646 | || obj instanceof ArrayList)) { |
| 1647 | extras.remove(key); |
| 1648 | } |
| 1649 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1650 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1653 | /** |
| 1654 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 1655 | * means it had better not be some custom Parcelable implementation. |
| 1656 | * @hide |
| 1657 | */ |
| 1658 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 1659 | if (cs == null) return cs; |
| 1660 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 1661 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 1662 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1663 | if (cs instanceof Parcelable) { |
| 1664 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 1665 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 1666 | return cs.toString(); |
| 1667 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1668 | return removeTextSizeSpans(cs); |
| 1669 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1670 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1671 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 1672 | if (charSequence instanceof Spanned) { |
| 1673 | Spanned ss = (Spanned) charSequence; |
| 1674 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 1675 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 1676 | for (Object span : spans) { |
| 1677 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 1678 | if (resultSpan instanceof CharacterStyle) { |
| 1679 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 1680 | } |
| 1681 | if (resultSpan instanceof TextAppearanceSpan) { |
| 1682 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1683 | resultSpan = new TextAppearanceSpan( |
| 1684 | originalSpan.getFamily(), |
| 1685 | originalSpan.getTextStyle(), |
| 1686 | -1, |
| 1687 | originalSpan.getTextColor(), |
| 1688 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 1689 | } else if (resultSpan instanceof RelativeSizeSpan |
| 1690 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1691 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 1692 | } else { |
| 1693 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1694 | } |
| 1695 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 1696 | ss.getSpanFlags(span)); |
| 1697 | } |
| 1698 | return builder; |
| 1699 | } |
| 1700 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1701 | } |
| 1702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1703 | public int describeContents() { |
| 1704 | return 0; |
| 1705 | } |
| 1706 | |
| 1707 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1708 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | */ |
| 1710 | public void writeToParcel(Parcel parcel, int flags) |
| 1711 | { |
| 1712 | parcel.writeInt(1); |
| 1713 | |
| 1714 | parcel.writeLong(when); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1715 | if (mSmallIcon == null && icon != 0) { |
| 1716 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1717 | mSmallIcon = Icon.createWithResource("", icon); |
| 1718 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1719 | if (mSmallIcon != null) { |
| 1720 | parcel.writeInt(1); |
| 1721 | mSmallIcon.writeToParcel(parcel, 0); |
| 1722 | } else { |
| 1723 | parcel.writeInt(0); |
| 1724 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1725 | parcel.writeInt(number); |
| 1726 | if (contentIntent != null) { |
| 1727 | parcel.writeInt(1); |
| 1728 | contentIntent.writeToParcel(parcel, 0); |
| 1729 | } else { |
| 1730 | parcel.writeInt(0); |
| 1731 | } |
| 1732 | if (deleteIntent != null) { |
| 1733 | parcel.writeInt(1); |
| 1734 | deleteIntent.writeToParcel(parcel, 0); |
| 1735 | } else { |
| 1736 | parcel.writeInt(0); |
| 1737 | } |
| 1738 | if (tickerText != null) { |
| 1739 | parcel.writeInt(1); |
| 1740 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 1741 | } else { |
| 1742 | parcel.writeInt(0); |
| 1743 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1744 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1745 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1746 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1747 | } else { |
| 1748 | parcel.writeInt(0); |
| 1749 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1750 | if (contentView != null) { |
| 1751 | parcel.writeInt(1); |
| 1752 | contentView.writeToParcel(parcel, 0); |
| 1753 | } else { |
| 1754 | parcel.writeInt(0); |
| 1755 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1756 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1757 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1758 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1759 | } else { |
| 1760 | parcel.writeInt(0); |
| 1761 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1762 | |
| 1763 | parcel.writeInt(defaults); |
| 1764 | parcel.writeInt(this.flags); |
| 1765 | |
| 1766 | if (sound != null) { |
| 1767 | parcel.writeInt(1); |
| 1768 | sound.writeToParcel(parcel, 0); |
| 1769 | } else { |
| 1770 | parcel.writeInt(0); |
| 1771 | } |
| 1772 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1773 | |
| 1774 | if (audioAttributes != null) { |
| 1775 | parcel.writeInt(1); |
| 1776 | audioAttributes.writeToParcel(parcel, 0); |
| 1777 | } else { |
| 1778 | parcel.writeInt(0); |
| 1779 | } |
| 1780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1781 | parcel.writeLongArray(vibrate); |
| 1782 | parcel.writeInt(ledARGB); |
| 1783 | parcel.writeInt(ledOnMS); |
| 1784 | parcel.writeInt(ledOffMS); |
| 1785 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1786 | |
| 1787 | if (fullScreenIntent != null) { |
| 1788 | parcel.writeInt(1); |
| 1789 | fullScreenIntent.writeToParcel(parcel, 0); |
| 1790 | } else { |
| 1791 | parcel.writeInt(0); |
| 1792 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1793 | |
| 1794 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1795 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1796 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1797 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1798 | parcel.writeString(mGroupKey); |
| 1799 | |
| 1800 | parcel.writeString(mSortKey); |
| 1801 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1802 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1803 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1804 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1805 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1806 | if (bigContentView != null) { |
| 1807 | parcel.writeInt(1); |
| 1808 | bigContentView.writeToParcel(parcel, 0); |
| 1809 | } else { |
| 1810 | parcel.writeInt(0); |
| 1811 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1812 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1813 | if (headsUpContentView != null) { |
| 1814 | parcel.writeInt(1); |
| 1815 | headsUpContentView.writeToParcel(parcel, 0); |
| 1816 | } else { |
| 1817 | parcel.writeInt(0); |
| 1818 | } |
| 1819 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1820 | parcel.writeInt(visibility); |
| 1821 | |
| 1822 | if (publicVersion != null) { |
| 1823 | parcel.writeInt(1); |
| 1824 | publicVersion.writeToParcel(parcel, 0); |
| 1825 | } else { |
| 1826 | parcel.writeInt(0); |
| 1827 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1828 | |
| 1829 | parcel.writeInt(color); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | /** |
| 1833 | * Parcelable.Creator that instantiates Notification objects |
| 1834 | */ |
| 1835 | public static final Parcelable.Creator<Notification> CREATOR |
| 1836 | = new Parcelable.Creator<Notification>() |
| 1837 | { |
| 1838 | public Notification createFromParcel(Parcel parcel) |
| 1839 | { |
| 1840 | return new Notification(parcel); |
| 1841 | } |
| 1842 | |
| 1843 | public Notification[] newArray(int size) |
| 1844 | { |
| 1845 | return new Notification[size]; |
| 1846 | } |
| 1847 | }; |
| 1848 | |
| 1849 | /** |
| 1850 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 1851 | * layout. |
| 1852 | * |
| 1853 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 1854 | * in the view.</p> |
| 1855 | * @param context The context for your application / activity. |
| 1856 | * @param contentTitle The title that goes in the expanded entry. |
| 1857 | * @param contentText The text that goes in the expanded entry. |
| 1858 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 1859 | * If this is an activity, it must include the |
| 1860 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 1861 | * that you take care of task management as described in the |
| 1862 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 1863 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1864 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1865 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 1866 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1867 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1868 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1869 | public void setLatestEventInfo(Context context, |
| 1870 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1871 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 1872 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 1873 | new Throwable()); |
| 1874 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1875 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1876 | // ensure that any information already set directly is preserved |
| 1877 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1878 | |
| 1879 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1881 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | } |
| 1883 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1884 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1886 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1887 | |
| 1888 | builder.build(); // callers expect this notification to be ready to use |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1889 | } |
| 1890 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 1891 | /** |
| 1892 | * @hide |
| 1893 | */ |
| 1894 | public static void addFieldsFromContext(Context context, Notification notification) { |
| 1895 | if (notification.extras.getParcelable(EXTRA_BUILDER_APPLICATION_INFO) == null) { |
| 1896 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, |
| 1897 | context.getApplicationInfo()); |
| 1898 | } |
| 1899 | if (!notification.extras.containsKey(EXTRA_ORIGINATING_USERID)) { |
| 1900 | notification.extras.putInt(EXTRA_ORIGINATING_USERID, context.getUserId()); |
| 1901 | } |
| 1902 | } |
| 1903 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1904 | @Override |
| 1905 | public String toString() { |
| 1906 | StringBuilder sb = new StringBuilder(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1907 | sb.append("Notification(pri="); |
| 1908 | sb.append(priority); |
| 1909 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 1910 | if (contentView != null) { |
| 1911 | sb.append(contentView.getPackage()); |
| 1912 | sb.append("/0x"); |
| 1913 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 1914 | } else { |
| 1915 | sb.append("null"); |
| 1916 | } |
| 1917 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1918 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 1919 | sb.append("default"); |
| 1920 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | int N = this.vibrate.length-1; |
| 1922 | sb.append("["); |
| 1923 | for (int i=0; i<N; i++) { |
| 1924 | sb.append(this.vibrate[i]); |
| 1925 | sb.append(','); |
| 1926 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 1927 | if (N != -1) { |
| 1928 | sb.append(this.vibrate[N]); |
| 1929 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1930 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1931 | } else { |
| 1932 | sb.append("null"); |
| 1933 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1934 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1935 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1937 | } else if (this.sound != null) { |
| 1938 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1939 | } else { |
| 1940 | sb.append("null"); |
| 1941 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 1942 | if (this.tickerText != null) { |
| 1943 | sb.append(" tick"); |
| 1944 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1945 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1946 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1947 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1948 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1949 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1950 | if (this.category != null) { |
| 1951 | sb.append(" category="); |
| 1952 | sb.append(this.category); |
| 1953 | } |
| 1954 | if (this.mGroupKey != null) { |
| 1955 | sb.append(" groupKey="); |
| 1956 | sb.append(this.mGroupKey); |
| 1957 | } |
| 1958 | if (this.mSortKey != null) { |
| 1959 | sb.append(" sortKey="); |
| 1960 | sb.append(this.mSortKey); |
| 1961 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1962 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1963 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1964 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1965 | } |
| 1966 | sb.append(" vis="); |
| 1967 | sb.append(visibilityToString(this.visibility)); |
| 1968 | if (this.publicVersion != null) { |
| 1969 | sb.append(" publicVersion="); |
| 1970 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1971 | } |
| 1972 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1973 | return sb.toString(); |
| 1974 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1975 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1976 | /** |
| 1977 | * {@hide} |
| 1978 | */ |
| 1979 | public static String visibilityToString(int vis) { |
| 1980 | switch (vis) { |
| 1981 | case VISIBILITY_PRIVATE: |
| 1982 | return "PRIVATE"; |
| 1983 | case VISIBILITY_PUBLIC: |
| 1984 | return "PUBLIC"; |
| 1985 | case VISIBILITY_SECRET: |
| 1986 | return "SECRET"; |
| 1987 | default: |
| 1988 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 1989 | } |
| 1990 | } |
| 1991 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1992 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 1993 | * {@hide} |
| 1994 | */ |
| 1995 | public static String priorityToString(@Priority int pri) { |
| 1996 | switch (pri) { |
| 1997 | case PRIORITY_MIN: |
| 1998 | return "MIN"; |
| 1999 | case PRIORITY_LOW: |
| 2000 | return "LOW"; |
| 2001 | case PRIORITY_DEFAULT: |
| 2002 | return "DEFAULT"; |
| 2003 | case PRIORITY_HIGH: |
| 2004 | return "HIGH"; |
| 2005 | case PRIORITY_MAX: |
| 2006 | return "MAX"; |
| 2007 | default: |
| 2008 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 2009 | } |
| 2010 | } |
| 2011 | |
| 2012 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2013 | * The small icon representing this notification in the status bar and content view. |
| 2014 | * |
| 2015 | * @return the small icon representing this notification. |
| 2016 | * |
| 2017 | * @see Builder#getSmallIcon() |
| 2018 | * @see Builder#setSmallIcon(Icon) |
| 2019 | */ |
| 2020 | public Icon getSmallIcon() { |
| 2021 | return mSmallIcon; |
| 2022 | } |
| 2023 | |
| 2024 | /** |
| 2025 | * Used when notifying to clean up legacy small icons. |
| 2026 | * @hide |
| 2027 | */ |
| 2028 | public void setSmallIcon(Icon icon) { |
| 2029 | mSmallIcon = icon; |
| 2030 | } |
| 2031 | |
| 2032 | /** |
| 2033 | * The large icon shown in this notification's content view. |
| 2034 | * @see Builder#getLargeIcon() |
| 2035 | * @see Builder#setLargeIcon(Icon) |
| 2036 | */ |
| 2037 | public Icon getLargeIcon() { |
| 2038 | return mLargeIcon; |
| 2039 | } |
| 2040 | |
| 2041 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2042 | * @hide |
| 2043 | */ |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 2044 | public boolean isGroupSummary() { |
| 2045 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 2046 | } |
| 2047 | |
| 2048 | /** |
| 2049 | * @hide |
| 2050 | */ |
| 2051 | public boolean isGroupChild() { |
| 2052 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 2053 | } |
| 2054 | |
| 2055 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2056 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2057 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2058 | * Provides a convenient way to set the various fields of a {@link Notification} and generate |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2059 | * content views using the platform's notification layout template. If your app supports |
| 2060 | * versions of Android as old as API level 4, you can instead use |
| 2061 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 2062 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 2063 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2064 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2065 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2066 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2067 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2068 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2069 | * .setContentTitle("New mail from " + sender.toString()) |
| 2070 | * .setContentText(subject) |
| 2071 | * .setSmallIcon(R.drawable.new_mail) |
| 2072 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2073 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2074 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2075 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2076 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 2077 | /** |
| 2078 | * @hide |
| 2079 | */ |
| 2080 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 2081 | "android.rebuild.contentViewActionCount"; |
| 2082 | /** |
| 2083 | * @hide |
| 2084 | */ |
| 2085 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 2086 | = "android.rebuild.bigViewActionCount"; |
| 2087 | /** |
| 2088 | * @hide |
| 2089 | */ |
| 2090 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 2091 | = "android.rebuild.hudViewActionCount"; |
| 2092 | |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 2093 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2094 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2095 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2096 | private Notification mN; |
| 2097 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2098 | private Style mStyle; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2099 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
| 2100 | private ArrayList<String> mPersonList = new ArrayList<String>(); |
| 2101 | private NotificationColorUtil mColorUtil; |
| 2102 | private boolean mColorUtilInited = false; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2103 | |
| 2104 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2105 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 2106 | */ |
| 2107 | private int mCachedContrastColor = COLOR_INVALID; |
| 2108 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
| 2109 | |
| 2110 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2111 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2112 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2113 | |
| 2114 | * <table> |
| 2115 | * <tr><th align=right>priority</th> |
| 2116 | * <td>{@link #PRIORITY_DEFAULT}</td></tr> |
| 2117 | * <tr><th align=right>when</th> |
| 2118 | * <td>now ({@link System#currentTimeMillis()})</td></tr> |
| 2119 | * <tr><th align=right>audio stream</th> |
| 2120 | * <td>{@link #STREAM_DEFAULT}</td></tr> |
| 2121 | * </table> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2122 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2123 | |
| 2124 | * @param context |
| 2125 | * A {@link Context} that will be used by the Builder to construct the |
| 2126 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 2127 | * object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2128 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2129 | public Builder(Context context) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2130 | this(context, null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2131 | } |
| 2132 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2133 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2134 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2135 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2136 | public Builder(Context context, Notification toAdopt) { |
| 2137 | mContext = context; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2138 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2139 | if (toAdopt == null) { |
| 2140 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame^] | 2141 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2142 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2143 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2144 | mN.priority = PRIORITY_DEFAULT; |
| 2145 | mN.visibility = VISIBILITY_PRIVATE; |
| 2146 | } else { |
| 2147 | mN = toAdopt; |
| 2148 | if (mN.actions != null) { |
| 2149 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2150 | } |
| 2151 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2152 | if (mN.extras.containsKey(EXTRA_PEOPLE)) { |
| 2153 | Collections.addAll(mPersonList, mN.extras.getStringArray(EXTRA_PEOPLE)); |
| 2154 | } |
| 2155 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2156 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 2157 | if (!TextUtils.isEmpty(templateClass)) { |
| 2158 | final Class<? extends Style> styleClass |
| 2159 | = getNotificationStyleClass(templateClass); |
| 2160 | if (styleClass == null) { |
| 2161 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 2162 | } else { |
| 2163 | try { |
| 2164 | final Constructor<? extends Style> ctor = styleClass.getConstructor(); |
| 2165 | ctor.setAccessible(true); |
| 2166 | final Style style = ctor.newInstance(); |
| 2167 | style.restoreFromExtras(mN.extras); |
| 2168 | |
| 2169 | if (style != null) { |
| 2170 | setStyle(style); |
| 2171 | } |
| 2172 | } catch (Throwable t) { |
| 2173 | Log.e(TAG, "Could not create Style", t); |
| 2174 | } |
| 2175 | } |
| 2176 | } |
| 2177 | |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | private NotificationColorUtil getColorUtil() { |
| 2182 | if (!mColorUtilInited) { |
| 2183 | mColorUtilInited = true; |
| 2184 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.LOLLIPOP) { |
| 2185 | mColorUtil = NotificationColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2186 | } |
| 2187 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2188 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2192 | * Add a timestamp pertaining to the notification (usually the time the event occurred). |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame^] | 2193 | * |
| 2194 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 2195 | * shown anymore by default and must be opted into by using |
| 2196 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2197 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2198 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2199 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2200 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2201 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2202 | return this; |
| 2203 | } |
| 2204 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2205 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2206 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2207 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame^] | 2208 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 2209 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2210 | */ |
| 2211 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2212 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2213 | return this; |
| 2214 | } |
| 2215 | |
| 2216 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2217 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2218 | * |
| 2219 | * Instead of presenting <code>when</code> as a timestamp, the notification will show an |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2220 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2221 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2222 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 2223 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2224 | * The counter can also be set to count down to <code>when</code> when using |
| 2225 | * {@link #setChronometerCountsDown(boolean)}. |
| 2226 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2227 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2228 | * @see Notification#when |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2229 | * @see #setChronometerCountsDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2230 | */ |
| 2231 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2232 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2233 | return this; |
| 2234 | } |
| 2235 | |
| 2236 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2237 | * Sets the Chronometer to count down instead of counting up. |
| 2238 | * |
| 2239 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 2240 | * If it isn't set the chronometer will count up. |
| 2241 | * |
| 2242 | * @see #setUsesChronometer(boolean) |
| 2243 | */ |
| 2244 | public Builder setChronometerCountsDown(boolean countsDown) { |
| 2245 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN, countsDown); |
| 2246 | return this; |
| 2247 | } |
| 2248 | |
| 2249 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2250 | * Set the small icon resource, which will be used to represent the notification in the |
| 2251 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2252 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2253 | |
| 2254 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 2255 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 2256 | * icon will be moved to the right-hand side. |
| 2257 | * |
| 2258 | |
| 2259 | * @param icon |
| 2260 | * A resource ID in the application's package of the drawable to use. |
| 2261 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2262 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2263 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2264 | return setSmallIcon(icon != 0 |
| 2265 | ? Icon.createWithResource(mContext, icon) |
| 2266 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2267 | } |
| 2268 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2269 | /** |
| 2270 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 2271 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 2272 | * LevelListDrawable}. |
| 2273 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2274 | * @param icon A resource ID in the application's package of the drawable to use. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2275 | * @param level The level to use for the icon. |
| 2276 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2277 | * @see Notification#icon |
| 2278 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2279 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2280 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2281 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2282 | return setSmallIcon(icon); |
| 2283 | } |
| 2284 | |
| 2285 | /** |
| 2286 | * Set the small icon, which will be used to represent the notification in the |
| 2287 | * status bar and content view (unless overriden there by a |
| 2288 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 2289 | * |
| 2290 | * @param icon An Icon object to use. |
| 2291 | * @see Notification#icon |
| 2292 | */ |
| 2293 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2294 | mN.setSmallIcon(icon); |
| 2295 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 2296 | mN.icon = icon.getResId(); |
| 2297 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2298 | return this; |
| 2299 | } |
| 2300 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2301 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2302 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2303 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2304 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2305 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2306 | return this; |
| 2307 | } |
| 2308 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2309 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2310 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2311 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2312 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2313 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2314 | return this; |
| 2315 | } |
| 2316 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2317 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 2318 | * This provides some additional information that is displayed in the notification. No |
| 2319 | * guarantees are given where exactly it is displayed. |
| 2320 | * |
| 2321 | * <p>This information should only be provided if it provides an essential |
| 2322 | * benefit to the understanding of the notification. The more text you provide the |
| 2323 | * less readable it becomes. For example, an email client should only provide the account |
| 2324 | * name here if more than one email account has been added.</p> |
| 2325 | * |
| 2326 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 2327 | * notification header area. |
| 2328 | * |
| 2329 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 2330 | * this will be shown in the third line of text in the platform notification template. |
| 2331 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 2332 | * same time on those versions; they occupy the same place. |
| 2333 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2334 | */ |
| 2335 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2336 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2337 | return this; |
| 2338 | } |
| 2339 | |
| 2340 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 2341 | * Set the remote input history. |
| 2342 | * |
| 2343 | * This should be set to the most recent inputs that have been sent |
| 2344 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 2345 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 2346 | * |
| 2347 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 2348 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 2349 | * and how much of each individual input is shown. |
| 2350 | * |
| 2351 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 2352 | * with a {@code RemoteInput}.</p> |
| 2353 | */ |
| 2354 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 2355 | if (text == null) { |
| 2356 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 2357 | } else { |
| 2358 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 2359 | CharSequence[] safe = new CharSequence[N]; |
| 2360 | for (int i = 0; i < N; i++) { |
| 2361 | safe[i] = safeCharSequence(text[i]); |
| 2362 | } |
| 2363 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 2364 | } |
| 2365 | return this; |
| 2366 | } |
| 2367 | |
| 2368 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2369 | * Set the large number at the right-hand side of the notification. This is |
| 2370 | * equivalent to setContentInfo, although it might show the number in a different |
| 2371 | * font size for readability. |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 2372 | * |
| 2373 | * @deprecated this number is not shown anywhere anymore |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2374 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2375 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2376 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2377 | return this; |
| 2378 | } |
| 2379 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2380 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2381 | * A small piece of additional information pertaining to this notification. |
| 2382 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2383 | * The platform template will draw this on the last line of the notification, at the far |
| 2384 | * right (to the right of a smallIcon if it has been placed there). |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 2385 | * |
| 2386 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 2387 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 2388 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2389 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2390 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2391 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2392 | return this; |
| 2393 | } |
| 2394 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2395 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2396 | * Set the progress this notification represents. |
| 2397 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2398 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2399 | */ |
| 2400 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2401 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 2402 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 2403 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2404 | return this; |
| 2405 | } |
| 2406 | |
| 2407 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2408 | * Supply a custom RemoteViews to use instead of the platform template. |
| 2409 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2410 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2411 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2412 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2413 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2414 | return setCustomContentView(views); |
| 2415 | } |
| 2416 | |
| 2417 | /** |
| 2418 | * Supply custom RemoteViews to use instead of the platform template. |
| 2419 | * |
| 2420 | * This will override the layout that would otherwise be constructed by this Builder |
| 2421 | * object. |
| 2422 | */ |
| 2423 | public Builder setCustomContentView(RemoteViews contentView) { |
| 2424 | mN.contentView = contentView; |
| 2425 | return this; |
| 2426 | } |
| 2427 | |
| 2428 | /** |
| 2429 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 2430 | * |
| 2431 | * This will override the expanded layout that would otherwise be constructed by this |
| 2432 | * Builder object. |
| 2433 | */ |
| 2434 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 2435 | mN.bigContentView = contentView; |
| 2436 | return this; |
| 2437 | } |
| 2438 | |
| 2439 | /** |
| 2440 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 2441 | * |
| 2442 | * This will override the heads-up layout that would otherwise be constructed by this |
| 2443 | * Builder object. |
| 2444 | */ |
| 2445 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 2446 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2447 | return this; |
| 2448 | } |
| 2449 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2450 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2451 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 2452 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2453 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 2454 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 2455 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2456 | * to assign PendingIntents to individual views in that custom layout (i.e., to create |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2457 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2458 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2459 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2460 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2461 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2462 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2463 | return this; |
| 2464 | } |
| 2465 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2466 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2467 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 2468 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2469 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2470 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2471 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2472 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2473 | return this; |
| 2474 | } |
| 2475 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2476 | /** |
| 2477 | * An intent to launch instead of posting the notification to the status bar. |
| 2478 | * Only for use with extremely high-priority notifications demanding the user's |
| 2479 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 2480 | * alarm clock that the user has explicitly set to a particular time. |
| 2481 | * If this facility is used for something else, please give the user an option |
| 2482 | * to turn it off and use a normal notification, as this can be extremely |
| 2483 | * disruptive. |
| 2484 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2485 | * <p> |
| 2486 | * The system UI may choose to display a heads-up notification, instead of |
| 2487 | * launching this intent, while the user is using the device. |
| 2488 | * </p> |
| 2489 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2490 | * @param intent The pending intent to launch. |
| 2491 | * @param highPriority Passing true will cause this notification to be sent |
| 2492 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2493 | * |
| 2494 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2495 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2496 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2497 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2498 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 2499 | return this; |
| 2500 | } |
| 2501 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2502 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2503 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2504 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2505 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2506 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2507 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2508 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2509 | return this; |
| 2510 | } |
| 2511 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2512 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2513 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2514 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2515 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2516 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2517 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2518 | setTicker(tickerText); |
| 2519 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2520 | return this; |
| 2521 | } |
| 2522 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2523 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2524 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2525 | * |
| 2526 | * In the platform template, this image will be shown on the left of the notification view |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2527 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 2528 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2529 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2530 | public Builder setLargeIcon(Bitmap b) { |
| 2531 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 2532 | } |
| 2533 | |
| 2534 | /** |
| 2535 | * Add a large icon to the notification content view. |
| 2536 | * |
| 2537 | * In the platform template, this image will be shown on the left of the notification view |
| 2538 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 2539 | * badge atop the large icon). |
| 2540 | */ |
| 2541 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2542 | mN.mLargeIcon = icon; |
| 2543 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2544 | return this; |
| 2545 | } |
| 2546 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2547 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2548 | * Set the sound to play. |
| 2549 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2550 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 2551 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2552 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2553 | * <p> |
| 2554 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2555 | * </p> |
| 2556 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2557 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2558 | */ |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 2559 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2560 | mN.sound = sound; |
| 2561 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 2562 | return this; |
| 2563 | } |
| 2564 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2565 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2566 | * Set the sound to play, along with a specific stream on which to play it. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2567 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2568 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 2569 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2570 | * <p> |
| 2571 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2572 | * </p> |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2573 | * @deprecated use {@link #setSound(Uri, AudioAttributes)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2574 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2575 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 2576 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2577 | public Builder setSound(Uri sound, int streamType) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2578 | mN.sound = sound; |
| 2579 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2580 | return this; |
| 2581 | } |
| 2582 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2583 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2584 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 2585 | * use during playback. |
| 2586 | * |
| 2587 | * <p> |
| 2588 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2589 | * </p> |
| 2590 | * |
| 2591 | * @see Notification#sound |
| 2592 | */ |
| 2593 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2594 | mN.sound = sound; |
| 2595 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2596 | return this; |
| 2597 | } |
| 2598 | |
| 2599 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2600 | * Set the vibration pattern to use. |
| 2601 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2602 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 2603 | * <code>pattern</code> parameter. |
| 2604 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2605 | * <p> |
| 2606 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 2607 | * </p> |
| 2608 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2609 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2610 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2611 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2612 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2613 | return this; |
| 2614 | } |
| 2615 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2616 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2617 | * Set the desired color for the indicator LED on the device, as well as the |
| 2618 | * blink duty cycle (specified in milliseconds). |
| 2619 | * |
| 2620 | |
| 2621 | * Not all devices will honor all (or even any) of these values. |
| 2622 | * |
| 2623 | |
| 2624 | * @see Notification#ledARGB |
| 2625 | * @see Notification#ledOnMS |
| 2626 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2627 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 2628 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2629 | mN.ledARGB = argb; |
| 2630 | mN.ledOnMS = onMs; |
| 2631 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 2632 | if (onMs != 0 || offMs != 0) { |
| 2633 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 2634 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2635 | return this; |
| 2636 | } |
| 2637 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2638 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2639 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2640 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2641 | |
| 2642 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 2643 | * must take care of canceling them. |
| 2644 | * |
| 2645 | |
| 2646 | * They are typically used to indicate a background task that the user is actively engaged |
| 2647 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 2648 | * (e.g., a file download, sync operation, active network connection). |
| 2649 | * |
| 2650 | |
| 2651 | * @see Notification#FLAG_ONGOING_EVENT |
| 2652 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2653 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2654 | public Builder setOngoing(boolean ongoing) { |
| 2655 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 2656 | return this; |
| 2657 | } |
| 2658 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2659 | /** |
| 2660 | * Set this flag if you would only like the sound, vibrate |
| 2661 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2662 | * |
| 2663 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2664 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2665 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 2666 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 2667 | return this; |
| 2668 | } |
| 2669 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2670 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2671 | * Make this notification automatically dismissed when the user touches it. The |
| 2672 | * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens. |
| 2673 | * |
| 2674 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2675 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2676 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 2677 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2678 | return this; |
| 2679 | } |
| 2680 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2681 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 2682 | * Set whether or not this notification should not bridge to other devices. |
| 2683 | * |
| 2684 | * <p>Some notifications can be bridged to other devices for remote display. |
| 2685 | * This hint can be set to recommend this notification not be bridged. |
| 2686 | */ |
| 2687 | public Builder setLocalOnly(boolean localOnly) { |
| 2688 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 2689 | return this; |
| 2690 | } |
| 2691 | |
| 2692 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2693 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2694 | * <p> |
| 2695 | * The value should be one or more of the following fields combined with |
| 2696 | * bitwise-or: |
| 2697 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 2698 | * <p> |
| 2699 | * For all default values, use {@link #DEFAULT_ALL}. |
| 2700 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2701 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2702 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2703 | return this; |
| 2704 | } |
| 2705 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2706 | /** |
| 2707 | * Set the priority of this notification. |
| 2708 | * |
| 2709 | * @see Notification#priority |
| 2710 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2711 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2712 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2713 | return this; |
| 2714 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2715 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2716 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2717 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2718 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2719 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2720 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2721 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2722 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2723 | return this; |
| 2724 | } |
| 2725 | |
| 2726 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2727 | * Add a person that is relevant to this notification. |
| 2728 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 2729 | * <P> |
| 2730 | * Depending on user preferences, this annotation may allow the notification to pass |
| 2731 | * through interruption filters, and to appear more prominently in the user interface. |
| 2732 | * </P> |
| 2733 | * |
| 2734 | * <P> |
| 2735 | * The person should be specified by the {@code String} representation of a |
| 2736 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 2737 | * </P> |
| 2738 | * |
| 2739 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 2740 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 2741 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 2742 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
| 2743 | * </P> |
| 2744 | * |
| 2745 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2746 | * @see Notification#EXTRA_PEOPLE |
| 2747 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 2748 | public Builder addPerson(String uri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2749 | mPersonList.add(uri); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2750 | return this; |
| 2751 | } |
| 2752 | |
| 2753 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2754 | * Set this notification to be part of a group of notifications sharing the same key. |
| 2755 | * Grouped notifications may display in a cluster or stack on devices which |
| 2756 | * support such rendering. |
| 2757 | * |
| 2758 | * <p>To make this notification the summary for its group, also call |
| 2759 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 2760 | * {@link #setSortKey}. |
| 2761 | * @param groupKey The group key of the group. |
| 2762 | * @return this object for method chaining |
| 2763 | */ |
| 2764 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2765 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2766 | return this; |
| 2767 | } |
| 2768 | |
| 2769 | /** |
| 2770 | * Set this notification to be the group summary for a group of notifications. |
| 2771 | * Grouped notifications may display in a cluster or stack on devices which |
| 2772 | * support such rendering. Requires a group key also be set using {@link #setGroup}. |
| 2773 | * @param isGroupSummary Whether this notification should be a group summary. |
| 2774 | * @return this object for method chaining |
| 2775 | */ |
| 2776 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 2777 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 2778 | return this; |
| 2779 | } |
| 2780 | |
| 2781 | /** |
| 2782 | * Set a sort key that orders this notification among other notifications from the |
| 2783 | * same package. This can be useful if an external sort was already applied and an app |
| 2784 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 2785 | * value, although providing different priorities in addition to providing sort key may |
| 2786 | * cause this value to be ignored. |
| 2787 | * |
| 2788 | * <p>This sort key can also be used to order members of a notification group. See |
Griff Hazen | 9e1379f | 2014-05-20 12:50:51 -0700 | [diff] [blame] | 2789 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2790 | * |
| 2791 | * @see String#compareTo(String) |
| 2792 | */ |
| 2793 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2794 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2795 | return this; |
| 2796 | } |
| 2797 | |
| 2798 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2799 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2800 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2801 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 2802 | * |
| 2803 | * @see Notification#extras |
| 2804 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2805 | public Builder addExtras(Bundle extras) { |
| 2806 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2807 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2808 | } |
| 2809 | return this; |
| 2810 | } |
| 2811 | |
| 2812 | /** |
| 2813 | * Set metadata for this notification. |
| 2814 | * |
| 2815 | * <p>A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2816 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2817 | * called. |
| 2818 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2819 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 2820 | * Use {@link #addExtras} to merge in metadata instead. |
| 2821 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2822 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2823 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2824 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2825 | if (extras != null) { |
| 2826 | mUserExtras = extras; |
| 2827 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2828 | return this; |
| 2829 | } |
| 2830 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2831 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2832 | * Get the current metadata Bundle used by this notification Builder. |
| 2833 | * |
| 2834 | * <p>The returned Bundle is shared with this Builder. |
| 2835 | * |
| 2836 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 2837 | * {@link #build()} is called. |
| 2838 | * |
| 2839 | * @see Notification#extras |
| 2840 | */ |
| 2841 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2842 | return mUserExtras; |
| 2843 | } |
| 2844 | |
| 2845 | private Bundle getAllExtras() { |
| 2846 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 2847 | saveExtras.putAll(mN.extras); |
| 2848 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2852 | * Add an action to this notification. Actions are typically displayed by |
| 2853 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2854 | * <p> |
| 2855 | * Every action must have an icon (32dp square and matching the |
| 2856 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2857 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2858 | * <p> |
| 2859 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2860 | * the order they were added. Actions will not be displayed when the notification is |
| 2861 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2862 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2863 | * |
| 2864 | * @param icon Resource ID of a drawable that represents the action. |
| 2865 | * @param title Text describing the action. |
| 2866 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 2867 | * |
| 2868 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2869 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 2870 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2871 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2872 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2873 | return this; |
| 2874 | } |
| 2875 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2876 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2877 | * Add an action to this notification. Actions are typically displayed by |
| 2878 | * the system as a button adjacent to the notification content. |
| 2879 | * <p> |
| 2880 | * Every action must have an icon (32dp square and matching the |
| 2881 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2882 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2883 | * <p> |
| 2884 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2885 | * the order they were added. Actions will not be displayed when the notification is |
| 2886 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2887 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 2888 | * |
| 2889 | * @param action The action to add. |
| 2890 | */ |
| 2891 | public Builder addAction(Action action) { |
| 2892 | mActions.add(action); |
| 2893 | return this; |
| 2894 | } |
| 2895 | |
| 2896 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2897 | * Alter the complete list of actions attached to this notification. |
| 2898 | * @see #addAction(Action). |
| 2899 | * |
| 2900 | * @param actions |
| 2901 | * @return |
| 2902 | */ |
| 2903 | public Builder setActions(Action... actions) { |
| 2904 | mActions.clear(); |
| 2905 | for (int i = 0; i < actions.length; i++) { |
| 2906 | mActions.add(actions[i]); |
| 2907 | } |
| 2908 | return this; |
| 2909 | } |
| 2910 | |
| 2911 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2912 | * Add a rich notification style to be applied at build time. |
| 2913 | * |
| 2914 | * @param style Object responsible for modifying the notification style. |
| 2915 | */ |
| 2916 | public Builder setStyle(Style style) { |
| 2917 | if (mStyle != style) { |
| 2918 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2919 | if (mStyle != null) { |
| 2920 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2921 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 2922 | } else { |
| 2923 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2924 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2925 | } |
| 2926 | return this; |
| 2927 | } |
| 2928 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2929 | /** |
| 2930 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2931 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2932 | * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default), |
| 2933 | * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}. |
| 2934 | * |
| 2935 | * @return The same Builder. |
| 2936 | */ |
| 2937 | public Builder setVisibility(int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2938 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2939 | return this; |
| 2940 | } |
| 2941 | |
| 2942 | /** |
| 2943 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 2944 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 2945 | * @param n A replacement notification, presumably with some or all info redacted. |
| 2946 | * @return The same Builder. |
| 2947 | */ |
| 2948 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2949 | if (n != null) { |
| 2950 | mN.publicVersion = new Notification(); |
| 2951 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 2952 | } else { |
| 2953 | mN.publicVersion = null; |
| 2954 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2955 | return this; |
| 2956 | } |
| 2957 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2958 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2959 | * Apply an extender to this notification builder. Extenders may be used to add |
| 2960 | * metadata or change options on this builder. |
| 2961 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2962 | public Builder extend(Extender extender) { |
| 2963 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2964 | return this; |
| 2965 | } |
| 2966 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2967 | /** |
| 2968 | * @hide |
| 2969 | */ |
| 2970 | public void setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2971 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2972 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2973 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2974 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2975 | } |
| 2976 | } |
| 2977 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2978 | /** |
| 2979 | * Sets {@link Notification#color}. |
| 2980 | * |
| 2981 | * @param argb The accent color to use |
| 2982 | * |
| 2983 | * @return The same Builder. |
| 2984 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 2985 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2986 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 2987 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2988 | return this; |
| 2989 | } |
| 2990 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2991 | private Drawable getProfileBadgeDrawable() { |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2992 | // Note: This assumes that the current user can read the profile badge of the |
| 2993 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 2994 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2995 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | private Bitmap getProfileBadge() { |
| 2999 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3000 | if (badge == null) { |
| 3001 | return null; |
| 3002 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3003 | final int size = mContext.getResources().getDimensionPixelSize( |
| 3004 | R.dimen.notification_badge_size); |
| 3005 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3006 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3007 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3008 | badge.draw(canvas); |
| 3009 | return bitmap; |
| 3010 | } |
| 3011 | |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3012 | private void bindProfileBadge(RemoteViews contentView) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3013 | Bitmap profileBadge = getProfileBadge(); |
| 3014 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3015 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3016 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 3017 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3018 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3019 | } |
| 3020 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3021 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3022 | resetNotificationHeader(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3023 | resetContentMargins(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3024 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3025 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3026 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3027 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3028 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3029 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3030 | contentView.setTextViewText(R.id.text_line_1, null); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3031 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3034 | /** |
| 3035 | * Resets the notification header to its original state |
| 3036 | */ |
| 3037 | private void resetNotificationHeader(RemoteViews contentView) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3038 | contentView.setImageViewResource(R.id.icon, 0); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 3039 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3040 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 3041 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3042 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
| 3043 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3044 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3045 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 3046 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | private void resetContentMargins(RemoteViews contentView) { |
| 3050 | contentView.setViewLayoutMarginEnd(R.id.line1, 0); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3051 | contentView.setViewLayoutMarginEnd(R.id.text, 0); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3052 | } |
| 3053 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3054 | private RemoteViews applyStandardTemplate(int resId) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3055 | return applyStandardTemplate(resId, true /* hasProgress */); |
| 3056 | } |
| 3057 | |
| 3058 | /** |
| 3059 | * @param hasProgress whether the progress bar should be shown and set |
| 3060 | */ |
| 3061 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3062 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 3063 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3064 | resetStandardTemplate(contentView); |
| 3065 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3066 | final Bundle ex = mN.extras; |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3067 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3068 | bindNotificationHeader(contentView); |
| 3069 | bindLargeIcon(contentView); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3070 | if (ex.getCharSequence(EXTRA_TITLE) != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3071 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3072 | contentView.setTextViewText(R.id.title, |
| 3073 | processLegacyText(ex.getCharSequence(EXTRA_TITLE))); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3074 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3075 | boolean showProgress = handleProgressBar(hasProgress, contentView, ex); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3076 | if (ex.getCharSequence(EXTRA_TEXT) != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3077 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 3078 | : com.android.internal.R.id.text; |
| 3079 | contentView.setTextViewText(textId, processLegacyText( |
| 3080 | ex.getCharSequence(EXTRA_TEXT))); |
| 3081 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3082 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3083 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3084 | setContentMinHeight(contentView, showProgress || mN.mLargeIcon != null); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3085 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3086 | return contentView; |
| 3087 | } |
| 3088 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3089 | /** |
| 3090 | * @param remoteView the remote view to update the minheight in |
| 3091 | * @param hasMinHeight does it have a mimHeight |
| 3092 | * @hide |
| 3093 | */ |
| 3094 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 3095 | int minHeight = 0; |
| 3096 | if (hasMinHeight) { |
| 3097 | // we need to set the minHeight of the notification |
| 3098 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 3099 | com.android.internal.R.dimen.notification_min_content_height); |
| 3100 | } |
| 3101 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 3102 | } |
| 3103 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3104 | private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3105 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 3106 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 3107 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 3108 | if (hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3109 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3110 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3111 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3112 | contentView.setProgressBackgroundTintList( |
| 3113 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 3114 | R.color.notification_progress_background_color))); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3115 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3116 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3117 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 3118 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3119 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3120 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3121 | } else { |
| 3122 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3123 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3124 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3125 | } |
| 3126 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3127 | private void bindLargeIcon(RemoteViews contentView) { |
| 3128 | if (mN.mLargeIcon != null) { |
| 3129 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 3130 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
| 3131 | processLargeLegacyIcon(mN.mLargeIcon, contentView); |
| 3132 | int endMargin = mContext.getResources().getDimensionPixelSize( |
| 3133 | R.dimen.notification_content_picture_margin); |
| 3134 | contentView.setViewLayoutMarginEnd(R.id.line1, endMargin); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3135 | contentView.setViewLayoutMarginEnd(R.id.text, endMargin); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3136 | contentView.setViewLayoutMarginEnd(R.id.progress, endMargin); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3137 | } |
| 3138 | } |
| 3139 | |
| 3140 | private void bindNotificationHeader(RemoteViews contentView) { |
| 3141 | bindSmallIcon(contentView); |
| 3142 | bindHeaderAppName(contentView); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3143 | bindHeaderText(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3144 | bindHeaderChronometerAndTime(contentView); |
| 3145 | bindExpandButton(contentView); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3146 | bindProfileBadge(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | private void bindExpandButton(RemoteViews contentView) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3150 | contentView.setDrawableParameters(R.id.expand_button, false, -1, resolveContrastColor(), |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3151 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3152 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3153 | resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | private void bindHeaderChronometerAndTime(RemoteViews contentView) { |
| 3157 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3158 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3159 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 3160 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 3161 | contentView.setLong(R.id.chronometer, "setBase", |
| 3162 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 3163 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3164 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN); |
| 3165 | contentView.setChronometerCountsDown(R.id.chronometer, countsDown); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3166 | } else { |
| 3167 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 3168 | contentView.setLong(R.id.time, "setTime", mN.when); |
| 3169 | } |
| 3170 | } |
| 3171 | } |
| 3172 | |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3173 | private void bindHeaderText(RemoteViews contentView) { |
| 3174 | CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 3175 | if (headerText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3176 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3177 | headerText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3178 | } |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3179 | if (headerText == null |
| 3180 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 3181 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 3182 | headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 3183 | } |
| 3184 | if (headerText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3185 | // TODO: Remove the span entirely to only have the string with propper formating. |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3186 | contentView.setTextViewText(R.id.header_text, processLegacyText(headerText)); |
| 3187 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 3188 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | private void bindHeaderAppName(RemoteViews contentView) { |
Tony Mak | 4dc008c | 2016-03-16 10:46:49 +0000 | [diff] [blame] | 3193 | CharSequence appName = mContext.getPackageManager() |
| 3194 | .getApplicationLabel(mContext.getApplicationInfo()); |
| 3195 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3196 | if (TextUtils.isEmpty(appName)) { |
| 3197 | return; |
| 3198 | } |
| 3199 | contentView.setTextViewText(R.id.app_name_text, appName); |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3200 | contentView.setTextColor(R.id.app_name_text, resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | private void bindSmallIcon(RemoteViews contentView) { |
| 3204 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
| 3205 | processSmallIconColor(mN.mSmallIcon, contentView); |
| 3206 | } |
| 3207 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3208 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3209 | * @return true if the built notification will show the time or the chronometer; false |
| 3210 | * otherwise |
| 3211 | */ |
| 3212 | private boolean showsTimeOrChronometer() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3213 | return mN.when != 0 && mN.extras.getBoolean(EXTRA_SHOW_WHEN); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3214 | } |
| 3215 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3216 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 3217 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3218 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3219 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3220 | |
| 3221 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 3222 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
| 3223 | |
| 3224 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 3225 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 3226 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 3227 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3228 | } |
| 3229 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3230 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3231 | RemoteViews big = applyStandardTemplate(layoutId); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3232 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3233 | resetStandardTemplateWithActions(big); |
| 3234 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3235 | boolean validRemoteInput = false; |
| 3236 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3237 | int N = mActions.size(); |
| 3238 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 3239 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3240 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3241 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3242 | for (int i=0; i<N; i++) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3243 | Action action = mActions.get(i); |
| 3244 | validRemoteInput |= hasValidRemoteInput(action); |
| 3245 | |
| 3246 | final RemoteViews button = generateActionButton(action); |
Adrian Roos | 9b123cf | 2016-02-04 14:55:57 -0800 | [diff] [blame] | 3247 | if (i == N - 1) { |
| 3248 | button.setViewLayoutWidth(com.android.internal.R.id.action0, |
| 3249 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 3250 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3251 | big.addView(R.id.actions, button); |
| 3252 | } |
| 3253 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3254 | |
| 3255 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
| 3256 | if (validRemoteInput && replyText != null |
| 3257 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) { |
| 3258 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
| 3259 | big.setTextViewText(R.id.notification_material_reply_text_1, replyText[0]); |
| 3260 | |
| 3261 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) { |
| 3262 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
| 3263 | big.setTextViewText(R.id.notification_material_reply_text_2, replyText[1]); |
| 3264 | |
| 3265 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) { |
| 3266 | big.setViewVisibility( |
| 3267 | R.id.notification_material_reply_text_3, View.VISIBLE); |
| 3268 | big.setTextViewText(R.id.notification_material_reply_text_3, replyText[2]); |
| 3269 | } |
| 3270 | } |
| 3271 | } |
| 3272 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3273 | return big; |
| 3274 | } |
| 3275 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3276 | private boolean hasValidRemoteInput(Action action) { |
| 3277 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 3278 | // Weird actions |
| 3279 | return false; |
| 3280 | } |
| 3281 | |
| 3282 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 3283 | if (remoteInputs == null) { |
| 3284 | return false; |
| 3285 | } |
| 3286 | |
| 3287 | for (RemoteInput r : remoteInputs) { |
| 3288 | CharSequence[] choices = r.getChoices(); |
| 3289 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 3290 | return true; |
| 3291 | } |
| 3292 | } |
| 3293 | return false; |
| 3294 | } |
| 3295 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3296 | /** |
| 3297 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 3298 | * 1. Custom contentView from the caller |
| 3299 | * 2. Style's proposed content view |
| 3300 | * 3. Standard template view |
| 3301 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3302 | public RemoteViews createContentView() { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3303 | if (mN.contentView != null && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3304 | return mN.contentView; |
| 3305 | } else if (mStyle != null) { |
| 3306 | final RemoteViews styleView = mStyle.makeContentView(); |
| 3307 | if (styleView != null) { |
| 3308 | return styleView; |
| 3309 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3310 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3311 | return applyStandardTemplate(getBaseLayoutResource()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3312 | } |
| 3313 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3314 | /** |
| 3315 | * Construct a RemoteViews for the final big notification layout. |
| 3316 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3317 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3318 | RemoteViews result = null; |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3319 | if (mN.bigContentView != null |
| 3320 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 3321 | return mN.bigContentView; |
| 3322 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3323 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 3324 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 3325 | } else if (mActions.size() != 0) { |
| 3326 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3327 | } |
| 3328 | adaptNotificationHeaderForBigContentView(result); |
| 3329 | return result; |
| 3330 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3331 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3332 | /** |
| 3333 | * Construct a RemoteViews for the final notification header only |
| 3334 | * |
| 3335 | * @hide |
| 3336 | */ |
| 3337 | public RemoteViews makeNotificationHeader() { |
| 3338 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
| 3339 | R.layout.notification_template_header); |
| 3340 | resetNotificationHeader(header); |
| 3341 | bindNotificationHeader(header); |
| 3342 | return header; |
| 3343 | } |
| 3344 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3345 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 3346 | if (result != null) { |
| 3347 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 3348 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3349 | } |
| 3350 | |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3351 | private void adaptNotificationHeaderForBigContentView(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 3352 | if (result != null) { |
| 3353 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 3354 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3355 | } |
| 3356 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3357 | /** |
| 3358 | * Construct a RemoteViews for the final heads-up notification layout. |
| 3359 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3360 | public RemoteViews createHeadsUpContentView() { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3361 | if (mN.headsUpContentView != null |
| 3362 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 3363 | return mN.headsUpContentView; |
| 3364 | } else if (mStyle != null) { |
| 3365 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(); |
| 3366 | if (styleView != null) { |
| 3367 | return styleView; |
| 3368 | } |
| 3369 | } else if (mActions.size() == 0) { |
| 3370 | return null; |
| 3371 | } |
| 3372 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3373 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 3374 | } |
| 3375 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 3376 | /** |
| 3377 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 3378 | * |
| 3379 | * @hide |
| 3380 | */ |
| 3381 | public RemoteViews makePublicContentView() { |
| 3382 | if (mN.publicVersion != null) { |
| 3383 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3384 | return builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 3385 | } |
| 3386 | Bundle savedBundle = mN.extras; |
| 3387 | Style style = mStyle; |
| 3388 | mStyle = null; |
| 3389 | Icon largeIcon = mN.mLargeIcon; |
| 3390 | mN.mLargeIcon = null; |
| 3391 | Bundle publicExtras = new Bundle(); |
| 3392 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 3393 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 3394 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 3395 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3396 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN, |
| 3397 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN)); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 3398 | publicExtras.putCharSequence(EXTRA_TITLE, |
| 3399 | mContext.getString(R.string.notification_hidden_text)); |
| 3400 | mN.extras = publicExtras; |
| 3401 | final RemoteViews publicView = applyStandardTemplate(getBaseLayoutResource()); |
| 3402 | mN.extras = savedBundle; |
| 3403 | mN.mLargeIcon = largeIcon; |
| 3404 | mStyle = style; |
| 3405 | return publicView; |
| 3406 | } |
| 3407 | |
| 3408 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 3409 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3410 | private RemoteViews generateActionButton(Action action) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3411 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 3412 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3413 | tombstone ? getActionTombstoneLayoutResource() |
| 3414 | : getActionLayoutResource()); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 3415 | final Icon ai = action.getIcon(); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3416 | button.setTextViewText(R.id.action0, processLegacyText(action.title)); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3417 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 3418 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 3419 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3420 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 3421 | if (action.mRemoteInputs != null) { |
| 3422 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 3423 | } |
| 3424 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3425 | button.setTextColor(R.id.action0, resolveContrastColor()); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 3426 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3427 | return button; |
| 3428 | } |
| 3429 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3430 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3431 | * @return Whether we are currently building a notification from a legacy (an app that |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3432 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3433 | */ |
| 3434 | private boolean isLegacy() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3435 | return getColorUtil() != null; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3436 | } |
| 3437 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3438 | private CharSequence processLegacyText(CharSequence charSequence) { |
| 3439 | if (isLegacy()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3440 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3441 | } else { |
| 3442 | return charSequence; |
| 3443 | } |
| 3444 | } |
| 3445 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3446 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3447 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3448 | */ |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3449 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3450 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
| 3451 | if (colorable) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3452 | contentView.setDrawableParameters(R.id.icon, false, -1, resolveContrastColor(), |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 3453 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3454 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3455 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3456 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3457 | colorable ? resolveContrastColor() : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3458 | } |
| 3459 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3460 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3461 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3462 | * if it's grayscale). |
| 3463 | */ |
| 3464 | // TODO: also check bounds, transparency, that sort of thing. |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3465 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) { |
| 3466 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3467 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3468 | // resolve color will fall back to the default when legacy |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3469 | contentView.setDrawableParameters(R.id.icon, false, -1, resolveContrastColor(), |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3470 | PorterDuff.Mode.SRC_ATOP, -1); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 3471 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3472 | } |
| 3473 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3474 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3475 | if (mN.color != COLOR_DEFAULT) { |
| 3476 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3477 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3478 | } |
| 3479 | |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3480 | int resolveContrastColor() { |
| 3481 | if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) { |
| 3482 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3483 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3484 | final int contrasted = NotificationColorUtil.resolveContrastColor(mContext, mN.color); |
| 3485 | |
| 3486 | mCachedContrastColorIsFor = mN.color; |
| 3487 | return mCachedContrastColor = contrasted; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3488 | } |
| 3489 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3490 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3491 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3492 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3493 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3494 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3495 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3496 | mN.actions = new Action[mActions.size()]; |
| 3497 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3498 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3499 | if (!mPersonList.isEmpty()) { |
| 3500 | mN.extras.putStringArray(EXTRA_PEOPLE, |
| 3501 | mPersonList.toArray(new String[mPersonList.size()])); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3502 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 3503 | if (mN.bigContentView != null || mN.contentView != null |
| 3504 | || mN.headsUpContentView != null) { |
| 3505 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 3506 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3507 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3508 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3509 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3510 | /** |
| 3511 | * Creates a Builder from an existing notification so further changes can be made. |
| 3512 | * @param context The context for your application / activity. |
| 3513 | * @param n The notification to create a Builder from. |
| 3514 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3515 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3516 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3517 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 3518 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3519 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 3520 | if (applicationInfo != null) { |
| 3521 | try { |
| 3522 | builderContext = context.createApplicationContext(applicationInfo, |
| 3523 | Context.CONTEXT_RESTRICTED); |
| 3524 | } catch (NameNotFoundException e) { |
| 3525 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 3526 | builderContext = context; // try with our context |
| 3527 | } |
| 3528 | } else { |
| 3529 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3530 | } |
| 3531 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3532 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | private static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3536 | Class<? extends Style>[] classes = new Class[] { |
| 3537 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 3538 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class }; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3539 | for (Class<? extends Style> innerClass : classes) { |
| 3540 | if (templateClass.equals(innerClass.getName())) { |
| 3541 | return innerClass; |
| 3542 | } |
| 3543 | } |
| 3544 | return null; |
| 3545 | } |
| 3546 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3547 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3548 | * @deprecated Use {@link #build()} instead. |
| 3549 | */ |
| 3550 | @Deprecated |
| 3551 | public Notification getNotification() { |
| 3552 | return build(); |
| 3553 | } |
| 3554 | |
| 3555 | /** |
| 3556 | * Combine all of the options that have been set and return a new {@link Notification} |
| 3557 | * object. |
| 3558 | */ |
| 3559 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3560 | // first, add any extras from the calling code |
| 3561 | if (mUserExtras != null) { |
| 3562 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 3563 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3564 | |
| 3565 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 3566 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 3567 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3568 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3569 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3570 | if (mStyle != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3571 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3572 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3573 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 3574 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 3575 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3576 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3577 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3578 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 3579 | mN.contentView.getSequenceNumber()); |
| 3580 | } |
| 3581 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3582 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3583 | if (mN.bigContentView != null) { |
| 3584 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 3585 | mN.bigContentView.getSequenceNumber()); |
| 3586 | } |
| 3587 | } |
| 3588 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3589 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3590 | if (mN.headsUpContentView != null) { |
| 3591 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 3592 | mN.headsUpContentView.getSequenceNumber()); |
| 3593 | } |
| 3594 | } |
| 3595 | } |
| 3596 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 3597 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 3598 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 3599 | } |
| 3600 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3601 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3602 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3603 | |
| 3604 | /** |
| 3605 | * Apply this Builder to an existing {@link Notification} object. |
| 3606 | * |
| 3607 | * @hide |
| 3608 | */ |
| 3609 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 3610 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3611 | return n; |
| 3612 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3613 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3614 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3615 | * Removes RemoteViews that were created for compatibility from {@param n}, if they did not |
| 3616 | * change. |
| 3617 | * |
| 3618 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 3619 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3620 | * @hide |
| 3621 | */ |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3622 | public static Notification maybeCloneStrippedForDelivery(Notification n) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3623 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3624 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3625 | // Only strip views for known Styles because we won't know how to |
| 3626 | // re-create them otherwise. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3627 | if (!TextUtils.isEmpty(templateClass) |
| 3628 | && getNotificationStyleClass(templateClass) == null) { |
| 3629 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3630 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3631 | |
| 3632 | // Only strip unmodified BuilderRemoteViews. |
| 3633 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3634 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3635 | n.contentView.getSequenceNumber(); |
| 3636 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3637 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3638 | n.bigContentView.getSequenceNumber(); |
| 3639 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3640 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3641 | n.headsUpContentView.getSequenceNumber(); |
| 3642 | |
| 3643 | // Nothing to do here, no need to clone. |
| 3644 | if (!stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
| 3645 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3646 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3647 | |
| 3648 | Notification clone = n.clone(); |
| 3649 | if (stripContentView) { |
| 3650 | clone.contentView = null; |
| 3651 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 3652 | } |
| 3653 | if (stripBigContentView) { |
| 3654 | clone.bigContentView = null; |
| 3655 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 3656 | } |
| 3657 | if (stripHeadsUpContentView) { |
| 3658 | clone.headsUpContentView = null; |
| 3659 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 3660 | } |
| 3661 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3662 | } |
| 3663 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3664 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3665 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3669 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3673 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3677 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3681 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3685 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3689 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3690 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3691 | } |
| 3692 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3693 | /** |
| 3694 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 3695 | * object. |
| 3696 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3697 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3698 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3699 | |
| 3700 | /** |
| 3701 | * @hide |
| 3702 | */ |
| 3703 | protected CharSequence mSummaryText = null; |
| 3704 | |
| 3705 | /** |
| 3706 | * @hide |
| 3707 | */ |
| 3708 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3709 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3710 | protected Builder mBuilder; |
| 3711 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3712 | /** |
| 3713 | * Overrides ContentTitle in the big form of the template. |
| 3714 | * This defaults to the value passed to setContentTitle(). |
| 3715 | */ |
| 3716 | protected void internalSetBigContentTitle(CharSequence title) { |
| 3717 | mBigContentTitle = title; |
| 3718 | } |
| 3719 | |
| 3720 | /** |
| 3721 | * Set the first line of text after the detail section in the big form of the template. |
| 3722 | */ |
| 3723 | protected void internalSetSummaryText(CharSequence cs) { |
| 3724 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3725 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3726 | } |
| 3727 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3728 | public void setBuilder(Builder builder) { |
| 3729 | if (mBuilder != builder) { |
| 3730 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3731 | if (mBuilder != null) { |
| 3732 | mBuilder.setStyle(this); |
| 3733 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3734 | } |
| 3735 | } |
| 3736 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3737 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3738 | if (mBuilder == null) { |
| 3739 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 3740 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3741 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3742 | |
| 3743 | protected RemoteViews getStandardView(int layoutId) { |
| 3744 | checkBuilder(); |
| 3745 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3746 | // Nasty. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3747 | CharSequence oldBuilderContentTitle = |
| 3748 | mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3749 | if (mBigContentTitle != null) { |
| 3750 | mBuilder.setContentTitle(mBigContentTitle); |
| 3751 | } |
| 3752 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3753 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 3754 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3755 | mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3756 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3757 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 3758 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 3759 | } else { |
| 3760 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3761 | } |
| 3762 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3763 | return contentView; |
| 3764 | } |
| 3765 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3766 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3767 | * Construct a Style-specific RemoteViews for the final 1U notification layout. |
| 3768 | * The default implementation has nothing additional to add. |
| 3769 | * @hide |
| 3770 | */ |
| 3771 | public RemoteViews makeContentView() { |
| 3772 | return null; |
| 3773 | } |
| 3774 | |
| 3775 | /** |
| 3776 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 3777 | * @hide |
| 3778 | */ |
| 3779 | public RemoteViews makeBigContentView() { |
| 3780 | return null; |
| 3781 | } |
| 3782 | |
| 3783 | /** |
| 3784 | * Construct a Style-specific RemoteViews for the final HUN layout. |
| 3785 | * @hide |
| 3786 | */ |
| 3787 | public RemoteViews makeHeadsUpContentView() { |
| 3788 | return null; |
| 3789 | } |
| 3790 | |
| 3791 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3792 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3793 | * @hide |
| 3794 | */ |
| 3795 | public void addExtras(Bundle extras) { |
| 3796 | if (mSummaryTextSet) { |
| 3797 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 3798 | } |
| 3799 | if (mBigContentTitle != null) { |
| 3800 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 3801 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 3802 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3803 | } |
| 3804 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3805 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3806 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3807 | * @hide |
| 3808 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3809 | protected void restoreFromExtras(Bundle extras) { |
| 3810 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 3811 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 3812 | mSummaryTextSet = true; |
| 3813 | } |
| 3814 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 3815 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | |
| 3820 | /** |
| 3821 | * @hide |
| 3822 | */ |
| 3823 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3824 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3825 | return wip; |
| 3826 | } |
| 3827 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 3828 | /** |
| 3829 | * @hide |
| 3830 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 3831 | public void purgeResources() {} |
| 3832 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3833 | /** |
| 3834 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 3835 | * attached to. |
| 3836 | * |
| 3837 | * @return the fully constructed Notification. |
| 3838 | */ |
| 3839 | public Notification build() { |
| 3840 | checkBuilder(); |
| 3841 | return mBuilder.build(); |
| 3842 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3843 | |
| 3844 | /** |
| 3845 | * @hide |
| 3846 | * @return true if the style positions the progress bar on the second line; false if the |
| 3847 | * style hides the progress bar |
| 3848 | */ |
| 3849 | protected boolean hasProgress() { |
| 3850 | return true; |
| 3851 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3852 | |
| 3853 | /** |
| 3854 | * @hide |
| 3855 | * @return Whether we should put the summary be put into the notification header |
| 3856 | */ |
| 3857 | public boolean hasSummaryInHeader() { |
| 3858 | return true; |
| 3859 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3860 | |
| 3861 | /** |
| 3862 | * @hide |
| 3863 | * @return Whether custom content views are displayed inline in the style |
| 3864 | */ |
| 3865 | public boolean displayCustomViewInline() { |
| 3866 | return false; |
| 3867 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3868 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3869 | |
| 3870 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3871 | * Helper class for generating large-format notifications that include a large image attachment. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3872 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3873 | * Here's how you'd set the <code>BigPictureStyle</code> on a notification: |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3874 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3875 | * Notification notif = new Notification.Builder(mContext) |
| 3876 | * .setContentTitle("New photo from " + sender.toString()) |
| 3877 | * .setContentText(subject) |
| 3878 | * .setSmallIcon(R.drawable.new_post) |
| 3879 | * .setLargeIcon(aBitmap) |
| 3880 | * .setStyle(new Notification.BigPictureStyle() |
| 3881 | * .bigPicture(aBigBitmap)) |
| 3882 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3883 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3884 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3885 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3886 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3887 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3888 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3889 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3890 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3891 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3892 | public BigPictureStyle() { |
| 3893 | } |
| 3894 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3895 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3896 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3897 | } |
| 3898 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3899 | /** |
| 3900 | * Overrides ContentTitle in the big form of the template. |
| 3901 | * This defaults to the value passed to setContentTitle(). |
| 3902 | */ |
| 3903 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3904 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3905 | return this; |
| 3906 | } |
| 3907 | |
| 3908 | /** |
| 3909 | * Set the first line of text after the detail section in the big form of the template. |
| 3910 | */ |
| 3911 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3912 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3913 | return this; |
| 3914 | } |
| 3915 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 3916 | /** |
| 3917 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 3918 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3919 | public BigPictureStyle bigPicture(Bitmap b) { |
| 3920 | mPicture = b; |
| 3921 | return this; |
| 3922 | } |
| 3923 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3924 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3925 | * Override the large icon when the big notification is shown. |
| 3926 | */ |
| 3927 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3928 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3929 | } |
| 3930 | |
| 3931 | /** |
| 3932 | * Override the large icon when the big notification is shown. |
| 3933 | */ |
| 3934 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3935 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3936 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3937 | return this; |
| 3938 | } |
| 3939 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 3940 | /** @hide */ |
| 3941 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 3942 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 3943 | /** |
| 3944 | * @hide |
| 3945 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 3946 | @Override |
| 3947 | public void purgeResources() { |
| 3948 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 3949 | if (mPicture != null && |
| 3950 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 3951 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 3952 | mPicture = mPicture.createAshmemBitmap(); |
| 3953 | } |
| 3954 | if (mBigLargeIcon != null) { |
| 3955 | mBigLargeIcon.convertToAshmem(); |
| 3956 | } |
| 3957 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3958 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3959 | /** |
| 3960 | * @hide |
| 3961 | */ |
| 3962 | public RemoteViews makeBigContentView() { |
| 3963 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3964 | // This covers the following cases: |
| 3965 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3966 | // mN.mLargeIcon |
| 3967 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3968 | Icon oldLargeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3969 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3970 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 3971 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3972 | } |
| 3973 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3974 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3975 | if (mSummaryTextSet) { |
| 3976 | contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(mSummaryText)); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3977 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3978 | } |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3979 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.mLargeIcon != null); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 3980 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3981 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3982 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3983 | } |
| 3984 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3985 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3986 | return contentView; |
| 3987 | } |
| 3988 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3989 | /** |
| 3990 | * @hide |
| 3991 | */ |
| 3992 | public void addExtras(Bundle extras) { |
| 3993 | super.addExtras(extras); |
| 3994 | |
| 3995 | if (mBigLargeIconSet) { |
| 3996 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 3997 | } |
| 3998 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 3999 | } |
| 4000 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4001 | /** |
| 4002 | * @hide |
| 4003 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4004 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4005 | protected void restoreFromExtras(Bundle extras) { |
| 4006 | super.restoreFromExtras(extras); |
| 4007 | |
| 4008 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 4009 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4010 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 4011 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4012 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 4013 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4014 | |
| 4015 | /** |
| 4016 | * @hide |
| 4017 | */ |
| 4018 | @Override |
| 4019 | public boolean hasSummaryInHeader() { |
| 4020 | return false; |
| 4021 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 4025 | * Helper class for generating large-format notifications that include a lot of text. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4026 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4027 | * Here's how you'd set the <code>BigTextStyle</code> on a notification: |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4028 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4029 | * Notification notif = new Notification.Builder(mContext) |
| 4030 | * .setContentTitle("New mail from " + sender.toString()) |
| 4031 | * .setContentText(subject) |
| 4032 | * .setSmallIcon(R.drawable.new_mail) |
| 4033 | * .setLargeIcon(aBitmap) |
| 4034 | * .setStyle(new Notification.BigTextStyle() |
| 4035 | * .bigText(aVeryLongString)) |
| 4036 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4037 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4038 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 4039 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4040 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4041 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4042 | |
| 4043 | private static final int MAX_LINES = 13; |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 4044 | private static final int LINES_CONSUMED_BY_ACTIONS = 4; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4045 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4046 | private CharSequence mBigText; |
| 4047 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4048 | public BigTextStyle() { |
| 4049 | } |
| 4050 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4051 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4052 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4053 | } |
| 4054 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4055 | /** |
| 4056 | * Overrides ContentTitle in the big form of the template. |
| 4057 | * This defaults to the value passed to setContentTitle(). |
| 4058 | */ |
| 4059 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4060 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4061 | return this; |
| 4062 | } |
| 4063 | |
| 4064 | /** |
| 4065 | * Set the first line of text after the detail section in the big form of the template. |
| 4066 | */ |
| 4067 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4068 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4069 | return this; |
| 4070 | } |
| 4071 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 4072 | /** |
| 4073 | * Provide the longer text to be displayed in the big form of the |
| 4074 | * template in place of the content text. |
| 4075 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4076 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4077 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4078 | return this; |
| 4079 | } |
| 4080 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4081 | /** |
| 4082 | * @hide |
| 4083 | */ |
| 4084 | public void addExtras(Bundle extras) { |
| 4085 | super.addExtras(extras); |
| 4086 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4087 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 4088 | } |
| 4089 | |
| 4090 | /** |
| 4091 | * @hide |
| 4092 | */ |
| 4093 | @Override |
| 4094 | protected void restoreFromExtras(Bundle extras) { |
| 4095 | super.restoreFromExtras(extras); |
| 4096 | |
| 4097 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4098 | } |
| 4099 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4100 | /** |
| 4101 | * @hide |
| 4102 | */ |
| 4103 | public RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4104 | |
| 4105 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4106 | CharSequence oldBuilderContentText = |
| 4107 | mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT); |
| 4108 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 4109 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4110 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4111 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4112 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4113 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 4114 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
| 4115 | contentView.setTextViewText(R.id.big_text, bigTextText); |
| 4116 | contentView.setViewVisibility(R.id.big_text, |
| 4117 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4118 | contentView.setInt(R.id.big_text, "setMaxLines", calculateMaxLines()); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 4119 | contentView.setBoolean(R.id.big_text, "setHasImage", mBuilder.mN.mLargeIcon != null); |
| 4120 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4121 | return contentView; |
| 4122 | } |
| 4123 | |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4124 | private int calculateMaxLines() { |
| 4125 | int lineCount = MAX_LINES; |
| 4126 | boolean hasActions = mBuilder.mActions.size() > 0; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4127 | if (hasActions) { |
| 4128 | lineCount -= LINES_CONSUMED_BY_ACTIONS; |
| 4129 | } |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4130 | return lineCount; |
| 4131 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4132 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4133 | |
| 4134 | /** |
| 4135 | * Helper class for generating large-format notifications that include a list of (up to 5) strings. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4136 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4137 | * Here's how you'd set the <code>InboxStyle</code> on a notification: |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4138 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4139 | * Notification notif = new Notification.Builder(mContext) |
| 4140 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 4141 | * .setContentText(subject) |
| 4142 | * .setSmallIcon(R.drawable.new_mail) |
| 4143 | * .setLargeIcon(aBitmap) |
| 4144 | * .setStyle(new Notification.InboxStyle() |
| 4145 | * .addLine(str1) |
| 4146 | * .addLine(str2) |
| 4147 | * .setContentTitle("") |
| 4148 | * .setSummaryText("+3 more")) |
| 4149 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4150 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4151 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4152 | * @see Notification#bigContentView |
| 4153 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4154 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4155 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 4156 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4157 | public InboxStyle() { |
| 4158 | } |
| 4159 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4160 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4161 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4162 | } |
| 4163 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4164 | /** |
| 4165 | * Overrides ContentTitle in the big form of the template. |
| 4166 | * This defaults to the value passed to setContentTitle(). |
| 4167 | */ |
| 4168 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4169 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4170 | return this; |
| 4171 | } |
| 4172 | |
| 4173 | /** |
| 4174 | * Set the first line of text after the detail section in the big form of the template. |
| 4175 | */ |
| 4176 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4177 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4178 | return this; |
| 4179 | } |
| 4180 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 4181 | /** |
| 4182 | * Append a line to the digest section of the Inbox notification. |
| 4183 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4184 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4185 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4186 | return this; |
| 4187 | } |
| 4188 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4189 | /** |
| 4190 | * @hide |
| 4191 | */ |
| 4192 | public void addExtras(Bundle extras) { |
| 4193 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4194 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4195 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 4196 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 4197 | } |
| 4198 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4199 | /** |
| 4200 | * @hide |
| 4201 | */ |
| 4202 | @Override |
| 4203 | protected void restoreFromExtras(Bundle extras) { |
| 4204 | super.restoreFromExtras(extras); |
| 4205 | |
| 4206 | mTexts.clear(); |
| 4207 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 4208 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 4209 | } |
| 4210 | } |
| 4211 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4212 | /** |
| 4213 | * @hide |
| 4214 | */ |
| 4215 | public RemoteViews makeBigContentView() { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4216 | // Remove the content text so it disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4217 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4218 | CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT); |
| 4219 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4220 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4221 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource()); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 4222 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4223 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4224 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4225 | int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3, |
Chris Wren | 29bb6d9 | 2012-05-17 18:09:42 -0400 | [diff] [blame] | 4226 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4227 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 4228 | // Make sure all rows are gone in case we reuse a view. |
| 4229 | for (int rowId : rowIds) { |
| 4230 | contentView.setViewVisibility(rowId, View.GONE); |
| 4231 | } |
| 4232 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4233 | final boolean largeText = |
| 4234 | mBuilder.mContext.getResources().getConfiguration().fontScale > 1f; |
| 4235 | final float subTextSize = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4236 | R.dimen.notification_subtext_size); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4237 | int i=0; |
Selim Cinek | 9d9fc6e | 2015-11-12 15:49:14 -0500 | [diff] [blame] | 4238 | final float density = mBuilder.mContext.getResources().getDisplayMetrics().density; |
| 4239 | int topPadding = (int) (5 * density); |
Selim Cinek | c0fac72 | 2016-03-07 19:57:06 -0800 | [diff] [blame] | 4240 | int bottomPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4241 | com.android.internal.R.dimen.notification_content_margin_bottom); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4242 | boolean first = true; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4243 | while (i < mTexts.size() && i < rowIds.length) { |
| 4244 | CharSequence str = mTexts.get(i); |
| 4245 | if (str != null && !str.equals("")) { |
| 4246 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4247 | contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4248 | if (largeText) { |
| 4249 | contentView.setTextViewTextSize(rowIds[i], TypedValue.COMPLEX_UNIT_PX, |
| 4250 | subTextSize); |
| 4251 | } |
Selim Cinek | 9d9fc6e | 2015-11-12 15:49:14 -0500 | [diff] [blame] | 4252 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, |
| 4253 | i == rowIds.length - 1 || i == mTexts.size() - 1 ? bottomPadding : 0); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4254 | handleInboxImageMargin(contentView, rowIds[i], first); |
| 4255 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4256 | } |
| 4257 | i++; |
| 4258 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4259 | |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4260 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4261 | return contentView; |
| 4262 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4263 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4264 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4265 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4266 | if (first) { |
| 4267 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4268 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 4269 | boolean hasProgress = max != 0 || ind; |
| 4270 | if (mBuilder.mN.mLargeIcon != null && !hasProgress) { |
| 4271 | endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4272 | R.dimen.notification_content_picture_margin); |
| 4273 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4274 | } |
| 4275 | contentView.setViewLayoutMarginEnd(id, endMargin); |
| 4276 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4277 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4278 | |
| 4279 | /** |
| 4280 | * Notification style for media playback notifications. |
| 4281 | * |
| 4282 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 4283 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4284 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4285 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 4286 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 4287 | * treated as album artwork. |
| 4288 | * |
| 4289 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 4290 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 4291 | * {@link #setShowActionsInCompactView(int...)} you can promote up to 3 actions to be displayed |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4292 | * in the standard view alongside the usual content. |
| 4293 | * |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4294 | * Notifications created with MediaStyle will have their category set to |
| 4295 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 4296 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
| 4297 | * |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4298 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 4299 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4300 | * the System UI can identify this as a notification representing an active media session |
| 4301 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 4302 | * |
| 4303 | * To use this style with your Notification, feed it to |
| 4304 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 4305 | * <pre class="prettyprint"> |
| 4306 | * Notification noti = new Notification.Builder() |
| 4307 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 4308 | * .setContentTitle("Track title") |
| 4309 | * .setContentText("Artist - Album") |
| 4310 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4311 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 4312 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4313 | * .build(); |
| 4314 | * </pre> |
| 4315 | * |
| 4316 | * @see Notification#bigContentView |
| 4317 | */ |
| 4318 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4319 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4320 | static final int MAX_MEDIA_BUTTONS = 5; |
| 4321 | |
| 4322 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4323 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4324 | |
| 4325 | public MediaStyle() { |
| 4326 | } |
| 4327 | |
| 4328 | public MediaStyle(Builder builder) { |
| 4329 | setBuilder(builder); |
| 4330 | } |
| 4331 | |
| 4332 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4333 | * Request up to 3 actions (by index in the order of addition) to be shown in the compact |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4334 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4335 | * |
| 4336 | * @param actions the indices of the actions to show in the compact notification view |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4337 | */ |
| 4338 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 4339 | mActionsToShowInCompact = actions; |
| 4340 | return this; |
| 4341 | } |
| 4342 | |
| 4343 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4344 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 4345 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4346 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4347 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4348 | mToken = token; |
| 4349 | return this; |
| 4350 | } |
| 4351 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4352 | /** |
| 4353 | * @hide |
| 4354 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4355 | @Override |
| 4356 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4357 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4358 | if (wip.category == null) { |
| 4359 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 4360 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4361 | return wip; |
| 4362 | } |
| 4363 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4364 | /** |
| 4365 | * @hide |
| 4366 | */ |
| 4367 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4368 | public RemoteViews makeContentView() { |
| 4369 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | /** |
| 4373 | * @hide |
| 4374 | */ |
| 4375 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4376 | public RemoteViews makeBigContentView() { |
| 4377 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4378 | } |
| 4379 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4380 | /** |
| 4381 | * @hide |
| 4382 | */ |
| 4383 | @Override |
| 4384 | public RemoteViews makeHeadsUpContentView() { |
| 4385 | RemoteViews expanded = makeMediaBigContentView(); |
| 4386 | return expanded != null ? expanded : makeMediaContentView(); |
| 4387 | } |
| 4388 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4389 | /** @hide */ |
| 4390 | @Override |
| 4391 | public void addExtras(Bundle extras) { |
| 4392 | super.addExtras(extras); |
| 4393 | |
| 4394 | if (mToken != null) { |
| 4395 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 4396 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 4397 | if (mActionsToShowInCompact != null) { |
| 4398 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 4399 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4400 | } |
| 4401 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4402 | /** |
| 4403 | * @hide |
| 4404 | */ |
| 4405 | @Override |
| 4406 | protected void restoreFromExtras(Bundle extras) { |
| 4407 | super.restoreFromExtras(extras); |
| 4408 | |
| 4409 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 4410 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 4411 | } |
| 4412 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 4413 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 4414 | } |
| 4415 | } |
| 4416 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4417 | private RemoteViews generateMediaActionButton(Action action, int color) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4418 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 4419 | RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4420 | R.layout.notification_material_media_action); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 4421 | button.setImageViewIcon(R.id.action0, action.getIcon()); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4422 | button.setDrawableParameters(R.id.action0, false, -1, color, PorterDuff.Mode.SRC_ATOP, |
| 4423 | -1); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4424 | if (!tombstone) { |
| 4425 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 4426 | } |
| 4427 | button.setContentDescription(R.id.action0, action.title); |
| 4428 | return button; |
| 4429 | } |
| 4430 | |
| 4431 | private RemoteViews makeMediaContentView() { |
| 4432 | RemoteViews view = mBuilder.applyStandardTemplate( |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4433 | R.layout.notification_template_material_media, false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4434 | |
| 4435 | final int numActions = mBuilder.mActions.size(); |
| 4436 | final int N = mActionsToShowInCompact == null |
| 4437 | ? 0 |
| 4438 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 4439 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4440 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4441 | for (int i = 0; i < N; i++) { |
| 4442 | if (i >= numActions) { |
| 4443 | throw new IllegalArgumentException(String.format( |
| 4444 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 4445 | i, numActions - 1)); |
| 4446 | } |
| 4447 | |
| 4448 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4449 | final RemoteViews button = generateMediaActionButton(action, |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4450 | mBuilder.resolveContrastColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4451 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4452 | } |
| 4453 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 4454 | handleImage(view); |
| 4455 | // handle the content margin |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4456 | int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4457 | R.dimen.notification_content_margin_end);; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 4458 | if (mBuilder.mN.mLargeIcon != null) { |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4459 | endMargin += mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4460 | R.dimen.notification_content_picture_margin); |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 4461 | } |
| 4462 | view.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4463 | return view; |
| 4464 | } |
| 4465 | |
| 4466 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4467 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4468 | // Dont add an expanded view if there is no more content to be revealed |
| 4469 | int actionsInCompact = mActionsToShowInCompact == null |
| 4470 | ? 0 |
| 4471 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 4472 | if (mBuilder.mN.mLargeIcon == null && actionCount <= actionsInCompact) { |
| 4473 | return null; |
| 4474 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4475 | RemoteViews big = mBuilder.applyStandardTemplate( |
| 4476 | R.layout.notification_template_material_big_media, |
| 4477 | false); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4478 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4479 | if (actionCount > 0) { |
| 4480 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 4481 | for (int i = 0; i < actionCount; i++) { |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4482 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i), |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4483 | mBuilder.resolveContrastColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4484 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4485 | } |
| 4486 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4487 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4488 | return big; |
| 4489 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4490 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4491 | private void handleImage(RemoteViews contentView) { |
| 4492 | if (mBuilder.mN.mLargeIcon != null) { |
| 4493 | contentView.setViewLayoutMarginEnd(R.id.line1, 0); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4494 | contentView.setViewLayoutMarginEnd(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4495 | } |
| 4496 | } |
| 4497 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4498 | /** |
| 4499 | * @hide |
| 4500 | */ |
| 4501 | @Override |
| 4502 | protected boolean hasProgress() { |
| 4503 | return false; |
| 4504 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4505 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4506 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4507 | /** |
| 4508 | * Notification style for custom views that are decorated by the system |
| 4509 | * |
| 4510 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 4511 | * style and still obtain system decorations like the notification header with the expand |
| 4512 | * affordance and actions. |
| 4513 | * |
| 4514 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 4515 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 4516 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 4517 | * corresponding custom views to display. |
| 4518 | * |
| 4519 | * To use this style with your Notification, feed it to |
| 4520 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 4521 | * <pre class="prettyprint"> |
| 4522 | * Notification noti = new Notification.Builder() |
| 4523 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 4524 | * .setLargeIcon(albumArtBitmap)) |
| 4525 | * .setCustomContentView(contentView); |
| 4526 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 4527 | * .build(); |
| 4528 | * </pre> |
| 4529 | */ |
| 4530 | public static class DecoratedCustomViewStyle extends Style { |
| 4531 | |
| 4532 | public DecoratedCustomViewStyle() { |
| 4533 | } |
| 4534 | |
| 4535 | public DecoratedCustomViewStyle(Builder builder) { |
| 4536 | setBuilder(builder); |
| 4537 | } |
| 4538 | |
| 4539 | /** |
| 4540 | * @hide |
| 4541 | */ |
| 4542 | public boolean displayCustomViewInline() { |
| 4543 | return true; |
| 4544 | } |
| 4545 | |
| 4546 | /** |
| 4547 | * @hide |
| 4548 | */ |
| 4549 | @Override |
| 4550 | public RemoteViews makeContentView() { |
| 4551 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 4552 | } |
| 4553 | |
| 4554 | /** |
| 4555 | * @hide |
| 4556 | */ |
| 4557 | @Override |
| 4558 | public RemoteViews makeBigContentView() { |
| 4559 | return makeDecoratedBigContentView(); |
| 4560 | } |
| 4561 | |
| 4562 | /** |
| 4563 | * @hide |
| 4564 | */ |
| 4565 | @Override |
| 4566 | public RemoteViews makeHeadsUpContentView() { |
| 4567 | return makeDecoratedHeadsUpContentView(); |
| 4568 | } |
| 4569 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4570 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 4571 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 4572 | ? mBuilder.mN.contentView |
| 4573 | : mBuilder.mN.headsUpContentView; |
| 4574 | if (mBuilder.mActions.size() == 0) { |
| 4575 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 4576 | } |
| 4577 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 4578 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4579 | buildIntoRemoteViewContent(remoteViews, headsUpContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4580 | return remoteViews; |
| 4581 | } |
| 4582 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4583 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
| 4584 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
| 4585 | mBuilder.getBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4586 | buildIntoRemoteViewContent(remoteViews, customContent); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4587 | return remoteViews; |
| 4588 | } |
| 4589 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4590 | private RemoteViews makeDecoratedBigContentView() { |
| 4591 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 4592 | ? mBuilder.mN.contentView |
| 4593 | : mBuilder.mN.bigContentView; |
| 4594 | if (mBuilder.mActions.size() == 0) { |
| 4595 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 4596 | } |
| 4597 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 4598 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4599 | buildIntoRemoteViewContent(remoteViews, bigContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4600 | return remoteViews; |
| 4601 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4602 | |
| 4603 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
| 4604 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4605 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 4606 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 4607 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4608 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 4609 | remoteViews.removeAllViews(R.id.notification_main_column); |
| 4610 | remoteViews.addView(R.id.notification_main_column, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4611 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4612 | // also update the end margin if there is an image |
| 4613 | int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4614 | R.dimen.notification_content_margin_end); |
| 4615 | if (mBuilder.mN.mLargeIcon != null) { |
| 4616 | endMargin += mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4617 | R.dimen.notification_content_picture_margin); |
| 4618 | } |
| 4619 | remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
| 4620 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4621 | } |
| 4622 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 4623 | /** |
| 4624 | * Notification style for media custom views that are decorated by the system |
| 4625 | * |
| 4626 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 4627 | * this style and still obtain system decorations like the notification header with the expand |
| 4628 | * affordance and actions. |
| 4629 | * |
| 4630 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 4631 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 4632 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 4633 | * corresponding custom views to display. |
| 4634 | * |
| 4635 | * To use this style with your Notification, feed it to |
| 4636 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 4637 | * <pre class="prettyprint"> |
| 4638 | * Notification noti = new Notification.Builder() |
| 4639 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 4640 | * .setLargeIcon(albumArtBitmap)) |
| 4641 | * .setCustomContentView(contentView); |
| 4642 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 4643 | * .setMediaSession(mySession)) |
| 4644 | * .build(); |
| 4645 | * </pre> |
| 4646 | * |
| 4647 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 4648 | * @see android.app.Notification.MediaStyle |
| 4649 | */ |
| 4650 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 4651 | |
| 4652 | public DecoratedMediaCustomViewStyle() { |
| 4653 | } |
| 4654 | |
| 4655 | public DecoratedMediaCustomViewStyle(Builder builder) { |
| 4656 | setBuilder(builder); |
| 4657 | } |
| 4658 | |
| 4659 | /** |
| 4660 | * @hide |
| 4661 | */ |
| 4662 | public boolean displayCustomViewInline() { |
| 4663 | return true; |
| 4664 | } |
| 4665 | |
| 4666 | /** |
| 4667 | * @hide |
| 4668 | */ |
| 4669 | @Override |
| 4670 | public RemoteViews makeContentView() { |
| 4671 | RemoteViews remoteViews = super.makeContentView(); |
| 4672 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 4673 | mBuilder.mN.contentView); |
| 4674 | } |
| 4675 | |
| 4676 | /** |
| 4677 | * @hide |
| 4678 | */ |
| 4679 | @Override |
| 4680 | public RemoteViews makeBigContentView() { |
| 4681 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 4682 | ? mBuilder.mN.bigContentView |
| 4683 | : mBuilder.mN.contentView; |
| 4684 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 4685 | } |
| 4686 | |
| 4687 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 4688 | RemoteViews remoteViews = super.makeBigContentView(); |
| 4689 | if (remoteViews != null) { |
| 4690 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 4691 | customRemoteView); |
| 4692 | } else if (customRemoteView != mBuilder.mN.contentView){ |
| 4693 | remoteViews = super.makeContentView(); |
| 4694 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 4695 | customRemoteView); |
| 4696 | } else { |
| 4697 | return null; |
| 4698 | } |
| 4699 | } |
| 4700 | |
| 4701 | /** |
| 4702 | * @hide |
| 4703 | */ |
| 4704 | @Override |
| 4705 | public RemoteViews makeHeadsUpContentView() { |
| 4706 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 4707 | ? mBuilder.mN.headsUpContentView |
| 4708 | : mBuilder.mN.contentView; |
| 4709 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 4710 | } |
| 4711 | |
| 4712 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 4713 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4714 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 4715 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 4716 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4717 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 4718 | remoteViews.removeAllViews(id); |
| 4719 | remoteViews.addView(id, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4720 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 4721 | return remoteViews; |
| 4722 | } |
| 4723 | } |
| 4724 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4725 | // When adding a new Style subclass here, don't forget to update |
| 4726 | // Builder.getNotificationStyleClass. |
| 4727 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4728 | /** |
| 4729 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 4730 | * metadata or change options on a notification builder. |
| 4731 | */ |
| 4732 | public interface Extender { |
| 4733 | /** |
| 4734 | * Apply this extender to a notification builder. |
| 4735 | * @param builder the builder to be modified. |
| 4736 | * @return the build object for chaining. |
| 4737 | */ |
| 4738 | public Builder extend(Builder builder); |
| 4739 | } |
| 4740 | |
| 4741 | /** |
| 4742 | * Helper class to add wearable extensions to notifications. |
| 4743 | * <p class="note"> See |
| 4744 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 4745 | * for Android Wear</a> for more information on how to use this class. |
| 4746 | * <p> |
| 4747 | * To create a notification with wearable extensions: |
| 4748 | * <ol> |
| 4749 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 4750 | * properties. |
| 4751 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 4752 | * <li>Set wearable-specific properties using the |
| 4753 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 4754 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 4755 | * notification. |
| 4756 | * <li>Post the notification to the notification system with the |
| 4757 | * {@code NotificationManager.notify(...)} methods. |
| 4758 | * </ol> |
| 4759 | * |
| 4760 | * <pre class="prettyprint"> |
| 4761 | * Notification notif = new Notification.Builder(mContext) |
| 4762 | * .setContentTitle("New mail from " + sender.toString()) |
| 4763 | * .setContentText(subject) |
| 4764 | * .setSmallIcon(R.drawable.new_mail) |
| 4765 | * .extend(new Notification.WearableExtender() |
| 4766 | * .setContentIcon(R.drawable.new_mail)) |
| 4767 | * .build(); |
| 4768 | * NotificationManager notificationManger = |
| 4769 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 4770 | * notificationManger.notify(0, notif);</pre> |
| 4771 | * |
| 4772 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 4773 | * {@code WearableExtender(Notification)} constructor, |
| 4774 | * and then using the {@code get} methods to access values. |
| 4775 | * |
| 4776 | * <pre class="prettyprint"> |
| 4777 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 4778 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 4779 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4780 | */ |
| 4781 | public static final class WearableExtender implements Extender { |
| 4782 | /** |
| 4783 | * Sentinel value for an action index that is unset. |
| 4784 | */ |
| 4785 | public static final int UNSET_ACTION_INDEX = -1; |
| 4786 | |
| 4787 | /** |
| 4788 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 4789 | * default sizing. |
| 4790 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 4791 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4792 | * on their content. |
| 4793 | */ |
| 4794 | public static final int SIZE_DEFAULT = 0; |
| 4795 | |
| 4796 | /** |
| 4797 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4798 | * with an extra small size. |
| 4799 | * <p>This value is only applicable for custom display notifications created using |
| 4800 | * {@link #setDisplayIntent}. |
| 4801 | */ |
| 4802 | public static final int SIZE_XSMALL = 1; |
| 4803 | |
| 4804 | /** |
| 4805 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4806 | * with a small size. |
| 4807 | * <p>This value is only applicable for custom display notifications created using |
| 4808 | * {@link #setDisplayIntent}. |
| 4809 | */ |
| 4810 | public static final int SIZE_SMALL = 2; |
| 4811 | |
| 4812 | /** |
| 4813 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4814 | * with a medium size. |
| 4815 | * <p>This value is only applicable for custom display notifications created using |
| 4816 | * {@link #setDisplayIntent}. |
| 4817 | */ |
| 4818 | public static final int SIZE_MEDIUM = 3; |
| 4819 | |
| 4820 | /** |
| 4821 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4822 | * with a large size. |
| 4823 | * <p>This value is only applicable for custom display notifications created using |
| 4824 | * {@link #setDisplayIntent}. |
| 4825 | */ |
| 4826 | public static final int SIZE_LARGE = 4; |
| 4827 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 4828 | /** |
| 4829 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4830 | * full screen. |
| 4831 | * <p>This value is only applicable for custom display notifications created using |
| 4832 | * {@link #setDisplayIntent}. |
| 4833 | */ |
| 4834 | public static final int SIZE_FULL_SCREEN = 5; |
| 4835 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4836 | /** |
| 4837 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 4838 | * short amount of time when this notification is displayed on the screen. This |
| 4839 | * is the default value. |
| 4840 | */ |
| 4841 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 4842 | |
| 4843 | /** |
| 4844 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 4845 | * for a longer amount of time when this notification is displayed on the screen. |
| 4846 | */ |
| 4847 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 4848 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4849 | /** Notification extra which contains wearable extensions */ |
| 4850 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 4851 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 4852 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4853 | private static final String KEY_ACTIONS = "actions"; |
| 4854 | private static final String KEY_FLAGS = "flags"; |
| 4855 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 4856 | private static final String KEY_PAGES = "pages"; |
| 4857 | private static final String KEY_BACKGROUND = "background"; |
| 4858 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 4859 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 4860 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 4861 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 4862 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 4863 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4864 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4865 | |
| 4866 | // Flags bitwise-ored to mFlags |
| 4867 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 4868 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 4869 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 4870 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4871 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4872 | |
| 4873 | // Default value for flags integer |
| 4874 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 4875 | |
| 4876 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 4877 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 4878 | |
| 4879 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 4880 | private int mFlags = DEFAULT_FLAGS; |
| 4881 | private PendingIntent mDisplayIntent; |
| 4882 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 4883 | private Bitmap mBackground; |
| 4884 | private int mContentIcon; |
| 4885 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 4886 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 4887 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 4888 | private int mCustomContentHeight; |
| 4889 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4890 | private int mHintScreenTimeout; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4891 | |
| 4892 | /** |
| 4893 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 4894 | * options. |
| 4895 | */ |
| 4896 | public WearableExtender() { |
| 4897 | } |
| 4898 | |
| 4899 | public WearableExtender(Notification notif) { |
| 4900 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 4901 | if (wearableBundle != null) { |
| 4902 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 4903 | if (actions != null) { |
| 4904 | mActions.addAll(actions); |
| 4905 | } |
| 4906 | |
| 4907 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 4908 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 4909 | |
| 4910 | Notification[] pages = getNotificationArrayFromBundle( |
| 4911 | wearableBundle, KEY_PAGES); |
| 4912 | if (pages != null) { |
| 4913 | Collections.addAll(mPages, pages); |
| 4914 | } |
| 4915 | |
| 4916 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 4917 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 4918 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 4919 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 4920 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 4921 | UNSET_ACTION_INDEX); |
| 4922 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 4923 | SIZE_DEFAULT); |
| 4924 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 4925 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4926 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4927 | } |
| 4928 | } |
| 4929 | |
| 4930 | /** |
| 4931 | * Apply wearable extensions to a notification that is being built. This is typically |
| 4932 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 4933 | * {@link android.app.Notification.Builder}. |
| 4934 | */ |
| 4935 | @Override |
| 4936 | public Notification.Builder extend(Notification.Builder builder) { |
| 4937 | Bundle wearableBundle = new Bundle(); |
| 4938 | |
| 4939 | if (!mActions.isEmpty()) { |
| 4940 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 4941 | } |
| 4942 | if (mFlags != DEFAULT_FLAGS) { |
| 4943 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 4944 | } |
| 4945 | if (mDisplayIntent != null) { |
| 4946 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 4947 | } |
| 4948 | if (!mPages.isEmpty()) { |
| 4949 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 4950 | new Notification[mPages.size()])); |
| 4951 | } |
| 4952 | if (mBackground != null) { |
| 4953 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 4954 | } |
| 4955 | if (mContentIcon != 0) { |
| 4956 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 4957 | } |
| 4958 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 4959 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 4960 | } |
| 4961 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 4962 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 4963 | mContentActionIndex); |
| 4964 | } |
| 4965 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 4966 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 4967 | } |
| 4968 | if (mCustomContentHeight != 0) { |
| 4969 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 4970 | } |
| 4971 | if (mGravity != DEFAULT_GRAVITY) { |
| 4972 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 4973 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4974 | if (mHintScreenTimeout != 0) { |
| 4975 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 4976 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4977 | |
| 4978 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 4979 | return builder; |
| 4980 | } |
| 4981 | |
| 4982 | @Override |
| 4983 | public WearableExtender clone() { |
| 4984 | WearableExtender that = new WearableExtender(); |
| 4985 | that.mActions = new ArrayList<Action>(this.mActions); |
| 4986 | that.mFlags = this.mFlags; |
| 4987 | that.mDisplayIntent = this.mDisplayIntent; |
| 4988 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 4989 | that.mBackground = this.mBackground; |
| 4990 | that.mContentIcon = this.mContentIcon; |
| 4991 | that.mContentIconGravity = this.mContentIconGravity; |
| 4992 | that.mContentActionIndex = this.mContentActionIndex; |
| 4993 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 4994 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 4995 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4996 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4997 | return that; |
| 4998 | } |
| 4999 | |
| 5000 | /** |
| 5001 | * Add a wearable action to this notification. |
| 5002 | * |
| 5003 | * <p>When wearable actions are added using this method, the set of actions that |
| 5004 | * show on a wearable device splits from devices that only show actions added |
| 5005 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 5006 | * of which actions display on different devices. |
| 5007 | * |
| 5008 | * @param action the action to add to this notification |
| 5009 | * @return this object for method chaining |
| 5010 | * @see android.app.Notification.Action |
| 5011 | */ |
| 5012 | public WearableExtender addAction(Action action) { |
| 5013 | mActions.add(action); |
| 5014 | return this; |
| 5015 | } |
| 5016 | |
| 5017 | /** |
| 5018 | * Adds wearable actions to this notification. |
| 5019 | * |
| 5020 | * <p>When wearable actions are added using this method, the set of actions that |
| 5021 | * show on a wearable device splits from devices that only show actions added |
| 5022 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 5023 | * of which actions display on different devices. |
| 5024 | * |
| 5025 | * @param actions the actions to add to this notification |
| 5026 | * @return this object for method chaining |
| 5027 | * @see android.app.Notification.Action |
| 5028 | */ |
| 5029 | public WearableExtender addActions(List<Action> actions) { |
| 5030 | mActions.addAll(actions); |
| 5031 | return this; |
| 5032 | } |
| 5033 | |
| 5034 | /** |
| 5035 | * Clear all wearable actions present on this builder. |
| 5036 | * @return this object for method chaining. |
| 5037 | * @see #addAction |
| 5038 | */ |
| 5039 | public WearableExtender clearActions() { |
| 5040 | mActions.clear(); |
| 5041 | return this; |
| 5042 | } |
| 5043 | |
| 5044 | /** |
| 5045 | * Get the wearable actions present on this notification. |
| 5046 | */ |
| 5047 | public List<Action> getActions() { |
| 5048 | return mActions; |
| 5049 | } |
| 5050 | |
| 5051 | /** |
| 5052 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5053 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 5054 | * |
| 5055 | * <pre class="prettyprint"> |
| 5056 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 5057 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 5058 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 5059 | * Notification notif = new Notification.Builder(context) |
| 5060 | * .extend(new Notification.WearableExtender() |
| 5061 | * .setDisplayIntent(displayPendingIntent) |
| 5062 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 5063 | * .build();</pre> |
| 5064 | * |
| 5065 | * <p>The activity to launch needs to allow embedding, must be exported, and |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 5066 | * should have an empty task affinity. It is also recommended to use the device |
| 5067 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5068 | * |
| 5069 | * <p>Example AndroidManifest.xml entry: |
| 5070 | * <pre class="prettyprint"> |
| 5071 | * <activity android:name="com.example.MyDisplayActivity" |
| 5072 | * android:exported="true" |
| 5073 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 5074 | * android:taskAffinity="" |
| 5075 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5076 | * |
| 5077 | * @param intent the {@link PendingIntent} for an activity |
| 5078 | * @return this object for method chaining |
| 5079 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 5080 | */ |
| 5081 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 5082 | mDisplayIntent = intent; |
| 5083 | return this; |
| 5084 | } |
| 5085 | |
| 5086 | /** |
| 5087 | * Get the intent to launch inside of an activity view when displaying this |
| 5088 | * notification. This {@code PendingIntent} should be for an activity. |
| 5089 | */ |
| 5090 | public PendingIntent getDisplayIntent() { |
| 5091 | return mDisplayIntent; |
| 5092 | } |
| 5093 | |
| 5094 | /** |
| 5095 | * Add an additional page 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 page the notification to add as another page |
| 5101 | * @return this object for method chaining |
| 5102 | * @see android.app.Notification.WearableExtender#getPages |
| 5103 | */ |
| 5104 | public WearableExtender addPage(Notification page) { |
| 5105 | mPages.add(page); |
| 5106 | return this; |
| 5107 | } |
| 5108 | |
| 5109 | /** |
| 5110 | * Add additional pages of content to display with this notification. The current |
| 5111 | * notification forms the first page, and pages added using this function form |
| 5112 | * subsequent pages. This field can be used to separate a notification into multiple |
| 5113 | * sections. |
| 5114 | * |
| 5115 | * @param pages a list of notifications |
| 5116 | * @return this object for method chaining |
| 5117 | * @see android.app.Notification.WearableExtender#getPages |
| 5118 | */ |
| 5119 | public WearableExtender addPages(List<Notification> pages) { |
| 5120 | mPages.addAll(pages); |
| 5121 | return this; |
| 5122 | } |
| 5123 | |
| 5124 | /** |
| 5125 | * Clear all additional pages present on this builder. |
| 5126 | * @return this object for method chaining. |
| 5127 | * @see #addPage |
| 5128 | */ |
| 5129 | public WearableExtender clearPages() { |
| 5130 | mPages.clear(); |
| 5131 | return this; |
| 5132 | } |
| 5133 | |
| 5134 | /** |
| 5135 | * Get the array of additional pages of content for displaying this notification. The |
| 5136 | * current notification forms the first page, and elements within this array form |
| 5137 | * subsequent pages. This field can be used to separate a notification into multiple |
| 5138 | * sections. |
| 5139 | * @return the pages for this notification |
| 5140 | */ |
| 5141 | public List<Notification> getPages() { |
| 5142 | return mPages; |
| 5143 | } |
| 5144 | |
| 5145 | /** |
| 5146 | * Set a background image to be displayed behind the notification content. |
| 5147 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 5148 | * will work with any notification style. |
| 5149 | * |
| 5150 | * @param background the background bitmap |
| 5151 | * @return this object for method chaining |
| 5152 | * @see android.app.Notification.WearableExtender#getBackground |
| 5153 | */ |
| 5154 | public WearableExtender setBackground(Bitmap background) { |
| 5155 | mBackground = background; |
| 5156 | return this; |
| 5157 | } |
| 5158 | |
| 5159 | /** |
| 5160 | * Get a background image to be displayed behind the notification content. |
| 5161 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 5162 | * will work with any notification style. |
| 5163 | * |
| 5164 | * @return the background image |
| 5165 | * @see android.app.Notification.WearableExtender#setBackground |
| 5166 | */ |
| 5167 | public Bitmap getBackground() { |
| 5168 | return mBackground; |
| 5169 | } |
| 5170 | |
| 5171 | /** |
| 5172 | * Set an icon that goes with the content of this notification. |
| 5173 | */ |
| 5174 | public WearableExtender setContentIcon(int icon) { |
| 5175 | mContentIcon = icon; |
| 5176 | return this; |
| 5177 | } |
| 5178 | |
| 5179 | /** |
| 5180 | * Get an icon that goes with the content of this notification. |
| 5181 | */ |
| 5182 | public int getContentIcon() { |
| 5183 | return mContentIcon; |
| 5184 | } |
| 5185 | |
| 5186 | /** |
| 5187 | * Set the gravity that the content icon should have within the notification display. |
| 5188 | * Supported values include {@link android.view.Gravity#START} and |
| 5189 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 5190 | * @see #setContentIcon |
| 5191 | */ |
| 5192 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 5193 | mContentIconGravity = contentIconGravity; |
| 5194 | return this; |
| 5195 | } |
| 5196 | |
| 5197 | /** |
| 5198 | * Get the gravity that the content icon should have within the notification display. |
| 5199 | * Supported values include {@link android.view.Gravity#START} and |
| 5200 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 5201 | * @see #getContentIcon |
| 5202 | */ |
| 5203 | public int getContentIconGravity() { |
| 5204 | return mContentIconGravity; |
| 5205 | } |
| 5206 | |
| 5207 | /** |
| 5208 | * Set an action from this notification's actions to be clickable with the content of |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5209 | * this notification. This action will no longer display separately from the |
| 5210 | * notification's content. |
| 5211 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 5212 | * <p>For notifications with multiple pages, child pages can also have content actions |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5213 | * set, although the list of available actions comes from the main notification and not |
| 5214 | * from the child page's notification. |
| 5215 | * |
| 5216 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 5217 | * If wearable actions were added to the main notification, this index |
| 5218 | * will apply to that list, otherwise it will apply to the regular |
| 5219 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5220 | */ |
| 5221 | public WearableExtender setContentAction(int actionIndex) { |
| 5222 | mContentActionIndex = actionIndex; |
| 5223 | return this; |
| 5224 | } |
| 5225 | |
| 5226 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 5227 | * Get the index of the notification action, if any, that was specified as being clickable |
| 5228 | * with the content of this notification. This action will no longer display separately |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5229 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5230 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 5231 | * <p>For notifications with multiple pages, child pages can also have content actions |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5232 | * set, although the list of available actions comes from the main notification and not |
| 5233 | * from the child page's notification. |
| 5234 | * |
| 5235 | * <p>If wearable specific actions were added to the main notification, this index will |
| 5236 | * apply to that list, otherwise it will apply to the regular actions list. |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 5237 | * |
| 5238 | * @return the action index or {@link #UNSET_ACTION_INDEX} if no action was selected. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5239 | */ |
| 5240 | public int getContentAction() { |
| 5241 | return mContentActionIndex; |
| 5242 | } |
| 5243 | |
| 5244 | /** |
| 5245 | * Set the gravity that this notification should have within the available viewport space. |
| 5246 | * Supported values include {@link android.view.Gravity#TOP}, |
| 5247 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 5248 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 5249 | */ |
| 5250 | public WearableExtender setGravity(int gravity) { |
| 5251 | mGravity = gravity; |
| 5252 | return this; |
| 5253 | } |
| 5254 | |
| 5255 | /** |
| 5256 | * Get the gravity that this notification should have within the available viewport space. |
| 5257 | * Supported values include {@link android.view.Gravity#TOP}, |
| 5258 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 5259 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 5260 | */ |
| 5261 | public int getGravity() { |
| 5262 | return mGravity; |
| 5263 | } |
| 5264 | |
| 5265 | /** |
| 5266 | * Set the custom size preset for the display of this notification out of the available |
| 5267 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 5268 | * {@link #SIZE_LARGE}. |
| 5269 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 5270 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 5271 | * documentation for the preset in question. See also |
| 5272 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 5273 | */ |
| 5274 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 5275 | mCustomSizePreset = sizePreset; |
| 5276 | return this; |
| 5277 | } |
| 5278 | |
| 5279 | /** |
| 5280 | * Get the custom size preset for the display of this notification out of the available |
| 5281 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 5282 | * {@link #SIZE_LARGE}. |
| 5283 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 5284 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 5285 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 5286 | */ |
| 5287 | public int getCustomSizePreset() { |
| 5288 | return mCustomSizePreset; |
| 5289 | } |
| 5290 | |
| 5291 | /** |
| 5292 | * Set the custom height in pixels for the display of this notification's content. |
| 5293 | * <p>This option is only available for custom display notifications created |
| 5294 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 5295 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 5296 | * {@link #getCustomContentHeight}. |
| 5297 | */ |
| 5298 | public WearableExtender setCustomContentHeight(int height) { |
| 5299 | mCustomContentHeight = height; |
| 5300 | return this; |
| 5301 | } |
| 5302 | |
| 5303 | /** |
| 5304 | * Get the custom height in pixels for the display of this notification's content. |
| 5305 | * <p>This option is only available for custom display notifications created |
| 5306 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 5307 | * {@link #setCustomContentHeight}. |
| 5308 | */ |
| 5309 | public int getCustomContentHeight() { |
| 5310 | return mCustomContentHeight; |
| 5311 | } |
| 5312 | |
| 5313 | /** |
| 5314 | * Set whether the scrolling position for the contents of this notification should start |
| 5315 | * at the bottom of the contents instead of the top when the contents are too long to |
| 5316 | * display within the screen. Default is false (start scroll at the top). |
| 5317 | */ |
| 5318 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 5319 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 5320 | return this; |
| 5321 | } |
| 5322 | |
| 5323 | /** |
| 5324 | * Get whether the scrolling position for the contents of this notification should start |
| 5325 | * at the bottom of the contents instead of the top when the contents are too long to |
| 5326 | * display within the screen. Default is false (start scroll at the top). |
| 5327 | */ |
| 5328 | public boolean getStartScrollBottom() { |
| 5329 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 5330 | } |
| 5331 | |
| 5332 | /** |
| 5333 | * Set whether the content intent is available when the wearable device is not connected |
| 5334 | * to a companion device. The user can still trigger this intent when the wearable device |
| 5335 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 5336 | * Defaults to true. |
| 5337 | */ |
| 5338 | public WearableExtender setContentIntentAvailableOffline( |
| 5339 | boolean contentIntentAvailableOffline) { |
| 5340 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 5341 | return this; |
| 5342 | } |
| 5343 | |
| 5344 | /** |
| 5345 | * Get whether the content intent is available when the wearable device is not connected |
| 5346 | * to a companion device. The user can still trigger this intent when the wearable device |
| 5347 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 5348 | * Defaults to true. |
| 5349 | */ |
| 5350 | public boolean getContentIntentAvailableOffline() { |
| 5351 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 5352 | } |
| 5353 | |
| 5354 | /** |
| 5355 | * Set a hint that this notification's icon should not be displayed. |
| 5356 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 5357 | * @return this object for method chaining |
| 5358 | */ |
| 5359 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 5360 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 5361 | return this; |
| 5362 | } |
| 5363 | |
| 5364 | /** |
| 5365 | * Get a hint that this notification's icon should not be displayed. |
| 5366 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 5367 | * The default value is {@code false} if this was never set. |
| 5368 | */ |
| 5369 | public boolean getHintHideIcon() { |
| 5370 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 5371 | } |
| 5372 | |
| 5373 | /** |
| 5374 | * Set a visual hint that only the background image of this notification should be |
| 5375 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 5376 | * to sub-pages added using {@link #addPage}. |
| 5377 | */ |
| 5378 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 5379 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 5380 | return this; |
| 5381 | } |
| 5382 | |
| 5383 | /** |
| 5384 | * Get a visual hint that only the background image of this notification should be |
| 5385 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 5386 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 5387 | */ |
| 5388 | public boolean getHintShowBackgroundOnly() { |
| 5389 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 5390 | } |
| 5391 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5392 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 5393 | * Set a hint that this notification's background should not be clipped if possible, |
| 5394 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 5395 | * ratio of the image. This can be useful for images like barcodes or qr codes. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5396 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 5397 | * @return this object for method chaining |
| 5398 | */ |
| 5399 | public WearableExtender setHintAvoidBackgroundClipping( |
| 5400 | boolean hintAvoidBackgroundClipping) { |
| 5401 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 5402 | return this; |
| 5403 | } |
| 5404 | |
| 5405 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 5406 | * Get a hint that this notification's background should not be clipped if possible, |
| 5407 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 5408 | * ratio of the image. This can be useful for images like barcodes or qr codes. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5409 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 5410 | * otherwise. The default value is {@code false} if this was never set. |
| 5411 | */ |
| 5412 | public boolean getHintAvoidBackgroundClipping() { |
| 5413 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 5414 | } |
| 5415 | |
| 5416 | /** |
| 5417 | * Set a hint that the screen should remain on for at least this duration when |
| 5418 | * this notification is displayed on the screen. |
| 5419 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 5420 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 5421 | * @return this object for method chaining |
| 5422 | */ |
| 5423 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 5424 | mHintScreenTimeout = timeout; |
| 5425 | return this; |
| 5426 | } |
| 5427 | |
| 5428 | /** |
| 5429 | * Get the duration, in milliseconds, that the screen should remain on for |
| 5430 | * when this notification is displayed. |
| 5431 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 5432 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 5433 | */ |
| 5434 | public int getHintScreenTimeout() { |
| 5435 | return mHintScreenTimeout; |
| 5436 | } |
| 5437 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5438 | private void setFlag(int mask, boolean value) { |
| 5439 | if (value) { |
| 5440 | mFlags |= mask; |
| 5441 | } else { |
| 5442 | mFlags &= ~mask; |
| 5443 | } |
| 5444 | } |
| 5445 | } |
| 5446 | |
| 5447 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5448 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 5449 | * with car extensions: |
| 5450 | * |
| 5451 | * <ol> |
| 5452 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 5453 | * properties. |
| 5454 | * <li>Create a {@link CarExtender}. |
| 5455 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 5456 | * {@link CarExtender}. |
| 5457 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 5458 | * to apply the extensions to a notification. |
| 5459 | * </ol> |
| 5460 | * |
| 5461 | * <pre class="prettyprint"> |
| 5462 | * Notification notification = new Notification.Builder(context) |
| 5463 | * ... |
| 5464 | * .extend(new CarExtender() |
| 5465 | * .set*(...)) |
| 5466 | * .build(); |
| 5467 | * </pre> |
| 5468 | * |
| 5469 | * <p>Car extensions can be accessed on an existing notification by using the |
| 5470 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 5471 | * to access values. |
| 5472 | */ |
| 5473 | public static final class CarExtender implements Extender { |
| 5474 | private static final String TAG = "CarExtender"; |
| 5475 | |
| 5476 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 5477 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 5478 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 5479 | private static final String EXTRA_COLOR = "app_color"; |
| 5480 | |
| 5481 | private Bitmap mLargeIcon; |
| 5482 | private UnreadConversation mUnreadConversation; |
| 5483 | private int mColor = Notification.COLOR_DEFAULT; |
| 5484 | |
| 5485 | /** |
| 5486 | * Create a {@link CarExtender} with default options. |
| 5487 | */ |
| 5488 | public CarExtender() { |
| 5489 | } |
| 5490 | |
| 5491 | /** |
| 5492 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 5493 | * |
| 5494 | * @param notif The notification from which to copy options. |
| 5495 | */ |
| 5496 | public CarExtender(Notification notif) { |
| 5497 | Bundle carBundle = notif.extras == null ? |
| 5498 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 5499 | if (carBundle != null) { |
| 5500 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 5501 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 5502 | |
| 5503 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 5504 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 5505 | } |
| 5506 | } |
| 5507 | |
| 5508 | /** |
| 5509 | * Apply car extensions to a notification that is being built. This is typically called by |
| 5510 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 5511 | * method of {@link Notification.Builder}. |
| 5512 | */ |
| 5513 | @Override |
| 5514 | public Notification.Builder extend(Notification.Builder builder) { |
| 5515 | Bundle carExtensions = new Bundle(); |
| 5516 | |
| 5517 | if (mLargeIcon != null) { |
| 5518 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 5519 | } |
| 5520 | if (mColor != Notification.COLOR_DEFAULT) { |
| 5521 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 5522 | } |
| 5523 | |
| 5524 | if (mUnreadConversation != null) { |
| 5525 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 5526 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 5527 | } |
| 5528 | |
| 5529 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 5530 | return builder; |
| 5531 | } |
| 5532 | |
| 5533 | /** |
| 5534 | * Sets the accent color to use when Android Auto presents the notification. |
| 5535 | * |
| 5536 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 5537 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 5538 | * automotive setting. This method can be used to override the color provided in the |
| 5539 | * notification in such a situation. |
| 5540 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 5541 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5542 | mColor = color; |
| 5543 | return this; |
| 5544 | } |
| 5545 | |
| 5546 | /** |
| 5547 | * Gets the accent color. |
| 5548 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5549 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5550 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 5551 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5552 | public int getColor() { |
| 5553 | return mColor; |
| 5554 | } |
| 5555 | |
| 5556 | /** |
| 5557 | * Sets the large icon of the car notification. |
| 5558 | * |
| 5559 | * If no large icon is set in the extender, Android Auto will display the icon |
| 5560 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 5561 | * |
| 5562 | * @param largeIcon The large icon to use in the car notification. |
| 5563 | * @return This object for method chaining. |
| 5564 | */ |
| 5565 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 5566 | mLargeIcon = largeIcon; |
| 5567 | return this; |
| 5568 | } |
| 5569 | |
| 5570 | /** |
| 5571 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 5572 | * |
| 5573 | * @return The large icon for the car notification. |
| 5574 | * @see CarExtender#setLargeIcon |
| 5575 | */ |
| 5576 | public Bitmap getLargeIcon() { |
| 5577 | return mLargeIcon; |
| 5578 | } |
| 5579 | |
| 5580 | /** |
| 5581 | * Sets the unread conversation in a message notification. |
| 5582 | * |
| 5583 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 5584 | * @return This object for method chaining. |
| 5585 | */ |
| 5586 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 5587 | mUnreadConversation = unreadConversation; |
| 5588 | return this; |
| 5589 | } |
| 5590 | |
| 5591 | /** |
| 5592 | * Returns the unread conversation conveyed by this notification. |
| 5593 | * @see #setUnreadConversation(UnreadConversation) |
| 5594 | */ |
| 5595 | public UnreadConversation getUnreadConversation() { |
| 5596 | return mUnreadConversation; |
| 5597 | } |
| 5598 | |
| 5599 | /** |
| 5600 | * A class which holds the unread messages from a conversation. |
| 5601 | */ |
| 5602 | public static class UnreadConversation { |
| 5603 | private static final String KEY_AUTHOR = "author"; |
| 5604 | private static final String KEY_TEXT = "text"; |
| 5605 | private static final String KEY_MESSAGES = "messages"; |
| 5606 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 5607 | private static final String KEY_ON_REPLY = "on_reply"; |
| 5608 | private static final String KEY_ON_READ = "on_read"; |
| 5609 | private static final String KEY_PARTICIPANTS = "participants"; |
| 5610 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 5611 | |
| 5612 | private final String[] mMessages; |
| 5613 | private final RemoteInput mRemoteInput; |
| 5614 | private final PendingIntent mReplyPendingIntent; |
| 5615 | private final PendingIntent mReadPendingIntent; |
| 5616 | private final String[] mParticipants; |
| 5617 | private final long mLatestTimestamp; |
| 5618 | |
| 5619 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 5620 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 5621 | String[] participants, long latestTimestamp) { |
| 5622 | mMessages = messages; |
| 5623 | mRemoteInput = remoteInput; |
| 5624 | mReadPendingIntent = readPendingIntent; |
| 5625 | mReplyPendingIntent = replyPendingIntent; |
| 5626 | mParticipants = participants; |
| 5627 | mLatestTimestamp = latestTimestamp; |
| 5628 | } |
| 5629 | |
| 5630 | /** |
| 5631 | * Gets the list of messages conveyed by this notification. |
| 5632 | */ |
| 5633 | public String[] getMessages() { |
| 5634 | return mMessages; |
| 5635 | } |
| 5636 | |
| 5637 | /** |
| 5638 | * Gets the remote input that will be used to convey the response to a message list, or |
| 5639 | * null if no such remote input exists. |
| 5640 | */ |
| 5641 | public RemoteInput getRemoteInput() { |
| 5642 | return mRemoteInput; |
| 5643 | } |
| 5644 | |
| 5645 | /** |
| 5646 | * Gets the pending intent that will be triggered when the user replies to this |
| 5647 | * notification. |
| 5648 | */ |
| 5649 | public PendingIntent getReplyPendingIntent() { |
| 5650 | return mReplyPendingIntent; |
| 5651 | } |
| 5652 | |
| 5653 | /** |
| 5654 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 5655 | * in this object's message list. |
| 5656 | */ |
| 5657 | public PendingIntent getReadPendingIntent() { |
| 5658 | return mReadPendingIntent; |
| 5659 | } |
| 5660 | |
| 5661 | /** |
| 5662 | * Gets the participants in the conversation. |
| 5663 | */ |
| 5664 | public String[] getParticipants() { |
| 5665 | return mParticipants; |
| 5666 | } |
| 5667 | |
| 5668 | /** |
| 5669 | * Gets the firs participant in the conversation. |
| 5670 | */ |
| 5671 | public String getParticipant() { |
| 5672 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 5673 | } |
| 5674 | |
| 5675 | /** |
| 5676 | * Gets the timestamp of the conversation. |
| 5677 | */ |
| 5678 | public long getLatestTimestamp() { |
| 5679 | return mLatestTimestamp; |
| 5680 | } |
| 5681 | |
| 5682 | Bundle getBundleForUnreadConversation() { |
| 5683 | Bundle b = new Bundle(); |
| 5684 | String author = null; |
| 5685 | if (mParticipants != null && mParticipants.length > 1) { |
| 5686 | author = mParticipants[0]; |
| 5687 | } |
| 5688 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 5689 | for (int i = 0; i < messages.length; i++) { |
| 5690 | Bundle m = new Bundle(); |
| 5691 | m.putString(KEY_TEXT, mMessages[i]); |
| 5692 | m.putString(KEY_AUTHOR, author); |
| 5693 | messages[i] = m; |
| 5694 | } |
| 5695 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 5696 | if (mRemoteInput != null) { |
| 5697 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 5698 | } |
| 5699 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 5700 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 5701 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 5702 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 5703 | return b; |
| 5704 | } |
| 5705 | |
| 5706 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 5707 | if (b == null) { |
| 5708 | return null; |
| 5709 | } |
| 5710 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 5711 | String[] messages = null; |
| 5712 | if (parcelableMessages != null) { |
| 5713 | String[] tmp = new String[parcelableMessages.length]; |
| 5714 | boolean success = true; |
| 5715 | for (int i = 0; i < tmp.length; i++) { |
| 5716 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 5717 | success = false; |
| 5718 | break; |
| 5719 | } |
| 5720 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 5721 | if (tmp[i] == null) { |
| 5722 | success = false; |
| 5723 | break; |
| 5724 | } |
| 5725 | } |
| 5726 | if (success) { |
| 5727 | messages = tmp; |
| 5728 | } else { |
| 5729 | return null; |
| 5730 | } |
| 5731 | } |
| 5732 | |
| 5733 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 5734 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 5735 | |
| 5736 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 5737 | |
| 5738 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 5739 | if (participants == null || participants.length != 1) { |
| 5740 | return null; |
| 5741 | } |
| 5742 | |
| 5743 | return new UnreadConversation(messages, |
| 5744 | remoteInput, |
| 5745 | onReply, |
| 5746 | onRead, |
| 5747 | participants, b.getLong(KEY_TIMESTAMP)); |
| 5748 | } |
| 5749 | }; |
| 5750 | |
| 5751 | /** |
| 5752 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 5753 | */ |
| 5754 | public static class Builder { |
| 5755 | private final List<String> mMessages = new ArrayList<String>(); |
| 5756 | private final String mParticipant; |
| 5757 | private RemoteInput mRemoteInput; |
| 5758 | private PendingIntent mReadPendingIntent; |
| 5759 | private PendingIntent mReplyPendingIntent; |
| 5760 | private long mLatestTimestamp; |
| 5761 | |
| 5762 | /** |
| 5763 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 5764 | * |
| 5765 | * @param name The name of the other participant in the conversation. |
| 5766 | */ |
| 5767 | public Builder(String name) { |
| 5768 | mParticipant = name; |
| 5769 | } |
| 5770 | |
| 5771 | /** |
| 5772 | * Appends a new unread message to the list of messages for this conversation. |
| 5773 | * |
| 5774 | * The messages should be added from oldest to newest. |
| 5775 | * |
| 5776 | * @param message The text of the new unread message. |
| 5777 | * @return This object for method chaining. |
| 5778 | */ |
| 5779 | public Builder addMessage(String message) { |
| 5780 | mMessages.add(message); |
| 5781 | return this; |
| 5782 | } |
| 5783 | |
| 5784 | /** |
| 5785 | * Sets the pending intent and remote input which will convey the reply to this |
| 5786 | * notification. |
| 5787 | * |
| 5788 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 5789 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 5790 | * @return This object for method chaining. |
| 5791 | * |
| 5792 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 5793 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 5794 | */ |
| 5795 | public Builder setReplyAction( |
| 5796 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 5797 | mRemoteInput = remoteInput; |
| 5798 | mReplyPendingIntent = pendingIntent; |
| 5799 | |
| 5800 | return this; |
| 5801 | } |
| 5802 | |
| 5803 | /** |
| 5804 | * Sets the pending intent that will be sent once the messages in this notification |
| 5805 | * are read. |
| 5806 | * |
| 5807 | * @param pendingIntent The pending intent to use. |
| 5808 | * @return This object for method chaining. |
| 5809 | */ |
| 5810 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 5811 | mReadPendingIntent = pendingIntent; |
| 5812 | return this; |
| 5813 | } |
| 5814 | |
| 5815 | /** |
| 5816 | * Sets the timestamp of the most recent message in an unread conversation. |
| 5817 | * |
| 5818 | * If a messaging notification has been posted by your application and has not |
| 5819 | * yet been cancelled, posting a later notification with the same id and tag |
| 5820 | * but without a newer timestamp may result in Android Auto not displaying a |
| 5821 | * heads up notification for the later notification. |
| 5822 | * |
| 5823 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 5824 | * @return This object for method chaining. |
| 5825 | */ |
| 5826 | public Builder setLatestTimestamp(long timestamp) { |
| 5827 | mLatestTimestamp = timestamp; |
| 5828 | return this; |
| 5829 | } |
| 5830 | |
| 5831 | /** |
| 5832 | * Builds a new unread conversation object. |
| 5833 | * |
| 5834 | * @return The new unread conversation object. |
| 5835 | */ |
| 5836 | public UnreadConversation build() { |
| 5837 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 5838 | String[] participants = { mParticipant }; |
| 5839 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 5840 | mReadPendingIntent, participants, mLatestTimestamp); |
| 5841 | } |
| 5842 | } |
| 5843 | } |
| 5844 | |
| 5845 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5846 | * Get an array of Notification objects from a parcelable array bundle field. |
| 5847 | * Update the bundle to have a typed array so fetches in the future don't need |
| 5848 | * to do an array copy. |
| 5849 | */ |
| 5850 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 5851 | Parcelable[] array = bundle.getParcelableArray(key); |
| 5852 | if (array instanceof Notification[] || array == null) { |
| 5853 | return (Notification[]) array; |
| 5854 | } |
| 5855 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 5856 | Notification[].class); |
| 5857 | bundle.putParcelableArray(key, typedArray); |
| 5858 | return typedArray; |
| 5859 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5860 | |
| 5861 | private static class BuilderRemoteViews extends RemoteViews { |
| 5862 | public BuilderRemoteViews(Parcel parcel) { |
| 5863 | super(parcel); |
| 5864 | } |
| 5865 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 5866 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 5867 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5868 | } |
| 5869 | |
| 5870 | @Override |
| 5871 | public BuilderRemoteViews clone() { |
| 5872 | Parcel p = Parcel.obtain(); |
| 5873 | writeToParcel(p, 0); |
| 5874 | p.setDataPosition(0); |
| 5875 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 5876 | p.recycle(); |
| 5877 | return brv; |
| 5878 | } |
| 5879 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5880 | } |