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; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 24 | import android.annotation.SystemApi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 27 | import android.content.pm.ApplicationInfo; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 28 | import android.content.pm.PackageManager.NameNotFoundException; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 29 | import android.content.res.ColorStateList; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 30 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 31 | import android.graphics.Canvas; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 32 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 33 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 34 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 35 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 36 | import android.media.AudioManager; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 37 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 39 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 40 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 41 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.os.Parcel; |
| 43 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 44 | import android.os.SystemClock; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 45 | import android.os.UserHandle; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 46 | import android.text.SpannableStringBuilder; |
| 47 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 49 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 50 | import android.text.style.CharacterStyle; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 51 | import android.text.style.RelativeSizeSpan; |
| 52 | import android.text.style.TextAppearanceSpan; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 53 | import android.util.Log; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 54 | import android.util.SparseArray; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 55 | import android.util.TypedValue; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 56 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 57 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 58 | import android.view.View; |
Adrian Roos | 9b123cf | 2016-02-04 14:55:57 -0800 | [diff] [blame] | 59 | import android.view.ViewGroup; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 60 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.widget.RemoteViews; |
| 62 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 63 | import com.android.internal.R; |
Griff Hazen | c091ba8 | 2014-05-16 10:13:26 -0700 | [diff] [blame] | 64 | import com.android.internal.util.NotificationColorUtil; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 65 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 66 | import java.lang.annotation.Retention; |
| 67 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 68 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 69 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 70 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 71 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 72 | import java.util.List; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 73 | import java.util.Set; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 74 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | /** |
| 76 | * A class that represents how a persistent notification is to be presented to |
| 77 | * the user using the {@link android.app.NotificationManager}. |
| 78 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 79 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 80 | * easier to construct Notifications.</p> |
| 81 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 82 | * <div class="special reference"> |
| 83 | * <h3>Developer Guides</h3> |
| 84 | * <p>For a guide to creating notifications, read the |
| 85 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 86 | * developer guide.</p> |
| 87 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | */ |
| 89 | public class Notification implements Parcelable |
| 90 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 91 | private static final String TAG = "Notification"; |
| 92 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 94 | * An activity that provides a user interface for adjusting notification preferences for its |
| 95 | * containing application. Optional but recommended for apps that post |
| 96 | * {@link android.app.Notification Notifications}. |
| 97 | */ |
| 98 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 99 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 100 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 101 | |
| 102 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | * Use all default values (where applicable). |
| 104 | */ |
| 105 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | /** |
| 108 | * Use the default notification sound. This will ignore any given |
| 109 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 110 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 111 | * <p> |
| 112 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 113 | * </p> |
| 114 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 116 | */ |
| 117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | public static final int DEFAULT_SOUND = 1; |
| 119 | |
| 120 | /** |
| 121 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 122 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 123 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 124 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 125 | * <p> |
| 126 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 127 | * </p> |
| 128 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 130 | */ |
| 131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | /** |
| 135 | * Use the default notification lights. This will ignore the |
| 136 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 137 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 138 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 140 | */ |
| 141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 145 | * Maximum length of CharSequences accepted by Builder and friends. |
| 146 | * |
| 147 | * <p> |
| 148 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 149 | */ |
| 150 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 151 | |
| 152 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 153 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 154 | */ |
| 155 | private static final int MAX_REPLY_HISTORY = 5; |
| 156 | |
| 157 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 158 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 159 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 160 | * Default value: {@link System#currentTimeMillis() Now}. |
| 161 | * |
| 162 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 163 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 164 | * yet to occur but about which the user is being informed). Indefinite events should be |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 165 | * timestamped according to when the activity began. |
| 166 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 167 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 168 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 169 | * <ul> |
| 170 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 171 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 172 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 173 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 174 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 175 | * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 176 | * </ul> |
| 177 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 178 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 179 | * anymore by default and must be opted into by using |
| 180 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | */ |
| 182 | public long when; |
| 183 | |
| 184 | /** |
| 185 | * 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] | 186 | * |
| 187 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 189 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 190 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | public int icon; |
| 192 | |
| 193 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 194 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 195 | * leave it at its default value of 0. |
| 196 | * |
| 197 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 198 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 199 | */ |
| 200 | public int iconLevel; |
| 201 | |
| 202 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 203 | * The number of events that this notification represents. For example, in a new mail |
| 204 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 205 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 206 | * The system may or may not use this field to modify the appearance of the notification. For |
| 207 | * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was |
| 208 | * superimposed over the icon in the status bar. Starting with |
| 209 | * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by |
| 210 | * {@link Notification.Builder} has displayed the number in the expanded notification view. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 211 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 212 | * If the number is 0 or negative, it is never shown. |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 213 | * |
| 214 | * @deprecated this number is not shown anymore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | */ |
| 216 | public int number; |
| 217 | |
| 218 | /** |
| 219 | * The intent to execute when the expanded status entry is clicked. If |
| 220 | * this is an activity, it must include the |
| 221 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 222 | * that you take care of task management as described in the |
| 223 | * <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] | 224 | * Stack</a> document. In particular, make sure to read the notification section |
| 225 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 226 | * Notifications</a> for the correct ways to launch an application from a |
| 227 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | */ |
| 229 | public PendingIntent contentIntent; |
| 230 | |
| 231 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 232 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 233 | * the "Clear All" button or by swiping it away individually. |
| 234 | * |
| 235 | * This probably shouldn't be launching an activity since several of those will be sent |
| 236 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | */ |
| 238 | public PendingIntent deleteIntent; |
| 239 | |
| 240 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 241 | * 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] | 242 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 243 | * <p> |
| 244 | * The system UI may choose to display a heads-up notification, instead of |
| 245 | * launching this intent, while the user is using the device. |
| 246 | * </p> |
| 247 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 248 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 249 | */ |
| 250 | public PendingIntent fullScreenIntent; |
| 251 | |
| 252 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 253 | * Text that summarizes this notification for accessibility services. |
| 254 | * |
| 255 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 256 | * accessibility services (where it serves as an audible announcement of the notification's |
| 257 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 258 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 259 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | */ |
| 261 | public CharSequence tickerText; |
| 262 | |
| 263 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 264 | * Formerly, a view showing the {@link #tickerText}. |
| 265 | * |
| 266 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 267 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 268 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 269 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 270 | |
| 271 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 272 | * The view that will represent this notification in the notification list (which is pulled |
| 273 | * down from the status bar). |
| 274 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 275 | * As of N, this field may be null. The notification view is determined by the inputs |
| 276 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 277 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 279 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | public RemoteViews contentView; |
| 281 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 282 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 283 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 284 | * opportunity to show more detail. The system UI may choose to show this |
| 285 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 286 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 287 | * 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] | 288 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 289 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 290 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 291 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 292 | public RemoteViews bigContentView; |
| 293 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 294 | |
| 295 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 296 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 297 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 298 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 299 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 300 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 301 | * 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] | 302 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 303 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 304 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 305 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 306 | public RemoteViews headsUpContentView; |
| 307 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 308 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 309 | * A large bitmap to be shown in the notification content area. |
| 310 | * |
| 311 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 313 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 314 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | |
| 316 | /** |
| 317 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 318 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 320 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 321 | * </p> |
| 322 | * |
| 323 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 324 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | * </p> |
| 326 | */ |
| 327 | public Uri sound; |
| 328 | |
| 329 | /** |
| 330 | * Use this constant as the value for audioStreamType to request that |
| 331 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 332 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 333 | * |
| 334 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 336 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | public static final int STREAM_DEFAULT = -1; |
| 338 | |
| 339 | /** |
| 340 | * The audio stream type to use when playing the sound. |
| 341 | * Should be one of the STREAM_ constants from |
| 342 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 343 | * |
| 344 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 346 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | public int audioStreamType = STREAM_DEFAULT; |
| 348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 350 | * The default value of {@link #audioAttributes}. |
| 351 | */ |
| 352 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 353 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 354 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 355 | .build(); |
| 356 | |
| 357 | /** |
| 358 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
| 359 | */ |
| 360 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 361 | |
| 362 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 363 | * The pattern with which to vibrate. |
| 364 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | * <p> |
| 366 | * To vibrate the default pattern, see {@link #defaults}. |
| 367 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 368 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 369 | * <p> |
| 370 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 371 | * </p> |
| 372 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | * @see android.os.Vibrator#vibrate(long[],int) |
| 374 | */ |
| 375 | public long[] vibrate; |
| 376 | |
| 377 | /** |
| 378 | * The color of the led. The hardware will do its best approximation. |
| 379 | * |
| 380 | * @see #FLAG_SHOW_LIGHTS |
| 381 | * @see #flags |
| 382 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 383 | @ColorInt |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | public int ledARGB; |
| 385 | |
| 386 | /** |
| 387 | * The number of milliseconds for the LED to be on while it's flashing. |
| 388 | * The hardware will do its best approximation. |
| 389 | * |
| 390 | * @see #FLAG_SHOW_LIGHTS |
| 391 | * @see #flags |
| 392 | */ |
| 393 | public int ledOnMS; |
| 394 | |
| 395 | /** |
| 396 | * The number of milliseconds for the LED to be off while it's flashing. |
| 397 | * The hardware will do its best approximation. |
| 398 | * |
| 399 | * @see #FLAG_SHOW_LIGHTS |
| 400 | * @see #flags |
| 401 | */ |
| 402 | public int ledOffMS; |
| 403 | |
| 404 | /** |
| 405 | * Specifies which values should be taken from the defaults. |
| 406 | * <p> |
| 407 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 408 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 409 | * values, use {@link #DEFAULT_ALL}. |
| 410 | * </p> |
| 411 | */ |
| 412 | public int defaults; |
| 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | /** |
| 415 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 416 | * set if you want the LED on for this notification. |
| 417 | * <ul> |
| 418 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 419 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 420 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 421 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 422 | * be on and off to ledOnMS and ledOffMS.</li> |
| 423 | * </ul> |
| 424 | * <p> |
| 425 | * Since hardware varies, you are not guaranteed that any of the values |
| 426 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 427 | * because they will be set to values that work on any given hardware. |
| 428 | * <p> |
| 429 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 430 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | */ |
| 432 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 433 | |
| 434 | /** |
| 435 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 436 | * set if this notification is in reference to something that is ongoing, |
| 437 | * like a phone call. It should not be set if this notification is in |
| 438 | * reference to something that happened at a particular point in time, |
| 439 | * like a missed phone call. |
| 440 | */ |
| 441 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 442 | |
| 443 | /** |
| 444 | * 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] | 445 | * the audio will be repeated until the notification is |
| 446 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | */ |
| 448 | public static final int FLAG_INSISTENT = 0x00000004; |
| 449 | |
| 450 | /** |
| 451 | * 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] | 452 | * set if you would only like the sound, vibrate and ticker to be played |
| 453 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | */ |
| 455 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 456 | |
| 457 | /** |
| 458 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 459 | * 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] | 460 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | */ |
| 462 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 463 | |
| 464 | /** |
| 465 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 466 | * set if the notification should not be canceled when the user clicks |
| 467 | * the Clear all button. |
| 468 | */ |
| 469 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 470 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 471 | /** |
| 472 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 473 | * set if this notification represents a currently running service. This |
| 474 | * will normally be set for you by {@link Service#startForeground}. |
| 475 | */ |
| 476 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 477 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 478 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 479 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 480 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 481 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 482 | */ |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 483 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 484 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 485 | /** |
| 486 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 487 | * set if this notification is relevant to the current device only |
| 488 | * and it is not recommended that it bridge to other devices. |
| 489 | */ |
| 490 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 491 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 492 | /** |
| 493 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 494 | * set if this notification is the group summary for a group of notifications. |
| 495 | * Grouped notifications may display in a cluster or stack on devices which |
| 496 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 497 | */ |
| 498 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 499 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 500 | /** |
| 501 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 502 | * set if this notification is the group summary for an auto-group of notifications. |
| 503 | * |
| 504 | * @hide |
| 505 | */ |
| 506 | @SystemApi |
| 507 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | public int flags; |
| 510 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 511 | /** @hide */ |
| 512 | @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX}) |
| 513 | @Retention(RetentionPolicy.SOURCE) |
| 514 | public @interface Priority {} |
| 515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 517 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 518 | * notifications, use this value for all notifications. |
| 519 | */ |
| 520 | public static final int PRIORITY_DEFAULT = 0; |
| 521 | |
| 522 | /** |
| 523 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 524 | * items smaller, or at a different position in the list, compared with your app's |
| 525 | * {@link #PRIORITY_DEFAULT} items. |
| 526 | */ |
| 527 | public static final int PRIORITY_LOW = -1; |
| 528 | |
| 529 | /** |
| 530 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 531 | * circumstances, such as detailed notification logs. |
| 532 | */ |
| 533 | public static final int PRIORITY_MIN = -2; |
| 534 | |
| 535 | /** |
| 536 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 537 | * show these items larger, or at a different position in notification lists, compared with |
| 538 | * your app's {@link #PRIORITY_DEFAULT} items. |
| 539 | */ |
| 540 | public static final int PRIORITY_HIGH = 1; |
| 541 | |
| 542 | /** |
| 543 | * Highest {@link #priority}, for your application's most important items that require the |
| 544 | * user's prompt attention or input. |
| 545 | */ |
| 546 | public static final int PRIORITY_MAX = 2; |
| 547 | |
| 548 | /** |
| 549 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 550 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 551 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 552 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 553 | * 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] | 554 | * system will make a determination about how to interpret this priority when presenting |
| 555 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 556 | * |
| 557 | * <p> |
| 558 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 559 | * as a heads-up notification. |
| 560 | * </p> |
| 561 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 562 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 563 | @Priority |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 564 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 565 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 566 | /** |
| 567 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 568 | * to be applied by the standard Style templates when presenting this notification. |
| 569 | * |
| 570 | * The current template design constructs a colorful header image by overlaying the |
| 571 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 572 | * ignored. |
| 573 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 574 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 575 | public int color = COLOR_DEFAULT; |
| 576 | |
| 577 | /** |
| 578 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 579 | * any special color but instead use default colors when presenting this notification. |
| 580 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 581 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 582 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 583 | |
| 584 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 585 | * Special value of {@link #color} used as a place holder for an invalid color. |
| 586 | */ |
| 587 | @ColorInt |
| 588 | private static final int COLOR_INVALID = 1; |
| 589 | |
| 590 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 591 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 592 | * the notification's presence and contents in untrusted situations (namely, on the secure |
| 593 | * lockscreen). |
| 594 | * |
| 595 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 596 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 597 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 598 | * the appropriate user. |
| 599 | * |
| 600 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 601 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 602 | * To modify the public version of this notification—for example, to redact some portions—see |
| 603 | * {@link Builder#setPublicVersion(Notification)}. |
| 604 | * |
| 605 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 606 | * and ticker until the user has bypassed the lockscreen. |
| 607 | */ |
| 608 | public int visibility; |
| 609 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 610 | /** |
| 611 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 612 | * |
| 613 | * {@see #visibility} |
| 614 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 615 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 616 | |
| 617 | /** |
| 618 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 619 | * private information on secure lockscreens. |
| 620 | * |
| 621 | * {@see #visibility} |
| 622 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 623 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 624 | |
| 625 | /** |
| 626 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 627 | * |
| 628 | * {@see #visibility} |
| 629 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 630 | public static final int VISIBILITY_SECRET = -1; |
| 631 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 632 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 633 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
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_CALL = "call"; |
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: incoming direct message (SMS, instant message, etc.). |
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_MESSAGE = "msg"; |
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: asynchronous bulk message (email). |
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_EMAIL = "email"; |
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: calendar event. |
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_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 651 | |
| 652 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 653 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 654 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 655 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 656 | |
| 657 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 658 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 659 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 660 | public static final String CATEGORY_ALARM = "alarm"; |
| 661 | |
| 662 | /** |
| 663 | * Notification category: progress of a long-running background operation. |
| 664 | */ |
| 665 | public static final String CATEGORY_PROGRESS = "progress"; |
| 666 | |
| 667 | /** |
| 668 | * Notification category: social network or sharing update. |
| 669 | */ |
| 670 | public static final String CATEGORY_SOCIAL = "social"; |
| 671 | |
| 672 | /** |
| 673 | * Notification category: error in background operation or authentication status. |
| 674 | */ |
| 675 | public static final String CATEGORY_ERROR = "err"; |
| 676 | |
| 677 | /** |
| 678 | * Notification category: media transport control for playback. |
| 679 | */ |
| 680 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 681 | |
| 682 | /** |
| 683 | * Notification category: system or device status update. Reserved for system use. |
| 684 | */ |
| 685 | public static final String CATEGORY_SYSTEM = "sys"; |
| 686 | |
| 687 | /** |
| 688 | * Notification category: indication of running background service. |
| 689 | */ |
| 690 | public static final String CATEGORY_SERVICE = "service"; |
| 691 | |
| 692 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 693 | * Notification category: a specific, timely recommendation for a single thing. |
| 694 | * For example, a news app might want to recommend a news story it believes the user will |
| 695 | * want to read next. |
| 696 | */ |
| 697 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 698 | |
| 699 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 700 | * Notification category: ongoing information about device or contextual status. |
| 701 | */ |
| 702 | public static final String CATEGORY_STATUS = "status"; |
| 703 | |
| 704 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 705 | * Notification category: user-scheduled reminder. |
| 706 | */ |
| 707 | public static final String CATEGORY_REMINDER = "reminder"; |
| 708 | |
| 709 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 710 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 711 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 712 | */ |
| 713 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 714 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 715 | private String mGroupKey; |
| 716 | |
| 717 | /** |
| 718 | * Get the key used to group this notification into a cluster or stack |
| 719 | * with other notifications on devices which support such rendering. |
| 720 | */ |
| 721 | public String getGroup() { |
| 722 | return mGroupKey; |
| 723 | } |
| 724 | |
| 725 | private String mSortKey; |
| 726 | |
| 727 | /** |
| 728 | * Get a sort key that orders this notification among other notifications from the |
| 729 | * same package. This can be useful if an external sort was already applied and an app |
| 730 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 731 | * value, although providing different priorities in addition to providing sort key may |
| 732 | * cause this value to be ignored. |
| 733 | * |
| 734 | * <p>This sort key can also be used to order members of a notification group. See |
| 735 | * {@link Builder#setGroup}. |
| 736 | * |
| 737 | * @see String#compareTo(String) |
| 738 | */ |
| 739 | public String getSortKey() { |
| 740 | return mSortKey; |
| 741 | } |
| 742 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 743 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 744 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 745 | * <p> |
| 746 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 747 | * APIs, and are intended to be used by |
| 748 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 749 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 750 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 751 | public Bundle extras = new Bundle(); |
| 752 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 753 | /** |
| 754 | * {@link #extras} key: this is the title of the notification, |
| 755 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 756 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 757 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 758 | |
| 759 | /** |
| 760 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 761 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 762 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 763 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 764 | |
| 765 | /** |
| 766 | * {@link #extras} key: this is the main text payload, as supplied to |
| 767 | * {@link Builder#setContentText(CharSequence)}. |
| 768 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 769 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 770 | |
| 771 | /** |
| 772 | * {@link #extras} key: this is a third line of text, as supplied to |
| 773 | * {@link Builder#setSubText(CharSequence)}. |
| 774 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 775 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 776 | |
| 777 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 778 | * {@link #extras} key: this is the remote input history, as supplied to |
| 779 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
| 780 | */ |
| 781 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 782 | |
| 783 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 784 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 785 | * {@link Builder#setContentInfo(CharSequence)}. |
| 786 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 787 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 788 | |
| 789 | /** |
| 790 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 791 | * alongside expanded notifications, as supplied to (e.g.) |
| 792 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 793 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 794 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 795 | |
| 796 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 797 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 798 | * {@link BigTextStyle} notification, as supplied to |
| 799 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 800 | */ |
| 801 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 802 | |
| 803 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 804 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 805 | * supplied to {@link Builder#setSmallIcon(int)}. |
| 806 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 807 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 808 | |
| 809 | /** |
| 810 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 811 | * notification payload, as |
| 812 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
| 813 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 814 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 815 | |
| 816 | /** |
| 817 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 818 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 819 | * shown in its expanded form, as supplied to |
| 820 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 821 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 822 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 823 | |
| 824 | /** |
| 825 | * {@link #extras} key: this is the progress value supplied to |
| 826 | * {@link Builder#setProgress(int, int, boolean)}. |
| 827 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 828 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 829 | |
| 830 | /** |
| 831 | * {@link #extras} key: this is the maximum value supplied to |
| 832 | * {@link Builder#setProgress(int, int, boolean)}. |
| 833 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 834 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 835 | |
| 836 | /** |
| 837 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 838 | * {@link Builder#setProgress(int, int, boolean)}. |
| 839 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 840 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 841 | |
| 842 | /** |
| 843 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 844 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 845 | * {@link Builder#setUsesChronometer(boolean)}. |
| 846 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 847 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 848 | |
| 849 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 850 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 851 | * instead of counting up. Is only relevant if key {@link #EXTRA_SHOW_CHRONOMETER} is present. |
| 852 | */ |
| 853 | public static final String EXTRA_CHRONOMETER_COUNTS_DOWN = "android.chronometerCountsDown"; |
| 854 | |
| 855 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 856 | * {@link #extras} key: whether {@link #when} should be shown, |
| 857 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 858 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 859 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 860 | |
| 861 | /** |
| 862 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 863 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 864 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 865 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 866 | |
| 867 | /** |
| 868 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 869 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 870 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 871 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 872 | |
| 873 | /** |
| 874 | * {@link #extras} key: A string representing the name of the specific |
| 875 | * {@link android.app.Notification.Style} used to create this notification. |
| 876 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 877 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 878 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 879 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 880 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 881 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 882 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 883 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 884 | |
| 885 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 886 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 887 | * Only available to notifications coming from the android package. |
| 888 | * @hide |
| 889 | */ |
| 890 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 891 | |
| 892 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 893 | * {@link #extras} key: A |
| 894 | * {@link android.content.ContentUris content URI} pointing to an image that can be displayed |
| 895 | * in the background when the notification is selected. The URI must point to an image stream |
| 896 | * suitable for passing into |
| 897 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
| 898 | * BitmapFactory.decodeStream}; all other content types will be ignored. The content provider |
| 899 | * URI used for this purpose must require no permissions to read the image data. |
| 900 | */ |
| 901 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 902 | |
| 903 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 904 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 905 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 906 | * {@link android.app.Notification.MediaStyle} notification. |
| 907 | */ |
| 908 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 909 | |
| 910 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 911 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 912 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 913 | */ |
| 914 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 915 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 916 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 917 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 918 | * direct replies |
| 919 | * {@link android.app.Notification.MessagingStyle} notification. |
| 920 | */ |
| 921 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 922 | |
| 923 | /** |
| 924 | * {@link #extras} key: a boolean describing whether the platform should automatically |
| 925 | * generate possible replies to |
| 926 | * {@link android.app.Notification.MessagingStyle.Message} objects provided by a |
| 927 | * {@link android.app.Notification.MessagingStyle} notification. |
| 928 | */ |
| 929 | public static final String EXTRA_ALLOW_GENERATED_REPLIES = "android.allowGeneratedReplies"; |
| 930 | |
| 931 | /** |
| 932 | * {@link #extras} key: a {@link String} to be displayed as the title to a thread represented by |
| 933 | * a {@link android.app.Notification.MessagingStyle} |
| 934 | */ |
| 935 | public static final String EXTRA_THREAD_TITLE = "android.threadTitle"; |
| 936 | |
| 937 | /** |
| 938 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 939 | * bundles provided by a |
| 940 | * {@link android.app.Notification.MessagingStyle} notification. |
| 941 | */ |
| 942 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 943 | |
| 944 | /** |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 945 | * {@link #extras} key: the user that built the notification. |
| 946 | * |
| 947 | * @hide |
| 948 | */ |
| 949 | public static final String EXTRA_ORIGINATING_USERID = "android.originatingUserId"; |
| 950 | |
| 951 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 952 | * @hide |
| 953 | */ |
| 954 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 955 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 956 | /** |
| 957 | * @hide |
| 958 | */ |
| 959 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 960 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 961 | private Icon mSmallIcon; |
| 962 | private Icon mLargeIcon; |
| 963 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 964 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 965 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 966 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 967 | * selected by the user. |
| 968 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 969 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 970 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 971 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 972 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 973 | public static class Action implements Parcelable { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 974 | private final Bundle mExtras; |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 975 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 976 | private final RemoteInput[] mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 977 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 978 | /** |
| 979 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 980 | * |
| 981 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 982 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 983 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 984 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 985 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 986 | /** |
| 987 | * Title of the action. |
| 988 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 989 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 990 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 991 | /** |
| 992 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 993 | * may be rendered in a disabled presentation by the system UI. |
| 994 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 995 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 996 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 997 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 998 | if (in.readInt() != 0) { |
| 999 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1000 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1001 | icon = mIcon.getResId(); |
| 1002 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1003 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1004 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1005 | if (in.readInt() == 1) { |
| 1006 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1007 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1008 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1009 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1010 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1011 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1012 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1013 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1014 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1015 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1016 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1017 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1020 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1021 | RemoteInput[] remoteInputs) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1022 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1023 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1024 | this.icon = icon.getResId(); |
| 1025 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1026 | this.title = title; |
| 1027 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1028 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1029 | this.mRemoteInputs = remoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1033 | * Return an icon representing the action. |
| 1034 | */ |
| 1035 | public Icon getIcon() { |
| 1036 | if (mIcon == null && icon != 0) { |
| 1037 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1038 | mIcon = Icon.createWithResource("", icon); |
| 1039 | } |
| 1040 | return mIcon; |
| 1041 | } |
| 1042 | |
| 1043 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1044 | * Get additional metadata carried around with this Action. |
| 1045 | */ |
| 1046 | public Bundle getExtras() { |
| 1047 | return mExtras; |
| 1048 | } |
| 1049 | |
| 1050 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1051 | * Get the list of inputs to be collected from the user when this action is sent. |
| 1052 | * May return null if no remote inputs were added. |
| 1053 | */ |
| 1054 | public RemoteInput[] getRemoteInputs() { |
| 1055 | return mRemoteInputs; |
| 1056 | } |
| 1057 | |
| 1058 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1059 | * Builder class for {@link Action} objects. |
| 1060 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1061 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1062 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1063 | private final CharSequence mTitle; |
| 1064 | private final PendingIntent mIntent; |
| 1065 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1066 | private ArrayList<RemoteInput> mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1067 | |
| 1068 | /** |
| 1069 | * Construct a new builder for {@link Action} object. |
| 1070 | * @param icon icon to show for this action |
| 1071 | * @param title the title of the action |
| 1072 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1073 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1074 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1075 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1076 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null); |
| 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * Construct a new builder for {@link Action} object. |
| 1081 | * @param icon icon to show for this action |
| 1082 | * @param title the title of the action |
| 1083 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1084 | */ |
| 1085 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1086 | this(icon, title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | /** |
| 1090 | * Construct a new builder for {@link Action} object using the fields from an |
| 1091 | * {@link Action}. |
| 1092 | * @param action the action to read fields from. |
| 1093 | */ |
| 1094 | public Builder(Action action) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1095 | this(action.getIcon(), action.title, action.actionIntent, new Bundle(action.mExtras), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1096 | action.getRemoteInputs()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1099 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1100 | RemoteInput[] remoteInputs) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1101 | mIcon = icon; |
| 1102 | mTitle = title; |
| 1103 | mIntent = intent; |
| 1104 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1105 | if (remoteInputs != null) { |
| 1106 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1107 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1108 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | /** |
| 1112 | * Merge additional metadata into this builder. |
| 1113 | * |
| 1114 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1115 | * |
| 1116 | * @see Notification.Action#extras |
| 1117 | */ |
| 1118 | public Builder addExtras(Bundle extras) { |
| 1119 | if (extras != null) { |
| 1120 | mExtras.putAll(extras); |
| 1121 | } |
| 1122 | return this; |
| 1123 | } |
| 1124 | |
| 1125 | /** |
| 1126 | * Get the metadata Bundle used by this Builder. |
| 1127 | * |
| 1128 | * <p>The returned Bundle is shared with this Builder. |
| 1129 | */ |
| 1130 | public Bundle getExtras() { |
| 1131 | return mExtras; |
| 1132 | } |
| 1133 | |
| 1134 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1135 | * Add an input to be collected from the user when this action is sent. |
| 1136 | * Response values can be retrieved from the fired intent by using the |
| 1137 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1138 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1139 | * @return this object for method chaining |
| 1140 | */ |
| 1141 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1142 | if (mRemoteInputs == null) { |
| 1143 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1144 | } |
| 1145 | mRemoteInputs.add(remoteInput); |
| 1146 | return this; |
| 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * Apply an extender to this action builder. Extenders may be used to add |
| 1151 | * metadata or change options on this builder. |
| 1152 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1153 | public Builder extend(Extender extender) { |
| 1154 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1155 | return this; |
| 1156 | } |
| 1157 | |
| 1158 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1159 | * Combine all of the options that have been set and return a new {@link Action} |
| 1160 | * object. |
| 1161 | * @return the built action |
| 1162 | */ |
| 1163 | public Action build() { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1164 | RemoteInput[] remoteInputs = mRemoteInputs != null |
| 1165 | ? mRemoteInputs.toArray(new RemoteInput[mRemoteInputs.size()]) : null; |
| 1166 | return new Action(mIcon, mTitle, mIntent, mExtras, remoteInputs); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1167 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1168 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1169 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1170 | @Override |
| 1171 | public Action clone() { |
| 1172 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1173 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1174 | title, |
| 1175 | actionIntent, // safe to alias |
| 1176 | new Bundle(mExtras), |
| 1177 | getRemoteInputs()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1178 | } |
| 1179 | @Override |
| 1180 | public int describeContents() { |
| 1181 | return 0; |
| 1182 | } |
| 1183 | @Override |
| 1184 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1185 | final Icon ic = getIcon(); |
| 1186 | if (ic != null) { |
| 1187 | out.writeInt(1); |
| 1188 | ic.writeToParcel(out, 0); |
| 1189 | } else { |
| 1190 | out.writeInt(0); |
| 1191 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1192 | TextUtils.writeToParcel(title, out, flags); |
| 1193 | if (actionIntent != null) { |
| 1194 | out.writeInt(1); |
| 1195 | actionIntent.writeToParcel(out, flags); |
| 1196 | } else { |
| 1197 | out.writeInt(0); |
| 1198 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1199 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1200 | out.writeTypedArray(mRemoteInputs, flags); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1201 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1202 | public static final Parcelable.Creator<Action> CREATOR = |
| 1203 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1204 | public Action createFromParcel(Parcel in) { |
| 1205 | return new Action(in); |
| 1206 | } |
| 1207 | public Action[] newArray(int size) { |
| 1208 | return new Action[size]; |
| 1209 | } |
| 1210 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1211 | |
| 1212 | /** |
| 1213 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1214 | * metadata or change options on an action builder. |
| 1215 | */ |
| 1216 | public interface Extender { |
| 1217 | /** |
| 1218 | * Apply this extender to a notification action builder. |
| 1219 | * @param builder the builder to be modified. |
| 1220 | * @return the build object for chaining. |
| 1221 | */ |
| 1222 | public Builder extend(Builder builder); |
| 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * Wearable extender for notification actions. To add extensions to an action, |
| 1227 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1228 | * the {@code WearableExtender()} constructor and apply it to a |
| 1229 | * {@link android.app.Notification.Action.Builder} using |
| 1230 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1231 | * |
| 1232 | * <pre class="prettyprint"> |
| 1233 | * Notification.Action action = new Notification.Action.Builder( |
| 1234 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1235 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1236 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1237 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1238 | */ |
| 1239 | public static final class WearableExtender implements Extender { |
| 1240 | /** Notification action extra which contains wearable extensions */ |
| 1241 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1242 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1243 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1244 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1245 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1246 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1247 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1248 | |
| 1249 | // Flags bitwise-ored to mFlags |
| 1250 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1251 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1252 | |
| 1253 | // Default value for flags integer |
| 1254 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1255 | |
| 1256 | private int mFlags = DEFAULT_FLAGS; |
| 1257 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1258 | private CharSequence mInProgressLabel; |
| 1259 | private CharSequence mConfirmLabel; |
| 1260 | private CharSequence mCancelLabel; |
| 1261 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1262 | /** |
| 1263 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1264 | * options. |
| 1265 | */ |
| 1266 | public WearableExtender() { |
| 1267 | } |
| 1268 | |
| 1269 | /** |
| 1270 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1271 | * wearable options present in an existing notification action. |
| 1272 | * @param action the notification action to inspect. |
| 1273 | */ |
| 1274 | public WearableExtender(Action action) { |
| 1275 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1276 | if (wearableBundle != null) { |
| 1277 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1278 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1279 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1280 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * Apply wearable extensions to a notification action that is being built. This is |
| 1286 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1287 | * method of {@link android.app.Notification.Action.Builder}. |
| 1288 | */ |
| 1289 | @Override |
| 1290 | public Action.Builder extend(Action.Builder builder) { |
| 1291 | Bundle wearableBundle = new Bundle(); |
| 1292 | |
| 1293 | if (mFlags != DEFAULT_FLAGS) { |
| 1294 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1295 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1296 | if (mInProgressLabel != null) { |
| 1297 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1298 | } |
| 1299 | if (mConfirmLabel != null) { |
| 1300 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1301 | } |
| 1302 | if (mCancelLabel != null) { |
| 1303 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1304 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1305 | |
| 1306 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1307 | return builder; |
| 1308 | } |
| 1309 | |
| 1310 | @Override |
| 1311 | public WearableExtender clone() { |
| 1312 | WearableExtender that = new WearableExtender(); |
| 1313 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1314 | that.mInProgressLabel = this.mInProgressLabel; |
| 1315 | that.mConfirmLabel = this.mConfirmLabel; |
| 1316 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1317 | return that; |
| 1318 | } |
| 1319 | |
| 1320 | /** |
| 1321 | * Set whether this action is available when the wearable device is not connected to |
| 1322 | * a companion device. The user can still trigger this action when the wearable device is |
| 1323 | * offline, but a visual hint will indicate that the action may not be available. |
| 1324 | * Defaults to true. |
| 1325 | */ |
| 1326 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1327 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1328 | return this; |
| 1329 | } |
| 1330 | |
| 1331 | /** |
| 1332 | * Get whether this action is available when the wearable device is not connected to |
| 1333 | * a companion device. The user can still trigger this action when the wearable device is |
| 1334 | * offline, but a visual hint will indicate that the action may not be available. |
| 1335 | * Defaults to true. |
| 1336 | */ |
| 1337 | public boolean isAvailableOffline() { |
| 1338 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1339 | } |
| 1340 | |
| 1341 | private void setFlag(int mask, boolean value) { |
| 1342 | if (value) { |
| 1343 | mFlags |= mask; |
| 1344 | } else { |
| 1345 | mFlags &= ~mask; |
| 1346 | } |
| 1347 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1348 | |
| 1349 | /** |
| 1350 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1351 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1352 | * |
| 1353 | * @param label the label to display while the action is being prepared to execute |
| 1354 | * @return this object for method chaining |
| 1355 | */ |
| 1356 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1357 | mInProgressLabel = label; |
| 1358 | return this; |
| 1359 | } |
| 1360 | |
| 1361 | /** |
| 1362 | * Get the label to display while the wearable is preparing to automatically execute |
| 1363 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1364 | * |
| 1365 | * @return the label to display while the action is being prepared to execute |
| 1366 | */ |
| 1367 | public CharSequence getInProgressLabel() { |
| 1368 | return mInProgressLabel; |
| 1369 | } |
| 1370 | |
| 1371 | /** |
| 1372 | * Set a label to display to confirm that the action should be executed. |
| 1373 | * This is usually an imperative verb like "Send". |
| 1374 | * |
| 1375 | * @param label the label to confirm the action should be executed |
| 1376 | * @return this object for method chaining |
| 1377 | */ |
| 1378 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1379 | mConfirmLabel = label; |
| 1380 | return this; |
| 1381 | } |
| 1382 | |
| 1383 | /** |
| 1384 | * Get the label to display to confirm that the action should be executed. |
| 1385 | * This is usually an imperative verb like "Send". |
| 1386 | * |
| 1387 | * @return the label to confirm the action should be executed |
| 1388 | */ |
| 1389 | public CharSequence getConfirmLabel() { |
| 1390 | return mConfirmLabel; |
| 1391 | } |
| 1392 | |
| 1393 | /** |
| 1394 | * Set a label to display to cancel the action. |
| 1395 | * This is usually an imperative verb, like "Cancel". |
| 1396 | * |
| 1397 | * @param label the label to display to cancel the action |
| 1398 | * @return this object for method chaining |
| 1399 | */ |
| 1400 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1401 | mCancelLabel = label; |
| 1402 | return this; |
| 1403 | } |
| 1404 | |
| 1405 | /** |
| 1406 | * Get the label to display to cancel the action. |
| 1407 | * This is usually an imperative verb like "Cancel". |
| 1408 | * |
| 1409 | * @return the label to display to cancel the action |
| 1410 | */ |
| 1411 | public CharSequence getCancelLabel() { |
| 1412 | return mCancelLabel; |
| 1413 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1414 | |
| 1415 | /** |
| 1416 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 1417 | * platform that it can generate the appropriate transitions. |
| 1418 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 1419 | * an activity and transitions should be generated, false otherwise. |
| 1420 | * @return this object for method chaining |
| 1421 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame^] | 1422 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1423 | boolean hintLaunchesActivity) { |
| 1424 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 1425 | return this; |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 1430 | * platform that it can generate the appropriate transitions |
| 1431 | * @return {@code true} if the content intent will launch an activity and transitions |
| 1432 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 1433 | * never set. |
| 1434 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame^] | 1435 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1436 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 1437 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1438 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1439 | } |
| 1440 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1441 | /** |
| 1442 | * Array of all {@link Action} structures attached to this notification by |
| 1443 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 1444 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 1445 | * interface for invoking actions. |
| 1446 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1447 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1448 | |
| 1449 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1450 | * Replacement version of this notification whose content will be shown |
| 1451 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 1452 | * and {@link #VISIBILITY_PUBLIC}. |
| 1453 | */ |
| 1454 | public Notification publicVersion; |
| 1455 | |
| 1456 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1457 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1458 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1459 | */ |
| 1460 | public Notification() |
| 1461 | { |
| 1462 | this.when = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1463 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | * @hide |
| 1468 | */ |
| 1469 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 1470 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 1471 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1472 | new Builder(context) |
| 1473 | .setWhen(when) |
| 1474 | .setSmallIcon(icon) |
| 1475 | .setTicker(tickerText) |
| 1476 | .setContentTitle(contentTitle) |
| 1477 | .setContentText(contentText) |
| 1478 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 1479 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /** |
| 1483 | * Constructs a Notification object with the information needed to |
| 1484 | * have a status bar icon without the standard expanded view. |
| 1485 | * |
| 1486 | * @param icon The resource id of the icon to put in the status bar. |
| 1487 | * @param tickerText The text that flows by in the status bar when the notification first |
| 1488 | * activates. |
| 1489 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 1490 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1491 | * |
| 1492 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1494 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | public Notification(int icon, CharSequence tickerText, long when) |
| 1496 | { |
| 1497 | this.icon = icon; |
| 1498 | this.tickerText = tickerText; |
| 1499 | this.when = when; |
| 1500 | } |
| 1501 | |
| 1502 | /** |
| 1503 | * Unflatten the notification from a parcel. |
| 1504 | */ |
| 1505 | public Notification(Parcel parcel) |
| 1506 | { |
| 1507 | int version = parcel.readInt(); |
| 1508 | |
| 1509 | when = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1510 | if (parcel.readInt() != 0) { |
| 1511 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1512 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1513 | icon = mSmallIcon.getResId(); |
| 1514 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1515 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | number = parcel.readInt(); |
| 1517 | if (parcel.readInt() != 0) { |
| 1518 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1519 | } |
| 1520 | if (parcel.readInt() != 0) { |
| 1521 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1522 | } |
| 1523 | if (parcel.readInt() != 0) { |
| 1524 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1525 | } |
| 1526 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1527 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1528 | } |
| 1529 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1531 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1532 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1533 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1534 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1535 | defaults = parcel.readInt(); |
| 1536 | flags = parcel.readInt(); |
| 1537 | if (parcel.readInt() != 0) { |
| 1538 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 1539 | } |
| 1540 | |
| 1541 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1542 | if (parcel.readInt() != 0) { |
| 1543 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 1544 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | vibrate = parcel.createLongArray(); |
| 1546 | ledARGB = parcel.readInt(); |
| 1547 | ledOnMS = parcel.readInt(); |
| 1548 | ledOffMS = parcel.readInt(); |
| 1549 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1550 | |
| 1551 | if (parcel.readInt() != 0) { |
| 1552 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1553 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1554 | |
| 1555 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1556 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1557 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1558 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1559 | mGroupKey = parcel.readString(); |
| 1560 | |
| 1561 | mSortKey = parcel.readString(); |
| 1562 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1563 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1564 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1565 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 1566 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1567 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1568 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1569 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1570 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1571 | if (parcel.readInt() != 0) { |
| 1572 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1573 | } |
| 1574 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1575 | visibility = parcel.readInt(); |
| 1576 | |
| 1577 | if (parcel.readInt() != 0) { |
| 1578 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 1579 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1580 | |
| 1581 | color = parcel.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | } |
| 1583 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1584 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1585 | public Notification clone() { |
| 1586 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1587 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1588 | return that; |
| 1589 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1590 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1591 | /** |
| 1592 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 1593 | * of this into that. |
| 1594 | * @hide |
| 1595 | */ |
| 1596 | public void cloneInto(Notification that, boolean heavy) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1597 | that.when = this.when; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1598 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1599 | that.number = this.number; |
| 1600 | |
| 1601 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 1602 | that.contentIntent = this.contentIntent; |
| 1603 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1604 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1605 | |
| 1606 | if (this.tickerText != null) { |
| 1607 | that.tickerText = this.tickerText.toString(); |
| 1608 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1609 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1610 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1611 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1612 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1613 | that.contentView = this.contentView.clone(); |
| 1614 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1615 | if (heavy && this.mLargeIcon != null) { |
| 1616 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1617 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 1618 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1619 | that.sound = this.sound; // android.net.Uri is immutable |
| 1620 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1621 | if (this.audioAttributes != null) { |
| 1622 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 1623 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1624 | |
| 1625 | final long[] vibrate = this.vibrate; |
| 1626 | if (vibrate != null) { |
| 1627 | final int N = vibrate.length; |
| 1628 | final long[] vib = that.vibrate = new long[N]; |
| 1629 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 1630 | } |
| 1631 | |
| 1632 | that.ledARGB = this.ledARGB; |
| 1633 | that.ledOnMS = this.ledOnMS; |
| 1634 | that.ledOffMS = this.ledOffMS; |
| 1635 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1636 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1637 | that.flags = this.flags; |
| 1638 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1639 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1640 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1641 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1642 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1643 | that.mGroupKey = this.mGroupKey; |
| 1644 | |
| 1645 | that.mSortKey = this.mSortKey; |
| 1646 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1647 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1648 | try { |
| 1649 | that.extras = new Bundle(this.extras); |
| 1650 | // will unparcel |
| 1651 | that.extras.size(); |
| 1652 | } catch (BadParcelableException e) { |
| 1653 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 1654 | that.extras = null; |
| 1655 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1656 | } |
| 1657 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1658 | if (this.actions != null) { |
| 1659 | that.actions = new Action[this.actions.length]; |
| 1660 | for(int i=0; i<this.actions.length; i++) { |
| 1661 | that.actions[i] = this.actions[i].clone(); |
| 1662 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1663 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1664 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1665 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1666 | that.bigContentView = this.bigContentView.clone(); |
| 1667 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1668 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1669 | if (heavy && this.headsUpContentView != null) { |
| 1670 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 1671 | } |
| 1672 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1673 | that.visibility = this.visibility; |
| 1674 | |
| 1675 | if (this.publicVersion != null) { |
| 1676 | that.publicVersion = new Notification(); |
| 1677 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 1678 | } |
| 1679 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1680 | that.color = this.color; |
| 1681 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1682 | if (!heavy) { |
| 1683 | that.lightenPayload(); // will clean out extras |
| 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | /** |
| 1688 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 1689 | * listeners when the full contents are not necessary. |
| 1690 | * @hide |
| 1691 | */ |
| 1692 | public final void lightenPayload() { |
| 1693 | tickerView = null; |
| 1694 | contentView = null; |
| 1695 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1696 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1697 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 1698 | if (extras != null && !extras.isEmpty()) { |
| 1699 | final Set<String> keyset = extras.keySet(); |
| 1700 | final int N = keyset.size(); |
| 1701 | final String[] keys = keyset.toArray(new String[N]); |
| 1702 | for (int i=0; i<N; i++) { |
| 1703 | final String key = keys[i]; |
| 1704 | final Object obj = extras.get(key); |
| 1705 | if (obj != null && |
| 1706 | ( obj instanceof Parcelable |
| 1707 | || obj instanceof Parcelable[] |
| 1708 | || obj instanceof SparseArray |
| 1709 | || obj instanceof ArrayList)) { |
| 1710 | extras.remove(key); |
| 1711 | } |
| 1712 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1713 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1716 | /** |
| 1717 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 1718 | * means it had better not be some custom Parcelable implementation. |
| 1719 | * @hide |
| 1720 | */ |
| 1721 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 1722 | if (cs == null) return cs; |
| 1723 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 1724 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 1725 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1726 | if (cs instanceof Parcelable) { |
| 1727 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 1728 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 1729 | return cs.toString(); |
| 1730 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1731 | return removeTextSizeSpans(cs); |
| 1732 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1733 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1734 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 1735 | if (charSequence instanceof Spanned) { |
| 1736 | Spanned ss = (Spanned) charSequence; |
| 1737 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 1738 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 1739 | for (Object span : spans) { |
| 1740 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 1741 | if (resultSpan instanceof CharacterStyle) { |
| 1742 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 1743 | } |
| 1744 | if (resultSpan instanceof TextAppearanceSpan) { |
| 1745 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1746 | resultSpan = new TextAppearanceSpan( |
| 1747 | originalSpan.getFamily(), |
| 1748 | originalSpan.getTextStyle(), |
| 1749 | -1, |
| 1750 | originalSpan.getTextColor(), |
| 1751 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 1752 | } else if (resultSpan instanceof RelativeSizeSpan |
| 1753 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1754 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 1755 | } else { |
| 1756 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1757 | } |
| 1758 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 1759 | ss.getSpanFlags(span)); |
| 1760 | } |
| 1761 | return builder; |
| 1762 | } |
| 1763 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1764 | } |
| 1765 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1766 | public int describeContents() { |
| 1767 | return 0; |
| 1768 | } |
| 1769 | |
| 1770 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1771 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1772 | */ |
| 1773 | public void writeToParcel(Parcel parcel, int flags) |
| 1774 | { |
| 1775 | parcel.writeInt(1); |
| 1776 | |
| 1777 | parcel.writeLong(when); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1778 | if (mSmallIcon == null && icon != 0) { |
| 1779 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1780 | mSmallIcon = Icon.createWithResource("", icon); |
| 1781 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1782 | if (mSmallIcon != null) { |
| 1783 | parcel.writeInt(1); |
| 1784 | mSmallIcon.writeToParcel(parcel, 0); |
| 1785 | } else { |
| 1786 | parcel.writeInt(0); |
| 1787 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | parcel.writeInt(number); |
| 1789 | if (contentIntent != null) { |
| 1790 | parcel.writeInt(1); |
| 1791 | contentIntent.writeToParcel(parcel, 0); |
| 1792 | } else { |
| 1793 | parcel.writeInt(0); |
| 1794 | } |
| 1795 | if (deleteIntent != null) { |
| 1796 | parcel.writeInt(1); |
| 1797 | deleteIntent.writeToParcel(parcel, 0); |
| 1798 | } else { |
| 1799 | parcel.writeInt(0); |
| 1800 | } |
| 1801 | if (tickerText != null) { |
| 1802 | parcel.writeInt(1); |
| 1803 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 1804 | } else { |
| 1805 | parcel.writeInt(0); |
| 1806 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1807 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1808 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1809 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1810 | } else { |
| 1811 | parcel.writeInt(0); |
| 1812 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1813 | if (contentView != null) { |
| 1814 | parcel.writeInt(1); |
| 1815 | contentView.writeToParcel(parcel, 0); |
| 1816 | } else { |
| 1817 | parcel.writeInt(0); |
| 1818 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1819 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1820 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1821 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1822 | } else { |
| 1823 | parcel.writeInt(0); |
| 1824 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1825 | |
| 1826 | parcel.writeInt(defaults); |
| 1827 | parcel.writeInt(this.flags); |
| 1828 | |
| 1829 | if (sound != null) { |
| 1830 | parcel.writeInt(1); |
| 1831 | sound.writeToParcel(parcel, 0); |
| 1832 | } else { |
| 1833 | parcel.writeInt(0); |
| 1834 | } |
| 1835 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1836 | |
| 1837 | if (audioAttributes != null) { |
| 1838 | parcel.writeInt(1); |
| 1839 | audioAttributes.writeToParcel(parcel, 0); |
| 1840 | } else { |
| 1841 | parcel.writeInt(0); |
| 1842 | } |
| 1843 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1844 | parcel.writeLongArray(vibrate); |
| 1845 | parcel.writeInt(ledARGB); |
| 1846 | parcel.writeInt(ledOnMS); |
| 1847 | parcel.writeInt(ledOffMS); |
| 1848 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1849 | |
| 1850 | if (fullScreenIntent != null) { |
| 1851 | parcel.writeInt(1); |
| 1852 | fullScreenIntent.writeToParcel(parcel, 0); |
| 1853 | } else { |
| 1854 | parcel.writeInt(0); |
| 1855 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1856 | |
| 1857 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1858 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1859 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1860 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1861 | parcel.writeString(mGroupKey); |
| 1862 | |
| 1863 | parcel.writeString(mSortKey); |
| 1864 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1865 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1866 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1867 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1868 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1869 | if (bigContentView != null) { |
| 1870 | parcel.writeInt(1); |
| 1871 | bigContentView.writeToParcel(parcel, 0); |
| 1872 | } else { |
| 1873 | parcel.writeInt(0); |
| 1874 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1875 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1876 | if (headsUpContentView != null) { |
| 1877 | parcel.writeInt(1); |
| 1878 | headsUpContentView.writeToParcel(parcel, 0); |
| 1879 | } else { |
| 1880 | parcel.writeInt(0); |
| 1881 | } |
| 1882 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1883 | parcel.writeInt(visibility); |
| 1884 | |
| 1885 | if (publicVersion != null) { |
| 1886 | parcel.writeInt(1); |
| 1887 | publicVersion.writeToParcel(parcel, 0); |
| 1888 | } else { |
| 1889 | parcel.writeInt(0); |
| 1890 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1891 | |
| 1892 | parcel.writeInt(color); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | /** |
| 1896 | * Parcelable.Creator that instantiates Notification objects |
| 1897 | */ |
| 1898 | public static final Parcelable.Creator<Notification> CREATOR |
| 1899 | = new Parcelable.Creator<Notification>() |
| 1900 | { |
| 1901 | public Notification createFromParcel(Parcel parcel) |
| 1902 | { |
| 1903 | return new Notification(parcel); |
| 1904 | } |
| 1905 | |
| 1906 | public Notification[] newArray(int size) |
| 1907 | { |
| 1908 | return new Notification[size]; |
| 1909 | } |
| 1910 | }; |
| 1911 | |
| 1912 | /** |
| 1913 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 1914 | * layout. |
| 1915 | * |
| 1916 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 1917 | * in the view.</p> |
| 1918 | * @param context The context for your application / activity. |
| 1919 | * @param contentTitle The title that goes in the expanded entry. |
| 1920 | * @param contentText The text that goes in the expanded entry. |
| 1921 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 1922 | * If this is an activity, it must include the |
| 1923 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 1924 | * that you take care of task management as described in the |
| 1925 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 1926 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1927 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1928 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 1929 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1930 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1931 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | public void setLatestEventInfo(Context context, |
| 1933 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1934 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 1935 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 1936 | new Throwable()); |
| 1937 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1938 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1939 | // ensure that any information already set directly is preserved |
| 1940 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1941 | |
| 1942 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1944 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1945 | } |
| 1946 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1947 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1948 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1949 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1950 | |
| 1951 | 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] | 1952 | } |
| 1953 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 1954 | /** |
| 1955 | * @hide |
| 1956 | */ |
| 1957 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 1958 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, |
| 1959 | context.getApplicationInfo()); |
| 1960 | notification.extras.putInt(EXTRA_ORIGINATING_USERID, context.getUserId()); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 1961 | } |
| 1962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1963 | @Override |
| 1964 | public String toString() { |
| 1965 | StringBuilder sb = new StringBuilder(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1966 | sb.append("Notification(pri="); |
| 1967 | sb.append(priority); |
| 1968 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 1969 | if (contentView != null) { |
| 1970 | sb.append(contentView.getPackage()); |
| 1971 | sb.append("/0x"); |
| 1972 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 1973 | } else { |
| 1974 | sb.append("null"); |
| 1975 | } |
| 1976 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1977 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 1978 | sb.append("default"); |
| 1979 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | int N = this.vibrate.length-1; |
| 1981 | sb.append("["); |
| 1982 | for (int i=0; i<N; i++) { |
| 1983 | sb.append(this.vibrate[i]); |
| 1984 | sb.append(','); |
| 1985 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 1986 | if (N != -1) { |
| 1987 | sb.append(this.vibrate[N]); |
| 1988 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1989 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | } else { |
| 1991 | sb.append("null"); |
| 1992 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1993 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1994 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1995 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1996 | } else if (this.sound != null) { |
| 1997 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1998 | } else { |
| 1999 | sb.append("null"); |
| 2000 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 2001 | if (this.tickerText != null) { |
| 2002 | sb.append(" tick"); |
| 2003 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2004 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2005 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2006 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2007 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2008 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2009 | if (this.category != null) { |
| 2010 | sb.append(" category="); |
| 2011 | sb.append(this.category); |
| 2012 | } |
| 2013 | if (this.mGroupKey != null) { |
| 2014 | sb.append(" groupKey="); |
| 2015 | sb.append(this.mGroupKey); |
| 2016 | } |
| 2017 | if (this.mSortKey != null) { |
| 2018 | sb.append(" sortKey="); |
| 2019 | sb.append(this.mSortKey); |
| 2020 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2021 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2022 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2023 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2024 | } |
| 2025 | sb.append(" vis="); |
| 2026 | sb.append(visibilityToString(this.visibility)); |
| 2027 | if (this.publicVersion != null) { |
| 2028 | sb.append(" publicVersion="); |
| 2029 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2030 | } |
| 2031 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2032 | return sb.toString(); |
| 2033 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2034 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2035 | /** |
| 2036 | * {@hide} |
| 2037 | */ |
| 2038 | public static String visibilityToString(int vis) { |
| 2039 | switch (vis) { |
| 2040 | case VISIBILITY_PRIVATE: |
| 2041 | return "PRIVATE"; |
| 2042 | case VISIBILITY_PUBLIC: |
| 2043 | return "PUBLIC"; |
| 2044 | case VISIBILITY_SECRET: |
| 2045 | return "SECRET"; |
| 2046 | default: |
| 2047 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 2048 | } |
| 2049 | } |
| 2050 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2051 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 2052 | * {@hide} |
| 2053 | */ |
| 2054 | public static String priorityToString(@Priority int pri) { |
| 2055 | switch (pri) { |
| 2056 | case PRIORITY_MIN: |
| 2057 | return "MIN"; |
| 2058 | case PRIORITY_LOW: |
| 2059 | return "LOW"; |
| 2060 | case PRIORITY_DEFAULT: |
| 2061 | return "DEFAULT"; |
| 2062 | case PRIORITY_HIGH: |
| 2063 | return "HIGH"; |
| 2064 | case PRIORITY_MAX: |
| 2065 | return "MAX"; |
| 2066 | default: |
| 2067 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2072 | * The small icon representing this notification in the status bar and content view. |
| 2073 | * |
| 2074 | * @return the small icon representing this notification. |
| 2075 | * |
| 2076 | * @see Builder#getSmallIcon() |
| 2077 | * @see Builder#setSmallIcon(Icon) |
| 2078 | */ |
| 2079 | public Icon getSmallIcon() { |
| 2080 | return mSmallIcon; |
| 2081 | } |
| 2082 | |
| 2083 | /** |
| 2084 | * Used when notifying to clean up legacy small icons. |
| 2085 | * @hide |
| 2086 | */ |
| 2087 | public void setSmallIcon(Icon icon) { |
| 2088 | mSmallIcon = icon; |
| 2089 | } |
| 2090 | |
| 2091 | /** |
| 2092 | * The large icon shown in this notification's content view. |
| 2093 | * @see Builder#getLargeIcon() |
| 2094 | * @see Builder#setLargeIcon(Icon) |
| 2095 | */ |
| 2096 | public Icon getLargeIcon() { |
| 2097 | return mLargeIcon; |
| 2098 | } |
| 2099 | |
| 2100 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2101 | * @hide |
| 2102 | */ |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 2103 | public boolean isGroupSummary() { |
| 2104 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 2105 | } |
| 2106 | |
| 2107 | /** |
| 2108 | * @hide |
| 2109 | */ |
| 2110 | public boolean isGroupChild() { |
| 2111 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 2112 | } |
| 2113 | |
| 2114 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2115 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2116 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2117 | * 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] | 2118 | * content views using the platform's notification layout template. If your app supports |
| 2119 | * versions of Android as old as API level 4, you can instead use |
| 2120 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 2121 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 2122 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2123 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2124 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2125 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2126 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2127 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2128 | * .setContentTitle("New mail from " + sender.toString()) |
| 2129 | * .setContentText(subject) |
| 2130 | * .setSmallIcon(R.drawable.new_mail) |
| 2131 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2132 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2133 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2134 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2135 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 2136 | /** |
| 2137 | * @hide |
| 2138 | */ |
| 2139 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 2140 | "android.rebuild.contentViewActionCount"; |
| 2141 | /** |
| 2142 | * @hide |
| 2143 | */ |
| 2144 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 2145 | = "android.rebuild.bigViewActionCount"; |
| 2146 | /** |
| 2147 | * @hide |
| 2148 | */ |
| 2149 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 2150 | = "android.rebuild.hudViewActionCount"; |
| 2151 | |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 2152 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2153 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2154 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2155 | private Notification mN; |
| 2156 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2157 | private Style mStyle; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2158 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
| 2159 | private ArrayList<String> mPersonList = new ArrayList<String>(); |
| 2160 | private NotificationColorUtil mColorUtil; |
| 2161 | private boolean mColorUtilInited = false; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2162 | |
| 2163 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2164 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 2165 | */ |
| 2166 | private int mCachedContrastColor = COLOR_INVALID; |
| 2167 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
| 2168 | |
| 2169 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2170 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2171 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2172 | |
| 2173 | * <table> |
| 2174 | * <tr><th align=right>priority</th> |
| 2175 | * <td>{@link #PRIORITY_DEFAULT}</td></tr> |
| 2176 | * <tr><th align=right>when</th> |
| 2177 | * <td>now ({@link System#currentTimeMillis()})</td></tr> |
| 2178 | * <tr><th align=right>audio stream</th> |
| 2179 | * <td>{@link #STREAM_DEFAULT}</td></tr> |
| 2180 | * </table> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2181 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2182 | |
| 2183 | * @param context |
| 2184 | * A {@link Context} that will be used by the Builder to construct the |
| 2185 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 2186 | * object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2187 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2188 | public Builder(Context context) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2189 | this(context, null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2190 | } |
| 2191 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2192 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2193 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2194 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2195 | public Builder(Context context, Notification toAdopt) { |
| 2196 | mContext = context; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2197 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2198 | if (toAdopt == null) { |
| 2199 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 2200 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2201 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2202 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2203 | mN.priority = PRIORITY_DEFAULT; |
| 2204 | mN.visibility = VISIBILITY_PRIVATE; |
| 2205 | } else { |
| 2206 | mN = toAdopt; |
| 2207 | if (mN.actions != null) { |
| 2208 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2209 | } |
| 2210 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2211 | if (mN.extras.containsKey(EXTRA_PEOPLE)) { |
| 2212 | Collections.addAll(mPersonList, mN.extras.getStringArray(EXTRA_PEOPLE)); |
| 2213 | } |
| 2214 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2215 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 2216 | if (!TextUtils.isEmpty(templateClass)) { |
| 2217 | final Class<? extends Style> styleClass |
| 2218 | = getNotificationStyleClass(templateClass); |
| 2219 | if (styleClass == null) { |
| 2220 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 2221 | } else { |
| 2222 | try { |
| 2223 | final Constructor<? extends Style> ctor = styleClass.getConstructor(); |
| 2224 | ctor.setAccessible(true); |
| 2225 | final Style style = ctor.newInstance(); |
| 2226 | style.restoreFromExtras(mN.extras); |
| 2227 | |
| 2228 | if (style != null) { |
| 2229 | setStyle(style); |
| 2230 | } |
| 2231 | } catch (Throwable t) { |
| 2232 | Log.e(TAG, "Could not create Style", t); |
| 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | private NotificationColorUtil getColorUtil() { |
| 2241 | if (!mColorUtilInited) { |
| 2242 | mColorUtilInited = true; |
| 2243 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.LOLLIPOP) { |
| 2244 | mColorUtil = NotificationColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2245 | } |
| 2246 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2247 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2251 | * 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] | 2252 | * |
| 2253 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 2254 | * shown anymore by default and must be opted into by using |
| 2255 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2256 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2257 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2258 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2259 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2260 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2261 | return this; |
| 2262 | } |
| 2263 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2264 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2265 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2266 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 2267 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 2268 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2269 | */ |
| 2270 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2271 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2272 | return this; |
| 2273 | } |
| 2274 | |
| 2275 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2276 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2277 | * |
| 2278 | * 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] | 2279 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2280 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2281 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 2282 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2283 | * The counter can also be set to count down to <code>when</code> when using |
| 2284 | * {@link #setChronometerCountsDown(boolean)}. |
| 2285 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2286 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2287 | * @see Notification#when |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2288 | * @see #setChronometerCountsDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2289 | */ |
| 2290 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2291 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2292 | return this; |
| 2293 | } |
| 2294 | |
| 2295 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2296 | * Sets the Chronometer to count down instead of counting up. |
| 2297 | * |
| 2298 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 2299 | * If it isn't set the chronometer will count up. |
| 2300 | * |
| 2301 | * @see #setUsesChronometer(boolean) |
| 2302 | */ |
| 2303 | public Builder setChronometerCountsDown(boolean countsDown) { |
| 2304 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN, countsDown); |
| 2305 | return this; |
| 2306 | } |
| 2307 | |
| 2308 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2309 | * Set the small icon resource, which will be used to represent the notification in the |
| 2310 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2311 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2312 | |
| 2313 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 2314 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 2315 | * icon will be moved to the right-hand side. |
| 2316 | * |
| 2317 | |
| 2318 | * @param icon |
| 2319 | * A resource ID in the application's package of the drawable to use. |
| 2320 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2321 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2322 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2323 | return setSmallIcon(icon != 0 |
| 2324 | ? Icon.createWithResource(mContext, icon) |
| 2325 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2326 | } |
| 2327 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2328 | /** |
| 2329 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 2330 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 2331 | * LevelListDrawable}. |
| 2332 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2333 | * @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] | 2334 | * @param level The level to use for the icon. |
| 2335 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2336 | * @see Notification#icon |
| 2337 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2338 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2339 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2340 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2341 | return setSmallIcon(icon); |
| 2342 | } |
| 2343 | |
| 2344 | /** |
| 2345 | * Set the small icon, which will be used to represent the notification in the |
| 2346 | * status bar and content view (unless overriden there by a |
| 2347 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 2348 | * |
| 2349 | * @param icon An Icon object to use. |
| 2350 | * @see Notification#icon |
| 2351 | */ |
| 2352 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2353 | mN.setSmallIcon(icon); |
| 2354 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 2355 | mN.icon = icon.getResId(); |
| 2356 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2357 | return this; |
| 2358 | } |
| 2359 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2360 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2361 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2362 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2363 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2364 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2365 | return this; |
| 2366 | } |
| 2367 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2368 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2369 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2370 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2371 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2372 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2373 | return this; |
| 2374 | } |
| 2375 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2376 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 2377 | * This provides some additional information that is displayed in the notification. No |
| 2378 | * guarantees are given where exactly it is displayed. |
| 2379 | * |
| 2380 | * <p>This information should only be provided if it provides an essential |
| 2381 | * benefit to the understanding of the notification. The more text you provide the |
| 2382 | * less readable it becomes. For example, an email client should only provide the account |
| 2383 | * name here if more than one email account has been added.</p> |
| 2384 | * |
| 2385 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 2386 | * notification header area. |
| 2387 | * |
| 2388 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 2389 | * this will be shown in the third line of text in the platform notification template. |
| 2390 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 2391 | * same time on those versions; they occupy the same place. |
| 2392 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2393 | */ |
| 2394 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2395 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2396 | return this; |
| 2397 | } |
| 2398 | |
| 2399 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 2400 | * Set the remote input history. |
| 2401 | * |
| 2402 | * This should be set to the most recent inputs that have been sent |
| 2403 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 2404 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 2405 | * |
| 2406 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 2407 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 2408 | * and how much of each individual input is shown. |
| 2409 | * |
| 2410 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 2411 | * with a {@code RemoteInput}.</p> |
| 2412 | */ |
| 2413 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 2414 | if (text == null) { |
| 2415 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 2416 | } else { |
| 2417 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 2418 | CharSequence[] safe = new CharSequence[N]; |
| 2419 | for (int i = 0; i < N; i++) { |
| 2420 | safe[i] = safeCharSequence(text[i]); |
| 2421 | } |
| 2422 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 2423 | } |
| 2424 | return this; |
| 2425 | } |
| 2426 | |
| 2427 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2428 | * Set the large number at the right-hand side of the notification. This is |
| 2429 | * equivalent to setContentInfo, although it might show the number in a different |
| 2430 | * font size for readability. |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 2431 | * |
| 2432 | * @deprecated this number is not shown anywhere anymore |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2433 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2434 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2435 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2436 | return this; |
| 2437 | } |
| 2438 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2439 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2440 | * A small piece of additional information pertaining to this notification. |
| 2441 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2442 | * The platform template will draw this on the last line of the notification, at the far |
| 2443 | * 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] | 2444 | * |
| 2445 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 2446 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 2447 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2448 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2449 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2450 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2451 | return this; |
| 2452 | } |
| 2453 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2454 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2455 | * Set the progress this notification represents. |
| 2456 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2457 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2458 | */ |
| 2459 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2460 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 2461 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 2462 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2463 | return this; |
| 2464 | } |
| 2465 | |
| 2466 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2467 | * Supply a custom RemoteViews to use instead of the platform template. |
| 2468 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2469 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2470 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2471 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2472 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2473 | return setCustomContentView(views); |
| 2474 | } |
| 2475 | |
| 2476 | /** |
| 2477 | * Supply custom RemoteViews to use instead of the platform template. |
| 2478 | * |
| 2479 | * This will override the layout that would otherwise be constructed by this Builder |
| 2480 | * object. |
| 2481 | */ |
| 2482 | public Builder setCustomContentView(RemoteViews contentView) { |
| 2483 | mN.contentView = contentView; |
| 2484 | return this; |
| 2485 | } |
| 2486 | |
| 2487 | /** |
| 2488 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 2489 | * |
| 2490 | * This will override the expanded layout that would otherwise be constructed by this |
| 2491 | * Builder object. |
| 2492 | */ |
| 2493 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 2494 | mN.bigContentView = contentView; |
| 2495 | return this; |
| 2496 | } |
| 2497 | |
| 2498 | /** |
| 2499 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 2500 | * |
| 2501 | * This will override the heads-up layout that would otherwise be constructed by this |
| 2502 | * Builder object. |
| 2503 | */ |
| 2504 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 2505 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2506 | return this; |
| 2507 | } |
| 2508 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2509 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2510 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 2511 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2512 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 2513 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 2514 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2515 | * 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] | 2516 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2517 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2518 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2519 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2520 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2521 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2522 | return this; |
| 2523 | } |
| 2524 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2525 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2526 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 2527 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2528 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2529 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2530 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2531 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2532 | return this; |
| 2533 | } |
| 2534 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2535 | /** |
| 2536 | * An intent to launch instead of posting the notification to the status bar. |
| 2537 | * Only for use with extremely high-priority notifications demanding the user's |
| 2538 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 2539 | * alarm clock that the user has explicitly set to a particular time. |
| 2540 | * If this facility is used for something else, please give the user an option |
| 2541 | * to turn it off and use a normal notification, as this can be extremely |
| 2542 | * disruptive. |
| 2543 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2544 | * <p> |
| 2545 | * The system UI may choose to display a heads-up notification, instead of |
| 2546 | * launching this intent, while the user is using the device. |
| 2547 | * </p> |
| 2548 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2549 | * @param intent The pending intent to launch. |
| 2550 | * @param highPriority Passing true will cause this notification to be sent |
| 2551 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2552 | * |
| 2553 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2554 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2555 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2556 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2557 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 2558 | return this; |
| 2559 | } |
| 2560 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2561 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2562 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2563 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2564 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2565 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2566 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2567 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2568 | return this; |
| 2569 | } |
| 2570 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2571 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2572 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2573 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2574 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2575 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2576 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2577 | setTicker(tickerText); |
| 2578 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2579 | return this; |
| 2580 | } |
| 2581 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2582 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2583 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2584 | * |
| 2585 | * 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] | 2586 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 2587 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2588 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2589 | public Builder setLargeIcon(Bitmap b) { |
| 2590 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 2591 | } |
| 2592 | |
| 2593 | /** |
| 2594 | * Add a large icon to the notification content view. |
| 2595 | * |
| 2596 | * In the platform template, this image will be shown on the left of the notification view |
| 2597 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 2598 | * badge atop the large icon). |
| 2599 | */ |
| 2600 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2601 | mN.mLargeIcon = icon; |
| 2602 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2603 | return this; |
| 2604 | } |
| 2605 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2606 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2607 | * Set the sound to play. |
| 2608 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2609 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 2610 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2611 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2612 | * <p> |
| 2613 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2614 | * </p> |
| 2615 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2616 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2617 | */ |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 2618 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2619 | mN.sound = sound; |
| 2620 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 2621 | return this; |
| 2622 | } |
| 2623 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2624 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2625 | * 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] | 2626 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2627 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 2628 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2629 | * <p> |
| 2630 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2631 | * </p> |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2632 | * @deprecated use {@link #setSound(Uri, AudioAttributes)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2633 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2634 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 2635 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2636 | public Builder setSound(Uri sound, int streamType) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2637 | mN.sound = sound; |
| 2638 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2639 | return this; |
| 2640 | } |
| 2641 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2642 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2643 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 2644 | * use during playback. |
| 2645 | * |
| 2646 | * <p> |
| 2647 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2648 | * </p> |
| 2649 | * |
| 2650 | * @see Notification#sound |
| 2651 | */ |
| 2652 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2653 | mN.sound = sound; |
| 2654 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2655 | return this; |
| 2656 | } |
| 2657 | |
| 2658 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2659 | * Set the vibration pattern to use. |
| 2660 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2661 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 2662 | * <code>pattern</code> parameter. |
| 2663 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2664 | * <p> |
| 2665 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 2666 | * </p> |
| 2667 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2668 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2669 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2670 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2671 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2672 | return this; |
| 2673 | } |
| 2674 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2675 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2676 | * Set the desired color for the indicator LED on the device, as well as the |
| 2677 | * blink duty cycle (specified in milliseconds). |
| 2678 | * |
| 2679 | |
| 2680 | * Not all devices will honor all (or even any) of these values. |
| 2681 | * |
| 2682 | |
| 2683 | * @see Notification#ledARGB |
| 2684 | * @see Notification#ledOnMS |
| 2685 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2686 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 2687 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2688 | mN.ledARGB = argb; |
| 2689 | mN.ledOnMS = onMs; |
| 2690 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 2691 | if (onMs != 0 || offMs != 0) { |
| 2692 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 2693 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2694 | return this; |
| 2695 | } |
| 2696 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2697 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2698 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2699 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2700 | |
| 2701 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 2702 | * must take care of canceling them. |
| 2703 | * |
| 2704 | |
| 2705 | * They are typically used to indicate a background task that the user is actively engaged |
| 2706 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 2707 | * (e.g., a file download, sync operation, active network connection). |
| 2708 | * |
| 2709 | |
| 2710 | * @see Notification#FLAG_ONGOING_EVENT |
| 2711 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2712 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2713 | public Builder setOngoing(boolean ongoing) { |
| 2714 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 2715 | return this; |
| 2716 | } |
| 2717 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2718 | /** |
| 2719 | * Set this flag if you would only like the sound, vibrate |
| 2720 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2721 | * |
| 2722 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2723 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2724 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 2725 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 2726 | return this; |
| 2727 | } |
| 2728 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2729 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2730 | * Make this notification automatically dismissed when the user touches it. The |
| 2731 | * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens. |
| 2732 | * |
| 2733 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2734 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2735 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 2736 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2737 | return this; |
| 2738 | } |
| 2739 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2740 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 2741 | * Set whether or not this notification should not bridge to other devices. |
| 2742 | * |
| 2743 | * <p>Some notifications can be bridged to other devices for remote display. |
| 2744 | * This hint can be set to recommend this notification not be bridged. |
| 2745 | */ |
| 2746 | public Builder setLocalOnly(boolean localOnly) { |
| 2747 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 2748 | return this; |
| 2749 | } |
| 2750 | |
| 2751 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2752 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2753 | * <p> |
| 2754 | * The value should be one or more of the following fields combined with |
| 2755 | * bitwise-or: |
| 2756 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 2757 | * <p> |
| 2758 | * For all default values, use {@link #DEFAULT_ALL}. |
| 2759 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2760 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2761 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2762 | return this; |
| 2763 | } |
| 2764 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2765 | /** |
| 2766 | * Set the priority of this notification. |
| 2767 | * |
| 2768 | * @see Notification#priority |
| 2769 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2770 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2771 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2772 | return this; |
| 2773 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2774 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2775 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2776 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2777 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2778 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2779 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2780 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2781 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2782 | return this; |
| 2783 | } |
| 2784 | |
| 2785 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2786 | * Add a person that is relevant to this notification. |
| 2787 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 2788 | * <P> |
| 2789 | * Depending on user preferences, this annotation may allow the notification to pass |
| 2790 | * through interruption filters, and to appear more prominently in the user interface. |
| 2791 | * </P> |
| 2792 | * |
| 2793 | * <P> |
| 2794 | * The person should be specified by the {@code String} representation of a |
| 2795 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 2796 | * </P> |
| 2797 | * |
| 2798 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 2799 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 2800 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 2801 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
| 2802 | * </P> |
| 2803 | * |
| 2804 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2805 | * @see Notification#EXTRA_PEOPLE |
| 2806 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 2807 | public Builder addPerson(String uri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2808 | mPersonList.add(uri); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2809 | return this; |
| 2810 | } |
| 2811 | |
| 2812 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2813 | * Set this notification to be part of a group of notifications sharing the same key. |
| 2814 | * Grouped notifications may display in a cluster or stack on devices which |
| 2815 | * support such rendering. |
| 2816 | * |
| 2817 | * <p>To make this notification the summary for its group, also call |
| 2818 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 2819 | * {@link #setSortKey}. |
| 2820 | * @param groupKey The group key of the group. |
| 2821 | * @return this object for method chaining |
| 2822 | */ |
| 2823 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2824 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2825 | return this; |
| 2826 | } |
| 2827 | |
| 2828 | /** |
| 2829 | * Set this notification to be the group summary for a group of notifications. |
| 2830 | * Grouped notifications may display in a cluster or stack on devices which |
| 2831 | * support such rendering. Requires a group key also be set using {@link #setGroup}. |
| 2832 | * @param isGroupSummary Whether this notification should be a group summary. |
| 2833 | * @return this object for method chaining |
| 2834 | */ |
| 2835 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 2836 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 2837 | return this; |
| 2838 | } |
| 2839 | |
| 2840 | /** |
| 2841 | * Set a sort key that orders this notification among other notifications from the |
| 2842 | * same package. This can be useful if an external sort was already applied and an app |
| 2843 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 2844 | * value, although providing different priorities in addition to providing sort key may |
| 2845 | * cause this value to be ignored. |
| 2846 | * |
| 2847 | * <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] | 2848 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2849 | * |
| 2850 | * @see String#compareTo(String) |
| 2851 | */ |
| 2852 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2853 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2854 | return this; |
| 2855 | } |
| 2856 | |
| 2857 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2858 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2859 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2860 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 2861 | * |
| 2862 | * @see Notification#extras |
| 2863 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2864 | public Builder addExtras(Bundle extras) { |
| 2865 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2866 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2867 | } |
| 2868 | return this; |
| 2869 | } |
| 2870 | |
| 2871 | /** |
| 2872 | * Set metadata for this notification. |
| 2873 | * |
| 2874 | * <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] | 2875 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2876 | * called. |
| 2877 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2878 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 2879 | * Use {@link #addExtras} to merge in metadata instead. |
| 2880 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2881 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2882 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2883 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2884 | if (extras != null) { |
| 2885 | mUserExtras = extras; |
| 2886 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2887 | return this; |
| 2888 | } |
| 2889 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2890 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2891 | * Get the current metadata Bundle used by this notification Builder. |
| 2892 | * |
| 2893 | * <p>The returned Bundle is shared with this Builder. |
| 2894 | * |
| 2895 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 2896 | * {@link #build()} is called. |
| 2897 | * |
| 2898 | * @see Notification#extras |
| 2899 | */ |
| 2900 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2901 | return mUserExtras; |
| 2902 | } |
| 2903 | |
| 2904 | private Bundle getAllExtras() { |
| 2905 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 2906 | saveExtras.putAll(mN.extras); |
| 2907 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2911 | * Add an action to this notification. Actions are typically displayed by |
| 2912 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2913 | * <p> |
| 2914 | * Every action must have an icon (32dp square and matching the |
| 2915 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2916 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2917 | * <p> |
| 2918 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2919 | * the order they were added. Actions will not be displayed when the notification is |
| 2920 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2921 | * 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] | 2922 | * |
| 2923 | * @param icon Resource ID of a drawable that represents the action. |
| 2924 | * @param title Text describing the action. |
| 2925 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 2926 | * |
| 2927 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2928 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 2929 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2930 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2931 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2932 | return this; |
| 2933 | } |
| 2934 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2935 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2936 | * Add an action to this notification. Actions are typically displayed by |
| 2937 | * the system as a button adjacent to the notification content. |
| 2938 | * <p> |
| 2939 | * Every action must have an icon (32dp square and matching the |
| 2940 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2941 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2942 | * <p> |
| 2943 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2944 | * the order they were added. Actions will not be displayed when the notification is |
| 2945 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2946 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 2947 | * |
| 2948 | * @param action The action to add. |
| 2949 | */ |
| 2950 | public Builder addAction(Action action) { |
| 2951 | mActions.add(action); |
| 2952 | return this; |
| 2953 | } |
| 2954 | |
| 2955 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2956 | * Alter the complete list of actions attached to this notification. |
| 2957 | * @see #addAction(Action). |
| 2958 | * |
| 2959 | * @param actions |
| 2960 | * @return |
| 2961 | */ |
| 2962 | public Builder setActions(Action... actions) { |
| 2963 | mActions.clear(); |
| 2964 | for (int i = 0; i < actions.length; i++) { |
| 2965 | mActions.add(actions[i]); |
| 2966 | } |
| 2967 | return this; |
| 2968 | } |
| 2969 | |
| 2970 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2971 | * Add a rich notification style to be applied at build time. |
| 2972 | * |
| 2973 | * @param style Object responsible for modifying the notification style. |
| 2974 | */ |
| 2975 | public Builder setStyle(Style style) { |
| 2976 | if (mStyle != style) { |
| 2977 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2978 | if (mStyle != null) { |
| 2979 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2980 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 2981 | } else { |
| 2982 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2983 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2984 | } |
| 2985 | return this; |
| 2986 | } |
| 2987 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2988 | /** |
| 2989 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2990 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2991 | * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default), |
| 2992 | * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}. |
| 2993 | * |
| 2994 | * @return The same Builder. |
| 2995 | */ |
| 2996 | public Builder setVisibility(int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2997 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2998 | return this; |
| 2999 | } |
| 3000 | |
| 3001 | /** |
| 3002 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 3003 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 3004 | * @param n A replacement notification, presumably with some or all info redacted. |
| 3005 | * @return The same Builder. |
| 3006 | */ |
| 3007 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3008 | if (n != null) { |
| 3009 | mN.publicVersion = new Notification(); |
| 3010 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 3011 | } else { |
| 3012 | mN.publicVersion = null; |
| 3013 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3014 | return this; |
| 3015 | } |
| 3016 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 3017 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3018 | * Apply an extender to this notification builder. Extenders may be used to add |
| 3019 | * metadata or change options on this builder. |
| 3020 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 3021 | public Builder extend(Extender extender) { |
| 3022 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3023 | return this; |
| 3024 | } |
| 3025 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 3026 | /** |
| 3027 | * @hide |
| 3028 | */ |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 3029 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3030 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3031 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3032 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3033 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3034 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 3035 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3036 | } |
| 3037 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3038 | /** |
| 3039 | * Sets {@link Notification#color}. |
| 3040 | * |
| 3041 | * @param argb The accent color to use |
| 3042 | * |
| 3043 | * @return The same Builder. |
| 3044 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3045 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3046 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3047 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3048 | return this; |
| 3049 | } |
| 3050 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3051 | private Drawable getProfileBadgeDrawable() { |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3052 | // Note: This assumes that the current user can read the profile badge of the |
| 3053 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 3054 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 3055 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | private Bitmap getProfileBadge() { |
| 3059 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3060 | if (badge == null) { |
| 3061 | return null; |
| 3062 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3063 | final int size = mContext.getResources().getDimensionPixelSize( |
| 3064 | R.dimen.notification_badge_size); |
| 3065 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3066 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3067 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3068 | badge.draw(canvas); |
| 3069 | return bitmap; |
| 3070 | } |
| 3071 | |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3072 | private void bindProfileBadge(RemoteViews contentView) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3073 | Bitmap profileBadge = getProfileBadge(); |
| 3074 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3075 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3076 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 3077 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3078 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3079 | } |
| 3080 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3081 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3082 | resetNotificationHeader(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3083 | resetContentMargins(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3084 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3085 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3086 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3087 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3088 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3089 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3090 | contentView.setTextViewText(R.id.text_line_1, null); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3091 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3094 | /** |
| 3095 | * Resets the notification header to its original state |
| 3096 | */ |
| 3097 | private void resetNotificationHeader(RemoteViews contentView) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3098 | contentView.setImageViewResource(R.id.icon, 0); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 3099 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3100 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 3101 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3102 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
| 3103 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3104 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3105 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 3106 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3107 | } |
| 3108 | |
| 3109 | private void resetContentMargins(RemoteViews contentView) { |
| 3110 | contentView.setViewLayoutMarginEnd(R.id.line1, 0); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3111 | contentView.setViewLayoutMarginEnd(R.id.text, 0); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3112 | } |
| 3113 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3114 | private RemoteViews applyStandardTemplate(int resId) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3115 | return applyStandardTemplate(resId, true /* hasProgress */); |
| 3116 | } |
| 3117 | |
| 3118 | /** |
| 3119 | * @param hasProgress whether the progress bar should be shown and set |
| 3120 | */ |
| 3121 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3122 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 3123 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3124 | resetStandardTemplate(contentView); |
| 3125 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3126 | final Bundle ex = mN.extras; |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3127 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3128 | bindNotificationHeader(contentView); |
| 3129 | bindLargeIcon(contentView); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3130 | if (ex.getCharSequence(EXTRA_TITLE) != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3131 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3132 | contentView.setTextViewText(R.id.title, |
| 3133 | processLegacyText(ex.getCharSequence(EXTRA_TITLE))); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3134 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3135 | boolean showProgress = handleProgressBar(hasProgress, contentView, ex); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3136 | if (ex.getCharSequence(EXTRA_TEXT) != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3137 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 3138 | : com.android.internal.R.id.text; |
| 3139 | contentView.setTextViewText(textId, processLegacyText( |
| 3140 | ex.getCharSequence(EXTRA_TEXT))); |
| 3141 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3142 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3143 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3144 | setContentMinHeight(contentView, showProgress || mN.mLargeIcon != null); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3145 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3146 | return contentView; |
| 3147 | } |
| 3148 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3149 | /** |
| 3150 | * @param remoteView the remote view to update the minheight in |
| 3151 | * @param hasMinHeight does it have a mimHeight |
| 3152 | * @hide |
| 3153 | */ |
| 3154 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 3155 | int minHeight = 0; |
| 3156 | if (hasMinHeight) { |
| 3157 | // we need to set the minHeight of the notification |
| 3158 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 3159 | com.android.internal.R.dimen.notification_min_content_height); |
| 3160 | } |
| 3161 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 3162 | } |
| 3163 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3164 | private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3165 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 3166 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 3167 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 3168 | if (hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3169 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3170 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3171 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3172 | contentView.setProgressBackgroundTintList( |
| 3173 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 3174 | R.color.notification_progress_background_color))); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3175 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3176 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3177 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 3178 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3179 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3180 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3181 | } else { |
| 3182 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3183 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3184 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3185 | } |
| 3186 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3187 | private void bindLargeIcon(RemoteViews contentView) { |
| 3188 | if (mN.mLargeIcon != null) { |
| 3189 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 3190 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
| 3191 | processLargeLegacyIcon(mN.mLargeIcon, contentView); |
| 3192 | int endMargin = mContext.getResources().getDimensionPixelSize( |
| 3193 | R.dimen.notification_content_picture_margin); |
| 3194 | contentView.setViewLayoutMarginEnd(R.id.line1, endMargin); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3195 | contentView.setViewLayoutMarginEnd(R.id.text, endMargin); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3196 | contentView.setViewLayoutMarginEnd(R.id.progress, endMargin); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | private void bindNotificationHeader(RemoteViews contentView) { |
| 3201 | bindSmallIcon(contentView); |
| 3202 | bindHeaderAppName(contentView); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3203 | bindHeaderText(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3204 | bindHeaderChronometerAndTime(contentView); |
| 3205 | bindExpandButton(contentView); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3206 | bindProfileBadge(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | private void bindExpandButton(RemoteViews contentView) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3210 | contentView.setDrawableParameters(R.id.expand_button, false, -1, resolveContrastColor(), |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3211 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3212 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3213 | resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | private void bindHeaderChronometerAndTime(RemoteViews contentView) { |
| 3217 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3218 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3219 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 3220 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 3221 | contentView.setLong(R.id.chronometer, "setBase", |
| 3222 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 3223 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3224 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN); |
| 3225 | contentView.setChronometerCountsDown(R.id.chronometer, countsDown); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3226 | } else { |
| 3227 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 3228 | contentView.setLong(R.id.time, "setTime", mN.when); |
| 3229 | } |
| 3230 | } |
| 3231 | } |
| 3232 | |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3233 | private void bindHeaderText(RemoteViews contentView) { |
| 3234 | CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 3235 | if (headerText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3236 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3237 | headerText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3238 | } |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3239 | if (headerText == null |
| 3240 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 3241 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 3242 | headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 3243 | } |
| 3244 | if (headerText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3245 | // 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] | 3246 | contentView.setTextViewText(R.id.header_text, processLegacyText(headerText)); |
| 3247 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 3248 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | private void bindHeaderAppName(RemoteViews contentView) { |
Tony Mak | 4dc008c | 2016-03-16 10:46:49 +0000 | [diff] [blame] | 3253 | CharSequence appName = mContext.getPackageManager() |
| 3254 | .getApplicationLabel(mContext.getApplicationInfo()); |
| 3255 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3256 | if (TextUtils.isEmpty(appName)) { |
| 3257 | return; |
| 3258 | } |
| 3259 | contentView.setTextViewText(R.id.app_name_text, appName); |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3260 | contentView.setTextColor(R.id.app_name_text, resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | private void bindSmallIcon(RemoteViews contentView) { |
| 3264 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
| 3265 | processSmallIconColor(mN.mSmallIcon, contentView); |
| 3266 | } |
| 3267 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3268 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3269 | * @return true if the built notification will show the time or the chronometer; false |
| 3270 | * otherwise |
| 3271 | */ |
| 3272 | private boolean showsTimeOrChronometer() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3273 | return mN.when != 0 && mN.extras.getBoolean(EXTRA_SHOW_WHEN); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3274 | } |
| 3275 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3276 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 3277 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3278 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3279 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3280 | |
| 3281 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 3282 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
| 3283 | |
| 3284 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 3285 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 3286 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 3287 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3288 | } |
| 3289 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3290 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3291 | RemoteViews big = applyStandardTemplate(layoutId); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3292 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3293 | resetStandardTemplateWithActions(big); |
| 3294 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3295 | boolean validRemoteInput = false; |
| 3296 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3297 | int N = mActions.size(); |
| 3298 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 3299 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3300 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3301 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3302 | for (int i=0; i<N; i++) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3303 | Action action = mActions.get(i); |
| 3304 | validRemoteInput |= hasValidRemoteInput(action); |
| 3305 | |
| 3306 | final RemoteViews button = generateActionButton(action); |
Adrian Roos | 9b123cf | 2016-02-04 14:55:57 -0800 | [diff] [blame] | 3307 | if (i == N - 1) { |
| 3308 | button.setViewLayoutWidth(com.android.internal.R.id.action0, |
| 3309 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 3310 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3311 | big.addView(R.id.actions, button); |
| 3312 | } |
| 3313 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3314 | |
| 3315 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
| 3316 | if (validRemoteInput && replyText != null |
| 3317 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) { |
| 3318 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
| 3319 | big.setTextViewText(R.id.notification_material_reply_text_1, replyText[0]); |
| 3320 | |
| 3321 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) { |
| 3322 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
| 3323 | big.setTextViewText(R.id.notification_material_reply_text_2, replyText[1]); |
| 3324 | |
| 3325 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) { |
| 3326 | big.setViewVisibility( |
| 3327 | R.id.notification_material_reply_text_3, View.VISIBLE); |
| 3328 | big.setTextViewText(R.id.notification_material_reply_text_3, replyText[2]); |
| 3329 | } |
| 3330 | } |
| 3331 | } |
| 3332 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3333 | return big; |
| 3334 | } |
| 3335 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3336 | private boolean hasValidRemoteInput(Action action) { |
| 3337 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 3338 | // Weird actions |
| 3339 | return false; |
| 3340 | } |
| 3341 | |
| 3342 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 3343 | if (remoteInputs == null) { |
| 3344 | return false; |
| 3345 | } |
| 3346 | |
| 3347 | for (RemoteInput r : remoteInputs) { |
| 3348 | CharSequence[] choices = r.getChoices(); |
| 3349 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 3350 | return true; |
| 3351 | } |
| 3352 | } |
| 3353 | return false; |
| 3354 | } |
| 3355 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3356 | /** |
| 3357 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 3358 | * 1. Custom contentView from the caller |
| 3359 | * 2. Style's proposed content view |
| 3360 | * 3. Standard template view |
| 3361 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3362 | public RemoteViews createContentView() { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3363 | if (mN.contentView != null && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3364 | return mN.contentView; |
| 3365 | } else if (mStyle != null) { |
| 3366 | final RemoteViews styleView = mStyle.makeContentView(); |
| 3367 | if (styleView != null) { |
| 3368 | return styleView; |
| 3369 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3370 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3371 | return applyStandardTemplate(getBaseLayoutResource()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3372 | } |
| 3373 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3374 | /** |
| 3375 | * Construct a RemoteViews for the final big notification layout. |
| 3376 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3377 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3378 | RemoteViews result = null; |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3379 | if (mN.bigContentView != null |
| 3380 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 3381 | return mN.bigContentView; |
| 3382 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3383 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 3384 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 3385 | } else if (mActions.size() != 0) { |
| 3386 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3387 | } |
| 3388 | adaptNotificationHeaderForBigContentView(result); |
| 3389 | return result; |
| 3390 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3391 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3392 | /** |
| 3393 | * Construct a RemoteViews for the final notification header only |
| 3394 | * |
| 3395 | * @hide |
| 3396 | */ |
| 3397 | public RemoteViews makeNotificationHeader() { |
| 3398 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
| 3399 | R.layout.notification_template_header); |
| 3400 | resetNotificationHeader(header); |
| 3401 | bindNotificationHeader(header); |
| 3402 | return header; |
| 3403 | } |
| 3404 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3405 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 3406 | if (result != null) { |
| 3407 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 3408 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3409 | } |
| 3410 | |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3411 | private void adaptNotificationHeaderForBigContentView(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 3412 | if (result != null) { |
| 3413 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 3414 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3415 | } |
| 3416 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3417 | /** |
| 3418 | * Construct a RemoteViews for the final heads-up notification layout. |
| 3419 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3420 | public RemoteViews createHeadsUpContentView() { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3421 | if (mN.headsUpContentView != null |
| 3422 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 3423 | return mN.headsUpContentView; |
| 3424 | } else if (mStyle != null) { |
| 3425 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(); |
| 3426 | if (styleView != null) { |
| 3427 | return styleView; |
| 3428 | } |
| 3429 | } else if (mActions.size() == 0) { |
| 3430 | return null; |
| 3431 | } |
| 3432 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3433 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 3434 | } |
| 3435 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 3436 | /** |
| 3437 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 3438 | * |
| 3439 | * @hide |
| 3440 | */ |
| 3441 | public RemoteViews makePublicContentView() { |
| 3442 | if (mN.publicVersion != null) { |
| 3443 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3444 | return builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 3445 | } |
| 3446 | Bundle savedBundle = mN.extras; |
| 3447 | Style style = mStyle; |
| 3448 | mStyle = null; |
| 3449 | Icon largeIcon = mN.mLargeIcon; |
| 3450 | mN.mLargeIcon = null; |
| 3451 | Bundle publicExtras = new Bundle(); |
| 3452 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 3453 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 3454 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 3455 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3456 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN, |
| 3457 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN)); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 3458 | publicExtras.putCharSequence(EXTRA_TITLE, |
| 3459 | mContext.getString(R.string.notification_hidden_text)); |
| 3460 | mN.extras = publicExtras; |
| 3461 | final RemoteViews publicView = applyStandardTemplate(getBaseLayoutResource()); |
| 3462 | mN.extras = savedBundle; |
| 3463 | mN.mLargeIcon = largeIcon; |
| 3464 | mStyle = style; |
| 3465 | return publicView; |
| 3466 | } |
| 3467 | |
| 3468 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 3469 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3470 | private RemoteViews generateActionButton(Action action) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3471 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 3472 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3473 | tombstone ? getActionTombstoneLayoutResource() |
| 3474 | : getActionLayoutResource()); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 3475 | final Icon ai = action.getIcon(); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3476 | button.setTextViewText(R.id.action0, processLegacyText(action.title)); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3477 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 3478 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 3479 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3480 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 3481 | if (action.mRemoteInputs != null) { |
| 3482 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 3483 | } |
| 3484 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3485 | button.setTextColor(R.id.action0, resolveContrastColor()); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 3486 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3487 | return button; |
| 3488 | } |
| 3489 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3490 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3491 | * @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] | 3492 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3493 | */ |
| 3494 | private boolean isLegacy() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3495 | return getColorUtil() != null; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3496 | } |
| 3497 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3498 | private CharSequence processLegacyText(CharSequence charSequence) { |
| 3499 | if (isLegacy()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3500 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3501 | } else { |
| 3502 | return charSequence; |
| 3503 | } |
| 3504 | } |
| 3505 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3506 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3507 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3508 | */ |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3509 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3510 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
| 3511 | if (colorable) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3512 | contentView.setDrawableParameters(R.id.icon, false, -1, resolveContrastColor(), |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 3513 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3514 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3515 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3516 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3517 | colorable ? resolveContrastColor() : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3518 | } |
| 3519 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3520 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3521 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3522 | * if it's grayscale). |
| 3523 | */ |
| 3524 | // TODO: also check bounds, transparency, that sort of thing. |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3525 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) { |
| 3526 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3527 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3528 | // resolve color will fall back to the default when legacy |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3529 | contentView.setDrawableParameters(R.id.icon, false, -1, resolveContrastColor(), |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3530 | PorterDuff.Mode.SRC_ATOP, -1); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 3531 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3532 | } |
| 3533 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3534 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3535 | if (mN.color != COLOR_DEFAULT) { |
| 3536 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3537 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3538 | } |
| 3539 | |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3540 | int resolveContrastColor() { |
| 3541 | if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) { |
| 3542 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3543 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3544 | final int contrasted = NotificationColorUtil.resolveContrastColor(mContext, mN.color); |
| 3545 | |
| 3546 | mCachedContrastColorIsFor = mN.color; |
| 3547 | return mCachedContrastColor = contrasted; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3548 | } |
| 3549 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3550 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3551 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3552 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3553 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3554 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3555 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3556 | mN.actions = new Action[mActions.size()]; |
| 3557 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3558 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3559 | if (!mPersonList.isEmpty()) { |
| 3560 | mN.extras.putStringArray(EXTRA_PEOPLE, |
| 3561 | mPersonList.toArray(new String[mPersonList.size()])); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3562 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 3563 | if (mN.bigContentView != null || mN.contentView != null |
| 3564 | || mN.headsUpContentView != null) { |
| 3565 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 3566 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3567 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3568 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3569 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3570 | /** |
| 3571 | * Creates a Builder from an existing notification so further changes can be made. |
| 3572 | * @param context The context for your application / activity. |
| 3573 | * @param n The notification to create a Builder from. |
| 3574 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3575 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3576 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3577 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 3578 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3579 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 3580 | if (applicationInfo != null) { |
| 3581 | try { |
| 3582 | builderContext = context.createApplicationContext(applicationInfo, |
| 3583 | Context.CONTEXT_RESTRICTED); |
| 3584 | } catch (NameNotFoundException e) { |
| 3585 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 3586 | builderContext = context; // try with our context |
| 3587 | } |
| 3588 | } else { |
| 3589 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3590 | } |
| 3591 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3592 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | private static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3596 | Class<? extends Style>[] classes = new Class[] { |
| 3597 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 3598 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 3599 | MessagingStyle.class }; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3600 | for (Class<? extends Style> innerClass : classes) { |
| 3601 | if (templateClass.equals(innerClass.getName())) { |
| 3602 | return innerClass; |
| 3603 | } |
| 3604 | } |
| 3605 | return null; |
| 3606 | } |
| 3607 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3608 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3609 | * @deprecated Use {@link #build()} instead. |
| 3610 | */ |
| 3611 | @Deprecated |
| 3612 | public Notification getNotification() { |
| 3613 | return build(); |
| 3614 | } |
| 3615 | |
| 3616 | /** |
| 3617 | * Combine all of the options that have been set and return a new {@link Notification} |
| 3618 | * object. |
| 3619 | */ |
| 3620 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3621 | // first, add any extras from the calling code |
| 3622 | if (mUserExtras != null) { |
| 3623 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 3624 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3625 | |
| 3626 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 3627 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 3628 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3629 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3630 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3631 | if (mStyle != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3632 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3633 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3634 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 3635 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 3636 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3637 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3638 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3639 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 3640 | mN.contentView.getSequenceNumber()); |
| 3641 | } |
| 3642 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3643 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3644 | if (mN.bigContentView != null) { |
| 3645 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 3646 | mN.bigContentView.getSequenceNumber()); |
| 3647 | } |
| 3648 | } |
| 3649 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3650 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3651 | if (mN.headsUpContentView != null) { |
| 3652 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 3653 | mN.headsUpContentView.getSequenceNumber()); |
| 3654 | } |
| 3655 | } |
| 3656 | } |
| 3657 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 3658 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 3659 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 3660 | } |
| 3661 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3662 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3663 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3664 | |
| 3665 | /** |
| 3666 | * Apply this Builder to an existing {@link Notification} object. |
| 3667 | * |
| 3668 | * @hide |
| 3669 | */ |
| 3670 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 3671 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3672 | return n; |
| 3673 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3674 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3675 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3676 | * Removes RemoteViews that were created for compatibility from {@param n}, if they did not |
| 3677 | * change. |
| 3678 | * |
| 3679 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 3680 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3681 | * @hide |
| 3682 | */ |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3683 | public static Notification maybeCloneStrippedForDelivery(Notification n) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3684 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3685 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3686 | // Only strip views for known Styles because we won't know how to |
| 3687 | // re-create them otherwise. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3688 | if (!TextUtils.isEmpty(templateClass) |
| 3689 | && getNotificationStyleClass(templateClass) == null) { |
| 3690 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3691 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3692 | |
| 3693 | // Only strip unmodified BuilderRemoteViews. |
| 3694 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3695 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3696 | n.contentView.getSequenceNumber(); |
| 3697 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3698 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3699 | n.bigContentView.getSequenceNumber(); |
| 3700 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3701 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3702 | n.headsUpContentView.getSequenceNumber(); |
| 3703 | |
| 3704 | // Nothing to do here, no need to clone. |
| 3705 | if (!stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
| 3706 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3707 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3708 | |
| 3709 | Notification clone = n.clone(); |
| 3710 | if (stripContentView) { |
| 3711 | clone.contentView = null; |
| 3712 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 3713 | } |
| 3714 | if (stripBigContentView) { |
| 3715 | clone.bigContentView = null; |
| 3716 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 3717 | } |
| 3718 | if (stripHeadsUpContentView) { |
| 3719 | clone.headsUpContentView = null; |
| 3720 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 3721 | } |
| 3722 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3723 | } |
| 3724 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3725 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3726 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3730 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3734 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3738 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3742 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3746 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3750 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3751 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3752 | } |
| 3753 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3754 | /** |
| 3755 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 3756 | * object. |
| 3757 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3758 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3759 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3760 | |
| 3761 | /** |
| 3762 | * @hide |
| 3763 | */ |
| 3764 | protected CharSequence mSummaryText = null; |
| 3765 | |
| 3766 | /** |
| 3767 | * @hide |
| 3768 | */ |
| 3769 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3770 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3771 | protected Builder mBuilder; |
| 3772 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3773 | /** |
| 3774 | * Overrides ContentTitle in the big form of the template. |
| 3775 | * This defaults to the value passed to setContentTitle(). |
| 3776 | */ |
| 3777 | protected void internalSetBigContentTitle(CharSequence title) { |
| 3778 | mBigContentTitle = title; |
| 3779 | } |
| 3780 | |
| 3781 | /** |
| 3782 | * Set the first line of text after the detail section in the big form of the template. |
| 3783 | */ |
| 3784 | protected void internalSetSummaryText(CharSequence cs) { |
| 3785 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3786 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3787 | } |
| 3788 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3789 | public void setBuilder(Builder builder) { |
| 3790 | if (mBuilder != builder) { |
| 3791 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3792 | if (mBuilder != null) { |
| 3793 | mBuilder.setStyle(this); |
| 3794 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3795 | } |
| 3796 | } |
| 3797 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3798 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3799 | if (mBuilder == null) { |
| 3800 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 3801 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3802 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3803 | |
| 3804 | protected RemoteViews getStandardView(int layoutId) { |
| 3805 | checkBuilder(); |
| 3806 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3807 | // Nasty. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3808 | CharSequence oldBuilderContentTitle = |
| 3809 | mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3810 | if (mBigContentTitle != null) { |
| 3811 | mBuilder.setContentTitle(mBigContentTitle); |
| 3812 | } |
| 3813 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3814 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 3815 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3816 | mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3817 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3818 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 3819 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 3820 | } else { |
| 3821 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3822 | } |
| 3823 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3824 | return contentView; |
| 3825 | } |
| 3826 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3827 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3828 | * Construct a Style-specific RemoteViews for the final 1U notification layout. |
| 3829 | * The default implementation has nothing additional to add. |
| 3830 | * @hide |
| 3831 | */ |
| 3832 | public RemoteViews makeContentView() { |
| 3833 | return null; |
| 3834 | } |
| 3835 | |
| 3836 | /** |
| 3837 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 3838 | * @hide |
| 3839 | */ |
| 3840 | public RemoteViews makeBigContentView() { |
| 3841 | return null; |
| 3842 | } |
| 3843 | |
| 3844 | /** |
| 3845 | * Construct a Style-specific RemoteViews for the final HUN layout. |
| 3846 | * @hide |
| 3847 | */ |
| 3848 | public RemoteViews makeHeadsUpContentView() { |
| 3849 | return null; |
| 3850 | } |
| 3851 | |
| 3852 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3853 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3854 | * @hide |
| 3855 | */ |
| 3856 | public void addExtras(Bundle extras) { |
| 3857 | if (mSummaryTextSet) { |
| 3858 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 3859 | } |
| 3860 | if (mBigContentTitle != null) { |
| 3861 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 3862 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 3863 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3864 | } |
| 3865 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3866 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3867 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3868 | * @hide |
| 3869 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3870 | protected void restoreFromExtras(Bundle extras) { |
| 3871 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 3872 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 3873 | mSummaryTextSet = true; |
| 3874 | } |
| 3875 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 3876 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 3877 | } |
| 3878 | } |
| 3879 | |
| 3880 | |
| 3881 | /** |
| 3882 | * @hide |
| 3883 | */ |
| 3884 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3885 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3886 | return wip; |
| 3887 | } |
| 3888 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 3889 | /** |
| 3890 | * @hide |
| 3891 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 3892 | public void purgeResources() {} |
| 3893 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3894 | /** |
| 3895 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 3896 | * attached to. |
| 3897 | * |
| 3898 | * @return the fully constructed Notification. |
| 3899 | */ |
| 3900 | public Notification build() { |
| 3901 | checkBuilder(); |
| 3902 | return mBuilder.build(); |
| 3903 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3904 | |
| 3905 | /** |
| 3906 | * @hide |
| 3907 | * @return true if the style positions the progress bar on the second line; false if the |
| 3908 | * style hides the progress bar |
| 3909 | */ |
| 3910 | protected boolean hasProgress() { |
| 3911 | return true; |
| 3912 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3913 | |
| 3914 | /** |
| 3915 | * @hide |
| 3916 | * @return Whether we should put the summary be put into the notification header |
| 3917 | */ |
| 3918 | public boolean hasSummaryInHeader() { |
| 3919 | return true; |
| 3920 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3921 | |
| 3922 | /** |
| 3923 | * @hide |
| 3924 | * @return Whether custom content views are displayed inline in the style |
| 3925 | */ |
| 3926 | public boolean displayCustomViewInline() { |
| 3927 | return false; |
| 3928 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3929 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3930 | |
| 3931 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3932 | * 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] | 3933 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3934 | * 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] | 3935 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3936 | * Notification notif = new Notification.Builder(mContext) |
| 3937 | * .setContentTitle("New photo from " + sender.toString()) |
| 3938 | * .setContentText(subject) |
| 3939 | * .setSmallIcon(R.drawable.new_post) |
| 3940 | * .setLargeIcon(aBitmap) |
| 3941 | * .setStyle(new Notification.BigPictureStyle() |
| 3942 | * .bigPicture(aBigBitmap)) |
| 3943 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3944 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3945 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3946 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3947 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3948 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3949 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3950 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3951 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3952 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3953 | public BigPictureStyle() { |
| 3954 | } |
| 3955 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3956 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3957 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3958 | } |
| 3959 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3960 | /** |
| 3961 | * Overrides ContentTitle in the big form of the template. |
| 3962 | * This defaults to the value passed to setContentTitle(). |
| 3963 | */ |
| 3964 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3965 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3966 | return this; |
| 3967 | } |
| 3968 | |
| 3969 | /** |
| 3970 | * Set the first line of text after the detail section in the big form of the template. |
| 3971 | */ |
| 3972 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3973 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3974 | return this; |
| 3975 | } |
| 3976 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 3977 | /** |
| 3978 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 3979 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3980 | public BigPictureStyle bigPicture(Bitmap b) { |
| 3981 | mPicture = b; |
| 3982 | return this; |
| 3983 | } |
| 3984 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3985 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3986 | * Override the large icon when the big notification is shown. |
| 3987 | */ |
| 3988 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3989 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3990 | } |
| 3991 | |
| 3992 | /** |
| 3993 | * Override the large icon when the big notification is shown. |
| 3994 | */ |
| 3995 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3996 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3997 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3998 | return this; |
| 3999 | } |
| 4000 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 4001 | /** @hide */ |
| 4002 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 4003 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 4004 | /** |
| 4005 | * @hide |
| 4006 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 4007 | @Override |
| 4008 | public void purgeResources() { |
| 4009 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 4010 | if (mPicture != null && |
| 4011 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 4012 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 4013 | mPicture = mPicture.createAshmemBitmap(); |
| 4014 | } |
| 4015 | if (mBigLargeIcon != null) { |
| 4016 | mBigLargeIcon.convertToAshmem(); |
| 4017 | } |
| 4018 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 4019 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4020 | /** |
| 4021 | * @hide |
| 4022 | */ |
| 4023 | public RemoteViews makeBigContentView() { |
| 4024 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 4025 | // This covers the following cases: |
| 4026 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4027 | // mN.mLargeIcon |
| 4028 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4029 | Icon oldLargeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 4030 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4031 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 4032 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 4033 | } |
| 4034 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4035 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4036 | if (mSummaryTextSet) { |
| 4037 | contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(mSummaryText)); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4038 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4039 | } |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4040 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.mLargeIcon != null); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 4041 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 4042 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4043 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 4044 | } |
| 4045 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4046 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4047 | return contentView; |
| 4048 | } |
| 4049 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4050 | /** |
| 4051 | * @hide |
| 4052 | */ |
| 4053 | public void addExtras(Bundle extras) { |
| 4054 | super.addExtras(extras); |
| 4055 | |
| 4056 | if (mBigLargeIconSet) { |
| 4057 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 4058 | } |
| 4059 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 4060 | } |
| 4061 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4062 | /** |
| 4063 | * @hide |
| 4064 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4065 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4066 | protected void restoreFromExtras(Bundle extras) { |
| 4067 | super.restoreFromExtras(extras); |
| 4068 | |
| 4069 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 4070 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4071 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 4072 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4073 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 4074 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4075 | |
| 4076 | /** |
| 4077 | * @hide |
| 4078 | */ |
| 4079 | @Override |
| 4080 | public boolean hasSummaryInHeader() { |
| 4081 | return false; |
| 4082 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 4086 | * 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] | 4087 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4088 | * 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] | 4089 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4090 | * Notification notif = new Notification.Builder(mContext) |
| 4091 | * .setContentTitle("New mail from " + sender.toString()) |
| 4092 | * .setContentText(subject) |
| 4093 | * .setSmallIcon(R.drawable.new_mail) |
| 4094 | * .setLargeIcon(aBitmap) |
| 4095 | * .setStyle(new Notification.BigTextStyle() |
| 4096 | * .bigText(aVeryLongString)) |
| 4097 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4098 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4099 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 4100 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4101 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4102 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4103 | |
| 4104 | private static final int MAX_LINES = 13; |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 4105 | private static final int LINES_CONSUMED_BY_ACTIONS = 4; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4106 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4107 | private CharSequence mBigText; |
| 4108 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4109 | public BigTextStyle() { |
| 4110 | } |
| 4111 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4112 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4113 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4114 | } |
| 4115 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4116 | /** |
| 4117 | * Overrides ContentTitle in the big form of the template. |
| 4118 | * This defaults to the value passed to setContentTitle(). |
| 4119 | */ |
| 4120 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4121 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4122 | return this; |
| 4123 | } |
| 4124 | |
| 4125 | /** |
| 4126 | * Set the first line of text after the detail section in the big form of the template. |
| 4127 | */ |
| 4128 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4129 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4130 | return this; |
| 4131 | } |
| 4132 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 4133 | /** |
| 4134 | * Provide the longer text to be displayed in the big form of the |
| 4135 | * template in place of the content text. |
| 4136 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4137 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4138 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4139 | return this; |
| 4140 | } |
| 4141 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4142 | /** |
| 4143 | * @hide |
| 4144 | */ |
| 4145 | public void addExtras(Bundle extras) { |
| 4146 | super.addExtras(extras); |
| 4147 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4148 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 4149 | } |
| 4150 | |
| 4151 | /** |
| 4152 | * @hide |
| 4153 | */ |
| 4154 | @Override |
| 4155 | protected void restoreFromExtras(Bundle extras) { |
| 4156 | super.restoreFromExtras(extras); |
| 4157 | |
| 4158 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4159 | } |
| 4160 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4161 | /** |
| 4162 | * @hide |
| 4163 | */ |
| 4164 | public RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4165 | |
| 4166 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4167 | CharSequence oldBuilderContentText = |
| 4168 | mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT); |
| 4169 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 4170 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4171 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4172 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4173 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4174 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 4175 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
| 4176 | contentView.setTextViewText(R.id.big_text, bigTextText); |
| 4177 | contentView.setViewVisibility(R.id.big_text, |
| 4178 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4179 | contentView.setInt(R.id.big_text, "setMaxLines", calculateMaxLines()); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 4180 | contentView.setBoolean(R.id.big_text, "setHasImage", mBuilder.mN.mLargeIcon != null); |
| 4181 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4182 | return contentView; |
| 4183 | } |
| 4184 | |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4185 | private int calculateMaxLines() { |
| 4186 | int lineCount = MAX_LINES; |
| 4187 | boolean hasActions = mBuilder.mActions.size() > 0; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4188 | if (hasActions) { |
| 4189 | lineCount -= LINES_CONSUMED_BY_ACTIONS; |
| 4190 | } |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4191 | return lineCount; |
| 4192 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4193 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4194 | |
| 4195 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 4196 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 4197 | * messages of varying types between any number of people. |
| 4198 | * |
| 4199 | * <br> |
| 4200 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 4201 | * user will always see the normal notification view. |
| 4202 | * <br> |
| 4203 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like |
| 4204 | * so: |
| 4205 | * <pre class="prettyprint"> |
| 4206 | * |
| 4207 | * Notification noti = new Notification.Builder() |
| 4208 | * .setContentTitle("2 new messages wtih " + sender.toString()) |
| 4209 | * .setContentText(subject) |
| 4210 | * .setSmallIcon(R.drawable.new_message) |
| 4211 | * .setLargeIcon(aBitmap) |
| 4212 | * .setStyle(new Notification.MessagingStyle(resources.getString(R.string.reply_name)) |
| 4213 | * .addMessage(messages[0].getText(), messages[0].getTime(), messages[0].getSender()) |
| 4214 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getSender())) |
| 4215 | * .build(); |
| 4216 | * </pre> |
| 4217 | */ |
| 4218 | public static class MessagingStyle extends Style { |
| 4219 | |
| 4220 | /** |
| 4221 | * The maximum number of messages that will be retained in the Notification itself (the |
| 4222 | * number displayed is up to the platform). |
| 4223 | */ |
| 4224 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 4225 | |
| 4226 | CharSequence mUserDisplayName; |
| 4227 | CharSequence mConversationTitle; |
| 4228 | boolean mAllowGeneratedReplies = true; |
| 4229 | ArrayList<Message> mMessages = new ArrayList<>(); |
| 4230 | |
| 4231 | MessagingStyle() { |
| 4232 | } |
| 4233 | |
| 4234 | /** |
| 4235 | * @param userDisplayName the name to be displayed for any replies sent by the user before the |
| 4236 | * posting app reposts the notification with those messages after they've been actually |
| 4237 | * sent and in previous messages sent by the user added in |
| 4238 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
| 4239 | */ |
| 4240 | public MessagingStyle(CharSequence userDisplayName) { |
| 4241 | mUserDisplayName = userDisplayName; |
| 4242 | } |
| 4243 | |
| 4244 | /** |
| 4245 | * Returns the name to be displayed for any replies sent by the user |
| 4246 | */ |
| 4247 | public CharSequence getUserDisplayName() { |
| 4248 | return mUserDisplayName; |
| 4249 | } |
| 4250 | |
| 4251 | /** |
| 4252 | * Set whether the platform should automatically generate possible replies from messages. |
| 4253 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 4254 | * otherwise |
| 4255 | * @return this object for method chaining |
| 4256 | * The default value is {@code true} |
| 4257 | */ |
| 4258 | public MessagingStyle setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 4259 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 4260 | return this; |
| 4261 | } |
| 4262 | |
| 4263 | /** |
| 4264 | * Return whether the platform should automatically generate possible replies from messages. |
| 4265 | */ |
| 4266 | public boolean getAllowGeneratedReplies() { |
| 4267 | return mAllowGeneratedReplies; |
| 4268 | } |
| 4269 | |
| 4270 | /** |
| 4271 | * Sets the title to be displayed on this conversation. This should only be used for |
| 4272 | * group messaging and left unset for one-on-one conversations. |
| 4273 | * @param conversationTitle |
| 4274 | * @return this object for method chaining. |
| 4275 | */ |
| 4276 | public MessagingStyle setConversationTitle(CharSequence conversationTitle) { |
| 4277 | mConversationTitle = conversationTitle; |
| 4278 | return this; |
| 4279 | } |
| 4280 | |
| 4281 | /** |
| 4282 | * Return the title to be displayed on this conversation. Can be <code>null</code> and |
| 4283 | * should be for one-on-one conversations |
| 4284 | */ |
| 4285 | public CharSequence getConversationTitle() { |
| 4286 | return mConversationTitle; |
| 4287 | } |
| 4288 | |
| 4289 | /** |
| 4290 | * Adds a message for display by this notification. Convenience call for a simple |
| 4291 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 4292 | * @param text A {@link CharSequence} to be displayed as the message content |
| 4293 | * @param timestamp Time at which the message arrived |
| 4294 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 4295 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 4296 | * the platform will insert {@link #getUserDisplayName()}. |
| 4297 | * Should be unique amongst all individuals in the conversation, and should be |
| 4298 | * consistent during re-posts of the notification. |
| 4299 | * |
| 4300 | * @see Message#Message(CharSequence, long, CharSequence) |
| 4301 | * |
| 4302 | * @return this object for method chaining |
| 4303 | */ |
| 4304 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
| 4305 | mMessages.add(new Message(text, timestamp, sender)); |
| 4306 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 4307 | mMessages.remove(0); |
| 4308 | } |
| 4309 | return this; |
| 4310 | } |
| 4311 | |
| 4312 | /** |
| 4313 | * Adds a {@link Message} for display in this notification. |
| 4314 | * @param message The {@link Message} to be displayed |
| 4315 | * @return this object for method chaining |
| 4316 | */ |
| 4317 | public MessagingStyle addMessage(Message message) { |
| 4318 | mMessages.add(message); |
| 4319 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 4320 | mMessages.remove(0); |
| 4321 | } |
| 4322 | return this; |
| 4323 | } |
| 4324 | |
| 4325 | /** |
| 4326 | * Gets the list of {@code Message} objects that represent the notification |
| 4327 | */ |
| 4328 | public List<Message> getMessages() { |
| 4329 | return mMessages; |
| 4330 | } |
| 4331 | |
| 4332 | /** |
| 4333 | * @hide |
| 4334 | */ |
| 4335 | @Override |
| 4336 | public void addExtras(Bundle extras) { |
| 4337 | super.addExtras(extras); |
| 4338 | if (mUserDisplayName != null) { |
| 4339 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUserDisplayName); |
| 4340 | } |
| 4341 | if (mConversationTitle != null) { |
| 4342 | extras.putCharSequence(EXTRA_THREAD_TITLE, mConversationTitle); |
| 4343 | } |
| 4344 | extras.putBoolean(EXTRA_ALLOW_GENERATED_REPLIES, mAllowGeneratedReplies); |
| 4345 | if (!mMessages.isEmpty()) { |
| 4346 | extras.putParcelableArrayList(EXTRA_MESSAGES, mMessages); |
| 4347 | } |
| 4348 | } |
| 4349 | |
| 4350 | /** |
| 4351 | * @hide |
| 4352 | */ |
| 4353 | @Override |
| 4354 | protected void restoreFromExtras(Bundle extras) { |
| 4355 | super.restoreFromExtras(extras); |
| 4356 | |
| 4357 | mMessages.clear(); |
| 4358 | mUserDisplayName = extras.getString(EXTRA_SELF_DISPLAY_NAME); |
| 4359 | mConversationTitle = extras.getString(EXTRA_THREAD_TITLE); |
| 4360 | mAllowGeneratedReplies = extras.getBoolean(EXTRA_ALLOW_GENERATED_REPLIES, |
| 4361 | mAllowGeneratedReplies); |
| 4362 | List<Message> messages = extras.getParcelableArrayList(EXTRA_MESSAGES); |
| 4363 | if (messages != null) { |
| 4364 | mMessages.addAll(messages); |
| 4365 | } |
| 4366 | } |
| 4367 | |
| 4368 | /** |
| 4369 | * @hide |
| 4370 | */ |
| 4371 | public RemoteViews makeBigContentView() { |
| 4372 | // TODO handset to write implementation |
| 4373 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
| 4374 | |
| 4375 | return contentView; |
| 4376 | } |
| 4377 | |
| 4378 | public static final class Message implements Parcelable { |
| 4379 | |
| 4380 | private final CharSequence mText; |
| 4381 | private final long mTimestamp; |
| 4382 | private final CharSequence mSender; |
| 4383 | |
| 4384 | private String mDataMimeType; |
| 4385 | private Uri mDataUri; |
| 4386 | |
| 4387 | /** |
| 4388 | * Constructor |
| 4389 | * @param text A {@link CharSequence} to be displayed as the message content |
| 4390 | * @param timestamp Time at which the message arrived |
| 4391 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 4392 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 4393 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 4394 | * Should be unique amongst all individuals in the conversation, and should be |
| 4395 | * consistent during re-posts of the notification. |
| 4396 | */ |
| 4397 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
| 4398 | mText = text; |
| 4399 | mTimestamp = timestamp; |
| 4400 | mSender = sender; |
| 4401 | } |
| 4402 | |
| 4403 | /** |
| 4404 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 4405 | * where the platform doesn't support the MIME type, the original text provided in the |
| 4406 | * constructor will be used. |
| 4407 | * @param dataMimeType The MIME type of the content. See |
| 4408 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 4409 | * types on Android and Android Wear. |
| 4410 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 4411 | * <p class="note"> |
| 4412 | * <ol> |
| 4413 | * <li>Notification Listeners including the System UI need permission to access the |
| 4414 | * data the Uri points to. The recommended ways to do this are:</li> |
| 4415 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 4416 | * the correct permission to access your provider. The preferred mechanism for |
| 4417 | * providing access is to use per-URI permissions which are temporary and only |
| 4418 | * grant access to the receiving application. An easy way to create a |
| 4419 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 4420 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 4421 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 4422 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 4423 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 4424 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 4425 | * Note that once added to the system MediaStore the content is accessible to any |
| 4426 | * app on the device.</li> |
| 4427 | * </ol> |
| 4428 | * @return this object for method chaining |
| 4429 | */ |
| 4430 | public Message setData(String dataMimeType, Uri dataUri) { |
| 4431 | mDataMimeType = dataMimeType; |
| 4432 | mDataUri = dataUri; |
| 4433 | return this; |
| 4434 | } |
| 4435 | |
| 4436 | private Message(Parcel in) { |
| 4437 | if (in.readInt() != 0) { |
| 4438 | mText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 4439 | } else { |
| 4440 | mText = null; |
| 4441 | } |
| 4442 | mTimestamp = in.readLong(); |
| 4443 | if (in.readInt() != 0) { |
| 4444 | mSender = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 4445 | } else { |
| 4446 | mSender = null; |
| 4447 | } |
| 4448 | if (in.readInt() != 0) { |
| 4449 | mDataMimeType = in.readString(); |
| 4450 | } |
| 4451 | if (in.readInt() != 0) { |
| 4452 | mDataUri = in.readParcelable(Uri.class.getClassLoader()); |
| 4453 | } |
| 4454 | } |
| 4455 | |
| 4456 | /** |
| 4457 | * Get the text to be used for this message, or the fallback text if a type and content |
| 4458 | * Uri have been set |
| 4459 | */ |
| 4460 | public CharSequence getText() { |
| 4461 | return mText; |
| 4462 | } |
| 4463 | |
| 4464 | /** |
| 4465 | * Get the time at which this message arrived |
| 4466 | */ |
| 4467 | public long getTimestamp() { |
| 4468 | return mTimestamp; |
| 4469 | } |
| 4470 | |
| 4471 | /** |
| 4472 | * Get the text used to display the contact's name in the messaging experience |
| 4473 | */ |
| 4474 | public CharSequence getSender() { |
| 4475 | return mSender; |
| 4476 | } |
| 4477 | |
| 4478 | /** |
| 4479 | * Get the MIME type of the data pointed to by the Uri |
| 4480 | */ |
| 4481 | public String getDataMimeType() { |
| 4482 | return mDataMimeType; |
| 4483 | } |
| 4484 | |
| 4485 | /** |
| 4486 | * Get the the Uri pointing to the content of the message. Can be null, in which case |
| 4487 | * {@see #getText()} is used. |
| 4488 | */ |
| 4489 | public Uri getDataUri() { |
| 4490 | return mDataUri; |
| 4491 | } |
| 4492 | |
| 4493 | @Override |
| 4494 | public int describeContents() { |
| 4495 | return 0; |
| 4496 | } |
| 4497 | |
| 4498 | @Override |
| 4499 | public void writeToParcel(Parcel out, int flags) { |
| 4500 | if (mText != null) { |
| 4501 | out.writeInt(1); |
| 4502 | TextUtils.writeToParcel(mText, out, flags); |
| 4503 | } else { |
| 4504 | out.writeInt(0); |
| 4505 | } |
| 4506 | out.writeLong(mTimestamp); |
| 4507 | if (mSender != null) { |
| 4508 | out.writeInt(1); |
| 4509 | TextUtils.writeToParcel(mSender, out, flags); |
| 4510 | } else { |
| 4511 | out.writeInt(0); |
| 4512 | } |
| 4513 | if (mDataMimeType != null) { |
| 4514 | out.writeInt(1); |
| 4515 | out.writeString(mDataMimeType); |
| 4516 | } else { |
| 4517 | out.writeInt(0); |
| 4518 | } |
| 4519 | if (mDataUri != null) { |
| 4520 | out.writeInt(1); |
| 4521 | out.writeParcelable(mDataUri, flags); |
| 4522 | } else { |
| 4523 | out.writeInt(0); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | public static final Parcelable.Creator<Message> CREATOR = |
| 4528 | new Parcelable.Creator<Message>() { |
| 4529 | public Message createFromParcel(Parcel in) { |
| 4530 | return new Message(in); |
| 4531 | } |
| 4532 | public Message[] newArray(int size) { |
| 4533 | return new Message[size]; |
| 4534 | } |
| 4535 | }; |
| 4536 | } |
| 4537 | } |
| 4538 | |
| 4539 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4540 | * 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] | 4541 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4542 | * 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] | 4543 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4544 | * Notification notif = new Notification.Builder(mContext) |
| 4545 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 4546 | * .setContentText(subject) |
| 4547 | * .setSmallIcon(R.drawable.new_mail) |
| 4548 | * .setLargeIcon(aBitmap) |
| 4549 | * .setStyle(new Notification.InboxStyle() |
| 4550 | * .addLine(str1) |
| 4551 | * .addLine(str2) |
| 4552 | * .setContentTitle("") |
| 4553 | * .setSummaryText("+3 more")) |
| 4554 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4555 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4556 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4557 | * @see Notification#bigContentView |
| 4558 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4559 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4560 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 4561 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4562 | public InboxStyle() { |
| 4563 | } |
| 4564 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4565 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4566 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4567 | } |
| 4568 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4569 | /** |
| 4570 | * Overrides ContentTitle in the big form of the template. |
| 4571 | * This defaults to the value passed to setContentTitle(). |
| 4572 | */ |
| 4573 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4574 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4575 | return this; |
| 4576 | } |
| 4577 | |
| 4578 | /** |
| 4579 | * Set the first line of text after the detail section in the big form of the template. |
| 4580 | */ |
| 4581 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4582 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4583 | return this; |
| 4584 | } |
| 4585 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 4586 | /** |
| 4587 | * Append a line to the digest section of the Inbox notification. |
| 4588 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4589 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4590 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4591 | return this; |
| 4592 | } |
| 4593 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4594 | /** |
| 4595 | * @hide |
| 4596 | */ |
| 4597 | public void addExtras(Bundle extras) { |
| 4598 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4599 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4600 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 4601 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 4602 | } |
| 4603 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4604 | /** |
| 4605 | * @hide |
| 4606 | */ |
| 4607 | @Override |
| 4608 | protected void restoreFromExtras(Bundle extras) { |
| 4609 | super.restoreFromExtras(extras); |
| 4610 | |
| 4611 | mTexts.clear(); |
| 4612 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 4613 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 4614 | } |
| 4615 | } |
| 4616 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4617 | /** |
| 4618 | * @hide |
| 4619 | */ |
| 4620 | public RemoteViews makeBigContentView() { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4621 | // Remove the content text so it disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4622 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4623 | CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT); |
| 4624 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4625 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4626 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource()); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 4627 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4628 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4629 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4630 | 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] | 4631 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4632 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 4633 | // Make sure all rows are gone in case we reuse a view. |
| 4634 | for (int rowId : rowIds) { |
| 4635 | contentView.setViewVisibility(rowId, View.GONE); |
| 4636 | } |
| 4637 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4638 | final boolean largeText = |
| 4639 | mBuilder.mContext.getResources().getConfiguration().fontScale > 1f; |
| 4640 | final float subTextSize = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4641 | R.dimen.notification_subtext_size); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4642 | int i=0; |
Selim Cinek | 9d9fc6e | 2015-11-12 15:49:14 -0500 | [diff] [blame] | 4643 | final float density = mBuilder.mContext.getResources().getDisplayMetrics().density; |
| 4644 | int topPadding = (int) (5 * density); |
Selim Cinek | c0fac72 | 2016-03-07 19:57:06 -0800 | [diff] [blame] | 4645 | int bottomPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4646 | com.android.internal.R.dimen.notification_content_margin_bottom); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4647 | boolean first = true; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4648 | while (i < mTexts.size() && i < rowIds.length) { |
| 4649 | CharSequence str = mTexts.get(i); |
| 4650 | if (str != null && !str.equals("")) { |
| 4651 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4652 | contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4653 | if (largeText) { |
| 4654 | contentView.setTextViewTextSize(rowIds[i], TypedValue.COMPLEX_UNIT_PX, |
| 4655 | subTextSize); |
| 4656 | } |
Selim Cinek | 9d9fc6e | 2015-11-12 15:49:14 -0500 | [diff] [blame] | 4657 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, |
| 4658 | i == rowIds.length - 1 || i == mTexts.size() - 1 ? bottomPadding : 0); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4659 | handleInboxImageMargin(contentView, rowIds[i], first); |
| 4660 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4661 | } |
| 4662 | i++; |
| 4663 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4664 | |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4665 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4666 | return contentView; |
| 4667 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4668 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4669 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4670 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4671 | if (first) { |
| 4672 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4673 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 4674 | boolean hasProgress = max != 0 || ind; |
| 4675 | if (mBuilder.mN.mLargeIcon != null && !hasProgress) { |
| 4676 | endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4677 | R.dimen.notification_content_picture_margin); |
| 4678 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4679 | } |
| 4680 | contentView.setViewLayoutMarginEnd(id, endMargin); |
| 4681 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4682 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4683 | |
| 4684 | /** |
| 4685 | * Notification style for media playback notifications. |
| 4686 | * |
| 4687 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 4688 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4689 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4690 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 4691 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 4692 | * treated as album artwork. |
| 4693 | * |
| 4694 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 4695 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 4696 | * {@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] | 4697 | * in the standard view alongside the usual content. |
| 4698 | * |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4699 | * Notifications created with MediaStyle will have their category set to |
| 4700 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 4701 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
| 4702 | * |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4703 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 4704 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4705 | * the System UI can identify this as a notification representing an active media session |
| 4706 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 4707 | * |
| 4708 | * To use this style with your Notification, feed it to |
| 4709 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 4710 | * <pre class="prettyprint"> |
| 4711 | * Notification noti = new Notification.Builder() |
| 4712 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 4713 | * .setContentTitle("Track title") |
| 4714 | * .setContentText("Artist - Album") |
| 4715 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4716 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 4717 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4718 | * .build(); |
| 4719 | * </pre> |
| 4720 | * |
| 4721 | * @see Notification#bigContentView |
| 4722 | */ |
| 4723 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4724 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4725 | static final int MAX_MEDIA_BUTTONS = 5; |
| 4726 | |
| 4727 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4728 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4729 | |
| 4730 | public MediaStyle() { |
| 4731 | } |
| 4732 | |
| 4733 | public MediaStyle(Builder builder) { |
| 4734 | setBuilder(builder); |
| 4735 | } |
| 4736 | |
| 4737 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4738 | * 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] | 4739 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4740 | * |
| 4741 | * @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] | 4742 | */ |
| 4743 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 4744 | mActionsToShowInCompact = actions; |
| 4745 | return this; |
| 4746 | } |
| 4747 | |
| 4748 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4749 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 4750 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4751 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4752 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4753 | mToken = token; |
| 4754 | return this; |
| 4755 | } |
| 4756 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4757 | /** |
| 4758 | * @hide |
| 4759 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4760 | @Override |
| 4761 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4762 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4763 | if (wip.category == null) { |
| 4764 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 4765 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4766 | return wip; |
| 4767 | } |
| 4768 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4769 | /** |
| 4770 | * @hide |
| 4771 | */ |
| 4772 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4773 | public RemoteViews makeContentView() { |
| 4774 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | /** |
| 4778 | * @hide |
| 4779 | */ |
| 4780 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4781 | public RemoteViews makeBigContentView() { |
| 4782 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4783 | } |
| 4784 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4785 | /** |
| 4786 | * @hide |
| 4787 | */ |
| 4788 | @Override |
| 4789 | public RemoteViews makeHeadsUpContentView() { |
| 4790 | RemoteViews expanded = makeMediaBigContentView(); |
| 4791 | return expanded != null ? expanded : makeMediaContentView(); |
| 4792 | } |
| 4793 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4794 | /** @hide */ |
| 4795 | @Override |
| 4796 | public void addExtras(Bundle extras) { |
| 4797 | super.addExtras(extras); |
| 4798 | |
| 4799 | if (mToken != null) { |
| 4800 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 4801 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 4802 | if (mActionsToShowInCompact != null) { |
| 4803 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 4804 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4805 | } |
| 4806 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4807 | /** |
| 4808 | * @hide |
| 4809 | */ |
| 4810 | @Override |
| 4811 | protected void restoreFromExtras(Bundle extras) { |
| 4812 | super.restoreFromExtras(extras); |
| 4813 | |
| 4814 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 4815 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 4816 | } |
| 4817 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 4818 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 4819 | } |
| 4820 | } |
| 4821 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4822 | private RemoteViews generateMediaActionButton(Action action, int color) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4823 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 4824 | RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4825 | R.layout.notification_material_media_action); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 4826 | button.setImageViewIcon(R.id.action0, action.getIcon()); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4827 | button.setDrawableParameters(R.id.action0, false, -1, color, PorterDuff.Mode.SRC_ATOP, |
| 4828 | -1); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4829 | if (!tombstone) { |
| 4830 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 4831 | } |
| 4832 | button.setContentDescription(R.id.action0, action.title); |
| 4833 | return button; |
| 4834 | } |
| 4835 | |
| 4836 | private RemoteViews makeMediaContentView() { |
| 4837 | RemoteViews view = mBuilder.applyStandardTemplate( |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4838 | R.layout.notification_template_material_media, false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4839 | |
| 4840 | final int numActions = mBuilder.mActions.size(); |
| 4841 | final int N = mActionsToShowInCompact == null |
| 4842 | ? 0 |
| 4843 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 4844 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4845 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4846 | for (int i = 0; i < N; i++) { |
| 4847 | if (i >= numActions) { |
| 4848 | throw new IllegalArgumentException(String.format( |
| 4849 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 4850 | i, numActions - 1)); |
| 4851 | } |
| 4852 | |
| 4853 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4854 | final RemoteViews button = generateMediaActionButton(action, |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4855 | mBuilder.resolveContrastColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4856 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4857 | } |
| 4858 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 4859 | handleImage(view); |
| 4860 | // handle the content margin |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4861 | int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4862 | R.dimen.notification_content_margin_end);; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 4863 | if (mBuilder.mN.mLargeIcon != null) { |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4864 | endMargin += mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4865 | R.dimen.notification_content_picture_margin); |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 4866 | } |
| 4867 | view.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4868 | return view; |
| 4869 | } |
| 4870 | |
| 4871 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4872 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4873 | // Dont add an expanded view if there is no more content to be revealed |
| 4874 | int actionsInCompact = mActionsToShowInCompact == null |
| 4875 | ? 0 |
| 4876 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 4877 | if (mBuilder.mN.mLargeIcon == null && actionCount <= actionsInCompact) { |
| 4878 | return null; |
| 4879 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4880 | RemoteViews big = mBuilder.applyStandardTemplate( |
| 4881 | R.layout.notification_template_material_big_media, |
| 4882 | false); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4883 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4884 | if (actionCount > 0) { |
| 4885 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 4886 | for (int i = 0; i < actionCount; i++) { |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4887 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i), |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4888 | mBuilder.resolveContrastColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4889 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4890 | } |
| 4891 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4892 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4893 | return big; |
| 4894 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4895 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4896 | private void handleImage(RemoteViews contentView) { |
| 4897 | if (mBuilder.mN.mLargeIcon != null) { |
| 4898 | contentView.setViewLayoutMarginEnd(R.id.line1, 0); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4899 | contentView.setViewLayoutMarginEnd(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4900 | } |
| 4901 | } |
| 4902 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4903 | /** |
| 4904 | * @hide |
| 4905 | */ |
| 4906 | @Override |
| 4907 | protected boolean hasProgress() { |
| 4908 | return false; |
| 4909 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4910 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4911 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4912 | /** |
| 4913 | * Notification style for custom views that are decorated by the system |
| 4914 | * |
| 4915 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 4916 | * style and still obtain system decorations like the notification header with the expand |
| 4917 | * affordance and actions. |
| 4918 | * |
| 4919 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 4920 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 4921 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 4922 | * corresponding custom views to display. |
| 4923 | * |
| 4924 | * To use this style with your Notification, feed it to |
| 4925 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 4926 | * <pre class="prettyprint"> |
| 4927 | * Notification noti = new Notification.Builder() |
| 4928 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 4929 | * .setLargeIcon(albumArtBitmap)) |
| 4930 | * .setCustomContentView(contentView); |
| 4931 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 4932 | * .build(); |
| 4933 | * </pre> |
| 4934 | */ |
| 4935 | public static class DecoratedCustomViewStyle extends Style { |
| 4936 | |
| 4937 | public DecoratedCustomViewStyle() { |
| 4938 | } |
| 4939 | |
| 4940 | public DecoratedCustomViewStyle(Builder builder) { |
| 4941 | setBuilder(builder); |
| 4942 | } |
| 4943 | |
| 4944 | /** |
| 4945 | * @hide |
| 4946 | */ |
| 4947 | public boolean displayCustomViewInline() { |
| 4948 | return true; |
| 4949 | } |
| 4950 | |
| 4951 | /** |
| 4952 | * @hide |
| 4953 | */ |
| 4954 | @Override |
| 4955 | public RemoteViews makeContentView() { |
| 4956 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 4957 | } |
| 4958 | |
| 4959 | /** |
| 4960 | * @hide |
| 4961 | */ |
| 4962 | @Override |
| 4963 | public RemoteViews makeBigContentView() { |
| 4964 | return makeDecoratedBigContentView(); |
| 4965 | } |
| 4966 | |
| 4967 | /** |
| 4968 | * @hide |
| 4969 | */ |
| 4970 | @Override |
| 4971 | public RemoteViews makeHeadsUpContentView() { |
| 4972 | return makeDecoratedHeadsUpContentView(); |
| 4973 | } |
| 4974 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4975 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 4976 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 4977 | ? mBuilder.mN.contentView |
| 4978 | : mBuilder.mN.headsUpContentView; |
| 4979 | if (mBuilder.mActions.size() == 0) { |
| 4980 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 4981 | } |
| 4982 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 4983 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4984 | buildIntoRemoteViewContent(remoteViews, headsUpContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4985 | return remoteViews; |
| 4986 | } |
| 4987 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4988 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
| 4989 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
| 4990 | mBuilder.getBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4991 | buildIntoRemoteViewContent(remoteViews, customContent); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4992 | return remoteViews; |
| 4993 | } |
| 4994 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4995 | private RemoteViews makeDecoratedBigContentView() { |
| 4996 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 4997 | ? mBuilder.mN.contentView |
| 4998 | : mBuilder.mN.bigContentView; |
| 4999 | if (mBuilder.mActions.size() == 0) { |
| 5000 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 5001 | } |
| 5002 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 5003 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5004 | buildIntoRemoteViewContent(remoteViews, bigContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 5005 | return remoteViews; |
| 5006 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5007 | |
| 5008 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
| 5009 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5010 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 5011 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 5012 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5013 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 5014 | remoteViews.removeAllViews(R.id.notification_main_column); |
| 5015 | remoteViews.addView(R.id.notification_main_column, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5016 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5017 | // also update the end margin if there is an image |
| 5018 | int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 5019 | R.dimen.notification_content_margin_end); |
| 5020 | if (mBuilder.mN.mLargeIcon != null) { |
| 5021 | endMargin += mBuilder.mContext.getResources().getDimensionPixelSize( |
| 5022 | R.dimen.notification_content_picture_margin); |
| 5023 | } |
| 5024 | remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
| 5025 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 5026 | } |
| 5027 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 5028 | /** |
| 5029 | * Notification style for media custom views that are decorated by the system |
| 5030 | * |
| 5031 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 5032 | * this style and still obtain system decorations like the notification header with the expand |
| 5033 | * affordance and actions. |
| 5034 | * |
| 5035 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 5036 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 5037 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 5038 | * corresponding custom views to display. |
| 5039 | * |
| 5040 | * To use this style with your Notification, feed it to |
| 5041 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 5042 | * <pre class="prettyprint"> |
| 5043 | * Notification noti = new Notification.Builder() |
| 5044 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 5045 | * .setLargeIcon(albumArtBitmap)) |
| 5046 | * .setCustomContentView(contentView); |
| 5047 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 5048 | * .setMediaSession(mySession)) |
| 5049 | * .build(); |
| 5050 | * </pre> |
| 5051 | * |
| 5052 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 5053 | * @see android.app.Notification.MediaStyle |
| 5054 | */ |
| 5055 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 5056 | |
| 5057 | public DecoratedMediaCustomViewStyle() { |
| 5058 | } |
| 5059 | |
| 5060 | public DecoratedMediaCustomViewStyle(Builder builder) { |
| 5061 | setBuilder(builder); |
| 5062 | } |
| 5063 | |
| 5064 | /** |
| 5065 | * @hide |
| 5066 | */ |
| 5067 | public boolean displayCustomViewInline() { |
| 5068 | return true; |
| 5069 | } |
| 5070 | |
| 5071 | /** |
| 5072 | * @hide |
| 5073 | */ |
| 5074 | @Override |
| 5075 | public RemoteViews makeContentView() { |
| 5076 | RemoteViews remoteViews = super.makeContentView(); |
| 5077 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 5078 | mBuilder.mN.contentView); |
| 5079 | } |
| 5080 | |
| 5081 | /** |
| 5082 | * @hide |
| 5083 | */ |
| 5084 | @Override |
| 5085 | public RemoteViews makeBigContentView() { |
| 5086 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 5087 | ? mBuilder.mN.bigContentView |
| 5088 | : mBuilder.mN.contentView; |
| 5089 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 5090 | } |
| 5091 | |
| 5092 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 5093 | RemoteViews remoteViews = super.makeBigContentView(); |
| 5094 | if (remoteViews != null) { |
| 5095 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 5096 | customRemoteView); |
| 5097 | } else if (customRemoteView != mBuilder.mN.contentView){ |
| 5098 | remoteViews = super.makeContentView(); |
| 5099 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 5100 | customRemoteView); |
| 5101 | } else { |
| 5102 | return null; |
| 5103 | } |
| 5104 | } |
| 5105 | |
| 5106 | /** |
| 5107 | * @hide |
| 5108 | */ |
| 5109 | @Override |
| 5110 | public RemoteViews makeHeadsUpContentView() { |
| 5111 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 5112 | ? mBuilder.mN.headsUpContentView |
| 5113 | : mBuilder.mN.contentView; |
| 5114 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 5115 | } |
| 5116 | |
| 5117 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 5118 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5119 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 5120 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 5121 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5122 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 5123 | remoteViews.removeAllViews(id); |
| 5124 | remoteViews.addView(id, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5125 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 5126 | return remoteViews; |
| 5127 | } |
| 5128 | } |
| 5129 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5130 | // When adding a new Style subclass here, don't forget to update |
| 5131 | // Builder.getNotificationStyleClass. |
| 5132 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5133 | /** |
| 5134 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 5135 | * metadata or change options on a notification builder. |
| 5136 | */ |
| 5137 | public interface Extender { |
| 5138 | /** |
| 5139 | * Apply this extender to a notification builder. |
| 5140 | * @param builder the builder to be modified. |
| 5141 | * @return the build object for chaining. |
| 5142 | */ |
| 5143 | public Builder extend(Builder builder); |
| 5144 | } |
| 5145 | |
| 5146 | /** |
| 5147 | * Helper class to add wearable extensions to notifications. |
| 5148 | * <p class="note"> See |
| 5149 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 5150 | * for Android Wear</a> for more information on how to use this class. |
| 5151 | * <p> |
| 5152 | * To create a notification with wearable extensions: |
| 5153 | * <ol> |
| 5154 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 5155 | * properties. |
| 5156 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 5157 | * <li>Set wearable-specific properties using the |
| 5158 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 5159 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 5160 | * notification. |
| 5161 | * <li>Post the notification to the notification system with the |
| 5162 | * {@code NotificationManager.notify(...)} methods. |
| 5163 | * </ol> |
| 5164 | * |
| 5165 | * <pre class="prettyprint"> |
| 5166 | * Notification notif = new Notification.Builder(mContext) |
| 5167 | * .setContentTitle("New mail from " + sender.toString()) |
| 5168 | * .setContentText(subject) |
| 5169 | * .setSmallIcon(R.drawable.new_mail) |
| 5170 | * .extend(new Notification.WearableExtender() |
| 5171 | * .setContentIcon(R.drawable.new_mail)) |
| 5172 | * .build(); |
| 5173 | * NotificationManager notificationManger = |
| 5174 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 5175 | * notificationManger.notify(0, notif);</pre> |
| 5176 | * |
| 5177 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 5178 | * {@code WearableExtender(Notification)} constructor, |
| 5179 | * and then using the {@code get} methods to access values. |
| 5180 | * |
| 5181 | * <pre class="prettyprint"> |
| 5182 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 5183 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5184 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5185 | */ |
| 5186 | public static final class WearableExtender implements Extender { |
| 5187 | /** |
| 5188 | * Sentinel value for an action index that is unset. |
| 5189 | */ |
| 5190 | public static final int UNSET_ACTION_INDEX = -1; |
| 5191 | |
| 5192 | /** |
| 5193 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 5194 | * default sizing. |
| 5195 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 5196 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5197 | * on their content. |
| 5198 | */ |
| 5199 | public static final int SIZE_DEFAULT = 0; |
| 5200 | |
| 5201 | /** |
| 5202 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 5203 | * with an extra small size. |
| 5204 | * <p>This value is only applicable for custom display notifications created using |
| 5205 | * {@link #setDisplayIntent}. |
| 5206 | */ |
| 5207 | public static final int SIZE_XSMALL = 1; |
| 5208 | |
| 5209 | /** |
| 5210 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 5211 | * with a small size. |
| 5212 | * <p>This value is only applicable for custom display notifications created using |
| 5213 | * {@link #setDisplayIntent}. |
| 5214 | */ |
| 5215 | public static final int SIZE_SMALL = 2; |
| 5216 | |
| 5217 | /** |
| 5218 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 5219 | * with a medium size. |
| 5220 | * <p>This value is only applicable for custom display notifications created using |
| 5221 | * {@link #setDisplayIntent}. |
| 5222 | */ |
| 5223 | public static final int SIZE_MEDIUM = 3; |
| 5224 | |
| 5225 | /** |
| 5226 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 5227 | * with a large size. |
| 5228 | * <p>This value is only applicable for custom display notifications created using |
| 5229 | * {@link #setDisplayIntent}. |
| 5230 | */ |
| 5231 | public static final int SIZE_LARGE = 4; |
| 5232 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 5233 | /** |
| 5234 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 5235 | * full screen. |
| 5236 | * <p>This value is only applicable for custom display notifications created using |
| 5237 | * {@link #setDisplayIntent}. |
| 5238 | */ |
| 5239 | public static final int SIZE_FULL_SCREEN = 5; |
| 5240 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5241 | /** |
| 5242 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 5243 | * short amount of time when this notification is displayed on the screen. This |
| 5244 | * is the default value. |
| 5245 | */ |
| 5246 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 5247 | |
| 5248 | /** |
| 5249 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 5250 | * for a longer amount of time when this notification is displayed on the screen. |
| 5251 | */ |
| 5252 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 5253 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5254 | /** Notification extra which contains wearable extensions */ |
| 5255 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 5256 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 5257 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5258 | private static final String KEY_ACTIONS = "actions"; |
| 5259 | private static final String KEY_FLAGS = "flags"; |
| 5260 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 5261 | private static final String KEY_PAGES = "pages"; |
| 5262 | private static final String KEY_BACKGROUND = "background"; |
| 5263 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 5264 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 5265 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 5266 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 5267 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 5268 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5269 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5270 | |
| 5271 | // Flags bitwise-ored to mFlags |
| 5272 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 5273 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 5274 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 5275 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5276 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 5277 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5278 | |
| 5279 | // Default value for flags integer |
| 5280 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 5281 | |
| 5282 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 5283 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 5284 | |
| 5285 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 5286 | private int mFlags = DEFAULT_FLAGS; |
| 5287 | private PendingIntent mDisplayIntent; |
| 5288 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 5289 | private Bitmap mBackground; |
| 5290 | private int mContentIcon; |
| 5291 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 5292 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 5293 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 5294 | private int mCustomContentHeight; |
| 5295 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5296 | private int mHintScreenTimeout; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5297 | |
| 5298 | /** |
| 5299 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 5300 | * options. |
| 5301 | */ |
| 5302 | public WearableExtender() { |
| 5303 | } |
| 5304 | |
| 5305 | public WearableExtender(Notification notif) { |
| 5306 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 5307 | if (wearableBundle != null) { |
| 5308 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 5309 | if (actions != null) { |
| 5310 | mActions.addAll(actions); |
| 5311 | } |
| 5312 | |
| 5313 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 5314 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 5315 | |
| 5316 | Notification[] pages = getNotificationArrayFromBundle( |
| 5317 | wearableBundle, KEY_PAGES); |
| 5318 | if (pages != null) { |
| 5319 | Collections.addAll(mPages, pages); |
| 5320 | } |
| 5321 | |
| 5322 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 5323 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 5324 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 5325 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 5326 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 5327 | UNSET_ACTION_INDEX); |
| 5328 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 5329 | SIZE_DEFAULT); |
| 5330 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 5331 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5332 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5333 | } |
| 5334 | } |
| 5335 | |
| 5336 | /** |
| 5337 | * Apply wearable extensions to a notification that is being built. This is typically |
| 5338 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 5339 | * {@link android.app.Notification.Builder}. |
| 5340 | */ |
| 5341 | @Override |
| 5342 | public Notification.Builder extend(Notification.Builder builder) { |
| 5343 | Bundle wearableBundle = new Bundle(); |
| 5344 | |
| 5345 | if (!mActions.isEmpty()) { |
| 5346 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 5347 | } |
| 5348 | if (mFlags != DEFAULT_FLAGS) { |
| 5349 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 5350 | } |
| 5351 | if (mDisplayIntent != null) { |
| 5352 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 5353 | } |
| 5354 | if (!mPages.isEmpty()) { |
| 5355 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 5356 | new Notification[mPages.size()])); |
| 5357 | } |
| 5358 | if (mBackground != null) { |
| 5359 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 5360 | } |
| 5361 | if (mContentIcon != 0) { |
| 5362 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 5363 | } |
| 5364 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 5365 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 5366 | } |
| 5367 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 5368 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 5369 | mContentActionIndex); |
| 5370 | } |
| 5371 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 5372 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 5373 | } |
| 5374 | if (mCustomContentHeight != 0) { |
| 5375 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 5376 | } |
| 5377 | if (mGravity != DEFAULT_GRAVITY) { |
| 5378 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 5379 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5380 | if (mHintScreenTimeout != 0) { |
| 5381 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 5382 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5383 | |
| 5384 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 5385 | return builder; |
| 5386 | } |
| 5387 | |
| 5388 | @Override |
| 5389 | public WearableExtender clone() { |
| 5390 | WearableExtender that = new WearableExtender(); |
| 5391 | that.mActions = new ArrayList<Action>(this.mActions); |
| 5392 | that.mFlags = this.mFlags; |
| 5393 | that.mDisplayIntent = this.mDisplayIntent; |
| 5394 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 5395 | that.mBackground = this.mBackground; |
| 5396 | that.mContentIcon = this.mContentIcon; |
| 5397 | that.mContentIconGravity = this.mContentIconGravity; |
| 5398 | that.mContentActionIndex = this.mContentActionIndex; |
| 5399 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 5400 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 5401 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5402 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5403 | return that; |
| 5404 | } |
| 5405 | |
| 5406 | /** |
| 5407 | * Add a wearable action to this notification. |
| 5408 | * |
| 5409 | * <p>When wearable actions are added using this method, the set of actions that |
| 5410 | * show on a wearable device splits from devices that only show actions added |
| 5411 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 5412 | * of which actions display on different devices. |
| 5413 | * |
| 5414 | * @param action the action to add to this notification |
| 5415 | * @return this object for method chaining |
| 5416 | * @see android.app.Notification.Action |
| 5417 | */ |
| 5418 | public WearableExtender addAction(Action action) { |
| 5419 | mActions.add(action); |
| 5420 | return this; |
| 5421 | } |
| 5422 | |
| 5423 | /** |
| 5424 | * Adds wearable actions to this notification. |
| 5425 | * |
| 5426 | * <p>When wearable actions are added using this method, the set of actions that |
| 5427 | * show on a wearable device splits from devices that only show actions added |
| 5428 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 5429 | * of which actions display on different devices. |
| 5430 | * |
| 5431 | * @param actions the actions to add to this notification |
| 5432 | * @return this object for method chaining |
| 5433 | * @see android.app.Notification.Action |
| 5434 | */ |
| 5435 | public WearableExtender addActions(List<Action> actions) { |
| 5436 | mActions.addAll(actions); |
| 5437 | return this; |
| 5438 | } |
| 5439 | |
| 5440 | /** |
| 5441 | * Clear all wearable actions present on this builder. |
| 5442 | * @return this object for method chaining. |
| 5443 | * @see #addAction |
| 5444 | */ |
| 5445 | public WearableExtender clearActions() { |
| 5446 | mActions.clear(); |
| 5447 | return this; |
| 5448 | } |
| 5449 | |
| 5450 | /** |
| 5451 | * Get the wearable actions present on this notification. |
| 5452 | */ |
| 5453 | public List<Action> getActions() { |
| 5454 | return mActions; |
| 5455 | } |
| 5456 | |
| 5457 | /** |
| 5458 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5459 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 5460 | * |
| 5461 | * <pre class="prettyprint"> |
| 5462 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 5463 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 5464 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 5465 | * Notification notif = new Notification.Builder(context) |
| 5466 | * .extend(new Notification.WearableExtender() |
| 5467 | * .setDisplayIntent(displayPendingIntent) |
| 5468 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 5469 | * .build();</pre> |
| 5470 | * |
| 5471 | * <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] | 5472 | * should have an empty task affinity. It is also recommended to use the device |
| 5473 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5474 | * |
| 5475 | * <p>Example AndroidManifest.xml entry: |
| 5476 | * <pre class="prettyprint"> |
| 5477 | * <activity android:name="com.example.MyDisplayActivity" |
| 5478 | * android:exported="true" |
| 5479 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 5480 | * android:taskAffinity="" |
| 5481 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5482 | * |
| 5483 | * @param intent the {@link PendingIntent} for an activity |
| 5484 | * @return this object for method chaining |
| 5485 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 5486 | */ |
| 5487 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 5488 | mDisplayIntent = intent; |
| 5489 | return this; |
| 5490 | } |
| 5491 | |
| 5492 | /** |
| 5493 | * Get the intent to launch inside of an activity view when displaying this |
| 5494 | * notification. This {@code PendingIntent} should be for an activity. |
| 5495 | */ |
| 5496 | public PendingIntent getDisplayIntent() { |
| 5497 | return mDisplayIntent; |
| 5498 | } |
| 5499 | |
| 5500 | /** |
| 5501 | * Add an additional page of content to display with this notification. The current |
| 5502 | * notification forms the first page, and pages added using this function form |
| 5503 | * subsequent pages. This field can be used to separate a notification into multiple |
| 5504 | * sections. |
| 5505 | * |
| 5506 | * @param page the notification to add as another page |
| 5507 | * @return this object for method chaining |
| 5508 | * @see android.app.Notification.WearableExtender#getPages |
| 5509 | */ |
| 5510 | public WearableExtender addPage(Notification page) { |
| 5511 | mPages.add(page); |
| 5512 | return this; |
| 5513 | } |
| 5514 | |
| 5515 | /** |
| 5516 | * Add additional pages of content to display with this notification. The current |
| 5517 | * notification forms the first page, and pages added using this function form |
| 5518 | * subsequent pages. This field can be used to separate a notification into multiple |
| 5519 | * sections. |
| 5520 | * |
| 5521 | * @param pages a list of notifications |
| 5522 | * @return this object for method chaining |
| 5523 | * @see android.app.Notification.WearableExtender#getPages |
| 5524 | */ |
| 5525 | public WearableExtender addPages(List<Notification> pages) { |
| 5526 | mPages.addAll(pages); |
| 5527 | return this; |
| 5528 | } |
| 5529 | |
| 5530 | /** |
| 5531 | * Clear all additional pages present on this builder. |
| 5532 | * @return this object for method chaining. |
| 5533 | * @see #addPage |
| 5534 | */ |
| 5535 | public WearableExtender clearPages() { |
| 5536 | mPages.clear(); |
| 5537 | return this; |
| 5538 | } |
| 5539 | |
| 5540 | /** |
| 5541 | * Get the array of additional pages of content for displaying this notification. The |
| 5542 | * current notification forms the first page, and elements within this array form |
| 5543 | * subsequent pages. This field can be used to separate a notification into multiple |
| 5544 | * sections. |
| 5545 | * @return the pages for this notification |
| 5546 | */ |
| 5547 | public List<Notification> getPages() { |
| 5548 | return mPages; |
| 5549 | } |
| 5550 | |
| 5551 | /** |
| 5552 | * Set a background image to be displayed behind the notification content. |
| 5553 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 5554 | * will work with any notification style. |
| 5555 | * |
| 5556 | * @param background the background bitmap |
| 5557 | * @return this object for method chaining |
| 5558 | * @see android.app.Notification.WearableExtender#getBackground |
| 5559 | */ |
| 5560 | public WearableExtender setBackground(Bitmap background) { |
| 5561 | mBackground = background; |
| 5562 | return this; |
| 5563 | } |
| 5564 | |
| 5565 | /** |
| 5566 | * Get a background image to be displayed behind the notification content. |
| 5567 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 5568 | * will work with any notification style. |
| 5569 | * |
| 5570 | * @return the background image |
| 5571 | * @see android.app.Notification.WearableExtender#setBackground |
| 5572 | */ |
| 5573 | public Bitmap getBackground() { |
| 5574 | return mBackground; |
| 5575 | } |
| 5576 | |
| 5577 | /** |
| 5578 | * Set an icon that goes with the content of this notification. |
| 5579 | */ |
| 5580 | public WearableExtender setContentIcon(int icon) { |
| 5581 | mContentIcon = icon; |
| 5582 | return this; |
| 5583 | } |
| 5584 | |
| 5585 | /** |
| 5586 | * Get an icon that goes with the content of this notification. |
| 5587 | */ |
| 5588 | public int getContentIcon() { |
| 5589 | return mContentIcon; |
| 5590 | } |
| 5591 | |
| 5592 | /** |
| 5593 | * Set the gravity that the content icon should have within the notification display. |
| 5594 | * Supported values include {@link android.view.Gravity#START} and |
| 5595 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 5596 | * @see #setContentIcon |
| 5597 | */ |
| 5598 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 5599 | mContentIconGravity = contentIconGravity; |
| 5600 | return this; |
| 5601 | } |
| 5602 | |
| 5603 | /** |
| 5604 | * Get the gravity that the content icon should have within the notification display. |
| 5605 | * Supported values include {@link android.view.Gravity#START} and |
| 5606 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 5607 | * @see #getContentIcon |
| 5608 | */ |
| 5609 | public int getContentIconGravity() { |
| 5610 | return mContentIconGravity; |
| 5611 | } |
| 5612 | |
| 5613 | /** |
| 5614 | * 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] | 5615 | * this notification. This action will no longer display separately from the |
| 5616 | * notification's content. |
| 5617 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 5618 | * <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] | 5619 | * set, although the list of available actions comes from the main notification and not |
| 5620 | * from the child page's notification. |
| 5621 | * |
| 5622 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 5623 | * If wearable actions were added to the main notification, this index |
| 5624 | * will apply to that list, otherwise it will apply to the regular |
| 5625 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5626 | */ |
| 5627 | public WearableExtender setContentAction(int actionIndex) { |
| 5628 | mContentActionIndex = actionIndex; |
| 5629 | return this; |
| 5630 | } |
| 5631 | |
| 5632 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 5633 | * Get the index of the notification action, if any, that was specified as being clickable |
| 5634 | * 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] | 5635 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5636 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 5637 | * <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] | 5638 | * set, although the list of available actions comes from the main notification and not |
| 5639 | * from the child page's notification. |
| 5640 | * |
| 5641 | * <p>If wearable specific actions were added to the main notification, this index will |
| 5642 | * 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] | 5643 | * |
| 5644 | * @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] | 5645 | */ |
| 5646 | public int getContentAction() { |
| 5647 | return mContentActionIndex; |
| 5648 | } |
| 5649 | |
| 5650 | /** |
| 5651 | * Set the gravity that this notification should have within the available viewport space. |
| 5652 | * Supported values include {@link android.view.Gravity#TOP}, |
| 5653 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 5654 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 5655 | */ |
| 5656 | public WearableExtender setGravity(int gravity) { |
| 5657 | mGravity = gravity; |
| 5658 | return this; |
| 5659 | } |
| 5660 | |
| 5661 | /** |
| 5662 | * Get the gravity that this notification should have within the available viewport space. |
| 5663 | * Supported values include {@link android.view.Gravity#TOP}, |
| 5664 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 5665 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 5666 | */ |
| 5667 | public int getGravity() { |
| 5668 | return mGravity; |
| 5669 | } |
| 5670 | |
| 5671 | /** |
| 5672 | * Set the custom size preset for the display of this notification out of the available |
| 5673 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 5674 | * {@link #SIZE_LARGE}. |
| 5675 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 5676 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 5677 | * documentation for the preset in question. See also |
| 5678 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 5679 | */ |
| 5680 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 5681 | mCustomSizePreset = sizePreset; |
| 5682 | return this; |
| 5683 | } |
| 5684 | |
| 5685 | /** |
| 5686 | * Get the custom size preset for the display of this notification out of the available |
| 5687 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 5688 | * {@link #SIZE_LARGE}. |
| 5689 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 5690 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 5691 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 5692 | */ |
| 5693 | public int getCustomSizePreset() { |
| 5694 | return mCustomSizePreset; |
| 5695 | } |
| 5696 | |
| 5697 | /** |
| 5698 | * Set the custom height in pixels for the display of this notification's content. |
| 5699 | * <p>This option is only available for custom display notifications created |
| 5700 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 5701 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 5702 | * {@link #getCustomContentHeight}. |
| 5703 | */ |
| 5704 | public WearableExtender setCustomContentHeight(int height) { |
| 5705 | mCustomContentHeight = height; |
| 5706 | return this; |
| 5707 | } |
| 5708 | |
| 5709 | /** |
| 5710 | * Get the custom height in pixels for the display of this notification's content. |
| 5711 | * <p>This option is only available for custom display notifications created |
| 5712 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 5713 | * {@link #setCustomContentHeight}. |
| 5714 | */ |
| 5715 | public int getCustomContentHeight() { |
| 5716 | return mCustomContentHeight; |
| 5717 | } |
| 5718 | |
| 5719 | /** |
| 5720 | * Set whether the scrolling position for the contents of this notification should start |
| 5721 | * at the bottom of the contents instead of the top when the contents are too long to |
| 5722 | * display within the screen. Default is false (start scroll at the top). |
| 5723 | */ |
| 5724 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 5725 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 5726 | return this; |
| 5727 | } |
| 5728 | |
| 5729 | /** |
| 5730 | * Get whether the scrolling position for the contents of this notification should start |
| 5731 | * at the bottom of the contents instead of the top when the contents are too long to |
| 5732 | * display within the screen. Default is false (start scroll at the top). |
| 5733 | */ |
| 5734 | public boolean getStartScrollBottom() { |
| 5735 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 5736 | } |
| 5737 | |
| 5738 | /** |
| 5739 | * Set whether the content intent is available when the wearable device is not connected |
| 5740 | * to a companion device. The user can still trigger this intent when the wearable device |
| 5741 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 5742 | * Defaults to true. |
| 5743 | */ |
| 5744 | public WearableExtender setContentIntentAvailableOffline( |
| 5745 | boolean contentIntentAvailableOffline) { |
| 5746 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 5747 | return this; |
| 5748 | } |
| 5749 | |
| 5750 | /** |
| 5751 | * Get whether the content intent is available when the wearable device is not connected |
| 5752 | * to a companion device. The user can still trigger this intent when the wearable device |
| 5753 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 5754 | * Defaults to true. |
| 5755 | */ |
| 5756 | public boolean getContentIntentAvailableOffline() { |
| 5757 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 5758 | } |
| 5759 | |
| 5760 | /** |
| 5761 | * Set a hint that this notification's icon should not be displayed. |
| 5762 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 5763 | * @return this object for method chaining |
| 5764 | */ |
| 5765 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 5766 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 5767 | return this; |
| 5768 | } |
| 5769 | |
| 5770 | /** |
| 5771 | * Get a hint that this notification's icon should not be displayed. |
| 5772 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 5773 | * The default value is {@code false} if this was never set. |
| 5774 | */ |
| 5775 | public boolean getHintHideIcon() { |
| 5776 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 5777 | } |
| 5778 | |
| 5779 | /** |
| 5780 | * Set a visual hint that only the background image of this notification should be |
| 5781 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 5782 | * to sub-pages added using {@link #addPage}. |
| 5783 | */ |
| 5784 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 5785 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 5786 | return this; |
| 5787 | } |
| 5788 | |
| 5789 | /** |
| 5790 | * Get a visual hint that only the background image of this notification should be |
| 5791 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 5792 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 5793 | */ |
| 5794 | public boolean getHintShowBackgroundOnly() { |
| 5795 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 5796 | } |
| 5797 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5798 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 5799 | * Set a hint that this notification's background should not be clipped if possible, |
| 5800 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 5801 | * 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] | 5802 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 5803 | * @return this object for method chaining |
| 5804 | */ |
| 5805 | public WearableExtender setHintAvoidBackgroundClipping( |
| 5806 | boolean hintAvoidBackgroundClipping) { |
| 5807 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 5808 | return this; |
| 5809 | } |
| 5810 | |
| 5811 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 5812 | * Get a hint that this notification's background should not be clipped if possible, |
| 5813 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 5814 | * 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] | 5815 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 5816 | * otherwise. The default value is {@code false} if this was never set. |
| 5817 | */ |
| 5818 | public boolean getHintAvoidBackgroundClipping() { |
| 5819 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 5820 | } |
| 5821 | |
| 5822 | /** |
| 5823 | * Set a hint that the screen should remain on for at least this duration when |
| 5824 | * this notification is displayed on the screen. |
| 5825 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 5826 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 5827 | * @return this object for method chaining |
| 5828 | */ |
| 5829 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 5830 | mHintScreenTimeout = timeout; |
| 5831 | return this; |
| 5832 | } |
| 5833 | |
| 5834 | /** |
| 5835 | * Get the duration, in milliseconds, that the screen should remain on for |
| 5836 | * when this notification is displayed. |
| 5837 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 5838 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 5839 | */ |
| 5840 | public int getHintScreenTimeout() { |
| 5841 | return mHintScreenTimeout; |
| 5842 | } |
| 5843 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 5844 | /** |
| 5845 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 5846 | * directly, telling the platform that it can generate the appropriate transitions. |
| 5847 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 5848 | * an activity and transitions should be generated, false otherwise. |
| 5849 | * @return this object for method chaining |
| 5850 | */ |
| 5851 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 5852 | boolean hintContentIntentLaunchesActivity) { |
| 5853 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 5854 | return this; |
| 5855 | } |
| 5856 | |
| 5857 | /** |
| 5858 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 5859 | * directly, telling the platform that it can generate the appropriate transitions |
| 5860 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 5861 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 5862 | */ |
| 5863 | public boolean getHintContentIntentLaunchesActivity() { |
| 5864 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 5865 | } |
| 5866 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5867 | private void setFlag(int mask, boolean value) { |
| 5868 | if (value) { |
| 5869 | mFlags |= mask; |
| 5870 | } else { |
| 5871 | mFlags &= ~mask; |
| 5872 | } |
| 5873 | } |
| 5874 | } |
| 5875 | |
| 5876 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5877 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 5878 | * with car extensions: |
| 5879 | * |
| 5880 | * <ol> |
| 5881 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 5882 | * properties. |
| 5883 | * <li>Create a {@link CarExtender}. |
| 5884 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 5885 | * {@link CarExtender}. |
| 5886 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 5887 | * to apply the extensions to a notification. |
| 5888 | * </ol> |
| 5889 | * |
| 5890 | * <pre class="prettyprint"> |
| 5891 | * Notification notification = new Notification.Builder(context) |
| 5892 | * ... |
| 5893 | * .extend(new CarExtender() |
| 5894 | * .set*(...)) |
| 5895 | * .build(); |
| 5896 | * </pre> |
| 5897 | * |
| 5898 | * <p>Car extensions can be accessed on an existing notification by using the |
| 5899 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 5900 | * to access values. |
| 5901 | */ |
| 5902 | public static final class CarExtender implements Extender { |
| 5903 | private static final String TAG = "CarExtender"; |
| 5904 | |
| 5905 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 5906 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 5907 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 5908 | private static final String EXTRA_COLOR = "app_color"; |
| 5909 | |
| 5910 | private Bitmap mLargeIcon; |
| 5911 | private UnreadConversation mUnreadConversation; |
| 5912 | private int mColor = Notification.COLOR_DEFAULT; |
| 5913 | |
| 5914 | /** |
| 5915 | * Create a {@link CarExtender} with default options. |
| 5916 | */ |
| 5917 | public CarExtender() { |
| 5918 | } |
| 5919 | |
| 5920 | /** |
| 5921 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 5922 | * |
| 5923 | * @param notif The notification from which to copy options. |
| 5924 | */ |
| 5925 | public CarExtender(Notification notif) { |
| 5926 | Bundle carBundle = notif.extras == null ? |
| 5927 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 5928 | if (carBundle != null) { |
| 5929 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 5930 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 5931 | |
| 5932 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 5933 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 5934 | } |
| 5935 | } |
| 5936 | |
| 5937 | /** |
| 5938 | * Apply car extensions to a notification that is being built. This is typically called by |
| 5939 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 5940 | * method of {@link Notification.Builder}. |
| 5941 | */ |
| 5942 | @Override |
| 5943 | public Notification.Builder extend(Notification.Builder builder) { |
| 5944 | Bundle carExtensions = new Bundle(); |
| 5945 | |
| 5946 | if (mLargeIcon != null) { |
| 5947 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 5948 | } |
| 5949 | if (mColor != Notification.COLOR_DEFAULT) { |
| 5950 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 5951 | } |
| 5952 | |
| 5953 | if (mUnreadConversation != null) { |
| 5954 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 5955 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 5956 | } |
| 5957 | |
| 5958 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 5959 | return builder; |
| 5960 | } |
| 5961 | |
| 5962 | /** |
| 5963 | * Sets the accent color to use when Android Auto presents the notification. |
| 5964 | * |
| 5965 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 5966 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 5967 | * automotive setting. This method can be used to override the color provided in the |
| 5968 | * notification in such a situation. |
| 5969 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 5970 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5971 | mColor = color; |
| 5972 | return this; |
| 5973 | } |
| 5974 | |
| 5975 | /** |
| 5976 | * Gets the accent color. |
| 5977 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5978 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5979 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 5980 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5981 | public int getColor() { |
| 5982 | return mColor; |
| 5983 | } |
| 5984 | |
| 5985 | /** |
| 5986 | * Sets the large icon of the car notification. |
| 5987 | * |
| 5988 | * If no large icon is set in the extender, Android Auto will display the icon |
| 5989 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 5990 | * |
| 5991 | * @param largeIcon The large icon to use in the car notification. |
| 5992 | * @return This object for method chaining. |
| 5993 | */ |
| 5994 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 5995 | mLargeIcon = largeIcon; |
| 5996 | return this; |
| 5997 | } |
| 5998 | |
| 5999 | /** |
| 6000 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 6001 | * |
| 6002 | * @return The large icon for the car notification. |
| 6003 | * @see CarExtender#setLargeIcon |
| 6004 | */ |
| 6005 | public Bitmap getLargeIcon() { |
| 6006 | return mLargeIcon; |
| 6007 | } |
| 6008 | |
| 6009 | /** |
| 6010 | * Sets the unread conversation in a message notification. |
| 6011 | * |
| 6012 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 6013 | * @return This object for method chaining. |
| 6014 | */ |
| 6015 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 6016 | mUnreadConversation = unreadConversation; |
| 6017 | return this; |
| 6018 | } |
| 6019 | |
| 6020 | /** |
| 6021 | * Returns the unread conversation conveyed by this notification. |
| 6022 | * @see #setUnreadConversation(UnreadConversation) |
| 6023 | */ |
| 6024 | public UnreadConversation getUnreadConversation() { |
| 6025 | return mUnreadConversation; |
| 6026 | } |
| 6027 | |
| 6028 | /** |
| 6029 | * A class which holds the unread messages from a conversation. |
| 6030 | */ |
| 6031 | public static class UnreadConversation { |
| 6032 | private static final String KEY_AUTHOR = "author"; |
| 6033 | private static final String KEY_TEXT = "text"; |
| 6034 | private static final String KEY_MESSAGES = "messages"; |
| 6035 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 6036 | private static final String KEY_ON_REPLY = "on_reply"; |
| 6037 | private static final String KEY_ON_READ = "on_read"; |
| 6038 | private static final String KEY_PARTICIPANTS = "participants"; |
| 6039 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 6040 | |
| 6041 | private final String[] mMessages; |
| 6042 | private final RemoteInput mRemoteInput; |
| 6043 | private final PendingIntent mReplyPendingIntent; |
| 6044 | private final PendingIntent mReadPendingIntent; |
| 6045 | private final String[] mParticipants; |
| 6046 | private final long mLatestTimestamp; |
| 6047 | |
| 6048 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 6049 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 6050 | String[] participants, long latestTimestamp) { |
| 6051 | mMessages = messages; |
| 6052 | mRemoteInput = remoteInput; |
| 6053 | mReadPendingIntent = readPendingIntent; |
| 6054 | mReplyPendingIntent = replyPendingIntent; |
| 6055 | mParticipants = participants; |
| 6056 | mLatestTimestamp = latestTimestamp; |
| 6057 | } |
| 6058 | |
| 6059 | /** |
| 6060 | * Gets the list of messages conveyed by this notification. |
| 6061 | */ |
| 6062 | public String[] getMessages() { |
| 6063 | return mMessages; |
| 6064 | } |
| 6065 | |
| 6066 | /** |
| 6067 | * Gets the remote input that will be used to convey the response to a message list, or |
| 6068 | * null if no such remote input exists. |
| 6069 | */ |
| 6070 | public RemoteInput getRemoteInput() { |
| 6071 | return mRemoteInput; |
| 6072 | } |
| 6073 | |
| 6074 | /** |
| 6075 | * Gets the pending intent that will be triggered when the user replies to this |
| 6076 | * notification. |
| 6077 | */ |
| 6078 | public PendingIntent getReplyPendingIntent() { |
| 6079 | return mReplyPendingIntent; |
| 6080 | } |
| 6081 | |
| 6082 | /** |
| 6083 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 6084 | * in this object's message list. |
| 6085 | */ |
| 6086 | public PendingIntent getReadPendingIntent() { |
| 6087 | return mReadPendingIntent; |
| 6088 | } |
| 6089 | |
| 6090 | /** |
| 6091 | * Gets the participants in the conversation. |
| 6092 | */ |
| 6093 | public String[] getParticipants() { |
| 6094 | return mParticipants; |
| 6095 | } |
| 6096 | |
| 6097 | /** |
| 6098 | * Gets the firs participant in the conversation. |
| 6099 | */ |
| 6100 | public String getParticipant() { |
| 6101 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 6102 | } |
| 6103 | |
| 6104 | /** |
| 6105 | * Gets the timestamp of the conversation. |
| 6106 | */ |
| 6107 | public long getLatestTimestamp() { |
| 6108 | return mLatestTimestamp; |
| 6109 | } |
| 6110 | |
| 6111 | Bundle getBundleForUnreadConversation() { |
| 6112 | Bundle b = new Bundle(); |
| 6113 | String author = null; |
| 6114 | if (mParticipants != null && mParticipants.length > 1) { |
| 6115 | author = mParticipants[0]; |
| 6116 | } |
| 6117 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 6118 | for (int i = 0; i < messages.length; i++) { |
| 6119 | Bundle m = new Bundle(); |
| 6120 | m.putString(KEY_TEXT, mMessages[i]); |
| 6121 | m.putString(KEY_AUTHOR, author); |
| 6122 | messages[i] = m; |
| 6123 | } |
| 6124 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 6125 | if (mRemoteInput != null) { |
| 6126 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 6127 | } |
| 6128 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 6129 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 6130 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 6131 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 6132 | return b; |
| 6133 | } |
| 6134 | |
| 6135 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 6136 | if (b == null) { |
| 6137 | return null; |
| 6138 | } |
| 6139 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 6140 | String[] messages = null; |
| 6141 | if (parcelableMessages != null) { |
| 6142 | String[] tmp = new String[parcelableMessages.length]; |
| 6143 | boolean success = true; |
| 6144 | for (int i = 0; i < tmp.length; i++) { |
| 6145 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 6146 | success = false; |
| 6147 | break; |
| 6148 | } |
| 6149 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 6150 | if (tmp[i] == null) { |
| 6151 | success = false; |
| 6152 | break; |
| 6153 | } |
| 6154 | } |
| 6155 | if (success) { |
| 6156 | messages = tmp; |
| 6157 | } else { |
| 6158 | return null; |
| 6159 | } |
| 6160 | } |
| 6161 | |
| 6162 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 6163 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 6164 | |
| 6165 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 6166 | |
| 6167 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 6168 | if (participants == null || participants.length != 1) { |
| 6169 | return null; |
| 6170 | } |
| 6171 | |
| 6172 | return new UnreadConversation(messages, |
| 6173 | remoteInput, |
| 6174 | onReply, |
| 6175 | onRead, |
| 6176 | participants, b.getLong(KEY_TIMESTAMP)); |
| 6177 | } |
| 6178 | }; |
| 6179 | |
| 6180 | /** |
| 6181 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 6182 | */ |
| 6183 | public static class Builder { |
| 6184 | private final List<String> mMessages = new ArrayList<String>(); |
| 6185 | private final String mParticipant; |
| 6186 | private RemoteInput mRemoteInput; |
| 6187 | private PendingIntent mReadPendingIntent; |
| 6188 | private PendingIntent mReplyPendingIntent; |
| 6189 | private long mLatestTimestamp; |
| 6190 | |
| 6191 | /** |
| 6192 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 6193 | * |
| 6194 | * @param name The name of the other participant in the conversation. |
| 6195 | */ |
| 6196 | public Builder(String name) { |
| 6197 | mParticipant = name; |
| 6198 | } |
| 6199 | |
| 6200 | /** |
| 6201 | * Appends a new unread message to the list of messages for this conversation. |
| 6202 | * |
| 6203 | * The messages should be added from oldest to newest. |
| 6204 | * |
| 6205 | * @param message The text of the new unread message. |
| 6206 | * @return This object for method chaining. |
| 6207 | */ |
| 6208 | public Builder addMessage(String message) { |
| 6209 | mMessages.add(message); |
| 6210 | return this; |
| 6211 | } |
| 6212 | |
| 6213 | /** |
| 6214 | * Sets the pending intent and remote input which will convey the reply to this |
| 6215 | * notification. |
| 6216 | * |
| 6217 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 6218 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 6219 | * @return This object for method chaining. |
| 6220 | * |
| 6221 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 6222 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 6223 | */ |
| 6224 | public Builder setReplyAction( |
| 6225 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 6226 | mRemoteInput = remoteInput; |
| 6227 | mReplyPendingIntent = pendingIntent; |
| 6228 | |
| 6229 | return this; |
| 6230 | } |
| 6231 | |
| 6232 | /** |
| 6233 | * Sets the pending intent that will be sent once the messages in this notification |
| 6234 | * are read. |
| 6235 | * |
| 6236 | * @param pendingIntent The pending intent to use. |
| 6237 | * @return This object for method chaining. |
| 6238 | */ |
| 6239 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 6240 | mReadPendingIntent = pendingIntent; |
| 6241 | return this; |
| 6242 | } |
| 6243 | |
| 6244 | /** |
| 6245 | * Sets the timestamp of the most recent message in an unread conversation. |
| 6246 | * |
| 6247 | * If a messaging notification has been posted by your application and has not |
| 6248 | * yet been cancelled, posting a later notification with the same id and tag |
| 6249 | * but without a newer timestamp may result in Android Auto not displaying a |
| 6250 | * heads up notification for the later notification. |
| 6251 | * |
| 6252 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 6253 | * @return This object for method chaining. |
| 6254 | */ |
| 6255 | public Builder setLatestTimestamp(long timestamp) { |
| 6256 | mLatestTimestamp = timestamp; |
| 6257 | return this; |
| 6258 | } |
| 6259 | |
| 6260 | /** |
| 6261 | * Builds a new unread conversation object. |
| 6262 | * |
| 6263 | * @return The new unread conversation object. |
| 6264 | */ |
| 6265 | public UnreadConversation build() { |
| 6266 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 6267 | String[] participants = { mParticipant }; |
| 6268 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 6269 | mReadPendingIntent, participants, mLatestTimestamp); |
| 6270 | } |
| 6271 | } |
| 6272 | } |
| 6273 | |
| 6274 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6275 | * Get an array of Notification objects from a parcelable array bundle field. |
| 6276 | * Update the bundle to have a typed array so fetches in the future don't need |
| 6277 | * to do an array copy. |
| 6278 | */ |
| 6279 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 6280 | Parcelable[] array = bundle.getParcelableArray(key); |
| 6281 | if (array instanceof Notification[] || array == null) { |
| 6282 | return (Notification[]) array; |
| 6283 | } |
| 6284 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 6285 | Notification[].class); |
| 6286 | bundle.putParcelableArray(key, typedArray); |
| 6287 | return typedArray; |
| 6288 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6289 | |
| 6290 | private static class BuilderRemoteViews extends RemoteViews { |
| 6291 | public BuilderRemoteViews(Parcel parcel) { |
| 6292 | super(parcel); |
| 6293 | } |
| 6294 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 6295 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 6296 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6297 | } |
| 6298 | |
| 6299 | @Override |
| 6300 | public BuilderRemoteViews clone() { |
| 6301 | Parcel p = Parcel.obtain(); |
| 6302 | writeToParcel(p, 0); |
| 6303 | p.setDataPosition(0); |
| 6304 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 6305 | p.recycle(); |
| 6306 | return brv; |
| 6307 | } |
| 6308 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6309 | } |