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 | |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 19 | import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast; |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 20 | |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 21 | import android.annotation.ColorInt; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 22 | import android.annotation.DrawableRes; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 23 | import android.annotation.IdRes; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 24 | import android.annotation.IntDef; |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 27 | import android.annotation.RequiresPermission; |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 28 | import android.annotation.SdkConstant; |
| 29 | import android.annotation.SdkConstant.SdkConstantType; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 30 | import android.annotation.SystemApi; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 31 | import android.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 36 | import android.content.pm.PackageManager.NameNotFoundException; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 37 | import android.content.pm.ShortcutInfo; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 38 | import android.content.res.ColorStateList; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 39 | import android.content.res.Configuration; |
| 40 | import android.content.res.Resources; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 41 | import android.content.res.TypedArray; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 42 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 43 | import android.graphics.Canvas; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 44 | import android.graphics.Color; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 45 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 46 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 47 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 48 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 49 | import android.media.AudioManager; |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 50 | import android.media.PlayerBase; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 51 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 53 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 54 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 55 | import android.os.Bundle; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 56 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.os.Parcel; |
| 58 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 59 | import android.os.SystemClock; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 60 | import android.os.SystemProperties; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 61 | import android.os.UserHandle; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 62 | import android.text.BidiFormatter; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 63 | import android.text.SpannableStringBuilder; |
| 64 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 66 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 67 | import android.text.style.CharacterStyle; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 68 | import android.text.style.ForegroundColorSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 69 | import android.text.style.RelativeSizeSpan; |
| 70 | import android.text.style.TextAppearanceSpan; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 71 | import android.util.ArraySet; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 72 | import android.util.Log; |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 73 | import android.util.Pair; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 74 | import android.util.SparseArray; |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 75 | import android.util.proto.ProtoOutputStream; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 76 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 77 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 78 | import android.view.View; |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 79 | import android.view.ViewGroup; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 80 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import android.widget.RemoteViews; |
| 82 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 83 | import com.android.internal.R; |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 84 | import com.android.internal.annotations.VisibleForTesting; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 85 | import com.android.internal.util.ArrayUtils; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 86 | import com.android.internal.util.ContrastColorUtil; |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 87 | import com.android.internal.util.Preconditions; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 88 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 89 | import java.lang.annotation.Retention; |
| 90 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 91 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 92 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 93 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 94 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 95 | import java.util.List; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 96 | import java.util.Objects; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 97 | import java.util.Set; |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 98 | import java.util.function.Consumer; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 99 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | /** |
| 101 | * A class that represents how a persistent notification is to be presented to |
| 102 | * the user using the {@link android.app.NotificationManager}. |
| 103 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 104 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 105 | * easier to construct Notifications.</p> |
| 106 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 107 | * <div class="special reference"> |
| 108 | * <h3>Developer Guides</h3> |
| 109 | * <p>For a guide to creating notifications, read the |
| 110 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 111 | * developer guide.</p> |
| 112 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | */ |
| 114 | public class Notification implements Parcelable |
| 115 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 116 | private static final String TAG = "Notification"; |
| 117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 119 | * An activity that provides a user interface for adjusting notification preferences for its |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 120 | * containing application. |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 121 | */ |
| 122 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 123 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 124 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 125 | |
| 126 | /** |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 127 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 128 | * contain a {@link NotificationChannel#getId() channel id} that can be used to narrow down |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 129 | * what settings should be shown in the target app. |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 130 | */ |
| 131 | public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 132 | |
| 133 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 134 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 005c8b9 | 2017-08-24 10:35:53 -0400 | [diff] [blame] | 135 | * contain a {@link NotificationChannelGroup#getId() group id} that can be used to narrow down |
| 136 | * what settings should be shown in the target app. |
| 137 | */ |
| 138 | public static final String EXTRA_CHANNEL_GROUP_ID = "android.intent.extra.CHANNEL_GROUP_ID"; |
| 139 | |
| 140 | /** |
| 141 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 142 | * contain the tag provided to {@link NotificationManager#notify(String, int, Notification)} |
| 143 | * that can be used to narrow down what settings should be shown in the target app. |
| 144 | */ |
| 145 | public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 146 | |
| 147 | /** |
| 148 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 149 | * contain the id provided to {@link NotificationManager#notify(String, int, Notification)} |
| 150 | * that can be used to narrow down what settings should be shown in the target app. |
| 151 | */ |
| 152 | public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 153 | |
| 154 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | * Use all default values (where applicable). |
| 156 | */ |
| 157 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | /** |
| 160 | * Use the default notification sound. This will ignore any given |
| 161 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 162 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 163 | * <p> |
| 164 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 165 | * </p> |
| 166 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 168 | */ |
| 169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | public static final int DEFAULT_SOUND = 1; |
| 171 | |
| 172 | /** |
| 173 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 174 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 175 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 176 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 177 | * <p> |
| 178 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 179 | * </p> |
| 180 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 182 | */ |
| 183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | /** |
| 187 | * Use the default notification lights. This will ignore the |
| 188 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 189 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 190 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 192 | */ |
| 193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 197 | * Maximum length of CharSequences accepted by Builder and friends. |
| 198 | * |
| 199 | * <p> |
| 200 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 201 | */ |
| 202 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 203 | |
| 204 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 205 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 206 | */ |
| 207 | private static final int MAX_REPLY_HISTORY = 5; |
| 208 | |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 209 | /** |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 210 | * Maximum number of (generic) action buttons in a notification (contextual action buttons are |
| 211 | * handled separately). |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 212 | * @hide |
| 213 | */ |
| 214 | public static final int MAX_ACTION_BUTTONS = 3; |
Selim Cinek | de4de0e | 2018-01-24 16:21:07 -0800 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * If the notification contained an unsent draft for a RemoteInput when the user clicked on it, |
| 218 | * we're adding the draft as a String extra to the {@link #contentIntent} using this key. |
| 219 | * |
| 220 | * <p>Apps may use this extra to prepopulate text fields in the app, where the user usually |
| 221 | * sends messages.</p> |
| 222 | */ |
| 223 | public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; |
| 224 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 225 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 226 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 227 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 228 | * Default value: {@link System#currentTimeMillis() Now}. |
| 229 | * |
| 230 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 231 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 232 | * 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] | 233 | * timestamped according to when the activity began. |
| 234 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 235 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 236 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 237 | * <ul> |
| 238 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 239 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 240 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 241 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 242 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 243 | * <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] | 244 | * </ul> |
| 245 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 246 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 247 | * anymore by default and must be opted into by using |
| 248 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | */ |
| 250 | public long when; |
| 251 | |
| 252 | /** |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 253 | * The creation time of the notification |
| 254 | */ |
| 255 | private long creationTime; |
| 256 | |
| 257 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | * 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] | 259 | * |
| 260 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 262 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 263 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | public int icon; |
| 265 | |
| 266 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 267 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 268 | * leave it at its default value of 0. |
| 269 | * |
| 270 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 271 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 272 | */ |
| 273 | public int iconLevel; |
| 274 | |
| 275 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 276 | * The number of events that this notification represents. For example, in a new mail |
| 277 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 278 | * |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 279 | * The system may or may not use this field to modify the appearance of the notification. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 280 | * Starting with {@link android.os.Build.VERSION_CODES#O}, the number may be displayed as a |
| 281 | * badge icon in Launchers that support badging. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | */ |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 283 | public int number = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | |
| 285 | /** |
| 286 | * The intent to execute when the expanded status entry is clicked. If |
| 287 | * this is an activity, it must include the |
| 288 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 289 | * that you take care of task management as described in the |
| 290 | * <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] | 291 | * Stack</a> document. In particular, make sure to read the notification section |
| 292 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 293 | * Notifications</a> for the correct ways to launch an application from a |
| 294 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | */ |
| 296 | public PendingIntent contentIntent; |
| 297 | |
| 298 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 299 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 300 | * the "Clear All" button or by swiping it away individually. |
| 301 | * |
| 302 | * This probably shouldn't be launching an activity since several of those will be sent |
| 303 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | */ |
| 305 | public PendingIntent deleteIntent; |
| 306 | |
| 307 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 308 | * 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] | 309 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 310 | * <p> |
| 311 | * The system UI may choose to display a heads-up notification, instead of |
| 312 | * launching this intent, while the user is using the device. |
| 313 | * </p> |
| 314 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 315 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 316 | */ |
| 317 | public PendingIntent fullScreenIntent; |
| 318 | |
| 319 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 320 | * Text that summarizes this notification for accessibility services. |
| 321 | * |
| 322 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 323 | * accessibility services (where it serves as an audible announcement of the notification's |
| 324 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 325 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 326 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | */ |
| 328 | public CharSequence tickerText; |
| 329 | |
| 330 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 331 | * Formerly, a view showing the {@link #tickerText}. |
| 332 | * |
| 333 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 334 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 335 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 336 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 337 | |
| 338 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 339 | * The view that will represent this notification in the notification list (which is pulled |
| 340 | * down from the status bar). |
| 341 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 342 | * As of N, this field may be null. The notification view is determined by the inputs |
| 343 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 344 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 346 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | public RemoteViews contentView; |
| 348 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 349 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 350 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 351 | * opportunity to show more detail. The system UI may choose to show this |
| 352 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 353 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 354 | * 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] | 355 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 356 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 357 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 358 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 359 | public RemoteViews bigContentView; |
| 360 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 361 | |
| 362 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 363 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 364 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 365 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 366 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 367 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 368 | * 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] | 369 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 370 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 371 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 372 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 373 | public RemoteViews headsUpContentView; |
| 374 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 375 | private boolean mUsesStandardHeader; |
| 376 | |
| 377 | private static final ArraySet<Integer> STANDARD_LAYOUTS = new ArraySet<>(); |
| 378 | static { |
| 379 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_base); |
| 380 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_base); |
| 381 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_picture); |
| 382 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text); |
| 383 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_inbox); |
| 384 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging); |
| 385 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_media); |
| 386 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 387 | STANDARD_LAYOUTS.add(R.layout.notification_template_header); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 388 | } |
| 389 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 390 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 391 | * A large bitmap to be shown in the notification content area. |
| 392 | * |
| 393 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 395 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 396 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | |
| 398 | /** |
| 399 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 400 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 402 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 403 | * </p> |
| 404 | * |
| 405 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 406 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 408 | * @deprecated use {@link NotificationChannel#getSound()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 410 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | public Uri sound; |
| 412 | |
| 413 | /** |
| 414 | * Use this constant as the value for audioStreamType to request that |
| 415 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 416 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 417 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 418 | * @deprecated Use {@link NotificationChannel#getAudioAttributes()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 420 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | public static final int STREAM_DEFAULT = -1; |
| 422 | |
| 423 | /** |
| 424 | * The audio stream type to use when playing the sound. |
| 425 | * Should be one of the STREAM_ constants from |
| 426 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 427 | * |
| 428 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 430 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | public int audioStreamType = STREAM_DEFAULT; |
| 432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 434 | * The default value of {@link #audioAttributes}. |
| 435 | */ |
| 436 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 437 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 438 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 439 | .build(); |
| 440 | |
| 441 | /** |
| 442 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 443 | * |
| 444 | * @deprecated use {@link NotificationChannel#getAudioAttributes()} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 445 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 446 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 447 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 448 | |
| 449 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 450 | * The pattern with which to vibrate. |
| 451 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | * <p> |
| 453 | * To vibrate the default pattern, see {@link #defaults}. |
| 454 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 455 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | * @see android.os.Vibrator#vibrate(long[],int) |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 457 | * @deprecated use {@link NotificationChannel#getVibrationPattern()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 459 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | public long[] vibrate; |
| 461 | |
| 462 | /** |
| 463 | * The color of the led. The hardware will do its best approximation. |
| 464 | * |
| 465 | * @see #FLAG_SHOW_LIGHTS |
| 466 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 467 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 469 | @ColorInt |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 470 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | public int ledARGB; |
| 472 | |
| 473 | /** |
| 474 | * The number of milliseconds for the LED to be on while it's flashing. |
| 475 | * The hardware will do its best approximation. |
| 476 | * |
| 477 | * @see #FLAG_SHOW_LIGHTS |
| 478 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 479 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 481 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | public int ledOnMS; |
| 483 | |
| 484 | /** |
| 485 | * The number of milliseconds for the LED to be off while it's flashing. |
| 486 | * The hardware will do its best approximation. |
| 487 | * |
| 488 | * @see #FLAG_SHOW_LIGHTS |
| 489 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 490 | * |
| 491 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 493 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | public int ledOffMS; |
| 495 | |
| 496 | /** |
| 497 | * Specifies which values should be taken from the defaults. |
| 498 | * <p> |
| 499 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 500 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 501 | * values, use {@link #DEFAULT_ALL}. |
| 502 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 503 | * |
| 504 | * @deprecated use {@link NotificationChannel#getSound()} and |
| 505 | * {@link NotificationChannel#shouldShowLights()} and |
| 506 | * {@link NotificationChannel#shouldVibrate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 508 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | public int defaults; |
| 510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | /** |
| 512 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 513 | * set if you want the LED on for this notification. |
| 514 | * <ul> |
| 515 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 516 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 517 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 518 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 519 | * be on and off to ledOnMS and ledOffMS.</li> |
| 520 | * </ul> |
| 521 | * <p> |
| 522 | * Since hardware varies, you are not guaranteed that any of the values |
Ricardo Loo Foronda | f8f6d0a | 2018-01-25 08:42:43 -0800 | [diff] [blame] | 523 | * you pass are honored exactly. Use the system defaults if possible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | * because they will be set to values that work on any given hardware. |
| 525 | * <p> |
| 526 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 527 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 528 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 530 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 532 | |
| 533 | /** |
| 534 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 535 | * set if this notification is in reference to something that is ongoing, |
| 536 | * like a phone call. It should not be set if this notification is in |
| 537 | * reference to something that happened at a particular point in time, |
| 538 | * like a missed phone call. |
| 539 | */ |
| 540 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 541 | |
| 542 | /** |
| 543 | * 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] | 544 | * the audio will be repeated until the notification is |
| 545 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | */ |
| 547 | public static final int FLAG_INSISTENT = 0x00000004; |
| 548 | |
| 549 | /** |
| 550 | * 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] | 551 | * set if you would only like the sound, vibrate and ticker to be played |
| 552 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | */ |
| 554 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 555 | |
| 556 | /** |
| 557 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 558 | * 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] | 559 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | */ |
| 561 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 562 | |
| 563 | /** |
| 564 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 565 | * set if the notification should not be canceled when the user clicks |
| 566 | * the Clear all button. |
| 567 | */ |
| 568 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 569 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 570 | /** |
| 571 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 572 | * set if this notification represents a currently running service. This |
| 573 | * will normally be set for you by {@link Service#startForeground}. |
| 574 | */ |
| 575 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 576 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 577 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 578 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 579 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 580 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 581 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 582 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 583 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 584 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 585 | /** |
| 586 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 587 | * set if this notification is relevant to the current device only |
| 588 | * and it is not recommended that it bridge to other devices. |
| 589 | */ |
| 590 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 591 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 592 | /** |
| 593 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 594 | * set if this notification is the group summary for a group of notifications. |
| 595 | * Grouped notifications may display in a cluster or stack on devices which |
| 596 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 597 | */ |
| 598 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 599 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 600 | /** |
| 601 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 602 | * set if this notification is the group summary for an auto-group of notifications. |
| 603 | * |
| 604 | * @hide |
| 605 | */ |
| 606 | @SystemApi |
| 607 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 608 | |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 609 | /** |
| 610 | * @hide |
| 611 | */ |
| 612 | public static final int FLAG_CAN_COLORIZE = 0x00000800; |
| 613 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | public int flags; |
| 615 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 616 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 617 | @IntDef(prefix = { "PRIORITY_" }, value = { |
| 618 | PRIORITY_DEFAULT, |
| 619 | PRIORITY_LOW, |
| 620 | PRIORITY_MIN, |
| 621 | PRIORITY_HIGH, |
| 622 | PRIORITY_MAX |
| 623 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 624 | @Retention(RetentionPolicy.SOURCE) |
| 625 | public @interface Priority {} |
| 626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 628 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 629 | * notifications, use this value for all notifications. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 630 | * |
| 631 | * @deprecated use {@link NotificationManager#IMPORTANCE_DEFAULT} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 632 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 633 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 634 | public static final int PRIORITY_DEFAULT = 0; |
| 635 | |
| 636 | /** |
| 637 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 638 | * items smaller, or at a different position in the list, compared with your app's |
| 639 | * {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 640 | * |
| 641 | * @deprecated use {@link NotificationManager#IMPORTANCE_LOW} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 642 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 643 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 644 | public static final int PRIORITY_LOW = -1; |
| 645 | |
| 646 | /** |
| 647 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 648 | * circumstances, such as detailed notification logs. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 649 | * |
| 650 | * @deprecated use {@link NotificationManager#IMPORTANCE_MIN} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 651 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 652 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 653 | public static final int PRIORITY_MIN = -2; |
| 654 | |
| 655 | /** |
| 656 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 657 | * show these items larger, or at a different position in notification lists, compared with |
| 658 | * your app's {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 659 | * |
| 660 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 661 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 662 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 663 | public static final int PRIORITY_HIGH = 1; |
| 664 | |
| 665 | /** |
| 666 | * Highest {@link #priority}, for your application's most important items that require the |
| 667 | * user's prompt attention or input. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 668 | * |
| 669 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 670 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 671 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 672 | public static final int PRIORITY_MAX = 2; |
| 673 | |
| 674 | /** |
| 675 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 676 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 677 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 678 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 679 | * 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] | 680 | * system will make a determination about how to interpret this priority when presenting |
| 681 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 682 | * |
| 683 | * <p> |
| 684 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 685 | * as a heads-up notification. |
| 686 | * </p> |
| 687 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 688 | * @deprecated use {@link NotificationChannel#getImportance()} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 689 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 690 | @Priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 691 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 692 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 693 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 694 | /** |
| 695 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 696 | * to be applied by the standard Style templates when presenting this notification. |
| 697 | * |
| 698 | * The current template design constructs a colorful header image by overlaying the |
| 699 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 700 | * ignored. |
| 701 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 702 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 703 | public int color = COLOR_DEFAULT; |
| 704 | |
| 705 | /** |
| 706 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 707 | * any special color but instead use default colors when presenting this notification. |
| 708 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 709 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 710 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 711 | |
| 712 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 713 | * Special value of {@link #color} used as a place holder for an invalid color. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 714 | * @hide |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 715 | */ |
| 716 | @ColorInt |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 717 | public static final int COLOR_INVALID = 1; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 718 | |
| 719 | /** |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 720 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 721 | * the notification's presence and contents in untrusted situations (namely, on the secure |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 722 | * lockscreen). |
| 723 | * |
| 724 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 725 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 726 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 727 | * the appropriate user. |
| 728 | * |
| 729 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 730 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 731 | * To modify the public version of this notification—for example, to redact some portions—see |
| 732 | * {@link Builder#setPublicVersion(Notification)}. |
| 733 | * |
| 734 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 735 | * and ticker until the user has bypassed the lockscreen. |
| 736 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 737 | public @Visibility int visibility; |
| 738 | |
| 739 | /** @hide */ |
| 740 | @IntDef(prefix = { "VISIBILITY_" }, value = { |
| 741 | VISIBILITY_PUBLIC, |
| 742 | VISIBILITY_PRIVATE, |
| 743 | VISIBILITY_SECRET, |
| 744 | }) |
| 745 | @Retention(RetentionPolicy.SOURCE) |
| 746 | public @interface Visibility {} |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 747 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 748 | /** |
| 749 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 750 | * |
| 751 | * {@see #visibility} |
| 752 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 753 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 754 | |
| 755 | /** |
| 756 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 757 | * private information on secure lockscreens. |
| 758 | * |
| 759 | * {@see #visibility} |
| 760 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 761 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 762 | |
| 763 | /** |
| 764 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 765 | * |
| 766 | * {@see #visibility} |
| 767 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 768 | public static final int VISIBILITY_SECRET = -1; |
| 769 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 770 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 771 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 772 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 773 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 774 | |
| 775 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 776 | * Notification category: map turn-by-turn navigation. |
| 777 | */ |
| 778 | public static final String CATEGORY_NAVIGATION = "navigation"; |
| 779 | |
| 780 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 781 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 782 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 783 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 784 | |
| 785 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 786 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 787 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 788 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 789 | |
| 790 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 791 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 792 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 793 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 794 | |
| 795 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 796 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 797 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 798 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 799 | |
| 800 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 801 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 802 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 803 | public static final String CATEGORY_ALARM = "alarm"; |
| 804 | |
| 805 | /** |
| 806 | * Notification category: progress of a long-running background operation. |
| 807 | */ |
| 808 | public static final String CATEGORY_PROGRESS = "progress"; |
| 809 | |
| 810 | /** |
| 811 | * Notification category: social network or sharing update. |
| 812 | */ |
| 813 | public static final String CATEGORY_SOCIAL = "social"; |
| 814 | |
| 815 | /** |
| 816 | * Notification category: error in background operation or authentication status. |
| 817 | */ |
| 818 | public static final String CATEGORY_ERROR = "err"; |
| 819 | |
| 820 | /** |
| 821 | * Notification category: media transport control for playback. |
| 822 | */ |
| 823 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 824 | |
| 825 | /** |
| 826 | * Notification category: system or device status update. Reserved for system use. |
| 827 | */ |
| 828 | public static final String CATEGORY_SYSTEM = "sys"; |
| 829 | |
| 830 | /** |
| 831 | * Notification category: indication of running background service. |
| 832 | */ |
| 833 | public static final String CATEGORY_SERVICE = "service"; |
| 834 | |
| 835 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 836 | * Notification category: a specific, timely recommendation for a single thing. |
| 837 | * For example, a news app might want to recommend a news story it believes the user will |
| 838 | * want to read next. |
| 839 | */ |
| 840 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 841 | |
| 842 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 843 | * Notification category: ongoing information about device or contextual status. |
| 844 | */ |
| 845 | public static final String CATEGORY_STATUS = "status"; |
| 846 | |
| 847 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 848 | * Notification category: user-scheduled reminder. |
| 849 | */ |
| 850 | public static final String CATEGORY_REMINDER = "reminder"; |
| 851 | |
| 852 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 853 | * Notification category: extreme car emergencies. |
| 854 | * @hide |
| 855 | */ |
| 856 | @SystemApi |
| 857 | public static final String CATEGORY_CAR_EMERGENCY = "car_emergency"; |
| 858 | |
| 859 | /** |
| 860 | * Notification category: car warnings. |
| 861 | * @hide |
| 862 | */ |
| 863 | @SystemApi |
| 864 | public static final String CATEGORY_CAR_WARNING = "car_warning"; |
| 865 | |
| 866 | /** |
| 867 | * Notification category: general car system information. |
| 868 | * @hide |
| 869 | */ |
| 870 | @SystemApi |
| 871 | public static final String CATEGORY_CAR_INFORMATION = "car_information"; |
| 872 | |
| 873 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 874 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 875 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 876 | */ |
| 877 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 878 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 879 | @UnsupportedAppUsage |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 880 | private String mGroupKey; |
| 881 | |
| 882 | /** |
| 883 | * Get the key used to group this notification into a cluster or stack |
| 884 | * with other notifications on devices which support such rendering. |
| 885 | */ |
| 886 | public String getGroup() { |
| 887 | return mGroupKey; |
| 888 | } |
| 889 | |
| 890 | private String mSortKey; |
| 891 | |
| 892 | /** |
| 893 | * Get a sort key that orders this notification among other notifications from the |
| 894 | * same package. This can be useful if an external sort was already applied and an app |
| 895 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 896 | * value, although providing different priorities in addition to providing sort key may |
| 897 | * cause this value to be ignored. |
| 898 | * |
| 899 | * <p>This sort key can also be used to order members of a notification group. See |
| 900 | * {@link Builder#setGroup}. |
| 901 | * |
| 902 | * @see String#compareTo(String) |
| 903 | */ |
| 904 | public String getSortKey() { |
| 905 | return mSortKey; |
| 906 | } |
| 907 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 908 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 909 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 910 | * <p> |
| 911 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 912 | * APIs, and are intended to be used by |
| 913 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 914 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 915 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 916 | public Bundle extras = new Bundle(); |
| 917 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 918 | /** |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 919 | * All pending intents in the notification as the system needs to be able to access them but |
| 920 | * touching the extras bundle in the system process is not safe because the bundle may contain |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 921 | * custom parcelable objects. |
| 922 | * |
| 923 | * @hide |
| 924 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 925 | @UnsupportedAppUsage |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 926 | public ArraySet<PendingIntent> allPendingIntents; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 927 | |
| 928 | /** |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 929 | * Token identifying the notification that is applying doze/bgcheck whitelisting to the |
| 930 | * pending intents inside of it, so only those will get the behavior. |
| 931 | * |
| 932 | * @hide |
| 933 | */ |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 934 | private IBinder mWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 935 | |
| 936 | /** |
| 937 | * Must be set by a process to start associating tokens with Notification objects |
| 938 | * coming in to it. This is set by NotificationManagerService. |
| 939 | * |
| 940 | * @hide |
| 941 | */ |
| 942 | static public IBinder processWhitelistToken; |
| 943 | |
| 944 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 945 | * {@link #extras} key: this is the title of the notification, |
| 946 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 947 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 948 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 949 | |
| 950 | /** |
| 951 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 952 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 953 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 954 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 955 | |
| 956 | /** |
| 957 | * {@link #extras} key: this is the main text payload, as supplied to |
| 958 | * {@link Builder#setContentText(CharSequence)}. |
| 959 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 960 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 961 | |
| 962 | /** |
| 963 | * {@link #extras} key: this is a third line of text, as supplied to |
| 964 | * {@link Builder#setSubText(CharSequence)}. |
| 965 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 966 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 967 | |
| 968 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 969 | * {@link #extras} key: this is the remote input history, as supplied to |
| 970 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
Adrian Roos | 005e774 | 2016-04-13 15:02:20 -0700 | [diff] [blame] | 971 | * |
| 972 | * Apps can fill this through {@link Builder#setRemoteInputHistory(CharSequence[])} |
| 973 | * with the most recent inputs that have been sent through a {@link RemoteInput} of this |
| 974 | * Notification and are expected to clear it once the it is no longer relevant (e.g. for chat |
| 975 | * notifications once the other party has responded). |
| 976 | * |
| 977 | * The extra with this key is of type CharSequence[] and contains the most recent entry at |
| 978 | * the 0 index, the second most recent at the 1 index, etc. |
| 979 | * |
| 980 | * @see Builder#setRemoteInputHistory(CharSequence[]) |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 981 | */ |
| 982 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 983 | |
| 984 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 985 | * {@link #extras} key: boolean as supplied to |
| 986 | * {@link Builder#setShowRemoteInputSpinner(boolean)}. |
| 987 | * |
| 988 | * If set to true, then the view displaying the remote input history from |
| 989 | * {@link Builder#setRemoteInputHistory(CharSequence[])} will have a progress spinner. |
| 990 | * |
| 991 | * @see Builder#setShowRemoteInputSpinner(boolean) |
| 992 | * @hide |
| 993 | */ |
| 994 | public static final String EXTRA_SHOW_REMOTE_INPUT_SPINNER = "android.remoteInputSpinner"; |
| 995 | |
| 996 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 997 | * {@link #extras} key: boolean as supplied to |
| 998 | * {@link Builder#setHideSmartReplies(boolean)}. |
| 999 | * |
| 1000 | * If set to true, then any smart reply buttons will be hidden. |
| 1001 | * |
| 1002 | * @see Builder#setHideSmartReplies(boolean) |
| 1003 | * @hide |
| 1004 | */ |
| 1005 | public static final String EXTRA_HIDE_SMART_REPLIES = "android.hideSmartReplies"; |
| 1006 | |
| 1007 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1008 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 1009 | * {@link Builder#setContentInfo(CharSequence)}. |
| 1010 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1011 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1012 | |
| 1013 | /** |
| 1014 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 1015 | * alongside expanded notifications, as supplied to (e.g.) |
| 1016 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 1017 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1018 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1019 | |
| 1020 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1021 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 1022 | * {@link BigTextStyle} notification, as supplied to |
| 1023 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 1024 | */ |
| 1025 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 1026 | |
| 1027 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1028 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 1029 | * supplied to {@link Builder#setSmallIcon(int)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1030 | * |
| 1031 | * @deprecated Use {@link #getSmallIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1032 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1033 | @Deprecated |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1034 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1035 | |
| 1036 | /** |
| 1037 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 1038 | * notification payload, as |
| 1039 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1040 | * |
| 1041 | * @deprecated Use {@link #getLargeIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1042 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1043 | @Deprecated |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1044 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1045 | |
| 1046 | /** |
| 1047 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 1048 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 1049 | * shown in its expanded form, as supplied to |
| 1050 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 1051 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1052 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1053 | |
| 1054 | /** |
| 1055 | * {@link #extras} key: this is the progress value supplied to |
| 1056 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1057 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1058 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1059 | |
| 1060 | /** |
| 1061 | * {@link #extras} key: this is the maximum value supplied to |
| 1062 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1063 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1064 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1065 | |
| 1066 | /** |
| 1067 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 1068 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1069 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1070 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1071 | |
| 1072 | /** |
| 1073 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 1074 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 1075 | * {@link Builder#setUsesChronometer(boolean)}. |
| 1076 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1077 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1078 | |
| 1079 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1080 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 1081 | * instead of counting up. Is only relevant if key {@link #EXTRA_SHOW_CHRONOMETER} is present. |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1082 | * This extra is a boolean. The default is false. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1083 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1084 | public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1085 | |
| 1086 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1087 | * {@link #extras} key: whether {@link #when} should be shown, |
| 1088 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 1089 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1090 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1091 | |
| 1092 | /** |
| 1093 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 1094 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 1095 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1096 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1097 | |
| 1098 | /** |
| 1099 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 1100 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 1101 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1102 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1103 | |
| 1104 | /** |
| 1105 | * {@link #extras} key: A string representing the name of the specific |
| 1106 | * {@link android.app.Notification.Style} used to create this notification. |
| 1107 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 1108 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1109 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1110 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 1111 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 1112 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1113 | * |
| 1114 | * @deprecated the actual objects are now in {@link #EXTRA_PEOPLE_LIST} |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1115 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1116 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1117 | |
| 1118 | /** |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1119 | * {@link #extras} key: An arrayList of {@link Person} objects containing the people that |
| 1120 | * this notification relates to. |
| 1121 | */ |
| 1122 | public static final String EXTRA_PEOPLE_LIST = "android.people.list"; |
| 1123 | |
| 1124 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1125 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 1126 | * Only available to notifications coming from the android package. |
| 1127 | * @hide |
| 1128 | */ |
Maurice Lam | 96c1003 | 2017-03-29 15:42:38 -0700 | [diff] [blame] | 1129 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1130 | @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1131 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 1132 | |
| 1133 | /** |
Robin Lee | d107af6 | 2018-04-27 13:55:56 +0200 | [diff] [blame] | 1134 | * {@link #extras} key: |
| 1135 | * flat {@link String} representation of a {@link android.content.ContentUris content URI} |
| 1136 | * pointing to an image that can be displayed in the background when the notification is |
| 1137 | * selected. Used on television platforms. The URI must point to an image stream suitable for |
| 1138 | * passing into {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1139 | * BitmapFactory.decodeStream}; all other content types will be ignored. |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1140 | */ |
| 1141 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1142 | |
| 1143 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1144 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 1145 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1146 | * {@link android.app.Notification.MediaStyle} notification. |
| 1147 | */ |
| 1148 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1149 | |
| 1150 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 1151 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 1152 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 1153 | */ |
| 1154 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1155 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 1156 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1157 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 1158 | * direct replies |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1159 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1160 | * {@link CharSequence} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1161 | * |
| 1162 | * @deprecated use {@link #EXTRA_MESSAGING_PERSON} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1163 | */ |
| 1164 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1165 | |
| 1166 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1167 | * {@link #extras} key: the person to be displayed for all messages sent by the user including |
| 1168 | * direct replies |
| 1169 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1170 | * {@link Person} |
| 1171 | */ |
| 1172 | public static final String EXTRA_MESSAGING_PERSON = "android.messagingUser"; |
| 1173 | |
| 1174 | /** |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1175 | * {@link #extras} key: a {@link CharSequence} to be displayed as the title to a conversation |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1176 | * represented by a {@link android.app.Notification.MessagingStyle} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1177 | */ |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1178 | public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1179 | |
| 1180 | /** |
| 1181 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 1182 | * bundles provided by a |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1183 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1184 | * array of bundles. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1185 | */ |
| 1186 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 1187 | |
| 1188 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 1189 | * {@link #extras} key: an array of |
| 1190 | * {@link android.app.Notification.MessagingStyle#addHistoricMessage historic} |
| 1191 | * {@link android.app.Notification.MessagingStyle.Message} bundles provided by a |
| 1192 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1193 | * array of bundles. |
| 1194 | */ |
| 1195 | public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1196 | |
| 1197 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 1198 | * {@link #extras} key: whether the {@link android.app.Notification.MessagingStyle} notification |
| 1199 | * represents a group conversation. |
| 1200 | */ |
| 1201 | public static final String EXTRA_IS_GROUP_CONVERSATION = "android.isGroupConversation"; |
| 1202 | |
| 1203 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1204 | * {@link #extras} key: whether the notification should be colorized as |
| 1205 | * supplied to {@link Builder#setColorized(boolean)}}. |
| 1206 | */ |
| 1207 | public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1208 | |
| 1209 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1210 | * @hide |
| 1211 | */ |
| 1212 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1213 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 1214 | /** |
| 1215 | * @hide |
| 1216 | */ |
| 1217 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1218 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1219 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 1220 | * @hide |
| 1221 | */ |
| 1222 | public static final String EXTRA_REDUCED_IMAGES = "android.reduced.images"; |
| 1223 | |
| 1224 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1225 | * {@link #extras} key: the audio contents of this notification. |
| 1226 | * |
| 1227 | * This is for use when rendering the notification on an audio-focused interface; |
| 1228 | * the audio contents are a complete sound sample that contains the contents/body of the |
| 1229 | * notification. This may be used in substitute of a Text-to-Speech reading of the |
| 1230 | * notification. For example if the notification represents a voice message this should point |
| 1231 | * to the audio of that message. |
| 1232 | * |
| 1233 | * The data stored under this key should be a String representation of a Uri that contains the |
| 1234 | * audio contents in one of the following formats: WAV, PCM 16-bit, AMR-WB. |
| 1235 | * |
| 1236 | * This extra is unnecessary if you are using {@code MessagingStyle} since each {@code Message} |
| 1237 | * has a field for holding data URI. That field can be used for audio. |
| 1238 | * See {@code Message#setData}. |
| 1239 | * |
| 1240 | * Example usage: |
| 1241 | * <pre> |
| 1242 | * {@code |
| 1243 | * Notification.Builder myBuilder = (build your Notification as normal); |
| 1244 | * myBuilder.getExtras().putString(EXTRA_AUDIO_CONTENTS_URI, myAudioUri.toString()); |
| 1245 | * } |
| 1246 | * </pre> |
| 1247 | */ |
| 1248 | public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1249 | |
Dan Sandler | 80eaa59 | 2016-04-14 23:34:54 -0400 | [diff] [blame] | 1250 | /** @hide */ |
| 1251 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1252 | @RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME) |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1253 | public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1254 | |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1255 | /** |
Julia Reynolds | 3c7de11 | 2018-03-28 09:33:13 -0400 | [diff] [blame] | 1256 | * This is set on the notifications shown by system_server about apps running foreground |
| 1257 | * services. It indicates that the notification should be shown |
| 1258 | * only if any of the given apps do not already have a properly tagged |
| 1259 | * {@link #FLAG_FOREGROUND_SERVICE} notification currently visible to the user. |
| 1260 | * This is a string array of all package names of the apps. |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1261 | * @hide |
| 1262 | */ |
| 1263 | public static final String EXTRA_FOREGROUND_APPS = "android.foregroundApps"; |
| 1264 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1265 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1266 | private Icon mSmallIcon; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1267 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1268 | private Icon mLargeIcon; |
| 1269 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1270 | @UnsupportedAppUsage |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1271 | private String mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1272 | private long mTimeout; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1273 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1274 | private String mShortcutId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1275 | private CharSequence mSettingsText; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1276 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 1277 | private BubbleMetadata mBubbleMetadata; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 1278 | |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1279 | /** @hide */ |
| 1280 | @IntDef(prefix = { "GROUP_ALERT_" }, value = { |
| 1281 | GROUP_ALERT_ALL, GROUP_ALERT_CHILDREN, GROUP_ALERT_SUMMARY |
| 1282 | }) |
| 1283 | @Retention(RetentionPolicy.SOURCE) |
| 1284 | public @interface GroupAlertBehavior {} |
| 1285 | |
| 1286 | /** |
| 1287 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all notifications in a |
| 1288 | * group with sound or vibration ought to make sound or vibrate (respectively), so this |
| 1289 | * notification will not be muted when it is in a group. |
| 1290 | */ |
| 1291 | public static final int GROUP_ALERT_ALL = 0; |
| 1292 | |
| 1293 | /** |
| 1294 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all children |
| 1295 | * notification in a group should be silenced (no sound or vibration) even if they are posted |
| 1296 | * to a {@link NotificationChannel} that has sound and/or vibration. Use this constant to |
Julia Reynolds | 399d9bf | 2017-08-11 12:52:14 -0400 | [diff] [blame] | 1297 | * mute this notification if this notification is a group child. This must be applied to all |
| 1298 | * children notifications you want to mute. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1299 | * |
| 1300 | * <p> For example, you might want to use this constant if you post a number of children |
| 1301 | * notifications at once (say, after a periodic sync), and only need to notify the user |
| 1302 | * audibly once. |
| 1303 | */ |
| 1304 | public static final int GROUP_ALERT_SUMMARY = 1; |
| 1305 | |
| 1306 | /** |
| 1307 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that the summary |
| 1308 | * notification in a group should be silenced (no sound or vibration) even if they are |
| 1309 | * posted to a {@link NotificationChannel} that has sound and/or vibration. Use this constant |
| 1310 | * to mute this notification if this notification is a group summary. |
| 1311 | * |
| 1312 | * <p>For example, you might want to use this constant if only the children notifications |
Julia Reynolds | 399d9bf | 2017-08-11 12:52:14 -0400 | [diff] [blame] | 1313 | * in your group have content and the summary is only used to visually group notifications |
| 1314 | * rather than to alert the user that new information is available. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1315 | */ |
| 1316 | public static final int GROUP_ALERT_CHILDREN = 2; |
| 1317 | |
Julia Reynolds | 2f431e2 | 2017-06-07 14:12:09 +0000 | [diff] [blame] | 1318 | private int mGroupAlertBehavior = GROUP_ALERT_ALL; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1319 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1320 | /** |
| 1321 | * If this notification is being shown as a badge, always show as a number. |
| 1322 | */ |
| 1323 | public static final int BADGE_ICON_NONE = 0; |
| 1324 | |
| 1325 | /** |
| 1326 | * If this notification is being shown as a badge, use the {@link #getSmallIcon()} to |
| 1327 | * represent this notification. |
| 1328 | */ |
| 1329 | public static final int BADGE_ICON_SMALL = 1; |
| 1330 | |
| 1331 | /** |
| 1332 | * If this notification is being shown as a badge, use the {@link #getLargeIcon()} to |
| 1333 | * represent this notification. |
| 1334 | */ |
| 1335 | public static final int BADGE_ICON_LARGE = 2; |
Julia Reynolds | 7d5b4da | 2017-03-20 10:18:49 -0400 | [diff] [blame] | 1336 | private int mBadgeIcon = BADGE_ICON_NONE; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1337 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1338 | /** |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 1339 | * Determines whether the platform can generate contextual actions for a notification. |
| 1340 | */ |
| 1341 | private boolean mAllowSystemGeneratedContextualActions = true; |
| 1342 | |
| 1343 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1344 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 1345 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 1346 | * selected by the user. |
| 1347 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1348 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 1349 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 1350 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1351 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1352 | public static class Action implements Parcelable { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1353 | /** |
| 1354 | * {@link #extras} key: Keys to a {@link Parcelable} {@link ArrayList} of |
| 1355 | * {@link RemoteInput}s. |
| 1356 | * |
| 1357 | * This is intended for {@link RemoteInput}s that only accept data, meaning |
| 1358 | * {@link RemoteInput#getAllowFreeFormInput} is false, {@link RemoteInput#getChoices} |
| 1359 | * is null or empty, and {@link RemoteInput#getAllowedDataTypes is non-null and not |
| 1360 | * empty. These {@link RemoteInput}s will be ignored by devices that do not |
| 1361 | * support non-text-based {@link RemoteInput}s. See {@link Builder#build}. |
| 1362 | * |
| 1363 | * You can test if a RemoteInput matches these constraints using |
| 1364 | * {@link RemoteInput#isDataOnly}. |
| 1365 | */ |
| 1366 | private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1367 | |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1368 | /** |
| 1369 | * {@link }: No semantic action defined. |
| 1370 | */ |
| 1371 | public static final int SEMANTIC_ACTION_NONE = 0; |
| 1372 | |
| 1373 | /** |
| 1374 | * {@code SemanticAction}: Reply to a conversation, chat, group, or wherever replies |
| 1375 | * may be appropriate. |
| 1376 | */ |
| 1377 | public static final int SEMANTIC_ACTION_REPLY = 1; |
| 1378 | |
| 1379 | /** |
| 1380 | * {@code SemanticAction}: Mark content as read. |
| 1381 | */ |
| 1382 | public static final int SEMANTIC_ACTION_MARK_AS_READ = 2; |
| 1383 | |
| 1384 | /** |
| 1385 | * {@code SemanticAction}: Mark content as unread. |
| 1386 | */ |
| 1387 | public static final int SEMANTIC_ACTION_MARK_AS_UNREAD = 3; |
| 1388 | |
| 1389 | /** |
| 1390 | * {@code SemanticAction}: Delete the content associated with the notification. This |
| 1391 | * could mean deleting an email, message, etc. |
| 1392 | */ |
| 1393 | public static final int SEMANTIC_ACTION_DELETE = 4; |
| 1394 | |
| 1395 | /** |
| 1396 | * {@code SemanticAction}: Archive the content associated with the notification. This |
| 1397 | * could mean archiving an email, message, etc. |
| 1398 | */ |
| 1399 | public static final int SEMANTIC_ACTION_ARCHIVE = 5; |
| 1400 | |
| 1401 | /** |
| 1402 | * {@code SemanticAction}: Mute the content associated with the notification. This could |
| 1403 | * mean silencing a conversation or currently playing media. |
| 1404 | */ |
| 1405 | public static final int SEMANTIC_ACTION_MUTE = 6; |
| 1406 | |
| 1407 | /** |
| 1408 | * {@code SemanticAction}: Unmute the content associated with the notification. This could |
| 1409 | * mean un-silencing a conversation or currently playing media. |
| 1410 | */ |
| 1411 | public static final int SEMANTIC_ACTION_UNMUTE = 7; |
| 1412 | |
| 1413 | /** |
| 1414 | * {@code SemanticAction}: Mark content with a thumbs up. |
| 1415 | */ |
| 1416 | public static final int SEMANTIC_ACTION_THUMBS_UP = 8; |
| 1417 | |
| 1418 | /** |
| 1419 | * {@code SemanticAction}: Mark content with a thumbs down. |
| 1420 | */ |
| 1421 | public static final int SEMANTIC_ACTION_THUMBS_DOWN = 9; |
| 1422 | |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 1423 | /** |
| 1424 | * {@code SemanticAction}: Call a contact, group, etc. |
| 1425 | */ |
| 1426 | public static final int SEMANTIC_ACTION_CALL = 10; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1427 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1428 | private final Bundle mExtras; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1429 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1430 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1431 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1432 | private boolean mAllowGeneratedReplies = true; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1433 | private final @SemanticAction int mSemanticAction; |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1434 | private final boolean mIsContextual; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1435 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1436 | /** |
| 1437 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1438 | * |
| 1439 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1440 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1441 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1442 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1443 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1444 | /** |
| 1445 | * Title of the action. |
| 1446 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1447 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1448 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1449 | /** |
| 1450 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1451 | * may be rendered in a disabled presentation by the system UI. |
| 1452 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1453 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1454 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1455 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1456 | if (in.readInt() != 0) { |
| 1457 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1458 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1459 | icon = mIcon.getResId(); |
| 1460 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1461 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1462 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1463 | if (in.readInt() == 1) { |
| 1464 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1465 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1466 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1467 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1468 | mAllowGeneratedReplies = in.readInt() == 1; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1469 | mSemanticAction = in.readInt(); |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1470 | mIsContextual = in.readInt() == 1; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1471 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1472 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1473 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1474 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1475 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1476 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1477 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1478 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1479 | SEMANTIC_ACTION_NONE, false /* isContextual */); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1482 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1483 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1484 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1485 | @SemanticAction int semanticAction, boolean isContextual) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1486 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1487 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1488 | this.icon = icon.getResId(); |
| 1489 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1490 | this.title = title; |
| 1491 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1492 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1493 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1494 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1495 | this.mSemanticAction = semanticAction; |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1496 | this.mIsContextual = isContextual; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1500 | * Return an icon representing the action. |
| 1501 | */ |
| 1502 | public Icon getIcon() { |
| 1503 | if (mIcon == null && icon != 0) { |
| 1504 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1505 | mIcon = Icon.createWithResource("", icon); |
| 1506 | } |
| 1507 | return mIcon; |
| 1508 | } |
| 1509 | |
| 1510 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1511 | * Get additional metadata carried around with this Action. |
| 1512 | */ |
| 1513 | public Bundle getExtras() { |
| 1514 | return mExtras; |
| 1515 | } |
| 1516 | |
| 1517 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1518 | * Return whether the platform should automatically generate possible replies for this |
| 1519 | * {@link Action} |
| 1520 | */ |
| 1521 | public boolean getAllowGeneratedReplies() { |
| 1522 | return mAllowGeneratedReplies; |
| 1523 | } |
| 1524 | |
| 1525 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1526 | * Get the list of inputs to be collected from the user when this action is sent. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1527 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1528 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1529 | */ |
| 1530 | public RemoteInput[] getRemoteInputs() { |
| 1531 | return mRemoteInputs; |
| 1532 | } |
| 1533 | |
| 1534 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1535 | * Returns the {@code SemanticAction} associated with this {@link Action}. A |
| 1536 | * {@code SemanticAction} denotes what an {@link Action}'s {@link PendingIntent} will do |
| 1537 | * (eg. reply, mark as read, delete, etc). |
| 1538 | */ |
| 1539 | public @SemanticAction int getSemanticAction() { |
| 1540 | return mSemanticAction; |
| 1541 | } |
| 1542 | |
| 1543 | /** |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1544 | * Returns whether this is a contextual Action, i.e. whether the action is dependent on the |
| 1545 | * notification message body. An example of a contextual action could be an action opening a |
| 1546 | * map application with an address shown in the notification. |
| 1547 | */ |
| 1548 | public boolean isContextual() { |
| 1549 | return mIsContextual; |
| 1550 | } |
| 1551 | |
| 1552 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1553 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1554 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1555 | * {@link RemoteInput#isDataOnly}. |
| 1556 | * |
Shane Brennan | f670d6c | 2017-04-25 13:05:45 -0700 | [diff] [blame] | 1557 | * Returns null if there are no data-only remote inputs. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1558 | * |
| 1559 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1560 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1561 | */ |
| 1562 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1563 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1564 | } |
| 1565 | |
| 1566 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1567 | * Builder class for {@link Action} objects. |
| 1568 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1569 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1570 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1571 | private final CharSequence mTitle; |
| 1572 | private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1573 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1574 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1575 | private ArrayList<RemoteInput> mRemoteInputs; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1576 | private @SemanticAction int mSemanticAction; |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1577 | private boolean mIsContextual; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1578 | |
| 1579 | /** |
| 1580 | * Construct a new builder for {@link Action} object. |
| 1581 | * @param icon icon to show for this action |
| 1582 | * @param title the title of the action |
| 1583 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1584 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1585 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1586 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1587 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | /** |
| 1591 | * Construct a new builder for {@link Action} object. |
| 1592 | * @param icon icon to show for this action |
| 1593 | * @param title the title of the action |
| 1594 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1595 | */ |
| 1596 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1597 | this(icon, title, intent, new Bundle(), null, true, SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | /** |
| 1601 | * Construct a new builder for {@link Action} object using the fields from an |
| 1602 | * {@link Action}. |
| 1603 | * @param action the action to read fields from. |
| 1604 | */ |
| 1605 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1606 | this(action.getIcon(), action.title, action.actionIntent, |
| 1607 | new Bundle(action.mExtras), action.getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1608 | action.getAllowGeneratedReplies(), action.getSemanticAction()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1611 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1612 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1613 | @SemanticAction int semanticAction) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1614 | mIcon = icon; |
| 1615 | mTitle = title; |
| 1616 | mIntent = intent; |
| 1617 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1618 | if (remoteInputs != null) { |
| 1619 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1620 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1621 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1622 | mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1623 | mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | /** |
| 1627 | * Merge additional metadata into this builder. |
| 1628 | * |
| 1629 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1630 | * |
| 1631 | * @see Notification.Action#extras |
| 1632 | */ |
| 1633 | public Builder addExtras(Bundle extras) { |
| 1634 | if (extras != null) { |
| 1635 | mExtras.putAll(extras); |
| 1636 | } |
| 1637 | return this; |
| 1638 | } |
| 1639 | |
| 1640 | /** |
| 1641 | * Get the metadata Bundle used by this Builder. |
| 1642 | * |
| 1643 | * <p>The returned Bundle is shared with this Builder. |
| 1644 | */ |
| 1645 | public Bundle getExtras() { |
| 1646 | return mExtras; |
| 1647 | } |
| 1648 | |
| 1649 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1650 | * Add an input to be collected from the user when this action is sent. |
| 1651 | * Response values can be retrieved from the fired intent by using the |
| 1652 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1653 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1654 | * @return this object for method chaining |
| 1655 | */ |
| 1656 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1657 | if (mRemoteInputs == null) { |
| 1658 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1659 | } |
| 1660 | mRemoteInputs.add(remoteInput); |
| 1661 | return this; |
| 1662 | } |
| 1663 | |
| 1664 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1665 | * Set whether the platform should automatically generate possible replies to add to |
| 1666 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1667 | * {@link RemoteInput}, this has no effect. |
| 1668 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1669 | * otherwise |
| 1670 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1671 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1672 | */ |
| 1673 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1674 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1675 | return this; |
| 1676 | } |
| 1677 | |
| 1678 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1679 | * Sets the {@code SemanticAction} for this {@link Action}. A |
| 1680 | * {@code SemanticAction} denotes what an {@link Action}'s |
| 1681 | * {@link PendingIntent} will do (eg. reply, mark as read, delete, etc). |
| 1682 | * @param semanticAction a SemanticAction defined within {@link Action} with |
| 1683 | * {@code SEMANTIC_ACTION_} prefixes |
| 1684 | * @return this object for method chaining |
| 1685 | */ |
| 1686 | public Builder setSemanticAction(@SemanticAction int semanticAction) { |
| 1687 | mSemanticAction = semanticAction; |
| 1688 | return this; |
| 1689 | } |
| 1690 | |
| 1691 | /** |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1692 | * Sets whether this {@link Action} is a contextual action, i.e. whether the action is |
| 1693 | * dependent on the notification message body. An example of a contextual action could |
| 1694 | * be an action opening a map application with an address shown in the notification. |
| 1695 | */ |
| 1696 | public Builder setContextual(boolean isContextual) { |
| 1697 | mIsContextual = isContextual; |
| 1698 | return this; |
| 1699 | } |
| 1700 | |
| 1701 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1702 | * Apply an extender to this action builder. Extenders may be used to add |
| 1703 | * metadata or change options on this builder. |
| 1704 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1705 | public Builder extend(Extender extender) { |
| 1706 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1707 | return this; |
| 1708 | } |
| 1709 | |
| 1710 | /** |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1711 | * Throws an NPE if we are building a contextual action missing one of the fields |
| 1712 | * necessary to display the action. |
| 1713 | */ |
| 1714 | private void checkContextualActionNullFields() { |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1715 | if (!mIsContextual) return; |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1716 | |
| 1717 | if (mIcon == null) { |
| 1718 | throw new NullPointerException("Contextual Actions must contain a valid icon"); |
| 1719 | } |
| 1720 | |
| 1721 | if (mIntent == null) { |
| 1722 | throw new NullPointerException( |
| 1723 | "Contextual Actions must contain a valid PendingIntent"); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1728 | * Combine all of the options that have been set and return a new {@link Action} |
| 1729 | * object. |
| 1730 | * @return the built action |
| 1731 | */ |
| 1732 | public Action build() { |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1733 | checkContextualActionNullFields(); |
| 1734 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1735 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1736 | RemoteInput[] previousDataInputs = |
| 1737 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1738 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1739 | for (RemoteInput input : previousDataInputs) { |
| 1740 | dataOnlyInputs.add(input); |
| 1741 | } |
| 1742 | } |
| 1743 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1744 | if (mRemoteInputs != null) { |
| 1745 | for (RemoteInput input : mRemoteInputs) { |
| 1746 | if (input.isDataOnly()) { |
| 1747 | dataOnlyInputs.add(input); |
| 1748 | } else { |
| 1749 | textInputs.add(input); |
| 1750 | } |
| 1751 | } |
| 1752 | } |
| 1753 | if (!dataOnlyInputs.isEmpty()) { |
| 1754 | RemoteInput[] dataInputsArr = |
| 1755 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1756 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1757 | } |
| 1758 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1759 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1760 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1761 | mAllowGeneratedReplies, mSemanticAction, mIsContextual); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1762 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1763 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1764 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1765 | @Override |
| 1766 | public Action clone() { |
| 1767 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1768 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1769 | title, |
| 1770 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1771 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1772 | getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1773 | getAllowGeneratedReplies(), |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1774 | getSemanticAction(), |
| 1775 | isContextual()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1776 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1777 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1778 | @Override |
| 1779 | public int describeContents() { |
| 1780 | return 0; |
| 1781 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1782 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1783 | @Override |
| 1784 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1785 | final Icon ic = getIcon(); |
| 1786 | if (ic != null) { |
| 1787 | out.writeInt(1); |
| 1788 | ic.writeToParcel(out, 0); |
| 1789 | } else { |
| 1790 | out.writeInt(0); |
| 1791 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1792 | TextUtils.writeToParcel(title, out, flags); |
| 1793 | if (actionIntent != null) { |
| 1794 | out.writeInt(1); |
| 1795 | actionIntent.writeToParcel(out, flags); |
| 1796 | } else { |
| 1797 | out.writeInt(0); |
| 1798 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1799 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1800 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1801 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1802 | out.writeInt(mSemanticAction); |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1803 | out.writeInt(mIsContextual ? 1 : 0); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1804 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1805 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1806 | public static final Parcelable.Creator<Action> CREATOR = |
| 1807 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1808 | public Action createFromParcel(Parcel in) { |
| 1809 | return new Action(in); |
| 1810 | } |
| 1811 | public Action[] newArray(int size) { |
| 1812 | return new Action[size]; |
| 1813 | } |
| 1814 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1815 | |
| 1816 | /** |
| 1817 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1818 | * metadata or change options on an action builder. |
| 1819 | */ |
| 1820 | public interface Extender { |
| 1821 | /** |
| 1822 | * Apply this extender to a notification action builder. |
| 1823 | * @param builder the builder to be modified. |
| 1824 | * @return the build object for chaining. |
| 1825 | */ |
| 1826 | public Builder extend(Builder builder); |
| 1827 | } |
| 1828 | |
| 1829 | /** |
| 1830 | * Wearable extender for notification actions. To add extensions to an action, |
| 1831 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1832 | * the {@code WearableExtender()} constructor and apply it to a |
| 1833 | * {@link android.app.Notification.Action.Builder} using |
| 1834 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1835 | * |
| 1836 | * <pre class="prettyprint"> |
| 1837 | * Notification.Action action = new Notification.Action.Builder( |
| 1838 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1839 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1840 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1841 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1842 | */ |
| 1843 | public static final class WearableExtender implements Extender { |
| 1844 | /** Notification action extra which contains wearable extensions */ |
| 1845 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1846 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1847 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1848 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1849 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1850 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1851 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1852 | |
| 1853 | // Flags bitwise-ored to mFlags |
| 1854 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1855 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1856 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1857 | |
| 1858 | // Default value for flags integer |
| 1859 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1860 | |
| 1861 | private int mFlags = DEFAULT_FLAGS; |
| 1862 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1863 | private CharSequence mInProgressLabel; |
| 1864 | private CharSequence mConfirmLabel; |
| 1865 | private CharSequence mCancelLabel; |
| 1866 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1867 | /** |
| 1868 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1869 | * options. |
| 1870 | */ |
| 1871 | public WearableExtender() { |
| 1872 | } |
| 1873 | |
| 1874 | /** |
| 1875 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1876 | * wearable options present in an existing notification action. |
| 1877 | * @param action the notification action to inspect. |
| 1878 | */ |
| 1879 | public WearableExtender(Action action) { |
| 1880 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1881 | if (wearableBundle != null) { |
| 1882 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1883 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1884 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1885 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | /** |
| 1890 | * Apply wearable extensions to a notification action that is being built. This is |
| 1891 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1892 | * method of {@link android.app.Notification.Action.Builder}. |
| 1893 | */ |
| 1894 | @Override |
| 1895 | public Action.Builder extend(Action.Builder builder) { |
| 1896 | Bundle wearableBundle = new Bundle(); |
| 1897 | |
| 1898 | if (mFlags != DEFAULT_FLAGS) { |
| 1899 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1900 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1901 | if (mInProgressLabel != null) { |
| 1902 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1903 | } |
| 1904 | if (mConfirmLabel != null) { |
| 1905 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1906 | } |
| 1907 | if (mCancelLabel != null) { |
| 1908 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1909 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1910 | |
| 1911 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1912 | return builder; |
| 1913 | } |
| 1914 | |
| 1915 | @Override |
| 1916 | public WearableExtender clone() { |
| 1917 | WearableExtender that = new WearableExtender(); |
| 1918 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1919 | that.mInProgressLabel = this.mInProgressLabel; |
| 1920 | that.mConfirmLabel = this.mConfirmLabel; |
| 1921 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1922 | return that; |
| 1923 | } |
| 1924 | |
| 1925 | /** |
| 1926 | * Set whether this action is available when the wearable device is not connected to |
| 1927 | * a companion device. The user can still trigger this action when the wearable device is |
| 1928 | * offline, but a visual hint will indicate that the action may not be available. |
| 1929 | * Defaults to true. |
| 1930 | */ |
| 1931 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1932 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1933 | return this; |
| 1934 | } |
| 1935 | |
| 1936 | /** |
| 1937 | * Get whether this action is available when the wearable device is not connected to |
| 1938 | * a companion device. The user can still trigger this action when the wearable device is |
| 1939 | * offline, but a visual hint will indicate that the action may not be available. |
| 1940 | * Defaults to true. |
| 1941 | */ |
| 1942 | public boolean isAvailableOffline() { |
| 1943 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1944 | } |
| 1945 | |
| 1946 | private void setFlag(int mask, boolean value) { |
| 1947 | if (value) { |
| 1948 | mFlags |= mask; |
| 1949 | } else { |
| 1950 | mFlags &= ~mask; |
| 1951 | } |
| 1952 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1953 | |
| 1954 | /** |
| 1955 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1956 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1957 | * |
| 1958 | * @param label the label to display while the action is being prepared to execute |
| 1959 | * @return this object for method chaining |
| 1960 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1961 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1962 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1963 | mInProgressLabel = label; |
| 1964 | return this; |
| 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * Get the label to display while the wearable is preparing to automatically execute |
| 1969 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1970 | * |
| 1971 | * @return the label to display while the action is being prepared to execute |
| 1972 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1973 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1974 | public CharSequence getInProgressLabel() { |
| 1975 | return mInProgressLabel; |
| 1976 | } |
| 1977 | |
| 1978 | /** |
| 1979 | * Set a label to display to confirm that the action should be executed. |
| 1980 | * This is usually an imperative verb like "Send". |
| 1981 | * |
| 1982 | * @param label the label to confirm the action should be executed |
| 1983 | * @return this object for method chaining |
| 1984 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1985 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1986 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1987 | mConfirmLabel = label; |
| 1988 | return this; |
| 1989 | } |
| 1990 | |
| 1991 | /** |
| 1992 | * Get the label to display to confirm that the action should be executed. |
| 1993 | * This is usually an imperative verb like "Send". |
| 1994 | * |
| 1995 | * @return the label to confirm the action should be executed |
| 1996 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1997 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1998 | public CharSequence getConfirmLabel() { |
| 1999 | return mConfirmLabel; |
| 2000 | } |
| 2001 | |
| 2002 | /** |
| 2003 | * Set a label to display to cancel the action. |
| 2004 | * This is usually an imperative verb, like "Cancel". |
| 2005 | * |
| 2006 | * @param label the label to display to cancel the action |
| 2007 | * @return this object for method chaining |
| 2008 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 2009 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 2010 | public WearableExtender setCancelLabel(CharSequence label) { |
| 2011 | mCancelLabel = label; |
| 2012 | return this; |
| 2013 | } |
| 2014 | |
| 2015 | /** |
| 2016 | * Get the label to display to cancel the action. |
| 2017 | * This is usually an imperative verb like "Cancel". |
| 2018 | * |
| 2019 | * @return the label to display to cancel the action |
| 2020 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 2021 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 2022 | public CharSequence getCancelLabel() { |
| 2023 | return mCancelLabel; |
| 2024 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2025 | |
| 2026 | /** |
| 2027 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 2028 | * platform that it can generate the appropriate transitions. |
| 2029 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 2030 | * an activity and transitions should be generated, false otherwise. |
| 2031 | * @return this object for method chaining |
| 2032 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 2033 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2034 | boolean hintLaunchesActivity) { |
| 2035 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 2036 | return this; |
| 2037 | } |
| 2038 | |
| 2039 | /** |
| 2040 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 2041 | * platform that it can generate the appropriate transitions |
| 2042 | * @return {@code true} if the content intent will launch an activity and transitions |
| 2043 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 2044 | * never set. |
| 2045 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 2046 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2047 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 2048 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2049 | |
| 2050 | /** |
| 2051 | * Set a hint that this Action should be displayed inline. |
| 2052 | * |
| 2053 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 2054 | * otherwise |
| 2055 | * @return this object for method chaining |
| 2056 | */ |
| 2057 | public WearableExtender setHintDisplayActionInline( |
| 2058 | boolean hintDisplayInline) { |
| 2059 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 2060 | return this; |
| 2061 | } |
| 2062 | |
| 2063 | /** |
| 2064 | * Get a hint that this Action should be displayed inline. |
| 2065 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 2066 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2067 | * otherwise. The default value is {@code false} if this was never set. |
| 2068 | */ |
| 2069 | public boolean getHintDisplayActionInline() { |
| 2070 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 2071 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2072 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2073 | |
| 2074 | /** |
| 2075 | * Provides meaning to an {@link Action} that hints at what the associated |
| 2076 | * {@link PendingIntent} will do. For example, an {@link Action} with a |
| 2077 | * {@link PendingIntent} that replies to a text message notification may have the |
| 2078 | * {@link #SEMANTIC_ACTION_REPLY} {@code SemanticAction} set within it. |
| 2079 | * |
| 2080 | * @hide |
| 2081 | */ |
| 2082 | @IntDef(prefix = { "SEMANTIC_ACTION_" }, value = { |
| 2083 | SEMANTIC_ACTION_NONE, |
| 2084 | SEMANTIC_ACTION_REPLY, |
| 2085 | SEMANTIC_ACTION_MARK_AS_READ, |
| 2086 | SEMANTIC_ACTION_MARK_AS_UNREAD, |
| 2087 | SEMANTIC_ACTION_DELETE, |
| 2088 | SEMANTIC_ACTION_ARCHIVE, |
| 2089 | SEMANTIC_ACTION_MUTE, |
| 2090 | SEMANTIC_ACTION_UNMUTE, |
| 2091 | SEMANTIC_ACTION_THUMBS_UP, |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 2092 | SEMANTIC_ACTION_THUMBS_DOWN, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 2093 | SEMANTIC_ACTION_CALL |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2094 | }) |
| 2095 | @Retention(RetentionPolicy.SOURCE) |
| 2096 | public @interface SemanticAction {} |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2097 | } |
| 2098 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2099 | /** |
| 2100 | * Array of all {@link Action} structures attached to this notification by |
| 2101 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 2102 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 2103 | * interface for invoking actions. |
| 2104 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 2105 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2106 | |
| 2107 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2108 | * Replacement version of this notification whose content will be shown |
| 2109 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 2110 | * and {@link #VISIBILITY_PUBLIC}. |
| 2111 | */ |
| 2112 | public Notification publicVersion; |
| 2113 | |
| 2114 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2115 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2116 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2117 | */ |
| 2118 | public Notification() |
| 2119 | { |
| 2120 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2121 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2122 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | * @hide |
| 2127 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2128 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2129 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 2130 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 2131 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2132 | new Builder(context) |
| 2133 | .setWhen(when) |
| 2134 | .setSmallIcon(icon) |
| 2135 | .setTicker(tickerText) |
| 2136 | .setContentTitle(contentTitle) |
| 2137 | .setContentText(contentText) |
| 2138 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 2139 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | /** |
| 2143 | * Constructs a Notification object with the information needed to |
| 2144 | * have a status bar icon without the standard expanded view. |
| 2145 | * |
| 2146 | * @param icon The resource id of the icon to put in the status bar. |
| 2147 | * @param tickerText The text that flows by in the status bar when the notification first |
| 2148 | * activates. |
| 2149 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 2150 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2151 | * |
| 2152 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2153 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2154 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2155 | public Notification(int icon, CharSequence tickerText, long when) |
| 2156 | { |
| 2157 | this.icon = icon; |
| 2158 | this.tickerText = tickerText; |
| 2159 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2160 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | /** |
| 2164 | * Unflatten the notification from a parcel. |
| 2165 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2166 | @SuppressWarnings("unchecked") |
| 2167 | public Notification(Parcel parcel) { |
| 2168 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 2169 | // intents in extras are always written as the last entry. |
| 2170 | readFromParcelImpl(parcel); |
| 2171 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2172 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2176 | { |
| 2177 | int version = parcel.readInt(); |
| 2178 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2179 | mWhitelistToken = parcel.readStrongBinder(); |
| 2180 | if (mWhitelistToken == null) { |
| 2181 | mWhitelistToken = processWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2182 | } |
| 2183 | // Propagate this token to all pending intents that are unmarshalled from the parcel. |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2184 | parcel.setClassCookie(PendingIntent.class, mWhitelistToken); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2186 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2187 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2188 | if (parcel.readInt() != 0) { |
| 2189 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2190 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 2191 | icon = mSmallIcon.getResId(); |
| 2192 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2193 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2194 | number = parcel.readInt(); |
| 2195 | if (parcel.readInt() != 0) { |
| 2196 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2197 | } |
| 2198 | if (parcel.readInt() != 0) { |
| 2199 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2200 | } |
| 2201 | if (parcel.readInt() != 0) { |
| 2202 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2203 | } |
| 2204 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2205 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2206 | } |
| 2207 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2208 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2209 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2210 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2211 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2212 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2213 | defaults = parcel.readInt(); |
| 2214 | flags = parcel.readInt(); |
| 2215 | if (parcel.readInt() != 0) { |
| 2216 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 2217 | } |
| 2218 | |
| 2219 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2220 | if (parcel.readInt() != 0) { |
| 2221 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 2222 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2223 | vibrate = parcel.createLongArray(); |
| 2224 | ledARGB = parcel.readInt(); |
| 2225 | ledOnMS = parcel.readInt(); |
| 2226 | ledOffMS = parcel.readInt(); |
| 2227 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2228 | |
| 2229 | if (parcel.readInt() != 0) { |
| 2230 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2231 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2232 | |
| 2233 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2234 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2235 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2236 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2237 | mGroupKey = parcel.readString(); |
| 2238 | |
| 2239 | mSortKey = parcel.readString(); |
| 2240 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 2241 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2242 | fixDuplicateExtras(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2243 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2244 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 2245 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2246 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2247 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2248 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2249 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2250 | if (parcel.readInt() != 0) { |
| 2251 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2252 | } |
| 2253 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2254 | visibility = parcel.readInt(); |
| 2255 | |
| 2256 | if (parcel.readInt() != 0) { |
| 2257 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 2258 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2259 | |
| 2260 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2261 | |
| 2262 | if (parcel.readInt() != 0) { |
| 2263 | mChannelId = parcel.readString(); |
| 2264 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2265 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2266 | |
| 2267 | if (parcel.readInt() != 0) { |
| 2268 | mShortcutId = parcel.readString(); |
| 2269 | } |
| 2270 | |
| 2271 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2272 | |
| 2273 | if (parcel.readInt() != 0) { |
| 2274 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2275 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2276 | |
| 2277 | mGroupAlertBehavior = parcel.readInt(); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2278 | if (parcel.readInt() != 0) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2279 | mBubbleMetadata = BubbleMetadata.CREATOR.createFromParcel(parcel); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2280 | } |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2281 | |
| 2282 | mAllowSystemGeneratedContextualActions = parcel.readBoolean(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2283 | } |
| 2284 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2285 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2286 | public Notification clone() { |
| 2287 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2288 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2289 | return that; |
| 2290 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2291 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2292 | /** |
| 2293 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 2294 | * of this into that. |
| 2295 | * @hide |
| 2296 | */ |
| 2297 | public void cloneInto(Notification that, boolean heavy) { |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2298 | that.mWhitelistToken = this.mWhitelistToken; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2299 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2300 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2301 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2302 | that.number = this.number; |
| 2303 | |
| 2304 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 2305 | that.contentIntent = this.contentIntent; |
| 2306 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2307 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2308 | |
| 2309 | if (this.tickerText != null) { |
| 2310 | that.tickerText = this.tickerText.toString(); |
| 2311 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2312 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2313 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2314 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2315 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2316 | that.contentView = this.contentView.clone(); |
| 2317 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2318 | if (heavy && this.mLargeIcon != null) { |
| 2319 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2320 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 2321 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2322 | that.sound = this.sound; // android.net.Uri is immutable |
| 2323 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2324 | if (this.audioAttributes != null) { |
| 2325 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 2326 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2327 | |
| 2328 | final long[] vibrate = this.vibrate; |
| 2329 | if (vibrate != null) { |
| 2330 | final int N = vibrate.length; |
| 2331 | final long[] vib = that.vibrate = new long[N]; |
| 2332 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 2333 | } |
| 2334 | |
| 2335 | that.ledARGB = this.ledARGB; |
| 2336 | that.ledOnMS = this.ledOnMS; |
| 2337 | that.ledOffMS = this.ledOffMS; |
| 2338 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2339 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2340 | that.flags = this.flags; |
| 2341 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2342 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2343 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2344 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2345 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2346 | that.mGroupKey = this.mGroupKey; |
| 2347 | |
| 2348 | that.mSortKey = this.mSortKey; |
| 2349 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2350 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2351 | try { |
| 2352 | that.extras = new Bundle(this.extras); |
| 2353 | // will unparcel |
| 2354 | that.extras.size(); |
| 2355 | } catch (BadParcelableException e) { |
| 2356 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2357 | that.extras = null; |
| 2358 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2359 | } |
| 2360 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2361 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2362 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2363 | } |
| 2364 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2365 | if (this.actions != null) { |
| 2366 | that.actions = new Action[this.actions.length]; |
| 2367 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 2368 | if ( this.actions[i] != null) { |
| 2369 | that.actions[i] = this.actions[i].clone(); |
| 2370 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2371 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2372 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2373 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2374 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2375 | that.bigContentView = this.bigContentView.clone(); |
| 2376 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2377 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2378 | if (heavy && this.headsUpContentView != null) { |
| 2379 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 2380 | } |
| 2381 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2382 | that.visibility = this.visibility; |
| 2383 | |
| 2384 | if (this.publicVersion != null) { |
| 2385 | that.publicVersion = new Notification(); |
| 2386 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2387 | } |
| 2388 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2389 | that.color = this.color; |
| 2390 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2391 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2392 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2393 | that.mShortcutId = this.mShortcutId; |
| 2394 | that.mBadgeIcon = this.mBadgeIcon; |
| 2395 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2396 | that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2397 | that.mBubbleMetadata = this.mBubbleMetadata; |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2398 | that.mAllowSystemGeneratedContextualActions = this.mAllowSystemGeneratedContextualActions; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2399 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2400 | if (!heavy) { |
| 2401 | that.lightenPayload(); // will clean out extras |
| 2402 | } |
| 2403 | } |
| 2404 | |
| 2405 | /** |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2406 | * Note all {@link Uri} that are referenced internally, with the expectation |
| 2407 | * that Uri permission grants will need to be issued to ensure the recipient |
| 2408 | * of this object is able to render its contents. |
| 2409 | * |
| 2410 | * @hide |
| 2411 | */ |
| 2412 | public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 2413 | visitor.accept(sound); |
| 2414 | |
| 2415 | if (tickerView != null) tickerView.visitUris(visitor); |
| 2416 | if (contentView != null) contentView.visitUris(visitor); |
| 2417 | if (bigContentView != null) bigContentView.visitUris(visitor); |
| 2418 | if (headsUpContentView != null) headsUpContentView.visitUris(visitor); |
| 2419 | |
| 2420 | if (extras != null) { |
| 2421 | visitor.accept(extras.getParcelable(EXTRA_AUDIO_CONTENTS_URI)); |
Robin Lee | d107af6 | 2018-04-27 13:55:56 +0200 | [diff] [blame] | 2422 | if (extras.containsKey(EXTRA_BACKGROUND_IMAGE_URI)) { |
| 2423 | visitor.accept(Uri.parse(extras.getString(EXTRA_BACKGROUND_IMAGE_URI))); |
| 2424 | } |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | if (MessagingStyle.class.equals(getNotificationStyle()) && extras != null) { |
| 2428 | final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 2429 | if (!ArrayUtils.isEmpty(messages)) { |
| 2430 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2431 | .getMessagesFromBundleArray(messages)) { |
| 2432 | visitor.accept(message.getDataUri()); |
| 2433 | } |
| 2434 | } |
| 2435 | |
| 2436 | final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 2437 | if (!ArrayUtils.isEmpty(historic)) { |
| 2438 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2439 | .getMessagesFromBundleArray(historic)) { |
| 2440 | visitor.accept(message.getDataUri()); |
| 2441 | } |
| 2442 | } |
| 2443 | } |
| 2444 | } |
| 2445 | |
| 2446 | /** |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2447 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 2448 | * listeners when the full contents are not necessary. |
| 2449 | * @hide |
| 2450 | */ |
| 2451 | public final void lightenPayload() { |
| 2452 | tickerView = null; |
| 2453 | contentView = null; |
| 2454 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2455 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2456 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2457 | if (extras != null && !extras.isEmpty()) { |
| 2458 | final Set<String> keyset = extras.keySet(); |
| 2459 | final int N = keyset.size(); |
| 2460 | final String[] keys = keyset.toArray(new String[N]); |
| 2461 | for (int i=0; i<N; i++) { |
| 2462 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2463 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2464 | continue; |
| 2465 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2466 | final Object obj = extras.get(key); |
| 2467 | if (obj != null && |
| 2468 | ( obj instanceof Parcelable |
| 2469 | || obj instanceof Parcelable[] |
| 2470 | || obj instanceof SparseArray |
| 2471 | || obj instanceof ArrayList)) { |
| 2472 | extras.remove(key); |
| 2473 | } |
| 2474 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2475 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2478 | /** |
| 2479 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2480 | * means it had better not be some custom Parcelable implementation. |
| 2481 | * @hide |
| 2482 | */ |
| 2483 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2484 | if (cs == null) return cs; |
| 2485 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2486 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2487 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2488 | if (cs instanceof Parcelable) { |
| 2489 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2490 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2491 | return cs.toString(); |
| 2492 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2493 | return removeTextSizeSpans(cs); |
| 2494 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2495 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2496 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2497 | if (charSequence instanceof Spanned) { |
| 2498 | Spanned ss = (Spanned) charSequence; |
| 2499 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2500 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2501 | for (Object span : spans) { |
| 2502 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2503 | if (resultSpan instanceof CharacterStyle) { |
| 2504 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2505 | } |
| 2506 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2507 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2508 | resultSpan = new TextAppearanceSpan( |
| 2509 | originalSpan.getFamily(), |
| 2510 | originalSpan.getTextStyle(), |
| 2511 | -1, |
| 2512 | originalSpan.getTextColor(), |
| 2513 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2514 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2515 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2516 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2517 | } else { |
| 2518 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2519 | } |
| 2520 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2521 | ss.getSpanFlags(span)); |
| 2522 | } |
| 2523 | return builder; |
| 2524 | } |
| 2525 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2526 | } |
| 2527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | public int describeContents() { |
| 2529 | return 0; |
| 2530 | } |
| 2531 | |
| 2532 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2533 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2535 | public void writeToParcel(Parcel parcel, int flags) { |
| 2536 | // We need to mark all pending intents getting into the notification |
| 2537 | // system as being put there to later allow the notification ranker |
| 2538 | // to launch them and by doing so add the app to the battery saver white |
| 2539 | // list for a short period of time. The problem is that the system |
| 2540 | // cannot look into the extras as there may be parcelables there that |
| 2541 | // the platform does not know how to handle. To go around that we have |
| 2542 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2543 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2544 | if (collectPendingIntents) { |
| 2545 | PendingIntent.setOnMarshaledListener( |
| 2546 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2547 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2548 | if (allPendingIntents == null) { |
| 2549 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2550 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2551 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2552 | } |
| 2553 | }); |
| 2554 | } |
| 2555 | try { |
| 2556 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2557 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2558 | writeToParcelImpl(parcel, flags); |
| 2559 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2560 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2561 | } finally { |
| 2562 | if (collectPendingIntents) { |
| 2563 | PendingIntent.setOnMarshaledListener(null); |
| 2564 | } |
| 2565 | } |
| 2566 | } |
| 2567 | |
| 2568 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2569 | parcel.writeInt(1); |
| 2570 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2571 | parcel.writeStrongBinder(mWhitelistToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2572 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2573 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2574 | if (mSmallIcon == null && icon != 0) { |
| 2575 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2576 | mSmallIcon = Icon.createWithResource("", icon); |
| 2577 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2578 | if (mSmallIcon != null) { |
| 2579 | parcel.writeInt(1); |
| 2580 | mSmallIcon.writeToParcel(parcel, 0); |
| 2581 | } else { |
| 2582 | parcel.writeInt(0); |
| 2583 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2584 | parcel.writeInt(number); |
| 2585 | if (contentIntent != null) { |
| 2586 | parcel.writeInt(1); |
| 2587 | contentIntent.writeToParcel(parcel, 0); |
| 2588 | } else { |
| 2589 | parcel.writeInt(0); |
| 2590 | } |
| 2591 | if (deleteIntent != null) { |
| 2592 | parcel.writeInt(1); |
| 2593 | deleteIntent.writeToParcel(parcel, 0); |
| 2594 | } else { |
| 2595 | parcel.writeInt(0); |
| 2596 | } |
| 2597 | if (tickerText != null) { |
| 2598 | parcel.writeInt(1); |
| 2599 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2600 | } else { |
| 2601 | parcel.writeInt(0); |
| 2602 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2603 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2604 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2605 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2606 | } else { |
| 2607 | parcel.writeInt(0); |
| 2608 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2609 | if (contentView != null) { |
| 2610 | parcel.writeInt(1); |
| 2611 | contentView.writeToParcel(parcel, 0); |
| 2612 | } else { |
| 2613 | parcel.writeInt(0); |
| 2614 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2615 | if (mLargeIcon == null && largeIcon != null) { |
| 2616 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2617 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2618 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2619 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2620 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2621 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2622 | } else { |
| 2623 | parcel.writeInt(0); |
| 2624 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | |
| 2626 | parcel.writeInt(defaults); |
| 2627 | parcel.writeInt(this.flags); |
| 2628 | |
| 2629 | if (sound != null) { |
| 2630 | parcel.writeInt(1); |
| 2631 | sound.writeToParcel(parcel, 0); |
| 2632 | } else { |
| 2633 | parcel.writeInt(0); |
| 2634 | } |
| 2635 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2636 | |
| 2637 | if (audioAttributes != null) { |
| 2638 | parcel.writeInt(1); |
| 2639 | audioAttributes.writeToParcel(parcel, 0); |
| 2640 | } else { |
| 2641 | parcel.writeInt(0); |
| 2642 | } |
| 2643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2644 | parcel.writeLongArray(vibrate); |
| 2645 | parcel.writeInt(ledARGB); |
| 2646 | parcel.writeInt(ledOnMS); |
| 2647 | parcel.writeInt(ledOffMS); |
| 2648 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2649 | |
| 2650 | if (fullScreenIntent != null) { |
| 2651 | parcel.writeInt(1); |
| 2652 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2653 | } else { |
| 2654 | parcel.writeInt(0); |
| 2655 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2656 | |
| 2657 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2658 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2659 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2660 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2661 | parcel.writeString(mGroupKey); |
| 2662 | |
| 2663 | parcel.writeString(mSortKey); |
| 2664 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2665 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2666 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2667 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2668 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2669 | if (bigContentView != null) { |
| 2670 | parcel.writeInt(1); |
| 2671 | bigContentView.writeToParcel(parcel, 0); |
| 2672 | } else { |
| 2673 | parcel.writeInt(0); |
| 2674 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2675 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2676 | if (headsUpContentView != null) { |
| 2677 | parcel.writeInt(1); |
| 2678 | headsUpContentView.writeToParcel(parcel, 0); |
| 2679 | } else { |
| 2680 | parcel.writeInt(0); |
| 2681 | } |
| 2682 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2683 | parcel.writeInt(visibility); |
| 2684 | |
| 2685 | if (publicVersion != null) { |
| 2686 | parcel.writeInt(1); |
| 2687 | publicVersion.writeToParcel(parcel, 0); |
| 2688 | } else { |
| 2689 | parcel.writeInt(0); |
| 2690 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2691 | |
| 2692 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2693 | |
| 2694 | if (mChannelId != null) { |
| 2695 | parcel.writeInt(1); |
| 2696 | parcel.writeString(mChannelId); |
| 2697 | } else { |
| 2698 | parcel.writeInt(0); |
| 2699 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2700 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2701 | |
| 2702 | if (mShortcutId != null) { |
| 2703 | parcel.writeInt(1); |
| 2704 | parcel.writeString(mShortcutId); |
| 2705 | } else { |
| 2706 | parcel.writeInt(0); |
| 2707 | } |
| 2708 | |
| 2709 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2710 | |
| 2711 | if (mSettingsText != null) { |
| 2712 | parcel.writeInt(1); |
| 2713 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2714 | } else { |
| 2715 | parcel.writeInt(0); |
| 2716 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2717 | |
| 2718 | parcel.writeInt(mGroupAlertBehavior); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2719 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2720 | if (mBubbleMetadata != null) { |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2721 | parcel.writeInt(1); |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2722 | mBubbleMetadata.writeToParcel(parcel, 0); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2723 | } else { |
| 2724 | parcel.writeInt(0); |
| 2725 | } |
| 2726 | |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2727 | parcel.writeBoolean(mAllowSystemGeneratedContextualActions); |
| 2728 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2729 | // mUsesStandardHeader is not written because it should be recomputed in listeners |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | /** |
| 2733 | * Parcelable.Creator that instantiates Notification objects |
| 2734 | */ |
| 2735 | public static final Parcelable.Creator<Notification> CREATOR |
| 2736 | = new Parcelable.Creator<Notification>() |
| 2737 | { |
| 2738 | public Notification createFromParcel(Parcel parcel) |
| 2739 | { |
| 2740 | return new Notification(parcel); |
| 2741 | } |
| 2742 | |
| 2743 | public Notification[] newArray(int size) |
| 2744 | { |
| 2745 | return new Notification[size]; |
| 2746 | } |
| 2747 | }; |
| 2748 | |
| 2749 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2750 | * @hide |
| 2751 | */ |
| 2752 | public static boolean areActionsVisiblyDifferent(Notification first, Notification second) { |
| 2753 | Notification.Action[] firstAs = first.actions; |
| 2754 | Notification.Action[] secondAs = second.actions; |
| 2755 | if (firstAs == null && secondAs != null || firstAs != null && secondAs == null) { |
| 2756 | return true; |
| 2757 | } |
| 2758 | if (firstAs != null && secondAs != null) { |
| 2759 | if (firstAs.length != secondAs.length) { |
| 2760 | return true; |
| 2761 | } |
| 2762 | for (int i = 0; i < firstAs.length; i++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2763 | if (!Objects.equals(String.valueOf(firstAs[i].title), |
| 2764 | String.valueOf(secondAs[i].title))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2765 | return true; |
| 2766 | } |
| 2767 | RemoteInput[] firstRs = firstAs[i].getRemoteInputs(); |
| 2768 | RemoteInput[] secondRs = secondAs[i].getRemoteInputs(); |
| 2769 | if (firstRs == null) { |
| 2770 | firstRs = new RemoteInput[0]; |
| 2771 | } |
| 2772 | if (secondRs == null) { |
| 2773 | secondRs = new RemoteInput[0]; |
| 2774 | } |
| 2775 | if (firstRs.length != secondRs.length) { |
| 2776 | return true; |
| 2777 | } |
| 2778 | for (int j = 0; j < firstRs.length; j++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2779 | if (!Objects.equals(String.valueOf(firstRs[j].getLabel()), |
| 2780 | String.valueOf(secondRs[j].getLabel()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2781 | return true; |
| 2782 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2783 | } |
| 2784 | } |
| 2785 | } |
| 2786 | return false; |
| 2787 | } |
| 2788 | |
| 2789 | /** |
| 2790 | * @hide |
| 2791 | */ |
| 2792 | public static boolean areStyledNotificationsVisiblyDifferent(Builder first, Builder second) { |
| 2793 | if (first.getStyle() == null) { |
| 2794 | return second.getStyle() != null; |
| 2795 | } |
| 2796 | if (second.getStyle() == null) { |
| 2797 | return true; |
| 2798 | } |
| 2799 | return first.getStyle().areNotificationsVisiblyDifferent(second.getStyle()); |
| 2800 | } |
| 2801 | |
| 2802 | /** |
| 2803 | * @hide |
| 2804 | */ |
| 2805 | public static boolean areRemoteViewsChanged(Builder first, Builder second) { |
Julia Reynolds | e5c6045 | 2018-04-30 14:41:36 -0400 | [diff] [blame] | 2806 | if (!Objects.equals(first.usesStandardHeader(), second.usesStandardHeader())) { |
| 2807 | return true; |
| 2808 | } |
| 2809 | |
| 2810 | if (areRemoteViewsChanged(first.mN.contentView, second.mN.contentView)) { |
| 2811 | return true; |
| 2812 | } |
| 2813 | if (areRemoteViewsChanged(first.mN.bigContentView, second.mN.bigContentView)) { |
| 2814 | return true; |
| 2815 | } |
| 2816 | if (areRemoteViewsChanged(first.mN.headsUpContentView, second.mN.headsUpContentView)) { |
| 2817 | return true; |
| 2818 | } |
| 2819 | |
| 2820 | return false; |
| 2821 | } |
| 2822 | |
| 2823 | private static boolean areRemoteViewsChanged(RemoteViews first, RemoteViews second) { |
| 2824 | if (first == null && second == null) { |
| 2825 | return false; |
| 2826 | } |
| 2827 | if (first == null && second != null || first != null && second == null) { |
| 2828 | return true; |
| 2829 | } |
| 2830 | |
| 2831 | if (!Objects.equals(first.getLayoutId(), second.getLayoutId())) { |
| 2832 | return true; |
| 2833 | } |
| 2834 | |
| 2835 | if (!Objects.equals(first.getSequenceNumber(), second.getSequenceNumber())) { |
| 2836 | return true; |
| 2837 | } |
| 2838 | |
| 2839 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | /** |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2843 | * Parcelling creates multiple copies of objects in {@code extras}. Fix them. |
| 2844 | * <p> |
| 2845 | * For backwards compatibility {@code extras} holds some references to "real" member data such |
| 2846 | * as {@link getLargeIcon()} which is mirrored by {@link #EXTRA_LARGE_ICON}. This is mostly |
| 2847 | * fine as long as the object stays in one process. |
| 2848 | * <p> |
| 2849 | * However, once the notification goes into a parcel each reference gets marshalled separately, |
| 2850 | * wasting memory. Especially with large images on Auto and TV, this is worth fixing. |
| 2851 | */ |
| 2852 | private void fixDuplicateExtras() { |
| 2853 | if (extras != null) { |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2854 | fixDuplicateExtra(mLargeIcon, EXTRA_LARGE_ICON); |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | /** |
| 2859 | * If we find an extra that's exactly the same as one of the "real" fields but refers to a |
| 2860 | * separate object, replace it with the field's version to avoid holding duplicate copies. |
| 2861 | */ |
| 2862 | private void fixDuplicateExtra(@Nullable Parcelable original, @NonNull String extraName) { |
| 2863 | if (original != null && extras.getParcelable(extraName) != null) { |
| 2864 | extras.putParcelable(extraName, original); |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2869 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2870 | * layout. |
| 2871 | * |
| 2872 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2873 | * in the view.</p> |
| 2874 | * @param context The context for your application / activity. |
| 2875 | * @param contentTitle The title that goes in the expanded entry. |
| 2876 | * @param contentText The text that goes in the expanded entry. |
| 2877 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2878 | * If this is an activity, it must include the |
| 2879 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2880 | * that you take care of task management as described in the |
| 2881 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2882 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2883 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2884 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2885 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2886 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2887 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2888 | public void setLatestEventInfo(Context context, |
| 2889 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2890 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2891 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2892 | new Throwable()); |
| 2893 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2894 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2895 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2896 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2897 | } |
| 2898 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2899 | // ensure that any information already set directly is preserved |
| 2900 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2901 | |
| 2902 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2904 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | } |
| 2906 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2907 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2908 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2909 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2910 | |
| 2911 | 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] | 2912 | } |
| 2913 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2914 | /** |
| 2915 | * @hide |
| 2916 | */ |
| 2917 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2918 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | /** |
| 2922 | * @hide |
| 2923 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2924 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2925 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2926 | } |
| 2927 | |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 2928 | /** |
| 2929 | * @hide |
| 2930 | */ |
| 2931 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 2932 | long token = proto.start(fieldId); |
| 2933 | proto.write(NotificationProto.CHANNEL_ID, getChannelId()); |
| 2934 | proto.write(NotificationProto.HAS_TICKER_TEXT, this.tickerText != null); |
| 2935 | proto.write(NotificationProto.FLAGS, this.flags); |
| 2936 | proto.write(NotificationProto.COLOR, this.color); |
| 2937 | proto.write(NotificationProto.CATEGORY, this.category); |
| 2938 | proto.write(NotificationProto.GROUP_KEY, this.mGroupKey); |
| 2939 | proto.write(NotificationProto.SORT_KEY, this.mSortKey); |
| 2940 | if (this.actions != null) { |
| 2941 | proto.write(NotificationProto.ACTION_LENGTH, this.actions.length); |
| 2942 | } |
| 2943 | if (this.visibility >= VISIBILITY_SECRET && this.visibility <= VISIBILITY_PUBLIC) { |
| 2944 | proto.write(NotificationProto.VISIBILITY, this.visibility); |
| 2945 | } |
| 2946 | if (publicVersion != null) { |
| 2947 | publicVersion.writeToProto(proto, NotificationProto.PUBLIC_VERSION); |
| 2948 | } |
| 2949 | proto.end(token); |
| 2950 | } |
| 2951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2952 | @Override |
| 2953 | public String toString() { |
| 2954 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2955 | sb.append("Notification(channel="); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2956 | sb.append(getChannelId()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2957 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2958 | sb.append(priority); |
| 2959 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2960 | if (contentView != null) { |
| 2961 | sb.append(contentView.getPackage()); |
| 2962 | sb.append("/0x"); |
| 2963 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2964 | } else { |
| 2965 | sb.append("null"); |
| 2966 | } |
| 2967 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2968 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2969 | sb.append("default"); |
| 2970 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | int N = this.vibrate.length-1; |
| 2972 | sb.append("["); |
| 2973 | for (int i=0; i<N; i++) { |
| 2974 | sb.append(this.vibrate[i]); |
| 2975 | sb.append(','); |
| 2976 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 2977 | if (N != -1) { |
| 2978 | sb.append(this.vibrate[N]); |
| 2979 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2980 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2981 | } else { |
| 2982 | sb.append("null"); |
| 2983 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2984 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2985 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2987 | } else if (this.sound != null) { |
| 2988 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2989 | } else { |
| 2990 | sb.append("null"); |
| 2991 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 2992 | if (this.tickerText != null) { |
| 2993 | sb.append(" tick"); |
| 2994 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2995 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2996 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2997 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2998 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2999 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3000 | if (this.category != null) { |
| 3001 | sb.append(" category="); |
| 3002 | sb.append(this.category); |
| 3003 | } |
| 3004 | if (this.mGroupKey != null) { |
| 3005 | sb.append(" groupKey="); |
| 3006 | sb.append(this.mGroupKey); |
| 3007 | } |
| 3008 | if (this.mSortKey != null) { |
| 3009 | sb.append(" sortKey="); |
| 3010 | sb.append(this.mSortKey); |
| 3011 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3012 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 3013 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3014 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 3015 | } |
| 3016 | sb.append(" vis="); |
| 3017 | sb.append(visibilityToString(this.visibility)); |
| 3018 | if (this.publicVersion != null) { |
| 3019 | sb.append(" publicVersion="); |
| 3020 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3021 | } |
| 3022 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | return sb.toString(); |
| 3024 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3025 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 3026 | /** |
| 3027 | * {@hide} |
| 3028 | */ |
| 3029 | public static String visibilityToString(int vis) { |
| 3030 | switch (vis) { |
| 3031 | case VISIBILITY_PRIVATE: |
| 3032 | return "PRIVATE"; |
| 3033 | case VISIBILITY_PUBLIC: |
| 3034 | return "PUBLIC"; |
| 3035 | case VISIBILITY_SECRET: |
| 3036 | return "SECRET"; |
| 3037 | default: |
| 3038 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 3039 | } |
| 3040 | } |
| 3041 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3042 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 3043 | * {@hide} |
| 3044 | */ |
| 3045 | public static String priorityToString(@Priority int pri) { |
| 3046 | switch (pri) { |
| 3047 | case PRIORITY_MIN: |
| 3048 | return "MIN"; |
| 3049 | case PRIORITY_LOW: |
| 3050 | return "LOW"; |
| 3051 | case PRIORITY_DEFAULT: |
| 3052 | return "DEFAULT"; |
| 3053 | case PRIORITY_HIGH: |
| 3054 | return "HIGH"; |
| 3055 | case PRIORITY_MAX: |
| 3056 | return "MAX"; |
| 3057 | default: |
| 3058 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 3059 | } |
| 3060 | } |
| 3061 | |
Julia Reynolds | 6ad0aec | 2017-07-05 08:47:03 -0400 | [diff] [blame] | 3062 | /** |
| 3063 | * @hide |
| 3064 | */ |
| 3065 | public boolean hasCompletedProgress() { |
| 3066 | // not a progress notification; can't be complete |
| 3067 | if (!extras.containsKey(EXTRA_PROGRESS) |
| 3068 | || !extras.containsKey(EXTRA_PROGRESS_MAX)) { |
| 3069 | return false; |
| 3070 | } |
| 3071 | // many apps use max 0 for 'indeterminate'; not complete |
| 3072 | if (extras.getInt(EXTRA_PROGRESS_MAX) == 0) { |
| 3073 | return false; |
| 3074 | } |
| 3075 | return extras.getInt(EXTRA_PROGRESS) == extras.getInt(EXTRA_PROGRESS_MAX); |
| 3076 | } |
| 3077 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3078 | /** @removed */ |
| 3079 | @Deprecated |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 3080 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3081 | return mChannelId; |
| 3082 | } |
| 3083 | |
| 3084 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3085 | * Returns the id of the channel this notification posts to. |
| 3086 | */ |
| 3087 | public String getChannelId() { |
| 3088 | return mChannelId; |
| 3089 | } |
| 3090 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3091 | /** @removed */ |
| 3092 | @Deprecated |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3093 | public long getTimeout() { |
| 3094 | return mTimeout; |
| 3095 | } |
| 3096 | |
| 3097 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3098 | * Returns the duration from posting after which this notification should be canceled by the |
| 3099 | * system, if it's not canceled already. |
| 3100 | */ |
| 3101 | public long getTimeoutAfter() { |
| 3102 | return mTimeout; |
| 3103 | } |
| 3104 | |
| 3105 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3106 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 3107 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 3108 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 3109 | */ |
| 3110 | public int getBadgeIconType() { |
| 3111 | return mBadgeIcon; |
| 3112 | } |
| 3113 | |
| 3114 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3115 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3116 | * |
| 3117 | * <p>Used by some Launchers that display notification content to hide shortcuts that duplicate |
| 3118 | * notifications. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3119 | */ |
| 3120 | public String getShortcutId() { |
| 3121 | return mShortcutId; |
| 3122 | } |
| 3123 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3124 | |
| 3125 | /** |
| 3126 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 3127 | */ |
| 3128 | public CharSequence getSettingsText() { |
| 3129 | return mSettingsText; |
| 3130 | } |
| 3131 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3132 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3133 | * Returns which type of notifications in a group are responsible for audibly alerting the |
| 3134 | * user. See {@link #GROUP_ALERT_ALL}, {@link #GROUP_ALERT_CHILDREN}, |
| 3135 | * {@link #GROUP_ALERT_SUMMARY}. |
| 3136 | */ |
| 3137 | public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 3138 | return mGroupAlertBehavior; |
| 3139 | } |
| 3140 | |
| 3141 | /** |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3142 | * Returns the bubble metadata that will be used to display app content in a floating window |
| 3143 | * over the existing foreground activity. |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3144 | */ |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3145 | public BubbleMetadata getBubbleMetadata() { |
| 3146 | return mBubbleMetadata; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3147 | } |
| 3148 | |
Gustav Sennton | 79ebf4b | 2018-12-19 10:31:51 +0000 | [diff] [blame] | 3149 | /** |
| 3150 | * Returns whether the platform is allowed (by the app developer) to generate contextual actions |
| 3151 | * for this notification. |
| 3152 | */ |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 3153 | public boolean getAllowSystemGeneratedContextualActions() { |
| 3154 | return mAllowSystemGeneratedContextualActions; |
| 3155 | } |
| 3156 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3157 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3158 | * The small icon representing this notification in the status bar and content view. |
| 3159 | * |
| 3160 | * @return the small icon representing this notification. |
| 3161 | * |
| 3162 | * @see Builder#getSmallIcon() |
| 3163 | * @see Builder#setSmallIcon(Icon) |
| 3164 | */ |
| 3165 | public Icon getSmallIcon() { |
| 3166 | return mSmallIcon; |
| 3167 | } |
| 3168 | |
| 3169 | /** |
| 3170 | * Used when notifying to clean up legacy small icons. |
| 3171 | * @hide |
| 3172 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3173 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3174 | public void setSmallIcon(Icon icon) { |
| 3175 | mSmallIcon = icon; |
| 3176 | } |
| 3177 | |
| 3178 | /** |
| 3179 | * The large icon shown in this notification's content view. |
| 3180 | * @see Builder#getLargeIcon() |
| 3181 | * @see Builder#setLargeIcon(Icon) |
| 3182 | */ |
| 3183 | public Icon getLargeIcon() { |
| 3184 | return mLargeIcon; |
| 3185 | } |
| 3186 | |
| 3187 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3188 | * @hide |
| 3189 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3190 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3191 | public boolean isGroupSummary() { |
| 3192 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 3193 | } |
| 3194 | |
| 3195 | /** |
| 3196 | * @hide |
| 3197 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3198 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3199 | public boolean isGroupChild() { |
| 3200 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 3201 | } |
| 3202 | |
| 3203 | /** |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3204 | * @hide |
| 3205 | */ |
| 3206 | public boolean suppressAlertingDueToGrouping() { |
| 3207 | if (isGroupSummary() |
| 3208 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { |
| 3209 | return true; |
| 3210 | } else if (isGroupChild() |
| 3211 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { |
| 3212 | return true; |
| 3213 | } |
| 3214 | return false; |
| 3215 | } |
| 3216 | |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 3217 | |
| 3218 | /** |
| 3219 | * Finds and returns a remote input and its corresponding action. |
| 3220 | * |
| 3221 | * @param requiresFreeform requires the remoteinput to allow freeform or not. |
| 3222 | * @return the result pair, {@code null} if no result is found. |
| 3223 | * |
| 3224 | * @hide |
| 3225 | */ |
| 3226 | @Nullable |
| 3227 | public Pair<RemoteInput, Action> findRemoteInputActionPair(boolean requiresFreeform) { |
| 3228 | if (actions == null) { |
| 3229 | return null; |
| 3230 | } |
| 3231 | for (Notification.Action action : actions) { |
| 3232 | if (action.getRemoteInputs() == null) { |
| 3233 | continue; |
| 3234 | } |
| 3235 | RemoteInput resultRemoteInput = null; |
| 3236 | for (RemoteInput remoteInput : action.getRemoteInputs()) { |
| 3237 | if (remoteInput.getAllowFreeFormInput() || !requiresFreeform) { |
| 3238 | resultRemoteInput = remoteInput; |
| 3239 | } |
| 3240 | } |
| 3241 | if (resultRemoteInput != null) { |
| 3242 | return Pair.create(resultRemoteInput, action); |
| 3243 | } |
| 3244 | } |
| 3245 | return null; |
| 3246 | } |
| 3247 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3248 | /** |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 3249 | * Returns the actions that are contextual out of the actions in this notification. |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 3250 | * |
| 3251 | * @hide |
| 3252 | */ |
| 3253 | public List<Notification.Action> getContextualActions() { |
| 3254 | if (actions == null) return Collections.emptyList(); |
| 3255 | |
| 3256 | List<Notification.Action> contextualActions = new ArrayList<>(); |
| 3257 | for (Notification.Action action : actions) { |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 3258 | if (action.isContextual()) { |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 3259 | contextualActions.add(action); |
| 3260 | } |
| 3261 | } |
| 3262 | return contextualActions; |
| 3263 | } |
| 3264 | |
| 3265 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3266 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3267 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3268 | * 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] | 3269 | * content views using the platform's notification layout template. If your app supports |
| 3270 | * versions of Android as old as API level 4, you can instead use |
| 3271 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 3272 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 3273 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3274 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3275 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3276 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3277 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3278 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3279 | * .setContentTitle("New mail from " + sender.toString()) |
| 3280 | * .setContentText(subject) |
| 3281 | * .setSmallIcon(R.drawable.new_mail) |
| 3282 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3283 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3284 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3285 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3286 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3287 | /** |
| 3288 | * @hide |
| 3289 | */ |
| 3290 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 3291 | "android.rebuild.contentViewActionCount"; |
| 3292 | /** |
| 3293 | * @hide |
| 3294 | */ |
| 3295 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 3296 | = "android.rebuild.bigViewActionCount"; |
| 3297 | /** |
| 3298 | * @hide |
| 3299 | */ |
| 3300 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 3301 | = "android.rebuild.hudViewActionCount"; |
| 3302 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 3303 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 3304 | SystemProperties.getBoolean("notifications.only_title", true); |
| 3305 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3306 | /** |
| 3307 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3308 | * secondary text color when the background is light. |
| 3309 | */ |
| 3310 | private static final int LIGHTNESS_TEXT_DIFFERENCE_LIGHT = 20; |
| 3311 | |
| 3312 | /** |
| 3313 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3314 | * secondary text color when the background is dark. |
| 3315 | * A bit less then the above value, since it looks better on dark backgrounds. |
| 3316 | */ |
| 3317 | private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10; |
| 3318 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3319 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3320 | private Notification mN; |
| 3321 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3322 | private Style mStyle; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3323 | @UnsupportedAppUsage |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3324 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3325 | private ArrayList<Person> mPersonList = new ArrayList<>(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3326 | private ContrastColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3327 | private boolean mIsLegacy; |
| 3328 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3329 | |
| 3330 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3331 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 3332 | */ |
| 3333 | private int mCachedContrastColor = COLOR_INVALID; |
| 3334 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3335 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3336 | * Caches a ambient version of {@link #mCachedAmbientColorIsFor}. |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3337 | */ |
| 3338 | private int mCachedAmbientColor = COLOR_INVALID; |
| 3339 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3340 | /** |
| 3341 | * A neutral color color that can be used for icons. |
| 3342 | */ |
| 3343 | private int mNeutralColor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3344 | |
| 3345 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3346 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 3347 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 3348 | */ |
| 3349 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3350 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 3351 | private int mPrimaryTextColor = COLOR_INVALID; |
| 3352 | private int mSecondaryTextColor = COLOR_INVALID; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3353 | private int mBackgroundColor = COLOR_INVALID; |
| 3354 | private int mForegroundColor = COLOR_INVALID; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 3355 | /** |
| 3356 | * A temporary location where actions are stored. If != null the view originally has action |
| 3357 | * but doesn't have any for this inflation. |
| 3358 | */ |
| 3359 | private ArrayList<Action> mOriginalActions; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 3360 | private boolean mRebuildStyledRemoteViews; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3361 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3362 | private boolean mTintActionButtons; |
| 3363 | private boolean mInNightMode; |
| 3364 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3365 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3366 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3367 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3368 | * @param context |
| 3369 | * A {@link Context} that will be used by the Builder to construct the |
| 3370 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 3371 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3372 | * @param channelId |
| 3373 | * The constructed Notification will be posted on this |
| 3374 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 3375 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3376 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3377 | public Builder(Context context, String channelId) { |
| 3378 | this(context, (Notification) null); |
| 3379 | mN.mChannelId = channelId; |
| 3380 | } |
| 3381 | |
| 3382 | /** |
| 3383 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 3384 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 3385 | */ |
| 3386 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3387 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3388 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3389 | } |
| 3390 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3391 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3392 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3393 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3394 | public Builder(Context context, Notification toAdopt) { |
| 3395 | mContext = context; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3396 | Resources res = mContext.getResources(); |
| 3397 | mTintActionButtons = res.getBoolean(R.bool.config_tintNotificationActionButtons); |
| 3398 | |
| 3399 | if (res.getBoolean(R.bool.config_enableNightMode)) { |
| 3400 | Configuration currentConfig = res.getConfiguration(); |
| 3401 | mInNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 3402 | == Configuration.UI_MODE_NIGHT_YES; |
| 3403 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3404 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3405 | if (toAdopt == null) { |
| 3406 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3407 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 3408 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 3409 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3410 | mN.priority = PRIORITY_DEFAULT; |
| 3411 | mN.visibility = VISIBILITY_PRIVATE; |
| 3412 | } else { |
| 3413 | mN = toAdopt; |
| 3414 | if (mN.actions != null) { |
| 3415 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3416 | } |
| 3417 | |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3418 | if (mN.extras.containsKey(EXTRA_PEOPLE_LIST)) { |
| 3419 | ArrayList<Person> people = mN.extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 3420 | mPersonList.addAll(people); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3421 | } |
| 3422 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 3423 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 3424 | setSmallIcon(mN.icon); |
| 3425 | } |
| 3426 | |
| 3427 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 3428 | setLargeIcon(mN.largeIcon); |
| 3429 | } |
| 3430 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3431 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 3432 | if (!TextUtils.isEmpty(templateClass)) { |
| 3433 | final Class<? extends Style> styleClass |
| 3434 | = getNotificationStyleClass(templateClass); |
| 3435 | if (styleClass == null) { |
| 3436 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 3437 | } else { |
| 3438 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3439 | final Constructor<? extends Style> ctor = |
| 3440 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3441 | ctor.setAccessible(true); |
| 3442 | final Style style = ctor.newInstance(); |
| 3443 | style.restoreFromExtras(mN.extras); |
| 3444 | |
| 3445 | if (style != null) { |
| 3446 | setStyle(style); |
| 3447 | } |
| 3448 | } catch (Throwable t) { |
| 3449 | Log.e(TAG, "Could not create Style", t); |
| 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | } |
| 3455 | } |
| 3456 | |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3457 | private ContrastColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3458 | if (mColorUtil == null) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3459 | mColorUtil = ContrastColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3460 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3461 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3465 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 3466 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 3467 | * the shortcut. |
| 3468 | * |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3469 | * This field will be ignored by Launchers that don't support badging, don't show |
| 3470 | * notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3471 | * |
| 3472 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 3473 | * supersedes |
| 3474 | */ |
| 3475 | public Builder setShortcutId(String shortcutId) { |
| 3476 | mN.mShortcutId = shortcutId; |
| 3477 | return this; |
| 3478 | } |
| 3479 | |
| 3480 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3481 | * Sets which icon to display as a badge for this notification. |
| 3482 | * |
| 3483 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 3484 | * {@link #BADGE_ICON_LARGE}. |
| 3485 | * |
| 3486 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 3487 | */ |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 3488 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3489 | mN.mBadgeIcon = icon; |
| 3490 | return this; |
| 3491 | } |
| 3492 | |
| 3493 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3494 | * Sets the group alert behavior for this notification. Use this method to mute this |
| 3495 | * notification if alerts for this notification's group should be handled by a different |
| 3496 | * notification. This is only applicable for notifications that belong to a |
Julia Reynolds | 399d9bf | 2017-08-11 12:52:14 -0400 | [diff] [blame] | 3497 | * {@link #setGroup(String) group}. This must be called on all notifications you want to |
| 3498 | * mute. For example, if you want only the summary of your group to make noise, all |
| 3499 | * children in the group should have the group alert behavior {@link #GROUP_ALERT_SUMMARY}. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3500 | * |
| 3501 | * <p> The default value is {@link #GROUP_ALERT_ALL}.</p> |
| 3502 | */ |
| 3503 | public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 3504 | mN.mGroupAlertBehavior = groupAlertBehavior; |
| 3505 | return this; |
| 3506 | } |
| 3507 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3508 | /** |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3509 | * Sets the {@link BubbleMetadata} that will be used to display app content in a floating |
| 3510 | * window over the existing foreground activity. |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3511 | * |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3512 | * <p>This data will be ignored unless the notification is posted to a channel that |
| 3513 | * allows {@link NotificationChannel#canBubble() bubbles}.</p> |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3514 | * |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3515 | * <b>Notifications with a valid and allowed bubble metadata will display in collapsed state |
| 3516 | * outside of the notification shade on unlocked devices. When a user interacts with the |
| 3517 | * collapsed state, the bubble intent will be invoked and displayed.</b> |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3518 | */ |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3519 | public Builder setBubbleMetadata(BubbleMetadata data) { |
| 3520 | mN.mBubbleMetadata = data; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3521 | return this; |
| 3522 | } |
| 3523 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3524 | /** @removed */ |
| 3525 | @Deprecated |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3526 | public Builder setChannel(String channelId) { |
| 3527 | mN.mChannelId = channelId; |
| 3528 | return this; |
| 3529 | } |
| 3530 | |
| 3531 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3532 | * Specifies the channel the notification should be delivered on. |
| 3533 | */ |
| 3534 | public Builder setChannelId(String channelId) { |
| 3535 | mN.mChannelId = channelId; |
| 3536 | return this; |
| 3537 | } |
| 3538 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3539 | /** @removed */ |
| 3540 | @Deprecated |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 3541 | public Builder setTimeout(long durationMs) { |
| 3542 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3543 | return this; |
| 3544 | } |
| 3545 | |
| 3546 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3547 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 3548 | * if it is not already canceled. |
| 3549 | */ |
| 3550 | public Builder setTimeoutAfter(long durationMs) { |
| 3551 | mN.mTimeout = durationMs; |
| 3552 | return this; |
| 3553 | } |
| 3554 | |
| 3555 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3556 | * Add a timestamp pertaining to the notification (usually the time the event occurred). |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3557 | * |
| 3558 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 3559 | * shown anymore by default and must be opted into by using |
| 3560 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3561 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3562 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3563 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3564 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3565 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3566 | return this; |
| 3567 | } |
| 3568 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3569 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 3570 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3571 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3572 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 3573 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3574 | */ |
| 3575 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3576 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3577 | return this; |
| 3578 | } |
| 3579 | |
| 3580 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3581 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3582 | * |
| 3583 | * 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] | 3584 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3585 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3586 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 3587 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3588 | * The counter can also be set to count down to <code>when</code> when using |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3589 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3590 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3591 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3592 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3593 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3594 | */ |
| 3595 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3596 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3597 | return this; |
| 3598 | } |
| 3599 | |
| 3600 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3601 | * Sets the Chronometer to count down instead of counting up. |
| 3602 | * |
| 3603 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 3604 | * If it isn't set the chronometer will count up. |
| 3605 | * |
| 3606 | * @see #setUsesChronometer(boolean) |
| 3607 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3608 | public Builder setChronometerCountDown(boolean countDown) { |
| 3609 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3610 | return this; |
| 3611 | } |
| 3612 | |
| 3613 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3614 | * Set the small icon resource, which will be used to represent the notification in the |
| 3615 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3616 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3617 | |
| 3618 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 3619 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 3620 | * icon will be moved to the right-hand side. |
| 3621 | * |
| 3622 | |
| 3623 | * @param icon |
| 3624 | * A resource ID in the application's package of the drawable to use. |
| 3625 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3626 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3627 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3628 | return setSmallIcon(icon != 0 |
| 3629 | ? Icon.createWithResource(mContext, icon) |
| 3630 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3631 | } |
| 3632 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3633 | /** |
| 3634 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 3635 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 3636 | * LevelListDrawable}. |
| 3637 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3638 | * @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] | 3639 | * @param level The level to use for the icon. |
| 3640 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3641 | * @see Notification#icon |
| 3642 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3643 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3644 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3645 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3646 | return setSmallIcon(icon); |
| 3647 | } |
| 3648 | |
| 3649 | /** |
| 3650 | * Set the small icon, which will be used to represent the notification in the |
kopriva | debd4ee | 2018-09-13 10:59:46 -0700 | [diff] [blame] | 3651 | * status bar and content view (unless overridden there by a |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3652 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 3653 | * |
| 3654 | * @param icon An Icon object to use. |
| 3655 | * @see Notification#icon |
| 3656 | */ |
| 3657 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3658 | mN.setSmallIcon(icon); |
| 3659 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 3660 | mN.icon = icon.getResId(); |
| 3661 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3662 | return this; |
| 3663 | } |
| 3664 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3665 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3666 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3667 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3668 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3669 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3670 | return this; |
| 3671 | } |
| 3672 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3673 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3674 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3675 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3676 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3677 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3678 | return this; |
| 3679 | } |
| 3680 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3681 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3682 | * This provides some additional information that is displayed in the notification. No |
| 3683 | * guarantees are given where exactly it is displayed. |
| 3684 | * |
| 3685 | * <p>This information should only be provided if it provides an essential |
| 3686 | * benefit to the understanding of the notification. The more text you provide the |
| 3687 | * less readable it becomes. For example, an email client should only provide the account |
| 3688 | * name here if more than one email account has been added.</p> |
| 3689 | * |
| 3690 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 3691 | * notification header area. |
| 3692 | * |
| 3693 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 3694 | * this will be shown in the third line of text in the platform notification template. |
| 3695 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 3696 | * same time on those versions; they occupy the same place. |
| 3697 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3698 | */ |
| 3699 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3700 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3701 | return this; |
| 3702 | } |
| 3703 | |
| 3704 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3705 | * Provides text that will appear as a link to your application's settings. |
| 3706 | * |
| 3707 | * <p>This text does not appear within notification {@link Style templates} but may |
| 3708 | * appear when the user uses an affordance to learn more about the notification. |
| 3709 | * Additionally, this text will not appear unless you provide a valid link target by |
| 3710 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 3711 | * |
| 3712 | * <p>This text is meant to be concise description about what the user can customize |
| 3713 | * when they click on this link. The recommended maximum length is 40 characters. |
| 3714 | * @param text |
| 3715 | * @return |
| 3716 | */ |
| 3717 | public Builder setSettingsText(CharSequence text) { |
| 3718 | mN.mSettingsText = safeCharSequence(text); |
| 3719 | return this; |
| 3720 | } |
| 3721 | |
| 3722 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3723 | * Set the remote input history. |
| 3724 | * |
| 3725 | * This should be set to the most recent inputs that have been sent |
| 3726 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 3727 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 3728 | * |
| 3729 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 3730 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 3731 | * and how much of each individual input is shown. |
| 3732 | * |
| 3733 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 3734 | * with a {@code RemoteInput}.</p> |
| 3735 | */ |
| 3736 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 3737 | if (text == null) { |
| 3738 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 3739 | } else { |
| 3740 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 3741 | CharSequence[] safe = new CharSequence[N]; |
| 3742 | for (int i = 0; i < N; i++) { |
| 3743 | safe[i] = safeCharSequence(text[i]); |
| 3744 | } |
| 3745 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 3746 | } |
| 3747 | return this; |
| 3748 | } |
| 3749 | |
| 3750 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 3751 | * Sets whether remote history entries view should have a spinner. |
| 3752 | * @hide |
| 3753 | */ |
| 3754 | public Builder setShowRemoteInputSpinner(boolean showSpinner) { |
| 3755 | mN.extras.putBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER, showSpinner); |
| 3756 | return this; |
| 3757 | } |
| 3758 | |
| 3759 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 3760 | * Sets whether smart reply buttons should be hidden. |
| 3761 | * @hide |
| 3762 | */ |
| 3763 | public Builder setHideSmartReplies(boolean hideSmartReplies) { |
| 3764 | mN.extras.putBoolean(EXTRA_HIDE_SMART_REPLIES, hideSmartReplies); |
| 3765 | return this; |
| 3766 | } |
| 3767 | |
| 3768 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3769 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 3770 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3771 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3772 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3773 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3774 | return this; |
| 3775 | } |
| 3776 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3777 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3778 | * A small piece of additional information pertaining to this notification. |
| 3779 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3780 | * The platform template will draw this on the last line of the notification, at the far |
| 3781 | * 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] | 3782 | * |
| 3783 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 3784 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 3785 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3786 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3787 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3788 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3789 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3790 | return this; |
| 3791 | } |
| 3792 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3793 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3794 | * Set the progress this notification represents. |
| 3795 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3796 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3797 | */ |
| 3798 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3799 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3800 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3801 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3802 | return this; |
| 3803 | } |
| 3804 | |
| 3805 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3806 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3807 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3808 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3809 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3810 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3811 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3812 | return setCustomContentView(views); |
| 3813 | } |
| 3814 | |
| 3815 | /** |
| 3816 | * Supply custom RemoteViews to use instead of the platform template. |
| 3817 | * |
| 3818 | * This will override the layout that would otherwise be constructed by this Builder |
| 3819 | * object. |
| 3820 | */ |
| 3821 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3822 | mN.contentView = contentView; |
| 3823 | return this; |
| 3824 | } |
| 3825 | |
| 3826 | /** |
| 3827 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3828 | * |
| 3829 | * This will override the expanded layout that would otherwise be constructed by this |
| 3830 | * Builder object. |
| 3831 | */ |
| 3832 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3833 | mN.bigContentView = contentView; |
| 3834 | return this; |
| 3835 | } |
| 3836 | |
| 3837 | /** |
| 3838 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3839 | * |
| 3840 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3841 | * Builder object. |
| 3842 | */ |
| 3843 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3844 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3845 | return this; |
| 3846 | } |
| 3847 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3848 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3849 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3850 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3851 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3852 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3853 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3854 | * 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] | 3855 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3856 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3857 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3858 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3859 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3860 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3861 | return this; |
| 3862 | } |
| 3863 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3864 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3865 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3866 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3867 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3868 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3869 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3870 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3871 | return this; |
| 3872 | } |
| 3873 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3874 | /** |
| 3875 | * An intent to launch instead of posting the notification to the status bar. |
| 3876 | * Only for use with extremely high-priority notifications demanding the user's |
| 3877 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3878 | * alarm clock that the user has explicitly set to a particular time. |
| 3879 | * If this facility is used for something else, please give the user an option |
| 3880 | * to turn it off and use a normal notification, as this can be extremely |
| 3881 | * disruptive. |
| 3882 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3883 | * <p> |
| 3884 | * The system UI may choose to display a heads-up notification, instead of |
| 3885 | * launching this intent, while the user is using the device. |
| 3886 | * </p> |
Julia Reynolds | 47fd15f | 2018-11-28 10:16:00 -0500 | [diff] [blame] | 3887 | * <p>Apps targeting {@link Build.VERSION_CODES#Q} and above will have to request |
| 3888 | * a permission ({@link android.Manifest.permission#USE_FULL_SCREEN_INTENT}) in order to |
| 3889 | * use full screen intents.</p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3890 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3891 | * @param intent The pending intent to launch. |
| 3892 | * @param highPriority Passing true will cause this notification to be sent |
| 3893 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3894 | * |
| 3895 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3896 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3897 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3898 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3899 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3900 | return this; |
| 3901 | } |
| 3902 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3903 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3904 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3905 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3906 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3907 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3908 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3909 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3910 | return this; |
| 3911 | } |
| 3912 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3913 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3914 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3915 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3916 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3917 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3918 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3919 | setTicker(tickerText); |
| 3920 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3921 | return this; |
| 3922 | } |
| 3923 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3924 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3925 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3926 | * |
| 3927 | * 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] | 3928 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3929 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3930 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3931 | public Builder setLargeIcon(Bitmap b) { |
| 3932 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3933 | } |
| 3934 | |
| 3935 | /** |
| 3936 | * Add a large icon to the notification content view. |
| 3937 | * |
| 3938 | * In the platform template, this image will be shown on the left of the notification view |
| 3939 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3940 | * badge atop the large icon). |
| 3941 | */ |
| 3942 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3943 | mN.mLargeIcon = icon; |
| 3944 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3945 | return this; |
| 3946 | } |
| 3947 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3948 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3949 | * Set the sound to play. |
| 3950 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3951 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 3952 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3953 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3954 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3955 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3956 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3957 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3958 | mN.sound = sound; |
| 3959 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3960 | return this; |
| 3961 | } |
| 3962 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3963 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3964 | * 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] | 3965 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3966 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 3967 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3968 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3969 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 3970 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3971 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 3972 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3973 | mN.sound = sound; |
| 3974 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3975 | return this; |
| 3976 | } |
| 3977 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3978 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3979 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 3980 | * use during playback. |
| 3981 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3982 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3983 | * @see Notification#sound |
| 3984 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3985 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3986 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3987 | mN.sound = sound; |
| 3988 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3989 | return this; |
| 3990 | } |
| 3991 | |
| 3992 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3993 | * Set the vibration pattern to use. |
| 3994 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3995 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 3996 | * <code>pattern</code> parameter. |
| 3997 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3998 | * <p> |
| 3999 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 4000 | * </p> |
| 4001 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4002 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4003 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4004 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4005 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4006 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4007 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4008 | return this; |
| 4009 | } |
| 4010 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4011 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4012 | * Set the desired color for the indicator LED on the device, as well as the |
| 4013 | * blink duty cycle (specified in milliseconds). |
| 4014 | * |
| 4015 | |
| 4016 | * Not all devices will honor all (or even any) of these values. |
| 4017 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 4018 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4019 | * @see Notification#ledARGB |
| 4020 | * @see Notification#ledOnMS |
| 4021 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4022 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4023 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4024 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4025 | mN.ledARGB = argb; |
| 4026 | mN.ledOnMS = onMs; |
| 4027 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4028 | if (onMs != 0 || offMs != 0) { |
| 4029 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 4030 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4031 | return this; |
| 4032 | } |
| 4033 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4034 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4035 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4036 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4037 | |
| 4038 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 4039 | * must take care of canceling them. |
| 4040 | * |
| 4041 | |
| 4042 | * They are typically used to indicate a background task that the user is actively engaged |
| 4043 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 4044 | * (e.g., a file download, sync operation, active network connection). |
| 4045 | * |
| 4046 | |
| 4047 | * @see Notification#FLAG_ONGOING_EVENT |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4048 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4049 | public Builder setOngoing(boolean ongoing) { |
| 4050 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 4051 | return this; |
| 4052 | } |
| 4053 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4054 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4055 | * Set whether this notification should be colorized. When set, the color set with |
| 4056 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 4057 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4058 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 4059 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4060 | * <p> |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 4061 | * For most styles, the coloring will only be applied if the notification is for a |
| 4062 | * foreground service notification. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4063 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 4064 | * that have a media session attached there is no such requirement. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4065 | * |
Aurimas Liutikas | 7f69533 | 2018-05-31 21:07:32 -0700 | [diff] [blame] | 4066 | * @see #setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4067 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4068 | */ |
| 4069 | public Builder setColorized(boolean colorize) { |
| 4070 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 4071 | return this; |
| 4072 | } |
| 4073 | |
| 4074 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4075 | * Set this flag if you would only like the sound, vibrate |
| 4076 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4077 | * |
| 4078 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4079 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4080 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 4081 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 4082 | return this; |
| 4083 | } |
| 4084 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4085 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4086 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4087 | * |
| 4088 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4089 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4090 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 4091 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4092 | return this; |
| 4093 | } |
| 4094 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4095 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 4096 | * Set whether or not this notification should not bridge to other devices. |
| 4097 | * |
| 4098 | * <p>Some notifications can be bridged to other devices for remote display. |
| 4099 | * This hint can be set to recommend this notification not be bridged. |
| 4100 | */ |
| 4101 | public Builder setLocalOnly(boolean localOnly) { |
| 4102 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 4103 | return this; |
| 4104 | } |
| 4105 | |
| 4106 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4107 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4108 | * <p> |
| 4109 | * The value should be one or more of the following fields combined with |
| 4110 | * bitwise-or: |
| 4111 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 4112 | * <p> |
| 4113 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4114 | * |
| 4115 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 4116 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4117 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4118 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4119 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4120 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4121 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4122 | return this; |
| 4123 | } |
| 4124 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4125 | /** |
| 4126 | * Set the priority of this notification. |
| 4127 | * |
| 4128 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4129 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4130 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4131 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4132 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4133 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4134 | return this; |
| 4135 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4136 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4137 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4138 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4139 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4140 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4141 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4142 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4143 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4144 | return this; |
| 4145 | } |
| 4146 | |
| 4147 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4148 | * Add a person that is relevant to this notification. |
| 4149 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4150 | * <P> |
| 4151 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 4152 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4153 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4154 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4155 | * </P> |
| 4156 | * |
| 4157 | * <P> |
| 4158 | * The person should be specified by the {@code String} representation of a |
| 4159 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 4160 | * </P> |
| 4161 | * |
| 4162 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 4163 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 4164 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 4165 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4166 | * It is also possible to provide a URI with the schema {@code name:} in order to uniquely |
| 4167 | * identify a person without an entry in the contacts database. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4168 | * </P> |
| 4169 | * |
| 4170 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4171 | * @see Notification#EXTRA_PEOPLE |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4172 | * @deprecated use {@link #addPerson(Person)} |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4173 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4174 | public Builder addPerson(String uri) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 4175 | addPerson(new Person.Builder().setUri(uri).build()); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4176 | return this; |
| 4177 | } |
| 4178 | |
| 4179 | /** |
| 4180 | * Add a person that is relevant to this notification. |
| 4181 | * |
| 4182 | * <P> |
| 4183 | * Depending on user preferences, this annotation may allow the notification to pass |
| 4184 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4185 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4186 | * appear more prominently in the user interface. |
| 4187 | * </P> |
| 4188 | * |
| 4189 | * <P> |
| 4190 | * A person should usually contain a uri in order to benefit from the ranking boost. |
| 4191 | * However, even if no uri is provided, it's beneficial to provide other people in the |
| 4192 | * notification, such that listeners and voice only devices can announce and handle them |
| 4193 | * properly. |
| 4194 | * </P> |
| 4195 | * |
| 4196 | * @param person the person to add. |
| 4197 | * @see Notification#EXTRA_PEOPLE_LIST |
| 4198 | */ |
| 4199 | public Builder addPerson(Person person) { |
| 4200 | mPersonList.add(person); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4201 | return this; |
| 4202 | } |
| 4203 | |
| 4204 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4205 | * Set this notification to be part of a group of notifications sharing the same key. |
| 4206 | * Grouped notifications may display in a cluster or stack on devices which |
| 4207 | * support such rendering. |
| 4208 | * |
| 4209 | * <p>To make this notification the summary for its group, also call |
| 4210 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 4211 | * {@link #setSortKey}. |
| 4212 | * @param groupKey The group key of the group. |
| 4213 | * @return this object for method chaining |
| 4214 | */ |
| 4215 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4216 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4217 | return this; |
| 4218 | } |
| 4219 | |
| 4220 | /** |
| 4221 | * Set this notification to be the group summary for a group of notifications. |
| 4222 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4223 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 4224 | * The group summary may be suppressed if too few notifications are included in the group. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4225 | * @param isGroupSummary Whether this notification should be a group summary. |
| 4226 | * @return this object for method chaining |
| 4227 | */ |
| 4228 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 4229 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 4230 | return this; |
| 4231 | } |
| 4232 | |
| 4233 | /** |
| 4234 | * Set a sort key that orders this notification among other notifications from the |
| 4235 | * same package. This can be useful if an external sort was already applied and an app |
| 4236 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 4237 | * value, although providing different priorities in addition to providing sort key may |
| 4238 | * cause this value to be ignored. |
| 4239 | * |
| 4240 | * <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] | 4241 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4242 | * |
| 4243 | * @see String#compareTo(String) |
| 4244 | */ |
| 4245 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4246 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4247 | return this; |
| 4248 | } |
| 4249 | |
| 4250 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4251 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4252 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4253 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 4254 | * |
| 4255 | * @see Notification#extras |
| 4256 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4257 | public Builder addExtras(Bundle extras) { |
| 4258 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4259 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4260 | } |
| 4261 | return this; |
| 4262 | } |
| 4263 | |
| 4264 | /** |
| 4265 | * Set metadata for this notification. |
| 4266 | * |
| 4267 | * <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] | 4268 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4269 | * called. |
| 4270 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4271 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 4272 | * Use {@link #addExtras} to merge in metadata instead. |
| 4273 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4274 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4275 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4276 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4277 | if (extras != null) { |
| 4278 | mUserExtras = extras; |
| 4279 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4280 | return this; |
| 4281 | } |
| 4282 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4283 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4284 | * Get the current metadata Bundle used by this notification Builder. |
| 4285 | * |
| 4286 | * <p>The returned Bundle is shared with this Builder. |
| 4287 | * |
| 4288 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 4289 | * {@link #build()} is called. |
| 4290 | * |
| 4291 | * @see Notification#extras |
| 4292 | */ |
| 4293 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4294 | return mUserExtras; |
| 4295 | } |
| 4296 | |
| 4297 | private Bundle getAllExtras() { |
| 4298 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 4299 | saveExtras.putAll(mN.extras); |
| 4300 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4304 | * Add an action to this notification. Actions are typically displayed by |
| 4305 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4306 | * <p> |
| 4307 | * Every action must have an icon (32dp square and matching the |
| 4308 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4309 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4310 | * <p> |
| 4311 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4312 | * the order they were added. Actions will not be displayed when the notification is |
| 4313 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4314 | * 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] | 4315 | * |
| 4316 | * @param icon Resource ID of a drawable that represents the action. |
| 4317 | * @param title Text describing the action. |
| 4318 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4319 | * |
| 4320 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4321 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4322 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4323 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4324 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4325 | return this; |
| 4326 | } |
| 4327 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4328 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4329 | * Add an action to this notification. Actions are typically displayed by |
| 4330 | * the system as a button adjacent to the notification content. |
| 4331 | * <p> |
| 4332 | * Every action must have an icon (32dp square and matching the |
| 4333 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4334 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4335 | * <p> |
| 4336 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4337 | * the order they were added. Actions will not be displayed when the notification is |
| 4338 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4339 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 4340 | * |
| 4341 | * @param action The action to add. |
| 4342 | */ |
| 4343 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4344 | if (action != null) { |
| 4345 | mActions.add(action); |
| 4346 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4347 | return this; |
| 4348 | } |
| 4349 | |
| 4350 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4351 | * Alter the complete list of actions attached to this notification. |
| 4352 | * @see #addAction(Action). |
| 4353 | * |
| 4354 | * @param actions |
| 4355 | * @return |
| 4356 | */ |
| 4357 | public Builder setActions(Action... actions) { |
| 4358 | mActions.clear(); |
| 4359 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4360 | if (actions[i] != null) { |
| 4361 | mActions.add(actions[i]); |
| 4362 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4363 | } |
| 4364 | return this; |
| 4365 | } |
| 4366 | |
| 4367 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4368 | * Add a rich notification style to be applied at build time. |
| 4369 | * |
| 4370 | * @param style Object responsible for modifying the notification style. |
| 4371 | */ |
| 4372 | public Builder setStyle(Style style) { |
| 4373 | if (mStyle != style) { |
| 4374 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4375 | if (mStyle != null) { |
| 4376 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4377 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 4378 | } else { |
| 4379 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4380 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4381 | } |
| 4382 | return this; |
| 4383 | } |
| 4384 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4385 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 4386 | * Returns the style set by {@link #setStyle(Style)}. |
| 4387 | */ |
| 4388 | public Style getStyle() { |
| 4389 | return mStyle; |
| 4390 | } |
| 4391 | |
| 4392 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4393 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4394 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4395 | * @return The same Builder. |
| 4396 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 4397 | public Builder setVisibility(@Visibility int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4398 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4399 | return this; |
| 4400 | } |
| 4401 | |
| 4402 | /** |
| 4403 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 4404 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 4405 | * @param n A replacement notification, presumably with some or all info redacted. |
| 4406 | * @return The same Builder. |
| 4407 | */ |
| 4408 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4409 | if (n != null) { |
| 4410 | mN.publicVersion = new Notification(); |
| 4411 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 4412 | } else { |
| 4413 | mN.publicVersion = null; |
| 4414 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4415 | return this; |
| 4416 | } |
| 4417 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4418 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4419 | * Apply an extender to this notification builder. Extenders may be used to add |
| 4420 | * metadata or change options on this builder. |
| 4421 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4422 | public Builder extend(Extender extender) { |
| 4423 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4424 | return this; |
| 4425 | } |
| 4426 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 4427 | /** |
| 4428 | * @hide |
| 4429 | */ |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4430 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4431 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4432 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4433 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4434 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4435 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4436 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4437 | } |
| 4438 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4439 | /** |
| 4440 | * Sets {@link Notification#color}. |
| 4441 | * |
| 4442 | * @param argb The accent color to use |
| 4443 | * |
| 4444 | * @return The same Builder. |
| 4445 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4446 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4447 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4448 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4449 | return this; |
| 4450 | } |
| 4451 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4452 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 4453 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 4454 | // This user can never be a badged profile, |
| 4455 | // and also includes USER_ALL system notifications. |
| 4456 | return null; |
| 4457 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 4458 | // Note: This assumes that the current user can read the profile badge of the |
| 4459 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 4460 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4461 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | private Bitmap getProfileBadge() { |
| 4465 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4466 | if (badge == null) { |
| 4467 | return null; |
| 4468 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4469 | final int size = mContext.getResources().getDimensionPixelSize( |
| 4470 | R.dimen.notification_badge_size); |
| 4471 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4472 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4473 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4474 | badge.draw(canvas); |
| 4475 | return bitmap; |
| 4476 | } |
| 4477 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4478 | private void bindProfileBadge(RemoteViews contentView, StandardTemplateParams p) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4479 | Bitmap profileBadge = getProfileBadge(); |
| 4480 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4481 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4482 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 4483 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4484 | if (isColorized(p)) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4485 | contentView.setDrawableTint(R.id.profile_badge, false, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4486 | getPrimaryTextColor(p), PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4487 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4488 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4489 | } |
| 4490 | |
Gus Prevas | bae5ba3 | 2018-11-28 15:45:13 -0500 | [diff] [blame] | 4491 | private void bindAlertedIcon(RemoteViews contentView, StandardTemplateParams p) { |
| 4492 | contentView.setDrawableTint( |
| 4493 | R.id.alerted_icon, |
| 4494 | false /* targetBackground */, |
| 4495 | getNeutralColor(p), |
| 4496 | PorterDuff.Mode.SRC_ATOP); |
| 4497 | } |
| 4498 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4499 | /** |
| 4500 | * @hide |
| 4501 | */ |
| 4502 | public boolean usesStandardHeader() { |
| 4503 | if (mN.mUsesStandardHeader) { |
| 4504 | return true; |
| 4505 | } |
| 4506 | if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.N) { |
| 4507 | if (mN.contentView == null && mN.bigContentView == null) { |
| 4508 | return true; |
| 4509 | } |
| 4510 | } |
| 4511 | boolean contentViewUsesHeader = mN.contentView == null |
| 4512 | || STANDARD_LAYOUTS.contains(mN.contentView.getLayoutId()); |
| 4513 | boolean bigContentViewUsesHeader = mN.bigContentView == null |
| 4514 | || STANDARD_LAYOUTS.contains(mN.bigContentView.getLayoutId()); |
| 4515 | return contentViewUsesHeader && bigContentViewUsesHeader; |
| 4516 | } |
| 4517 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4518 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4519 | resetNotificationHeader(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4520 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4521 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4522 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4523 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4524 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4525 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4526 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4529 | /** |
| 4530 | * Resets the notification header to its original state |
| 4531 | */ |
| 4532 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 4533 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 4534 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 4535 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4536 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 4537 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4538 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 4539 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4540 | contentView.setViewVisibility(R.id.header_text_secondary, View.GONE); |
| 4541 | contentView.setTextViewText(R.id.header_text_secondary, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4542 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4543 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4544 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4545 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4546 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 4547 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 4548 | contentView.setViewVisibility(R.id.alerted_icon, View.GONE); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4549 | mN.mUsesStandardHeader = false; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4550 | } |
| 4551 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4552 | private RemoteViews applyStandardTemplate(int resId, TemplateBindResult result) { |
| 4553 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this), |
| 4554 | result); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4555 | } |
| 4556 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4557 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p, |
| 4558 | TemplateBindResult result) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 4559 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 4560 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4561 | resetStandardTemplate(contentView); |
| 4562 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4563 | final Bundle ex = mN.extras; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4564 | updateBackgroundColor(contentView, p); |
| 4565 | bindNotificationHeader(contentView, p); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4566 | bindLargeIconAndReply(contentView, p, result); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4567 | boolean showProgress = handleProgressBar(contentView, ex, p); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4568 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4569 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4570 | contentView.setTextViewText(R.id.title, processTextSpans(p.title)); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4571 | setTextViewColorPrimary(contentView, R.id.title, p); |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 4572 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 4573 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 4574 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4575 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4576 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4577 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 4578 | : com.android.internal.R.id.text; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4579 | contentView.setTextViewText(textId, processTextSpans(p.text)); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4580 | setTextViewColorSecondary(contentView, textId, p); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4581 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4582 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4583 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4584 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4585 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4586 | return contentView; |
| 4587 | } |
| 4588 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4589 | private CharSequence processTextSpans(CharSequence text) { |
Lucas Dupin | d3c9932 | 2018-09-27 10:22:29 -0700 | [diff] [blame] | 4590 | if (hasForegroundColor() || mInNightMode) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4591 | return ContrastColorUtil.clearColorSpans(text); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4592 | } |
| 4593 | return text; |
| 4594 | } |
| 4595 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4596 | private void setTextViewColorPrimary(RemoteViews contentView, int id, |
| 4597 | StandardTemplateParams p) { |
| 4598 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4599 | contentView.setTextColor(id, mPrimaryTextColor); |
| 4600 | } |
| 4601 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4602 | private boolean hasForegroundColor() { |
| 4603 | return mForegroundColor != COLOR_INVALID; |
| 4604 | } |
| 4605 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4606 | /** |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4607 | * Return the primary text color using the existing template params |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4608 | * @hide |
| 4609 | */ |
| 4610 | @VisibleForTesting |
| 4611 | public int getPrimaryTextColor() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4612 | return getPrimaryTextColor(mParams); |
| 4613 | } |
| 4614 | |
| 4615 | /** |
| 4616 | * @param p the template params to inflate this with |
| 4617 | * @return the primary text color |
| 4618 | * @hide |
| 4619 | */ |
| 4620 | @VisibleForTesting |
| 4621 | public int getPrimaryTextColor(StandardTemplateParams p) { |
| 4622 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4623 | return mPrimaryTextColor; |
| 4624 | } |
| 4625 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4626 | /** |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4627 | * Return the secondary text color using the existing template params |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4628 | * @hide |
| 4629 | */ |
| 4630 | @VisibleForTesting |
| 4631 | public int getSecondaryTextColor() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4632 | return getSecondaryTextColor(mParams); |
| 4633 | } |
| 4634 | |
| 4635 | /** |
| 4636 | * @param p the template params to inflate this with |
| 4637 | * @return the secondary text color |
| 4638 | * @hide |
| 4639 | */ |
| 4640 | @VisibleForTesting |
| 4641 | public int getSecondaryTextColor(StandardTemplateParams p) { |
| 4642 | ensureColors(p); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4643 | return mSecondaryTextColor; |
| 4644 | } |
| 4645 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4646 | private void setTextViewColorSecondary(RemoteViews contentView, int id, |
| 4647 | StandardTemplateParams p) { |
| 4648 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4649 | contentView.setTextColor(id, mSecondaryTextColor); |
| 4650 | } |
| 4651 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4652 | private void ensureColors(StandardTemplateParams p) { |
| 4653 | int backgroundColor = getBackgroundColor(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4654 | if (mPrimaryTextColor == COLOR_INVALID |
| 4655 | || mSecondaryTextColor == COLOR_INVALID |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4656 | || mTextColorsAreForBackground != backgroundColor) { |
| 4657 | mTextColorsAreForBackground = backgroundColor; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4658 | if (!hasForegroundColor() || !isColorized(p)) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4659 | mPrimaryTextColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 4660 | backgroundColor, mInNightMode); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4661 | mSecondaryTextColor = ContrastColorUtil.resolveSecondaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 4662 | backgroundColor, mInNightMode); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4663 | if (backgroundColor != COLOR_DEFAULT && isColorized(p)) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4664 | mPrimaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4665 | mPrimaryTextColor, backgroundColor, 4.5); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4666 | mSecondaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4667 | mSecondaryTextColor, backgroundColor, 4.5); |
| 4668 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4669 | } else { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4670 | double backLum = ContrastColorUtil.calculateLuminance(backgroundColor); |
| 4671 | double textLum = ContrastColorUtil.calculateLuminance(mForegroundColor); |
| 4672 | double contrast = ContrastColorUtil.calculateContrast(mForegroundColor, |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4673 | backgroundColor); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4674 | // We only respect the given colors if worst case Black or White still has |
| 4675 | // contrast |
| 4676 | boolean backgroundLight = backLum > textLum |
| 4677 | && satisfiesTextContrast(backgroundColor, Color.BLACK) |
| 4678 | || backLum <= textLum |
| 4679 | && !satisfiesTextContrast(backgroundColor, Color.WHITE); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4680 | if (contrast < 4.5f) { |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4681 | if (backgroundLight) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4682 | mSecondaryTextColor = ContrastColorUtil.findContrastColor( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4683 | mForegroundColor, |
| 4684 | backgroundColor, |
| 4685 | true /* findFG */, |
| 4686 | 4.5f); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4687 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4688 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_LIGHT); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4689 | } else { |
| 4690 | mSecondaryTextColor = |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4691 | ContrastColorUtil.findContrastColorAgainstDark( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4692 | mForegroundColor, |
| 4693 | backgroundColor, |
| 4694 | true /* findFG */, |
| 4695 | 4.5f); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4696 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4697 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4698 | } |
| 4699 | } else { |
| 4700 | mPrimaryTextColor = mForegroundColor; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4701 | mSecondaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4702 | mPrimaryTextColor, backgroundLight ? LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4703 | : LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4704 | if (ContrastColorUtil.calculateContrast(mSecondaryTextColor, |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4705 | backgroundColor) < 4.5f) { |
| 4706 | // oh well the secondary is not good enough |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4707 | if (backgroundLight) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4708 | mSecondaryTextColor = ContrastColorUtil.findContrastColor( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4709 | mSecondaryTextColor, |
| 4710 | backgroundColor, |
| 4711 | true /* findFG */, |
| 4712 | 4.5f); |
| 4713 | } else { |
| 4714 | mSecondaryTextColor |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4715 | = ContrastColorUtil.findContrastColorAgainstDark( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4716 | mSecondaryTextColor, |
| 4717 | backgroundColor, |
| 4718 | true /* findFG */, |
| 4719 | 4.5f); |
| 4720 | } |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4721 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4722 | mSecondaryTextColor, backgroundLight |
| 4723 | ? -LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4724 | : -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4725 | } |
| 4726 | } |
| 4727 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4728 | } |
| 4729 | } |
| 4730 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4731 | private void updateBackgroundColor(RemoteViews contentView, |
| 4732 | StandardTemplateParams p) { |
| 4733 | if (isColorized(p)) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4734 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4735 | getBackgroundColor(p)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4736 | } else { |
| 4737 | // Clear it! |
| 4738 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 4739 | 0); |
| 4740 | } |
| 4741 | } |
| 4742 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4743 | /** |
| 4744 | * @param remoteView the remote view to update the minheight in |
| 4745 | * @param hasMinHeight does it have a mimHeight |
| 4746 | * @hide |
| 4747 | */ |
| 4748 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 4749 | int minHeight = 0; |
| 4750 | if (hasMinHeight) { |
| 4751 | // we need to set the minHeight of the notification |
| 4752 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 4753 | com.android.internal.R.dimen.notification_min_content_height); |
| 4754 | } |
| 4755 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 4756 | } |
| 4757 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4758 | private boolean handleProgressBar(RemoteViews contentView, Bundle ex, |
| 4759 | StandardTemplateParams p) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4760 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4761 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 4762 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4763 | if (p.hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4764 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4765 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4766 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4767 | contentView.setProgressBackgroundTintList( |
| 4768 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 4769 | R.color.notification_progress_background_color))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4770 | if (getRawColor(p) != COLOR_DEFAULT) { |
| 4771 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor(p)); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4772 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 4773 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4774 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4775 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4776 | } else { |
| 4777 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4778 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 4779 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4780 | } |
| 4781 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4782 | private void bindLargeIconAndReply(RemoteViews contentView, StandardTemplateParams p, |
| 4783 | TemplateBindResult result) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4784 | boolean largeIconShown = bindLargeIcon(contentView, p); |
| 4785 | boolean replyIconShown = bindReplyIcon(contentView, p); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 4786 | boolean iconContainerVisible = largeIconShown || replyIconShown; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4787 | contentView.setViewVisibility(R.id.right_icon_container, |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 4788 | iconContainerVisible ? View.VISIBLE : View.GONE); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4789 | int marginEnd = calculateMarginEnd(largeIconShown, replyIconShown); |
| 4790 | contentView.setViewLayoutMarginEnd(R.id.line1, marginEnd); |
| 4791 | contentView.setViewLayoutMarginEnd(R.id.text, marginEnd); |
| 4792 | contentView.setViewLayoutMarginEnd(R.id.progress, marginEnd); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4793 | if (result != null) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4794 | result.setIconMarginEnd(marginEnd); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 4795 | result.setRightIconContainerVisible(iconContainerVisible); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4796 | } |
| 4797 | } |
| 4798 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4799 | private int calculateMarginEnd(boolean largeIconShown, boolean replyIconShown) { |
| 4800 | int marginEnd = 0; |
| 4801 | int contentMargin = mContext.getResources().getDimensionPixelSize( |
| 4802 | R.dimen.notification_content_margin_end); |
| 4803 | int iconSize = mContext.getResources().getDimensionPixelSize( |
| 4804 | R.dimen.notification_right_icon_size); |
| 4805 | if (replyIconShown) { |
| 4806 | // The size of the reply icon |
| 4807 | marginEnd += iconSize; |
| 4808 | |
| 4809 | int replyInset = mContext.getResources().getDimensionPixelSize( |
| 4810 | R.dimen.notification_reply_inset); |
| 4811 | // We're subtracting the inset of the reply icon to make sure it's |
| 4812 | // aligned nicely on the right, and remove it from the following padding |
| 4813 | marginEnd -= replyInset * 2; |
| 4814 | } |
| 4815 | if (largeIconShown) { |
| 4816 | // adding size of the right icon |
| 4817 | marginEnd += iconSize; |
| 4818 | |
| 4819 | if (replyIconShown) { |
| 4820 | // We also add some padding to the reply icon if it's around |
| 4821 | marginEnd += contentMargin; |
| 4822 | } |
| 4823 | } |
| 4824 | if (replyIconShown || largeIconShown) { |
| 4825 | // The padding to the content |
| 4826 | marginEnd += contentMargin; |
| 4827 | } |
| 4828 | return marginEnd; |
| 4829 | } |
| 4830 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4831 | /** |
| 4832 | * Bind the large icon. |
| 4833 | * @return if the largeIcon is visible |
| 4834 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4835 | private boolean bindLargeIcon(RemoteViews contentView, StandardTemplateParams p) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4836 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 4837 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 4838 | } |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4839 | boolean showLargeIcon = mN.mLargeIcon != null && !p.hideLargeIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4840 | if (showLargeIcon) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4841 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 4842 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4843 | processLargeLegacyIcon(mN.mLargeIcon, contentView, p); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4844 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4845 | return showLargeIcon; |
| 4846 | } |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4847 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4848 | /** |
| 4849 | * Bind the reply icon. |
| 4850 | * @return if the reply icon is visible |
| 4851 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4852 | private boolean bindReplyIcon(RemoteViews contentView, StandardTemplateParams p) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4853 | boolean actionVisible = !p.hideReplyIcon; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4854 | Action action = null; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4855 | if (actionVisible) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4856 | action = findReplyAction(); |
| 4857 | actionVisible = action != null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4858 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4859 | if (actionVisible) { |
| 4860 | contentView.setViewVisibility(R.id.reply_icon_action, View.VISIBLE); |
| 4861 | contentView.setDrawableTint(R.id.reply_icon_action, |
| 4862 | false /* targetBackground */, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4863 | getNeutralColor(p), |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4864 | PorterDuff.Mode.SRC_ATOP); |
| 4865 | contentView.setOnClickPendingIntent(R.id.reply_icon_action, action.actionIntent); |
| 4866 | contentView.setRemoteInputs(R.id.reply_icon_action, action.mRemoteInputs); |
| 4867 | } else { |
| 4868 | contentView.setRemoteInputs(R.id.reply_icon_action, null); |
| 4869 | } |
| 4870 | contentView.setViewVisibility(R.id.reply_icon_action, |
| 4871 | actionVisible ? View.VISIBLE : View.GONE); |
| 4872 | return actionVisible; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | private Action findReplyAction() { |
| 4876 | ArrayList<Action> actions = mActions; |
| 4877 | if (mOriginalActions != null) { |
| 4878 | actions = mOriginalActions; |
| 4879 | } |
| 4880 | int numActions = actions.size(); |
| 4881 | for (int i = 0; i < numActions; i++) { |
| 4882 | Action action = actions.get(i); |
| 4883 | if (hasValidRemoteInput(action)) { |
| 4884 | return action; |
| 4885 | } |
| 4886 | } |
| 4887 | return null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4888 | } |
| 4889 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4890 | private void bindNotificationHeader(RemoteViews contentView, StandardTemplateParams p) { |
| 4891 | bindSmallIcon(contentView, p); |
| 4892 | bindHeaderAppName(contentView, p); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4893 | bindHeaderText(contentView, p); |
| 4894 | bindHeaderTextSecondary(contentView, p); |
| 4895 | bindHeaderChronometerAndTime(contentView, p); |
| 4896 | bindProfileBadge(contentView, p); |
| 4897 | bindAlertedIcon(contentView, p); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4898 | bindActivePermissions(contentView, p); |
| 4899 | bindExpandButton(contentView, p); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4900 | mN.mUsesStandardHeader = true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4901 | } |
| 4902 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4903 | private void bindActivePermissions(RemoteViews contentView, StandardTemplateParams p) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4904 | int color = getNeutralColor(p); |
Julia Reynolds | b887b23 | 2018-04-10 16:38:08 -0400 | [diff] [blame] | 4905 | contentView.setDrawableTint(R.id.camera, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4906 | contentView.setDrawableTint(R.id.mic, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4907 | contentView.setDrawableTint(R.id.overlay, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4908 | } |
| 4909 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4910 | private void bindExpandButton(RemoteViews contentView, StandardTemplateParams p) { |
| 4911 | int color = isColorized(p) ? getPrimaryTextColor(p) : getSecondaryTextColor(p); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4912 | contentView.setDrawableTint(R.id.expand_button, false, color, |
| 4913 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4914 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4915 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4916 | } |
| 4917 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4918 | private void bindHeaderChronometerAndTime(RemoteViews contentView, |
| 4919 | StandardTemplateParams p) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4920 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4921 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4922 | setTextViewColorSecondary(contentView, R.id.time_divider, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4923 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 4924 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 4925 | contentView.setLong(R.id.chronometer, "setBase", |
| 4926 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 4927 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4928 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 4929 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4930 | setTextViewColorSecondary(contentView, R.id.chronometer, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4931 | } else { |
| 4932 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 4933 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4934 | setTextViewColorSecondary(contentView, R.id.time, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4935 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4936 | } else { |
| 4937 | // We still want a time to be set but gone, such that we can show and hide it |
| 4938 | // on demand in case it's a child notification without anything in the header |
| 4939 | contentView.setLong(R.id.time, "setTime", mN.when != 0 ? mN.when : mN.creationTime); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4940 | } |
| 4941 | } |
| 4942 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4943 | private void bindHeaderText(RemoteViews contentView, StandardTemplateParams p) { |
| 4944 | CharSequence summaryText = p.summaryText; |
| 4945 | if (summaryText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4946 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4947 | summaryText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4948 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4949 | if (summaryText == null |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4950 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 4951 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4952 | summaryText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4953 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4954 | if (summaryText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4955 | // TODO: Remove the span entirely to only have the string with propper formating. |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4956 | contentView.setTextViewText(R.id.header_text, processTextSpans( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4957 | processLegacyText(summaryText))); |
| 4958 | setTextViewColorSecondary(contentView, R.id.header_text, p); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4959 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 4960 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4961 | setTextViewColorSecondary(contentView, R.id.header_text_divider, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4962 | } |
| 4963 | } |
| 4964 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4965 | private void bindHeaderTextSecondary(RemoteViews contentView, StandardTemplateParams p) { |
| 4966 | if (!TextUtils.isEmpty(p.headerTextSecondary)) { |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4967 | contentView.setTextViewText(R.id.header_text_secondary, processTextSpans( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4968 | processLegacyText(p.headerTextSecondary))); |
| 4969 | setTextViewColorSecondary(contentView, R.id.header_text_secondary, p); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4970 | contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE); |
| 4971 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4972 | setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider, p); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4973 | } |
| 4974 | } |
| 4975 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4976 | /** |
| 4977 | * @hide |
| 4978 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 4979 | @UnsupportedAppUsage |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4980 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4981 | CharSequence name = null; |
| 4982 | final PackageManager pm = mContext.getPackageManager(); |
| 4983 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 4984 | // only system packages which lump together a bunch of unrelated stuff |
| 4985 | // may substitute a different name to make the purpose of the |
| 4986 | // notification more clear. the correct package label should always |
| 4987 | // be accessible via SystemUI. |
| 4988 | final String pkg = mContext.getPackageName(); |
| 4989 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 4990 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 4991 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 4992 | name = subName; |
| 4993 | } else { |
| 4994 | Log.w(TAG, "warning: pkg " |
| 4995 | + pkg + " attempting to substitute app name '" + subName |
| 4996 | + "' without holding perm " |
| 4997 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 4998 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4999 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 5000 | if (TextUtils.isEmpty(name)) { |
| 5001 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 5002 | } |
| 5003 | if (TextUtils.isEmpty(name)) { |
| 5004 | // still nothing? |
| 5005 | return null; |
| 5006 | } |
| 5007 | |
| 5008 | return String.valueOf(name); |
| 5009 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5010 | private void bindHeaderAppName(RemoteViews contentView, StandardTemplateParams p) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 5011 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5012 | if (isColorized(p)) { |
| 5013 | setTextViewColorPrimary(contentView, R.id.app_name_text, p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5014 | } else { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5015 | contentView.setTextColor(R.id.app_name_text, getSecondaryTextColor(p)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5016 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5017 | } |
| 5018 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5019 | private boolean isColorized(StandardTemplateParams p) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5020 | return p.allowColorization && mN.isColorized(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5021 | } |
| 5022 | |
| 5023 | private void bindSmallIcon(RemoteViews contentView, StandardTemplateParams p) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5024 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 5025 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 5026 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5027 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5028 | contentView.setInt(R.id.icon, "setImageLevel", mN.iconLevel); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5029 | processSmallIconColor(mN.mSmallIcon, contentView, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5030 | } |
| 5031 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5032 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5033 | * @return true if the built notification will show the time or the chronometer; false |
| 5034 | * otherwise |
| 5035 | */ |
| 5036 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5037 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5038 | } |
| 5039 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5040 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 5041 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 5042 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5043 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5044 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5045 | |
| 5046 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 5047 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5048 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, View.GONE); |
| 5049 | big.setViewVisibility(R.id.notification_material_reply_progress, View.GONE); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5050 | |
| 5051 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 5052 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 5053 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 5054 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 5055 | |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 5056 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 5057 | R.dimen.notification_content_margin); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5058 | } |
| 5059 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5060 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 5061 | TemplateBindResult result) { |
| 5062 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this), |
| 5063 | result); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 5064 | } |
| 5065 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5066 | private static List<Notification.Action> filterOutContextualActions( |
| 5067 | List<Notification.Action> actions) { |
| 5068 | List<Notification.Action> nonContextualActions = new ArrayList<>(); |
| 5069 | for (Notification.Action action : actions) { |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 5070 | if (!action.isContextual()) { |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5071 | nonContextualActions.add(action); |
| 5072 | } |
| 5073 | } |
| 5074 | return nonContextualActions; |
| 5075 | } |
| 5076 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 5077 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5078 | StandardTemplateParams p, TemplateBindResult result) { |
| 5079 | RemoteViews big = applyStandardTemplate(layoutId, p, result); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5080 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5081 | resetStandardTemplateWithActions(big); |
| 5082 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5083 | boolean validRemoteInput = false; |
| 5084 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5085 | // In the UI contextual actions appear separately from the standard actions, so we |
| 5086 | // filter them out here. |
| 5087 | List<Notification.Action> nonContextualActions = filterOutContextualActions(mActions); |
| 5088 | |
| 5089 | int N = nonContextualActions.size(); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5090 | boolean emphazisedMode = mN.fullScreenIntent != null; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5091 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5092 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 5093 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5094 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 5095 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5096 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5097 | for (int i=0; i<N; i++) { |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5098 | Action action = nonContextualActions.get(i); |
| 5099 | |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 5100 | boolean actionHasValidInput = hasValidRemoteInput(action); |
| 5101 | validRemoteInput |= actionHasValidInput; |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5102 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5103 | final RemoteViews button = generateActionButton(action, emphazisedMode, p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5104 | if (actionHasValidInput && !emphazisedMode) { |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 5105 | // Clear the drawable |
| 5106 | button.setInt(R.id.action0, "setBackgroundResource", 0); |
| 5107 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5108 | big.addView(R.id.actions, button); |
| 5109 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 5110 | } else { |
| 5111 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5112 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5113 | |
| 5114 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5115 | if (validRemoteInput && replyText != null |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5116 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0]) |
| 5117 | && p.maxRemoteInputHistory > 0) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5118 | boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5119 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5120 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, |
| 5121 | View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5122 | big.setTextViewText(R.id.notification_material_reply_text_1, |
| 5123 | processTextSpans(replyText[0])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5124 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1, p); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5125 | big.setViewVisibility(R.id.notification_material_reply_progress, |
| 5126 | showSpinner ? View.VISIBLE : View.GONE); |
| 5127 | big.setProgressIndeterminateTintList( |
| 5128 | R.id.notification_material_reply_progress, |
| 5129 | ColorStateList.valueOf( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5130 | isColorized(p) ? getPrimaryTextColor(p) : resolveContrastColor(p))); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5131 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5132 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1]) |
| 5133 | && p.maxRemoteInputHistory > 1) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5134 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5135 | big.setTextViewText(R.id.notification_material_reply_text_2, |
| 5136 | processTextSpans(replyText[1])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5137 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2, p); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5138 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5139 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2]) |
| 5140 | && p.maxRemoteInputHistory > 2) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5141 | big.setViewVisibility( |
| 5142 | R.id.notification_material_reply_text_3, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5143 | big.setTextViewText(R.id.notification_material_reply_text_3, |
| 5144 | processTextSpans(replyText[2])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5145 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3, p); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5146 | } |
| 5147 | } |
| 5148 | } |
| 5149 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5150 | return big; |
| 5151 | } |
| 5152 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5153 | private boolean hasValidRemoteInput(Action action) { |
| 5154 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 5155 | // Weird actions |
| 5156 | return false; |
| 5157 | } |
| 5158 | |
| 5159 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 5160 | if (remoteInputs == null) { |
| 5161 | return false; |
| 5162 | } |
| 5163 | |
| 5164 | for (RemoteInput r : remoteInputs) { |
| 5165 | CharSequence[] choices = r.getChoices(); |
| 5166 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 5167 | return true; |
| 5168 | } |
| 5169 | } |
| 5170 | return false; |
| 5171 | } |
| 5172 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5173 | /** |
| 5174 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 5175 | * 1. Custom contentView from the caller |
| 5176 | * 2. Style's proposed content view |
| 5177 | * 3. Standard template view |
| 5178 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5179 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5180 | return createContentView(false /* increasedheight */ ); |
| 5181 | } |
| 5182 | |
| 5183 | /** |
| 5184 | * Construct a RemoteViews for the smaller content view. |
| 5185 | * |
| 5186 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5187 | * styles may support showing more then just that basic 1U size |
| 5188 | * and the system may decide to render important notifications |
| 5189 | * slightly bigger even when collapsed. |
| 5190 | * |
| 5191 | * @hide |
| 5192 | */ |
| 5193 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5194 | if (mN.contentView != null && useExistingRemoteView()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5195 | return mN.contentView; |
| 5196 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5197 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5198 | if (styleView != null) { |
| 5199 | return styleView; |
| 5200 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5201 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5202 | return applyStandardTemplate(getBaseLayoutResource(), null /* result */); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5203 | } |
| 5204 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5205 | private boolean useExistingRemoteView() { |
| 5206 | return mStyle == null || (!mStyle.displayCustomViewInline() |
| 5207 | && !mRebuildStyledRemoteViews); |
| 5208 | } |
| 5209 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5210 | /** |
| 5211 | * Construct a RemoteViews for the final big notification layout. |
| 5212 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5213 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5214 | RemoteViews result = null; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5215 | if (mN.bigContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5216 | return mN.bigContentView; |
| 5217 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5218 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 5219 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5220 | } else if (mActions.size() != 0) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5221 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5222 | null /* result */); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5223 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5224 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5225 | return result; |
| 5226 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5227 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5228 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 5229 | * Construct a RemoteViews for the final notification header only. This will not be |
| 5230 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5231 | * |
| 5232 | * @hide |
| 5233 | */ |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5234 | public RemoteViews makeNotificationHeader() { |
| 5235 | return makeNotificationHeader(mParams.reset().fillTextsFrom(this)); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | /** |
| 5239 | * Construct a RemoteViews for the final notification header only. This will not be |
| 5240 | * colorized. |
| 5241 | * |
| 5242 | * @param p the template params to inflate this with |
| 5243 | */ |
| 5244 | private RemoteViews makeNotificationHeader(StandardTemplateParams p) { |
| 5245 | // Headers on their own are never colorized |
| 5246 | p.disallowColorization(); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5247 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5248 | R.layout.notification_template_header); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5249 | resetNotificationHeader(header); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5250 | bindNotificationHeader(header, p); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5251 | return header; |
| 5252 | } |
| 5253 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5254 | /** |
| 5255 | * Construct a RemoteViews for the ambient version of the notification. |
| 5256 | * |
| 5257 | * @hide |
| 5258 | */ |
| 5259 | public RemoteViews makeAmbientNotification() { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5260 | return createHeadsUpContentView(false /* increasedHeight */); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5261 | } |
| 5262 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5263 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5264 | if (result != null) { |
| 5265 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 5266 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5267 | } |
| 5268 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5269 | /** |
| 5270 | * Adapt the Notification header if this view is used as an expanded view. |
| 5271 | * |
| 5272 | * @hide |
| 5273 | */ |
| 5274 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5275 | if (result != null) { |
| 5276 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 5277 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5278 | } |
| 5279 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5280 | /** |
| 5281 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5282 | * |
| 5283 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5284 | * styles may support showing more then just that basic 1U size |
| 5285 | * and the system may decide to render important notifications |
| 5286 | * slightly bigger even when collapsed. |
| 5287 | * |
| 5288 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5289 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5290 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5291 | if (mN.headsUpContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5292 | return mN.headsUpContentView; |
| 5293 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5294 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 5295 | if (styleView != null) { |
| 5296 | return styleView; |
| 5297 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5298 | } else if (mActions.size() == 0) { |
| 5299 | return null; |
| 5300 | } |
| 5301 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5302 | // We only want at most a single remote input history to be shown here, otherwise |
| 5303 | // the content would become squished. |
| 5304 | StandardTemplateParams p = mParams.reset().fillTextsFrom(this) |
| 5305 | .setMaxRemoteInputHistory(1); |
| 5306 | return applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5307 | p, |
| 5308 | null /* result */); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5309 | } |
| 5310 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5311 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5312 | * Construct a RemoteViews for the final heads-up notification layout. |
| 5313 | */ |
| 5314 | public RemoteViews createHeadsUpContentView() { |
| 5315 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 5316 | } |
| 5317 | |
| 5318 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5319 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5320 | * |
| 5321 | * @hide |
| 5322 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5323 | @UnsupportedAppUsage |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5324 | public RemoteViews makePublicContentView() { |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5325 | return makePublicView(false /* ambient */); |
| 5326 | } |
| 5327 | |
| 5328 | /** |
| 5329 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5330 | * |
| 5331 | * @hide |
| 5332 | */ |
| 5333 | public RemoteViews makePublicAmbientNotification() { |
| 5334 | return makePublicView(true /* ambient */); |
| 5335 | } |
| 5336 | |
| 5337 | private RemoteViews makePublicView(boolean ambient) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5338 | if (mN.publicVersion != null) { |
| 5339 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5340 | return ambient ? builder.makeAmbientNotification() : builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5341 | } |
| 5342 | Bundle savedBundle = mN.extras; |
| 5343 | Style style = mStyle; |
| 5344 | mStyle = null; |
| 5345 | Icon largeIcon = mN.mLargeIcon; |
| 5346 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5347 | Bitmap largeIconLegacy = mN.largeIcon; |
| 5348 | mN.largeIcon = null; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5349 | ArrayList<Action> actions = mActions; |
| 5350 | mActions = new ArrayList<>(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5351 | Bundle publicExtras = new Bundle(); |
| 5352 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 5353 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 5354 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 5355 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5356 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 5357 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | ed07b96 | 2018-04-30 14:39:35 -0700 | [diff] [blame] | 5358 | String appName = savedBundle.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 5359 | if (appName != null) { |
| 5360 | publicExtras.putString(EXTRA_SUBSTITUTE_APP_NAME, appName); |
| 5361 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5362 | mN.extras = publicExtras; |
Selim Cinek | 499c20f | 2017-07-20 14:06:09 -0700 | [diff] [blame] | 5363 | RemoteViews view; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5364 | view = makeNotificationHeader(); |
| 5365 | view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5366 | mN.extras = savedBundle; |
| 5367 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5368 | mN.largeIcon = largeIconLegacy; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5369 | mActions = actions; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5370 | mStyle = style; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5371 | return view; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5372 | } |
| 5373 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5374 | /** |
| 5375 | * Construct a content view for the display when low - priority |
| 5376 | * |
| 5377 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 5378 | * a new subtext is created consisting of the content of the |
| 5379 | * notification. |
| 5380 | * @hide |
| 5381 | */ |
| 5382 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5383 | StandardTemplateParams p = mParams.reset() |
| 5384 | .forceDefaultColor() |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5385 | .fillTextsFrom(this); |
| 5386 | if (!useRegularSubtext || TextUtils.isEmpty(mParams.summaryText)) { |
| 5387 | p.summaryText(createSummaryText()); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5388 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5389 | RemoteViews header = makeNotificationHeader(p); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 5390 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5391 | return header; |
| 5392 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5393 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5394 | private CharSequence createSummaryText() { |
| 5395 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 5396 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 5397 | return titleText; |
| 5398 | } |
| 5399 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 5400 | if (titleText == null) { |
| 5401 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 5402 | } |
| 5403 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5404 | if (titleText != null) { |
| 5405 | summary.append(bidi.unicodeWrap(titleText)); |
| 5406 | } |
| 5407 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 5408 | if (titleText != null && contentText != null) { |
| 5409 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 5410 | R.string.notification_header_divider_symbol_with_spaces))); |
| 5411 | } |
| 5412 | if (contentText != null) { |
| 5413 | summary.append(bidi.unicodeWrap(contentText)); |
| 5414 | } |
| 5415 | return summary; |
| 5416 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5417 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5418 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5419 | StandardTemplateParams p) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5420 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 5421 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5422 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 5423 | : tombstone ? getActionTombstoneLayoutResource() |
| 5424 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5425 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5426 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5427 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5428 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5429 | if (action.mRemoteInputs != null) { |
| 5430 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 5431 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5432 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5433 | // change the background bgColor |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5434 | CharSequence title = action.title; |
| 5435 | ColorStateList[] outResultColor = null; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5436 | int background = resolveBackgroundColor(p); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5437 | if (isLegacy()) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5438 | title = ContrastColorUtil.clearColorSpans(title); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5439 | } else { |
| 5440 | outResultColor = new ColorStateList[1]; |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5441 | title = ensureColorSpanContrast(title, background, outResultColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5442 | } |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5443 | button.setTextViewText(R.id.action0, processTextSpans(title)); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5444 | setTextViewColorPrimary(button, R.id.action0, p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5445 | int rippleColor; |
| 5446 | boolean hasColorOverride = outResultColor != null && outResultColor[0] != null; |
| 5447 | if (hasColorOverride) { |
| 5448 | // There's a span spanning the full text, let's take it and use it as the |
| 5449 | // background color |
| 5450 | background = outResultColor[0].getDefaultColor(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5451 | int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5452 | background, mInNightMode); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5453 | button.setTextColor(R.id.action0, textColor); |
| 5454 | rippleColor = textColor; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5455 | } else if (getRawColor(p) != COLOR_DEFAULT && !isColorized(p) |
| 5456 | && mTintActionButtons) { |
| 5457 | rippleColor = resolveContrastColor(p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5458 | button.setTextColor(R.id.action0, rippleColor); |
| 5459 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5460 | rippleColor = getPrimaryTextColor(p); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5461 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5462 | // We only want about 20% alpha for the ripple |
| 5463 | rippleColor = (rippleColor & 0x00ffffff) | 0x33000000; |
| 5464 | button.setColorStateList(R.id.action0, "setRippleColor", |
| 5465 | ColorStateList.valueOf(rippleColor)); |
| 5466 | button.setColorStateList(R.id.action0, "setButtonBackground", |
| 5467 | ColorStateList.valueOf(background)); |
| 5468 | button.setBoolean(R.id.action0, "setHasStroke", !hasColorOverride); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5469 | } else { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5470 | button.setTextViewText(R.id.action0, processTextSpans( |
| 5471 | processLegacyText(action.title))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5472 | if (isColorized(p)) { |
| 5473 | setTextViewColorPrimary(button, R.id.action0, p); |
| 5474 | } else if (getRawColor(p) != COLOR_DEFAULT && mTintActionButtons) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5475 | button.setTextColor(R.id.action0, resolveContrastColor(p)); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5476 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5477 | } |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 5478 | button.setIntTag(R.id.action0, R.id.notification_action_index_tag, |
| 5479 | mActions.indexOf(action)); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5480 | return button; |
| 5481 | } |
| 5482 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5483 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5484 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 5485 | * text if a span was found that spans over the whole text. |
| 5486 | * |
| 5487 | * @param charSequence the charSequence on which the spans are |
| 5488 | * @param background the background color to ensure the contrast against |
| 5489 | * @param outResultColor an array in which a color will be returned as the first element if |
| 5490 | * there exists a full length color span. |
| 5491 | * @return the contrasted charSequence |
| 5492 | */ |
| 5493 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 5494 | ColorStateList[] outResultColor) { |
| 5495 | if (charSequence instanceof Spanned) { |
| 5496 | Spanned ss = (Spanned) charSequence; |
| 5497 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 5498 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 5499 | for (Object span : spans) { |
| 5500 | Object resultSpan = span; |
| 5501 | int spanStart = ss.getSpanStart(span); |
| 5502 | int spanEnd = ss.getSpanEnd(span); |
| 5503 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 5504 | if (resultSpan instanceof CharacterStyle) { |
| 5505 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 5506 | } |
| 5507 | if (resultSpan instanceof TextAppearanceSpan) { |
| 5508 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 5509 | ColorStateList textColor = originalSpan.getTextColor(); |
| 5510 | if (textColor != null) { |
| 5511 | int[] colors = textColor.getColors(); |
| 5512 | int[] newColors = new int[colors.length]; |
| 5513 | for (int i = 0; i < newColors.length; i++) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5514 | newColors[i] = ContrastColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5515 | colors[i], background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5516 | } |
| 5517 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 5518 | newColors); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5519 | if (fullLength) { |
| 5520 | outResultColor[0] = textColor; |
| 5521 | // Let's drop the color from the span |
| 5522 | textColor = null; |
| 5523 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5524 | resultSpan = new TextAppearanceSpan( |
| 5525 | originalSpan.getFamily(), |
| 5526 | originalSpan.getTextStyle(), |
| 5527 | originalSpan.getTextSize(), |
| 5528 | textColor, |
| 5529 | originalSpan.getLinkTextColor()); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5530 | } |
| 5531 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 5532 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 5533 | int foregroundColor = originalSpan.getForegroundColor(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5534 | foregroundColor = ContrastColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5535 | foregroundColor, background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5536 | if (fullLength) { |
| 5537 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5538 | resultSpan = null; |
| 5539 | } else { |
| 5540 | resultSpan = new ForegroundColorSpan(foregroundColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5541 | } |
| 5542 | } else { |
| 5543 | resultSpan = span; |
| 5544 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5545 | if (resultSpan != null) { |
| 5546 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 5547 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5548 | } |
| 5549 | return builder; |
| 5550 | } |
| 5551 | return charSequence; |
| 5552 | } |
| 5553 | |
| 5554 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5555 | * @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] | 5556 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5557 | */ |
| 5558 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5559 | if (!mIsLegacyInitialized) { |
| 5560 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 5561 | < Build.VERSION_CODES.LOLLIPOP; |
| 5562 | mIsLegacyInitialized = true; |
| 5563 | } |
| 5564 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5565 | } |
| 5566 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5567 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 5568 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5569 | if (isAlreadyLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5570 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5571 | } else { |
| 5572 | return charSequence; |
| 5573 | } |
| 5574 | } |
| 5575 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5576 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5577 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5578 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5579 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5580 | StandardTemplateParams p) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5581 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5582 | int color; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5583 | if (isColorized(p)) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5584 | color = getPrimaryTextColor(p); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5585 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5586 | color = resolveContrastColor(p); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5587 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5588 | if (colorable) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5589 | contentView.setDrawableTint(R.id.icon, false, color, |
| 5590 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5591 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5592 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5593 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5594 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5595 | } |
| 5596 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5597 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5598 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5599 | * if it's grayscale). |
| 5600 | */ |
| 5601 | // TODO: also check bounds, transparency, that sort of thing. |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5602 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView, |
| 5603 | StandardTemplateParams p) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5604 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5605 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5606 | // resolve color will fall back to the default when legacy |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5607 | contentView.setDrawableTint(R.id.icon, false, resolveContrastColor(p), |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5608 | PorterDuff.Mode.SRC_ATOP); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 5609 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5610 | } |
| 5611 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 5612 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5613 | if (mN.color != COLOR_DEFAULT) { |
| 5614 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5615 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5616 | } |
| 5617 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5618 | int resolveContrastColor(StandardTemplateParams p) { |
| 5619 | int rawColor = getRawColor(p); |
| 5620 | if (mCachedContrastColorIsFor == rawColor && mCachedContrastColor != COLOR_INVALID) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5621 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5622 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5623 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5624 | int color; |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5625 | int background = mContext.getColor( |
| 5626 | com.android.internal.R.color.notification_material_background_color); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5627 | if (rawColor == COLOR_DEFAULT) { |
| 5628 | ensureColors(p); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5629 | color = ContrastColorUtil.resolveDefaultColor(mContext, background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5630 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5631 | color = ContrastColorUtil.resolveContrastColor(mContext, rawColor, |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5632 | background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5633 | } |
| 5634 | if (Color.alpha(color) < 255) { |
| 5635 | // alpha doesn't go well for color filters, so let's blend it manually |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5636 | color = ContrastColorUtil.compositeColors(color, background); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5637 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5638 | mCachedContrastColorIsFor = rawColor; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5639 | return mCachedContrastColor = color; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5640 | } |
| 5641 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5642 | /** |
| 5643 | * Return the raw color of this Notification, which doesn't necessarily satisfy contrast. |
| 5644 | * |
| 5645 | * @see #resolveContrastColor(StandardTemplateParams) for the contrasted color |
| 5646 | * @param p the template params to inflate this with |
| 5647 | */ |
| 5648 | private int getRawColor(StandardTemplateParams p) { |
| 5649 | if (p.forceDefaultColor) { |
| 5650 | return COLOR_DEFAULT; |
| 5651 | } |
| 5652 | return mN.color; |
| 5653 | } |
| 5654 | |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5655 | int resolveNeutralColor() { |
| 5656 | if (mNeutralColor != COLOR_INVALID) { |
| 5657 | return mNeutralColor; |
| 5658 | } |
| 5659 | int background = mContext.getColor( |
| 5660 | com.android.internal.R.color.notification_material_background_color); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5661 | mNeutralColor = ContrastColorUtil.resolveDefaultColor(mContext, background, |
| 5662 | mInNightMode); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5663 | if (Color.alpha(mNeutralColor) < 255) { |
| 5664 | // alpha doesn't go well for color filters, so let's blend it manually |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5665 | mNeutralColor = ContrastColorUtil.compositeColors(mNeutralColor, background); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5666 | } |
| 5667 | return mNeutralColor; |
| 5668 | } |
| 5669 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5670 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5671 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5672 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5673 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5674 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5675 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5676 | mN.actions = new Action[mActions.size()]; |
| 5677 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5678 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5679 | if (!mPersonList.isEmpty()) { |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 5680 | mN.extras.putParcelableArrayList(EXTRA_PEOPLE_LIST, mPersonList); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 5681 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5682 | if (mN.bigContentView != null || mN.contentView != null |
| 5683 | || mN.headsUpContentView != null) { |
| 5684 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 5685 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5686 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5687 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5688 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5689 | /** |
| 5690 | * Creates a Builder from an existing notification so further changes can be made. |
| 5691 | * @param context The context for your application / activity. |
| 5692 | * @param n The notification to create a Builder from. |
| 5693 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5694 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5695 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5696 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 5697 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5698 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5699 | if (applicationInfo != null) { |
| 5700 | try { |
| 5701 | builderContext = context.createApplicationContext(applicationInfo, |
| 5702 | Context.CONTEXT_RESTRICTED); |
| 5703 | } catch (NameNotFoundException e) { |
| 5704 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 5705 | builderContext = context; // try with our context |
| 5706 | } |
| 5707 | } else { |
| 5708 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5709 | } |
| 5710 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5711 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5712 | } |
| 5713 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5714 | /** |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 5715 | * Determines whether the platform can generate contextual actions for a notification. |
| 5716 | * By default this is true. |
| 5717 | */ |
| 5718 | public Builder setAllowSystemGeneratedContextualActions(boolean allowed) { |
| 5719 | mN.mAllowSystemGeneratedContextualActions = allowed; |
| 5720 | return this; |
| 5721 | } |
| 5722 | |
| 5723 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5724 | * @deprecated Use {@link #build()} instead. |
| 5725 | */ |
| 5726 | @Deprecated |
| 5727 | public Notification getNotification() { |
| 5728 | return build(); |
| 5729 | } |
| 5730 | |
| 5731 | /** |
| 5732 | * Combine all of the options that have been set and return a new {@link Notification} |
| 5733 | * object. |
| 5734 | */ |
| 5735 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5736 | // first, add any extras from the calling code |
| 5737 | if (mUserExtras != null) { |
| 5738 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5739 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5740 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5741 | mN.creationTime = System.currentTimeMillis(); |
| 5742 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5743 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5744 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 5745 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5746 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5747 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5748 | if (mStyle != null) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5749 | mStyle.reduceImageSizes(mContext); |
| 5750 | mStyle.purgeResources(); |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 5751 | mStyle.validate(mContext); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5752 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5753 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5754 | mN.reduceImageSizes(mContext); |
| 5755 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5756 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5757 | && (useExistingRemoteView())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5758 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5759 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5760 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 5761 | mN.contentView.getSequenceNumber()); |
| 5762 | } |
| 5763 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5764 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5765 | if (mN.bigContentView != null) { |
| 5766 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 5767 | mN.bigContentView.getSequenceNumber()); |
| 5768 | } |
| 5769 | } |
| 5770 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5771 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5772 | if (mN.headsUpContentView != null) { |
| 5773 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 5774 | mN.headsUpContentView.getSequenceNumber()); |
| 5775 | } |
| 5776 | } |
| 5777 | } |
| 5778 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 5779 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 5780 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 5781 | } |
| 5782 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 5783 | mN.allPendingIntents = null; |
| 5784 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5785 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5786 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5787 | |
| 5788 | /** |
| 5789 | * Apply this Builder to an existing {@link Notification} object. |
| 5790 | * |
| 5791 | * @hide |
| 5792 | */ |
| 5793 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 5794 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5795 | return n; |
| 5796 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5797 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5798 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5799 | * Removes RemoteViews that were created for compatibility from {@param n}, if they did not |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5800 | * change. Also removes extenders on low ram devices, as |
| 5801 | * {@link android.service.notification.NotificationListenerService} services are disabled. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5802 | * |
| 5803 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 5804 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5805 | * @hide |
| 5806 | */ |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5807 | public static Notification maybeCloneStrippedForDelivery(Notification n, boolean isLowRam, |
| 5808 | Context context) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5809 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5810 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5811 | // Only strip views for known Styles because we won't know how to |
| 5812 | // re-create them otherwise. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5813 | if (!isLowRam |
| 5814 | && !TextUtils.isEmpty(templateClass) |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5815 | && getNotificationStyleClass(templateClass) == null) { |
| 5816 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5817 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5818 | |
| 5819 | // Only strip unmodified BuilderRemoteViews. |
| 5820 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5821 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5822 | n.contentView.getSequenceNumber(); |
| 5823 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5824 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5825 | n.bigContentView.getSequenceNumber(); |
| 5826 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5827 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5828 | n.headsUpContentView.getSequenceNumber(); |
| 5829 | |
| 5830 | // Nothing to do here, no need to clone. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5831 | if (!isLowRam |
| 5832 | && !stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5833 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5834 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5835 | |
| 5836 | Notification clone = n.clone(); |
| 5837 | if (stripContentView) { |
| 5838 | clone.contentView = null; |
| 5839 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 5840 | } |
| 5841 | if (stripBigContentView) { |
| 5842 | clone.bigContentView = null; |
| 5843 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 5844 | } |
| 5845 | if (stripHeadsUpContentView) { |
| 5846 | clone.headsUpContentView = null; |
| 5847 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 5848 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5849 | if (isLowRam) { |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5850 | String[] allowedServices = context.getResources().getStringArray( |
| 5851 | R.array.config_allowedManagedServicesOnLowRamDevices); |
| 5852 | if (allowedServices.length == 0) { |
| 5853 | clone.extras.remove(Notification.TvExtender.EXTRA_TV_EXTENDER); |
| 5854 | clone.extras.remove(WearableExtender.EXTRA_WEARABLE_EXTENSIONS); |
| 5855 | clone.extras.remove(CarExtender.EXTRA_CAR_EXTENDER); |
| 5856 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5857 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5858 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5859 | } |
| 5860 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5861 | @UnsupportedAppUsage |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5862 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5863 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5867 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5868 | } |
| 5869 | |
| 5870 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5871 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5875 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5876 | } |
| 5877 | |
| 5878 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5879 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5880 | } |
| 5881 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5882 | private int getMessagingLayoutResource() { |
| 5883 | return R.layout.notification_template_material_messaging; |
| 5884 | } |
| 5885 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5886 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5887 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5888 | } |
| 5889 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5890 | private int getEmphasizedActionLayoutResource() { |
| 5891 | return R.layout.notification_material_action_emphasized; |
| 5892 | } |
| 5893 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5894 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5895 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5896 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5897 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5898 | private int getBackgroundColor(StandardTemplateParams p) { |
| 5899 | if (isColorized(p)) { |
| 5900 | return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : getRawColor(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5901 | } else { |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5902 | return COLOR_DEFAULT; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5903 | } |
| 5904 | } |
| 5905 | |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5906 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5907 | * Gets a neutral color that can be used for icons or similar that should not stand out. |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5908 | * @param p the template params to inflate this with |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5909 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5910 | private int getNeutralColor(StandardTemplateParams p) { |
| 5911 | if (isColorized(p)) { |
| 5912 | return getSecondaryTextColor(p); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5913 | } else { |
| 5914 | return resolveNeutralColor(); |
| 5915 | } |
| 5916 | } |
| 5917 | |
| 5918 | /** |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5919 | * Same as getBackgroundColor but also resolved the default color to the background. |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5920 | * @param p the template params to inflate this with |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5921 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5922 | private int resolveBackgroundColor(StandardTemplateParams p) { |
| 5923 | int backgroundColor = getBackgroundColor(p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5924 | if (backgroundColor == COLOR_DEFAULT) { |
| 5925 | backgroundColor = mContext.getColor( |
| 5926 | com.android.internal.R.color.notification_material_background_color); |
| 5927 | } |
| 5928 | return backgroundColor; |
| 5929 | } |
| 5930 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5931 | private boolean shouldTintActionButtons() { |
| 5932 | return mTintActionButtons; |
| 5933 | } |
| 5934 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5935 | private boolean textColorsNeedInversion() { |
| 5936 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 5937 | return false; |
| 5938 | } |
| 5939 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 5940 | return targetSdkVersion > Build.VERSION_CODES.M |
| 5941 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 5942 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5943 | |
| 5944 | /** |
| 5945 | * Set a color palette to be used as the background and textColors |
| 5946 | * |
| 5947 | * @param backgroundColor the color to be used as the background |
| 5948 | * @param foregroundColor the color to be used as the foreground |
| 5949 | * |
| 5950 | * @hide |
| 5951 | */ |
| 5952 | public void setColorPalette(int backgroundColor, int foregroundColor) { |
| 5953 | mBackgroundColor = backgroundColor; |
| 5954 | mForegroundColor = foregroundColor; |
| 5955 | mTextColorsAreForBackground = COLOR_INVALID; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5956 | ensureColors(mParams.reset().fillTextsFrom(this)); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5957 | } |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5958 | |
| 5959 | /** |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5960 | * Forces all styled remoteViews to be built from scratch and not use any cached |
| 5961 | * RemoteViews. |
| 5962 | * This is needed for legacy apps that are baking in their remoteviews into the |
| 5963 | * notification. |
| 5964 | * |
| 5965 | * @hide |
| 5966 | */ |
| 5967 | public void setRebuildStyledRemoteViews(boolean rebuild) { |
| 5968 | mRebuildStyledRemoteViews = rebuild; |
| 5969 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5970 | |
| 5971 | /** |
| 5972 | * Get the text that should be displayed in the statusBar when heads upped. This is |
| 5973 | * usually just the app name, but may be different depending on the style. |
| 5974 | * |
| 5975 | * @param publicMode If true, return a text that is safe to display in public. |
| 5976 | * |
| 5977 | * @hide |
| 5978 | */ |
| 5979 | public CharSequence getHeadsUpStatusBarText(boolean publicMode) { |
| 5980 | if (mStyle != null && !publicMode) { |
| 5981 | CharSequence text = mStyle.getHeadsUpStatusBarText(); |
| 5982 | if (!TextUtils.isEmpty(text)) { |
| 5983 | return text; |
| 5984 | } |
| 5985 | } |
| 5986 | return loadHeaderAppName(); |
| 5987 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5988 | } |
| 5989 | |
| 5990 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5991 | * Reduces the image sizes to conform to a maximum allowed size. This also processes all custom |
| 5992 | * remote views. |
| 5993 | * |
| 5994 | * @hide |
| 5995 | */ |
| 5996 | void reduceImageSizes(Context context) { |
| 5997 | if (extras.getBoolean(EXTRA_REDUCED_IMAGES)) { |
| 5998 | return; |
| 5999 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6000 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6001 | if (mLargeIcon != null || largeIcon != null) { |
| 6002 | Resources resources = context.getResources(); |
| 6003 | Class<? extends Style> style = getNotificationStyle(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6004 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6005 | ? R.dimen.notification_right_icon_size_low_ram |
| 6006 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6007 | int maxHeight = maxWidth; |
| 6008 | if (MediaStyle.class.equals(style) |
| 6009 | || DecoratedMediaCustomViewStyle.class.equals(style)) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6010 | maxHeight = resources.getDimensionPixelSize(isLowRam |
| 6011 | ? R.dimen.notification_media_image_max_height_low_ram |
| 6012 | : R.dimen.notification_media_image_max_height); |
| 6013 | maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6014 | ? R.dimen.notification_media_image_max_width_low_ram |
| 6015 | : R.dimen.notification_media_image_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6016 | } |
| 6017 | if (mLargeIcon != null) { |
| 6018 | mLargeIcon.scaleDownIfNecessary(maxWidth, maxHeight); |
| 6019 | } |
| 6020 | if (largeIcon != null) { |
| 6021 | largeIcon = Icon.scaleDownIfNecessary(largeIcon, maxWidth, maxHeight); |
| 6022 | } |
| 6023 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6024 | reduceImageSizesForRemoteView(contentView, context, isLowRam); |
| 6025 | reduceImageSizesForRemoteView(headsUpContentView, context, isLowRam); |
| 6026 | reduceImageSizesForRemoteView(bigContentView, context, isLowRam); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6027 | extras.putBoolean(EXTRA_REDUCED_IMAGES, true); |
| 6028 | } |
| 6029 | |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6030 | private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context, |
| 6031 | boolean isLowRam) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6032 | if (remoteView != null) { |
| 6033 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6034 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6035 | ? R.dimen.notification_custom_view_max_image_width_low_ram |
| 6036 | : R.dimen.notification_custom_view_max_image_width); |
| 6037 | int maxHeight = resources.getDimensionPixelSize(isLowRam |
| 6038 | ? R.dimen.notification_custom_view_max_image_height_low_ram |
| 6039 | : R.dimen.notification_custom_view_max_image_height); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6040 | remoteView.reduceImageSizes(maxWidth, maxHeight); |
| 6041 | } |
| 6042 | } |
| 6043 | |
| 6044 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6045 | * @return whether this notification is a foreground service notification |
Gus Prevas | b0c1a46 | 2018-11-05 11:06:15 -0500 | [diff] [blame] | 6046 | * @hide |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6047 | */ |
Gus Prevas | b0c1a46 | 2018-11-05 11:06:15 -0500 | [diff] [blame] | 6048 | public boolean isForegroundService() { |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6049 | return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6050 | } |
| 6051 | |
| 6052 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6053 | * @return whether this notification has a media session attached |
| 6054 | * @hide |
| 6055 | */ |
| 6056 | public boolean hasMediaSession() { |
| 6057 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 6058 | } |
| 6059 | |
| 6060 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6061 | * @return the style class of this notification |
| 6062 | * @hide |
| 6063 | */ |
| 6064 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 6065 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 6066 | |
| 6067 | if (!TextUtils.isEmpty(templateClass)) { |
| 6068 | return Notification.getNotificationStyleClass(templateClass); |
| 6069 | } |
| 6070 | return null; |
| 6071 | } |
| 6072 | |
| 6073 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6074 | * @return true if this notification is colorized. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6075 | * |
| 6076 | * @hide |
| 6077 | */ |
| 6078 | public boolean isColorized() { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6079 | if (isColorizedMedia()) { |
| 6080 | return true; |
| 6081 | } |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 6082 | return extras.getBoolean(EXTRA_COLORIZED) |
| 6083 | && (hasColorizedPermission() || isForegroundService()); |
| 6084 | } |
| 6085 | |
| 6086 | /** |
| 6087 | * Returns whether an app can colorize due to the android.permission.USE_COLORIZED_NOTIFICATIONS |
| 6088 | * permission. The permission is checked when a notification is enqueued. |
| 6089 | */ |
| 6090 | private boolean hasColorizedPermission() { |
| 6091 | return (flags & Notification.FLAG_CAN_COLORIZE) != 0; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6092 | } |
| 6093 | |
| 6094 | /** |
| 6095 | * @return true if this notification is colorized and it is a media notification |
| 6096 | * |
| 6097 | * @hide |
| 6098 | */ |
| 6099 | public boolean isColorizedMedia() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6100 | Class<? extends Style> style = getNotificationStyle(); |
| 6101 | if (MediaStyle.class.equals(style)) { |
| 6102 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 6103 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 6104 | return true; |
| 6105 | } |
| 6106 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 6107 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 6108 | return true; |
| 6109 | } |
| 6110 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6111 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6112 | } |
| 6113 | |
Selim Cinek | 0847acd | 2017-04-24 19:48:29 -0700 | [diff] [blame] | 6114 | |
| 6115 | /** |
| 6116 | * @return true if this is a media notification |
| 6117 | * |
| 6118 | * @hide |
| 6119 | */ |
| 6120 | public boolean isMediaNotification() { |
| 6121 | Class<? extends Style> style = getNotificationStyle(); |
| 6122 | if (MediaStyle.class.equals(style)) { |
| 6123 | return true; |
| 6124 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 6125 | return true; |
| 6126 | } |
| 6127 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6128 | } |
| 6129 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6130 | private boolean hasLargeIcon() { |
| 6131 | return mLargeIcon != null || largeIcon != null; |
| 6132 | } |
| 6133 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6134 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6135 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 6136 | * @hide |
| 6137 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6138 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 6139 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 6140 | } |
| 6141 | |
| 6142 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6143 | * @return true if the notification will show a chronometer; false otherwise |
| 6144 | * @hide |
| 6145 | */ |
| 6146 | public boolean showsChronometer() { |
| 6147 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 6148 | } |
| 6149 | |
| 6150 | /** |
Julia Reynolds | 7ca3307 | 2017-06-29 13:58:24 -0400 | [diff] [blame] | 6151 | * @removed |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 6152 | */ |
| 6153 | @SystemApi |
| 6154 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 6155 | Class<? extends Style>[] classes = new Class[] { |
| 6156 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 6157 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 6158 | MessagingStyle.class }; |
| 6159 | for (Class<? extends Style> innerClass : classes) { |
| 6160 | if (templateClass.equals(innerClass.getName())) { |
| 6161 | return innerClass; |
| 6162 | } |
| 6163 | } |
| 6164 | return null; |
| 6165 | } |
| 6166 | |
| 6167 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6168 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 6169 | * object. |
| 6170 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 6171 | public static abstract class Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 6172 | |
| 6173 | /** |
| 6174 | * The number of items allowed simulatanously in the remote input history. |
| 6175 | * @hide |
| 6176 | */ |
| 6177 | static final int MAX_REMOTE_INPUT_HISTORY_LINES = 3; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6178 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6179 | |
| 6180 | /** |
| 6181 | * @hide |
| 6182 | */ |
| 6183 | protected CharSequence mSummaryText = null; |
| 6184 | |
| 6185 | /** |
| 6186 | * @hide |
| 6187 | */ |
| 6188 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6189 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6190 | protected Builder mBuilder; |
| 6191 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6192 | /** |
| 6193 | * Overrides ContentTitle in the big form of the template. |
| 6194 | * This defaults to the value passed to setContentTitle(). |
| 6195 | */ |
| 6196 | protected void internalSetBigContentTitle(CharSequence title) { |
| 6197 | mBigContentTitle = title; |
| 6198 | } |
| 6199 | |
| 6200 | /** |
| 6201 | * Set the first line of text after the detail section in the big form of the template. |
| 6202 | */ |
| 6203 | protected void internalSetSummaryText(CharSequence cs) { |
| 6204 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 6205 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6206 | } |
| 6207 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6208 | public void setBuilder(Builder builder) { |
| 6209 | if (mBuilder != builder) { |
| 6210 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 6211 | if (mBuilder != null) { |
| 6212 | mBuilder.setStyle(this); |
| 6213 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6214 | } |
| 6215 | } |
| 6216 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6217 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6218 | if (mBuilder == null) { |
| 6219 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 6220 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6221 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6222 | |
| 6223 | protected RemoteViews getStandardView(int layoutId) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6224 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder); |
| 6225 | return getStandardView(layoutId, p, null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6226 | } |
| 6227 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6228 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6229 | /** |
| 6230 | * Get the standard view for this style. |
| 6231 | * |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6232 | * @param layoutId The layout id to use. |
| 6233 | * @param p the params for this inflation. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6234 | * @param result The result where template bind information is saved. |
| 6235 | * @return A remoteView for this style. |
| 6236 | * @hide |
| 6237 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6238 | protected RemoteViews getStandardView(int layoutId, StandardTemplateParams p, |
| 6239 | TemplateBindResult result) { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6240 | checkBuilder(); |
| 6241 | |
| 6242 | if (mBigContentTitle != null) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6243 | p.title = mBigContentTitle; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6244 | } |
| 6245 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6246 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId, p, |
| 6247 | result); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6248 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6249 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 6250 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 6251 | } else { |
| 6252 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6253 | } |
| 6254 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6255 | return contentView; |
| 6256 | } |
| 6257 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6258 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6259 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6260 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6261 | * |
| 6262 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6263 | * @hide |
| 6264 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6265 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6266 | return null; |
| 6267 | } |
| 6268 | |
| 6269 | /** |
| 6270 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 6271 | * @hide |
| 6272 | */ |
| 6273 | public RemoteViews makeBigContentView() { |
| 6274 | return null; |
| 6275 | } |
| 6276 | |
| 6277 | /** |
| 6278 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6279 | * |
| 6280 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6281 | * @hide |
| 6282 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6283 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6284 | return null; |
| 6285 | } |
| 6286 | |
| 6287 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6288 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6289 | * @hide |
| 6290 | */ |
| 6291 | public void addExtras(Bundle extras) { |
| 6292 | if (mSummaryTextSet) { |
| 6293 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 6294 | } |
| 6295 | if (mBigContentTitle != null) { |
| 6296 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 6297 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 6298 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6299 | } |
| 6300 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6301 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6302 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6303 | * @hide |
| 6304 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6305 | protected void restoreFromExtras(Bundle extras) { |
| 6306 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 6307 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 6308 | mSummaryTextSet = true; |
| 6309 | } |
| 6310 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 6311 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | |
| 6316 | /** |
| 6317 | * @hide |
| 6318 | */ |
| 6319 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6320 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6321 | return wip; |
| 6322 | } |
| 6323 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6324 | /** |
| 6325 | * @hide |
| 6326 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6327 | public void purgeResources() {} |
| 6328 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6329 | /** |
| 6330 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 6331 | * attached to. |
| 6332 | * |
| 6333 | * @return the fully constructed Notification. |
| 6334 | */ |
| 6335 | public Notification build() { |
| 6336 | checkBuilder(); |
| 6337 | return mBuilder.build(); |
| 6338 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6339 | |
| 6340 | /** |
| 6341 | * @hide |
| 6342 | * @return true if the style positions the progress bar on the second line; false if the |
| 6343 | * style hides the progress bar |
| 6344 | */ |
| 6345 | protected boolean hasProgress() { |
| 6346 | return true; |
| 6347 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6348 | |
| 6349 | /** |
| 6350 | * @hide |
| 6351 | * @return Whether we should put the summary be put into the notification header |
| 6352 | */ |
| 6353 | public boolean hasSummaryInHeader() { |
| 6354 | return true; |
| 6355 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6356 | |
| 6357 | /** |
| 6358 | * @hide |
| 6359 | * @return Whether custom content views are displayed inline in the style |
| 6360 | */ |
| 6361 | public boolean displayCustomViewInline() { |
| 6362 | return false; |
| 6363 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6364 | |
| 6365 | /** |
| 6366 | * Reduces the image sizes contained in this style. |
| 6367 | * |
| 6368 | * @hide |
| 6369 | */ |
| 6370 | public void reduceImageSizes(Context context) { |
| 6371 | } |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6372 | |
| 6373 | /** |
| 6374 | * Validate that this style was properly composed. This is called at build time. |
| 6375 | * @hide |
| 6376 | */ |
| 6377 | public void validate(Context context) { |
| 6378 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6379 | |
| 6380 | /** |
| 6381 | * @hide |
| 6382 | */ |
| 6383 | public abstract boolean areNotificationsVisiblyDifferent(Style other); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 6384 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6385 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6386 | * @return the text that should be displayed in the statusBar when heads-upped. |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6387 | * If {@code null} is returned, the default implementation will be used. |
| 6388 | * |
| 6389 | * @hide |
| 6390 | */ |
| 6391 | public CharSequence getHeadsUpStatusBarText() { |
| 6392 | return null; |
| 6393 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 6394 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6395 | |
| 6396 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6397 | * 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] | 6398 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6399 | * 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] | 6400 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6401 | * Notification notif = new Notification.Builder(mContext) |
| 6402 | * .setContentTitle("New photo from " + sender.toString()) |
| 6403 | * .setContentText(subject) |
| 6404 | * .setSmallIcon(R.drawable.new_post) |
| 6405 | * .setLargeIcon(aBitmap) |
| 6406 | * .setStyle(new Notification.BigPictureStyle() |
| 6407 | * .bigPicture(aBigBitmap)) |
| 6408 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6409 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6410 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6411 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6412 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6413 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6414 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6415 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6416 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6417 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6418 | public BigPictureStyle() { |
| 6419 | } |
| 6420 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6421 | /** |
| 6422 | * @deprecated use {@code BigPictureStyle()}. |
| 6423 | */ |
| 6424 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6425 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6426 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6427 | } |
| 6428 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6429 | /** |
| 6430 | * Overrides ContentTitle in the big form of the template. |
| 6431 | * This defaults to the value passed to setContentTitle(). |
| 6432 | */ |
| 6433 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6434 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6435 | return this; |
| 6436 | } |
| 6437 | |
| 6438 | /** |
| 6439 | * Set the first line of text after the detail section in the big form of the template. |
| 6440 | */ |
| 6441 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6442 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6443 | return this; |
| 6444 | } |
| 6445 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6446 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6447 | * @hide |
| 6448 | */ |
| 6449 | public Bitmap getBigPicture() { |
| 6450 | return mPicture; |
| 6451 | } |
| 6452 | |
| 6453 | /** |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6454 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 6455 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6456 | public BigPictureStyle bigPicture(Bitmap b) { |
| 6457 | mPicture = b; |
| 6458 | return this; |
| 6459 | } |
| 6460 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6461 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6462 | * Override the large icon when the big notification is shown. |
| 6463 | */ |
| 6464 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6465 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 6466 | } |
| 6467 | |
| 6468 | /** |
| 6469 | * Override the large icon when the big notification is shown. |
| 6470 | */ |
| 6471 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6472 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6473 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6474 | return this; |
| 6475 | } |
| 6476 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6477 | /** @hide */ |
| 6478 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 6479 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6480 | /** |
| 6481 | * @hide |
| 6482 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6483 | @Override |
| 6484 | public void purgeResources() { |
| 6485 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 6486 | if (mPicture != null && |
| 6487 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6488 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6489 | mPicture = mPicture.createAshmemBitmap(); |
| 6490 | } |
| 6491 | if (mBigLargeIcon != null) { |
| 6492 | mBigLargeIcon.convertToAshmem(); |
| 6493 | } |
| 6494 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6495 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6496 | /** |
| 6497 | * @hide |
| 6498 | */ |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6499 | @Override |
| 6500 | public void reduceImageSizes(Context context) { |
| 6501 | super.reduceImageSizes(context); |
| 6502 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6503 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6504 | if (mPicture != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6505 | int maxPictureWidth = resources.getDimensionPixelSize(isLowRam |
| 6506 | ? R.dimen.notification_big_picture_max_height_low_ram |
| 6507 | : R.dimen.notification_big_picture_max_height); |
| 6508 | int maxPictureHeight = resources.getDimensionPixelSize(isLowRam |
| 6509 | ? R.dimen.notification_big_picture_max_width_low_ram |
| 6510 | : R.dimen.notification_big_picture_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6511 | mPicture = Icon.scaleDownIfNecessary(mPicture, maxPictureWidth, maxPictureHeight); |
| 6512 | } |
| 6513 | if (mBigLargeIcon != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6514 | int rightIconSize = resources.getDimensionPixelSize(isLowRam |
| 6515 | ? R.dimen.notification_right_icon_size_low_ram |
| 6516 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6517 | mBigLargeIcon.scaleDownIfNecessary(rightIconSize, rightIconSize); |
| 6518 | } |
| 6519 | } |
| 6520 | |
| 6521 | /** |
| 6522 | * @hide |
| 6523 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6524 | public RemoteViews makeBigContentView() { |
| 6525 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6526 | // This covers the following cases: |
| 6527 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6528 | // mN.mLargeIcon |
| 6529 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6530 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6531 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6532 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6533 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 6534 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6535 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 6536 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 6537 | // for old listeners, this is in general non-null. |
| 6538 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 6539 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6540 | } |
| 6541 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6542 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6543 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource(), |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6544 | p, null /* result */); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6545 | if (mSummaryTextSet) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6546 | contentView.setTextViewText(R.id.text, mBuilder.processTextSpans( |
| 6547 | mBuilder.processLegacyText(mSummaryText))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6548 | mBuilder.setTextViewColorSecondary(contentView, R.id.text, p); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 6549 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6550 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6551 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 6552 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6553 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6554 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6555 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6556 | } |
| 6557 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6558 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6559 | return contentView; |
| 6560 | } |
| 6561 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6562 | /** |
| 6563 | * @hide |
| 6564 | */ |
| 6565 | public void addExtras(Bundle extras) { |
| 6566 | super.addExtras(extras); |
| 6567 | |
| 6568 | if (mBigLargeIconSet) { |
| 6569 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 6570 | } |
| 6571 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 6572 | } |
| 6573 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6574 | /** |
| 6575 | * @hide |
| 6576 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6577 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6578 | protected void restoreFromExtras(Bundle extras) { |
| 6579 | super.restoreFromExtras(extras); |
| 6580 | |
| 6581 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6582 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6583 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6584 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6585 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 6586 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6587 | |
| 6588 | /** |
| 6589 | * @hide |
| 6590 | */ |
| 6591 | @Override |
| 6592 | public boolean hasSummaryInHeader() { |
| 6593 | return false; |
| 6594 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6595 | |
| 6596 | /** |
| 6597 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6598 | * Note that we aren't actually comparing the contents of the bitmaps here, so this |
| 6599 | * is only doing a cursory inspection. Bitmaps of equal size will appear the same. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6600 | */ |
| 6601 | @Override |
| 6602 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6603 | if (other == null || getClass() != other.getClass()) { |
| 6604 | return true; |
| 6605 | } |
| 6606 | BigPictureStyle otherS = (BigPictureStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6607 | return areBitmapsObviouslyDifferent(getBigPicture(), otherS.getBigPicture()); |
| 6608 | } |
| 6609 | |
| 6610 | private static boolean areBitmapsObviouslyDifferent(Bitmap a, Bitmap b) { |
| 6611 | if (a == b) { |
| 6612 | return false; |
| 6613 | } |
| 6614 | if (a == null || b == null) { |
| 6615 | return true; |
| 6616 | } |
| 6617 | return a.getWidth() != b.getWidth() |
| 6618 | || a.getHeight() != b.getHeight() |
| 6619 | || a.getConfig() != b.getConfig() |
| 6620 | || a.getGenerationId() != b.getGenerationId(); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6621 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6622 | } |
| 6623 | |
| 6624 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6625 | * 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] | 6626 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6627 | * 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] | 6628 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6629 | * Notification notif = new Notification.Builder(mContext) |
| 6630 | * .setContentTitle("New mail from " + sender.toString()) |
| 6631 | * .setContentText(subject) |
| 6632 | * .setSmallIcon(R.drawable.new_mail) |
| 6633 | * .setLargeIcon(aBitmap) |
| 6634 | * .setStyle(new Notification.BigTextStyle() |
| 6635 | * .bigText(aVeryLongString)) |
| 6636 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6637 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6638 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6639 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6640 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6641 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6642 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6643 | private CharSequence mBigText; |
| 6644 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6645 | public BigTextStyle() { |
| 6646 | } |
| 6647 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6648 | /** |
| 6649 | * @deprecated use {@code BigTextStyle()}. |
| 6650 | */ |
| 6651 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6652 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6653 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6654 | } |
| 6655 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6656 | /** |
| 6657 | * Overrides ContentTitle in the big form of the template. |
| 6658 | * This defaults to the value passed to setContentTitle(). |
| 6659 | */ |
| 6660 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6661 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6662 | return this; |
| 6663 | } |
| 6664 | |
| 6665 | /** |
| 6666 | * Set the first line of text after the detail section in the big form of the template. |
| 6667 | */ |
| 6668 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6669 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6670 | return this; |
| 6671 | } |
| 6672 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6673 | /** |
| 6674 | * Provide the longer text to be displayed in the big form of the |
| 6675 | * template in place of the content text. |
| 6676 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6677 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6678 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6679 | return this; |
| 6680 | } |
| 6681 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6682 | /** |
| 6683 | * @hide |
| 6684 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6685 | public CharSequence getBigText() { |
| 6686 | return mBigText; |
| 6687 | } |
| 6688 | |
| 6689 | /** |
| 6690 | * @hide |
| 6691 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6692 | public void addExtras(Bundle extras) { |
| 6693 | super.addExtras(extras); |
| 6694 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6695 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 6696 | } |
| 6697 | |
| 6698 | /** |
| 6699 | * @hide |
| 6700 | */ |
| 6701 | @Override |
| 6702 | protected void restoreFromExtras(Bundle extras) { |
| 6703 | super.restoreFromExtras(extras); |
| 6704 | |
| 6705 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6706 | } |
| 6707 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6708 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6709 | * @param increasedHeight true if this layout be created with an increased height. |
| 6710 | * |
| 6711 | * @hide |
| 6712 | */ |
| 6713 | @Override |
| 6714 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6715 | if (increasedHeight) { |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6716 | mBuilder.mOriginalActions = mBuilder.mActions; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6717 | mBuilder.mActions = new ArrayList<>(); |
| 6718 | RemoteViews remoteViews = makeBigContentView(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6719 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6720 | mBuilder.mOriginalActions = null; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6721 | return remoteViews; |
| 6722 | } |
| 6723 | return super.makeContentView(increasedHeight); |
| 6724 | } |
| 6725 | |
| 6726 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6727 | * @hide |
| 6728 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6729 | @Override |
| 6730 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 6731 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 6732 | return makeBigContentView(); |
| 6733 | } |
| 6734 | return super.makeHeadsUpContentView(increasedHeight); |
| 6735 | } |
| 6736 | |
| 6737 | /** |
| 6738 | * @hide |
| 6739 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6740 | public RemoteViews makeBigContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6741 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder).text(null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6742 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6743 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource(), p, |
| 6744 | result); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 6745 | contentView.setInt(R.id.big_text, "setImageEndMargin", result.getIconMarginEnd()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6746 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 6747 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6748 | if (TextUtils.isEmpty(bigTextText)) { |
| 6749 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 6750 | // experience |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6751 | bigTextText = mBuilder.processLegacyText( |
| 6752 | mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT)); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6753 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6754 | contentView.setTextViewText(R.id.big_text, mBuilder.processTextSpans(bigTextText)); |
| 6755 | mBuilder.setTextViewColorSecondary(contentView, R.id.big_text, p); |
| 6756 | contentView.setViewVisibility(R.id.big_text, |
| 6757 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 6758 | contentView.setBoolean(R.id.big_text, "setHasImage", |
| 6759 | result.isRightIconContainerVisible()); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 6760 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6761 | return contentView; |
| 6762 | } |
| 6763 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6764 | /** |
| 6765 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6766 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6767 | */ |
| 6768 | @Override |
| 6769 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6770 | if (other == null || getClass() != other.getClass()) { |
| 6771 | return true; |
| 6772 | } |
| 6773 | BigTextStyle newS = (BigTextStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6774 | return !Objects.equals(String.valueOf(getBigText()), String.valueOf(newS.getBigText())); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6775 | } |
| 6776 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6777 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6778 | |
| 6779 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6780 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 6781 | * messages of varying types between any number of people. |
| 6782 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6783 | * <p> |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6784 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 6785 | * user will always see the normal notification view. |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6786 | * |
| 6787 | * <p> |
| 6788 | * If the app is targeting Android P and above, it is required to use the {@link Person} |
| 6789 | * class in order to get an optimal rendering of the notification and its avatars. For |
| 6790 | * conversations involving multiple people, the app should also make sure that it marks the |
| 6791 | * conversation as a group with {@link #setGroupConversation(boolean)}. |
| 6792 | * |
| 6793 | * <p> |
| 6794 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior. |
| 6795 | * Here's an example of how this may be used: |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6796 | * <pre class="prettyprint"> |
| 6797 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6798 | * Person user = new Person.Builder().setIcon(userIcon).setName(userName).build(); |
| 6799 | * MessagingStyle style = new MessagingStyle(user) |
| 6800 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getPerson()) |
| 6801 | * .addMessage(messages[2].getText(), messages[2].getTime(), messages[2].getPerson()) |
| 6802 | * .setGroupConversation(hasMultiplePeople()); |
| 6803 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6804 | * Notification noti = new Notification.Builder() |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6805 | * .setContentTitle("2 new messages with " + sender.toString()) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6806 | * .setContentText(subject) |
| 6807 | * .setSmallIcon(R.drawable.new_message) |
| 6808 | * .setLargeIcon(aBitmap) |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6809 | * .setStyle(style) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6810 | * .build(); |
| 6811 | * </pre> |
| 6812 | */ |
| 6813 | public static class MessagingStyle extends Style { |
| 6814 | |
| 6815 | /** |
| 6816 | * The maximum number of messages that will be retained in the Notification itself (the |
| 6817 | * number displayed is up to the platform). |
| 6818 | */ |
| 6819 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 6820 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6821 | @NonNull Person mUser; |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6822 | @Nullable CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6823 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6824 | List<Message> mHistoricMessages = new ArrayList<>(); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6825 | boolean mIsGroupConversation; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6826 | |
| 6827 | MessagingStyle() { |
| 6828 | } |
| 6829 | |
| 6830 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6831 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 6832 | * user before the posting app reposts the notification with those messages after they've |
| 6833 | * been actually sent and in previous messages sent by the user added in |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6834 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6835 | * |
| 6836 | * @deprecated use {@code MessagingStyle(Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6837 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6838 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6839 | this(new Person.Builder().setName(userDisplayName).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6840 | } |
| 6841 | |
| 6842 | /** |
| 6843 | * @param user Required - The person displayed for any messages that are sent by the |
| 6844 | * user. Any messages added with {@link #addMessage(Notification.MessagingStyle.Message)} |
| 6845 | * who don't have a Person associated with it will be displayed as if they were sent |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6846 | * by this user. The user also needs to have a valid name associated with it, which will |
| 6847 | * be enforced starting in Android P. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6848 | */ |
| 6849 | public MessagingStyle(@NonNull Person user) { |
| 6850 | mUser = user; |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6851 | } |
| 6852 | |
| 6853 | /** |
| 6854 | * Validate that this style was properly composed. This is called at build time. |
| 6855 | * @hide |
| 6856 | */ |
| 6857 | @Override |
| 6858 | public void validate(Context context) { |
| 6859 | super.validate(context); |
| 6860 | if (context.getApplicationInfo().targetSdkVersion |
| 6861 | >= Build.VERSION_CODES.P && (mUser == null || mUser.getName() == null)) { |
| 6862 | throw new RuntimeException("User must be valid and have a name."); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6863 | } |
| 6864 | } |
| 6865 | |
| 6866 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6867 | * @return the text that should be displayed in the statusBar when heads upped. |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6868 | * If {@code null} is returned, the default implementation will be used. |
| 6869 | * |
| 6870 | * @hide |
| 6871 | */ |
| 6872 | @Override |
| 6873 | public CharSequence getHeadsUpStatusBarText() { |
| 6874 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
| 6875 | ? super.mBigContentTitle |
| 6876 | : mConversationTitle; |
| 6877 | if (!TextUtils.isEmpty(conversationTitle) && !hasOnlyWhiteSpaceSenders()) { |
| 6878 | return conversationTitle; |
| 6879 | } |
| 6880 | return null; |
| 6881 | } |
| 6882 | |
| 6883 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6884 | * @return the user to be displayed for any replies sent by the user |
| 6885 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6886 | @NonNull |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6887 | public Person getUser() { |
| 6888 | return mUser; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | /** |
| 6892 | * Returns the name to be displayed for any replies sent by the user |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6893 | * |
| 6894 | * @deprecated use {@link #getUser()} instead |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6895 | */ |
| 6896 | public CharSequence getUserDisplayName() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6897 | return mUser.getName(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6898 | } |
| 6899 | |
| 6900 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6901 | * Sets the title to be displayed on this conversation. May be set to {@code null}. |
| 6902 | * |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6903 | * <p>This API's behavior was changed in SDK version {@link Build.VERSION_CODES#P}. If your |
| 6904 | * application's target version is less than {@link Build.VERSION_CODES#P}, setting a |
| 6905 | * conversation title to a non-null value will make {@link #isGroupConversation()} return |
| 6906 | * {@code true} and passing {@code null} will make it return {@code false}. In |
| 6907 | * {@link Build.VERSION_CODES#P} and beyond, use {@link #setGroupConversation(boolean)} |
| 6908 | * to set group conversation status. |
| 6909 | * |
| 6910 | * @param conversationTitle Title displayed for this conversation |
| 6911 | * @return this object for method chaining |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6912 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6913 | public MessagingStyle setConversationTitle(@Nullable CharSequence conversationTitle) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6914 | mConversationTitle = conversationTitle; |
| 6915 | return this; |
| 6916 | } |
| 6917 | |
| 6918 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6919 | * Return the title to be displayed on this conversation. May return {@code null}. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6920 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6921 | @Nullable |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6922 | public CharSequence getConversationTitle() { |
| 6923 | return mConversationTitle; |
| 6924 | } |
| 6925 | |
| 6926 | /** |
| 6927 | * Adds a message for display by this notification. Convenience call for a simple |
| 6928 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6929 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6930 | * @param timestamp Time at which the message arrived |
| 6931 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 6932 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 6933 | * the platform will insert {@link #getUserDisplayName()}. |
| 6934 | * Should be unique amongst all individuals in the conversation, and should be |
| 6935 | * consistent during re-posts of the notification. |
| 6936 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 6937 | * @see Message#Notification.MessagingStyle.Message(CharSequence, long, CharSequence) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6938 | * |
| 6939 | * @return this object for method chaining |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6940 | * |
| 6941 | * @deprecated use {@link #addMessage(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6942 | */ |
| 6943 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6944 | return addMessage(text, timestamp, |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6945 | sender == null ? null : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6946 | } |
| 6947 | |
| 6948 | /** |
| 6949 | * Adds a message for display by this notification. Convenience call for a simple |
| 6950 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6951 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6952 | * @param timestamp Time at which the message arrived |
| 6953 | * @param sender The {@link Person} who sent the message. |
| 6954 | * Should be <code>null</code> for messages by the current user, in which case |
| 6955 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 6956 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 6957 | * @see Message#Notification.MessagingStyle.Message(CharSequence, long, CharSequence) |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6958 | * |
| 6959 | * @return this object for method chaining |
| 6960 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6961 | public MessagingStyle addMessage(@NonNull CharSequence text, long timestamp, |
| 6962 | @Nullable Person sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6963 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6964 | } |
| 6965 | |
| 6966 | /** |
| 6967 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6968 | * |
| 6969 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6970 | * the newest last. |
| 6971 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6972 | * @param message The {@link Message} to be displayed |
| 6973 | * @return this object for method chaining |
| 6974 | */ |
| 6975 | public MessagingStyle addMessage(Message message) { |
| 6976 | mMessages.add(message); |
| 6977 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 6978 | mMessages.remove(0); |
| 6979 | } |
| 6980 | return this; |
| 6981 | } |
| 6982 | |
| 6983 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6984 | * Adds a {@link Message} for historic context in this notification. |
| 6985 | * |
| 6986 | * <p>Messages should be added as historic if they are not the main subject of the |
| 6987 | * notification but may give context to a conversation. The system may choose to present |
| 6988 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 6989 | * |
| 6990 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6991 | * the newest last. |
| 6992 | * |
| 6993 | * @param message The historic {@link Message} to be added |
| 6994 | * @return this object for method chaining |
| 6995 | */ |
| 6996 | public MessagingStyle addHistoricMessage(Message message) { |
| 6997 | mHistoricMessages.add(message); |
| 6998 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 6999 | mHistoricMessages.remove(0); |
| 7000 | } |
| 7001 | return this; |
| 7002 | } |
| 7003 | |
| 7004 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7005 | * Gets the list of {@code Message} objects that represent the notification |
| 7006 | */ |
| 7007 | public List<Message> getMessages() { |
| 7008 | return mMessages; |
| 7009 | } |
| 7010 | |
| 7011 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7012 | * Gets the list of historic {@code Message}s in the notification. |
| 7013 | */ |
| 7014 | public List<Message> getHistoricMessages() { |
| 7015 | return mHistoricMessages; |
| 7016 | } |
| 7017 | |
| 7018 | /** |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7019 | * Sets whether this conversation notification represents a group. If the app is targeting |
| 7020 | * Android P, this is required if the app wants to display the largeIcon set with |
| 7021 | * {@link Notification.Builder#setLargeIcon(Bitmap)}, otherwise it will be hidden. |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7022 | * |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7023 | * @param isGroupConversation {@code true} if the conversation represents a group, |
| 7024 | * {@code false} otherwise. |
| 7025 | * @return this object for method chaining |
| 7026 | */ |
| 7027 | public MessagingStyle setGroupConversation(boolean isGroupConversation) { |
| 7028 | mIsGroupConversation = isGroupConversation; |
| 7029 | return this; |
| 7030 | } |
| 7031 | |
| 7032 | /** |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7033 | * Returns {@code true} if this notification represents a group conversation, otherwise |
| 7034 | * {@code false}. |
| 7035 | * |
| 7036 | * <p> If the application that generated this {@link MessagingStyle} targets an SDK version |
| 7037 | * less than {@link Build.VERSION_CODES#P}, this method becomes dependent on whether or |
| 7038 | * not the conversation title is set; returning {@code true} if the conversation title is |
| 7039 | * a non-null value, or {@code false} otherwise. From {@link Build.VERSION_CODES#P} forward, |
| 7040 | * this method returns what's set by {@link #setGroupConversation(boolean)} allowing for |
| 7041 | * named, non-group conversations. |
| 7042 | * |
| 7043 | * @see #setConversationTitle(CharSequence) |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7044 | */ |
| 7045 | public boolean isGroupConversation() { |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7046 | // When target SDK version is < P, a non-null conversation title dictates if this is |
| 7047 | // as group conversation. |
| 7048 | if (mBuilder != null |
| 7049 | && mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 7050 | < Build.VERSION_CODES.P) { |
| 7051 | return mConversationTitle != null; |
| 7052 | } |
| 7053 | |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7054 | return mIsGroupConversation; |
| 7055 | } |
| 7056 | |
| 7057 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7058 | * @hide |
| 7059 | */ |
| 7060 | @Override |
| 7061 | public void addExtras(Bundle extras) { |
| 7062 | super.addExtras(extras); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7063 | if (mUser != null) { |
| 7064 | // For legacy usages |
| 7065 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUser.getName()); |
| 7066 | extras.putParcelable(EXTRA_MESSAGING_PERSON, mUser); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7067 | } |
| 7068 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7069 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7070 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7071 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 7072 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7073 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7074 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 7075 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 7076 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7077 | |
| 7078 | fixTitleAndTextExtras(extras); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7079 | extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7080 | } |
| 7081 | |
| 7082 | private void fixTitleAndTextExtras(Bundle extras) { |
| 7083 | Message m = findLatestIncomingMessage(); |
| 7084 | CharSequence text = (m == null) ? null : m.mText; |
| 7085 | CharSequence sender = m == null ? null |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7086 | : m.mSender == null || TextUtils.isEmpty(m.mSender.getName()) |
| 7087 | ? mUser.getName() : m.mSender.getName(); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7088 | CharSequence title; |
| 7089 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 7090 | if (!TextUtils.isEmpty(sender)) { |
| 7091 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 7092 | title = mBuilder.mContext.getString( |
| 7093 | com.android.internal.R.string.notification_messaging_title_template, |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7094 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(sender)); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7095 | } else { |
| 7096 | title = mConversationTitle; |
| 7097 | } |
| 7098 | } else { |
| 7099 | title = sender; |
| 7100 | } |
| 7101 | |
| 7102 | if (title != null) { |
| 7103 | extras.putCharSequence(EXTRA_TITLE, title); |
| 7104 | } |
| 7105 | if (text != null) { |
| 7106 | extras.putCharSequence(EXTRA_TEXT, text); |
| 7107 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7108 | } |
| 7109 | |
| 7110 | /** |
| 7111 | * @hide |
| 7112 | */ |
| 7113 | @Override |
| 7114 | protected void restoreFromExtras(Bundle extras) { |
| 7115 | super.restoreFromExtras(extras); |
| 7116 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7117 | mUser = extras.getParcelable(EXTRA_MESSAGING_PERSON); |
| 7118 | if (mUser == null) { |
| 7119 | CharSequence displayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7120 | mUser = new Person.Builder().setName(displayName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7121 | } |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 7122 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7123 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7124 | mMessages = Message.getMessagesFromBundleArray(messages); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7125 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7126 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7127 | mIsGroupConversation = extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | /** |
| 7131 | * @hide |
| 7132 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7133 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7134 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7135 | mBuilder.mOriginalActions = mBuilder.mActions; |
| 7136 | mBuilder.mActions = new ArrayList<>(); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7137 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7138 | false /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7139 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 7140 | mBuilder.mOriginalActions = null; |
| 7141 | return remoteViews; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7142 | } |
| 7143 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7144 | /** |
| 7145 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7146 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7147 | */ |
| 7148 | @Override |
| 7149 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7150 | if (other == null || getClass() != other.getClass()) { |
| 7151 | return true; |
| 7152 | } |
| 7153 | MessagingStyle newS = (MessagingStyle) other; |
| 7154 | List<MessagingStyle.Message> oldMs = getMessages(); |
| 7155 | List<MessagingStyle.Message> newMs = newS.getMessages(); |
| 7156 | |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7157 | if (oldMs == null || newMs == null) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7158 | newMs = new ArrayList<>(); |
| 7159 | } |
| 7160 | |
| 7161 | int n = oldMs.size(); |
| 7162 | if (n != newMs.size()) { |
| 7163 | return true; |
| 7164 | } |
| 7165 | for (int i = 0; i < n; i++) { |
| 7166 | MessagingStyle.Message oldM = oldMs.get(i); |
| 7167 | MessagingStyle.Message newM = newMs.get(i); |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7168 | if (!Objects.equals( |
| 7169 | String.valueOf(oldM.getText()), |
| 7170 | String.valueOf(newM.getText()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7171 | return true; |
| 7172 | } |
| 7173 | if (!Objects.equals(oldM.getDataUri(), newM.getDataUri())) { |
| 7174 | return true; |
| 7175 | } |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7176 | String oldSender = String.valueOf(oldM.getSenderPerson() == null |
| 7177 | ? oldM.getSender() |
| 7178 | : oldM.getSenderPerson().getName()); |
| 7179 | String newSender = String.valueOf(newM.getSenderPerson() == null |
| 7180 | ? newM.getSender() |
| 7181 | : newM.getSenderPerson().getName()); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7182 | if (!Objects.equals(oldSender, newSender)) { |
| 7183 | return true; |
| 7184 | } |
| 7185 | |
| 7186 | String oldKey = oldM.getSenderPerson() == null |
| 7187 | ? null : oldM.getSenderPerson().getKey(); |
| 7188 | String newKey = newM.getSenderPerson() == null |
| 7189 | ? null : newM.getSenderPerson().getKey(); |
| 7190 | if (!Objects.equals(oldKey, newKey)) { |
| 7191 | return true; |
| 7192 | } |
| 7193 | // Other fields (like timestamp) intentionally excluded |
| 7194 | } |
| 7195 | return false; |
| 7196 | } |
| 7197 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7198 | private Message findLatestIncomingMessage() { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7199 | return findLatestIncomingMessage(mMessages); |
| 7200 | } |
| 7201 | |
| 7202 | /** |
| 7203 | * @hide |
| 7204 | */ |
| 7205 | @Nullable |
| 7206 | public static Message findLatestIncomingMessage( |
| 7207 | List<Message> messages) { |
| 7208 | for (int i = messages.size() - 1; i >= 0; i--) { |
| 7209 | Message m = messages.get(i); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7210 | // Incoming messages have a non-empty sender. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7211 | if (m.mSender != null && !TextUtils.isEmpty(m.mSender.getName())) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7212 | return m; |
| 7213 | } |
| 7214 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7215 | if (!messages.isEmpty()) { |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7216 | // No incoming messages, fall back to outgoing message |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7217 | return messages.get(messages.size() - 1); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7218 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7219 | return null; |
| 7220 | } |
| 7221 | |
| 7222 | /** |
| 7223 | * @hide |
| 7224 | */ |
| 7225 | @Override |
| 7226 | public RemoteViews makeBigContentView() { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7227 | return makeMessagingView(false /* displayImagesAtEnd */, true /* hideLargeIcon */); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7228 | } |
| 7229 | |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7230 | /** |
| 7231 | * Create a messaging layout. |
| 7232 | * |
| 7233 | * @param displayImagesAtEnd should images be displayed at the end of the content instead |
| 7234 | * of inline. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7235 | * @param hideRightIcons Should the reply affordance be shown at the end of the notification |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7236 | * @return the created remoteView. |
| 7237 | */ |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7238 | @NonNull |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7239 | private RemoteViews makeMessagingView(boolean displayImagesAtEnd, boolean hideRightIcons) { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7240 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7241 | ? super.mBigContentTitle |
| 7242 | : mConversationTitle; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7243 | boolean atLeastP = mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 7244 | >= Build.VERSION_CODES.P; |
| 7245 | boolean isOneToOne; |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7246 | CharSequence nameReplacement = null; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7247 | Icon avatarReplacement = null; |
| 7248 | if (!atLeastP) { |
| 7249 | isOneToOne = TextUtils.isEmpty(conversationTitle); |
| 7250 | avatarReplacement = mBuilder.mN.mLargeIcon; |
| 7251 | if (hasOnlyWhiteSpaceSenders()) { |
| 7252 | isOneToOne = true; |
| 7253 | nameReplacement = conversationTitle; |
| 7254 | conversationTitle = null; |
| 7255 | } |
| 7256 | } else { |
| 7257 | isOneToOne = !isGroupConversation(); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 7258 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7259 | TemplateBindResult bindResult = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7260 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).title( |
| 7261 | conversationTitle).text(null) |
| 7262 | .hideLargeIcon(hideRightIcons || isOneToOne) |
| 7263 | .hideReplyIcon(hideRightIcons) |
| 7264 | .headerTextSecondary(conversationTitle); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 7265 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7266 | mBuilder.getMessagingLayoutResource(), |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7267 | p, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7268 | bindResult); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7269 | addExtras(mBuilder.mN.extras); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7270 | // also update the end margin if there is an image |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7271 | contentView.setViewLayoutMarginEnd(R.id.notification_messaging, |
| 7272 | bindResult.getIconMarginEnd()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7273 | contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7274 | mBuilder.isColorized(p) ? mBuilder.getPrimaryTextColor(p) |
| 7275 | : mBuilder.resolveContrastColor(p)); |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 7276 | contentView.setInt(R.id.status_bar_latest_event_content, "setSenderTextColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7277 | mBuilder.getPrimaryTextColor(p)); |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 7278 | contentView.setInt(R.id.status_bar_latest_event_content, "setMessageTextColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7279 | mBuilder.getSecondaryTextColor(p)); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7280 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd", |
| 7281 | displayImagesAtEnd); |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7282 | contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement", |
| 7283 | avatarReplacement); |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7284 | contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement", |
| 7285 | nameReplacement); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7286 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne", |
| 7287 | isOneToOne); |
| 7288 | contentView.setBundle(R.id.status_bar_latest_event_content, "setData", |
| 7289 | mBuilder.mN.extras); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7290 | return contentView; |
| 7291 | } |
| 7292 | |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7293 | private boolean hasOnlyWhiteSpaceSenders() { |
| 7294 | for (int i = 0; i < mMessages.size(); i++) { |
| 7295 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7296 | Person sender = m.getSenderPerson(); |
| 7297 | if (sender != null && !isWhiteSpace(sender.getName())) { |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7298 | return false; |
| 7299 | } |
| 7300 | } |
| 7301 | return true; |
| 7302 | } |
| 7303 | |
| 7304 | private boolean isWhiteSpace(CharSequence sender) { |
| 7305 | if (TextUtils.isEmpty(sender)) { |
| 7306 | return true; |
| 7307 | } |
| 7308 | if (sender.toString().matches("^\\s*$")) { |
| 7309 | return true; |
| 7310 | } |
| 7311 | // Let's check if we only have 0 whitespace chars. Some apps did this as a workaround |
| 7312 | // For the presentation that we had. |
| 7313 | for (int i = 0; i < sender.length(); i++) { |
| 7314 | char c = sender.charAt(i); |
| 7315 | if (c != '\u200B') { |
| 7316 | return false; |
| 7317 | } |
| 7318 | } |
| 7319 | return true; |
| 7320 | } |
| 7321 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7322 | private CharSequence createConversationTitleFromMessages() { |
| 7323 | ArraySet<CharSequence> names = new ArraySet<>(); |
| 7324 | for (int i = 0; i < mMessages.size(); i++) { |
| 7325 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7326 | Person sender = m.getSenderPerson(); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7327 | if (sender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7328 | names.add(sender.getName()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7329 | } |
| 7330 | } |
| 7331 | SpannableStringBuilder title = new SpannableStringBuilder(); |
| 7332 | int size = names.size(); |
| 7333 | for (int i = 0; i < size; i++) { |
| 7334 | CharSequence name = names.valueAt(i); |
| 7335 | if (!TextUtils.isEmpty(title)) { |
| 7336 | title.append(", "); |
| 7337 | } |
| 7338 | title.append(BidiFormatter.getInstance().unicodeWrap(name)); |
| 7339 | } |
| 7340 | return title; |
| 7341 | } |
| 7342 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7343 | /** |
| 7344 | * @hide |
| 7345 | */ |
| 7346 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7347 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7348 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7349 | true /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7350 | remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1); |
| 7351 | return remoteViews; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7352 | } |
| 7353 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7354 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 7355 | return new TextAppearanceSpan(null, 0, 0, |
| 7356 | ColorStateList.valueOf(color), null); |
| 7357 | } |
| 7358 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7359 | public static final class Message { |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 7360 | /** @hide */ |
| 7361 | public static final String KEY_TEXT = "text"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7362 | static final String KEY_TIMESTAMP = "time"; |
| 7363 | static final String KEY_SENDER = "sender"; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7364 | static final String KEY_SENDER_PERSON = "sender_person"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7365 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 7366 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7367 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7368 | static final String KEY_REMOTE_INPUT_HISTORY = "remote_input_history"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7369 | |
| 7370 | private final CharSequence mText; |
| 7371 | private final long mTimestamp; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7372 | @Nullable |
| 7373 | private final Person mSender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7374 | /** True if this message was generated from the extra |
| 7375 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY} |
| 7376 | */ |
| 7377 | private final boolean mRemoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7378 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7379 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7380 | private String mDataMimeType; |
| 7381 | private Uri mDataUri; |
| 7382 | |
| 7383 | /** |
| 7384 | * Constructor |
| 7385 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7386 | * @param timestamp Time at which the message arrived |
| 7387 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 7388 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 7389 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 7390 | * Should be unique amongst all individuals in the conversation, and should be |
| 7391 | * consistent during re-posts of the notification. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7392 | * |
| 7393 | * @deprecated use {@code Message(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7394 | */ |
| 7395 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7396 | this(text, timestamp, sender == null ? null |
| 7397 | : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7398 | } |
| 7399 | |
| 7400 | /** |
| 7401 | * Constructor |
| 7402 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7403 | * @param timestamp Time at which the message arrived |
| 7404 | * @param sender The {@link Person} who sent the message. |
| 7405 | * Should be <code>null</code> for messages by the current user, in which case |
| 7406 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7407 | * <p> |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7408 | * The person provided should contain an Icon, set with |
| 7409 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7410 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7411 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7412 | * to differentiate between the different users. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7413 | * </p> |
| 7414 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 7415 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7416 | this(text, timestamp, sender, false /* remoteHistory */); |
| 7417 | } |
| 7418 | |
| 7419 | /** |
| 7420 | * Constructor |
| 7421 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7422 | * @param timestamp Time at which the message arrived |
| 7423 | * @param sender The {@link Person} who sent the message. |
| 7424 | * Should be <code>null</code> for messages by the current user, in which case |
| 7425 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7426 | * @param remoteInputHistory True if the messages was generated from the extra |
| 7427 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7428 | * <p> |
| 7429 | * The person provided should contain an Icon, set with |
| 7430 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7431 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7432 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7433 | * to differentiate between the different users. |
| 7434 | * </p> |
| 7435 | * @hide |
| 7436 | */ |
| 7437 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender, |
| 7438 | boolean remoteInputHistory) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7439 | mText = text; |
| 7440 | mTimestamp = timestamp; |
| 7441 | mSender = sender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7442 | mRemoteInputHistory = remoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7443 | } |
| 7444 | |
| 7445 | /** |
| 7446 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 7447 | * where the platform doesn't support the MIME type, the original text provided in the |
| 7448 | * constructor will be used. |
| 7449 | * @param dataMimeType The MIME type of the content. See |
| 7450 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 7451 | * types on Android and Android Wear. |
| 7452 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 7453 | * <p class="note"> |
| 7454 | * <ol> |
| 7455 | * <li>Notification Listeners including the System UI need permission to access the |
| 7456 | * data the Uri points to. The recommended ways to do this are:</li> |
| 7457 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 7458 | * the correct permission to access your provider. The preferred mechanism for |
| 7459 | * providing access is to use per-URI permissions which are temporary and only |
| 7460 | * grant access to the receiving application. An easy way to create a |
| 7461 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 7462 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 7463 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 7464 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 7465 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 7466 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 7467 | * Note that once added to the system MediaStore the content is accessible to any |
| 7468 | * app on the device.</li> |
| 7469 | * </ol> |
| 7470 | * @return this object for method chaining |
| 7471 | */ |
| 7472 | public Message setData(String dataMimeType, Uri dataUri) { |
| 7473 | mDataMimeType = dataMimeType; |
| 7474 | mDataUri = dataUri; |
| 7475 | return this; |
| 7476 | } |
| 7477 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7478 | /** |
| 7479 | * Get the text to be used for this message, or the fallback text if a type and content |
| 7480 | * Uri have been set |
| 7481 | */ |
| 7482 | public CharSequence getText() { |
| 7483 | return mText; |
| 7484 | } |
| 7485 | |
| 7486 | /** |
| 7487 | * Get the time at which this message arrived |
| 7488 | */ |
| 7489 | public long getTimestamp() { |
| 7490 | return mTimestamp; |
| 7491 | } |
| 7492 | |
| 7493 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7494 | * Get the extras Bundle for this message. |
| 7495 | */ |
| 7496 | public Bundle getExtras() { |
| 7497 | return mExtras; |
| 7498 | } |
| 7499 | |
| 7500 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7501 | * Get the text used to display the contact's name in the messaging experience |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7502 | * |
| 7503 | * @deprecated use {@link #getSenderPerson()} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7504 | */ |
| 7505 | public CharSequence getSender() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7506 | return mSender == null ? null : mSender.getName(); |
| 7507 | } |
| 7508 | |
| 7509 | /** |
| 7510 | * Get the sender associated with this message. |
| 7511 | */ |
| 7512 | @Nullable |
| 7513 | public Person getSenderPerson() { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7514 | return mSender; |
| 7515 | } |
| 7516 | |
| 7517 | /** |
| 7518 | * Get the MIME type of the data pointed to by the Uri |
| 7519 | */ |
| 7520 | public String getDataMimeType() { |
| 7521 | return mDataMimeType; |
| 7522 | } |
| 7523 | |
| 7524 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 7525 | * Get the Uri pointing to the content of the message. Can be null, in which case |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7526 | * {@see #getText()} is used. |
| 7527 | */ |
| 7528 | public Uri getDataUri() { |
| 7529 | return mDataUri; |
| 7530 | } |
| 7531 | |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7532 | /** |
| 7533 | * @return True if the message was generated from |
| 7534 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7535 | * @hide |
| 7536 | */ |
| 7537 | public boolean isRemoteInputHistory() { |
| 7538 | return mRemoteInputHistory; |
| 7539 | } |
| 7540 | |
Beverly | e98937a | 2018-11-15 10:18:57 -0500 | [diff] [blame] | 7541 | /** |
| 7542 | * @hide |
| 7543 | */ |
| 7544 | @VisibleForTesting |
| 7545 | public Bundle toBundle() { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7546 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7547 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7548 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7549 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7550 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7551 | if (mSender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7552 | // Legacy listeners need this |
| 7553 | bundle.putCharSequence(KEY_SENDER, mSender.getName()); |
| 7554 | bundle.putParcelable(KEY_SENDER_PERSON, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7555 | } |
| 7556 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7557 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7558 | } |
| 7559 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7560 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7561 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7562 | if (mExtras != null) { |
| 7563 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 7564 | } |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7565 | if (mRemoteInputHistory) { |
| 7566 | bundle.putBoolean(KEY_REMOTE_INPUT_HISTORY, mRemoteInputHistory); |
| 7567 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7568 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7569 | } |
| 7570 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7571 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 7572 | Bundle[] bundles = new Bundle[messages.size()]; |
| 7573 | final int N = messages.size(); |
| 7574 | for (int i = 0; i < N; i++) { |
| 7575 | bundles[i] = messages.get(i).toBundle(); |
| 7576 | } |
| 7577 | return bundles; |
| 7578 | } |
| 7579 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7580 | /** |
| 7581 | * @return A list of messages read from the bundles. |
| 7582 | * |
| 7583 | * @hide |
| 7584 | */ |
| 7585 | public static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
| 7586 | if (bundles == null) { |
| 7587 | return new ArrayList<>(); |
| 7588 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7589 | List<Message> messages = new ArrayList<>(bundles.length); |
| 7590 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7591 | if (bundles[i] instanceof Bundle) { |
| 7592 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 7593 | if (message != null) { |
| 7594 | messages.add(message); |
| 7595 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7596 | } |
| 7597 | } |
| 7598 | return messages; |
| 7599 | } |
| 7600 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 7601 | /** |
| 7602 | * @return The message that is stored in the bundle or null if the message couldn't be |
| 7603 | * resolved. |
| 7604 | * |
| 7605 | * @hide |
| 7606 | */ |
| 7607 | @Nullable |
| 7608 | public static Message getMessageFromBundle(Bundle bundle) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7609 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 7610 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7611 | return null; |
| 7612 | } else { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7613 | |
| 7614 | Person senderPerson = bundle.getParcelable(KEY_SENDER_PERSON); |
| 7615 | if (senderPerson == null) { |
| 7616 | // Legacy apps that use compat don't actually provide the sender objects |
| 7617 | // We need to fix the compat version to provide people / use |
| 7618 | // the native api instead |
| 7619 | CharSequence senderName = bundle.getCharSequence(KEY_SENDER); |
| 7620 | if (senderName != null) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7621 | senderPerson = new Person.Builder().setName(senderName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7622 | } |
| 7623 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7624 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7625 | bundle.getLong(KEY_TIMESTAMP), |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7626 | senderPerson, |
| 7627 | bundle.getBoolean(KEY_REMOTE_INPUT_HISTORY, false)); |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7628 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 7629 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7630 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 7631 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7632 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7633 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 7634 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 7635 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7636 | return message; |
| 7637 | } |
| 7638 | } catch (ClassCastException e) { |
| 7639 | return null; |
| 7640 | } |
| 7641 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7642 | } |
| 7643 | } |
| 7644 | |
| 7645 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7646 | * 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] | 7647 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7648 | * 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] | 7649 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7650 | * Notification notif = new Notification.Builder(mContext) |
| 7651 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 7652 | * .setContentText(subject) |
| 7653 | * .setSmallIcon(R.drawable.new_mail) |
| 7654 | * .setLargeIcon(aBitmap) |
| 7655 | * .setStyle(new Notification.InboxStyle() |
| 7656 | * .addLine(str1) |
| 7657 | * .addLine(str2) |
| 7658 | * .setContentTitle("") |
| 7659 | * .setSummaryText("+3 more")) |
| 7660 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7661 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 7662 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7663 | * @see Notification#bigContentView |
| 7664 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7665 | public static class InboxStyle extends Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7666 | |
| 7667 | /** |
| 7668 | * The number of lines of remote input history allowed until we start reducing lines. |
| 7669 | */ |
| 7670 | private static final int NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION = 1; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7671 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 7672 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7673 | public InboxStyle() { |
| 7674 | } |
| 7675 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7676 | /** |
| 7677 | * @deprecated use {@code InboxStyle()}. |
| 7678 | */ |
| 7679 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7680 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7681 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7682 | } |
| 7683 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7684 | /** |
| 7685 | * Overrides ContentTitle in the big form of the template. |
| 7686 | * This defaults to the value passed to setContentTitle(). |
| 7687 | */ |
| 7688 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7689 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7690 | return this; |
| 7691 | } |
| 7692 | |
| 7693 | /** |
| 7694 | * Set the first line of text after the detail section in the big form of the template. |
| 7695 | */ |
| 7696 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7697 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7698 | return this; |
| 7699 | } |
| 7700 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 7701 | /** |
| 7702 | * Append a line to the digest section of the Inbox notification. |
| 7703 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7704 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7705 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7706 | return this; |
| 7707 | } |
| 7708 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7709 | /** |
| 7710 | * @hide |
| 7711 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7712 | public ArrayList<CharSequence> getLines() { |
| 7713 | return mTexts; |
| 7714 | } |
| 7715 | |
| 7716 | /** |
| 7717 | * @hide |
| 7718 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7719 | public void addExtras(Bundle extras) { |
| 7720 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7721 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7722 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 7723 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 7724 | } |
| 7725 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7726 | /** |
| 7727 | * @hide |
| 7728 | */ |
| 7729 | @Override |
| 7730 | protected void restoreFromExtras(Bundle extras) { |
| 7731 | super.restoreFromExtras(extras); |
| 7732 | |
| 7733 | mTexts.clear(); |
| 7734 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 7735 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 7736 | } |
| 7737 | } |
| 7738 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7739 | /** |
| 7740 | * @hide |
| 7741 | */ |
| 7742 | public RemoteViews makeBigContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7743 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder).text(null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7744 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7745 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource(), p, result); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7746 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7747 | 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] | 7748 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7749 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 7750 | // Make sure all rows are gone in case we reuse a view. |
| 7751 | for (int rowId : rowIds) { |
| 7752 | contentView.setViewVisibility(rowId, View.GONE); |
| 7753 | } |
| 7754 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7755 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7756 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7757 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7758 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7759 | int onlyViewId = 0; |
| 7760 | int maxRows = rowIds.length; |
| 7761 | if (mBuilder.mActions.size() > 0) { |
| 7762 | maxRows--; |
| 7763 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7764 | CharSequence[] remoteInputHistory = mBuilder.mN.extras.getCharSequenceArray( |
| 7765 | EXTRA_REMOTE_INPUT_HISTORY); |
| 7766 | if (remoteInputHistory != null |
| 7767 | && remoteInputHistory.length > NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION) { |
| 7768 | // Let's remove some messages to make room for the remote input history. |
| 7769 | // 1 is always able to fit, but let's remove them if they are 2 or 3 |
| 7770 | int numRemoteInputs = Math.min(remoteInputHistory.length, |
| 7771 | MAX_REMOTE_INPUT_HISTORY_LINES); |
| 7772 | int totalNumRows = mTexts.size() + numRemoteInputs |
| 7773 | - NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION; |
| 7774 | if (totalNumRows > maxRows) { |
| 7775 | int overflow = totalNumRows - maxRows; |
| 7776 | if (mTexts.size() > maxRows) { |
| 7777 | // Heuristic: if the Texts don't fit anyway, we'll rather drop the last |
| 7778 | // few messages, even with the remote input |
| 7779 | maxRows -= overflow; |
| 7780 | } else { |
| 7781 | // otherwise we drop the first messages |
| 7782 | i = overflow; |
| 7783 | } |
| 7784 | } |
| 7785 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7786 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7787 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7788 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7789 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 7790 | contentView.setTextViewText(rowIds[i], |
| 7791 | mBuilder.processTextSpans(mBuilder.processLegacyText(str))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7792 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i], p); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7793 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7794 | handleInboxImageMargin(contentView, rowIds[i], first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7795 | result.getIconMarginEnd()); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7796 | if (first) { |
| 7797 | onlyViewId = rowIds[i]; |
| 7798 | } else { |
| 7799 | onlyViewId = 0; |
| 7800 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7801 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7802 | } |
| 7803 | i++; |
| 7804 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7805 | if (onlyViewId != 0) { |
| 7806 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 7807 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7808 | R.dimen.notification_text_margin_top); |
| 7809 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 7810 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7811 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7812 | return contentView; |
| 7813 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7814 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7815 | /** |
| 7816 | * @hide |
| 7817 | */ |
| 7818 | @Override |
| 7819 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7820 | if (other == null || getClass() != other.getClass()) { |
| 7821 | return true; |
| 7822 | } |
| 7823 | InboxStyle newS = (InboxStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7824 | |
| 7825 | final ArrayList<CharSequence> myLines = getLines(); |
| 7826 | final ArrayList<CharSequence> newLines = newS.getLines(); |
| 7827 | final int n = myLines.size(); |
| 7828 | if (n != newLines.size()) { |
| 7829 | return true; |
| 7830 | } |
| 7831 | |
| 7832 | for (int i = 0; i < n; i++) { |
| 7833 | if (!Objects.equals( |
| 7834 | String.valueOf(myLines.get(i)), |
| 7835 | String.valueOf(newLines.get(i)))) { |
| 7836 | return true; |
| 7837 | } |
| 7838 | } |
| 7839 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7840 | } |
| 7841 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7842 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7843 | int marginEndValue) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7844 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7845 | if (first) { |
| 7846 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 7847 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 7848 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7849 | if (!hasProgress) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7850 | endMargin = marginEndValue; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7851 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7852 | } |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7853 | contentView.setViewLayoutMarginEnd(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7854 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7855 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7856 | |
| 7857 | /** |
| 7858 | * Notification style for media playback notifications. |
| 7859 | * |
| 7860 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 7861 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 7862 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7863 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 7864 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 7865 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7866 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7867 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 7868 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 7869 | * {@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] | 7870 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7871 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7872 | * Notifications created with MediaStyle will have their category set to |
| 7873 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 7874 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7875 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7876 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 7877 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7878 | * the System UI can identify this as a notification representing an active media session |
| 7879 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 7880 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7881 | * <p> |
| 7882 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 7883 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 7884 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 7885 | * <p> |
| 7886 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7887 | * To use this style with your Notification, feed it to |
| 7888 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7889 | * <pre class="prettyprint"> |
| 7890 | * Notification noti = new Notification.Builder() |
| 7891 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 7892 | * .setContentTitle("Track title") |
| 7893 | * .setContentText("Artist - Album") |
| 7894 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7895 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 7896 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7897 | * .build(); |
| 7898 | * </pre> |
| 7899 | * |
| 7900 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7901 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7902 | */ |
| 7903 | public static class MediaStyle extends Style { |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7904 | // Changing max media buttons requires also changing templates |
| 7905 | // (notification_template_material_media and notification_template_material_big_media). |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7906 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7907 | static final int MAX_MEDIA_BUTTONS = 5; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7908 | @IdRes private static final int[] MEDIA_BUTTON_IDS = { |
| 7909 | R.id.action0, |
| 7910 | R.id.action1, |
| 7911 | R.id.action2, |
| 7912 | R.id.action3, |
| 7913 | R.id.action4, |
| 7914 | }; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7915 | |
| 7916 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7917 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7918 | |
| 7919 | public MediaStyle() { |
| 7920 | } |
| 7921 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7922 | /** |
| 7923 | * @deprecated use {@code MediaStyle()}. |
| 7924 | */ |
| 7925 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7926 | public MediaStyle(Builder builder) { |
| 7927 | setBuilder(builder); |
| 7928 | } |
| 7929 | |
| 7930 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7931 | * 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] | 7932 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7933 | * |
| 7934 | * @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] | 7935 | */ |
| 7936 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 7937 | mActionsToShowInCompact = actions; |
| 7938 | return this; |
| 7939 | } |
| 7940 | |
| 7941 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7942 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 7943 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7944 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7945 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7946 | mToken = token; |
| 7947 | return this; |
| 7948 | } |
| 7949 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7950 | /** |
| 7951 | * @hide |
| 7952 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7953 | @Override |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7954 | @UnsupportedAppUsage |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7955 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7956 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7957 | if (wip.category == null) { |
| 7958 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 7959 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7960 | return wip; |
| 7961 | } |
| 7962 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7963 | /** |
| 7964 | * @hide |
| 7965 | */ |
| 7966 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7967 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7968 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7969 | } |
| 7970 | |
| 7971 | /** |
| 7972 | * @hide |
| 7973 | */ |
| 7974 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7975 | public RemoteViews makeBigContentView() { |
| 7976 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7977 | } |
| 7978 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7979 | /** |
| 7980 | * @hide |
| 7981 | */ |
| 7982 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7983 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7984 | RemoteViews expanded = makeMediaBigContentView(); |
| 7985 | return expanded != null ? expanded : makeMediaContentView(); |
| 7986 | } |
| 7987 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7988 | /** @hide */ |
| 7989 | @Override |
| 7990 | public void addExtras(Bundle extras) { |
| 7991 | super.addExtras(extras); |
| 7992 | |
| 7993 | if (mToken != null) { |
| 7994 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 7995 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 7996 | if (mActionsToShowInCompact != null) { |
| 7997 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 7998 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7999 | } |
| 8000 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8001 | /** |
| 8002 | * @hide |
| 8003 | */ |
| 8004 | @Override |
| 8005 | protected void restoreFromExtras(Bundle extras) { |
| 8006 | super.restoreFromExtras(extras); |
| 8007 | |
| 8008 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 8009 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 8010 | } |
| 8011 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 8012 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 8013 | } |
| 8014 | } |
| 8015 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8016 | /** |
| 8017 | * @hide |
| 8018 | */ |
| 8019 | @Override |
| 8020 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8021 | if (other == null || getClass() != other.getClass()) { |
| 8022 | return true; |
| 8023 | } |
| 8024 | // All fields to compare are on the Notification object |
| 8025 | return false; |
| 8026 | } |
| 8027 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8028 | private void bindMediaActionButton(RemoteViews container, @IdRes int buttonId, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8029 | Action action, StandardTemplateParams p) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8030 | final boolean tombstone = (action.actionIntent == null); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8031 | container.setViewVisibility(buttonId, View.VISIBLE); |
| 8032 | container.setImageViewIcon(buttonId, action.getIcon()); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 8033 | |
| 8034 | // If the action buttons should not be tinted, then just use the default |
| 8035 | // notification color. Otherwise, just use the passed-in color. |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8036 | Resources resources = mBuilder.mContext.getResources(); |
| 8037 | Configuration currentConfig = resources.getConfiguration(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 8038 | boolean inNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 8039 | == Configuration.UI_MODE_NIGHT_YES; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8040 | int tintColor = mBuilder.shouldTintActionButtons() || mBuilder.isColorized(p) |
| 8041 | ? getActionColor(p) |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 8042 | : ContrastColorUtil.resolveColor(mBuilder.mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 8043 | Notification.COLOR_DEFAULT, inNightMode); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 8044 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8045 | container.setDrawableTint(buttonId, false, tintColor, |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 8046 | PorterDuff.Mode.SRC_ATOP); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8047 | |
| 8048 | final TypedArray typedArray = mBuilder.mContext.obtainStyledAttributes( |
| 8049 | new int[]{ android.R.attr.colorControlHighlight }); |
| 8050 | int rippleAlpha = Color.alpha(typedArray.getColor(0, 0)); |
| 8051 | typedArray.recycle(); |
| 8052 | int rippleColor = Color.argb(rippleAlpha, Color.red(tintColor), Color.green(tintColor), |
| 8053 | Color.blue(tintColor)); |
| 8054 | container.setRippleDrawableColor(buttonId, ColorStateList.valueOf(rippleColor)); |
| 8055 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8056 | if (!tombstone) { |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8057 | container.setOnClickPendingIntent(buttonId, action.actionIntent); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8058 | } |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8059 | container.setContentDescription(buttonId, action.title); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8060 | } |
| 8061 | |
| 8062 | private RemoteViews makeMediaContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8063 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).fillTextsFrom( |
| 8064 | mBuilder); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8065 | RemoteViews view = mBuilder.applyStandardTemplate( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8066 | R.layout.notification_template_material_media, p, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8067 | null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8068 | |
| 8069 | final int numActions = mBuilder.mActions.size(); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8070 | final int numActionsToShow = mActionsToShowInCompact == null |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8071 | ? 0 |
| 8072 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8073 | if (numActionsToShow > numActions) { |
| 8074 | throw new IllegalArgumentException(String.format( |
| 8075 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 8076 | numActions, numActions - 1)); |
| 8077 | } |
| 8078 | for (int i = 0; i < MAX_MEDIA_BUTTONS_IN_COMPACT; i++) { |
| 8079 | if (i < numActionsToShow) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8080 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8081 | bindMediaActionButton(view, MEDIA_BUTTON_IDS[i], action, p); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8082 | } else { |
| 8083 | view.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8084 | } |
| 8085 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 8086 | handleImage(view); |
| 8087 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8088 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8089 | if (mBuilder.mN.hasLargeIcon()) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8090 | endMargin = R.dimen.notification_media_image_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 8091 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8092 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8093 | return view; |
| 8094 | } |
| 8095 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8096 | private int getActionColor(StandardTemplateParams p) { |
| 8097 | return mBuilder.isColorized(p) ? mBuilder.getPrimaryTextColor(p) |
| 8098 | : mBuilder.resolveContrastColor(p); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8099 | } |
| 8100 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8101 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8102 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8103 | // Dont add an expanded view if there is no more content to be revealed |
| 8104 | int actionsInCompact = mActionsToShowInCompact == null |
| 8105 | ? 0 |
| 8106 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8107 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8108 | return null; |
| 8109 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8110 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).fillTextsFrom( |
| 8111 | mBuilder); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8112 | RemoteViews big = mBuilder.applyStandardTemplate( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8113 | R.layout.notification_template_material_big_media, p , null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8114 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8115 | for (int i = 0; i < MAX_MEDIA_BUTTONS; i++) { |
| 8116 | if (i < actionCount) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8117 | bindMediaActionButton(big, MEDIA_BUTTON_IDS[i], mBuilder.mActions.get(i), p); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8118 | } else { |
| 8119 | big.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8120 | } |
| 8121 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8122 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8123 | return big; |
| 8124 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8125 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8126 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8127 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8128 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 8129 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8130 | } |
| 8131 | } |
| 8132 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8133 | /** |
| 8134 | * @hide |
| 8135 | */ |
| 8136 | @Override |
| 8137 | protected boolean hasProgress() { |
| 8138 | return false; |
| 8139 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8140 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8141 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8142 | /** |
| 8143 | * Notification style for custom views that are decorated by the system |
| 8144 | * |
| 8145 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 8146 | * style and still obtain system decorations like the notification header with the expand |
| 8147 | * affordance and actions. |
| 8148 | * |
| 8149 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8150 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8151 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8152 | * corresponding custom views to display. |
| 8153 | * |
| 8154 | * To use this style with your Notification, feed it to |
| 8155 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8156 | * <pre class="prettyprint"> |
| 8157 | * Notification noti = new Notification.Builder() |
| 8158 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8159 | * .setLargeIcon(albumArtBitmap)) |
| 8160 | * .setCustomContentView(contentView); |
| 8161 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 8162 | * .build(); |
| 8163 | * </pre> |
| 8164 | */ |
| 8165 | public static class DecoratedCustomViewStyle extends Style { |
| 8166 | |
| 8167 | public DecoratedCustomViewStyle() { |
| 8168 | } |
| 8169 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8170 | /** |
| 8171 | * @hide |
| 8172 | */ |
| 8173 | public boolean displayCustomViewInline() { |
| 8174 | return true; |
| 8175 | } |
| 8176 | |
| 8177 | /** |
| 8178 | * @hide |
| 8179 | */ |
| 8180 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8181 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8182 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 8183 | } |
| 8184 | |
| 8185 | /** |
| 8186 | * @hide |
| 8187 | */ |
| 8188 | @Override |
| 8189 | public RemoteViews makeBigContentView() { |
| 8190 | return makeDecoratedBigContentView(); |
| 8191 | } |
| 8192 | |
| 8193 | /** |
| 8194 | * @hide |
| 8195 | */ |
| 8196 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8197 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8198 | return makeDecoratedHeadsUpContentView(); |
| 8199 | } |
| 8200 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8201 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 8202 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 8203 | ? mBuilder.mN.contentView |
| 8204 | : mBuilder.mN.headsUpContentView; |
| 8205 | if (mBuilder.mActions.size() == 0) { |
| 8206 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 8207 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8208 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8209 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8210 | mBuilder.getBigBaseLayoutResource(), result); |
| 8211 | buildIntoRemoteViewContent(remoteViews, headsUpContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8212 | return remoteViews; |
| 8213 | } |
| 8214 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8215 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8216 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8217 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8218 | mBuilder.getBaseLayoutResource(), result); |
| 8219 | buildIntoRemoteViewContent(remoteViews, customContent, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8220 | return remoteViews; |
| 8221 | } |
| 8222 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8223 | private RemoteViews makeDecoratedBigContentView() { |
| 8224 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 8225 | ? mBuilder.mN.contentView |
| 8226 | : mBuilder.mN.bigContentView; |
| 8227 | if (mBuilder.mActions.size() == 0) { |
| 8228 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 8229 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8230 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8231 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8232 | mBuilder.getBigBaseLayoutResource(), result); |
| 8233 | buildIntoRemoteViewContent(remoteViews, bigContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8234 | return remoteViews; |
| 8235 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8236 | |
| 8237 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8238 | RemoteViews customContent, TemplateBindResult result) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8239 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8240 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8241 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8242 | customContent = customContent.clone(); |
Anthony Chen | 8f5f358 | 2017-04-11 11:18:37 -0700 | [diff] [blame] | 8243 | remoteViews.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress); |
| 8244 | remoteViews.addView(R.id.notification_main_column, customContent, 0 /* index */); |
Sunny Goyal | c12d31c | 2018-11-12 16:29:18 -0800 | [diff] [blame] | 8245 | remoteViews.addFlags(RemoteViews.FLAG_REAPPLY_DISALLOWED); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8246 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8247 | // also update the end margin if there is an image |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8248 | Resources resources = mBuilder.mContext.getResources(); |
| 8249 | int endMargin = resources.getDimensionPixelSize( |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 8250 | R.dimen.notification_content_margin_end) + result.getIconMarginEnd(); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8251 | remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8252 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8253 | |
| 8254 | /** |
| 8255 | * @hide |
| 8256 | */ |
| 8257 | @Override |
| 8258 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8259 | if (other == null || getClass() != other.getClass()) { |
| 8260 | return true; |
| 8261 | } |
| 8262 | // Comparison done for all custom RemoteViews, independent of style |
| 8263 | return false; |
| 8264 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8265 | } |
| 8266 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8267 | /** |
| 8268 | * Notification style for media custom views that are decorated by the system |
| 8269 | * |
| 8270 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 8271 | * this style and still obtain system decorations like the notification header with the expand |
| 8272 | * affordance and actions. |
| 8273 | * |
| 8274 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8275 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8276 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8277 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8278 | * <p> |
| 8279 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 8280 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 8281 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8282 | * To use this style with your Notification, feed it to |
| 8283 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8284 | * <pre class="prettyprint"> |
| 8285 | * Notification noti = new Notification.Builder() |
| 8286 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8287 | * .setLargeIcon(albumArtBitmap)) |
| 8288 | * .setCustomContentView(contentView); |
| 8289 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 8290 | * .setMediaSession(mySession)) |
| 8291 | * .build(); |
| 8292 | * </pre> |
| 8293 | * |
| 8294 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 8295 | * @see android.app.Notification.MediaStyle |
| 8296 | */ |
| 8297 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 8298 | |
| 8299 | public DecoratedMediaCustomViewStyle() { |
| 8300 | } |
| 8301 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8302 | /** |
| 8303 | * @hide |
| 8304 | */ |
| 8305 | public boolean displayCustomViewInline() { |
| 8306 | return true; |
| 8307 | } |
| 8308 | |
| 8309 | /** |
| 8310 | * @hide |
| 8311 | */ |
| 8312 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8313 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 8314 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8315 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8316 | mBuilder.mN.contentView); |
| 8317 | } |
| 8318 | |
| 8319 | /** |
| 8320 | * @hide |
| 8321 | */ |
| 8322 | @Override |
| 8323 | public RemoteViews makeBigContentView() { |
| 8324 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 8325 | ? mBuilder.mN.bigContentView |
| 8326 | : mBuilder.mN.contentView; |
| 8327 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8328 | } |
| 8329 | |
| 8330 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 8331 | RemoteViews remoteViews = super.makeBigContentView(); |
| 8332 | if (remoteViews != null) { |
| 8333 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 8334 | customRemoteView); |
| 8335 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8336 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8337 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8338 | customRemoteView); |
| 8339 | } else { |
| 8340 | return null; |
| 8341 | } |
| 8342 | } |
| 8343 | |
| 8344 | /** |
| 8345 | * @hide |
| 8346 | */ |
| 8347 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8348 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8349 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 8350 | ? mBuilder.mN.headsUpContentView |
| 8351 | : mBuilder.mN.contentView; |
| 8352 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8353 | } |
| 8354 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8355 | /** |
| 8356 | * @hide |
| 8357 | */ |
| 8358 | @Override |
| 8359 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8360 | if (other == null || getClass() != other.getClass()) { |
| 8361 | return true; |
| 8362 | } |
| 8363 | // Comparison done for all custom RemoteViews, independent of style |
| 8364 | return false; |
| 8365 | } |
| 8366 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8367 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 8368 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8369 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8370 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8371 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8372 | customContent = customContent.clone(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8373 | customContent.overrideTextColors(mBuilder.getPrimaryTextColor(mBuilder.mParams)); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8374 | remoteViews.removeAllViews(id); |
| 8375 | remoteViews.addView(id, customContent); |
Sunny Goyal | c12d31c | 2018-11-12 16:29:18 -0800 | [diff] [blame] | 8376 | remoteViews.addFlags(RemoteViews.FLAG_REAPPLY_DISALLOWED); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8377 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8378 | return remoteViews; |
| 8379 | } |
| 8380 | } |
| 8381 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8382 | /** |
| 8383 | * Encapsulates the information needed to display a notification as a bubble. |
| 8384 | * |
| 8385 | * <p>A bubble is used to display app content in a floating window over the existing |
| 8386 | * foreground activity. A bubble has a collapsed state represented by an icon, |
| 8387 | * {@link BubbleMetadata.Builder#setIcon(Icon)} and an expanded state which is populated |
| 8388 | * via {@link BubbleMetadata.Builder#setIntent(PendingIntent)}.</p> |
| 8389 | * |
| 8390 | * <b>Notifications with a valid and allowed bubble will display in collapsed state |
| 8391 | * outside of the notification shade on unlocked devices. When a user interacts with the |
| 8392 | * collapsed bubble, the bubble intent will be invoked and displayed.</b> |
| 8393 | * |
| 8394 | * @see Notification.Builder#setBubbleMetadata(BubbleMetadata) |
| 8395 | */ |
| 8396 | public static final class BubbleMetadata implements Parcelable { |
| 8397 | |
| 8398 | private PendingIntent mPendingIntent; |
| 8399 | private CharSequence mTitle; |
| 8400 | private Icon mIcon; |
| 8401 | private int mDesiredHeight; |
| 8402 | |
| 8403 | private BubbleMetadata(PendingIntent intent, CharSequence title, Icon icon, int height) { |
| 8404 | mPendingIntent = intent; |
| 8405 | mTitle = title; |
| 8406 | mIcon = icon; |
| 8407 | mDesiredHeight = height; |
| 8408 | } |
| 8409 | |
| 8410 | private BubbleMetadata(Parcel in) { |
| 8411 | mPendingIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 8412 | mTitle = in.readCharSequence(); |
| 8413 | mIcon = Icon.CREATOR.createFromParcel(in); |
| 8414 | mDesiredHeight = in.readInt(); |
| 8415 | } |
| 8416 | |
| 8417 | /** |
| 8418 | * @return the pending intent used to populate the floating window for this bubble. |
| 8419 | */ |
| 8420 | public PendingIntent getIntent() { |
| 8421 | return mPendingIntent; |
| 8422 | } |
| 8423 | |
| 8424 | /** |
| 8425 | * @return the title that will appear along with the app content defined by |
| 8426 | * {@link #getIntent()} for this bubble. |
| 8427 | */ |
| 8428 | public CharSequence getTitle() { |
| 8429 | return mTitle; |
| 8430 | } |
| 8431 | |
| 8432 | /** |
| 8433 | * @return the icon that will be displayed for this bubble when it is collapsed. |
| 8434 | */ |
| 8435 | public Icon getIcon() { |
| 8436 | return mIcon; |
| 8437 | } |
| 8438 | |
| 8439 | /** |
| 8440 | * @return the ideal height for the floating window that app content defined by |
| 8441 | * {@link #getIntent()} for this bubble. |
| 8442 | */ |
| 8443 | public int getDesiredHeight() { |
| 8444 | return mDesiredHeight; |
| 8445 | } |
| 8446 | |
| 8447 | public static final Parcelable.Creator<BubbleMetadata> CREATOR = |
| 8448 | new Parcelable.Creator<BubbleMetadata>() { |
| 8449 | |
| 8450 | @Override |
| 8451 | public BubbleMetadata createFromParcel(Parcel source) { |
| 8452 | return new BubbleMetadata(source); |
| 8453 | } |
| 8454 | |
| 8455 | @Override |
| 8456 | public BubbleMetadata[] newArray(int size) { |
| 8457 | return new BubbleMetadata[size]; |
| 8458 | } |
| 8459 | }; |
| 8460 | |
| 8461 | @Override |
| 8462 | public int describeContents() { |
| 8463 | return 0; |
| 8464 | } |
| 8465 | |
| 8466 | @Override |
| 8467 | public void writeToParcel(Parcel out, int flags) { |
| 8468 | mPendingIntent.writeToParcel(out, 0); |
| 8469 | out.writeCharSequence(mTitle); |
| 8470 | mIcon.writeToParcel(out, 0); |
| 8471 | out.writeInt(mDesiredHeight); |
| 8472 | } |
| 8473 | |
| 8474 | /** |
| 8475 | * Builder to construct a {@link BubbleMetadata} object. |
| 8476 | */ |
| 8477 | public static class Builder { |
| 8478 | |
| 8479 | private PendingIntent mPendingIntent; |
| 8480 | private CharSequence mTitle; |
| 8481 | private Icon mIcon; |
| 8482 | private int mDesiredHeight; |
| 8483 | |
| 8484 | /** |
| 8485 | * Constructs a new builder object. |
| 8486 | */ |
| 8487 | public Builder() { |
| 8488 | } |
| 8489 | |
| 8490 | /** |
| 8491 | * Sets the intent that will be used when the bubble is expanded. This will display the |
| 8492 | * app content in a floating window over the existing foreground activity. |
| 8493 | */ |
| 8494 | public BubbleMetadata.Builder setIntent(PendingIntent intent) { |
| 8495 | if (intent == null) { |
| 8496 | throw new IllegalArgumentException("Bubble requires non-null pending intent"); |
| 8497 | } |
| 8498 | mPendingIntent = intent; |
| 8499 | return this; |
| 8500 | } |
| 8501 | |
| 8502 | /** |
| 8503 | * Sets the title that will appear along with the app content for this bubble. |
| 8504 | * |
| 8505 | * <p>A title is required and should expect to fit on a single line and make sense when |
| 8506 | * shown with the content defined by {@link #setIntent(PendingIntent)}.</p> |
| 8507 | */ |
| 8508 | public BubbleMetadata.Builder setTitle(CharSequence title) { |
| 8509 | if (TextUtils.isEmpty(title)) { |
| 8510 | throw new IllegalArgumentException("Bubbles require non-null or empty title"); |
| 8511 | } |
| 8512 | mTitle = title; |
| 8513 | return this; |
| 8514 | } |
| 8515 | |
| 8516 | /** |
| 8517 | * Sets the icon that will represent the bubble when it is collapsed. |
| 8518 | * |
| 8519 | * <p>An icon is required and should be representative of the content within the bubble. |
| 8520 | * If your app produces multiple bubbles, the image should be unique for each of them. |
| 8521 | * </p> |
| 8522 | */ |
| 8523 | public BubbleMetadata.Builder setIcon(Icon icon) { |
| 8524 | if (icon == null) { |
| 8525 | throw new IllegalArgumentException("Bubbles require non-null icon"); |
| 8526 | } |
| 8527 | mIcon = icon; |
| 8528 | return this; |
| 8529 | } |
| 8530 | |
| 8531 | /** |
| 8532 | * Sets the desired height for the app content defined by |
| 8533 | * {@link #setIntent(PendingIntent)}, this height may not be respected if there is not |
| 8534 | * enough space on the screen or if the provided height is too small to be useful. |
| 8535 | */ |
| 8536 | public BubbleMetadata.Builder setDesiredHeight(int height) { |
| 8537 | mDesiredHeight = Math.max(height, 0); |
| 8538 | return this; |
| 8539 | } |
| 8540 | |
| 8541 | /** |
| 8542 | * Creates the {@link BubbleMetadata} defined by this builder. |
| 8543 | * <p>Will throw {@link IllegalStateException} if required fields have not been set |
| 8544 | * on this builder.</p> |
| 8545 | */ |
| 8546 | public BubbleMetadata build() { |
| 8547 | if (mPendingIntent == null) { |
| 8548 | throw new IllegalStateException("Must supply pending intent to bubble"); |
| 8549 | } |
| 8550 | if (TextUtils.isEmpty(mTitle)) { |
| 8551 | throw new IllegalStateException("Must supply a title for the bubble"); |
| 8552 | } |
| 8553 | if (mIcon == null) { |
| 8554 | throw new IllegalStateException("Must supply an icon for the bubble"); |
| 8555 | } |
| 8556 | return new BubbleMetadata(mPendingIntent, mTitle, mIcon, mDesiredHeight); |
| 8557 | } |
| 8558 | } |
| 8559 | } |
| 8560 | |
| 8561 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8562 | // When adding a new Style subclass here, don't forget to update |
| 8563 | // Builder.getNotificationStyleClass. |
| 8564 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8565 | /** |
| 8566 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 8567 | * metadata or change options on a notification builder. |
| 8568 | */ |
| 8569 | public interface Extender { |
| 8570 | /** |
| 8571 | * Apply this extender to a notification builder. |
| 8572 | * @param builder the builder to be modified. |
| 8573 | * @return the build object for chaining. |
| 8574 | */ |
| 8575 | public Builder extend(Builder builder); |
| 8576 | } |
| 8577 | |
| 8578 | /** |
| 8579 | * Helper class to add wearable extensions to notifications. |
| 8580 | * <p class="note"> See |
| 8581 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 8582 | * for Android Wear</a> for more information on how to use this class. |
| 8583 | * <p> |
| 8584 | * To create a notification with wearable extensions: |
| 8585 | * <ol> |
| 8586 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 8587 | * properties. |
| 8588 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 8589 | * <li>Set wearable-specific properties using the |
| 8590 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 8591 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 8592 | * notification. |
| 8593 | * <li>Post the notification to the notification system with the |
| 8594 | * {@code NotificationManager.notify(...)} methods. |
| 8595 | * </ol> |
| 8596 | * |
| 8597 | * <pre class="prettyprint"> |
| 8598 | * Notification notif = new Notification.Builder(mContext) |
| 8599 | * .setContentTitle("New mail from " + sender.toString()) |
| 8600 | * .setContentText(subject) |
| 8601 | * .setSmallIcon(R.drawable.new_mail) |
| 8602 | * .extend(new Notification.WearableExtender() |
| 8603 | * .setContentIcon(R.drawable.new_mail)) |
| 8604 | * .build(); |
| 8605 | * NotificationManager notificationManger = |
| 8606 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 8607 | * notificationManger.notify(0, notif);</pre> |
| 8608 | * |
| 8609 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 8610 | * {@code WearableExtender(Notification)} constructor, |
| 8611 | * and then using the {@code get} methods to access values. |
| 8612 | * |
| 8613 | * <pre class="prettyprint"> |
| 8614 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 8615 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8616 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8617 | */ |
| 8618 | public static final class WearableExtender implements Extender { |
| 8619 | /** |
| 8620 | * Sentinel value for an action index that is unset. |
| 8621 | */ |
| 8622 | public static final int UNSET_ACTION_INDEX = -1; |
| 8623 | |
| 8624 | /** |
| 8625 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 8626 | * default sizing. |
| 8627 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 8628 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8629 | * on their content. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8630 | * |
| 8631 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8632 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8633 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8634 | public static final int SIZE_DEFAULT = 0; |
| 8635 | |
| 8636 | /** |
| 8637 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8638 | * with an extra small size. |
| 8639 | * <p>This value is only applicable for custom display notifications created using |
| 8640 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8641 | * |
| 8642 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8643 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8644 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8645 | public static final int SIZE_XSMALL = 1; |
| 8646 | |
| 8647 | /** |
| 8648 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8649 | * with a small size. |
| 8650 | * <p>This value is only applicable for custom display notifications created using |
| 8651 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8652 | * |
| 8653 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8654 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8655 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8656 | public static final int SIZE_SMALL = 2; |
| 8657 | |
| 8658 | /** |
| 8659 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8660 | * with a medium size. |
| 8661 | * <p>This value is only applicable for custom display notifications created using |
| 8662 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8663 | * |
| 8664 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8665 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8666 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8667 | public static final int SIZE_MEDIUM = 3; |
| 8668 | |
| 8669 | /** |
| 8670 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8671 | * with a large size. |
| 8672 | * <p>This value is only applicable for custom display notifications created using |
| 8673 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8674 | * |
| 8675 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8676 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8677 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8678 | public static final int SIZE_LARGE = 4; |
| 8679 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8680 | /** |
| 8681 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8682 | * full screen. |
| 8683 | * <p>This value is only applicable for custom display notifications created using |
| 8684 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8685 | * |
| 8686 | * @deprecated Display intents are no longer supported. |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8687 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8688 | @Deprecated |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8689 | public static final int SIZE_FULL_SCREEN = 5; |
| 8690 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8691 | /** |
| 8692 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 8693 | * short amount of time when this notification is displayed on the screen. This |
| 8694 | * is the default value. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8695 | * |
| 8696 | * @deprecated This feature is no longer supported. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8697 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8698 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8699 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 8700 | |
| 8701 | /** |
| 8702 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 8703 | * for a longer amount of time when this notification is displayed on the screen. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8704 | * |
| 8705 | * @deprecated This feature is no longer supported. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8706 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8707 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8708 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 8709 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8710 | /** Notification extra which contains wearable extensions */ |
| 8711 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 8712 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 8713 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8714 | private static final String KEY_ACTIONS = "actions"; |
| 8715 | private static final String KEY_FLAGS = "flags"; |
| 8716 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 8717 | private static final String KEY_PAGES = "pages"; |
| 8718 | private static final String KEY_BACKGROUND = "background"; |
| 8719 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 8720 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 8721 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 8722 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 8723 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 8724 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8725 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8726 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8727 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8728 | |
| 8729 | // Flags bitwise-ored to mFlags |
| 8730 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 8731 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 8732 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 8733 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8734 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 8735 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8736 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8737 | |
| 8738 | // Default value for flags integer |
| 8739 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 8740 | |
| 8741 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 8742 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 8743 | |
| 8744 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 8745 | private int mFlags = DEFAULT_FLAGS; |
| 8746 | private PendingIntent mDisplayIntent; |
| 8747 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 8748 | private Bitmap mBackground; |
| 8749 | private int mContentIcon; |
| 8750 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 8751 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 8752 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 8753 | private int mCustomContentHeight; |
| 8754 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8755 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8756 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8757 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8758 | |
| 8759 | /** |
| 8760 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 8761 | * options. |
| 8762 | */ |
| 8763 | public WearableExtender() { |
| 8764 | } |
| 8765 | |
| 8766 | public WearableExtender(Notification notif) { |
| 8767 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 8768 | if (wearableBundle != null) { |
| 8769 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 8770 | if (actions != null) { |
| 8771 | mActions.addAll(actions); |
| 8772 | } |
| 8773 | |
| 8774 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 8775 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 8776 | |
| 8777 | Notification[] pages = getNotificationArrayFromBundle( |
| 8778 | wearableBundle, KEY_PAGES); |
| 8779 | if (pages != null) { |
| 8780 | Collections.addAll(mPages, pages); |
| 8781 | } |
| 8782 | |
| 8783 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 8784 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 8785 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 8786 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 8787 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 8788 | UNSET_ACTION_INDEX); |
| 8789 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 8790 | SIZE_DEFAULT); |
| 8791 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 8792 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8793 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8794 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8795 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8796 | } |
| 8797 | } |
| 8798 | |
| 8799 | /** |
| 8800 | * Apply wearable extensions to a notification that is being built. This is typically |
| 8801 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 8802 | * {@link android.app.Notification.Builder}. |
| 8803 | */ |
| 8804 | @Override |
| 8805 | public Notification.Builder extend(Notification.Builder builder) { |
| 8806 | Bundle wearableBundle = new Bundle(); |
| 8807 | |
| 8808 | if (!mActions.isEmpty()) { |
| 8809 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 8810 | } |
| 8811 | if (mFlags != DEFAULT_FLAGS) { |
| 8812 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 8813 | } |
| 8814 | if (mDisplayIntent != null) { |
| 8815 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 8816 | } |
| 8817 | if (!mPages.isEmpty()) { |
| 8818 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 8819 | new Notification[mPages.size()])); |
| 8820 | } |
| 8821 | if (mBackground != null) { |
| 8822 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 8823 | } |
| 8824 | if (mContentIcon != 0) { |
| 8825 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 8826 | } |
| 8827 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 8828 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 8829 | } |
| 8830 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 8831 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 8832 | mContentActionIndex); |
| 8833 | } |
| 8834 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 8835 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 8836 | } |
| 8837 | if (mCustomContentHeight != 0) { |
| 8838 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 8839 | } |
| 8840 | if (mGravity != DEFAULT_GRAVITY) { |
| 8841 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 8842 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8843 | if (mHintScreenTimeout != 0) { |
| 8844 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 8845 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8846 | if (mDismissalId != null) { |
| 8847 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 8848 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8849 | if (mBridgeTag != null) { |
| 8850 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 8851 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8852 | |
| 8853 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 8854 | return builder; |
| 8855 | } |
| 8856 | |
| 8857 | @Override |
| 8858 | public WearableExtender clone() { |
| 8859 | WearableExtender that = new WearableExtender(); |
| 8860 | that.mActions = new ArrayList<Action>(this.mActions); |
| 8861 | that.mFlags = this.mFlags; |
| 8862 | that.mDisplayIntent = this.mDisplayIntent; |
| 8863 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 8864 | that.mBackground = this.mBackground; |
| 8865 | that.mContentIcon = this.mContentIcon; |
| 8866 | that.mContentIconGravity = this.mContentIconGravity; |
| 8867 | that.mContentActionIndex = this.mContentActionIndex; |
| 8868 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 8869 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 8870 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8871 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8872 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8873 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8874 | return that; |
| 8875 | } |
| 8876 | |
| 8877 | /** |
| 8878 | * Add a wearable action to this notification. |
| 8879 | * |
| 8880 | * <p>When wearable actions are added using this method, the set of actions that |
| 8881 | * show on a wearable device splits from devices that only show actions added |
| 8882 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 8883 | * of which actions display on different devices. |
| 8884 | * |
| 8885 | * @param action the action to add to this notification |
| 8886 | * @return this object for method chaining |
| 8887 | * @see android.app.Notification.Action |
| 8888 | */ |
| 8889 | public WearableExtender addAction(Action action) { |
| 8890 | mActions.add(action); |
| 8891 | return this; |
| 8892 | } |
| 8893 | |
| 8894 | /** |
| 8895 | * Adds wearable actions to this notification. |
| 8896 | * |
| 8897 | * <p>When wearable actions are added using this method, the set of actions that |
| 8898 | * show on a wearable device splits from devices that only show actions added |
| 8899 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 8900 | * of which actions display on different devices. |
| 8901 | * |
| 8902 | * @param actions the actions to add to this notification |
| 8903 | * @return this object for method chaining |
| 8904 | * @see android.app.Notification.Action |
| 8905 | */ |
| 8906 | public WearableExtender addActions(List<Action> actions) { |
| 8907 | mActions.addAll(actions); |
| 8908 | return this; |
| 8909 | } |
| 8910 | |
| 8911 | /** |
| 8912 | * Clear all wearable actions present on this builder. |
| 8913 | * @return this object for method chaining. |
| 8914 | * @see #addAction |
| 8915 | */ |
| 8916 | public WearableExtender clearActions() { |
| 8917 | mActions.clear(); |
| 8918 | return this; |
| 8919 | } |
| 8920 | |
| 8921 | /** |
| 8922 | * Get the wearable actions present on this notification. |
| 8923 | */ |
| 8924 | public List<Action> getActions() { |
| 8925 | return mActions; |
| 8926 | } |
| 8927 | |
| 8928 | /** |
| 8929 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8930 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 8931 | * |
| 8932 | * <pre class="prettyprint"> |
| 8933 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 8934 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 8935 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 8936 | * Notification notif = new Notification.Builder(context) |
| 8937 | * .extend(new Notification.WearableExtender() |
| 8938 | * .setDisplayIntent(displayPendingIntent) |
| 8939 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 8940 | * .build();</pre> |
| 8941 | * |
| 8942 | * <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] | 8943 | * should have an empty task affinity. It is also recommended to use the device |
| 8944 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8945 | * |
| 8946 | * <p>Example AndroidManifest.xml entry: |
| 8947 | * <pre class="prettyprint"> |
| 8948 | * <activity android:name="com.example.MyDisplayActivity" |
| 8949 | * android:exported="true" |
| 8950 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 8951 | * android:taskAffinity="" |
| 8952 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8953 | * |
| 8954 | * @param intent the {@link PendingIntent} for an activity |
| 8955 | * @return this object for method chaining |
| 8956 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8957 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8958 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8959 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8960 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 8961 | mDisplayIntent = intent; |
| 8962 | return this; |
| 8963 | } |
| 8964 | |
| 8965 | /** |
| 8966 | * Get the intent to launch inside of an activity view when displaying this |
| 8967 | * notification. This {@code PendingIntent} should be for an activity. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8968 | * |
| 8969 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8970 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8971 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8972 | public PendingIntent getDisplayIntent() { |
| 8973 | return mDisplayIntent; |
| 8974 | } |
| 8975 | |
| 8976 | /** |
| 8977 | * Add an additional page of content to display with this notification. The current |
| 8978 | * notification forms the first page, and pages added using this function form |
| 8979 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8980 | * sections. |
| 8981 | * |
| 8982 | * @param page the notification to add as another page |
| 8983 | * @return this object for method chaining |
| 8984 | * @see android.app.Notification.WearableExtender#getPages |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8985 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8986 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8987 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8988 | public WearableExtender addPage(Notification page) { |
| 8989 | mPages.add(page); |
| 8990 | return this; |
| 8991 | } |
| 8992 | |
| 8993 | /** |
| 8994 | * Add additional pages of content to display with this notification. The current |
| 8995 | * notification forms the first page, and pages added using this function form |
| 8996 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8997 | * sections. |
| 8998 | * |
| 8999 | * @param pages a list of notifications |
| 9000 | * @return this object for method chaining |
| 9001 | * @see android.app.Notification.WearableExtender#getPages |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9002 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9003 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9004 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9005 | public WearableExtender addPages(List<Notification> pages) { |
| 9006 | mPages.addAll(pages); |
| 9007 | return this; |
| 9008 | } |
| 9009 | |
| 9010 | /** |
| 9011 | * Clear all additional pages present on this builder. |
| 9012 | * @return this object for method chaining. |
| 9013 | * @see #addPage |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9014 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9015 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9016 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9017 | public WearableExtender clearPages() { |
| 9018 | mPages.clear(); |
| 9019 | return this; |
| 9020 | } |
| 9021 | |
| 9022 | /** |
| 9023 | * Get the array of additional pages of content for displaying this notification. The |
| 9024 | * current notification forms the first page, and elements within this array form |
| 9025 | * subsequent pages. This field can be used to separate a notification into multiple |
| 9026 | * sections. |
| 9027 | * @return the pages for this notification |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9028 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9029 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9030 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9031 | public List<Notification> getPages() { |
| 9032 | return mPages; |
| 9033 | } |
| 9034 | |
| 9035 | /** |
| 9036 | * Set a background image to be displayed behind the notification content. |
| 9037 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 9038 | * will work with any notification style. |
| 9039 | * |
| 9040 | * @param background the background bitmap |
| 9041 | * @return this object for method chaining |
| 9042 | * @see android.app.Notification.WearableExtender#getBackground |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9043 | * @deprecated Background images are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9044 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9045 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9046 | public WearableExtender setBackground(Bitmap background) { |
| 9047 | mBackground = background; |
| 9048 | return this; |
| 9049 | } |
| 9050 | |
| 9051 | /** |
| 9052 | * Get a background image to be displayed behind the notification content. |
| 9053 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 9054 | * will work with any notification style. |
| 9055 | * |
| 9056 | * @return the background image |
| 9057 | * @see android.app.Notification.WearableExtender#setBackground |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9058 | * @deprecated Background images are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9059 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9060 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9061 | public Bitmap getBackground() { |
| 9062 | return mBackground; |
| 9063 | } |
| 9064 | |
| 9065 | /** |
| 9066 | * Set an icon that goes with the content of this notification. |
| 9067 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9068 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9069 | public WearableExtender setContentIcon(int icon) { |
| 9070 | mContentIcon = icon; |
| 9071 | return this; |
| 9072 | } |
| 9073 | |
| 9074 | /** |
| 9075 | * Get an icon that goes with the content of this notification. |
| 9076 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9077 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9078 | public int getContentIcon() { |
| 9079 | return mContentIcon; |
| 9080 | } |
| 9081 | |
| 9082 | /** |
| 9083 | * Set the gravity that the content icon should have within the notification display. |
| 9084 | * Supported values include {@link android.view.Gravity#START} and |
| 9085 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 9086 | * @see #setContentIcon |
| 9087 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9088 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9089 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 9090 | mContentIconGravity = contentIconGravity; |
| 9091 | return this; |
| 9092 | } |
| 9093 | |
| 9094 | /** |
| 9095 | * Get the gravity that the content icon should have within the notification display. |
| 9096 | * Supported values include {@link android.view.Gravity#START} and |
| 9097 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 9098 | * @see #getContentIcon |
| 9099 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9100 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9101 | public int getContentIconGravity() { |
| 9102 | return mContentIconGravity; |
| 9103 | } |
| 9104 | |
| 9105 | /** |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9106 | * Set an action from this notification's actions as the primary action. If the action has a |
| 9107 | * {@link RemoteInput} associated with it, shortcuts to the options for that input are shown |
| 9108 | * directly on the notification. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9109 | * |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9110 | * @param actionIndex The index of the primary action. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9111 | * If wearable actions were added to the main notification, this index |
| 9112 | * will apply to that list, otherwise it will apply to the regular |
| 9113 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9114 | */ |
| 9115 | public WearableExtender setContentAction(int actionIndex) { |
| 9116 | mContentActionIndex = actionIndex; |
| 9117 | return this; |
| 9118 | } |
| 9119 | |
| 9120 | /** |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9121 | * Get the index of the notification action, if any, that was specified as the primary |
| 9122 | * action. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9123 | * |
| 9124 | * <p>If wearable specific actions were added to the main notification, this index will |
| 9125 | * 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] | 9126 | * |
| 9127 | * @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] | 9128 | */ |
| 9129 | public int getContentAction() { |
| 9130 | return mContentActionIndex; |
| 9131 | } |
| 9132 | |
| 9133 | /** |
| 9134 | * Set the gravity that this notification should have within the available viewport space. |
| 9135 | * Supported values include {@link android.view.Gravity#TOP}, |
| 9136 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 9137 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 9138 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9139 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9140 | public WearableExtender setGravity(int gravity) { |
| 9141 | mGravity = gravity; |
| 9142 | return this; |
| 9143 | } |
| 9144 | |
| 9145 | /** |
| 9146 | * Get the gravity that this notification should have within the available viewport space. |
| 9147 | * Supported values include {@link android.view.Gravity#TOP}, |
| 9148 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 9149 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 9150 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9151 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9152 | public int getGravity() { |
| 9153 | return mGravity; |
| 9154 | } |
| 9155 | |
| 9156 | /** |
| 9157 | * Set the custom size preset for the display of this notification out of the available |
| 9158 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 9159 | * {@link #SIZE_LARGE}. |
| 9160 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 9161 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 9162 | * documentation for the preset in question. See also |
| 9163 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 9164 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9165 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9166 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 9167 | mCustomSizePreset = sizePreset; |
| 9168 | return this; |
| 9169 | } |
| 9170 | |
| 9171 | /** |
| 9172 | * Get the custom size preset for the display of this notification out of the available |
| 9173 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 9174 | * {@link #SIZE_LARGE}. |
| 9175 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 9176 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 9177 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 9178 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9179 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9180 | public int getCustomSizePreset() { |
| 9181 | return mCustomSizePreset; |
| 9182 | } |
| 9183 | |
| 9184 | /** |
| 9185 | * Set the custom height in pixels for the display of this notification's content. |
| 9186 | * <p>This option is only available for custom display notifications created |
| 9187 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 9188 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 9189 | * {@link #getCustomContentHeight}. |
| 9190 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9191 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9192 | public WearableExtender setCustomContentHeight(int height) { |
| 9193 | mCustomContentHeight = height; |
| 9194 | return this; |
| 9195 | } |
| 9196 | |
| 9197 | /** |
| 9198 | * Get the custom height in pixels for the display of this notification's content. |
| 9199 | * <p>This option is only available for custom display notifications created |
| 9200 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 9201 | * {@link #setCustomContentHeight}. |
| 9202 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9203 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9204 | public int getCustomContentHeight() { |
| 9205 | return mCustomContentHeight; |
| 9206 | } |
| 9207 | |
| 9208 | /** |
| 9209 | * Set whether the scrolling position for the contents of this notification should start |
| 9210 | * at the bottom of the contents instead of the top when the contents are too long to |
| 9211 | * display within the screen. Default is false (start scroll at the top). |
| 9212 | */ |
| 9213 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 9214 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 9215 | return this; |
| 9216 | } |
| 9217 | |
| 9218 | /** |
| 9219 | * Get whether the scrolling position for the contents of this notification should start |
| 9220 | * at the bottom of the contents instead of the top when the contents are too long to |
| 9221 | * display within the screen. Default is false (start scroll at the top). |
| 9222 | */ |
| 9223 | public boolean getStartScrollBottom() { |
| 9224 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 9225 | } |
| 9226 | |
| 9227 | /** |
| 9228 | * Set whether the content intent is available when the wearable device is not connected |
| 9229 | * to a companion device. The user can still trigger this intent when the wearable device |
| 9230 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 9231 | * Defaults to true. |
| 9232 | */ |
| 9233 | public WearableExtender setContentIntentAvailableOffline( |
| 9234 | boolean contentIntentAvailableOffline) { |
| 9235 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 9236 | return this; |
| 9237 | } |
| 9238 | |
| 9239 | /** |
| 9240 | * Get whether the content intent is available when the wearable device is not connected |
| 9241 | * to a companion device. The user can still trigger this intent when the wearable device |
| 9242 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 9243 | * Defaults to true. |
| 9244 | */ |
| 9245 | public boolean getContentIntentAvailableOffline() { |
| 9246 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 9247 | } |
| 9248 | |
| 9249 | /** |
| 9250 | * Set a hint that this notification's icon should not be displayed. |
| 9251 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 9252 | * @return this object for method chaining |
| 9253 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9254 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9255 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 9256 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 9257 | return this; |
| 9258 | } |
| 9259 | |
| 9260 | /** |
| 9261 | * Get a hint that this notification's icon should not be displayed. |
| 9262 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 9263 | * The default value is {@code false} if this was never set. |
| 9264 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9265 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9266 | public boolean getHintHideIcon() { |
| 9267 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 9268 | } |
| 9269 | |
| 9270 | /** |
| 9271 | * Set a visual hint that only the background image of this notification should be |
| 9272 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 9273 | * to sub-pages added using {@link #addPage}. |
| 9274 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9275 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9276 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 9277 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 9278 | return this; |
| 9279 | } |
| 9280 | |
| 9281 | /** |
| 9282 | * Get a visual hint that only the background image of this notification should be |
| 9283 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 9284 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 9285 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9286 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9287 | public boolean getHintShowBackgroundOnly() { |
| 9288 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 9289 | } |
| 9290 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9291 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 9292 | * Set a hint that this notification's background should not be clipped if possible, |
| 9293 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 9294 | * 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] | 9295 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 9296 | * @return this object for method chaining |
| 9297 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9298 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9299 | public WearableExtender setHintAvoidBackgroundClipping( |
| 9300 | boolean hintAvoidBackgroundClipping) { |
| 9301 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 9302 | return this; |
| 9303 | } |
| 9304 | |
| 9305 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 9306 | * Get a hint that this notification's background should not be clipped if possible, |
| 9307 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 9308 | * 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] | 9309 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 9310 | * otherwise. The default value is {@code false} if this was never set. |
| 9311 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9312 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9313 | public boolean getHintAvoidBackgroundClipping() { |
| 9314 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 9315 | } |
| 9316 | |
| 9317 | /** |
| 9318 | * Set a hint that the screen should remain on for at least this duration when |
| 9319 | * this notification is displayed on the screen. |
| 9320 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 9321 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 9322 | * @return this object for method chaining |
| 9323 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9324 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9325 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 9326 | mHintScreenTimeout = timeout; |
| 9327 | return this; |
| 9328 | } |
| 9329 | |
| 9330 | /** |
| 9331 | * Get the duration, in milliseconds, that the screen should remain on for |
| 9332 | * when this notification is displayed. |
| 9333 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 9334 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 9335 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9336 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9337 | public int getHintScreenTimeout() { |
| 9338 | return mHintScreenTimeout; |
| 9339 | } |
| 9340 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9341 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9342 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 9343 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 9344 | * qr codes, as well as other simple black-and-white tickets. |
| 9345 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 9346 | * @return this object for method chaining |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9347 | * @deprecated This feature is no longer supported. |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9348 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9349 | @Deprecated |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9350 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 9351 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 9352 | return this; |
| 9353 | } |
| 9354 | |
| 9355 | /** |
| 9356 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 9357 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 9358 | * qr codes, as well as other simple black-and-white tickets. |
| 9359 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 9360 | * otherwise. The default value is {@code false} if this was never set. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9361 | * @deprecated This feature is no longer supported. |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9362 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9363 | @Deprecated |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9364 | public boolean getHintAmbientBigPicture() { |
| 9365 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 9366 | } |
| 9367 | |
| 9368 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9369 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 9370 | * directly, telling the platform that it can generate the appropriate transitions. |
| 9371 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 9372 | * an activity and transitions should be generated, false otherwise. |
| 9373 | * @return this object for method chaining |
| 9374 | */ |
| 9375 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 9376 | boolean hintContentIntentLaunchesActivity) { |
| 9377 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 9378 | return this; |
| 9379 | } |
| 9380 | |
| 9381 | /** |
| 9382 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 9383 | * directly, telling the platform that it can generate the appropriate transitions |
| 9384 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 9385 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 9386 | */ |
| 9387 | public boolean getHintContentIntentLaunchesActivity() { |
| 9388 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 9389 | } |
| 9390 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9391 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9392 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 9393 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 9394 | * and the paired Android phone having that same dismissal id will also be canceled. See |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9395 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9396 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9397 | * @param dismissalId the dismissal id of the notification. |
| 9398 | * @return this object for method chaining |
| 9399 | */ |
| 9400 | public WearableExtender setDismissalId(String dismissalId) { |
| 9401 | mDismissalId = dismissalId; |
| 9402 | return this; |
| 9403 | } |
| 9404 | |
| 9405 | /** |
| 9406 | * Returns the dismissal id of the notification. |
| 9407 | * @return the dismissal id of the notification or null if it has not been set. |
| 9408 | */ |
| 9409 | public String getDismissalId() { |
| 9410 | return mDismissalId; |
| 9411 | } |
| 9412 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9413 | /** |
| 9414 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 9415 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 9416 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 9417 | * Features to Notifications</a> for more information. |
| 9418 | * @param bridgeTag the bridge tag of the notification. |
| 9419 | * @return this object for method chaining |
| 9420 | */ |
| 9421 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 9422 | mBridgeTag = bridgeTag; |
| 9423 | return this; |
| 9424 | } |
| 9425 | |
| 9426 | /** |
| 9427 | * Returns the bridge tag of the notification. |
| 9428 | * @return the bridge tag or null if not present. |
| 9429 | */ |
| 9430 | public String getBridgeTag() { |
| 9431 | return mBridgeTag; |
| 9432 | } |
| 9433 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9434 | private void setFlag(int mask, boolean value) { |
| 9435 | if (value) { |
| 9436 | mFlags |= mask; |
| 9437 | } else { |
| 9438 | mFlags &= ~mask; |
| 9439 | } |
| 9440 | } |
| 9441 | } |
| 9442 | |
| 9443 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9444 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 9445 | * with car extensions: |
| 9446 | * |
| 9447 | * <ol> |
| 9448 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 9449 | * properties. |
| 9450 | * <li>Create a {@link CarExtender}. |
| 9451 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 9452 | * {@link CarExtender}. |
| 9453 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9454 | * to apply the extensions to a notification. |
| 9455 | * </ol> |
| 9456 | * |
| 9457 | * <pre class="prettyprint"> |
| 9458 | * Notification notification = new Notification.Builder(context) |
| 9459 | * ... |
| 9460 | * .extend(new CarExtender() |
| 9461 | * .set*(...)) |
| 9462 | * .build(); |
| 9463 | * </pre> |
| 9464 | * |
| 9465 | * <p>Car extensions can be accessed on an existing notification by using the |
| 9466 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 9467 | * to access values. |
| 9468 | */ |
| 9469 | public static final class CarExtender implements Extender { |
| 9470 | private static final String TAG = "CarExtender"; |
| 9471 | |
| 9472 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 9473 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 9474 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 9475 | private static final String EXTRA_COLOR = "app_color"; |
| 9476 | |
| 9477 | private Bitmap mLargeIcon; |
| 9478 | private UnreadConversation mUnreadConversation; |
| 9479 | private int mColor = Notification.COLOR_DEFAULT; |
| 9480 | |
| 9481 | /** |
| 9482 | * Create a {@link CarExtender} with default options. |
| 9483 | */ |
| 9484 | public CarExtender() { |
| 9485 | } |
| 9486 | |
| 9487 | /** |
| 9488 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 9489 | * |
| 9490 | * @param notif The notification from which to copy options. |
| 9491 | */ |
| 9492 | public CarExtender(Notification notif) { |
| 9493 | Bundle carBundle = notif.extras == null ? |
| 9494 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 9495 | if (carBundle != null) { |
| 9496 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 9497 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 9498 | |
| 9499 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 9500 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 9501 | } |
| 9502 | } |
| 9503 | |
| 9504 | /** |
| 9505 | * Apply car extensions to a notification that is being built. This is typically called by |
| 9506 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9507 | * method of {@link Notification.Builder}. |
| 9508 | */ |
| 9509 | @Override |
| 9510 | public Notification.Builder extend(Notification.Builder builder) { |
| 9511 | Bundle carExtensions = new Bundle(); |
| 9512 | |
| 9513 | if (mLargeIcon != null) { |
| 9514 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 9515 | } |
| 9516 | if (mColor != Notification.COLOR_DEFAULT) { |
| 9517 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 9518 | } |
| 9519 | |
| 9520 | if (mUnreadConversation != null) { |
| 9521 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 9522 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 9523 | } |
| 9524 | |
| 9525 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 9526 | return builder; |
| 9527 | } |
| 9528 | |
| 9529 | /** |
| 9530 | * Sets the accent color to use when Android Auto presents the notification. |
| 9531 | * |
| 9532 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 9533 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 9534 | * automotive setting. This method can be used to override the color provided in the |
| 9535 | * notification in such a situation. |
| 9536 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9537 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9538 | mColor = color; |
| 9539 | return this; |
| 9540 | } |
| 9541 | |
| 9542 | /** |
| 9543 | * Gets the accent color. |
| 9544 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 9545 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9546 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9547 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9548 | public int getColor() { |
| 9549 | return mColor; |
| 9550 | } |
| 9551 | |
| 9552 | /** |
| 9553 | * Sets the large icon of the car notification. |
| 9554 | * |
| 9555 | * If no large icon is set in the extender, Android Auto will display the icon |
| 9556 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 9557 | * |
| 9558 | * @param largeIcon The large icon to use in the car notification. |
| 9559 | * @return This object for method chaining. |
| 9560 | */ |
| 9561 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 9562 | mLargeIcon = largeIcon; |
| 9563 | return this; |
| 9564 | } |
| 9565 | |
| 9566 | /** |
| 9567 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 9568 | * |
| 9569 | * @return The large icon for the car notification. |
| 9570 | * @see CarExtender#setLargeIcon |
| 9571 | */ |
| 9572 | public Bitmap getLargeIcon() { |
| 9573 | return mLargeIcon; |
| 9574 | } |
| 9575 | |
| 9576 | /** |
| 9577 | * Sets the unread conversation in a message notification. |
| 9578 | * |
| 9579 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 9580 | * @return This object for method chaining. |
| 9581 | */ |
| 9582 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 9583 | mUnreadConversation = unreadConversation; |
| 9584 | return this; |
| 9585 | } |
| 9586 | |
| 9587 | /** |
| 9588 | * Returns the unread conversation conveyed by this notification. |
| 9589 | * @see #setUnreadConversation(UnreadConversation) |
| 9590 | */ |
| 9591 | public UnreadConversation getUnreadConversation() { |
| 9592 | return mUnreadConversation; |
| 9593 | } |
| 9594 | |
| 9595 | /** |
| 9596 | * A class which holds the unread messages from a conversation. |
| 9597 | */ |
| 9598 | public static class UnreadConversation { |
| 9599 | private static final String KEY_AUTHOR = "author"; |
| 9600 | private static final String KEY_TEXT = "text"; |
| 9601 | private static final String KEY_MESSAGES = "messages"; |
| 9602 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 9603 | private static final String KEY_ON_REPLY = "on_reply"; |
| 9604 | private static final String KEY_ON_READ = "on_read"; |
| 9605 | private static final String KEY_PARTICIPANTS = "participants"; |
| 9606 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 9607 | |
| 9608 | private final String[] mMessages; |
| 9609 | private final RemoteInput mRemoteInput; |
| 9610 | private final PendingIntent mReplyPendingIntent; |
| 9611 | private final PendingIntent mReadPendingIntent; |
| 9612 | private final String[] mParticipants; |
| 9613 | private final long mLatestTimestamp; |
| 9614 | |
| 9615 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 9616 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 9617 | String[] participants, long latestTimestamp) { |
| 9618 | mMessages = messages; |
| 9619 | mRemoteInput = remoteInput; |
| 9620 | mReadPendingIntent = readPendingIntent; |
| 9621 | mReplyPendingIntent = replyPendingIntent; |
| 9622 | mParticipants = participants; |
| 9623 | mLatestTimestamp = latestTimestamp; |
| 9624 | } |
| 9625 | |
| 9626 | /** |
| 9627 | * Gets the list of messages conveyed by this notification. |
| 9628 | */ |
| 9629 | public String[] getMessages() { |
| 9630 | return mMessages; |
| 9631 | } |
| 9632 | |
| 9633 | /** |
| 9634 | * Gets the remote input that will be used to convey the response to a message list, or |
| 9635 | * null if no such remote input exists. |
| 9636 | */ |
| 9637 | public RemoteInput getRemoteInput() { |
| 9638 | return mRemoteInput; |
| 9639 | } |
| 9640 | |
| 9641 | /** |
| 9642 | * Gets the pending intent that will be triggered when the user replies to this |
| 9643 | * notification. |
| 9644 | */ |
| 9645 | public PendingIntent getReplyPendingIntent() { |
| 9646 | return mReplyPendingIntent; |
| 9647 | } |
| 9648 | |
| 9649 | /** |
| 9650 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 9651 | * in this object's message list. |
| 9652 | */ |
| 9653 | public PendingIntent getReadPendingIntent() { |
| 9654 | return mReadPendingIntent; |
| 9655 | } |
| 9656 | |
| 9657 | /** |
| 9658 | * Gets the participants in the conversation. |
| 9659 | */ |
| 9660 | public String[] getParticipants() { |
| 9661 | return mParticipants; |
| 9662 | } |
| 9663 | |
| 9664 | /** |
| 9665 | * Gets the firs participant in the conversation. |
| 9666 | */ |
| 9667 | public String getParticipant() { |
| 9668 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 9669 | } |
| 9670 | |
| 9671 | /** |
| 9672 | * Gets the timestamp of the conversation. |
| 9673 | */ |
| 9674 | public long getLatestTimestamp() { |
| 9675 | return mLatestTimestamp; |
| 9676 | } |
| 9677 | |
| 9678 | Bundle getBundleForUnreadConversation() { |
| 9679 | Bundle b = new Bundle(); |
| 9680 | String author = null; |
| 9681 | if (mParticipants != null && mParticipants.length > 1) { |
| 9682 | author = mParticipants[0]; |
| 9683 | } |
| 9684 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 9685 | for (int i = 0; i < messages.length; i++) { |
| 9686 | Bundle m = new Bundle(); |
| 9687 | m.putString(KEY_TEXT, mMessages[i]); |
| 9688 | m.putString(KEY_AUTHOR, author); |
| 9689 | messages[i] = m; |
| 9690 | } |
| 9691 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 9692 | if (mRemoteInput != null) { |
| 9693 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 9694 | } |
| 9695 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 9696 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 9697 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 9698 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 9699 | return b; |
| 9700 | } |
| 9701 | |
| 9702 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 9703 | if (b == null) { |
| 9704 | return null; |
| 9705 | } |
| 9706 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 9707 | String[] messages = null; |
| 9708 | if (parcelableMessages != null) { |
| 9709 | String[] tmp = new String[parcelableMessages.length]; |
| 9710 | boolean success = true; |
| 9711 | for (int i = 0; i < tmp.length; i++) { |
| 9712 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 9713 | success = false; |
| 9714 | break; |
| 9715 | } |
| 9716 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 9717 | if (tmp[i] == null) { |
| 9718 | success = false; |
| 9719 | break; |
| 9720 | } |
| 9721 | } |
| 9722 | if (success) { |
| 9723 | messages = tmp; |
| 9724 | } else { |
| 9725 | return null; |
| 9726 | } |
| 9727 | } |
| 9728 | |
| 9729 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 9730 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 9731 | |
| 9732 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 9733 | |
| 9734 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 9735 | if (participants == null || participants.length != 1) { |
| 9736 | return null; |
| 9737 | } |
| 9738 | |
| 9739 | return new UnreadConversation(messages, |
| 9740 | remoteInput, |
| 9741 | onReply, |
| 9742 | onRead, |
| 9743 | participants, b.getLong(KEY_TIMESTAMP)); |
| 9744 | } |
| 9745 | }; |
| 9746 | |
| 9747 | /** |
| 9748 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 9749 | */ |
| 9750 | public static class Builder { |
| 9751 | private final List<String> mMessages = new ArrayList<String>(); |
| 9752 | private final String mParticipant; |
| 9753 | private RemoteInput mRemoteInput; |
| 9754 | private PendingIntent mReadPendingIntent; |
| 9755 | private PendingIntent mReplyPendingIntent; |
| 9756 | private long mLatestTimestamp; |
| 9757 | |
| 9758 | /** |
| 9759 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 9760 | * |
| 9761 | * @param name The name of the other participant in the conversation. |
| 9762 | */ |
| 9763 | public Builder(String name) { |
| 9764 | mParticipant = name; |
| 9765 | } |
| 9766 | |
| 9767 | /** |
| 9768 | * Appends a new unread message to the list of messages for this conversation. |
| 9769 | * |
| 9770 | * The messages should be added from oldest to newest. |
| 9771 | * |
| 9772 | * @param message The text of the new unread message. |
| 9773 | * @return This object for method chaining. |
| 9774 | */ |
| 9775 | public Builder addMessage(String message) { |
| 9776 | mMessages.add(message); |
| 9777 | return this; |
| 9778 | } |
| 9779 | |
| 9780 | /** |
| 9781 | * Sets the pending intent and remote input which will convey the reply to this |
| 9782 | * notification. |
| 9783 | * |
| 9784 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 9785 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 9786 | * @return This object for method chaining. |
| 9787 | * |
| 9788 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 9789 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 9790 | */ |
| 9791 | public Builder setReplyAction( |
| 9792 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 9793 | mRemoteInput = remoteInput; |
| 9794 | mReplyPendingIntent = pendingIntent; |
| 9795 | |
| 9796 | return this; |
| 9797 | } |
| 9798 | |
| 9799 | /** |
| 9800 | * Sets the pending intent that will be sent once the messages in this notification |
| 9801 | * are read. |
| 9802 | * |
| 9803 | * @param pendingIntent The pending intent to use. |
| 9804 | * @return This object for method chaining. |
| 9805 | */ |
| 9806 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 9807 | mReadPendingIntent = pendingIntent; |
| 9808 | return this; |
| 9809 | } |
| 9810 | |
| 9811 | /** |
| 9812 | * Sets the timestamp of the most recent message in an unread conversation. |
| 9813 | * |
| 9814 | * If a messaging notification has been posted by your application and has not |
| 9815 | * yet been cancelled, posting a later notification with the same id and tag |
| 9816 | * but without a newer timestamp may result in Android Auto not displaying a |
| 9817 | * heads up notification for the later notification. |
| 9818 | * |
| 9819 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 9820 | * @return This object for method chaining. |
| 9821 | */ |
| 9822 | public Builder setLatestTimestamp(long timestamp) { |
| 9823 | mLatestTimestamp = timestamp; |
| 9824 | return this; |
| 9825 | } |
| 9826 | |
| 9827 | /** |
| 9828 | * Builds a new unread conversation object. |
| 9829 | * |
| 9830 | * @return The new unread conversation object. |
| 9831 | */ |
| 9832 | public UnreadConversation build() { |
| 9833 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 9834 | String[] participants = { mParticipant }; |
| 9835 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 9836 | mReadPendingIntent, participants, mLatestTimestamp); |
| 9837 | } |
| 9838 | } |
| 9839 | } |
| 9840 | |
| 9841 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9842 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 9843 | * with a TV extension: |
| 9844 | * |
| 9845 | * <ol> |
| 9846 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 9847 | * <li>Create a {@link TvExtender}. |
| 9848 | * <li>Set TV-specific properties using the {@code set} methods of |
| 9849 | * {@link TvExtender}. |
| 9850 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9851 | * to apply the extension to a notification. |
| 9852 | * </ol> |
| 9853 | * |
| 9854 | * <pre class="prettyprint"> |
| 9855 | * Notification notification = new Notification.Builder(context) |
| 9856 | * ... |
| 9857 | * .extend(new TvExtender() |
| 9858 | * .set*(...)) |
| 9859 | * .build(); |
| 9860 | * </pre> |
| 9861 | * |
| 9862 | * <p>TV extensions can be accessed on an existing notification by using the |
| 9863 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 9864 | * to access values. |
| 9865 | * |
| 9866 | * @hide |
| 9867 | */ |
| 9868 | @SystemApi |
| 9869 | public static final class TvExtender implements Extender { |
| 9870 | private static final String TAG = "TvExtender"; |
| 9871 | |
| 9872 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 9873 | private static final String EXTRA_FLAGS = "flags"; |
| 9874 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 9875 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9876 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9877 | private static final String EXTRA_SUPPRESS_SHOW_OVER_APPS = "suppressShowOverApps"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9878 | |
| 9879 | // Flags bitwise-ored to mFlags |
| 9880 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 9881 | |
| 9882 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9883 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9884 | private PendingIntent mContentIntent; |
| 9885 | private PendingIntent mDeleteIntent; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9886 | private boolean mSuppressShowOverApps; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9887 | |
| 9888 | /** |
| 9889 | * Create a {@link TvExtender} with default options. |
| 9890 | */ |
| 9891 | public TvExtender() { |
| 9892 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 9893 | } |
| 9894 | |
| 9895 | /** |
| 9896 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 9897 | * |
| 9898 | * @param notif The notification from which to copy options. |
| 9899 | */ |
| 9900 | public TvExtender(Notification notif) { |
| 9901 | Bundle bundle = notif.extras == null ? |
| 9902 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 9903 | if (bundle != null) { |
| 9904 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9905 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9906 | mSuppressShowOverApps = bundle.getBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9907 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 9908 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 9909 | } |
| 9910 | } |
| 9911 | |
| 9912 | /** |
| 9913 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 9914 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9915 | * method of {@link Notification.Builder}. |
| 9916 | */ |
| 9917 | @Override |
| 9918 | public Notification.Builder extend(Notification.Builder builder) { |
| 9919 | Bundle bundle = new Bundle(); |
| 9920 | |
| 9921 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9922 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9923 | bundle.putBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS, mSuppressShowOverApps); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9924 | if (mContentIntent != null) { |
| 9925 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 9926 | } |
| 9927 | |
| 9928 | if (mDeleteIntent != null) { |
| 9929 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 9930 | } |
| 9931 | |
| 9932 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 9933 | return builder; |
| 9934 | } |
| 9935 | |
| 9936 | /** |
| 9937 | * Returns true if this notification should be shown on TV. This method return true |
| 9938 | * if the notification was extended with a TvExtender. |
| 9939 | */ |
| 9940 | public boolean isAvailableOnTv() { |
| 9941 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 9942 | } |
| 9943 | |
| 9944 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9945 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 9946 | * It can be different from the channel that the notification is delivered to when |
| 9947 | * posting on a non-TV device. |
| 9948 | */ |
| 9949 | public TvExtender setChannel(String channelId) { |
| 9950 | mChannelId = channelId; |
| 9951 | return this; |
| 9952 | } |
| 9953 | |
| 9954 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 9955 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 9956 | * It can be different from the channel that the notification is delivered to when |
| 9957 | * posting on a non-TV device. |
| 9958 | */ |
| 9959 | public TvExtender setChannelId(String channelId) { |
| 9960 | mChannelId = channelId; |
| 9961 | return this; |
| 9962 | } |
| 9963 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 9964 | /** @removed */ |
| 9965 | @Deprecated |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9966 | public String getChannel() { |
| 9967 | return mChannelId; |
| 9968 | } |
| 9969 | |
| 9970 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 9971 | * Returns the id of the channel this notification posts to on TV. |
| 9972 | */ |
| 9973 | public String getChannelId() { |
| 9974 | return mChannelId; |
| 9975 | } |
| 9976 | |
| 9977 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9978 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 9979 | * If provided, it is used instead of the content intent specified |
| 9980 | * at the level of Notification. |
| 9981 | */ |
| 9982 | public TvExtender setContentIntent(PendingIntent intent) { |
| 9983 | mContentIntent = intent; |
| 9984 | return this; |
| 9985 | } |
| 9986 | |
| 9987 | /** |
| 9988 | * Returns the TV-specific content intent. If this method returns null, the |
| 9989 | * main content intent on the notification should be used. |
| 9990 | * |
| 9991 | * @see {@link Notification#contentIntent} |
| 9992 | */ |
| 9993 | public PendingIntent getContentIntent() { |
| 9994 | return mContentIntent; |
| 9995 | } |
| 9996 | |
| 9997 | /** |
| 9998 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 9999 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 10000 | * at the level of Notification. |
| 10001 | */ |
| 10002 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 10003 | mDeleteIntent = intent; |
| 10004 | return this; |
| 10005 | } |
| 10006 | |
| 10007 | /** |
| 10008 | * Returns the TV-specific delete intent. If this method returns null, the |
| 10009 | * main delete intent on the notification should be used. |
| 10010 | * |
| 10011 | * @see {@link Notification#deleteIntent} |
| 10012 | */ |
| 10013 | public PendingIntent getDeleteIntent() { |
| 10014 | return mDeleteIntent; |
| 10015 | } |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10016 | |
| 10017 | /** |
| 10018 | * Specifies whether this notification should suppress showing a message over top of apps |
| 10019 | * outside of the launcher. |
| 10020 | */ |
| 10021 | public TvExtender setSuppressShowOverApps(boolean suppress) { |
| 10022 | mSuppressShowOverApps = suppress; |
| 10023 | return this; |
| 10024 | } |
| 10025 | |
| 10026 | /** |
| 10027 | * Returns true if this notification should not show messages over top of apps |
| 10028 | * outside of the launcher. |
| 10029 | */ |
| 10030 | public boolean getSuppressShowOverApps() { |
| 10031 | return mSuppressShowOverApps; |
| 10032 | } |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10033 | } |
| 10034 | |
| 10035 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 10036 | * Get an array of Notification objects from a parcelable array bundle field. |
| 10037 | * Update the bundle to have a typed array so fetches in the future don't need |
| 10038 | * to do an array copy. |
| 10039 | */ |
| 10040 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 10041 | Parcelable[] array = bundle.getParcelableArray(key); |
| 10042 | if (array instanceof Notification[] || array == null) { |
| 10043 | return (Notification[]) array; |
| 10044 | } |
| 10045 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 10046 | Notification[].class); |
| 10047 | bundle.putParcelableArray(key, typedArray); |
| 10048 | return typedArray; |
| 10049 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 10050 | |
| 10051 | private static class BuilderRemoteViews extends RemoteViews { |
| 10052 | public BuilderRemoteViews(Parcel parcel) { |
| 10053 | super(parcel); |
| 10054 | } |
| 10055 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 10056 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 10057 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 10058 | } |
| 10059 | |
| 10060 | @Override |
| 10061 | public BuilderRemoteViews clone() { |
| 10062 | Parcel p = Parcel.obtain(); |
| 10063 | writeToParcel(p, 0); |
| 10064 | p.setDataPosition(0); |
| 10065 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 10066 | p.recycle(); |
| 10067 | return brv; |
| 10068 | } |
| 10069 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10070 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10071 | /** |
| 10072 | * A result object where information about the template that was created is saved. |
| 10073 | */ |
| 10074 | private static class TemplateBindResult { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10075 | int mIconMarginEnd; |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 10076 | boolean mRightIconContainerVisible; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10077 | |
| 10078 | /** |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10079 | * Get the margin end that needs to be added to any fields that may overlap |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10080 | * with the right actions. |
| 10081 | */ |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10082 | public int getIconMarginEnd() { |
| 10083 | return mIconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10084 | } |
| 10085 | |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 10086 | /** |
| 10087 | * Is the icon container visible on the right size because of the reply button or the |
| 10088 | * right icon. |
| 10089 | */ |
| 10090 | public boolean isRightIconContainerVisible() { |
| 10091 | return mRightIconContainerVisible; |
| 10092 | } |
| 10093 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10094 | public void setIconMarginEnd(int iconMarginEnd) { |
| 10095 | this.mIconMarginEnd = iconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10096 | } |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 10097 | |
| 10098 | public void setRightIconContainerVisible(boolean iconContainerVisible) { |
| 10099 | mRightIconContainerVisible = iconContainerVisible; |
| 10100 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10101 | } |
| 10102 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10103 | private static class StandardTemplateParams { |
| 10104 | boolean hasProgress = true; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10105 | CharSequence title; |
| 10106 | CharSequence text; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 10107 | CharSequence headerTextSecondary; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10108 | CharSequence summaryText; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 10109 | int maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10110 | boolean hideLargeIcon; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10111 | boolean hideReplyIcon; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10112 | boolean allowColorization = true; |
| 10113 | boolean forceDefaultColor = false; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10114 | |
| 10115 | final StandardTemplateParams reset() { |
| 10116 | hasProgress = true; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10117 | title = null; |
| 10118 | text = null; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10119 | summaryText = null; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 10120 | headerTextSecondary = null; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 10121 | maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10122 | allowColorization = true; |
| 10123 | forceDefaultColor = false; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10124 | return this; |
| 10125 | } |
| 10126 | |
| 10127 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 10128 | this.hasProgress = hasProgress; |
| 10129 | return this; |
| 10130 | } |
| 10131 | |
| 10132 | final StandardTemplateParams title(CharSequence title) { |
| 10133 | this.title = title; |
| 10134 | return this; |
| 10135 | } |
| 10136 | |
| 10137 | final StandardTemplateParams text(CharSequence text) { |
| 10138 | this.text = text; |
| 10139 | return this; |
| 10140 | } |
| 10141 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10142 | final StandardTemplateParams summaryText(CharSequence text) { |
| 10143 | this.summaryText = text; |
| 10144 | return this; |
| 10145 | } |
| 10146 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 10147 | final StandardTemplateParams headerTextSecondary(CharSequence text) { |
| 10148 | this.headerTextSecondary = text; |
| 10149 | return this; |
| 10150 | } |
| 10151 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10152 | final StandardTemplateParams hideLargeIcon(boolean hideLargeIcon) { |
| 10153 | this.hideLargeIcon = hideLargeIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10154 | return this; |
| 10155 | } |
| 10156 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10157 | final StandardTemplateParams hideReplyIcon(boolean hideReplyIcon) { |
| 10158 | this.hideReplyIcon = hideReplyIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10159 | return this; |
| 10160 | } |
| 10161 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10162 | final StandardTemplateParams disallowColorization() { |
| 10163 | this.allowColorization = false; |
| 10164 | return this; |
| 10165 | } |
| 10166 | |
| 10167 | final StandardTemplateParams forceDefaultColor() { |
| 10168 | this.forceDefaultColor = true; |
| 10169 | return this; |
| 10170 | } |
| 10171 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10172 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 10173 | Bundle extras = b.mN.extras; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 10174 | this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE)); |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 10175 | |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 10176 | CharSequence text = extras.getCharSequence(EXTRA_BIG_TEXT); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 10177 | if (TextUtils.isEmpty(text)) { |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 10178 | text = extras.getCharSequence(EXTRA_TEXT); |
| 10179 | } |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 10180 | this.text = b.processLegacyText(text); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10181 | this.summaryText = extras.getCharSequence(EXTRA_SUB_TEXT); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10182 | return this; |
| 10183 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 10184 | |
| 10185 | /** |
| 10186 | * Set the maximum lines of remote input history lines allowed. |
| 10187 | * @param maxRemoteInputHistory The number of lines. |
| 10188 | * @return The builder for method chaining. |
| 10189 | */ |
| 10190 | public StandardTemplateParams setMaxRemoteInputHistory(int maxRemoteInputHistory) { |
| 10191 | this.maxRemoteInputHistory = maxRemoteInputHistory; |
| 10192 | return this; |
| 10193 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10194 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10195 | } |