The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 20 | import android.annotation.DrawableRes; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 21 | import android.annotation.IntDef; |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 22 | import android.annotation.SdkConstant; |
| 23 | import android.annotation.SdkConstant.SdkConstantType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 26 | import android.content.pm.ApplicationInfo; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 27 | import android.content.pm.PackageManager.NameNotFoundException; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 28 | import android.content.res.ColorStateList; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 29 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 30 | import android.graphics.Canvas; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 31 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 32 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 33 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 34 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 35 | import android.media.AudioManager; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 36 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 38 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 39 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 40 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.os.Parcel; |
| 42 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 43 | import android.os.SystemClock; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 44 | import android.os.UserHandle; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 45 | import android.text.SpannableStringBuilder; |
| 46 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 48 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 49 | import android.text.style.CharacterStyle; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 50 | import android.text.style.RelativeSizeSpan; |
| 51 | import android.text.style.TextAppearanceSpan; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 52 | import android.util.Log; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 53 | import android.util.SparseArray; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 54 | import android.util.TypedValue; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 55 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 56 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 57 | import android.view.View; |
Adrian Roos | 9b123cf | 2016-02-04 14:55:57 -0800 | [diff] [blame] | 58 | import android.view.ViewGroup; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 59 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.widget.RemoteViews; |
| 61 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 62 | import com.android.internal.R; |
Griff Hazen | c091ba8 | 2014-05-16 10:13:26 -0700 | [diff] [blame] | 63 | import com.android.internal.util.NotificationColorUtil; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 64 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 65 | import java.lang.annotation.Retention; |
| 66 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 67 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 68 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 69 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 70 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 71 | import java.util.List; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 72 | import java.util.Set; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 73 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | /** |
| 75 | * A class that represents how a persistent notification is to be presented to |
| 76 | * the user using the {@link android.app.NotificationManager}. |
| 77 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 78 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 79 | * easier to construct Notifications.</p> |
| 80 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 81 | * <div class="special reference"> |
| 82 | * <h3>Developer Guides</h3> |
| 83 | * <p>For a guide to creating notifications, read the |
| 84 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 85 | * developer guide.</p> |
| 86 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | */ |
| 88 | public class Notification implements Parcelable |
| 89 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 90 | private static final String TAG = "Notification"; |
| 91 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 93 | * An activity that provides a user interface for adjusting notification preferences for its |
| 94 | * containing application. Optional but recommended for apps that post |
| 95 | * {@link android.app.Notification Notifications}. |
| 96 | */ |
| 97 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 98 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 99 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 100 | |
| 101 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | * Use all default values (where applicable). |
| 103 | */ |
| 104 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | /** |
| 107 | * Use the default notification sound. This will ignore any given |
| 108 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 109 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 110 | * <p> |
| 111 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 112 | * </p> |
| 113 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 115 | */ |
| 116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | public static final int DEFAULT_SOUND = 1; |
| 118 | |
| 119 | /** |
| 120 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 121 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 122 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 123 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 124 | * <p> |
| 125 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 126 | * </p> |
| 127 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 129 | */ |
| 130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | /** |
| 134 | * Use the default notification lights. This will ignore the |
| 135 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 136 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 137 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 139 | */ |
| 140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 144 | * Maximum length of CharSequences accepted by Builder and friends. |
| 145 | * |
| 146 | * <p> |
| 147 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 148 | */ |
| 149 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 150 | |
| 151 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 152 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 153 | */ |
| 154 | private static final int MAX_REPLY_HISTORY = 5; |
| 155 | |
| 156 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 157 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 158 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 159 | * Default value: {@link System#currentTimeMillis() Now}. |
| 160 | * |
| 161 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 162 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 163 | * yet to occur but about which the user is being informed). Indefinite events should be |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 164 | * timestamped according to when the activity began. |
| 165 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 166 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 167 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 168 | * <ul> |
| 169 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 170 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 171 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 172 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 173 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 174 | * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 175 | * </ul> |
| 176 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | */ |
| 178 | public long when; |
| 179 | |
| 180 | /** |
| 181 | * 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] | 182 | * |
| 183 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 185 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 186 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | public int icon; |
| 188 | |
| 189 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 190 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 191 | * leave it at its default value of 0. |
| 192 | * |
| 193 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 194 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 195 | */ |
| 196 | public int iconLevel; |
| 197 | |
| 198 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 199 | * The number of events that this notification represents. For example, in a new mail |
| 200 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 201 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 202 | * The system may or may not use this field to modify the appearance of the notification. For |
| 203 | * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was |
| 204 | * superimposed over the icon in the status bar. Starting with |
| 205 | * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by |
| 206 | * {@link Notification.Builder} has displayed the number in the expanded notification view. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 207 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 208 | * If the number is 0 or negative, it is never shown. |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame^] | 209 | * |
| 210 | * @deprecated this number is not shown anymore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | */ |
| 212 | public int number; |
| 213 | |
| 214 | /** |
| 215 | * The intent to execute when the expanded status entry is clicked. If |
| 216 | * this is an activity, it must include the |
| 217 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 218 | * that you take care of task management as described in the |
| 219 | * <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] | 220 | * Stack</a> document. In particular, make sure to read the notification section |
| 221 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 222 | * Notifications</a> for the correct ways to launch an application from a |
| 223 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | */ |
| 225 | public PendingIntent contentIntent; |
| 226 | |
| 227 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 228 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 229 | * the "Clear All" button or by swiping it away individually. |
| 230 | * |
| 231 | * This probably shouldn't be launching an activity since several of those will be sent |
| 232 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | */ |
| 234 | public PendingIntent deleteIntent; |
| 235 | |
| 236 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 237 | * 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] | 238 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 239 | * <p> |
| 240 | * The system UI may choose to display a heads-up notification, instead of |
| 241 | * launching this intent, while the user is using the device. |
| 242 | * </p> |
| 243 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 244 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 245 | */ |
| 246 | public PendingIntent fullScreenIntent; |
| 247 | |
| 248 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 249 | * Text that summarizes this notification for accessibility services. |
| 250 | * |
| 251 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 252 | * accessibility services (where it serves as an audible announcement of the notification's |
| 253 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 254 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 255 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | */ |
| 257 | public CharSequence tickerText; |
| 258 | |
| 259 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 260 | * Formerly, a view showing the {@link #tickerText}. |
| 261 | * |
| 262 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 263 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 264 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 265 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 266 | |
| 267 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 268 | * The view that will represent this notification in the notification list (which is pulled |
| 269 | * down from the status bar). |
| 270 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 271 | * As of N, this field may be null. The notification view is determined by the inputs |
| 272 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 273 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 275 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | public RemoteViews contentView; |
| 277 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 278 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 279 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 280 | * opportunity to show more detail. The system UI may choose to show this |
| 281 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 282 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 283 | * 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] | 284 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 285 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 286 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 287 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 288 | public RemoteViews bigContentView; |
| 289 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 290 | |
| 291 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 292 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 293 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 294 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 295 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 296 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 297 | * 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] | 298 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 299 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 300 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 301 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 302 | public RemoteViews headsUpContentView; |
| 303 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 304 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 305 | * A large bitmap to be shown in the notification content area. |
| 306 | * |
| 307 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 309 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 310 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | |
| 312 | /** |
| 313 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 314 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 316 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 317 | * </p> |
| 318 | * |
| 319 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 320 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | * </p> |
| 322 | */ |
| 323 | public Uri sound; |
| 324 | |
| 325 | /** |
| 326 | * Use this constant as the value for audioStreamType to request that |
| 327 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 328 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 329 | * |
| 330 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 332 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | public static final int STREAM_DEFAULT = -1; |
| 334 | |
| 335 | /** |
| 336 | * The audio stream type to use when playing the sound. |
| 337 | * Should be one of the STREAM_ constants from |
| 338 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 339 | * |
| 340 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 342 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | public int audioStreamType = STREAM_DEFAULT; |
| 344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 346 | * The default value of {@link #audioAttributes}. |
| 347 | */ |
| 348 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 349 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 350 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 351 | .build(); |
| 352 | |
| 353 | /** |
| 354 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
| 355 | */ |
| 356 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 357 | |
| 358 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 359 | * The pattern with which to vibrate. |
| 360 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | * <p> |
| 362 | * To vibrate the default pattern, see {@link #defaults}. |
| 363 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 364 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 365 | * <p> |
| 366 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 367 | * </p> |
| 368 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | * @see android.os.Vibrator#vibrate(long[],int) |
| 370 | */ |
| 371 | public long[] vibrate; |
| 372 | |
| 373 | /** |
| 374 | * The color of the led. The hardware will do its best approximation. |
| 375 | * |
| 376 | * @see #FLAG_SHOW_LIGHTS |
| 377 | * @see #flags |
| 378 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 379 | @ColorInt |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | public int ledARGB; |
| 381 | |
| 382 | /** |
| 383 | * The number of milliseconds for the LED to be on while it's flashing. |
| 384 | * The hardware will do its best approximation. |
| 385 | * |
| 386 | * @see #FLAG_SHOW_LIGHTS |
| 387 | * @see #flags |
| 388 | */ |
| 389 | public int ledOnMS; |
| 390 | |
| 391 | /** |
| 392 | * The number of milliseconds for the LED to be off while it's flashing. |
| 393 | * The hardware will do its best approximation. |
| 394 | * |
| 395 | * @see #FLAG_SHOW_LIGHTS |
| 396 | * @see #flags |
| 397 | */ |
| 398 | public int ledOffMS; |
| 399 | |
| 400 | /** |
| 401 | * Specifies which values should be taken from the defaults. |
| 402 | * <p> |
| 403 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 404 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 405 | * values, use {@link #DEFAULT_ALL}. |
| 406 | * </p> |
| 407 | */ |
| 408 | public int defaults; |
| 409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | /** |
| 411 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 412 | * set if you want the LED on for this notification. |
| 413 | * <ul> |
| 414 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 415 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 416 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 417 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 418 | * be on and off to ledOnMS and ledOffMS.</li> |
| 419 | * </ul> |
| 420 | * <p> |
| 421 | * Since hardware varies, you are not guaranteed that any of the values |
| 422 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 423 | * because they will be set to values that work on any given hardware. |
| 424 | * <p> |
| 425 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 426 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | */ |
| 428 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 429 | |
| 430 | /** |
| 431 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 432 | * set if this notification is in reference to something that is ongoing, |
| 433 | * like a phone call. It should not be set if this notification is in |
| 434 | * reference to something that happened at a particular point in time, |
| 435 | * like a missed phone call. |
| 436 | */ |
| 437 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 438 | |
| 439 | /** |
| 440 | * 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] | 441 | * the audio will be repeated until the notification is |
| 442 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | */ |
| 444 | public static final int FLAG_INSISTENT = 0x00000004; |
| 445 | |
| 446 | /** |
| 447 | * 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] | 448 | * set if you would only like the sound, vibrate and ticker to be played |
| 449 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | */ |
| 451 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 452 | |
| 453 | /** |
| 454 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 455 | * 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] | 456 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | */ |
| 458 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 459 | |
| 460 | /** |
| 461 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 462 | * set if the notification should not be canceled when the user clicks |
| 463 | * the Clear all button. |
| 464 | */ |
| 465 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 466 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 467 | /** |
| 468 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 469 | * set if this notification represents a currently running service. This |
| 470 | * will normally be set for you by {@link Service#startForeground}. |
| 471 | */ |
| 472 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 473 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 474 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 475 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 476 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 477 | * @deprecated Use {@link #priority} with a positive value. |
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 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 480 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 481 | /** |
| 482 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 483 | * set if this notification is relevant to the current device only |
| 484 | * and it is not recommended that it bridge to other devices. |
| 485 | */ |
| 486 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 487 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 488 | /** |
| 489 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 490 | * set if this notification is the group summary for a group of notifications. |
| 491 | * Grouped notifications may display in a cluster or stack on devices which |
| 492 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 493 | */ |
| 494 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | public int flags; |
| 497 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 498 | /** @hide */ |
| 499 | @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX}) |
| 500 | @Retention(RetentionPolicy.SOURCE) |
| 501 | public @interface Priority {} |
| 502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 504 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 505 | * notifications, use this value for all notifications. |
| 506 | */ |
| 507 | public static final int PRIORITY_DEFAULT = 0; |
| 508 | |
| 509 | /** |
| 510 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 511 | * items smaller, or at a different position in the list, compared with your app's |
| 512 | * {@link #PRIORITY_DEFAULT} items. |
| 513 | */ |
| 514 | public static final int PRIORITY_LOW = -1; |
| 515 | |
| 516 | /** |
| 517 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 518 | * circumstances, such as detailed notification logs. |
| 519 | */ |
| 520 | public static final int PRIORITY_MIN = -2; |
| 521 | |
| 522 | /** |
| 523 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 524 | * show these items larger, or at a different position in notification lists, compared with |
| 525 | * your app's {@link #PRIORITY_DEFAULT} items. |
| 526 | */ |
| 527 | public static final int PRIORITY_HIGH = 1; |
| 528 | |
| 529 | /** |
| 530 | * Highest {@link #priority}, for your application's most important items that require the |
| 531 | * user's prompt attention or input. |
| 532 | */ |
| 533 | public static final int PRIORITY_MAX = 2; |
| 534 | |
| 535 | /** |
| 536 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 537 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 538 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 539 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 540 | * 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] | 541 | * system will make a determination about how to interpret this priority when presenting |
| 542 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 543 | * |
| 544 | * <p> |
| 545 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 546 | * as a heads-up notification. |
| 547 | * </p> |
| 548 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 549 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 550 | @Priority |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 551 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 552 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 553 | /** |
| 554 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 555 | * to be applied by the standard Style templates when presenting this notification. |
| 556 | * |
| 557 | * The current template design constructs a colorful header image by overlaying the |
| 558 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 559 | * ignored. |
| 560 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 561 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 562 | public int color = COLOR_DEFAULT; |
| 563 | |
| 564 | /** |
| 565 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 566 | * any special color but instead use default colors when presenting this notification. |
| 567 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 568 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 569 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 570 | |
| 571 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 572 | * Special value of {@link #color} used as a place holder for an invalid color. |
| 573 | */ |
| 574 | @ColorInt |
| 575 | private static final int COLOR_INVALID = 1; |
| 576 | |
| 577 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 578 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 579 | * the notification's presence and contents in untrusted situations (namely, on the secure |
| 580 | * lockscreen). |
| 581 | * |
| 582 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 583 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 584 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 585 | * the appropriate user. |
| 586 | * |
| 587 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 588 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 589 | * To modify the public version of this notification—for example, to redact some portions—see |
| 590 | * {@link Builder#setPublicVersion(Notification)}. |
| 591 | * |
| 592 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 593 | * and ticker until the user has bypassed the lockscreen. |
| 594 | */ |
| 595 | public int visibility; |
| 596 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 597 | /** |
| 598 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 599 | * |
| 600 | * {@see #visibility} |
| 601 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 602 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 603 | |
| 604 | /** |
| 605 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 606 | * private information on secure lockscreens. |
| 607 | * |
| 608 | * {@see #visibility} |
| 609 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 610 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 611 | |
| 612 | /** |
| 613 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 614 | * |
| 615 | * {@see #visibility} |
| 616 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 617 | public static final int VISIBILITY_SECRET = -1; |
| 618 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 619 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 620 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 621 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 622 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 623 | |
| 624 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 625 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 626 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 627 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 628 | |
| 629 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 630 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 631 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 632 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 633 | |
| 634 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 635 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 636 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 637 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 638 | |
| 639 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 640 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 641 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 642 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 643 | |
| 644 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 645 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 646 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 647 | public static final String CATEGORY_ALARM = "alarm"; |
| 648 | |
| 649 | /** |
| 650 | * Notification category: progress of a long-running background operation. |
| 651 | */ |
| 652 | public static final String CATEGORY_PROGRESS = "progress"; |
| 653 | |
| 654 | /** |
| 655 | * Notification category: social network or sharing update. |
| 656 | */ |
| 657 | public static final String CATEGORY_SOCIAL = "social"; |
| 658 | |
| 659 | /** |
| 660 | * Notification category: error in background operation or authentication status. |
| 661 | */ |
| 662 | public static final String CATEGORY_ERROR = "err"; |
| 663 | |
| 664 | /** |
| 665 | * Notification category: media transport control for playback. |
| 666 | */ |
| 667 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 668 | |
| 669 | /** |
| 670 | * Notification category: system or device status update. Reserved for system use. |
| 671 | */ |
| 672 | public static final String CATEGORY_SYSTEM = "sys"; |
| 673 | |
| 674 | /** |
| 675 | * Notification category: indication of running background service. |
| 676 | */ |
| 677 | public static final String CATEGORY_SERVICE = "service"; |
| 678 | |
| 679 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 680 | * Notification category: a specific, timely recommendation for a single thing. |
| 681 | * For example, a news app might want to recommend a news story it believes the user will |
| 682 | * want to read next. |
| 683 | */ |
| 684 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 685 | |
| 686 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 687 | * Notification category: ongoing information about device or contextual status. |
| 688 | */ |
| 689 | public static final String CATEGORY_STATUS = "status"; |
| 690 | |
| 691 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 692 | * Notification category: user-scheduled reminder. |
| 693 | */ |
| 694 | public static final String CATEGORY_REMINDER = "reminder"; |
| 695 | |
| 696 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 697 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 698 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 699 | */ |
| 700 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 701 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 702 | private String mGroupKey; |
| 703 | |
| 704 | /** |
| 705 | * Get the key used to group this notification into a cluster or stack |
| 706 | * with other notifications on devices which support such rendering. |
| 707 | */ |
| 708 | public String getGroup() { |
| 709 | return mGroupKey; |
| 710 | } |
| 711 | |
| 712 | private String mSortKey; |
| 713 | |
| 714 | /** |
| 715 | * Get a sort key that orders this notification among other notifications from the |
| 716 | * same package. This can be useful if an external sort was already applied and an app |
| 717 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 718 | * value, although providing different priorities in addition to providing sort key may |
| 719 | * cause this value to be ignored. |
| 720 | * |
| 721 | * <p>This sort key can also be used to order members of a notification group. See |
| 722 | * {@link Builder#setGroup}. |
| 723 | * |
| 724 | * @see String#compareTo(String) |
| 725 | */ |
| 726 | public String getSortKey() { |
| 727 | return mSortKey; |
| 728 | } |
| 729 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 730 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 731 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 732 | * <p> |
| 733 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 734 | * APIs, and are intended to be used by |
| 735 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 736 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 737 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 738 | public Bundle extras = new Bundle(); |
| 739 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 740 | /** |
| 741 | * {@link #extras} key: this is the title of the notification, |
| 742 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 743 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 744 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 745 | |
| 746 | /** |
| 747 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 748 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 749 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 750 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 751 | |
| 752 | /** |
| 753 | * {@link #extras} key: this is the main text payload, as supplied to |
| 754 | * {@link Builder#setContentText(CharSequence)}. |
| 755 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 756 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 757 | |
| 758 | /** |
| 759 | * {@link #extras} key: this is a third line of text, as supplied to |
| 760 | * {@link Builder#setSubText(CharSequence)}. |
| 761 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 762 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 763 | |
| 764 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 765 | * {@link #extras} key: this is the remote input history, as supplied to |
| 766 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
| 767 | */ |
| 768 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 769 | |
| 770 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 771 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 772 | * {@link Builder#setContentInfo(CharSequence)}. |
| 773 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 774 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 775 | |
| 776 | /** |
| 777 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 778 | * alongside expanded notifications, as supplied to (e.g.) |
| 779 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 780 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 781 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 782 | |
| 783 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 784 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 785 | * {@link BigTextStyle} notification, as supplied to |
| 786 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 787 | */ |
| 788 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 789 | |
| 790 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 791 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 792 | * supplied to {@link Builder#setSmallIcon(int)}. |
| 793 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 794 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 795 | |
| 796 | /** |
| 797 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 798 | * notification payload, as |
| 799 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
| 800 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 801 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 802 | |
| 803 | /** |
| 804 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 805 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 806 | * shown in its expanded form, as supplied to |
| 807 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 808 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 809 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 810 | |
| 811 | /** |
| 812 | * {@link #extras} key: this is the progress value supplied to |
| 813 | * {@link Builder#setProgress(int, int, boolean)}. |
| 814 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 815 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 816 | |
| 817 | /** |
| 818 | * {@link #extras} key: this is the maximum value supplied to |
| 819 | * {@link Builder#setProgress(int, int, boolean)}. |
| 820 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 821 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 822 | |
| 823 | /** |
| 824 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 825 | * {@link Builder#setProgress(int, int, boolean)}. |
| 826 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 827 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 828 | |
| 829 | /** |
| 830 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 831 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 832 | * {@link Builder#setUsesChronometer(boolean)}. |
| 833 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 834 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 835 | |
| 836 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 837 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 838 | * instead of counting up. Is only relevant if key {@link #EXTRA_SHOW_CHRONOMETER} is present. |
| 839 | */ |
| 840 | public static final String EXTRA_CHRONOMETER_COUNTS_DOWN = "android.chronometerCountsDown"; |
| 841 | |
| 842 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 843 | * {@link #extras} key: whether {@link #when} should be shown, |
| 844 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 845 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 846 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 847 | |
| 848 | /** |
| 849 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 850 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 851 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 852 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 853 | |
| 854 | /** |
| 855 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 856 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 857 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 858 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 859 | |
| 860 | /** |
| 861 | * {@link #extras} key: A string representing the name of the specific |
| 862 | * {@link android.app.Notification.Style} used to create this notification. |
| 863 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 864 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 865 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 866 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 867 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 868 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 869 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 870 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 871 | |
| 872 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 873 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 874 | * Only available to notifications coming from the android package. |
| 875 | * @hide |
| 876 | */ |
| 877 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 878 | |
| 879 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 880 | * {@link #extras} key: A |
| 881 | * {@link android.content.ContentUris content URI} pointing to an image that can be displayed |
| 882 | * in the background when the notification is selected. The URI must point to an image stream |
| 883 | * suitable for passing into |
| 884 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
| 885 | * BitmapFactory.decodeStream}; all other content types will be ignored. The content provider |
| 886 | * URI used for this purpose must require no permissions to read the image data. |
| 887 | */ |
| 888 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 889 | |
| 890 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 891 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 892 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 893 | * {@link android.app.Notification.MediaStyle} notification. |
| 894 | */ |
| 895 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 896 | |
| 897 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 898 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 899 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 900 | */ |
| 901 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 902 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 903 | /** |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 904 | * {@link #extras} key: the user that built the notification. |
| 905 | * |
| 906 | * @hide |
| 907 | */ |
| 908 | public static final String EXTRA_ORIGINATING_USERID = "android.originatingUserId"; |
| 909 | |
| 910 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 911 | * @hide |
| 912 | */ |
| 913 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 914 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 915 | /** |
| 916 | * @hide |
| 917 | */ |
| 918 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 919 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 920 | private Icon mSmallIcon; |
| 921 | private Icon mLargeIcon; |
| 922 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 923 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 924 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 925 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 926 | * selected by the user. |
| 927 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 928 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 929 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 930 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 931 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 932 | public static class Action implements Parcelable { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 933 | private final Bundle mExtras; |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 934 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 935 | private final RemoteInput[] mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 936 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 937 | /** |
| 938 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 939 | * |
| 940 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 941 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 942 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 943 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 944 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 945 | /** |
| 946 | * Title of the action. |
| 947 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 948 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 949 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 950 | /** |
| 951 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 952 | * may be rendered in a disabled presentation by the system UI. |
| 953 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 954 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 955 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 956 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 957 | if (in.readInt() != 0) { |
| 958 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 959 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 960 | icon = mIcon.getResId(); |
| 961 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 962 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 963 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 964 | if (in.readInt() == 1) { |
| 965 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 966 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 967 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 968 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 969 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 970 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 971 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 972 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 973 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 974 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 975 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 976 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 979 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 980 | RemoteInput[] remoteInputs) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 981 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 982 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 983 | this.icon = icon.getResId(); |
| 984 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 985 | this.title = title; |
| 986 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 987 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 988 | this.mRemoteInputs = remoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 992 | * Return an icon representing the action. |
| 993 | */ |
| 994 | public Icon getIcon() { |
| 995 | if (mIcon == null && icon != 0) { |
| 996 | // you snuck an icon in here without using the builder; let's try to keep it |
| 997 | mIcon = Icon.createWithResource("", icon); |
| 998 | } |
| 999 | return mIcon; |
| 1000 | } |
| 1001 | |
| 1002 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1003 | * Get additional metadata carried around with this Action. |
| 1004 | */ |
| 1005 | public Bundle getExtras() { |
| 1006 | return mExtras; |
| 1007 | } |
| 1008 | |
| 1009 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1010 | * Get the list of inputs to be collected from the user when this action is sent. |
| 1011 | * May return null if no remote inputs were added. |
| 1012 | */ |
| 1013 | public RemoteInput[] getRemoteInputs() { |
| 1014 | return mRemoteInputs; |
| 1015 | } |
| 1016 | |
| 1017 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1018 | * Builder class for {@link Action} objects. |
| 1019 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1020 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1021 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1022 | private final CharSequence mTitle; |
| 1023 | private final PendingIntent mIntent; |
| 1024 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1025 | private ArrayList<RemoteInput> mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1026 | |
| 1027 | /** |
| 1028 | * Construct a new builder for {@link Action} object. |
| 1029 | * @param icon icon to show for this action |
| 1030 | * @param title the title of the action |
| 1031 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1032 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1033 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1034 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1035 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null); |
| 1036 | } |
| 1037 | |
| 1038 | /** |
| 1039 | * Construct a new builder for {@link Action} object. |
| 1040 | * @param icon icon to show for this action |
| 1041 | * @param title the title of the action |
| 1042 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1043 | */ |
| 1044 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1045 | this(icon, title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | /** |
| 1049 | * Construct a new builder for {@link Action} object using the fields from an |
| 1050 | * {@link Action}. |
| 1051 | * @param action the action to read fields from. |
| 1052 | */ |
| 1053 | public Builder(Action action) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1054 | this(action.getIcon(), action.title, action.actionIntent, new Bundle(action.mExtras), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1055 | action.getRemoteInputs()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1058 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1059 | RemoteInput[] remoteInputs) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1060 | mIcon = icon; |
| 1061 | mTitle = title; |
| 1062 | mIntent = intent; |
| 1063 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1064 | if (remoteInputs != null) { |
| 1065 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1066 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1067 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | /** |
| 1071 | * Merge additional metadata into this builder. |
| 1072 | * |
| 1073 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1074 | * |
| 1075 | * @see Notification.Action#extras |
| 1076 | */ |
| 1077 | public Builder addExtras(Bundle extras) { |
| 1078 | if (extras != null) { |
| 1079 | mExtras.putAll(extras); |
| 1080 | } |
| 1081 | return this; |
| 1082 | } |
| 1083 | |
| 1084 | /** |
| 1085 | * Get the metadata Bundle used by this Builder. |
| 1086 | * |
| 1087 | * <p>The returned Bundle is shared with this Builder. |
| 1088 | */ |
| 1089 | public Bundle getExtras() { |
| 1090 | return mExtras; |
| 1091 | } |
| 1092 | |
| 1093 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1094 | * Add an input to be collected from the user when this action is sent. |
| 1095 | * Response values can be retrieved from the fired intent by using the |
| 1096 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1097 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1098 | * @return this object for method chaining |
| 1099 | */ |
| 1100 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1101 | if (mRemoteInputs == null) { |
| 1102 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1103 | } |
| 1104 | mRemoteInputs.add(remoteInput); |
| 1105 | return this; |
| 1106 | } |
| 1107 | |
| 1108 | /** |
| 1109 | * Apply an extender to this action builder. Extenders may be used to add |
| 1110 | * metadata or change options on this builder. |
| 1111 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1112 | public Builder extend(Extender extender) { |
| 1113 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1114 | return this; |
| 1115 | } |
| 1116 | |
| 1117 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1118 | * Combine all of the options that have been set and return a new {@link Action} |
| 1119 | * object. |
| 1120 | * @return the built action |
| 1121 | */ |
| 1122 | public Action build() { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1123 | RemoteInput[] remoteInputs = mRemoteInputs != null |
| 1124 | ? mRemoteInputs.toArray(new RemoteInput[mRemoteInputs.size()]) : null; |
| 1125 | return new Action(mIcon, mTitle, mIntent, mExtras, remoteInputs); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1126 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1127 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1128 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1129 | @Override |
| 1130 | public Action clone() { |
| 1131 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1132 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1133 | title, |
| 1134 | actionIntent, // safe to alias |
| 1135 | new Bundle(mExtras), |
| 1136 | getRemoteInputs()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1137 | } |
| 1138 | @Override |
| 1139 | public int describeContents() { |
| 1140 | return 0; |
| 1141 | } |
| 1142 | @Override |
| 1143 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1144 | final Icon ic = getIcon(); |
| 1145 | if (ic != null) { |
| 1146 | out.writeInt(1); |
| 1147 | ic.writeToParcel(out, 0); |
| 1148 | } else { |
| 1149 | out.writeInt(0); |
| 1150 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1151 | TextUtils.writeToParcel(title, out, flags); |
| 1152 | if (actionIntent != null) { |
| 1153 | out.writeInt(1); |
| 1154 | actionIntent.writeToParcel(out, flags); |
| 1155 | } else { |
| 1156 | out.writeInt(0); |
| 1157 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1158 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1159 | out.writeTypedArray(mRemoteInputs, flags); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1160 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1161 | public static final Parcelable.Creator<Action> CREATOR = |
| 1162 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1163 | public Action createFromParcel(Parcel in) { |
| 1164 | return new Action(in); |
| 1165 | } |
| 1166 | public Action[] newArray(int size) { |
| 1167 | return new Action[size]; |
| 1168 | } |
| 1169 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1170 | |
| 1171 | /** |
| 1172 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1173 | * metadata or change options on an action builder. |
| 1174 | */ |
| 1175 | public interface Extender { |
| 1176 | /** |
| 1177 | * Apply this extender to a notification action builder. |
| 1178 | * @param builder the builder to be modified. |
| 1179 | * @return the build object for chaining. |
| 1180 | */ |
| 1181 | public Builder extend(Builder builder); |
| 1182 | } |
| 1183 | |
| 1184 | /** |
| 1185 | * Wearable extender for notification actions. To add extensions to an action, |
| 1186 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1187 | * the {@code WearableExtender()} constructor and apply it to a |
| 1188 | * {@link android.app.Notification.Action.Builder} using |
| 1189 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1190 | * |
| 1191 | * <pre class="prettyprint"> |
| 1192 | * Notification.Action action = new Notification.Action.Builder( |
| 1193 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1194 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1195 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1196 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1197 | */ |
| 1198 | public static final class WearableExtender implements Extender { |
| 1199 | /** Notification action extra which contains wearable extensions */ |
| 1200 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1201 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1202 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1203 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1204 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1205 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1206 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1207 | |
| 1208 | // Flags bitwise-ored to mFlags |
| 1209 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
| 1210 | |
| 1211 | // Default value for flags integer |
| 1212 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1213 | |
| 1214 | private int mFlags = DEFAULT_FLAGS; |
| 1215 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1216 | private CharSequence mInProgressLabel; |
| 1217 | private CharSequence mConfirmLabel; |
| 1218 | private CharSequence mCancelLabel; |
| 1219 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1220 | /** |
| 1221 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1222 | * options. |
| 1223 | */ |
| 1224 | public WearableExtender() { |
| 1225 | } |
| 1226 | |
| 1227 | /** |
| 1228 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1229 | * wearable options present in an existing notification action. |
| 1230 | * @param action the notification action to inspect. |
| 1231 | */ |
| 1232 | public WearableExtender(Action action) { |
| 1233 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1234 | if (wearableBundle != null) { |
| 1235 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1236 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1237 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1238 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | /** |
| 1243 | * Apply wearable extensions to a notification action that is being built. This is |
| 1244 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1245 | * method of {@link android.app.Notification.Action.Builder}. |
| 1246 | */ |
| 1247 | @Override |
| 1248 | public Action.Builder extend(Action.Builder builder) { |
| 1249 | Bundle wearableBundle = new Bundle(); |
| 1250 | |
| 1251 | if (mFlags != DEFAULT_FLAGS) { |
| 1252 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1253 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1254 | if (mInProgressLabel != null) { |
| 1255 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1256 | } |
| 1257 | if (mConfirmLabel != null) { |
| 1258 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1259 | } |
| 1260 | if (mCancelLabel != null) { |
| 1261 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1262 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1263 | |
| 1264 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1265 | return builder; |
| 1266 | } |
| 1267 | |
| 1268 | @Override |
| 1269 | public WearableExtender clone() { |
| 1270 | WearableExtender that = new WearableExtender(); |
| 1271 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1272 | that.mInProgressLabel = this.mInProgressLabel; |
| 1273 | that.mConfirmLabel = this.mConfirmLabel; |
| 1274 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1275 | return that; |
| 1276 | } |
| 1277 | |
| 1278 | /** |
| 1279 | * Set whether this action is available when the wearable device is not connected to |
| 1280 | * a companion device. The user can still trigger this action when the wearable device is |
| 1281 | * offline, but a visual hint will indicate that the action may not be available. |
| 1282 | * Defaults to true. |
| 1283 | */ |
| 1284 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1285 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1286 | return this; |
| 1287 | } |
| 1288 | |
| 1289 | /** |
| 1290 | * Get whether this action is available when the wearable device is not connected to |
| 1291 | * a companion device. The user can still trigger this action when the wearable device is |
| 1292 | * offline, but a visual hint will indicate that the action may not be available. |
| 1293 | * Defaults to true. |
| 1294 | */ |
| 1295 | public boolean isAvailableOffline() { |
| 1296 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1297 | } |
| 1298 | |
| 1299 | private void setFlag(int mask, boolean value) { |
| 1300 | if (value) { |
| 1301 | mFlags |= mask; |
| 1302 | } else { |
| 1303 | mFlags &= ~mask; |
| 1304 | } |
| 1305 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1306 | |
| 1307 | /** |
| 1308 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1309 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1310 | * |
| 1311 | * @param label the label to display while the action is being prepared to execute |
| 1312 | * @return this object for method chaining |
| 1313 | */ |
| 1314 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1315 | mInProgressLabel = label; |
| 1316 | return this; |
| 1317 | } |
| 1318 | |
| 1319 | /** |
| 1320 | * Get the label to display while the wearable is preparing to automatically execute |
| 1321 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1322 | * |
| 1323 | * @return the label to display while the action is being prepared to execute |
| 1324 | */ |
| 1325 | public CharSequence getInProgressLabel() { |
| 1326 | return mInProgressLabel; |
| 1327 | } |
| 1328 | |
| 1329 | /** |
| 1330 | * Set a label to display to confirm that the action should be executed. |
| 1331 | * This is usually an imperative verb like "Send". |
| 1332 | * |
| 1333 | * @param label the label to confirm the action should be executed |
| 1334 | * @return this object for method chaining |
| 1335 | */ |
| 1336 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1337 | mConfirmLabel = label; |
| 1338 | return this; |
| 1339 | } |
| 1340 | |
| 1341 | /** |
| 1342 | * Get the label to display to confirm that the action should be executed. |
| 1343 | * This is usually an imperative verb like "Send". |
| 1344 | * |
| 1345 | * @return the label to confirm the action should be executed |
| 1346 | */ |
| 1347 | public CharSequence getConfirmLabel() { |
| 1348 | return mConfirmLabel; |
| 1349 | } |
| 1350 | |
| 1351 | /** |
| 1352 | * Set a label to display to cancel the action. |
| 1353 | * This is usually an imperative verb, like "Cancel". |
| 1354 | * |
| 1355 | * @param label the label to display to cancel the action |
| 1356 | * @return this object for method chaining |
| 1357 | */ |
| 1358 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1359 | mCancelLabel = label; |
| 1360 | return this; |
| 1361 | } |
| 1362 | |
| 1363 | /** |
| 1364 | * Get the label to display to cancel the action. |
| 1365 | * This is usually an imperative verb like "Cancel". |
| 1366 | * |
| 1367 | * @return the label to display to cancel the action |
| 1368 | */ |
| 1369 | public CharSequence getCancelLabel() { |
| 1370 | return mCancelLabel; |
| 1371 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1372 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1373 | } |
| 1374 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1375 | /** |
| 1376 | * Array of all {@link Action} structures attached to this notification by |
| 1377 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 1378 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 1379 | * interface for invoking actions. |
| 1380 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1381 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1382 | |
| 1383 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1384 | * Replacement version of this notification whose content will be shown |
| 1385 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 1386 | * and {@link #VISIBILITY_PUBLIC}. |
| 1387 | */ |
| 1388 | public Notification publicVersion; |
| 1389 | |
| 1390 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1391 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1392 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1393 | */ |
| 1394 | public Notification() |
| 1395 | { |
| 1396 | this.when = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1397 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1401 | * @hide |
| 1402 | */ |
| 1403 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 1404 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 1405 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1406 | new Builder(context) |
| 1407 | .setWhen(when) |
| 1408 | .setSmallIcon(icon) |
| 1409 | .setTicker(tickerText) |
| 1410 | .setContentTitle(contentTitle) |
| 1411 | .setContentText(contentText) |
| 1412 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 1413 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | /** |
| 1417 | * Constructs a Notification object with the information needed to |
| 1418 | * have a status bar icon without the standard expanded view. |
| 1419 | * |
| 1420 | * @param icon The resource id of the icon to put in the status bar. |
| 1421 | * @param tickerText The text that flows by in the status bar when the notification first |
| 1422 | * activates. |
| 1423 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 1424 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1425 | * |
| 1426 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1428 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1429 | public Notification(int icon, CharSequence tickerText, long when) |
| 1430 | { |
| 1431 | this.icon = icon; |
| 1432 | this.tickerText = tickerText; |
| 1433 | this.when = when; |
| 1434 | } |
| 1435 | |
| 1436 | /** |
| 1437 | * Unflatten the notification from a parcel. |
| 1438 | */ |
| 1439 | public Notification(Parcel parcel) |
| 1440 | { |
| 1441 | int version = parcel.readInt(); |
| 1442 | |
| 1443 | when = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1444 | if (parcel.readInt() != 0) { |
| 1445 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1446 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1447 | icon = mSmallIcon.getResId(); |
| 1448 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1449 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1450 | number = parcel.readInt(); |
| 1451 | if (parcel.readInt() != 0) { |
| 1452 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1453 | } |
| 1454 | if (parcel.readInt() != 0) { |
| 1455 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1456 | } |
| 1457 | if (parcel.readInt() != 0) { |
| 1458 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1459 | } |
| 1460 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1461 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1462 | } |
| 1463 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1465 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1466 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1467 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1468 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | defaults = parcel.readInt(); |
| 1470 | flags = parcel.readInt(); |
| 1471 | if (parcel.readInt() != 0) { |
| 1472 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 1473 | } |
| 1474 | |
| 1475 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1476 | if (parcel.readInt() != 0) { |
| 1477 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 1478 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | vibrate = parcel.createLongArray(); |
| 1480 | ledARGB = parcel.readInt(); |
| 1481 | ledOnMS = parcel.readInt(); |
| 1482 | ledOffMS = parcel.readInt(); |
| 1483 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1484 | |
| 1485 | if (parcel.readInt() != 0) { |
| 1486 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1487 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1488 | |
| 1489 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1490 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1491 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1492 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1493 | mGroupKey = parcel.readString(); |
| 1494 | |
| 1495 | mSortKey = parcel.readString(); |
| 1496 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1497 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1498 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1499 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 1500 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1501 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1502 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1503 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1504 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1505 | if (parcel.readInt() != 0) { |
| 1506 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1507 | } |
| 1508 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1509 | visibility = parcel.readInt(); |
| 1510 | |
| 1511 | if (parcel.readInt() != 0) { |
| 1512 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 1513 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1514 | |
| 1515 | color = parcel.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | } |
| 1517 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1518 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1519 | public Notification clone() { |
| 1520 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1521 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1522 | return that; |
| 1523 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1524 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1525 | /** |
| 1526 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 1527 | * of this into that. |
| 1528 | * @hide |
| 1529 | */ |
| 1530 | public void cloneInto(Notification that, boolean heavy) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1531 | that.when = this.when; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1532 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1533 | that.number = this.number; |
| 1534 | |
| 1535 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 1536 | that.contentIntent = this.contentIntent; |
| 1537 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1538 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1539 | |
| 1540 | if (this.tickerText != null) { |
| 1541 | that.tickerText = this.tickerText.toString(); |
| 1542 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1543 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1544 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1545 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1546 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1547 | that.contentView = this.contentView.clone(); |
| 1548 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1549 | if (heavy && this.mLargeIcon != null) { |
| 1550 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1551 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 1552 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1553 | that.sound = this.sound; // android.net.Uri is immutable |
| 1554 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1555 | if (this.audioAttributes != null) { |
| 1556 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 1557 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1558 | |
| 1559 | final long[] vibrate = this.vibrate; |
| 1560 | if (vibrate != null) { |
| 1561 | final int N = vibrate.length; |
| 1562 | final long[] vib = that.vibrate = new long[N]; |
| 1563 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 1564 | } |
| 1565 | |
| 1566 | that.ledARGB = this.ledARGB; |
| 1567 | that.ledOnMS = this.ledOnMS; |
| 1568 | that.ledOffMS = this.ledOffMS; |
| 1569 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1570 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1571 | that.flags = this.flags; |
| 1572 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1573 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1574 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1575 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1576 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1577 | that.mGroupKey = this.mGroupKey; |
| 1578 | |
| 1579 | that.mSortKey = this.mSortKey; |
| 1580 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1581 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1582 | try { |
| 1583 | that.extras = new Bundle(this.extras); |
| 1584 | // will unparcel |
| 1585 | that.extras.size(); |
| 1586 | } catch (BadParcelableException e) { |
| 1587 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 1588 | that.extras = null; |
| 1589 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1590 | } |
| 1591 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1592 | if (this.actions != null) { |
| 1593 | that.actions = new Action[this.actions.length]; |
| 1594 | for(int i=0; i<this.actions.length; i++) { |
| 1595 | that.actions[i] = this.actions[i].clone(); |
| 1596 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1597 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1598 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1599 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1600 | that.bigContentView = this.bigContentView.clone(); |
| 1601 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1602 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1603 | if (heavy && this.headsUpContentView != null) { |
| 1604 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 1605 | } |
| 1606 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1607 | that.visibility = this.visibility; |
| 1608 | |
| 1609 | if (this.publicVersion != null) { |
| 1610 | that.publicVersion = new Notification(); |
| 1611 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 1612 | } |
| 1613 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1614 | that.color = this.color; |
| 1615 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1616 | if (!heavy) { |
| 1617 | that.lightenPayload(); // will clean out extras |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | /** |
| 1622 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 1623 | * listeners when the full contents are not necessary. |
| 1624 | * @hide |
| 1625 | */ |
| 1626 | public final void lightenPayload() { |
| 1627 | tickerView = null; |
| 1628 | contentView = null; |
| 1629 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1630 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1631 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 1632 | if (extras != null && !extras.isEmpty()) { |
| 1633 | final Set<String> keyset = extras.keySet(); |
| 1634 | final int N = keyset.size(); |
| 1635 | final String[] keys = keyset.toArray(new String[N]); |
| 1636 | for (int i=0; i<N; i++) { |
| 1637 | final String key = keys[i]; |
| 1638 | final Object obj = extras.get(key); |
| 1639 | if (obj != null && |
| 1640 | ( obj instanceof Parcelable |
| 1641 | || obj instanceof Parcelable[] |
| 1642 | || obj instanceof SparseArray |
| 1643 | || obj instanceof ArrayList)) { |
| 1644 | extras.remove(key); |
| 1645 | } |
| 1646 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1647 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1650 | /** |
| 1651 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 1652 | * means it had better not be some custom Parcelable implementation. |
| 1653 | * @hide |
| 1654 | */ |
| 1655 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 1656 | if (cs == null) return cs; |
| 1657 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 1658 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 1659 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1660 | if (cs instanceof Parcelable) { |
| 1661 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 1662 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 1663 | return cs.toString(); |
| 1664 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1665 | return removeTextSizeSpans(cs); |
| 1666 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1667 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1668 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 1669 | if (charSequence instanceof Spanned) { |
| 1670 | Spanned ss = (Spanned) charSequence; |
| 1671 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 1672 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 1673 | for (Object span : spans) { |
| 1674 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 1675 | if (resultSpan instanceof CharacterStyle) { |
| 1676 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 1677 | } |
| 1678 | if (resultSpan instanceof TextAppearanceSpan) { |
| 1679 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1680 | resultSpan = new TextAppearanceSpan( |
| 1681 | originalSpan.getFamily(), |
| 1682 | originalSpan.getTextStyle(), |
| 1683 | -1, |
| 1684 | originalSpan.getTextColor(), |
| 1685 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 1686 | } else if (resultSpan instanceof RelativeSizeSpan |
| 1687 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1688 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 1689 | } else { |
| 1690 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 1691 | } |
| 1692 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 1693 | ss.getSpanFlags(span)); |
| 1694 | } |
| 1695 | return builder; |
| 1696 | } |
| 1697 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1698 | } |
| 1699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1700 | public int describeContents() { |
| 1701 | return 0; |
| 1702 | } |
| 1703 | |
| 1704 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1705 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | */ |
| 1707 | public void writeToParcel(Parcel parcel, int flags) |
| 1708 | { |
| 1709 | parcel.writeInt(1); |
| 1710 | |
| 1711 | parcel.writeLong(when); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1712 | if (mSmallIcon == null && icon != 0) { |
| 1713 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1714 | mSmallIcon = Icon.createWithResource("", icon); |
| 1715 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1716 | if (mSmallIcon != null) { |
| 1717 | parcel.writeInt(1); |
| 1718 | mSmallIcon.writeToParcel(parcel, 0); |
| 1719 | } else { |
| 1720 | parcel.writeInt(0); |
| 1721 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1722 | parcel.writeInt(number); |
| 1723 | if (contentIntent != null) { |
| 1724 | parcel.writeInt(1); |
| 1725 | contentIntent.writeToParcel(parcel, 0); |
| 1726 | } else { |
| 1727 | parcel.writeInt(0); |
| 1728 | } |
| 1729 | if (deleteIntent != null) { |
| 1730 | parcel.writeInt(1); |
| 1731 | deleteIntent.writeToParcel(parcel, 0); |
| 1732 | } else { |
| 1733 | parcel.writeInt(0); |
| 1734 | } |
| 1735 | if (tickerText != null) { |
| 1736 | parcel.writeInt(1); |
| 1737 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 1738 | } else { |
| 1739 | parcel.writeInt(0); |
| 1740 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1741 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1742 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1743 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1744 | } else { |
| 1745 | parcel.writeInt(0); |
| 1746 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1747 | if (contentView != null) { |
| 1748 | parcel.writeInt(1); |
| 1749 | contentView.writeToParcel(parcel, 0); |
| 1750 | } else { |
| 1751 | parcel.writeInt(0); |
| 1752 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1753 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1754 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1755 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1756 | } else { |
| 1757 | parcel.writeInt(0); |
| 1758 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1759 | |
| 1760 | parcel.writeInt(defaults); |
| 1761 | parcel.writeInt(this.flags); |
| 1762 | |
| 1763 | if (sound != null) { |
| 1764 | parcel.writeInt(1); |
| 1765 | sound.writeToParcel(parcel, 0); |
| 1766 | } else { |
| 1767 | parcel.writeInt(0); |
| 1768 | } |
| 1769 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1770 | |
| 1771 | if (audioAttributes != null) { |
| 1772 | parcel.writeInt(1); |
| 1773 | audioAttributes.writeToParcel(parcel, 0); |
| 1774 | } else { |
| 1775 | parcel.writeInt(0); |
| 1776 | } |
| 1777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1778 | parcel.writeLongArray(vibrate); |
| 1779 | parcel.writeInt(ledARGB); |
| 1780 | parcel.writeInt(ledOnMS); |
| 1781 | parcel.writeInt(ledOffMS); |
| 1782 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1783 | |
| 1784 | if (fullScreenIntent != null) { |
| 1785 | parcel.writeInt(1); |
| 1786 | fullScreenIntent.writeToParcel(parcel, 0); |
| 1787 | } else { |
| 1788 | parcel.writeInt(0); |
| 1789 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1790 | |
| 1791 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1792 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1793 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1794 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1795 | parcel.writeString(mGroupKey); |
| 1796 | |
| 1797 | parcel.writeString(mSortKey); |
| 1798 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1799 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1800 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1801 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1802 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1803 | if (bigContentView != null) { |
| 1804 | parcel.writeInt(1); |
| 1805 | bigContentView.writeToParcel(parcel, 0); |
| 1806 | } else { |
| 1807 | parcel.writeInt(0); |
| 1808 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1809 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1810 | if (headsUpContentView != null) { |
| 1811 | parcel.writeInt(1); |
| 1812 | headsUpContentView.writeToParcel(parcel, 0); |
| 1813 | } else { |
| 1814 | parcel.writeInt(0); |
| 1815 | } |
| 1816 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1817 | parcel.writeInt(visibility); |
| 1818 | |
| 1819 | if (publicVersion != null) { |
| 1820 | parcel.writeInt(1); |
| 1821 | publicVersion.writeToParcel(parcel, 0); |
| 1822 | } else { |
| 1823 | parcel.writeInt(0); |
| 1824 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1825 | |
| 1826 | parcel.writeInt(color); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | /** |
| 1830 | * Parcelable.Creator that instantiates Notification objects |
| 1831 | */ |
| 1832 | public static final Parcelable.Creator<Notification> CREATOR |
| 1833 | = new Parcelable.Creator<Notification>() |
| 1834 | { |
| 1835 | public Notification createFromParcel(Parcel parcel) |
| 1836 | { |
| 1837 | return new Notification(parcel); |
| 1838 | } |
| 1839 | |
| 1840 | public Notification[] newArray(int size) |
| 1841 | { |
| 1842 | return new Notification[size]; |
| 1843 | } |
| 1844 | }; |
| 1845 | |
| 1846 | /** |
| 1847 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 1848 | * layout. |
| 1849 | * |
| 1850 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 1851 | * in the view.</p> |
| 1852 | * @param context The context for your application / activity. |
| 1853 | * @param contentTitle The title that goes in the expanded entry. |
| 1854 | * @param contentText The text that goes in the expanded entry. |
| 1855 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 1856 | * If this is an activity, it must include the |
| 1857 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 1858 | * that you take care of task management as described in the |
| 1859 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 1860 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1861 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1862 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 1863 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1864 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1865 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1866 | public void setLatestEventInfo(Context context, |
| 1867 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1868 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 1869 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 1870 | new Throwable()); |
| 1871 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1872 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1873 | // ensure that any information already set directly is preserved |
| 1874 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1875 | |
| 1876 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1878 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | } |
| 1880 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1881 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1883 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1884 | |
| 1885 | 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] | 1886 | } |
| 1887 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 1888 | /** |
| 1889 | * @hide |
| 1890 | */ |
| 1891 | public static void addFieldsFromContext(Context context, Notification notification) { |
| 1892 | if (notification.extras.getParcelable(EXTRA_BUILDER_APPLICATION_INFO) == null) { |
| 1893 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, |
| 1894 | context.getApplicationInfo()); |
| 1895 | } |
| 1896 | if (!notification.extras.containsKey(EXTRA_ORIGINATING_USERID)) { |
| 1897 | notification.extras.putInt(EXTRA_ORIGINATING_USERID, context.getUserId()); |
| 1898 | } |
| 1899 | } |
| 1900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1901 | @Override |
| 1902 | public String toString() { |
| 1903 | StringBuilder sb = new StringBuilder(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1904 | sb.append("Notification(pri="); |
| 1905 | sb.append(priority); |
| 1906 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 1907 | if (contentView != null) { |
| 1908 | sb.append(contentView.getPackage()); |
| 1909 | sb.append("/0x"); |
| 1910 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 1911 | } else { |
| 1912 | sb.append("null"); |
| 1913 | } |
| 1914 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1915 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 1916 | sb.append("default"); |
| 1917 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | int N = this.vibrate.length-1; |
| 1919 | sb.append("["); |
| 1920 | for (int i=0; i<N; i++) { |
| 1921 | sb.append(this.vibrate[i]); |
| 1922 | sb.append(','); |
| 1923 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 1924 | if (N != -1) { |
| 1925 | sb.append(this.vibrate[N]); |
| 1926 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1928 | } else { |
| 1929 | sb.append("null"); |
| 1930 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1931 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1932 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1933 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1934 | } else if (this.sound != null) { |
| 1935 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | } else { |
| 1937 | sb.append("null"); |
| 1938 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 1939 | if (this.tickerText != null) { |
| 1940 | sb.append(" tick"); |
| 1941 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1942 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1944 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1945 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1946 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1947 | if (this.category != null) { |
| 1948 | sb.append(" category="); |
| 1949 | sb.append(this.category); |
| 1950 | } |
| 1951 | if (this.mGroupKey != null) { |
| 1952 | sb.append(" groupKey="); |
| 1953 | sb.append(this.mGroupKey); |
| 1954 | } |
| 1955 | if (this.mSortKey != null) { |
| 1956 | sb.append(" sortKey="); |
| 1957 | sb.append(this.mSortKey); |
| 1958 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1959 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1960 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1961 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1962 | } |
| 1963 | sb.append(" vis="); |
| 1964 | sb.append(visibilityToString(this.visibility)); |
| 1965 | if (this.publicVersion != null) { |
| 1966 | sb.append(" publicVersion="); |
| 1967 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1968 | } |
| 1969 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1970 | return sb.toString(); |
| 1971 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1972 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1973 | /** |
| 1974 | * {@hide} |
| 1975 | */ |
| 1976 | public static String visibilityToString(int vis) { |
| 1977 | switch (vis) { |
| 1978 | case VISIBILITY_PRIVATE: |
| 1979 | return "PRIVATE"; |
| 1980 | case VISIBILITY_PUBLIC: |
| 1981 | return "PUBLIC"; |
| 1982 | case VISIBILITY_SECRET: |
| 1983 | return "SECRET"; |
| 1984 | default: |
| 1985 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 1986 | } |
| 1987 | } |
| 1988 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1989 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 1990 | * {@hide} |
| 1991 | */ |
| 1992 | public static String priorityToString(@Priority int pri) { |
| 1993 | switch (pri) { |
| 1994 | case PRIORITY_MIN: |
| 1995 | return "MIN"; |
| 1996 | case PRIORITY_LOW: |
| 1997 | return "LOW"; |
| 1998 | case PRIORITY_DEFAULT: |
| 1999 | return "DEFAULT"; |
| 2000 | case PRIORITY_HIGH: |
| 2001 | return "HIGH"; |
| 2002 | case PRIORITY_MAX: |
| 2003 | return "MAX"; |
| 2004 | default: |
| 2005 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2010 | * The small icon representing this notification in the status bar and content view. |
| 2011 | * |
| 2012 | * @return the small icon representing this notification. |
| 2013 | * |
| 2014 | * @see Builder#getSmallIcon() |
| 2015 | * @see Builder#setSmallIcon(Icon) |
| 2016 | */ |
| 2017 | public Icon getSmallIcon() { |
| 2018 | return mSmallIcon; |
| 2019 | } |
| 2020 | |
| 2021 | /** |
| 2022 | * Used when notifying to clean up legacy small icons. |
| 2023 | * @hide |
| 2024 | */ |
| 2025 | public void setSmallIcon(Icon icon) { |
| 2026 | mSmallIcon = icon; |
| 2027 | } |
| 2028 | |
| 2029 | /** |
| 2030 | * The large icon shown in this notification's content view. |
| 2031 | * @see Builder#getLargeIcon() |
| 2032 | * @see Builder#setLargeIcon(Icon) |
| 2033 | */ |
| 2034 | public Icon getLargeIcon() { |
| 2035 | return mLargeIcon; |
| 2036 | } |
| 2037 | |
| 2038 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2039 | * @hide |
| 2040 | */ |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 2041 | public boolean isGroupSummary() { |
| 2042 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 2043 | } |
| 2044 | |
| 2045 | /** |
| 2046 | * @hide |
| 2047 | */ |
| 2048 | public boolean isGroupChild() { |
| 2049 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 2050 | } |
| 2051 | |
| 2052 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2053 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2054 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2055 | * 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] | 2056 | * content views using the platform's notification layout template. If your app supports |
| 2057 | * versions of Android as old as API level 4, you can instead use |
| 2058 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 2059 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 2060 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2061 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2062 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2063 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2064 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2065 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2066 | * .setContentTitle("New mail from " + sender.toString()) |
| 2067 | * .setContentText(subject) |
| 2068 | * .setSmallIcon(R.drawable.new_mail) |
| 2069 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2070 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2071 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2072 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2073 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 2074 | /** |
| 2075 | * @hide |
| 2076 | */ |
| 2077 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 2078 | "android.rebuild.contentViewActionCount"; |
| 2079 | /** |
| 2080 | * @hide |
| 2081 | */ |
| 2082 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 2083 | = "android.rebuild.bigViewActionCount"; |
| 2084 | /** |
| 2085 | * @hide |
| 2086 | */ |
| 2087 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 2088 | = "android.rebuild.hudViewActionCount"; |
| 2089 | |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 2090 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2091 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2092 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2093 | private Notification mN; |
| 2094 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2095 | private Style mStyle; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2096 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
| 2097 | private ArrayList<String> mPersonList = new ArrayList<String>(); |
| 2098 | private NotificationColorUtil mColorUtil; |
| 2099 | private boolean mColorUtilInited = false; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2100 | |
| 2101 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2102 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 2103 | */ |
| 2104 | private int mCachedContrastColor = COLOR_INVALID; |
| 2105 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
| 2106 | |
| 2107 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2108 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2109 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2110 | |
| 2111 | * <table> |
| 2112 | * <tr><th align=right>priority</th> |
| 2113 | * <td>{@link #PRIORITY_DEFAULT}</td></tr> |
| 2114 | * <tr><th align=right>when</th> |
| 2115 | * <td>now ({@link System#currentTimeMillis()})</td></tr> |
| 2116 | * <tr><th align=right>audio stream</th> |
| 2117 | * <td>{@link #STREAM_DEFAULT}</td></tr> |
| 2118 | * </table> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2119 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2120 | |
| 2121 | * @param context |
| 2122 | * A {@link Context} that will be used by the Builder to construct the |
| 2123 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 2124 | * object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2125 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2126 | public Builder(Context context) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2127 | this(context, null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2128 | } |
| 2129 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2130 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2131 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2132 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2133 | public Builder(Context context, Notification toAdopt) { |
| 2134 | mContext = context; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2135 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2136 | if (toAdopt == null) { |
| 2137 | mN = new Notification(); |
| 2138 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2139 | mN.priority = PRIORITY_DEFAULT; |
| 2140 | mN.visibility = VISIBILITY_PRIVATE; |
| 2141 | } else { |
| 2142 | mN = toAdopt; |
| 2143 | if (mN.actions != null) { |
| 2144 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2145 | } |
| 2146 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2147 | if (mN.extras.containsKey(EXTRA_PEOPLE)) { |
| 2148 | Collections.addAll(mPersonList, mN.extras.getStringArray(EXTRA_PEOPLE)); |
| 2149 | } |
| 2150 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2151 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 2152 | if (!TextUtils.isEmpty(templateClass)) { |
| 2153 | final Class<? extends Style> styleClass |
| 2154 | = getNotificationStyleClass(templateClass); |
| 2155 | if (styleClass == null) { |
| 2156 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 2157 | } else { |
| 2158 | try { |
| 2159 | final Constructor<? extends Style> ctor = styleClass.getConstructor(); |
| 2160 | ctor.setAccessible(true); |
| 2161 | final Style style = ctor.newInstance(); |
| 2162 | style.restoreFromExtras(mN.extras); |
| 2163 | |
| 2164 | if (style != null) { |
| 2165 | setStyle(style); |
| 2166 | } |
| 2167 | } catch (Throwable t) { |
| 2168 | Log.e(TAG, "Could not create Style", t); |
| 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | } |
| 2174 | } |
| 2175 | |
| 2176 | private NotificationColorUtil getColorUtil() { |
| 2177 | if (!mColorUtilInited) { |
| 2178 | mColorUtilInited = true; |
| 2179 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.LOLLIPOP) { |
| 2180 | mColorUtil = NotificationColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2181 | } |
| 2182 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2183 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2187 | * Add a timestamp pertaining to the notification (usually the time the event occurred). |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2188 | * It will be shown in the notification content view by default; use |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2189 | * {@link #setShowWhen(boolean) setShowWhen} to control this. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2190 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2191 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2192 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2193 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2194 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2195 | return this; |
| 2196 | } |
| 2197 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2198 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2199 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2200 | * in the content view. |
| 2201 | */ |
| 2202 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2203 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2204 | return this; |
| 2205 | } |
| 2206 | |
| 2207 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2208 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2209 | * |
| 2210 | * 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] | 2211 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2212 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2213 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 2214 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2215 | * The counter can also be set to count down to <code>when</code> when using |
| 2216 | * {@link #setChronometerCountsDown(boolean)}. |
| 2217 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2218 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2219 | * @see Notification#when |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2220 | * @see #setChronometerCountsDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2221 | */ |
| 2222 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2223 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2224 | return this; |
| 2225 | } |
| 2226 | |
| 2227 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2228 | * Sets the Chronometer to count down instead of counting up. |
| 2229 | * |
| 2230 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 2231 | * If it isn't set the chronometer will count up. |
| 2232 | * |
| 2233 | * @see #setUsesChronometer(boolean) |
| 2234 | */ |
| 2235 | public Builder setChronometerCountsDown(boolean countsDown) { |
| 2236 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN, countsDown); |
| 2237 | return this; |
| 2238 | } |
| 2239 | |
| 2240 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2241 | * Set the small icon resource, which will be used to represent the notification in the |
| 2242 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2243 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2244 | |
| 2245 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 2246 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 2247 | * icon will be moved to the right-hand side. |
| 2248 | * |
| 2249 | |
| 2250 | * @param icon |
| 2251 | * A resource ID in the application's package of the drawable to use. |
| 2252 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2253 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2254 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2255 | return setSmallIcon(icon != 0 |
| 2256 | ? Icon.createWithResource(mContext, icon) |
| 2257 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2258 | } |
| 2259 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2260 | /** |
| 2261 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 2262 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 2263 | * LevelListDrawable}. |
| 2264 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2265 | * @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] | 2266 | * @param level The level to use for the icon. |
| 2267 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2268 | * @see Notification#icon |
| 2269 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2270 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2271 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2272 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2273 | return setSmallIcon(icon); |
| 2274 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * Set the small icon, which will be used to represent the notification in the |
| 2278 | * status bar and content view (unless overriden there by a |
| 2279 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 2280 | * |
| 2281 | * @param icon An Icon object to use. |
| 2282 | * @see Notification#icon |
| 2283 | */ |
| 2284 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2285 | mN.setSmallIcon(icon); |
| 2286 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 2287 | mN.icon = icon.getResId(); |
| 2288 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2289 | return this; |
| 2290 | } |
| 2291 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2292 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2293 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2294 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2295 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2296 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2297 | return this; |
| 2298 | } |
| 2299 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2300 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2301 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2302 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2303 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2304 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2305 | return this; |
| 2306 | } |
| 2307 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2308 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame^] | 2309 | * This provides some additional information that is displayed in the notification. No |
| 2310 | * guarantees are given where exactly it is displayed. |
| 2311 | * |
| 2312 | * <p>This information should only be provided if it provides an essential |
| 2313 | * benefit to the understanding of the notification. The more text you provide the |
| 2314 | * less readable it becomes. For example, an email client should only provide the account |
| 2315 | * name here if more than one email account has been added.</p> |
| 2316 | * |
| 2317 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 2318 | * notification header area. |
| 2319 | * |
| 2320 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 2321 | * this will be shown in the third line of text in the platform notification template. |
| 2322 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 2323 | * same time on those versions; they occupy the same place. |
| 2324 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2325 | */ |
| 2326 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2327 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2328 | return this; |
| 2329 | } |
| 2330 | |
| 2331 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 2332 | * Set the remote input history. |
| 2333 | * |
| 2334 | * This should be set to the most recent inputs that have been sent |
| 2335 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 2336 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 2337 | * |
| 2338 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 2339 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 2340 | * and how much of each individual input is shown. |
| 2341 | * |
| 2342 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 2343 | * with a {@code RemoteInput}.</p> |
| 2344 | */ |
| 2345 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 2346 | if (text == null) { |
| 2347 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 2348 | } else { |
| 2349 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 2350 | CharSequence[] safe = new CharSequence[N]; |
| 2351 | for (int i = 0; i < N; i++) { |
| 2352 | safe[i] = safeCharSequence(text[i]); |
| 2353 | } |
| 2354 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 2355 | } |
| 2356 | return this; |
| 2357 | } |
| 2358 | |
| 2359 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2360 | * Set the large number at the right-hand side of the notification. This is |
| 2361 | * equivalent to setContentInfo, although it might show the number in a different |
| 2362 | * font size for readability. |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame^] | 2363 | * |
| 2364 | * @deprecated this number is not shown anywhere anymore |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2365 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2366 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2367 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2368 | return this; |
| 2369 | } |
| 2370 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2371 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2372 | * A small piece of additional information pertaining to this notification. |
| 2373 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2374 | * The platform template will draw this on the last line of the notification, at the far |
| 2375 | * 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^] | 2376 | * |
| 2377 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 2378 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 2379 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2380 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2381 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2382 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2383 | return this; |
| 2384 | } |
| 2385 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2386 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2387 | * Set the progress this notification represents. |
| 2388 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2389 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2390 | */ |
| 2391 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2392 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 2393 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 2394 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2395 | return this; |
| 2396 | } |
| 2397 | |
| 2398 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2399 | * Supply a custom RemoteViews to use instead of the platform template. |
| 2400 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2401 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2402 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2403 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2404 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2405 | return setCustomContentView(views); |
| 2406 | } |
| 2407 | |
| 2408 | /** |
| 2409 | * Supply custom RemoteViews to use instead of the platform template. |
| 2410 | * |
| 2411 | * This will override the layout that would otherwise be constructed by this Builder |
| 2412 | * object. |
| 2413 | */ |
| 2414 | public Builder setCustomContentView(RemoteViews contentView) { |
| 2415 | mN.contentView = contentView; |
| 2416 | return this; |
| 2417 | } |
| 2418 | |
| 2419 | /** |
| 2420 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 2421 | * |
| 2422 | * This will override the expanded layout that would otherwise be constructed by this |
| 2423 | * Builder object. |
| 2424 | */ |
| 2425 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 2426 | mN.bigContentView = contentView; |
| 2427 | return this; |
| 2428 | } |
| 2429 | |
| 2430 | /** |
| 2431 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 2432 | * |
| 2433 | * This will override the heads-up layout that would otherwise be constructed by this |
| 2434 | * Builder object. |
| 2435 | */ |
| 2436 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 2437 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2438 | return this; |
| 2439 | } |
| 2440 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2441 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2442 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 2443 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2444 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 2445 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 2446 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2447 | * 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] | 2448 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2449 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2450 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2451 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2452 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2453 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2454 | return this; |
| 2455 | } |
| 2456 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2457 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2458 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 2459 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2460 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2461 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2462 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2463 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2464 | return this; |
| 2465 | } |
| 2466 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2467 | /** |
| 2468 | * An intent to launch instead of posting the notification to the status bar. |
| 2469 | * Only for use with extremely high-priority notifications demanding the user's |
| 2470 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 2471 | * alarm clock that the user has explicitly set to a particular time. |
| 2472 | * If this facility is used for something else, please give the user an option |
| 2473 | * to turn it off and use a normal notification, as this can be extremely |
| 2474 | * disruptive. |
| 2475 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2476 | * <p> |
| 2477 | * The system UI may choose to display a heads-up notification, instead of |
| 2478 | * launching this intent, while the user is using the device. |
| 2479 | * </p> |
| 2480 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2481 | * @param intent The pending intent to launch. |
| 2482 | * @param highPriority Passing true will cause this notification to be sent |
| 2483 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2484 | * |
| 2485 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2486 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2487 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2488 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2489 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 2490 | return this; |
| 2491 | } |
| 2492 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2493 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2494 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2495 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2496 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2497 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2498 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2499 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2500 | return this; |
| 2501 | } |
| 2502 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2503 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2504 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2505 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2506 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2507 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2508 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2509 | setTicker(tickerText); |
| 2510 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2511 | return this; |
| 2512 | } |
| 2513 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2514 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2515 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2516 | * |
| 2517 | * 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] | 2518 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 2519 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2520 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2521 | public Builder setLargeIcon(Bitmap b) { |
| 2522 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 2523 | } |
| 2524 | |
| 2525 | /** |
| 2526 | * Add a large icon to the notification content view. |
| 2527 | * |
| 2528 | * In the platform template, this image will be shown on the left of the notification view |
| 2529 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 2530 | * badge atop the large icon). |
| 2531 | */ |
| 2532 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2533 | mN.mLargeIcon = icon; |
| 2534 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2535 | return this; |
| 2536 | } |
| 2537 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2538 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2539 | * Set the sound to play. |
| 2540 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2541 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 2542 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2543 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2544 | * <p> |
| 2545 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2546 | * </p> |
| 2547 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2548 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2549 | */ |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 2550 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2551 | mN.sound = sound; |
| 2552 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 2553 | return this; |
| 2554 | } |
| 2555 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2556 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2557 | * 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] | 2558 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2559 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 2560 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2561 | * <p> |
| 2562 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2563 | * </p> |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2564 | * @deprecated use {@link #setSound(Uri, AudioAttributes)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2565 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2566 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 2567 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2568 | public Builder setSound(Uri sound, int streamType) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2569 | mN.sound = sound; |
| 2570 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2571 | return this; |
| 2572 | } |
| 2573 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2574 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2575 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 2576 | * use during playback. |
| 2577 | * |
| 2578 | * <p> |
| 2579 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2580 | * </p> |
| 2581 | * |
| 2582 | * @see Notification#sound |
| 2583 | */ |
| 2584 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2585 | mN.sound = sound; |
| 2586 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2587 | return this; |
| 2588 | } |
| 2589 | |
| 2590 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2591 | * Set the vibration pattern to use. |
| 2592 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2593 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 2594 | * <code>pattern</code> parameter. |
| 2595 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2596 | * <p> |
| 2597 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 2598 | * </p> |
| 2599 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2600 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2601 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2602 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2603 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2604 | return this; |
| 2605 | } |
| 2606 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2607 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2608 | * Set the desired color for the indicator LED on the device, as well as the |
| 2609 | * blink duty cycle (specified in milliseconds). |
| 2610 | * |
| 2611 | |
| 2612 | * Not all devices will honor all (or even any) of these values. |
| 2613 | * |
| 2614 | |
| 2615 | * @see Notification#ledARGB |
| 2616 | * @see Notification#ledOnMS |
| 2617 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2618 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 2619 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2620 | mN.ledARGB = argb; |
| 2621 | mN.ledOnMS = onMs; |
| 2622 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 2623 | if (onMs != 0 || offMs != 0) { |
| 2624 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 2625 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2626 | return this; |
| 2627 | } |
| 2628 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2629 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2630 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2631 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2632 | |
| 2633 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 2634 | * must take care of canceling them. |
| 2635 | * |
| 2636 | |
| 2637 | * They are typically used to indicate a background task that the user is actively engaged |
| 2638 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 2639 | * (e.g., a file download, sync operation, active network connection). |
| 2640 | * |
| 2641 | |
| 2642 | * @see Notification#FLAG_ONGOING_EVENT |
| 2643 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2644 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2645 | public Builder setOngoing(boolean ongoing) { |
| 2646 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 2647 | return this; |
| 2648 | } |
| 2649 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2650 | /** |
| 2651 | * Set this flag if you would only like the sound, vibrate |
| 2652 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2653 | * |
| 2654 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2655 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2656 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 2657 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 2658 | return this; |
| 2659 | } |
| 2660 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2661 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2662 | * Make this notification automatically dismissed when the user touches it. The |
| 2663 | * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens. |
| 2664 | * |
| 2665 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2666 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2667 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 2668 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2669 | return this; |
| 2670 | } |
| 2671 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2672 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 2673 | * Set whether or not this notification should not bridge to other devices. |
| 2674 | * |
| 2675 | * <p>Some notifications can be bridged to other devices for remote display. |
| 2676 | * This hint can be set to recommend this notification not be bridged. |
| 2677 | */ |
| 2678 | public Builder setLocalOnly(boolean localOnly) { |
| 2679 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 2680 | return this; |
| 2681 | } |
| 2682 | |
| 2683 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2684 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2685 | * <p> |
| 2686 | * The value should be one or more of the following fields combined with |
| 2687 | * bitwise-or: |
| 2688 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 2689 | * <p> |
| 2690 | * For all default values, use {@link #DEFAULT_ALL}. |
| 2691 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2692 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2693 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2694 | return this; |
| 2695 | } |
| 2696 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2697 | /** |
| 2698 | * Set the priority of this notification. |
| 2699 | * |
| 2700 | * @see Notification#priority |
| 2701 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2702 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2703 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2704 | return this; |
| 2705 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2706 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2707 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2708 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2709 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2710 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2711 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2712 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2713 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2714 | return this; |
| 2715 | } |
| 2716 | |
| 2717 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2718 | * Add a person that is relevant to this notification. |
| 2719 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 2720 | * <P> |
| 2721 | * Depending on user preferences, this annotation may allow the notification to pass |
| 2722 | * through interruption filters, and to appear more prominently in the user interface. |
| 2723 | * </P> |
| 2724 | * |
| 2725 | * <P> |
| 2726 | * The person should be specified by the {@code String} representation of a |
| 2727 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 2728 | * </P> |
| 2729 | * |
| 2730 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 2731 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 2732 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 2733 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
| 2734 | * </P> |
| 2735 | * |
| 2736 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2737 | * @see Notification#EXTRA_PEOPLE |
| 2738 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 2739 | public Builder addPerson(String uri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2740 | mPersonList.add(uri); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2741 | return this; |
| 2742 | } |
| 2743 | |
| 2744 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2745 | * Set this notification to be part of a group of notifications sharing the same key. |
| 2746 | * Grouped notifications may display in a cluster or stack on devices which |
| 2747 | * support such rendering. |
| 2748 | * |
| 2749 | * <p>To make this notification the summary for its group, also call |
| 2750 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 2751 | * {@link #setSortKey}. |
| 2752 | * @param groupKey The group key of the group. |
| 2753 | * @return this object for method chaining |
| 2754 | */ |
| 2755 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2756 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2757 | return this; |
| 2758 | } |
| 2759 | |
| 2760 | /** |
| 2761 | * Set this notification to be the group summary for a group of notifications. |
| 2762 | * Grouped notifications may display in a cluster or stack on devices which |
| 2763 | * support such rendering. Requires a group key also be set using {@link #setGroup}. |
| 2764 | * @param isGroupSummary Whether this notification should be a group summary. |
| 2765 | * @return this object for method chaining |
| 2766 | */ |
| 2767 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 2768 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 2769 | return this; |
| 2770 | } |
| 2771 | |
| 2772 | /** |
| 2773 | * Set a sort key that orders this notification among other notifications from the |
| 2774 | * same package. This can be useful if an external sort was already applied and an app |
| 2775 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 2776 | * value, although providing different priorities in addition to providing sort key may |
| 2777 | * cause this value to be ignored. |
| 2778 | * |
| 2779 | * <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] | 2780 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2781 | * |
| 2782 | * @see String#compareTo(String) |
| 2783 | */ |
| 2784 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2785 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2786 | return this; |
| 2787 | } |
| 2788 | |
| 2789 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2790 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2791 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2792 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 2793 | * |
| 2794 | * @see Notification#extras |
| 2795 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2796 | public Builder addExtras(Bundle extras) { |
| 2797 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2798 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2799 | } |
| 2800 | return this; |
| 2801 | } |
| 2802 | |
| 2803 | /** |
| 2804 | * Set metadata for this notification. |
| 2805 | * |
| 2806 | * <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] | 2807 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2808 | * called. |
| 2809 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2810 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 2811 | * Use {@link #addExtras} to merge in metadata instead. |
| 2812 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2813 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2814 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2815 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2816 | if (extras != null) { |
| 2817 | mUserExtras = extras; |
| 2818 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2819 | return this; |
| 2820 | } |
| 2821 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2822 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2823 | * Get the current metadata Bundle used by this notification Builder. |
| 2824 | * |
| 2825 | * <p>The returned Bundle is shared with this Builder. |
| 2826 | * |
| 2827 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 2828 | * {@link #build()} is called. |
| 2829 | * |
| 2830 | * @see Notification#extras |
| 2831 | */ |
| 2832 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2833 | return mUserExtras; |
| 2834 | } |
| 2835 | |
| 2836 | private Bundle getAllExtras() { |
| 2837 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 2838 | saveExtras.putAll(mN.extras); |
| 2839 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2843 | * Add an action to this notification. Actions are typically displayed by |
| 2844 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2845 | * <p> |
| 2846 | * Every action must have an icon (32dp square and matching the |
| 2847 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2848 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2849 | * <p> |
| 2850 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2851 | * the order they were added. Actions will not be displayed when the notification is |
| 2852 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2853 | * 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] | 2854 | * |
| 2855 | * @param icon Resource ID of a drawable that represents the action. |
| 2856 | * @param title Text describing the action. |
| 2857 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 2858 | * |
| 2859 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2860 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 2861 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2862 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2863 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2864 | return this; |
| 2865 | } |
| 2866 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2867 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2868 | * Add an action to this notification. Actions are typically displayed by |
| 2869 | * the system as a button adjacent to the notification content. |
| 2870 | * <p> |
| 2871 | * Every action must have an icon (32dp square and matching the |
| 2872 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2873 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2874 | * <p> |
| 2875 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2876 | * the order they were added. Actions will not be displayed when the notification is |
| 2877 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2878 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 2879 | * |
| 2880 | * @param action The action to add. |
| 2881 | */ |
| 2882 | public Builder addAction(Action action) { |
| 2883 | mActions.add(action); |
| 2884 | return this; |
| 2885 | } |
| 2886 | |
| 2887 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2888 | * Alter the complete list of actions attached to this notification. |
| 2889 | * @see #addAction(Action). |
| 2890 | * |
| 2891 | * @param actions |
| 2892 | * @return |
| 2893 | */ |
| 2894 | public Builder setActions(Action... actions) { |
| 2895 | mActions.clear(); |
| 2896 | for (int i = 0; i < actions.length; i++) { |
| 2897 | mActions.add(actions[i]); |
| 2898 | } |
| 2899 | return this; |
| 2900 | } |
| 2901 | |
| 2902 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2903 | * Add a rich notification style to be applied at build time. |
| 2904 | * |
| 2905 | * @param style Object responsible for modifying the notification style. |
| 2906 | */ |
| 2907 | public Builder setStyle(Style style) { |
| 2908 | if (mStyle != style) { |
| 2909 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2910 | if (mStyle != null) { |
| 2911 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2912 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 2913 | } else { |
| 2914 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2915 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2916 | } |
| 2917 | return this; |
| 2918 | } |
| 2919 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2920 | /** |
| 2921 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2922 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2923 | * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default), |
| 2924 | * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}. |
| 2925 | * |
| 2926 | * @return The same Builder. |
| 2927 | */ |
| 2928 | public Builder setVisibility(int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2929 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2930 | return this; |
| 2931 | } |
| 2932 | |
| 2933 | /** |
| 2934 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 2935 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 2936 | * @param n A replacement notification, presumably with some or all info redacted. |
| 2937 | * @return The same Builder. |
| 2938 | */ |
| 2939 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2940 | if (n != null) { |
| 2941 | mN.publicVersion = new Notification(); |
| 2942 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 2943 | } else { |
| 2944 | mN.publicVersion = null; |
| 2945 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2946 | return this; |
| 2947 | } |
| 2948 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2949 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2950 | * Apply an extender to this notification builder. Extenders may be used to add |
| 2951 | * metadata or change options on this builder. |
| 2952 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2953 | public Builder extend(Extender extender) { |
| 2954 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2955 | return this; |
| 2956 | } |
| 2957 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2958 | /** |
| 2959 | * @hide |
| 2960 | */ |
| 2961 | public void setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2962 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2963 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2964 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2965 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2966 | } |
| 2967 | } |
| 2968 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2969 | /** |
| 2970 | * Sets {@link Notification#color}. |
| 2971 | * |
| 2972 | * @param argb The accent color to use |
| 2973 | * |
| 2974 | * @return The same Builder. |
| 2975 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 2976 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2977 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 2978 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2979 | return this; |
| 2980 | } |
| 2981 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2982 | private Drawable getProfileBadgeDrawable() { |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2983 | // Note: This assumes that the current user can read the profile badge of the |
| 2984 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 2985 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2986 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | private Bitmap getProfileBadge() { |
| 2990 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 2991 | if (badge == null) { |
| 2992 | return null; |
| 2993 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2994 | final int size = mContext.getResources().getDimensionPixelSize( |
| 2995 | R.dimen.notification_badge_size); |
| 2996 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 2997 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2998 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 2999 | badge.draw(canvas); |
| 3000 | return bitmap; |
| 3001 | } |
| 3002 | |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3003 | private void bindProfileBadge(RemoteViews contentView) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3004 | Bitmap profileBadge = getProfileBadge(); |
| 3005 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3006 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3007 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 3008 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3009 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3010 | } |
| 3011 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3012 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3013 | resetNotificationHeader(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3014 | resetContentMargins(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3015 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3016 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3017 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3018 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3019 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3020 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3021 | contentView.setTextViewText(R.id.text_line_1, null); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3022 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3023 | } |
| 3024 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3025 | /** |
| 3026 | * Resets the notification header to its original state |
| 3027 | */ |
| 3028 | private void resetNotificationHeader(RemoteViews contentView) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3029 | contentView.setImageViewResource(R.id.icon, 0); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 3030 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3031 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 3032 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame^] | 3033 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
| 3034 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3035 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3036 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 3037 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | private void resetContentMargins(RemoteViews contentView) { |
| 3041 | contentView.setViewLayoutMarginEnd(R.id.line1, 0); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3042 | contentView.setViewLayoutMarginEnd(R.id.text, 0); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3043 | } |
| 3044 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3045 | private RemoteViews applyStandardTemplate(int resId) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3046 | return applyStandardTemplate(resId, true /* hasProgress */); |
| 3047 | } |
| 3048 | |
| 3049 | /** |
| 3050 | * @param hasProgress whether the progress bar should be shown and set |
| 3051 | */ |
| 3052 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3053 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 3054 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3055 | resetStandardTemplate(contentView); |
| 3056 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3057 | final Bundle ex = mN.extras; |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3058 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3059 | bindNotificationHeader(contentView); |
| 3060 | bindLargeIcon(contentView); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3061 | if (ex.getCharSequence(EXTRA_TITLE) != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3062 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3063 | contentView.setTextViewText(R.id.title, |
| 3064 | processLegacyText(ex.getCharSequence(EXTRA_TITLE))); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3065 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3066 | boolean showProgress = handleProgressBar(hasProgress, contentView, ex); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3067 | if (ex.getCharSequence(EXTRA_TEXT) != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3068 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 3069 | : com.android.internal.R.id.text; |
| 3070 | contentView.setTextViewText(textId, processLegacyText( |
| 3071 | ex.getCharSequence(EXTRA_TEXT))); |
| 3072 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3073 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3074 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3075 | setContentMinHeight(contentView, showProgress || mN.mLargeIcon != null); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3076 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3077 | return contentView; |
| 3078 | } |
| 3079 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3080 | /** |
| 3081 | * @param remoteView the remote view to update the minheight in |
| 3082 | * @param hasMinHeight does it have a mimHeight |
| 3083 | * @hide |
| 3084 | */ |
| 3085 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 3086 | int minHeight = 0; |
| 3087 | if (hasMinHeight) { |
| 3088 | // we need to set the minHeight of the notification |
| 3089 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 3090 | com.android.internal.R.dimen.notification_min_content_height); |
| 3091 | } |
| 3092 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 3093 | } |
| 3094 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3095 | private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3096 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 3097 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 3098 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 3099 | if (hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3100 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3101 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3102 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3103 | contentView.setProgressBackgroundTintList( |
| 3104 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 3105 | R.color.notification_progress_background_color))); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3106 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3107 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3108 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 3109 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3110 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3111 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3112 | } else { |
| 3113 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3114 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3115 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3116 | } |
| 3117 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3118 | private void bindLargeIcon(RemoteViews contentView) { |
| 3119 | if (mN.mLargeIcon != null) { |
| 3120 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 3121 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
| 3122 | processLargeLegacyIcon(mN.mLargeIcon, contentView); |
| 3123 | int endMargin = mContext.getResources().getDimensionPixelSize( |
| 3124 | R.dimen.notification_content_picture_margin); |
| 3125 | contentView.setViewLayoutMarginEnd(R.id.line1, endMargin); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3126 | contentView.setViewLayoutMarginEnd(R.id.text, endMargin); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3127 | contentView.setViewLayoutMarginEnd(R.id.progress, endMargin); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3128 | } |
| 3129 | } |
| 3130 | |
| 3131 | private void bindNotificationHeader(RemoteViews contentView) { |
| 3132 | bindSmallIcon(contentView); |
| 3133 | bindHeaderAppName(contentView); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame^] | 3134 | bindHeaderText(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3135 | bindHeaderChronometerAndTime(contentView); |
| 3136 | bindExpandButton(contentView); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3137 | bindProfileBadge(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | private void bindExpandButton(RemoteViews contentView) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3141 | contentView.setDrawableParameters(R.id.expand_button, false, -1, resolveContrastColor(), |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3142 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3143 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3144 | resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | private void bindHeaderChronometerAndTime(RemoteViews contentView) { |
| 3148 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3149 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3150 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 3151 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 3152 | contentView.setLong(R.id.chronometer, "setBase", |
| 3153 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 3154 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3155 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN); |
| 3156 | contentView.setChronometerCountsDown(R.id.chronometer, countsDown); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3157 | } else { |
| 3158 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 3159 | contentView.setLong(R.id.time, "setTime", mN.when); |
| 3160 | } |
| 3161 | } |
| 3162 | } |
| 3163 | |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame^] | 3164 | private void bindHeaderText(RemoteViews contentView) { |
| 3165 | CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 3166 | if (headerText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3167 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame^] | 3168 | headerText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3169 | } |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame^] | 3170 | if (headerText == null |
| 3171 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 3172 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 3173 | headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 3174 | } |
| 3175 | if (headerText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3176 | // 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^] | 3177 | contentView.setTextViewText(R.id.header_text, processLegacyText(headerText)); |
| 3178 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 3179 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | private void bindHeaderAppName(RemoteViews contentView) { |
Tony Mak | 4dc008c | 2016-03-16 10:46:49 +0000 | [diff] [blame] | 3184 | CharSequence appName = mContext.getPackageManager() |
| 3185 | .getApplicationLabel(mContext.getApplicationInfo()); |
| 3186 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3187 | if (TextUtils.isEmpty(appName)) { |
| 3188 | return; |
| 3189 | } |
| 3190 | contentView.setTextViewText(R.id.app_name_text, appName); |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3191 | contentView.setTextColor(R.id.app_name_text, resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | private void bindSmallIcon(RemoteViews contentView) { |
| 3195 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
| 3196 | processSmallIconColor(mN.mSmallIcon, contentView); |
| 3197 | } |
| 3198 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3199 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3200 | * @return true if the built notification will show the time or the chronometer; false |
| 3201 | * otherwise |
| 3202 | */ |
| 3203 | private boolean showsTimeOrChronometer() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3204 | return mN.when != 0 && mN.extras.getBoolean(EXTRA_SHOW_WHEN); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3205 | } |
| 3206 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3207 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 3208 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3209 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3210 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3211 | |
| 3212 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 3213 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
| 3214 | |
| 3215 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 3216 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 3217 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 3218 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3219 | } |
| 3220 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3221 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3222 | RemoteViews big = applyStandardTemplate(layoutId); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3223 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3224 | resetStandardTemplateWithActions(big); |
| 3225 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3226 | boolean validRemoteInput = false; |
| 3227 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3228 | int N = mActions.size(); |
| 3229 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 3230 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3231 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3232 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3233 | for (int i=0; i<N; i++) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3234 | Action action = mActions.get(i); |
| 3235 | validRemoteInput |= hasValidRemoteInput(action); |
| 3236 | |
| 3237 | final RemoteViews button = generateActionButton(action); |
Adrian Roos | 9b123cf | 2016-02-04 14:55:57 -0800 | [diff] [blame] | 3238 | if (i == N - 1) { |
| 3239 | button.setViewLayoutWidth(com.android.internal.R.id.action0, |
| 3240 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 3241 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3242 | big.addView(R.id.actions, button); |
| 3243 | } |
| 3244 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3245 | |
| 3246 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
| 3247 | if (validRemoteInput && replyText != null |
| 3248 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) { |
| 3249 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
| 3250 | big.setTextViewText(R.id.notification_material_reply_text_1, replyText[0]); |
| 3251 | |
| 3252 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) { |
| 3253 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
| 3254 | big.setTextViewText(R.id.notification_material_reply_text_2, replyText[1]); |
| 3255 | |
| 3256 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) { |
| 3257 | big.setViewVisibility( |
| 3258 | R.id.notification_material_reply_text_3, View.VISIBLE); |
| 3259 | big.setTextViewText(R.id.notification_material_reply_text_3, replyText[2]); |
| 3260 | } |
| 3261 | } |
| 3262 | } |
| 3263 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3264 | return big; |
| 3265 | } |
| 3266 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3267 | private boolean hasValidRemoteInput(Action action) { |
| 3268 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 3269 | // Weird actions |
| 3270 | return false; |
| 3271 | } |
| 3272 | |
| 3273 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 3274 | if (remoteInputs == null) { |
| 3275 | return false; |
| 3276 | } |
| 3277 | |
| 3278 | for (RemoteInput r : remoteInputs) { |
| 3279 | CharSequence[] choices = r.getChoices(); |
| 3280 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 3281 | return true; |
| 3282 | } |
| 3283 | } |
| 3284 | return false; |
| 3285 | } |
| 3286 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3287 | /** |
| 3288 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 3289 | * 1. Custom contentView from the caller |
| 3290 | * 2. Style's proposed content view |
| 3291 | * 3. Standard template view |
| 3292 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3293 | public RemoteViews createContentView() { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3294 | if (mN.contentView != null && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3295 | return mN.contentView; |
| 3296 | } else if (mStyle != null) { |
| 3297 | final RemoteViews styleView = mStyle.makeContentView(); |
| 3298 | if (styleView != null) { |
| 3299 | return styleView; |
| 3300 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3301 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3302 | return applyStandardTemplate(getBaseLayoutResource()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3303 | } |
| 3304 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3305 | /** |
| 3306 | * Construct a RemoteViews for the final big notification layout. |
| 3307 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3308 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3309 | RemoteViews result = null; |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3310 | if (mN.bigContentView != null |
| 3311 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 3312 | return mN.bigContentView; |
| 3313 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3314 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 3315 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 3316 | } else if (mActions.size() != 0) { |
| 3317 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3318 | } |
| 3319 | adaptNotificationHeaderForBigContentView(result); |
| 3320 | return result; |
| 3321 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3322 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3323 | /** |
| 3324 | * Construct a RemoteViews for the final notification header only |
| 3325 | * |
| 3326 | * @hide |
| 3327 | */ |
| 3328 | public RemoteViews makeNotificationHeader() { |
| 3329 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
| 3330 | R.layout.notification_template_header); |
| 3331 | resetNotificationHeader(header); |
| 3332 | bindNotificationHeader(header); |
| 3333 | return header; |
| 3334 | } |
| 3335 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3336 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 3337 | if (result != null) { |
| 3338 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 3339 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3340 | } |
| 3341 | |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 3342 | private void adaptNotificationHeaderForBigContentView(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 3343 | if (result != null) { |
| 3344 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 3345 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3346 | } |
| 3347 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3348 | /** |
| 3349 | * Construct a RemoteViews for the final heads-up notification layout. |
| 3350 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3351 | public RemoteViews createHeadsUpContentView() { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3352 | if (mN.headsUpContentView != null |
| 3353 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 3354 | return mN.headsUpContentView; |
| 3355 | } else if (mStyle != null) { |
| 3356 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(); |
| 3357 | if (styleView != null) { |
| 3358 | return styleView; |
| 3359 | } |
| 3360 | } else if (mActions.size() == 0) { |
| 3361 | return null; |
| 3362 | } |
| 3363 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3364 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 3365 | } |
| 3366 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 3367 | /** |
| 3368 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 3369 | * |
| 3370 | * @hide |
| 3371 | */ |
| 3372 | public RemoteViews makePublicContentView() { |
| 3373 | if (mN.publicVersion != null) { |
| 3374 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3375 | return builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 3376 | } |
| 3377 | Bundle savedBundle = mN.extras; |
| 3378 | Style style = mStyle; |
| 3379 | mStyle = null; |
| 3380 | Icon largeIcon = mN.mLargeIcon; |
| 3381 | mN.mLargeIcon = null; |
| 3382 | Bundle publicExtras = new Bundle(); |
| 3383 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 3384 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 3385 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 3386 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3387 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN, |
| 3388 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNTS_DOWN)); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 3389 | publicExtras.putCharSequence(EXTRA_TITLE, |
| 3390 | mContext.getString(R.string.notification_hidden_text)); |
| 3391 | mN.extras = publicExtras; |
| 3392 | final RemoteViews publicView = applyStandardTemplate(getBaseLayoutResource()); |
| 3393 | mN.extras = savedBundle; |
| 3394 | mN.mLargeIcon = largeIcon; |
| 3395 | mStyle = style; |
| 3396 | return publicView; |
| 3397 | } |
| 3398 | |
| 3399 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 3400 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3401 | private RemoteViews generateActionButton(Action action) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3402 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 3403 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3404 | tombstone ? getActionTombstoneLayoutResource() |
| 3405 | : getActionLayoutResource()); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 3406 | final Icon ai = action.getIcon(); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3407 | button.setTextViewText(R.id.action0, processLegacyText(action.title)); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3408 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 3409 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 3410 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3411 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 3412 | if (action.mRemoteInputs != null) { |
| 3413 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 3414 | } |
| 3415 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3416 | button.setTextColor(R.id.action0, resolveContrastColor()); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 3417 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3418 | return button; |
| 3419 | } |
| 3420 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3421 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3422 | * @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] | 3423 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3424 | */ |
| 3425 | private boolean isLegacy() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3426 | return getColorUtil() != null; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3427 | } |
| 3428 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3429 | private CharSequence processLegacyText(CharSequence charSequence) { |
| 3430 | if (isLegacy()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3431 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3432 | } else { |
| 3433 | return charSequence; |
| 3434 | } |
| 3435 | } |
| 3436 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3437 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3438 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3439 | */ |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3440 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3441 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
| 3442 | if (colorable) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3443 | contentView.setDrawableParameters(R.id.icon, false, -1, resolveContrastColor(), |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 3444 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3445 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3446 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3447 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3448 | colorable ? resolveContrastColor() : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3449 | } |
| 3450 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3451 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3452 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3453 | * if it's grayscale). |
| 3454 | */ |
| 3455 | // TODO: also check bounds, transparency, that sort of thing. |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3456 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) { |
| 3457 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3458 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3459 | // resolve color will fall back to the default when legacy |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3460 | contentView.setDrawableParameters(R.id.icon, false, -1, resolveContrastColor(), |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3461 | PorterDuff.Mode.SRC_ATOP, -1); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 3462 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3463 | } |
| 3464 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3465 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3466 | if (mN.color != COLOR_DEFAULT) { |
| 3467 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3468 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3469 | } |
| 3470 | |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3471 | int resolveContrastColor() { |
| 3472 | if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) { |
| 3473 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3474 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3475 | final int contrasted = NotificationColorUtil.resolveContrastColor(mContext, mN.color); |
| 3476 | |
| 3477 | mCachedContrastColorIsFor = mN.color; |
| 3478 | return mCachedContrastColor = contrasted; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3479 | } |
| 3480 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3481 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3482 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3483 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3484 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3485 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3486 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3487 | mN.actions = new Action[mActions.size()]; |
| 3488 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3489 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3490 | if (!mPersonList.isEmpty()) { |
| 3491 | mN.extras.putStringArray(EXTRA_PEOPLE, |
| 3492 | mPersonList.toArray(new String[mPersonList.size()])); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3493 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 3494 | if (mN.bigContentView != null || mN.contentView != null |
| 3495 | || mN.headsUpContentView != null) { |
| 3496 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 3497 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3498 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3499 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3500 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3501 | /** |
| 3502 | * Creates a Builder from an existing notification so further changes can be made. |
| 3503 | * @param context The context for your application / activity. |
| 3504 | * @param n The notification to create a Builder from. |
| 3505 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3506 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3507 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3508 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 3509 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3510 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 3511 | if (applicationInfo != null) { |
| 3512 | try { |
| 3513 | builderContext = context.createApplicationContext(applicationInfo, |
| 3514 | Context.CONTEXT_RESTRICTED); |
| 3515 | } catch (NameNotFoundException e) { |
| 3516 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 3517 | builderContext = context; // try with our context |
| 3518 | } |
| 3519 | } else { |
| 3520 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3521 | } |
| 3522 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3523 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | private static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3527 | Class<? extends Style>[] classes = new Class[] { |
| 3528 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 3529 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class }; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3530 | for (Class<? extends Style> innerClass : classes) { |
| 3531 | if (templateClass.equals(innerClass.getName())) { |
| 3532 | return innerClass; |
| 3533 | } |
| 3534 | } |
| 3535 | return null; |
| 3536 | } |
| 3537 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3538 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3539 | * @deprecated Use {@link #build()} instead. |
| 3540 | */ |
| 3541 | @Deprecated |
| 3542 | public Notification getNotification() { |
| 3543 | return build(); |
| 3544 | } |
| 3545 | |
| 3546 | /** |
| 3547 | * Combine all of the options that have been set and return a new {@link Notification} |
| 3548 | * object. |
| 3549 | */ |
| 3550 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3551 | // first, add any extras from the calling code |
| 3552 | if (mUserExtras != null) { |
| 3553 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 3554 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3555 | |
| 3556 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 3557 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 3558 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3559 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3560 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3561 | if (mStyle != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3562 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3563 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3564 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 3565 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 3566 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3567 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3568 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3569 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 3570 | mN.contentView.getSequenceNumber()); |
| 3571 | } |
| 3572 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3573 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3574 | if (mN.bigContentView != null) { |
| 3575 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 3576 | mN.bigContentView.getSequenceNumber()); |
| 3577 | } |
| 3578 | } |
| 3579 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 3580 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3581 | if (mN.headsUpContentView != null) { |
| 3582 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 3583 | mN.headsUpContentView.getSequenceNumber()); |
| 3584 | } |
| 3585 | } |
| 3586 | } |
| 3587 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 3588 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 3589 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 3590 | } |
| 3591 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3592 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3593 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3594 | |
| 3595 | /** |
| 3596 | * Apply this Builder to an existing {@link Notification} object. |
| 3597 | * |
| 3598 | * @hide |
| 3599 | */ |
| 3600 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 3601 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3602 | return n; |
| 3603 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3604 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3605 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3606 | * Removes RemoteViews that were created for compatibility from {@param n}, if they did not |
| 3607 | * change. |
| 3608 | * |
| 3609 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 3610 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3611 | * @hide |
| 3612 | */ |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3613 | public static Notification maybeCloneStrippedForDelivery(Notification n) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3614 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3615 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3616 | // Only strip views for known Styles because we won't know how to |
| 3617 | // re-create them otherwise. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3618 | if (!TextUtils.isEmpty(templateClass) |
| 3619 | && getNotificationStyleClass(templateClass) == null) { |
| 3620 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3621 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3622 | |
| 3623 | // Only strip unmodified BuilderRemoteViews. |
| 3624 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3625 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3626 | n.contentView.getSequenceNumber(); |
| 3627 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3628 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3629 | n.bigContentView.getSequenceNumber(); |
| 3630 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3631 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3632 | n.headsUpContentView.getSequenceNumber(); |
| 3633 | |
| 3634 | // Nothing to do here, no need to clone. |
| 3635 | if (!stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
| 3636 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3637 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 3638 | |
| 3639 | Notification clone = n.clone(); |
| 3640 | if (stripContentView) { |
| 3641 | clone.contentView = null; |
| 3642 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 3643 | } |
| 3644 | if (stripBigContentView) { |
| 3645 | clone.bigContentView = null; |
| 3646 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 3647 | } |
| 3648 | if (stripHeadsUpContentView) { |
| 3649 | clone.headsUpContentView = null; |
| 3650 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 3651 | } |
| 3652 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3653 | } |
| 3654 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3655 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3656 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3660 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3664 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3668 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3672 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3676 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3680 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3681 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3682 | } |
| 3683 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3684 | /** |
| 3685 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 3686 | * object. |
| 3687 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3688 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3689 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3690 | |
| 3691 | /** |
| 3692 | * @hide |
| 3693 | */ |
| 3694 | protected CharSequence mSummaryText = null; |
| 3695 | |
| 3696 | /** |
| 3697 | * @hide |
| 3698 | */ |
| 3699 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3700 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3701 | protected Builder mBuilder; |
| 3702 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3703 | /** |
| 3704 | * Overrides ContentTitle in the big form of the template. |
| 3705 | * This defaults to the value passed to setContentTitle(). |
| 3706 | */ |
| 3707 | protected void internalSetBigContentTitle(CharSequence title) { |
| 3708 | mBigContentTitle = title; |
| 3709 | } |
| 3710 | |
| 3711 | /** |
| 3712 | * Set the first line of text after the detail section in the big form of the template. |
| 3713 | */ |
| 3714 | protected void internalSetSummaryText(CharSequence cs) { |
| 3715 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3716 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3717 | } |
| 3718 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3719 | public void setBuilder(Builder builder) { |
| 3720 | if (mBuilder != builder) { |
| 3721 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3722 | if (mBuilder != null) { |
| 3723 | mBuilder.setStyle(this); |
| 3724 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3725 | } |
| 3726 | } |
| 3727 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3728 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3729 | if (mBuilder == null) { |
| 3730 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 3731 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3732 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3733 | |
| 3734 | protected RemoteViews getStandardView(int layoutId) { |
| 3735 | checkBuilder(); |
| 3736 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3737 | // Nasty. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3738 | CharSequence oldBuilderContentTitle = |
| 3739 | mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3740 | if (mBigContentTitle != null) { |
| 3741 | mBuilder.setContentTitle(mBigContentTitle); |
| 3742 | } |
| 3743 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3744 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 3745 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3746 | mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3747 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3748 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 3749 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 3750 | } else { |
| 3751 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3752 | } |
| 3753 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3754 | return contentView; |
| 3755 | } |
| 3756 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3757 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3758 | * Construct a Style-specific RemoteViews for the final 1U notification layout. |
| 3759 | * The default implementation has nothing additional to add. |
| 3760 | * @hide |
| 3761 | */ |
| 3762 | public RemoteViews makeContentView() { |
| 3763 | return null; |
| 3764 | } |
| 3765 | |
| 3766 | /** |
| 3767 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 3768 | * @hide |
| 3769 | */ |
| 3770 | public RemoteViews makeBigContentView() { |
| 3771 | return null; |
| 3772 | } |
| 3773 | |
| 3774 | /** |
| 3775 | * Construct a Style-specific RemoteViews for the final HUN layout. |
| 3776 | * @hide |
| 3777 | */ |
| 3778 | public RemoteViews makeHeadsUpContentView() { |
| 3779 | return null; |
| 3780 | } |
| 3781 | |
| 3782 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3783 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3784 | * @hide |
| 3785 | */ |
| 3786 | public void addExtras(Bundle extras) { |
| 3787 | if (mSummaryTextSet) { |
| 3788 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 3789 | } |
| 3790 | if (mBigContentTitle != null) { |
| 3791 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 3792 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 3793 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3794 | } |
| 3795 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3796 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3797 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3798 | * @hide |
| 3799 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3800 | protected void restoreFromExtras(Bundle extras) { |
| 3801 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 3802 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 3803 | mSummaryTextSet = true; |
| 3804 | } |
| 3805 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 3806 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | |
| 3811 | /** |
| 3812 | * @hide |
| 3813 | */ |
| 3814 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3815 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3816 | return wip; |
| 3817 | } |
| 3818 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 3819 | /** |
| 3820 | * @hide |
| 3821 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 3822 | public void purgeResources() {} |
| 3823 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3824 | /** |
| 3825 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 3826 | * attached to. |
| 3827 | * |
| 3828 | * @return the fully constructed Notification. |
| 3829 | */ |
| 3830 | public Notification build() { |
| 3831 | checkBuilder(); |
| 3832 | return mBuilder.build(); |
| 3833 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3834 | |
| 3835 | /** |
| 3836 | * @hide |
| 3837 | * @return true if the style positions the progress bar on the second line; false if the |
| 3838 | * style hides the progress bar |
| 3839 | */ |
| 3840 | protected boolean hasProgress() { |
| 3841 | return true; |
| 3842 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3843 | |
| 3844 | /** |
| 3845 | * @hide |
| 3846 | * @return Whether we should put the summary be put into the notification header |
| 3847 | */ |
| 3848 | public boolean hasSummaryInHeader() { |
| 3849 | return true; |
| 3850 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 3851 | |
| 3852 | /** |
| 3853 | * @hide |
| 3854 | * @return Whether custom content views are displayed inline in the style |
| 3855 | */ |
| 3856 | public boolean displayCustomViewInline() { |
| 3857 | return false; |
| 3858 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3859 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3860 | |
| 3861 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3862 | * 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] | 3863 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3864 | * 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] | 3865 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3866 | * Notification notif = new Notification.Builder(mContext) |
| 3867 | * .setContentTitle("New photo from " + sender.toString()) |
| 3868 | * .setContentText(subject) |
| 3869 | * .setSmallIcon(R.drawable.new_post) |
| 3870 | * .setLargeIcon(aBitmap) |
| 3871 | * .setStyle(new Notification.BigPictureStyle() |
| 3872 | * .bigPicture(aBigBitmap)) |
| 3873 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3874 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3875 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3876 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3877 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3878 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3879 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3880 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3881 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3882 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3883 | public BigPictureStyle() { |
| 3884 | } |
| 3885 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3886 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3887 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3888 | } |
| 3889 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3890 | /** |
| 3891 | * Overrides ContentTitle in the big form of the template. |
| 3892 | * This defaults to the value passed to setContentTitle(). |
| 3893 | */ |
| 3894 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3895 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3896 | return this; |
| 3897 | } |
| 3898 | |
| 3899 | /** |
| 3900 | * Set the first line of text after the detail section in the big form of the template. |
| 3901 | */ |
| 3902 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3903 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3904 | return this; |
| 3905 | } |
| 3906 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 3907 | /** |
| 3908 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 3909 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3910 | public BigPictureStyle bigPicture(Bitmap b) { |
| 3911 | mPicture = b; |
| 3912 | return this; |
| 3913 | } |
| 3914 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3915 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3916 | * Override the large icon when the big notification is shown. |
| 3917 | */ |
| 3918 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3919 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3920 | } |
| 3921 | |
| 3922 | /** |
| 3923 | * Override the large icon when the big notification is shown. |
| 3924 | */ |
| 3925 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3926 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3927 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3928 | return this; |
| 3929 | } |
| 3930 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 3931 | /** @hide */ |
| 3932 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 3933 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 3934 | /** |
| 3935 | * @hide |
| 3936 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 3937 | @Override |
| 3938 | public void purgeResources() { |
| 3939 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 3940 | if (mPicture != null && |
| 3941 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 3942 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 3943 | mPicture = mPicture.createAshmemBitmap(); |
| 3944 | } |
| 3945 | if (mBigLargeIcon != null) { |
| 3946 | mBigLargeIcon.convertToAshmem(); |
| 3947 | } |
| 3948 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3949 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3950 | /** |
| 3951 | * @hide |
| 3952 | */ |
| 3953 | public RemoteViews makeBigContentView() { |
| 3954 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3955 | // This covers the following cases: |
| 3956 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3957 | // mN.mLargeIcon |
| 3958 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3959 | Icon oldLargeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3960 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3961 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 3962 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3963 | } |
| 3964 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3965 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3966 | if (mSummaryTextSet) { |
| 3967 | contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(mSummaryText)); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3968 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3969 | } |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3970 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.mLargeIcon != null); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 3971 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3972 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3973 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3974 | } |
| 3975 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3976 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3977 | return contentView; |
| 3978 | } |
| 3979 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3980 | /** |
| 3981 | * @hide |
| 3982 | */ |
| 3983 | public void addExtras(Bundle extras) { |
| 3984 | super.addExtras(extras); |
| 3985 | |
| 3986 | if (mBigLargeIconSet) { |
| 3987 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 3988 | } |
| 3989 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 3990 | } |
| 3991 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3992 | /** |
| 3993 | * @hide |
| 3994 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3995 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3996 | protected void restoreFromExtras(Bundle extras) { |
| 3997 | super.restoreFromExtras(extras); |
| 3998 | |
| 3999 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 4000 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4001 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 4002 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4003 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 4004 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4005 | |
| 4006 | /** |
| 4007 | * @hide |
| 4008 | */ |
| 4009 | @Override |
| 4010 | public boolean hasSummaryInHeader() { |
| 4011 | return false; |
| 4012 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4013 | } |
| 4014 | |
| 4015 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 4016 | * 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] | 4017 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4018 | * 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] | 4019 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4020 | * Notification notif = new Notification.Builder(mContext) |
| 4021 | * .setContentTitle("New mail from " + sender.toString()) |
| 4022 | * .setContentText(subject) |
| 4023 | * .setSmallIcon(R.drawable.new_mail) |
| 4024 | * .setLargeIcon(aBitmap) |
| 4025 | * .setStyle(new Notification.BigTextStyle() |
| 4026 | * .bigText(aVeryLongString)) |
| 4027 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4028 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4029 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 4030 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4031 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4032 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4033 | |
| 4034 | private static final int MAX_LINES = 13; |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 4035 | private static final int LINES_CONSUMED_BY_ACTIONS = 4; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4036 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4037 | private CharSequence mBigText; |
| 4038 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4039 | public BigTextStyle() { |
| 4040 | } |
| 4041 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4042 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4043 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4044 | } |
| 4045 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4046 | /** |
| 4047 | * Overrides ContentTitle in the big form of the template. |
| 4048 | * This defaults to the value passed to setContentTitle(). |
| 4049 | */ |
| 4050 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4051 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4052 | return this; |
| 4053 | } |
| 4054 | |
| 4055 | /** |
| 4056 | * Set the first line of text after the detail section in the big form of the template. |
| 4057 | */ |
| 4058 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4059 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4060 | return this; |
| 4061 | } |
| 4062 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 4063 | /** |
| 4064 | * Provide the longer text to be displayed in the big form of the |
| 4065 | * template in place of the content text. |
| 4066 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4067 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4068 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4069 | return this; |
| 4070 | } |
| 4071 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4072 | /** |
| 4073 | * @hide |
| 4074 | */ |
| 4075 | public void addExtras(Bundle extras) { |
| 4076 | super.addExtras(extras); |
| 4077 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4078 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 4079 | } |
| 4080 | |
| 4081 | /** |
| 4082 | * @hide |
| 4083 | */ |
| 4084 | @Override |
| 4085 | protected void restoreFromExtras(Bundle extras) { |
| 4086 | super.restoreFromExtras(extras); |
| 4087 | |
| 4088 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4089 | } |
| 4090 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4091 | /** |
| 4092 | * @hide |
| 4093 | */ |
| 4094 | public RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4095 | |
| 4096 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4097 | CharSequence oldBuilderContentText = |
| 4098 | mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT); |
| 4099 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 4100 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4101 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4102 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4103 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4104 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 4105 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
| 4106 | contentView.setTextViewText(R.id.big_text, bigTextText); |
| 4107 | contentView.setViewVisibility(R.id.big_text, |
| 4108 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4109 | contentView.setInt(R.id.big_text, "setMaxLines", calculateMaxLines()); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 4110 | contentView.setBoolean(R.id.big_text, "setHasImage", mBuilder.mN.mLargeIcon != null); |
| 4111 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4112 | return contentView; |
| 4113 | } |
| 4114 | |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4115 | private int calculateMaxLines() { |
| 4116 | int lineCount = MAX_LINES; |
| 4117 | boolean hasActions = mBuilder.mActions.size() > 0; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4118 | if (hasActions) { |
| 4119 | lineCount -= LINES_CONSUMED_BY_ACTIONS; |
| 4120 | } |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4121 | return lineCount; |
| 4122 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4123 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4124 | |
| 4125 | /** |
| 4126 | * 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] | 4127 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4128 | * 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] | 4129 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 4130 | * Notification notif = new Notification.Builder(mContext) |
| 4131 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 4132 | * .setContentText(subject) |
| 4133 | * .setSmallIcon(R.drawable.new_mail) |
| 4134 | * .setLargeIcon(aBitmap) |
| 4135 | * .setStyle(new Notification.InboxStyle() |
| 4136 | * .addLine(str1) |
| 4137 | * .addLine(str2) |
| 4138 | * .setContentTitle("") |
| 4139 | * .setSummaryText("+3 more")) |
| 4140 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4141 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4142 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4143 | * @see Notification#bigContentView |
| 4144 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4145 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4146 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 4147 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4148 | public InboxStyle() { |
| 4149 | } |
| 4150 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4151 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4152 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4153 | } |
| 4154 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4155 | /** |
| 4156 | * Overrides ContentTitle in the big form of the template. |
| 4157 | * This defaults to the value passed to setContentTitle(). |
| 4158 | */ |
| 4159 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4160 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4161 | return this; |
| 4162 | } |
| 4163 | |
| 4164 | /** |
| 4165 | * Set the first line of text after the detail section in the big form of the template. |
| 4166 | */ |
| 4167 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4168 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4169 | return this; |
| 4170 | } |
| 4171 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 4172 | /** |
| 4173 | * Append a line to the digest section of the Inbox notification. |
| 4174 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4175 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4176 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4177 | return this; |
| 4178 | } |
| 4179 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4180 | /** |
| 4181 | * @hide |
| 4182 | */ |
| 4183 | public void addExtras(Bundle extras) { |
| 4184 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4185 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4186 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 4187 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 4188 | } |
| 4189 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4190 | /** |
| 4191 | * @hide |
| 4192 | */ |
| 4193 | @Override |
| 4194 | protected void restoreFromExtras(Bundle extras) { |
| 4195 | super.restoreFromExtras(extras); |
| 4196 | |
| 4197 | mTexts.clear(); |
| 4198 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 4199 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 4200 | } |
| 4201 | } |
| 4202 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4203 | /** |
| 4204 | * @hide |
| 4205 | */ |
| 4206 | public RemoteViews makeBigContentView() { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4207 | // Remove the content text so it disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4208 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4209 | CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT); |
| 4210 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4211 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4212 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource()); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 4213 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4214 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4215 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4216 | 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] | 4217 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4218 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 4219 | // Make sure all rows are gone in case we reuse a view. |
| 4220 | for (int rowId : rowIds) { |
| 4221 | contentView.setViewVisibility(rowId, View.GONE); |
| 4222 | } |
| 4223 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4224 | final boolean largeText = |
| 4225 | mBuilder.mContext.getResources().getConfiguration().fontScale > 1f; |
| 4226 | final float subTextSize = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4227 | R.dimen.notification_subtext_size); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4228 | int i=0; |
Selim Cinek | 9d9fc6e | 2015-11-12 15:49:14 -0500 | [diff] [blame] | 4229 | final float density = mBuilder.mContext.getResources().getDisplayMetrics().density; |
| 4230 | int topPadding = (int) (5 * density); |
Selim Cinek | c0fac72 | 2016-03-07 19:57:06 -0800 | [diff] [blame] | 4231 | int bottomPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4232 | com.android.internal.R.dimen.notification_content_margin_bottom); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4233 | boolean first = true; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4234 | while (i < mTexts.size() && i < rowIds.length) { |
| 4235 | CharSequence str = mTexts.get(i); |
| 4236 | if (str != null && !str.equals("")) { |
| 4237 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4238 | contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4239 | if (largeText) { |
| 4240 | contentView.setTextViewTextSize(rowIds[i], TypedValue.COMPLEX_UNIT_PX, |
| 4241 | subTextSize); |
| 4242 | } |
Selim Cinek | 9d9fc6e | 2015-11-12 15:49:14 -0500 | [diff] [blame] | 4243 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, |
| 4244 | i == rowIds.length - 1 || i == mTexts.size() - 1 ? bottomPadding : 0); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4245 | handleInboxImageMargin(contentView, rowIds[i], first); |
| 4246 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4247 | } |
| 4248 | i++; |
| 4249 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4250 | |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4251 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4252 | return contentView; |
| 4253 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4254 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4255 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4256 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4257 | if (first) { |
| 4258 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4259 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 4260 | boolean hasProgress = max != 0 || ind; |
| 4261 | if (mBuilder.mN.mLargeIcon != null && !hasProgress) { |
| 4262 | endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4263 | R.dimen.notification_content_picture_margin); |
| 4264 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 4265 | } |
| 4266 | contentView.setViewLayoutMarginEnd(id, endMargin); |
| 4267 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4268 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4269 | |
| 4270 | /** |
| 4271 | * Notification style for media playback notifications. |
| 4272 | * |
| 4273 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 4274 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4275 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4276 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 4277 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 4278 | * treated as album artwork. |
| 4279 | * |
| 4280 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 4281 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 4282 | * {@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] | 4283 | * in the standard view alongside the usual content. |
| 4284 | * |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4285 | * Notifications created with MediaStyle will have their category set to |
| 4286 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 4287 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
| 4288 | * |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4289 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 4290 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4291 | * the System UI can identify this as a notification representing an active media session |
| 4292 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 4293 | * |
| 4294 | * To use this style with your Notification, feed it to |
| 4295 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 4296 | * <pre class="prettyprint"> |
| 4297 | * Notification noti = new Notification.Builder() |
| 4298 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 4299 | * .setContentTitle("Track title") |
| 4300 | * .setContentText("Artist - Album") |
| 4301 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4302 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 4303 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4304 | * .build(); |
| 4305 | * </pre> |
| 4306 | * |
| 4307 | * @see Notification#bigContentView |
| 4308 | */ |
| 4309 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4310 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4311 | static final int MAX_MEDIA_BUTTONS = 5; |
| 4312 | |
| 4313 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4314 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4315 | |
| 4316 | public MediaStyle() { |
| 4317 | } |
| 4318 | |
| 4319 | public MediaStyle(Builder builder) { |
| 4320 | setBuilder(builder); |
| 4321 | } |
| 4322 | |
| 4323 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4324 | * 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] | 4325 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4326 | * |
| 4327 | * @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] | 4328 | */ |
| 4329 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 4330 | mActionsToShowInCompact = actions; |
| 4331 | return this; |
| 4332 | } |
| 4333 | |
| 4334 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4335 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 4336 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4337 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4338 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4339 | mToken = token; |
| 4340 | return this; |
| 4341 | } |
| 4342 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4343 | /** |
| 4344 | * @hide |
| 4345 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4346 | @Override |
| 4347 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4348 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4349 | if (wip.category == null) { |
| 4350 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 4351 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4352 | return wip; |
| 4353 | } |
| 4354 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4355 | /** |
| 4356 | * @hide |
| 4357 | */ |
| 4358 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4359 | public RemoteViews makeContentView() { |
| 4360 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | /** |
| 4364 | * @hide |
| 4365 | */ |
| 4366 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4367 | public RemoteViews makeBigContentView() { |
| 4368 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4369 | } |
| 4370 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4371 | /** |
| 4372 | * @hide |
| 4373 | */ |
| 4374 | @Override |
| 4375 | public RemoteViews makeHeadsUpContentView() { |
| 4376 | RemoteViews expanded = makeMediaBigContentView(); |
| 4377 | return expanded != null ? expanded : makeMediaContentView(); |
| 4378 | } |
| 4379 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4380 | /** @hide */ |
| 4381 | @Override |
| 4382 | public void addExtras(Bundle extras) { |
| 4383 | super.addExtras(extras); |
| 4384 | |
| 4385 | if (mToken != null) { |
| 4386 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 4387 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 4388 | if (mActionsToShowInCompact != null) { |
| 4389 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 4390 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4391 | } |
| 4392 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4393 | /** |
| 4394 | * @hide |
| 4395 | */ |
| 4396 | @Override |
| 4397 | protected void restoreFromExtras(Bundle extras) { |
| 4398 | super.restoreFromExtras(extras); |
| 4399 | |
| 4400 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 4401 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 4402 | } |
| 4403 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 4404 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 4405 | } |
| 4406 | } |
| 4407 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4408 | private RemoteViews generateMediaActionButton(Action action, int color) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4409 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 4410 | RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4411 | R.layout.notification_material_media_action); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 4412 | button.setImageViewIcon(R.id.action0, action.getIcon()); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4413 | button.setDrawableParameters(R.id.action0, false, -1, color, PorterDuff.Mode.SRC_ATOP, |
| 4414 | -1); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4415 | if (!tombstone) { |
| 4416 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 4417 | } |
| 4418 | button.setContentDescription(R.id.action0, action.title); |
| 4419 | return button; |
| 4420 | } |
| 4421 | |
| 4422 | private RemoteViews makeMediaContentView() { |
| 4423 | RemoteViews view = mBuilder.applyStandardTemplate( |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4424 | R.layout.notification_template_material_media, false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4425 | |
| 4426 | final int numActions = mBuilder.mActions.size(); |
| 4427 | final int N = mActionsToShowInCompact == null |
| 4428 | ? 0 |
| 4429 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 4430 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4431 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4432 | for (int i = 0; i < N; i++) { |
| 4433 | if (i >= numActions) { |
| 4434 | throw new IllegalArgumentException(String.format( |
| 4435 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 4436 | i, numActions - 1)); |
| 4437 | } |
| 4438 | |
| 4439 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4440 | final RemoteViews button = generateMediaActionButton(action, |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4441 | mBuilder.resolveContrastColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4442 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4443 | } |
| 4444 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 4445 | handleImage(view); |
| 4446 | // handle the content margin |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4447 | int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4448 | R.dimen.notification_content_margin_end);; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 4449 | if (mBuilder.mN.mLargeIcon != null) { |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4450 | endMargin += mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4451 | R.dimen.notification_content_picture_margin); |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 4452 | } |
| 4453 | view.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4454 | return view; |
| 4455 | } |
| 4456 | |
| 4457 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4458 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4459 | // Dont add an expanded view if there is no more content to be revealed |
| 4460 | int actionsInCompact = mActionsToShowInCompact == null |
| 4461 | ? 0 |
| 4462 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 4463 | if (mBuilder.mN.mLargeIcon == null && actionCount <= actionsInCompact) { |
| 4464 | return null; |
| 4465 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4466 | RemoteViews big = mBuilder.applyStandardTemplate( |
| 4467 | R.layout.notification_template_material_big_media, |
| 4468 | false); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4469 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4470 | if (actionCount > 0) { |
| 4471 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 4472 | for (int i = 0; i < actionCount; i++) { |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4473 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i), |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4474 | mBuilder.resolveContrastColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4475 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4476 | } |
| 4477 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4478 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4479 | return big; |
| 4480 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4481 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 4482 | private void handleImage(RemoteViews contentView) { |
| 4483 | if (mBuilder.mN.mLargeIcon != null) { |
| 4484 | contentView.setViewLayoutMarginEnd(R.id.line1, 0); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4485 | contentView.setViewLayoutMarginEnd(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4486 | } |
| 4487 | } |
| 4488 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4489 | /** |
| 4490 | * @hide |
| 4491 | */ |
| 4492 | @Override |
| 4493 | protected boolean hasProgress() { |
| 4494 | return false; |
| 4495 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4496 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4497 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4498 | /** |
| 4499 | * Notification style for custom views that are decorated by the system |
| 4500 | * |
| 4501 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 4502 | * style and still obtain system decorations like the notification header with the expand |
| 4503 | * affordance and actions. |
| 4504 | * |
| 4505 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 4506 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 4507 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 4508 | * corresponding custom views to display. |
| 4509 | * |
| 4510 | * To use this style with your Notification, feed it to |
| 4511 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 4512 | * <pre class="prettyprint"> |
| 4513 | * Notification noti = new Notification.Builder() |
| 4514 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 4515 | * .setLargeIcon(albumArtBitmap)) |
| 4516 | * .setCustomContentView(contentView); |
| 4517 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 4518 | * .build(); |
| 4519 | * </pre> |
| 4520 | */ |
| 4521 | public static class DecoratedCustomViewStyle extends Style { |
| 4522 | |
| 4523 | public DecoratedCustomViewStyle() { |
| 4524 | } |
| 4525 | |
| 4526 | public DecoratedCustomViewStyle(Builder builder) { |
| 4527 | setBuilder(builder); |
| 4528 | } |
| 4529 | |
| 4530 | /** |
| 4531 | * @hide |
| 4532 | */ |
| 4533 | public boolean displayCustomViewInline() { |
| 4534 | return true; |
| 4535 | } |
| 4536 | |
| 4537 | /** |
| 4538 | * @hide |
| 4539 | */ |
| 4540 | @Override |
| 4541 | public RemoteViews makeContentView() { |
| 4542 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 4543 | } |
| 4544 | |
| 4545 | /** |
| 4546 | * @hide |
| 4547 | */ |
| 4548 | @Override |
| 4549 | public RemoteViews makeBigContentView() { |
| 4550 | return makeDecoratedBigContentView(); |
| 4551 | } |
| 4552 | |
| 4553 | /** |
| 4554 | * @hide |
| 4555 | */ |
| 4556 | @Override |
| 4557 | public RemoteViews makeHeadsUpContentView() { |
| 4558 | return makeDecoratedHeadsUpContentView(); |
| 4559 | } |
| 4560 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4561 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 4562 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 4563 | ? mBuilder.mN.contentView |
| 4564 | : mBuilder.mN.headsUpContentView; |
| 4565 | if (mBuilder.mActions.size() == 0) { |
| 4566 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 4567 | } |
| 4568 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 4569 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4570 | buildIntoRemoteViewContent(remoteViews, headsUpContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4571 | return remoteViews; |
| 4572 | } |
| 4573 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4574 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
| 4575 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
| 4576 | mBuilder.getBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4577 | buildIntoRemoteViewContent(remoteViews, customContent); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4578 | return remoteViews; |
| 4579 | } |
| 4580 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4581 | private RemoteViews makeDecoratedBigContentView() { |
| 4582 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 4583 | ? mBuilder.mN.contentView |
| 4584 | : mBuilder.mN.bigContentView; |
| 4585 | if (mBuilder.mActions.size() == 0) { |
| 4586 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 4587 | } |
| 4588 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 4589 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4590 | buildIntoRemoteViewContent(remoteViews, bigContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4591 | return remoteViews; |
| 4592 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4593 | |
| 4594 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
| 4595 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4596 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 4597 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 4598 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4599 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 4600 | remoteViews.removeAllViews(R.id.notification_main_column); |
| 4601 | remoteViews.addView(R.id.notification_main_column, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4602 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4603 | // also update the end margin if there is an image |
| 4604 | int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4605 | R.dimen.notification_content_margin_end); |
| 4606 | if (mBuilder.mN.mLargeIcon != null) { |
| 4607 | endMargin += mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4608 | R.dimen.notification_content_picture_margin); |
| 4609 | } |
| 4610 | remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
| 4611 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4612 | } |
| 4613 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 4614 | /** |
| 4615 | * Notification style for media custom views that are decorated by the system |
| 4616 | * |
| 4617 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 4618 | * this style and still obtain system decorations like the notification header with the expand |
| 4619 | * affordance and actions. |
| 4620 | * |
| 4621 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 4622 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 4623 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 4624 | * corresponding custom views to display. |
| 4625 | * |
| 4626 | * To use this style with your Notification, feed it to |
| 4627 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 4628 | * <pre class="prettyprint"> |
| 4629 | * Notification noti = new Notification.Builder() |
| 4630 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 4631 | * .setLargeIcon(albumArtBitmap)) |
| 4632 | * .setCustomContentView(contentView); |
| 4633 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 4634 | * .setMediaSession(mySession)) |
| 4635 | * .build(); |
| 4636 | * </pre> |
| 4637 | * |
| 4638 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 4639 | * @see android.app.Notification.MediaStyle |
| 4640 | */ |
| 4641 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 4642 | |
| 4643 | public DecoratedMediaCustomViewStyle() { |
| 4644 | } |
| 4645 | |
| 4646 | public DecoratedMediaCustomViewStyle(Builder builder) { |
| 4647 | setBuilder(builder); |
| 4648 | } |
| 4649 | |
| 4650 | /** |
| 4651 | * @hide |
| 4652 | */ |
| 4653 | public boolean displayCustomViewInline() { |
| 4654 | return true; |
| 4655 | } |
| 4656 | |
| 4657 | /** |
| 4658 | * @hide |
| 4659 | */ |
| 4660 | @Override |
| 4661 | public RemoteViews makeContentView() { |
| 4662 | RemoteViews remoteViews = super.makeContentView(); |
| 4663 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 4664 | mBuilder.mN.contentView); |
| 4665 | } |
| 4666 | |
| 4667 | /** |
| 4668 | * @hide |
| 4669 | */ |
| 4670 | @Override |
| 4671 | public RemoteViews makeBigContentView() { |
| 4672 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 4673 | ? mBuilder.mN.bigContentView |
| 4674 | : mBuilder.mN.contentView; |
| 4675 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 4676 | } |
| 4677 | |
| 4678 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 4679 | RemoteViews remoteViews = super.makeBigContentView(); |
| 4680 | if (remoteViews != null) { |
| 4681 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 4682 | customRemoteView); |
| 4683 | } else if (customRemoteView != mBuilder.mN.contentView){ |
| 4684 | remoteViews = super.makeContentView(); |
| 4685 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 4686 | customRemoteView); |
| 4687 | } else { |
| 4688 | return null; |
| 4689 | } |
| 4690 | } |
| 4691 | |
| 4692 | /** |
| 4693 | * @hide |
| 4694 | */ |
| 4695 | @Override |
| 4696 | public RemoteViews makeHeadsUpContentView() { |
| 4697 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 4698 | ? mBuilder.mN.headsUpContentView |
| 4699 | : mBuilder.mN.contentView; |
| 4700 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 4701 | } |
| 4702 | |
| 4703 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 4704 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4705 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 4706 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 4707 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4708 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 4709 | remoteViews.removeAllViews(id); |
| 4710 | remoteViews.addView(id, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4711 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 4712 | return remoteViews; |
| 4713 | } |
| 4714 | } |
| 4715 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4716 | // When adding a new Style subclass here, don't forget to update |
| 4717 | // Builder.getNotificationStyleClass. |
| 4718 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4719 | /** |
| 4720 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 4721 | * metadata or change options on a notification builder. |
| 4722 | */ |
| 4723 | public interface Extender { |
| 4724 | /** |
| 4725 | * Apply this extender to a notification builder. |
| 4726 | * @param builder the builder to be modified. |
| 4727 | * @return the build object for chaining. |
| 4728 | */ |
| 4729 | public Builder extend(Builder builder); |
| 4730 | } |
| 4731 | |
| 4732 | /** |
| 4733 | * Helper class to add wearable extensions to notifications. |
| 4734 | * <p class="note"> See |
| 4735 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 4736 | * for Android Wear</a> for more information on how to use this class. |
| 4737 | * <p> |
| 4738 | * To create a notification with wearable extensions: |
| 4739 | * <ol> |
| 4740 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 4741 | * properties. |
| 4742 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 4743 | * <li>Set wearable-specific properties using the |
| 4744 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 4745 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 4746 | * notification. |
| 4747 | * <li>Post the notification to the notification system with the |
| 4748 | * {@code NotificationManager.notify(...)} methods. |
| 4749 | * </ol> |
| 4750 | * |
| 4751 | * <pre class="prettyprint"> |
| 4752 | * Notification notif = new Notification.Builder(mContext) |
| 4753 | * .setContentTitle("New mail from " + sender.toString()) |
| 4754 | * .setContentText(subject) |
| 4755 | * .setSmallIcon(R.drawable.new_mail) |
| 4756 | * .extend(new Notification.WearableExtender() |
| 4757 | * .setContentIcon(R.drawable.new_mail)) |
| 4758 | * .build(); |
| 4759 | * NotificationManager notificationManger = |
| 4760 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 4761 | * notificationManger.notify(0, notif);</pre> |
| 4762 | * |
| 4763 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 4764 | * {@code WearableExtender(Notification)} constructor, |
| 4765 | * and then using the {@code get} methods to access values. |
| 4766 | * |
| 4767 | * <pre class="prettyprint"> |
| 4768 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 4769 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 4770 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4771 | */ |
| 4772 | public static final class WearableExtender implements Extender { |
| 4773 | /** |
| 4774 | * Sentinel value for an action index that is unset. |
| 4775 | */ |
| 4776 | public static final int UNSET_ACTION_INDEX = -1; |
| 4777 | |
| 4778 | /** |
| 4779 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 4780 | * default sizing. |
| 4781 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 4782 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4783 | * on their content. |
| 4784 | */ |
| 4785 | public static final int SIZE_DEFAULT = 0; |
| 4786 | |
| 4787 | /** |
| 4788 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4789 | * with an extra small size. |
| 4790 | * <p>This value is only applicable for custom display notifications created using |
| 4791 | * {@link #setDisplayIntent}. |
| 4792 | */ |
| 4793 | public static final int SIZE_XSMALL = 1; |
| 4794 | |
| 4795 | /** |
| 4796 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4797 | * with a small size. |
| 4798 | * <p>This value is only applicable for custom display notifications created using |
| 4799 | * {@link #setDisplayIntent}. |
| 4800 | */ |
| 4801 | public static final int SIZE_SMALL = 2; |
| 4802 | |
| 4803 | /** |
| 4804 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4805 | * with a medium size. |
| 4806 | * <p>This value is only applicable for custom display notifications created using |
| 4807 | * {@link #setDisplayIntent}. |
| 4808 | */ |
| 4809 | public static final int SIZE_MEDIUM = 3; |
| 4810 | |
| 4811 | /** |
| 4812 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4813 | * with a large size. |
| 4814 | * <p>This value is only applicable for custom display notifications created using |
| 4815 | * {@link #setDisplayIntent}. |
| 4816 | */ |
| 4817 | public static final int SIZE_LARGE = 4; |
| 4818 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 4819 | /** |
| 4820 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4821 | * full screen. |
| 4822 | * <p>This value is only applicable for custom display notifications created using |
| 4823 | * {@link #setDisplayIntent}. |
| 4824 | */ |
| 4825 | public static final int SIZE_FULL_SCREEN = 5; |
| 4826 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4827 | /** |
| 4828 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 4829 | * short amount of time when this notification is displayed on the screen. This |
| 4830 | * is the default value. |
| 4831 | */ |
| 4832 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 4833 | |
| 4834 | /** |
| 4835 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 4836 | * for a longer amount of time when this notification is displayed on the screen. |
| 4837 | */ |
| 4838 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 4839 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4840 | /** Notification extra which contains wearable extensions */ |
| 4841 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 4842 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 4843 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4844 | private static final String KEY_ACTIONS = "actions"; |
| 4845 | private static final String KEY_FLAGS = "flags"; |
| 4846 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 4847 | private static final String KEY_PAGES = "pages"; |
| 4848 | private static final String KEY_BACKGROUND = "background"; |
| 4849 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 4850 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 4851 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 4852 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 4853 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 4854 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4855 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4856 | |
| 4857 | // Flags bitwise-ored to mFlags |
| 4858 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 4859 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 4860 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 4861 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4862 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4863 | |
| 4864 | // Default value for flags integer |
| 4865 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 4866 | |
| 4867 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 4868 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 4869 | |
| 4870 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 4871 | private int mFlags = DEFAULT_FLAGS; |
| 4872 | private PendingIntent mDisplayIntent; |
| 4873 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 4874 | private Bitmap mBackground; |
| 4875 | private int mContentIcon; |
| 4876 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 4877 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 4878 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 4879 | private int mCustomContentHeight; |
| 4880 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4881 | private int mHintScreenTimeout; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4882 | |
| 4883 | /** |
| 4884 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 4885 | * options. |
| 4886 | */ |
| 4887 | public WearableExtender() { |
| 4888 | } |
| 4889 | |
| 4890 | public WearableExtender(Notification notif) { |
| 4891 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 4892 | if (wearableBundle != null) { |
| 4893 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 4894 | if (actions != null) { |
| 4895 | mActions.addAll(actions); |
| 4896 | } |
| 4897 | |
| 4898 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 4899 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 4900 | |
| 4901 | Notification[] pages = getNotificationArrayFromBundle( |
| 4902 | wearableBundle, KEY_PAGES); |
| 4903 | if (pages != null) { |
| 4904 | Collections.addAll(mPages, pages); |
| 4905 | } |
| 4906 | |
| 4907 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 4908 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 4909 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 4910 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 4911 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 4912 | UNSET_ACTION_INDEX); |
| 4913 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 4914 | SIZE_DEFAULT); |
| 4915 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 4916 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4917 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4918 | } |
| 4919 | } |
| 4920 | |
| 4921 | /** |
| 4922 | * Apply wearable extensions to a notification that is being built. This is typically |
| 4923 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 4924 | * {@link android.app.Notification.Builder}. |
| 4925 | */ |
| 4926 | @Override |
| 4927 | public Notification.Builder extend(Notification.Builder builder) { |
| 4928 | Bundle wearableBundle = new Bundle(); |
| 4929 | |
| 4930 | if (!mActions.isEmpty()) { |
| 4931 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 4932 | } |
| 4933 | if (mFlags != DEFAULT_FLAGS) { |
| 4934 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 4935 | } |
| 4936 | if (mDisplayIntent != null) { |
| 4937 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 4938 | } |
| 4939 | if (!mPages.isEmpty()) { |
| 4940 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 4941 | new Notification[mPages.size()])); |
| 4942 | } |
| 4943 | if (mBackground != null) { |
| 4944 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 4945 | } |
| 4946 | if (mContentIcon != 0) { |
| 4947 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 4948 | } |
| 4949 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 4950 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 4951 | } |
| 4952 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 4953 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 4954 | mContentActionIndex); |
| 4955 | } |
| 4956 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 4957 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 4958 | } |
| 4959 | if (mCustomContentHeight != 0) { |
| 4960 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 4961 | } |
| 4962 | if (mGravity != DEFAULT_GRAVITY) { |
| 4963 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 4964 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4965 | if (mHintScreenTimeout != 0) { |
| 4966 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 4967 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4968 | |
| 4969 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 4970 | return builder; |
| 4971 | } |
| 4972 | |
| 4973 | @Override |
| 4974 | public WearableExtender clone() { |
| 4975 | WearableExtender that = new WearableExtender(); |
| 4976 | that.mActions = new ArrayList<Action>(this.mActions); |
| 4977 | that.mFlags = this.mFlags; |
| 4978 | that.mDisplayIntent = this.mDisplayIntent; |
| 4979 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 4980 | that.mBackground = this.mBackground; |
| 4981 | that.mContentIcon = this.mContentIcon; |
| 4982 | that.mContentIconGravity = this.mContentIconGravity; |
| 4983 | that.mContentActionIndex = this.mContentActionIndex; |
| 4984 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 4985 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 4986 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4987 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4988 | return that; |
| 4989 | } |
| 4990 | |
| 4991 | /** |
| 4992 | * Add a wearable action to this notification. |
| 4993 | * |
| 4994 | * <p>When wearable actions are added using this method, the set of actions that |
| 4995 | * show on a wearable device splits from devices that only show actions added |
| 4996 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 4997 | * of which actions display on different devices. |
| 4998 | * |
| 4999 | * @param action the action to add to this notification |
| 5000 | * @return this object for method chaining |
| 5001 | * @see android.app.Notification.Action |
| 5002 | */ |
| 5003 | public WearableExtender addAction(Action action) { |
| 5004 | mActions.add(action); |
| 5005 | return this; |
| 5006 | } |
| 5007 | |
| 5008 | /** |
| 5009 | * Adds wearable actions to this notification. |
| 5010 | * |
| 5011 | * <p>When wearable actions are added using this method, the set of actions that |
| 5012 | * show on a wearable device splits from devices that only show actions added |
| 5013 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 5014 | * of which actions display on different devices. |
| 5015 | * |
| 5016 | * @param actions the actions to add to this notification |
| 5017 | * @return this object for method chaining |
| 5018 | * @see android.app.Notification.Action |
| 5019 | */ |
| 5020 | public WearableExtender addActions(List<Action> actions) { |
| 5021 | mActions.addAll(actions); |
| 5022 | return this; |
| 5023 | } |
| 5024 | |
| 5025 | /** |
| 5026 | * Clear all wearable actions present on this builder. |
| 5027 | * @return this object for method chaining. |
| 5028 | * @see #addAction |
| 5029 | */ |
| 5030 | public WearableExtender clearActions() { |
| 5031 | mActions.clear(); |
| 5032 | return this; |
| 5033 | } |
| 5034 | |
| 5035 | /** |
| 5036 | * Get the wearable actions present on this notification. |
| 5037 | */ |
| 5038 | public List<Action> getActions() { |
| 5039 | return mActions; |
| 5040 | } |
| 5041 | |
| 5042 | /** |
| 5043 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5044 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 5045 | * |
| 5046 | * <pre class="prettyprint"> |
| 5047 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 5048 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 5049 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 5050 | * Notification notif = new Notification.Builder(context) |
| 5051 | * .extend(new Notification.WearableExtender() |
| 5052 | * .setDisplayIntent(displayPendingIntent) |
| 5053 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 5054 | * .build();</pre> |
| 5055 | * |
| 5056 | * <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] | 5057 | * should have an empty task affinity. It is also recommended to use the device |
| 5058 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 5059 | * |
| 5060 | * <p>Example AndroidManifest.xml entry: |
| 5061 | * <pre class="prettyprint"> |
| 5062 | * <activity android:name="com.example.MyDisplayActivity" |
| 5063 | * android:exported="true" |
| 5064 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 5065 | * android:taskAffinity="" |
| 5066 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5067 | * |
| 5068 | * @param intent the {@link PendingIntent} for an activity |
| 5069 | * @return this object for method chaining |
| 5070 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 5071 | */ |
| 5072 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 5073 | mDisplayIntent = intent; |
| 5074 | return this; |
| 5075 | } |
| 5076 | |
| 5077 | /** |
| 5078 | * Get the intent to launch inside of an activity view when displaying this |
| 5079 | * notification. This {@code PendingIntent} should be for an activity. |
| 5080 | */ |
| 5081 | public PendingIntent getDisplayIntent() { |
| 5082 | return mDisplayIntent; |
| 5083 | } |
| 5084 | |
| 5085 | /** |
| 5086 | * Add an additional page of content to display with this notification. The current |
| 5087 | * notification forms the first page, and pages added using this function form |
| 5088 | * subsequent pages. This field can be used to separate a notification into multiple |
| 5089 | * sections. |
| 5090 | * |
| 5091 | * @param page the notification to add as another page |
| 5092 | * @return this object for method chaining |
| 5093 | * @see android.app.Notification.WearableExtender#getPages |
| 5094 | */ |
| 5095 | public WearableExtender addPage(Notification page) { |
| 5096 | mPages.add(page); |
| 5097 | return this; |
| 5098 | } |
| 5099 | |
| 5100 | /** |
| 5101 | * Add additional pages of content to display with this notification. The current |
| 5102 | * notification forms the first page, and pages added using this function form |
| 5103 | * subsequent pages. This field can be used to separate a notification into multiple |
| 5104 | * sections. |
| 5105 | * |
| 5106 | * @param pages a list of notifications |
| 5107 | * @return this object for method chaining |
| 5108 | * @see android.app.Notification.WearableExtender#getPages |
| 5109 | */ |
| 5110 | public WearableExtender addPages(List<Notification> pages) { |
| 5111 | mPages.addAll(pages); |
| 5112 | return this; |
| 5113 | } |
| 5114 | |
| 5115 | /** |
| 5116 | * Clear all additional pages present on this builder. |
| 5117 | * @return this object for method chaining. |
| 5118 | * @see #addPage |
| 5119 | */ |
| 5120 | public WearableExtender clearPages() { |
| 5121 | mPages.clear(); |
| 5122 | return this; |
| 5123 | } |
| 5124 | |
| 5125 | /** |
| 5126 | * Get the array of additional pages of content for displaying this notification. The |
| 5127 | * current notification forms the first page, and elements within this array form |
| 5128 | * subsequent pages. This field can be used to separate a notification into multiple |
| 5129 | * sections. |
| 5130 | * @return the pages for this notification |
| 5131 | */ |
| 5132 | public List<Notification> getPages() { |
| 5133 | return mPages; |
| 5134 | } |
| 5135 | |
| 5136 | /** |
| 5137 | * Set a background image to be displayed behind the notification content. |
| 5138 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 5139 | * will work with any notification style. |
| 5140 | * |
| 5141 | * @param background the background bitmap |
| 5142 | * @return this object for method chaining |
| 5143 | * @see android.app.Notification.WearableExtender#getBackground |
| 5144 | */ |
| 5145 | public WearableExtender setBackground(Bitmap background) { |
| 5146 | mBackground = background; |
| 5147 | return this; |
| 5148 | } |
| 5149 | |
| 5150 | /** |
| 5151 | * Get a background image to be displayed behind the notification content. |
| 5152 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 5153 | * will work with any notification style. |
| 5154 | * |
| 5155 | * @return the background image |
| 5156 | * @see android.app.Notification.WearableExtender#setBackground |
| 5157 | */ |
| 5158 | public Bitmap getBackground() { |
| 5159 | return mBackground; |
| 5160 | } |
| 5161 | |
| 5162 | /** |
| 5163 | * Set an icon that goes with the content of this notification. |
| 5164 | */ |
| 5165 | public WearableExtender setContentIcon(int icon) { |
| 5166 | mContentIcon = icon; |
| 5167 | return this; |
| 5168 | } |
| 5169 | |
| 5170 | /** |
| 5171 | * Get an icon that goes with the content of this notification. |
| 5172 | */ |
| 5173 | public int getContentIcon() { |
| 5174 | return mContentIcon; |
| 5175 | } |
| 5176 | |
| 5177 | /** |
| 5178 | * Set the gravity that the content icon should have within the notification display. |
| 5179 | * Supported values include {@link android.view.Gravity#START} and |
| 5180 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 5181 | * @see #setContentIcon |
| 5182 | */ |
| 5183 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 5184 | mContentIconGravity = contentIconGravity; |
| 5185 | return this; |
| 5186 | } |
| 5187 | |
| 5188 | /** |
| 5189 | * Get the gravity that the content icon should have within the notification display. |
| 5190 | * Supported values include {@link android.view.Gravity#START} and |
| 5191 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 5192 | * @see #getContentIcon |
| 5193 | */ |
| 5194 | public int getContentIconGravity() { |
| 5195 | return mContentIconGravity; |
| 5196 | } |
| 5197 | |
| 5198 | /** |
| 5199 | * 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] | 5200 | * this notification. This action will no longer display separately from the |
| 5201 | * notification's content. |
| 5202 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 5203 | * <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] | 5204 | * set, although the list of available actions comes from the main notification and not |
| 5205 | * from the child page's notification. |
| 5206 | * |
| 5207 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 5208 | * If wearable actions were added to the main notification, this index |
| 5209 | * will apply to that list, otherwise it will apply to the regular |
| 5210 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5211 | */ |
| 5212 | public WearableExtender setContentAction(int actionIndex) { |
| 5213 | mContentActionIndex = actionIndex; |
| 5214 | return this; |
| 5215 | } |
| 5216 | |
| 5217 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 5218 | * Get the index of the notification action, if any, that was specified as being clickable |
| 5219 | * 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] | 5220 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5221 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 5222 | * <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] | 5223 | * set, although the list of available actions comes from the main notification and not |
| 5224 | * from the child page's notification. |
| 5225 | * |
| 5226 | * <p>If wearable specific actions were added to the main notification, this index will |
| 5227 | * 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] | 5228 | * |
| 5229 | * @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] | 5230 | */ |
| 5231 | public int getContentAction() { |
| 5232 | return mContentActionIndex; |
| 5233 | } |
| 5234 | |
| 5235 | /** |
| 5236 | * Set the gravity that this notification should have within the available viewport space. |
| 5237 | * Supported values include {@link android.view.Gravity#TOP}, |
| 5238 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 5239 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 5240 | */ |
| 5241 | public WearableExtender setGravity(int gravity) { |
| 5242 | mGravity = gravity; |
| 5243 | return this; |
| 5244 | } |
| 5245 | |
| 5246 | /** |
| 5247 | * Get the gravity that this notification should have within the available viewport space. |
| 5248 | * Supported values include {@link android.view.Gravity#TOP}, |
| 5249 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 5250 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 5251 | */ |
| 5252 | public int getGravity() { |
| 5253 | return mGravity; |
| 5254 | } |
| 5255 | |
| 5256 | /** |
| 5257 | * Set the custom size preset for the display of this notification out of the available |
| 5258 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 5259 | * {@link #SIZE_LARGE}. |
| 5260 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 5261 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 5262 | * documentation for the preset in question. See also |
| 5263 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 5264 | */ |
| 5265 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 5266 | mCustomSizePreset = sizePreset; |
| 5267 | return this; |
| 5268 | } |
| 5269 | |
| 5270 | /** |
| 5271 | * Get the custom size preset for the display of this notification out of the available |
| 5272 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 5273 | * {@link #SIZE_LARGE}. |
| 5274 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 5275 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 5276 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 5277 | */ |
| 5278 | public int getCustomSizePreset() { |
| 5279 | return mCustomSizePreset; |
| 5280 | } |
| 5281 | |
| 5282 | /** |
| 5283 | * Set the custom height in pixels for the display of this notification's content. |
| 5284 | * <p>This option is only available for custom display notifications created |
| 5285 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 5286 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 5287 | * {@link #getCustomContentHeight}. |
| 5288 | */ |
| 5289 | public WearableExtender setCustomContentHeight(int height) { |
| 5290 | mCustomContentHeight = height; |
| 5291 | return this; |
| 5292 | } |
| 5293 | |
| 5294 | /** |
| 5295 | * Get the custom height in pixels for the display of this notification's content. |
| 5296 | * <p>This option is only available for custom display notifications created |
| 5297 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 5298 | * {@link #setCustomContentHeight}. |
| 5299 | */ |
| 5300 | public int getCustomContentHeight() { |
| 5301 | return mCustomContentHeight; |
| 5302 | } |
| 5303 | |
| 5304 | /** |
| 5305 | * Set whether the scrolling position for the contents of this notification should start |
| 5306 | * at the bottom of the contents instead of the top when the contents are too long to |
| 5307 | * display within the screen. Default is false (start scroll at the top). |
| 5308 | */ |
| 5309 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 5310 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 5311 | return this; |
| 5312 | } |
| 5313 | |
| 5314 | /** |
| 5315 | * Get whether the scrolling position for the contents of this notification should start |
| 5316 | * at the bottom of the contents instead of the top when the contents are too long to |
| 5317 | * display within the screen. Default is false (start scroll at the top). |
| 5318 | */ |
| 5319 | public boolean getStartScrollBottom() { |
| 5320 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 5321 | } |
| 5322 | |
| 5323 | /** |
| 5324 | * Set whether the content intent is available when the wearable device is not connected |
| 5325 | * to a companion device. The user can still trigger this intent when the wearable device |
| 5326 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 5327 | * Defaults to true. |
| 5328 | */ |
| 5329 | public WearableExtender setContentIntentAvailableOffline( |
| 5330 | boolean contentIntentAvailableOffline) { |
| 5331 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 5332 | return this; |
| 5333 | } |
| 5334 | |
| 5335 | /** |
| 5336 | * Get whether the content intent is available when the wearable device is not connected |
| 5337 | * to a companion device. The user can still trigger this intent when the wearable device |
| 5338 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 5339 | * Defaults to true. |
| 5340 | */ |
| 5341 | public boolean getContentIntentAvailableOffline() { |
| 5342 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 5343 | } |
| 5344 | |
| 5345 | /** |
| 5346 | * Set a hint that this notification's icon should not be displayed. |
| 5347 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 5348 | * @return this object for method chaining |
| 5349 | */ |
| 5350 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 5351 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 5352 | return this; |
| 5353 | } |
| 5354 | |
| 5355 | /** |
| 5356 | * Get a hint that this notification's icon should not be displayed. |
| 5357 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 5358 | * The default value is {@code false} if this was never set. |
| 5359 | */ |
| 5360 | public boolean getHintHideIcon() { |
| 5361 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 5362 | } |
| 5363 | |
| 5364 | /** |
| 5365 | * Set a visual hint that only the background image of this notification should be |
| 5366 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 5367 | * to sub-pages added using {@link #addPage}. |
| 5368 | */ |
| 5369 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 5370 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 5371 | return this; |
| 5372 | } |
| 5373 | |
| 5374 | /** |
| 5375 | * Get a visual hint that only the background image of this notification should be |
| 5376 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 5377 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 5378 | */ |
| 5379 | public boolean getHintShowBackgroundOnly() { |
| 5380 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 5381 | } |
| 5382 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5383 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 5384 | * Set a hint that this notification's background should not be clipped if possible, |
| 5385 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 5386 | * 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] | 5387 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 5388 | * @return this object for method chaining |
| 5389 | */ |
| 5390 | public WearableExtender setHintAvoidBackgroundClipping( |
| 5391 | boolean hintAvoidBackgroundClipping) { |
| 5392 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 5393 | return this; |
| 5394 | } |
| 5395 | |
| 5396 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 5397 | * Get a hint that this notification's background should not be clipped if possible, |
| 5398 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 5399 | * 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] | 5400 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 5401 | * otherwise. The default value is {@code false} if this was never set. |
| 5402 | */ |
| 5403 | public boolean getHintAvoidBackgroundClipping() { |
| 5404 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 5405 | } |
| 5406 | |
| 5407 | /** |
| 5408 | * Set a hint that the screen should remain on for at least this duration when |
| 5409 | * this notification is displayed on the screen. |
| 5410 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 5411 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 5412 | * @return this object for method chaining |
| 5413 | */ |
| 5414 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 5415 | mHintScreenTimeout = timeout; |
| 5416 | return this; |
| 5417 | } |
| 5418 | |
| 5419 | /** |
| 5420 | * Get the duration, in milliseconds, that the screen should remain on for |
| 5421 | * when this notification is displayed. |
| 5422 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 5423 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 5424 | */ |
| 5425 | public int getHintScreenTimeout() { |
| 5426 | return mHintScreenTimeout; |
| 5427 | } |
| 5428 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5429 | private void setFlag(int mask, boolean value) { |
| 5430 | if (value) { |
| 5431 | mFlags |= mask; |
| 5432 | } else { |
| 5433 | mFlags &= ~mask; |
| 5434 | } |
| 5435 | } |
| 5436 | } |
| 5437 | |
| 5438 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5439 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 5440 | * with car extensions: |
| 5441 | * |
| 5442 | * <ol> |
| 5443 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 5444 | * properties. |
| 5445 | * <li>Create a {@link CarExtender}. |
| 5446 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 5447 | * {@link CarExtender}. |
| 5448 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 5449 | * to apply the extensions to a notification. |
| 5450 | * </ol> |
| 5451 | * |
| 5452 | * <pre class="prettyprint"> |
| 5453 | * Notification notification = new Notification.Builder(context) |
| 5454 | * ... |
| 5455 | * .extend(new CarExtender() |
| 5456 | * .set*(...)) |
| 5457 | * .build(); |
| 5458 | * </pre> |
| 5459 | * |
| 5460 | * <p>Car extensions can be accessed on an existing notification by using the |
| 5461 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 5462 | * to access values. |
| 5463 | */ |
| 5464 | public static final class CarExtender implements Extender { |
| 5465 | private static final String TAG = "CarExtender"; |
| 5466 | |
| 5467 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 5468 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 5469 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 5470 | private static final String EXTRA_COLOR = "app_color"; |
| 5471 | |
| 5472 | private Bitmap mLargeIcon; |
| 5473 | private UnreadConversation mUnreadConversation; |
| 5474 | private int mColor = Notification.COLOR_DEFAULT; |
| 5475 | |
| 5476 | /** |
| 5477 | * Create a {@link CarExtender} with default options. |
| 5478 | */ |
| 5479 | public CarExtender() { |
| 5480 | } |
| 5481 | |
| 5482 | /** |
| 5483 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 5484 | * |
| 5485 | * @param notif The notification from which to copy options. |
| 5486 | */ |
| 5487 | public CarExtender(Notification notif) { |
| 5488 | Bundle carBundle = notif.extras == null ? |
| 5489 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 5490 | if (carBundle != null) { |
| 5491 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 5492 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 5493 | |
| 5494 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 5495 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 5496 | } |
| 5497 | } |
| 5498 | |
| 5499 | /** |
| 5500 | * Apply car extensions to a notification that is being built. This is typically called by |
| 5501 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 5502 | * method of {@link Notification.Builder}. |
| 5503 | */ |
| 5504 | @Override |
| 5505 | public Notification.Builder extend(Notification.Builder builder) { |
| 5506 | Bundle carExtensions = new Bundle(); |
| 5507 | |
| 5508 | if (mLargeIcon != null) { |
| 5509 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 5510 | } |
| 5511 | if (mColor != Notification.COLOR_DEFAULT) { |
| 5512 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 5513 | } |
| 5514 | |
| 5515 | if (mUnreadConversation != null) { |
| 5516 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 5517 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 5518 | } |
| 5519 | |
| 5520 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 5521 | return builder; |
| 5522 | } |
| 5523 | |
| 5524 | /** |
| 5525 | * Sets the accent color to use when Android Auto presents the notification. |
| 5526 | * |
| 5527 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 5528 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 5529 | * automotive setting. This method can be used to override the color provided in the |
| 5530 | * notification in such a situation. |
| 5531 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 5532 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5533 | mColor = color; |
| 5534 | return this; |
| 5535 | } |
| 5536 | |
| 5537 | /** |
| 5538 | * Gets the accent color. |
| 5539 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5540 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5541 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 5542 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 5543 | public int getColor() { |
| 5544 | return mColor; |
| 5545 | } |
| 5546 | |
| 5547 | /** |
| 5548 | * Sets the large icon of the car notification. |
| 5549 | * |
| 5550 | * If no large icon is set in the extender, Android Auto will display the icon |
| 5551 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 5552 | * |
| 5553 | * @param largeIcon The large icon to use in the car notification. |
| 5554 | * @return This object for method chaining. |
| 5555 | */ |
| 5556 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 5557 | mLargeIcon = largeIcon; |
| 5558 | return this; |
| 5559 | } |
| 5560 | |
| 5561 | /** |
| 5562 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 5563 | * |
| 5564 | * @return The large icon for the car notification. |
| 5565 | * @see CarExtender#setLargeIcon |
| 5566 | */ |
| 5567 | public Bitmap getLargeIcon() { |
| 5568 | return mLargeIcon; |
| 5569 | } |
| 5570 | |
| 5571 | /** |
| 5572 | * Sets the unread conversation in a message notification. |
| 5573 | * |
| 5574 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 5575 | * @return This object for method chaining. |
| 5576 | */ |
| 5577 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 5578 | mUnreadConversation = unreadConversation; |
| 5579 | return this; |
| 5580 | } |
| 5581 | |
| 5582 | /** |
| 5583 | * Returns the unread conversation conveyed by this notification. |
| 5584 | * @see #setUnreadConversation(UnreadConversation) |
| 5585 | */ |
| 5586 | public UnreadConversation getUnreadConversation() { |
| 5587 | return mUnreadConversation; |
| 5588 | } |
| 5589 | |
| 5590 | /** |
| 5591 | * A class which holds the unread messages from a conversation. |
| 5592 | */ |
| 5593 | public static class UnreadConversation { |
| 5594 | private static final String KEY_AUTHOR = "author"; |
| 5595 | private static final String KEY_TEXT = "text"; |
| 5596 | private static final String KEY_MESSAGES = "messages"; |
| 5597 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 5598 | private static final String KEY_ON_REPLY = "on_reply"; |
| 5599 | private static final String KEY_ON_READ = "on_read"; |
| 5600 | private static final String KEY_PARTICIPANTS = "participants"; |
| 5601 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 5602 | |
| 5603 | private final String[] mMessages; |
| 5604 | private final RemoteInput mRemoteInput; |
| 5605 | private final PendingIntent mReplyPendingIntent; |
| 5606 | private final PendingIntent mReadPendingIntent; |
| 5607 | private final String[] mParticipants; |
| 5608 | private final long mLatestTimestamp; |
| 5609 | |
| 5610 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 5611 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 5612 | String[] participants, long latestTimestamp) { |
| 5613 | mMessages = messages; |
| 5614 | mRemoteInput = remoteInput; |
| 5615 | mReadPendingIntent = readPendingIntent; |
| 5616 | mReplyPendingIntent = replyPendingIntent; |
| 5617 | mParticipants = participants; |
| 5618 | mLatestTimestamp = latestTimestamp; |
| 5619 | } |
| 5620 | |
| 5621 | /** |
| 5622 | * Gets the list of messages conveyed by this notification. |
| 5623 | */ |
| 5624 | public String[] getMessages() { |
| 5625 | return mMessages; |
| 5626 | } |
| 5627 | |
| 5628 | /** |
| 5629 | * Gets the remote input that will be used to convey the response to a message list, or |
| 5630 | * null if no such remote input exists. |
| 5631 | */ |
| 5632 | public RemoteInput getRemoteInput() { |
| 5633 | return mRemoteInput; |
| 5634 | } |
| 5635 | |
| 5636 | /** |
| 5637 | * Gets the pending intent that will be triggered when the user replies to this |
| 5638 | * notification. |
| 5639 | */ |
| 5640 | public PendingIntent getReplyPendingIntent() { |
| 5641 | return mReplyPendingIntent; |
| 5642 | } |
| 5643 | |
| 5644 | /** |
| 5645 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 5646 | * in this object's message list. |
| 5647 | */ |
| 5648 | public PendingIntent getReadPendingIntent() { |
| 5649 | return mReadPendingIntent; |
| 5650 | } |
| 5651 | |
| 5652 | /** |
| 5653 | * Gets the participants in the conversation. |
| 5654 | */ |
| 5655 | public String[] getParticipants() { |
| 5656 | return mParticipants; |
| 5657 | } |
| 5658 | |
| 5659 | /** |
| 5660 | * Gets the firs participant in the conversation. |
| 5661 | */ |
| 5662 | public String getParticipant() { |
| 5663 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 5664 | } |
| 5665 | |
| 5666 | /** |
| 5667 | * Gets the timestamp of the conversation. |
| 5668 | */ |
| 5669 | public long getLatestTimestamp() { |
| 5670 | return mLatestTimestamp; |
| 5671 | } |
| 5672 | |
| 5673 | Bundle getBundleForUnreadConversation() { |
| 5674 | Bundle b = new Bundle(); |
| 5675 | String author = null; |
| 5676 | if (mParticipants != null && mParticipants.length > 1) { |
| 5677 | author = mParticipants[0]; |
| 5678 | } |
| 5679 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 5680 | for (int i = 0; i < messages.length; i++) { |
| 5681 | Bundle m = new Bundle(); |
| 5682 | m.putString(KEY_TEXT, mMessages[i]); |
| 5683 | m.putString(KEY_AUTHOR, author); |
| 5684 | messages[i] = m; |
| 5685 | } |
| 5686 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 5687 | if (mRemoteInput != null) { |
| 5688 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 5689 | } |
| 5690 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 5691 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 5692 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 5693 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 5694 | return b; |
| 5695 | } |
| 5696 | |
| 5697 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 5698 | if (b == null) { |
| 5699 | return null; |
| 5700 | } |
| 5701 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 5702 | String[] messages = null; |
| 5703 | if (parcelableMessages != null) { |
| 5704 | String[] tmp = new String[parcelableMessages.length]; |
| 5705 | boolean success = true; |
| 5706 | for (int i = 0; i < tmp.length; i++) { |
| 5707 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 5708 | success = false; |
| 5709 | break; |
| 5710 | } |
| 5711 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 5712 | if (tmp[i] == null) { |
| 5713 | success = false; |
| 5714 | break; |
| 5715 | } |
| 5716 | } |
| 5717 | if (success) { |
| 5718 | messages = tmp; |
| 5719 | } else { |
| 5720 | return null; |
| 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 5725 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 5726 | |
| 5727 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 5728 | |
| 5729 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 5730 | if (participants == null || participants.length != 1) { |
| 5731 | return null; |
| 5732 | } |
| 5733 | |
| 5734 | return new UnreadConversation(messages, |
| 5735 | remoteInput, |
| 5736 | onReply, |
| 5737 | onRead, |
| 5738 | participants, b.getLong(KEY_TIMESTAMP)); |
| 5739 | } |
| 5740 | }; |
| 5741 | |
| 5742 | /** |
| 5743 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 5744 | */ |
| 5745 | public static class Builder { |
| 5746 | private final List<String> mMessages = new ArrayList<String>(); |
| 5747 | private final String mParticipant; |
| 5748 | private RemoteInput mRemoteInput; |
| 5749 | private PendingIntent mReadPendingIntent; |
| 5750 | private PendingIntent mReplyPendingIntent; |
| 5751 | private long mLatestTimestamp; |
| 5752 | |
| 5753 | /** |
| 5754 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 5755 | * |
| 5756 | * @param name The name of the other participant in the conversation. |
| 5757 | */ |
| 5758 | public Builder(String name) { |
| 5759 | mParticipant = name; |
| 5760 | } |
| 5761 | |
| 5762 | /** |
| 5763 | * Appends a new unread message to the list of messages for this conversation. |
| 5764 | * |
| 5765 | * The messages should be added from oldest to newest. |
| 5766 | * |
| 5767 | * @param message The text of the new unread message. |
| 5768 | * @return This object for method chaining. |
| 5769 | */ |
| 5770 | public Builder addMessage(String message) { |
| 5771 | mMessages.add(message); |
| 5772 | return this; |
| 5773 | } |
| 5774 | |
| 5775 | /** |
| 5776 | * Sets the pending intent and remote input which will convey the reply to this |
| 5777 | * notification. |
| 5778 | * |
| 5779 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 5780 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 5781 | * @return This object for method chaining. |
| 5782 | * |
| 5783 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 5784 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 5785 | */ |
| 5786 | public Builder setReplyAction( |
| 5787 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 5788 | mRemoteInput = remoteInput; |
| 5789 | mReplyPendingIntent = pendingIntent; |
| 5790 | |
| 5791 | return this; |
| 5792 | } |
| 5793 | |
| 5794 | /** |
| 5795 | * Sets the pending intent that will be sent once the messages in this notification |
| 5796 | * are read. |
| 5797 | * |
| 5798 | * @param pendingIntent The pending intent to use. |
| 5799 | * @return This object for method chaining. |
| 5800 | */ |
| 5801 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 5802 | mReadPendingIntent = pendingIntent; |
| 5803 | return this; |
| 5804 | } |
| 5805 | |
| 5806 | /** |
| 5807 | * Sets the timestamp of the most recent message in an unread conversation. |
| 5808 | * |
| 5809 | * If a messaging notification has been posted by your application and has not |
| 5810 | * yet been cancelled, posting a later notification with the same id and tag |
| 5811 | * but without a newer timestamp may result in Android Auto not displaying a |
| 5812 | * heads up notification for the later notification. |
| 5813 | * |
| 5814 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 5815 | * @return This object for method chaining. |
| 5816 | */ |
| 5817 | public Builder setLatestTimestamp(long timestamp) { |
| 5818 | mLatestTimestamp = timestamp; |
| 5819 | return this; |
| 5820 | } |
| 5821 | |
| 5822 | /** |
| 5823 | * Builds a new unread conversation object. |
| 5824 | * |
| 5825 | * @return The new unread conversation object. |
| 5826 | */ |
| 5827 | public UnreadConversation build() { |
| 5828 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 5829 | String[] participants = { mParticipant }; |
| 5830 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 5831 | mReadPendingIntent, participants, mLatestTimestamp); |
| 5832 | } |
| 5833 | } |
| 5834 | } |
| 5835 | |
| 5836 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5837 | * Get an array of Notification objects from a parcelable array bundle field. |
| 5838 | * Update the bundle to have a typed array so fetches in the future don't need |
| 5839 | * to do an array copy. |
| 5840 | */ |
| 5841 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 5842 | Parcelable[] array = bundle.getParcelableArray(key); |
| 5843 | if (array instanceof Notification[] || array == null) { |
| 5844 | return (Notification[]) array; |
| 5845 | } |
| 5846 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 5847 | Notification[].class); |
| 5848 | bundle.putParcelableArray(key, typedArray); |
| 5849 | return typedArray; |
| 5850 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5851 | |
| 5852 | private static class BuilderRemoteViews extends RemoteViews { |
| 5853 | public BuilderRemoteViews(Parcel parcel) { |
| 5854 | super(parcel); |
| 5855 | } |
| 5856 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 5857 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 5858 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | @Override |
| 5862 | public BuilderRemoteViews clone() { |
| 5863 | Parcel p = Parcel.obtain(); |
| 5864 | writeToParcel(p, 0); |
| 5865 | p.setDataPosition(0); |
| 5866 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 5867 | p.recycle(); |
| 5868 | return brv; |
| 5869 | } |
| 5870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5871 | } |