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; |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 22 | import android.annotation.DimenRes; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 23 | import android.annotation.DrawableRes; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 24 | import android.annotation.IdRes; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 25 | import android.annotation.IntDef; |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 26 | import android.annotation.NonNull; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 27 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 28 | import android.annotation.RequiresPermission; |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 29 | import android.annotation.SdkConstant; |
| 30 | import android.annotation.SdkConstant.SdkConstantType; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 31 | import android.annotation.SystemApi; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 32 | import android.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.content.Context; |
| 34 | import android.content.Intent; |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 35 | import android.content.LocusId; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 36 | import android.content.pm.ApplicationInfo; |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 38 | import android.content.pm.PackageManager.NameNotFoundException; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 39 | import android.content.pm.ShortcutInfo; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 40 | import android.content.res.ColorStateList; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 41 | import android.content.res.Configuration; |
| 42 | import android.content.res.Resources; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 43 | import android.content.res.TypedArray; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 44 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 45 | import android.graphics.Canvas; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 46 | import android.graphics.Color; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 47 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 48 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 49 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 50 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 51 | import android.media.AudioManager; |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 52 | import android.media.PlayerBase; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 53 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 55 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 56 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 57 | import android.os.Bundle; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 58 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.os.Parcel; |
| 60 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 61 | import android.os.SystemClock; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 62 | import android.os.SystemProperties; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 63 | import android.os.UserHandle; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 64 | import android.text.BidiFormatter; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 65 | import android.text.SpannableStringBuilder; |
| 66 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 68 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 69 | import android.text.style.CharacterStyle; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 70 | import android.text.style.ForegroundColorSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 71 | import android.text.style.RelativeSizeSpan; |
| 72 | import android.text.style.TextAppearanceSpan; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 73 | import android.util.ArraySet; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 74 | import android.util.Log; |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 75 | import android.util.Pair; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 76 | import android.util.SparseArray; |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 77 | import android.util.proto.ProtoOutputStream; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 78 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 79 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 80 | import android.view.View; |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 81 | import android.view.ViewGroup; |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 82 | import android.view.contentcapture.ContentCaptureContext; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 83 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import android.widget.RemoteViews; |
| 85 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 86 | import com.android.internal.R; |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 87 | import com.android.internal.annotations.VisibleForTesting; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 88 | import com.android.internal.util.ArrayUtils; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 89 | import com.android.internal.util.ContrastColorUtil; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 90 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 91 | import java.lang.annotation.Retention; |
| 92 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 93 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 94 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 95 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 96 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 97 | import java.util.List; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 98 | import java.util.Objects; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 99 | import java.util.Set; |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 100 | import java.util.function.Consumer; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | /** |
| 103 | * A class that represents how a persistent notification is to be presented to |
| 104 | * the user using the {@link android.app.NotificationManager}. |
| 105 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 106 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 107 | * easier to construct Notifications.</p> |
| 108 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 109 | * <div class="special reference"> |
| 110 | * <h3>Developer Guides</h3> |
| 111 | * <p>For a guide to creating notifications, read the |
| 112 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 113 | * developer guide.</p> |
| 114 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | */ |
| 116 | public class Notification implements Parcelable |
| 117 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 118 | private static final String TAG = "Notification"; |
| 119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 121 | * 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] | 122 | * containing application. |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 123 | */ |
| 124 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 125 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 126 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 127 | |
| 128 | /** |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 129 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 130 | * 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] | 131 | * what settings should be shown in the target app. |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 132 | */ |
| 133 | public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 134 | |
| 135 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 136 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 005c8b9 | 2017-08-24 10:35:53 -0400 | [diff] [blame] | 137 | * contain a {@link NotificationChannelGroup#getId() group id} that can be used to narrow down |
| 138 | * what settings should be shown in the target app. |
| 139 | */ |
| 140 | public static final String EXTRA_CHANNEL_GROUP_ID = "android.intent.extra.CHANNEL_GROUP_ID"; |
| 141 | |
| 142 | /** |
| 143 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 144 | * contain the tag provided to {@link NotificationManager#notify(String, int, Notification)} |
| 145 | * that can be used to narrow down what settings should be shown in the target app. |
| 146 | */ |
| 147 | public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 148 | |
| 149 | /** |
| 150 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 151 | * contain the id provided to {@link NotificationManager#notify(String, int, Notification)} |
| 152 | * that can be used to narrow down what settings should be shown in the target app. |
| 153 | */ |
| 154 | public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 155 | |
| 156 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | * Use all default values (where applicable). |
| 158 | */ |
| 159 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | /** |
| 162 | * Use the default notification sound. This will ignore any given |
| 163 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 164 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 165 | * <p> |
| 166 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 167 | * </p> |
| 168 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 170 | */ |
| 171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | public static final int DEFAULT_SOUND = 1; |
| 173 | |
| 174 | /** |
| 175 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 176 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 177 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 178 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 179 | * <p> |
| 180 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 181 | * </p> |
| 182 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 184 | */ |
| 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | /** |
| 189 | * Use the default notification lights. This will ignore the |
| 190 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 191 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 192 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 194 | */ |
| 195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 199 | * Maximum length of CharSequences accepted by Builder and friends. |
| 200 | * |
| 201 | * <p> |
| 202 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 203 | */ |
| 204 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 205 | |
| 206 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 207 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 208 | */ |
| 209 | private static final int MAX_REPLY_HISTORY = 5; |
| 210 | |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 211 | /** |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 212 | * Maximum number of (generic) action buttons in a notification (contextual action buttons are |
| 213 | * handled separately). |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 214 | * @hide |
| 215 | */ |
| 216 | public static final int MAX_ACTION_BUTTONS = 3; |
Selim Cinek | de4de0e | 2018-01-24 16:21:07 -0800 | [diff] [blame] | 217 | |
| 218 | /** |
| 219 | * If the notification contained an unsent draft for a RemoteInput when the user clicked on it, |
| 220 | * we're adding the draft as a String extra to the {@link #contentIntent} using this key. |
| 221 | * |
| 222 | * <p>Apps may use this extra to prepopulate text fields in the app, where the user usually |
| 223 | * sends messages.</p> |
| 224 | */ |
| 225 | public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; |
| 226 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 227 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 228 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 229 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 230 | * Default value: {@link System#currentTimeMillis() Now}. |
| 231 | * |
| 232 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 233 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 234 | * 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] | 235 | * timestamped according to when the activity began. |
| 236 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 237 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 238 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 239 | * <ul> |
| 240 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 241 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 242 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 243 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 244 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 245 | * <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] | 246 | * </ul> |
| 247 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 248 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 249 | * anymore by default and must be opted into by using |
| 250 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | */ |
| 252 | public long when; |
| 253 | |
| 254 | /** |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 255 | * The creation time of the notification |
| 256 | */ |
| 257 | private long creationTime; |
| 258 | |
| 259 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | * 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] | 261 | * |
| 262 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 264 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 265 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | public int icon; |
| 267 | |
| 268 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 269 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 270 | * leave it at its default value of 0. |
| 271 | * |
| 272 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 273 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 274 | */ |
| 275 | public int iconLevel; |
| 276 | |
| 277 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 278 | * The number of events that this notification represents. For example, in a new mail |
| 279 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 280 | * |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 281 | * 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] | 282 | * Starting with {@link android.os.Build.VERSION_CODES#O}, the number may be displayed as a |
| 283 | * badge icon in Launchers that support badging. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | */ |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 285 | public int number = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | |
| 287 | /** |
| 288 | * The intent to execute when the expanded status entry is clicked. If |
| 289 | * this is an activity, it must include the |
| 290 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 291 | * that you take care of task management as described in the |
| 292 | * <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] | 293 | * Stack</a> document. In particular, make sure to read the notification section |
| 294 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 295 | * Notifications</a> for the correct ways to launch an application from a |
| 296 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | */ |
| 298 | public PendingIntent contentIntent; |
| 299 | |
| 300 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 301 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 302 | * the "Clear All" button or by swiping it away individually. |
| 303 | * |
| 304 | * This probably shouldn't be launching an activity since several of those will be sent |
| 305 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | */ |
| 307 | public PendingIntent deleteIntent; |
| 308 | |
| 309 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 310 | * 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] | 311 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 312 | * <p> |
| 313 | * The system UI may choose to display a heads-up notification, instead of |
| 314 | * launching this intent, while the user is using the device. |
| 315 | * </p> |
| 316 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 317 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 318 | */ |
| 319 | public PendingIntent fullScreenIntent; |
| 320 | |
| 321 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 322 | * Text that summarizes this notification for accessibility services. |
| 323 | * |
| 324 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 325 | * accessibility services (where it serves as an audible announcement of the notification's |
| 326 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 327 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 328 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | */ |
| 330 | public CharSequence tickerText; |
| 331 | |
| 332 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 333 | * Formerly, a view showing the {@link #tickerText}. |
| 334 | * |
| 335 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 336 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 337 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 338 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 339 | |
| 340 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 341 | * The view that will represent this notification in the notification list (which is pulled |
| 342 | * down from the status bar). |
| 343 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 344 | * As of N, this field may be null. The notification view is determined by the inputs |
| 345 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 346 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 348 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | public RemoteViews contentView; |
| 350 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 351 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 352 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 353 | * opportunity to show more detail. The system UI may choose to show this |
| 354 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 355 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 356 | * 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] | 357 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 358 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 359 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 360 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 361 | public RemoteViews bigContentView; |
| 362 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 363 | |
| 364 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 365 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 366 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 367 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 368 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 369 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 370 | * 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] | 371 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 372 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 373 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 374 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 375 | public RemoteViews headsUpContentView; |
| 376 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 377 | private boolean mUsesStandardHeader; |
| 378 | |
| 379 | private static final ArraySet<Integer> STANDARD_LAYOUTS = new ArraySet<>(); |
| 380 | static { |
| 381 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_base); |
| 382 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_base); |
| 383 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_picture); |
| 384 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text); |
| 385 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_inbox); |
| 386 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging); |
| 387 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_media); |
| 388 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 389 | STANDARD_LAYOUTS.add(R.layout.notification_template_header); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 390 | } |
| 391 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 392 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 393 | * A large bitmap to be shown in the notification content area. |
| 394 | * |
| 395 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 397 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 398 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | |
| 400 | /** |
| 401 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 402 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 404 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 405 | * </p> |
| 406 | * |
| 407 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 408 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 410 | * @deprecated use {@link NotificationChannel#getSound()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 412 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | public Uri sound; |
| 414 | |
| 415 | /** |
| 416 | * Use this constant as the value for audioStreamType to request that |
| 417 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 418 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 419 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 420 | * @deprecated Use {@link NotificationChannel#getAudioAttributes()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 422 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | public static final int STREAM_DEFAULT = -1; |
| 424 | |
| 425 | /** |
| 426 | * The audio stream type to use when playing the sound. |
| 427 | * Should be one of the STREAM_ constants from |
| 428 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 429 | * |
| 430 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 432 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | public int audioStreamType = STREAM_DEFAULT; |
| 434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 436 | * The default value of {@link #audioAttributes}. |
| 437 | */ |
| 438 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 439 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 440 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 441 | .build(); |
| 442 | |
| 443 | /** |
| 444 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 445 | * |
| 446 | * @deprecated use {@link NotificationChannel#getAudioAttributes()} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 447 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 448 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 449 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 450 | |
| 451 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 452 | * The pattern with which to vibrate. |
| 453 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | * <p> |
| 455 | * To vibrate the default pattern, see {@link #defaults}. |
| 456 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 457 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | * @see android.os.Vibrator#vibrate(long[],int) |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 459 | * @deprecated use {@link NotificationChannel#getVibrationPattern()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 461 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | public long[] vibrate; |
| 463 | |
| 464 | /** |
| 465 | * The color of the led. The hardware will do its best approximation. |
| 466 | * |
| 467 | * @see #FLAG_SHOW_LIGHTS |
| 468 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 469 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 471 | @ColorInt |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 472 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | public int ledARGB; |
| 474 | |
| 475 | /** |
| 476 | * The number of milliseconds for the LED to be on while it's flashing. |
| 477 | * The hardware will do its best approximation. |
| 478 | * |
| 479 | * @see #FLAG_SHOW_LIGHTS |
| 480 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 481 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 483 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | public int ledOnMS; |
| 485 | |
| 486 | /** |
| 487 | * The number of milliseconds for the LED to be off while it's flashing. |
| 488 | * The hardware will do its best approximation. |
| 489 | * |
| 490 | * @see #FLAG_SHOW_LIGHTS |
| 491 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 492 | * |
| 493 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 495 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | public int ledOffMS; |
| 497 | |
| 498 | /** |
| 499 | * Specifies which values should be taken from the defaults. |
| 500 | * <p> |
| 501 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 502 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 503 | * values, use {@link #DEFAULT_ALL}. |
| 504 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 505 | * |
| 506 | * @deprecated use {@link NotificationChannel#getSound()} and |
| 507 | * {@link NotificationChannel#shouldShowLights()} and |
| 508 | * {@link NotificationChannel#shouldVibrate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 510 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | public int defaults; |
| 512 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | /** |
| 514 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 515 | * set if you want the LED on for this notification. |
| 516 | * <ul> |
| 517 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 518 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 519 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 520 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 521 | * be on and off to ledOnMS and ledOffMS.</li> |
| 522 | * </ul> |
| 523 | * <p> |
| 524 | * 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] | 525 | * 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] | 526 | * because they will be set to values that work on any given hardware. |
| 527 | * <p> |
| 528 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 529 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 530 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 532 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 534 | |
| 535 | /** |
| 536 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 537 | * set if this notification is in reference to something that is ongoing, |
| 538 | * like a phone call. It should not be set if this notification is in |
| 539 | * reference to something that happened at a particular point in time, |
| 540 | * like a missed phone call. |
| 541 | */ |
| 542 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 543 | |
| 544 | /** |
| 545 | * 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] | 546 | * the audio will be repeated until the notification is |
| 547 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | */ |
| 549 | public static final int FLAG_INSISTENT = 0x00000004; |
| 550 | |
| 551 | /** |
| 552 | * 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] | 553 | * set if you would only like the sound, vibrate and ticker to be played |
| 554 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | */ |
| 556 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 557 | |
| 558 | /** |
| 559 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 560 | * 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] | 561 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | */ |
| 563 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 564 | |
| 565 | /** |
| 566 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 567 | * set if the notification should not be canceled when the user clicks |
| 568 | * the Clear all button. |
| 569 | */ |
| 570 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 571 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 572 | /** |
| 573 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 574 | * set if this notification represents a currently running service. This |
| 575 | * will normally be set for you by {@link Service#startForeground}. |
| 576 | */ |
| 577 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 578 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 579 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 580 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 581 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 582 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 583 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 584 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 585 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 586 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 587 | /** |
| 588 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 589 | * set if this notification is relevant to the current device only |
| 590 | * and it is not recommended that it bridge to other devices. |
| 591 | */ |
| 592 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 593 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 594 | /** |
| 595 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 596 | * set if this notification is the group summary for a group of notifications. |
| 597 | * Grouped notifications may display in a cluster or stack on devices which |
| 598 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 599 | */ |
| 600 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 601 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 602 | /** |
| 603 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 604 | * set if this notification is the group summary for an auto-group of notifications. |
| 605 | * |
| 606 | * @hide |
| 607 | */ |
| 608 | @SystemApi |
| 609 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 610 | |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 611 | /** |
| 612 | * @hide |
| 613 | */ |
| 614 | public static final int FLAG_CAN_COLORIZE = 0x00000800; |
| 615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | public int flags; |
| 617 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 618 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 619 | @IntDef(prefix = { "PRIORITY_" }, value = { |
| 620 | PRIORITY_DEFAULT, |
| 621 | PRIORITY_LOW, |
| 622 | PRIORITY_MIN, |
| 623 | PRIORITY_HIGH, |
| 624 | PRIORITY_MAX |
| 625 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 626 | @Retention(RetentionPolicy.SOURCE) |
| 627 | public @interface Priority {} |
| 628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 630 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 631 | * notifications, use this value for all notifications. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 632 | * |
| 633 | * @deprecated use {@link NotificationManager#IMPORTANCE_DEFAULT} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 634 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 635 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 636 | public static final int PRIORITY_DEFAULT = 0; |
| 637 | |
| 638 | /** |
| 639 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 640 | * items smaller, or at a different position in the list, compared with your app's |
| 641 | * {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 642 | * |
| 643 | * @deprecated use {@link NotificationManager#IMPORTANCE_LOW} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 644 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 645 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 646 | public static final int PRIORITY_LOW = -1; |
| 647 | |
| 648 | /** |
| 649 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 650 | * circumstances, such as detailed notification logs. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 651 | * |
| 652 | * @deprecated use {@link NotificationManager#IMPORTANCE_MIN} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 653 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 654 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 655 | public static final int PRIORITY_MIN = -2; |
| 656 | |
| 657 | /** |
| 658 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 659 | * show these items larger, or at a different position in notification lists, compared with |
| 660 | * your app's {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 661 | * |
| 662 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 663 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 664 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 665 | public static final int PRIORITY_HIGH = 1; |
| 666 | |
| 667 | /** |
| 668 | * Highest {@link #priority}, for your application's most important items that require the |
| 669 | * user's prompt attention or input. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 670 | * |
| 671 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 672 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 673 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 674 | public static final int PRIORITY_MAX = 2; |
| 675 | |
| 676 | /** |
| 677 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 678 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 679 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 680 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 681 | * 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] | 682 | * system will make a determination about how to interpret this priority when presenting |
| 683 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 684 | * |
| 685 | * <p> |
| 686 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 687 | * as a heads-up notification. |
| 688 | * </p> |
| 689 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 690 | * @deprecated use {@link NotificationChannel#getImportance()} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 691 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 692 | @Priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 693 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 694 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 695 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 696 | /** |
| 697 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 698 | * to be applied by the standard Style templates when presenting this notification. |
| 699 | * |
| 700 | * The current template design constructs a colorful header image by overlaying the |
| 701 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 702 | * ignored. |
| 703 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 704 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 705 | public int color = COLOR_DEFAULT; |
| 706 | |
| 707 | /** |
| 708 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 709 | * any special color but instead use default colors when presenting this notification. |
| 710 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 711 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 712 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 713 | |
| 714 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 715 | * 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] | 716 | * @hide |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 717 | */ |
| 718 | @ColorInt |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 719 | public static final int COLOR_INVALID = 1; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 720 | |
| 721 | /** |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 722 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 723 | * 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] | 724 | * lockscreen). |
| 725 | * |
| 726 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 727 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 728 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 729 | * the appropriate user. |
| 730 | * |
| 731 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 732 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 733 | * To modify the public version of this notification—for example, to redact some portions—see |
| 734 | * {@link Builder#setPublicVersion(Notification)}. |
| 735 | * |
| 736 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 737 | * and ticker until the user has bypassed the lockscreen. |
| 738 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 739 | public @Visibility int visibility; |
| 740 | |
| 741 | /** @hide */ |
| 742 | @IntDef(prefix = { "VISIBILITY_" }, value = { |
| 743 | VISIBILITY_PUBLIC, |
| 744 | VISIBILITY_PRIVATE, |
| 745 | VISIBILITY_SECRET, |
| 746 | }) |
| 747 | @Retention(RetentionPolicy.SOURCE) |
| 748 | public @interface Visibility {} |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 749 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 750 | /** |
| 751 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 752 | * |
| 753 | * {@see #visibility} |
| 754 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 755 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 756 | |
| 757 | /** |
| 758 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 759 | * private information on secure lockscreens. |
| 760 | * |
| 761 | * {@see #visibility} |
| 762 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 763 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 764 | |
| 765 | /** |
| 766 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 767 | * |
| 768 | * {@see #visibility} |
| 769 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 770 | public static final int VISIBILITY_SECRET = -1; |
| 771 | |
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 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 774 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 775 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 776 | |
| 777 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 778 | * Notification category: map turn-by-turn navigation. |
| 779 | */ |
| 780 | public static final String CATEGORY_NAVIGATION = "navigation"; |
| 781 | |
| 782 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 783 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 784 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 785 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 786 | |
| 787 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 788 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 789 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 790 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 791 | |
| 792 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 793 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 794 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 795 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 796 | |
| 797 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 798 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 799 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 800 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 801 | |
| 802 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 803 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 804 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 805 | public static final String CATEGORY_ALARM = "alarm"; |
| 806 | |
| 807 | /** |
| 808 | * Notification category: progress of a long-running background operation. |
| 809 | */ |
| 810 | public static final String CATEGORY_PROGRESS = "progress"; |
| 811 | |
| 812 | /** |
| 813 | * Notification category: social network or sharing update. |
| 814 | */ |
| 815 | public static final String CATEGORY_SOCIAL = "social"; |
| 816 | |
| 817 | /** |
| 818 | * Notification category: error in background operation or authentication status. |
| 819 | */ |
| 820 | public static final String CATEGORY_ERROR = "err"; |
| 821 | |
| 822 | /** |
| 823 | * Notification category: media transport control for playback. |
| 824 | */ |
| 825 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 826 | |
| 827 | /** |
| 828 | * Notification category: system or device status update. Reserved for system use. |
| 829 | */ |
| 830 | public static final String CATEGORY_SYSTEM = "sys"; |
| 831 | |
| 832 | /** |
| 833 | * Notification category: indication of running background service. |
| 834 | */ |
| 835 | public static final String CATEGORY_SERVICE = "service"; |
| 836 | |
| 837 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 838 | * Notification category: a specific, timely recommendation for a single thing. |
| 839 | * For example, a news app might want to recommend a news story it believes the user will |
| 840 | * want to read next. |
| 841 | */ |
| 842 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 843 | |
| 844 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 845 | * Notification category: ongoing information about device or contextual status. |
| 846 | */ |
| 847 | public static final String CATEGORY_STATUS = "status"; |
| 848 | |
| 849 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 850 | * Notification category: user-scheduled reminder. |
| 851 | */ |
| 852 | public static final String CATEGORY_REMINDER = "reminder"; |
| 853 | |
| 854 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 855 | * Notification category: extreme car emergencies. |
| 856 | * @hide |
| 857 | */ |
| 858 | @SystemApi |
| 859 | public static final String CATEGORY_CAR_EMERGENCY = "car_emergency"; |
| 860 | |
| 861 | /** |
| 862 | * Notification category: car warnings. |
| 863 | * @hide |
| 864 | */ |
| 865 | @SystemApi |
| 866 | public static final String CATEGORY_CAR_WARNING = "car_warning"; |
| 867 | |
| 868 | /** |
| 869 | * Notification category: general car system information. |
| 870 | * @hide |
| 871 | */ |
| 872 | @SystemApi |
| 873 | public static final String CATEGORY_CAR_INFORMATION = "car_information"; |
| 874 | |
| 875 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 876 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 877 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 878 | */ |
| 879 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 880 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 881 | @UnsupportedAppUsage |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 882 | private String mGroupKey; |
| 883 | |
| 884 | /** |
| 885 | * Get the key used to group this notification into a cluster or stack |
| 886 | * with other notifications on devices which support such rendering. |
| 887 | */ |
| 888 | public String getGroup() { |
| 889 | return mGroupKey; |
| 890 | } |
| 891 | |
| 892 | private String mSortKey; |
| 893 | |
| 894 | /** |
| 895 | * Get a sort key that orders this notification among other notifications from the |
| 896 | * same package. This can be useful if an external sort was already applied and an app |
| 897 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 898 | * value, although providing different priorities in addition to providing sort key may |
| 899 | * cause this value to be ignored. |
| 900 | * |
| 901 | * <p>This sort key can also be used to order members of a notification group. See |
| 902 | * {@link Builder#setGroup}. |
| 903 | * |
| 904 | * @see String#compareTo(String) |
| 905 | */ |
| 906 | public String getSortKey() { |
| 907 | return mSortKey; |
| 908 | } |
| 909 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 910 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 911 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 912 | * <p> |
| 913 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 914 | * APIs, and are intended to be used by |
| 915 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 916 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 917 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 918 | public Bundle extras = new Bundle(); |
| 919 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 920 | /** |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 921 | * All pending intents in the notification as the system needs to be able to access them but |
| 922 | * 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] | 923 | * custom parcelable objects. |
| 924 | * |
| 925 | * @hide |
| 926 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 927 | @UnsupportedAppUsage |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 928 | public ArraySet<PendingIntent> allPendingIntents; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 929 | |
| 930 | /** |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 931 | * Token identifying the notification that is applying doze/bgcheck whitelisting to the |
| 932 | * pending intents inside of it, so only those will get the behavior. |
| 933 | * |
| 934 | * @hide |
| 935 | */ |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 936 | private IBinder mWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 937 | |
| 938 | /** |
| 939 | * Must be set by a process to start associating tokens with Notification objects |
| 940 | * coming in to it. This is set by NotificationManagerService. |
| 941 | * |
| 942 | * @hide |
| 943 | */ |
| 944 | static public IBinder processWhitelistToken; |
| 945 | |
| 946 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 947 | * {@link #extras} key: this is the title of the notification, |
| 948 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 949 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 950 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 951 | |
| 952 | /** |
| 953 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 954 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 955 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 956 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 957 | |
| 958 | /** |
| 959 | * {@link #extras} key: this is the main text payload, as supplied to |
| 960 | * {@link Builder#setContentText(CharSequence)}. |
| 961 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 962 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 963 | |
| 964 | /** |
| 965 | * {@link #extras} key: this is a third line of text, as supplied to |
| 966 | * {@link Builder#setSubText(CharSequence)}. |
| 967 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 968 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 969 | |
| 970 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 971 | * {@link #extras} key: this is the remote input history, as supplied to |
| 972 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
Adrian Roos | 005e774 | 2016-04-13 15:02:20 -0700 | [diff] [blame] | 973 | * |
| 974 | * Apps can fill this through {@link Builder#setRemoteInputHistory(CharSequence[])} |
| 975 | * with the most recent inputs that have been sent through a {@link RemoteInput} of this |
| 976 | * Notification and are expected to clear it once the it is no longer relevant (e.g. for chat |
| 977 | * notifications once the other party has responded). |
| 978 | * |
| 979 | * The extra with this key is of type CharSequence[] and contains the most recent entry at |
| 980 | * the 0 index, the second most recent at the 1 index, etc. |
| 981 | * |
| 982 | * @see Builder#setRemoteInputHistory(CharSequence[]) |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 983 | */ |
| 984 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 985 | |
| 986 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 987 | * {@link #extras} key: boolean as supplied to |
| 988 | * {@link Builder#setShowRemoteInputSpinner(boolean)}. |
| 989 | * |
| 990 | * If set to true, then the view displaying the remote input history from |
| 991 | * {@link Builder#setRemoteInputHistory(CharSequence[])} will have a progress spinner. |
| 992 | * |
| 993 | * @see Builder#setShowRemoteInputSpinner(boolean) |
| 994 | * @hide |
| 995 | */ |
| 996 | public static final String EXTRA_SHOW_REMOTE_INPUT_SPINNER = "android.remoteInputSpinner"; |
| 997 | |
| 998 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 999 | * {@link #extras} key: boolean as supplied to |
| 1000 | * {@link Builder#setHideSmartReplies(boolean)}. |
| 1001 | * |
| 1002 | * If set to true, then any smart reply buttons will be hidden. |
| 1003 | * |
| 1004 | * @see Builder#setHideSmartReplies(boolean) |
| 1005 | * @hide |
| 1006 | */ |
| 1007 | public static final String EXTRA_HIDE_SMART_REPLIES = "android.hideSmartReplies"; |
| 1008 | |
| 1009 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1010 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 1011 | * {@link Builder#setContentInfo(CharSequence)}. |
| 1012 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1013 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1014 | |
| 1015 | /** |
| 1016 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 1017 | * alongside expanded notifications, as supplied to (e.g.) |
| 1018 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 1019 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1020 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1021 | |
| 1022 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1023 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 1024 | * {@link BigTextStyle} notification, as supplied to |
| 1025 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 1026 | */ |
| 1027 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 1028 | |
| 1029 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1030 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 1031 | * supplied to {@link Builder#setSmallIcon(int)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1032 | * |
| 1033 | * @deprecated Use {@link #getSmallIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1034 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1035 | @Deprecated |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1036 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1037 | |
| 1038 | /** |
| 1039 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 1040 | * notification payload, as |
| 1041 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1042 | * |
| 1043 | * @deprecated Use {@link #getLargeIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1044 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1045 | @Deprecated |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1046 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1047 | |
| 1048 | /** |
| 1049 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 1050 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 1051 | * shown in its expanded form, as supplied to |
| 1052 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 1053 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1054 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1055 | |
| 1056 | /** |
| 1057 | * {@link #extras} key: this is the progress value supplied to |
| 1058 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1059 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1060 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1061 | |
| 1062 | /** |
| 1063 | * {@link #extras} key: this is the maximum value supplied to |
| 1064 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1065 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1066 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1067 | |
| 1068 | /** |
| 1069 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 1070 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1071 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1072 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1073 | |
| 1074 | /** |
| 1075 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 1076 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 1077 | * {@link Builder#setUsesChronometer(boolean)}. |
| 1078 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1079 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1080 | |
| 1081 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1082 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 1083 | * 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] | 1084 | * This extra is a boolean. The default is false. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1085 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1086 | public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1087 | |
| 1088 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1089 | * {@link #extras} key: whether {@link #when} should be shown, |
| 1090 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 1091 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1092 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1093 | |
| 1094 | /** |
| 1095 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 1096 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 1097 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1098 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1099 | |
| 1100 | /** |
| 1101 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 1102 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 1103 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1104 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1105 | |
| 1106 | /** |
| 1107 | * {@link #extras} key: A string representing the name of the specific |
| 1108 | * {@link android.app.Notification.Style} used to create this notification. |
| 1109 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 1110 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1111 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1112 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 1113 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 1114 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1115 | * |
| 1116 | * @deprecated the actual objects are now in {@link #EXTRA_PEOPLE_LIST} |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1117 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1118 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1119 | |
| 1120 | /** |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1121 | * {@link #extras} key: An arrayList of {@link Person} objects containing the people that |
| 1122 | * this notification relates to. |
| 1123 | */ |
| 1124 | public static final String EXTRA_PEOPLE_LIST = "android.people.list"; |
| 1125 | |
| 1126 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1127 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 1128 | * Only available to notifications coming from the android package. |
| 1129 | * @hide |
| 1130 | */ |
Maurice Lam | 96c1003 | 2017-03-29 15:42:38 -0700 | [diff] [blame] | 1131 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1132 | @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1133 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 1134 | |
| 1135 | /** |
Robin Lee | d107af6 | 2018-04-27 13:55:56 +0200 | [diff] [blame] | 1136 | * {@link #extras} key: |
| 1137 | * flat {@link String} representation of a {@link android.content.ContentUris content URI} |
| 1138 | * pointing to an image that can be displayed in the background when the notification is |
| 1139 | * selected. Used on television platforms. The URI must point to an image stream suitable for |
| 1140 | * passing into {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1141 | * BitmapFactory.decodeStream}; all other content types will be ignored. |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1142 | */ |
| 1143 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1144 | |
| 1145 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1146 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 1147 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1148 | * {@link android.app.Notification.MediaStyle} notification. |
| 1149 | */ |
| 1150 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1151 | |
| 1152 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 1153 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 1154 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 1155 | */ |
| 1156 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1157 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 1158 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1159 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 1160 | * direct replies |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1161 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1162 | * {@link CharSequence} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1163 | * |
| 1164 | * @deprecated use {@link #EXTRA_MESSAGING_PERSON} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1165 | */ |
| 1166 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1167 | |
| 1168 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1169 | * {@link #extras} key: the person to be displayed for all messages sent by the user including |
| 1170 | * direct replies |
| 1171 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1172 | * {@link Person} |
| 1173 | */ |
| 1174 | public static final String EXTRA_MESSAGING_PERSON = "android.messagingUser"; |
| 1175 | |
| 1176 | /** |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1177 | * {@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] | 1178 | * represented by a {@link android.app.Notification.MessagingStyle} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1179 | */ |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1180 | public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1181 | |
| 1182 | /** |
| 1183 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 1184 | * bundles provided by a |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1185 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1186 | * array of bundles. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1187 | */ |
| 1188 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 1189 | |
| 1190 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 1191 | * {@link #extras} key: an array of |
| 1192 | * {@link android.app.Notification.MessagingStyle#addHistoricMessage historic} |
| 1193 | * {@link android.app.Notification.MessagingStyle.Message} bundles provided by a |
| 1194 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1195 | * array of bundles. |
| 1196 | */ |
| 1197 | public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1198 | |
| 1199 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 1200 | * {@link #extras} key: whether the {@link android.app.Notification.MessagingStyle} notification |
| 1201 | * represents a group conversation. |
| 1202 | */ |
| 1203 | public static final String EXTRA_IS_GROUP_CONVERSATION = "android.isGroupConversation"; |
| 1204 | |
| 1205 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1206 | * {@link #extras} key: whether the notification should be colorized as |
Gustav Sennton | df4c244 | 2019-03-18 11:41:11 +0000 | [diff] [blame] | 1207 | * supplied to {@link Builder#setColorized(boolean)}. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1208 | */ |
| 1209 | public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1210 | |
| 1211 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1212 | * @hide |
| 1213 | */ |
| 1214 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1215 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 1216 | /** |
| 1217 | * @hide |
| 1218 | */ |
| 1219 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1220 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1221 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 1222 | * @hide |
| 1223 | */ |
| 1224 | public static final String EXTRA_REDUCED_IMAGES = "android.reduced.images"; |
| 1225 | |
| 1226 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1227 | * {@link #extras} key: the audio contents of this notification. |
| 1228 | * |
| 1229 | * This is for use when rendering the notification on an audio-focused interface; |
| 1230 | * the audio contents are a complete sound sample that contains the contents/body of the |
| 1231 | * notification. This may be used in substitute of a Text-to-Speech reading of the |
| 1232 | * notification. For example if the notification represents a voice message this should point |
| 1233 | * to the audio of that message. |
| 1234 | * |
| 1235 | * The data stored under this key should be a String representation of a Uri that contains the |
| 1236 | * audio contents in one of the following formats: WAV, PCM 16-bit, AMR-WB. |
| 1237 | * |
| 1238 | * This extra is unnecessary if you are using {@code MessagingStyle} since each {@code Message} |
| 1239 | * has a field for holding data URI. That field can be used for audio. |
| 1240 | * See {@code Message#setData}. |
| 1241 | * |
| 1242 | * Example usage: |
| 1243 | * <pre> |
| 1244 | * {@code |
| 1245 | * Notification.Builder myBuilder = (build your Notification as normal); |
| 1246 | * myBuilder.getExtras().putString(EXTRA_AUDIO_CONTENTS_URI, myAudioUri.toString()); |
| 1247 | * } |
| 1248 | * </pre> |
| 1249 | */ |
| 1250 | public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1251 | |
Dan Sandler | 80eaa59 | 2016-04-14 23:34:54 -0400 | [diff] [blame] | 1252 | /** @hide */ |
| 1253 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1254 | @RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME) |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1255 | public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1256 | |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1257 | /** |
Julia Reynolds | 3c7de11 | 2018-03-28 09:33:13 -0400 | [diff] [blame] | 1258 | * This is set on the notifications shown by system_server about apps running foreground |
| 1259 | * services. It indicates that the notification should be shown |
| 1260 | * only if any of the given apps do not already have a properly tagged |
| 1261 | * {@link #FLAG_FOREGROUND_SERVICE} notification currently visible to the user. |
| 1262 | * This is a string array of all package names of the apps. |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1263 | * @hide |
| 1264 | */ |
| 1265 | public static final String EXTRA_FOREGROUND_APPS = "android.foregroundApps"; |
| 1266 | |
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 mSmallIcon; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1269 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1270 | private Icon mLargeIcon; |
| 1271 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1272 | @UnsupportedAppUsage |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1273 | private String mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1274 | private long mTimeout; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1275 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1276 | private String mShortcutId; |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 1277 | private LocusId mLocusId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1278 | private CharSequence mSettingsText; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1279 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 1280 | private BubbleMetadata mBubbleMetadata; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 1281 | |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1282 | /** @hide */ |
| 1283 | @IntDef(prefix = { "GROUP_ALERT_" }, value = { |
| 1284 | GROUP_ALERT_ALL, GROUP_ALERT_CHILDREN, GROUP_ALERT_SUMMARY |
| 1285 | }) |
| 1286 | @Retention(RetentionPolicy.SOURCE) |
| 1287 | public @interface GroupAlertBehavior {} |
| 1288 | |
| 1289 | /** |
| 1290 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all notifications in a |
| 1291 | * group with sound or vibration ought to make sound or vibrate (respectively), so this |
| 1292 | * notification will not be muted when it is in a group. |
| 1293 | */ |
| 1294 | public static final int GROUP_ALERT_ALL = 0; |
| 1295 | |
| 1296 | /** |
| 1297 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all children |
| 1298 | * notification in a group should be silenced (no sound or vibration) even if they are posted |
| 1299 | * 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] | 1300 | * mute this notification if this notification is a group child. This must be applied to all |
| 1301 | * children notifications you want to mute. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1302 | * |
| 1303 | * <p> For example, you might want to use this constant if you post a number of children |
| 1304 | * notifications at once (say, after a periodic sync), and only need to notify the user |
| 1305 | * audibly once. |
| 1306 | */ |
| 1307 | public static final int GROUP_ALERT_SUMMARY = 1; |
| 1308 | |
| 1309 | /** |
| 1310 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that the summary |
| 1311 | * notification in a group should be silenced (no sound or vibration) even if they are |
| 1312 | * posted to a {@link NotificationChannel} that has sound and/or vibration. Use this constant |
| 1313 | * to mute this notification if this notification is a group summary. |
| 1314 | * |
| 1315 | * <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] | 1316 | * in your group have content and the summary is only used to visually group notifications |
| 1317 | * rather than to alert the user that new information is available. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1318 | */ |
| 1319 | public static final int GROUP_ALERT_CHILDREN = 2; |
| 1320 | |
Julia Reynolds | 2f431e2 | 2017-06-07 14:12:09 +0000 | [diff] [blame] | 1321 | private int mGroupAlertBehavior = GROUP_ALERT_ALL; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1322 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1323 | /** |
| 1324 | * If this notification is being shown as a badge, always show as a number. |
| 1325 | */ |
| 1326 | public static final int BADGE_ICON_NONE = 0; |
| 1327 | |
| 1328 | /** |
| 1329 | * If this notification is being shown as a badge, use the {@link #getSmallIcon()} to |
| 1330 | * represent this notification. |
| 1331 | */ |
| 1332 | public static final int BADGE_ICON_SMALL = 1; |
| 1333 | |
| 1334 | /** |
| 1335 | * If this notification is being shown as a badge, use the {@link #getLargeIcon()} to |
| 1336 | * represent this notification. |
| 1337 | */ |
| 1338 | public static final int BADGE_ICON_LARGE = 2; |
Julia Reynolds | 7d5b4da | 2017-03-20 10:18:49 -0400 | [diff] [blame] | 1339 | private int mBadgeIcon = BADGE_ICON_NONE; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1340 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1341 | /** |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 1342 | * Determines whether the platform can generate contextual actions for a notification. |
| 1343 | */ |
| 1344 | private boolean mAllowSystemGeneratedContextualActions = true; |
| 1345 | |
| 1346 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1347 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 1348 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 1349 | * selected by the user. |
| 1350 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1351 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 1352 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 1353 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1354 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1355 | public static class Action implements Parcelable { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1356 | /** |
| 1357 | * {@link #extras} key: Keys to a {@link Parcelable} {@link ArrayList} of |
| 1358 | * {@link RemoteInput}s. |
| 1359 | * |
| 1360 | * This is intended for {@link RemoteInput}s that only accept data, meaning |
| 1361 | * {@link RemoteInput#getAllowFreeFormInput} is false, {@link RemoteInput#getChoices} |
Gustav Sennton | df4c244 | 2019-03-18 11:41:11 +0000 | [diff] [blame] | 1362 | * is null or empty, and {@link RemoteInput#getAllowedDataTypes} is non-null and not |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1363 | * empty. These {@link RemoteInput}s will be ignored by devices that do not |
| 1364 | * support non-text-based {@link RemoteInput}s. See {@link Builder#build}. |
| 1365 | * |
| 1366 | * You can test if a RemoteInput matches these constraints using |
| 1367 | * {@link RemoteInput#isDataOnly}. |
| 1368 | */ |
| 1369 | private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1370 | |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1371 | /** |
| 1372 | * {@link }: No semantic action defined. |
| 1373 | */ |
| 1374 | public static final int SEMANTIC_ACTION_NONE = 0; |
| 1375 | |
| 1376 | /** |
| 1377 | * {@code SemanticAction}: Reply to a conversation, chat, group, or wherever replies |
| 1378 | * may be appropriate. |
| 1379 | */ |
| 1380 | public static final int SEMANTIC_ACTION_REPLY = 1; |
| 1381 | |
| 1382 | /** |
| 1383 | * {@code SemanticAction}: Mark content as read. |
| 1384 | */ |
| 1385 | public static final int SEMANTIC_ACTION_MARK_AS_READ = 2; |
| 1386 | |
| 1387 | /** |
| 1388 | * {@code SemanticAction}: Mark content as unread. |
| 1389 | */ |
| 1390 | public static final int SEMANTIC_ACTION_MARK_AS_UNREAD = 3; |
| 1391 | |
| 1392 | /** |
| 1393 | * {@code SemanticAction}: Delete the content associated with the notification. This |
| 1394 | * could mean deleting an email, message, etc. |
| 1395 | */ |
| 1396 | public static final int SEMANTIC_ACTION_DELETE = 4; |
| 1397 | |
| 1398 | /** |
| 1399 | * {@code SemanticAction}: Archive the content associated with the notification. This |
| 1400 | * could mean archiving an email, message, etc. |
| 1401 | */ |
| 1402 | public static final int SEMANTIC_ACTION_ARCHIVE = 5; |
| 1403 | |
| 1404 | /** |
| 1405 | * {@code SemanticAction}: Mute the content associated with the notification. This could |
| 1406 | * mean silencing a conversation or currently playing media. |
| 1407 | */ |
| 1408 | public static final int SEMANTIC_ACTION_MUTE = 6; |
| 1409 | |
| 1410 | /** |
| 1411 | * {@code SemanticAction}: Unmute the content associated with the notification. This could |
| 1412 | * mean un-silencing a conversation or currently playing media. |
| 1413 | */ |
| 1414 | public static final int SEMANTIC_ACTION_UNMUTE = 7; |
| 1415 | |
| 1416 | /** |
| 1417 | * {@code SemanticAction}: Mark content with a thumbs up. |
| 1418 | */ |
| 1419 | public static final int SEMANTIC_ACTION_THUMBS_UP = 8; |
| 1420 | |
| 1421 | /** |
| 1422 | * {@code SemanticAction}: Mark content with a thumbs down. |
| 1423 | */ |
| 1424 | public static final int SEMANTIC_ACTION_THUMBS_DOWN = 9; |
| 1425 | |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 1426 | /** |
| 1427 | * {@code SemanticAction}: Call a contact, group, etc. |
| 1428 | */ |
| 1429 | public static final int SEMANTIC_ACTION_CALL = 10; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1430 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1431 | private final Bundle mExtras; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1432 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1433 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1434 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1435 | private boolean mAllowGeneratedReplies = true; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1436 | private final @SemanticAction int mSemanticAction; |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1437 | private final boolean mIsContextual; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1438 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1439 | /** |
| 1440 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1441 | * |
| 1442 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1443 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1444 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1445 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1446 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1447 | /** |
| 1448 | * Title of the action. |
| 1449 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1450 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1451 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1452 | /** |
| 1453 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1454 | * may be rendered in a disabled presentation by the system UI. |
| 1455 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1456 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1457 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1458 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1459 | if (in.readInt() != 0) { |
| 1460 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1461 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1462 | icon = mIcon.getResId(); |
| 1463 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1464 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1465 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1466 | if (in.readInt() == 1) { |
| 1467 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1468 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1469 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1470 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1471 | mAllowGeneratedReplies = in.readInt() == 1; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1472 | mSemanticAction = in.readInt(); |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1473 | mIsContextual = in.readInt() == 1; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1474 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1475 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1476 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1477 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1478 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1479 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1480 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1481 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1482 | SEMANTIC_ACTION_NONE, false /* isContextual */); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1485 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1486 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1487 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1488 | @SemanticAction int semanticAction, boolean isContextual) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1489 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1490 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1491 | this.icon = icon.getResId(); |
| 1492 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1493 | this.title = title; |
| 1494 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1495 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1496 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1497 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1498 | this.mSemanticAction = semanticAction; |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1499 | this.mIsContextual = isContextual; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1503 | * Return an icon representing the action. |
| 1504 | */ |
| 1505 | public Icon getIcon() { |
| 1506 | if (mIcon == null && icon != 0) { |
| 1507 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1508 | mIcon = Icon.createWithResource("", icon); |
| 1509 | } |
| 1510 | return mIcon; |
| 1511 | } |
| 1512 | |
| 1513 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1514 | * Get additional metadata carried around with this Action. |
| 1515 | */ |
| 1516 | public Bundle getExtras() { |
| 1517 | return mExtras; |
| 1518 | } |
| 1519 | |
| 1520 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1521 | * Return whether the platform should automatically generate possible replies for this |
| 1522 | * {@link Action} |
| 1523 | */ |
| 1524 | public boolean getAllowGeneratedReplies() { |
| 1525 | return mAllowGeneratedReplies; |
| 1526 | } |
| 1527 | |
| 1528 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1529 | * 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] | 1530 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1531 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1532 | */ |
| 1533 | public RemoteInput[] getRemoteInputs() { |
| 1534 | return mRemoteInputs; |
| 1535 | } |
| 1536 | |
| 1537 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1538 | * Returns the {@code SemanticAction} associated with this {@link Action}. A |
| 1539 | * {@code SemanticAction} denotes what an {@link Action}'s {@link PendingIntent} will do |
| 1540 | * (eg. reply, mark as read, delete, etc). |
| 1541 | */ |
| 1542 | public @SemanticAction int getSemanticAction() { |
| 1543 | return mSemanticAction; |
| 1544 | } |
| 1545 | |
| 1546 | /** |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1547 | * Returns whether this is a contextual Action, i.e. whether the action is dependent on the |
| 1548 | * notification message body. An example of a contextual action could be an action opening a |
| 1549 | * map application with an address shown in the notification. |
| 1550 | */ |
| 1551 | public boolean isContextual() { |
| 1552 | return mIsContextual; |
| 1553 | } |
| 1554 | |
| 1555 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1556 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1557 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1558 | * {@link RemoteInput#isDataOnly}. |
| 1559 | * |
Shane Brennan | f670d6c | 2017-04-25 13:05:45 -0700 | [diff] [blame] | 1560 | * Returns null if there are no data-only remote inputs. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1561 | * |
| 1562 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1563 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1564 | */ |
| 1565 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1566 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1567 | } |
| 1568 | |
| 1569 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1570 | * Builder class for {@link Action} objects. |
| 1571 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1572 | public static final class Builder { |
Gustav Sennton | e1fc87b | 2019-03-18 14:31:28 +0000 | [diff] [blame] | 1573 | @Nullable private final Icon mIcon; |
| 1574 | @Nullable private final CharSequence mTitle; |
| 1575 | @Nullable private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1576 | private boolean mAllowGeneratedReplies = true; |
Gustav Sennton | e1fc87b | 2019-03-18 14:31:28 +0000 | [diff] [blame] | 1577 | @NonNull private final Bundle mExtras; |
| 1578 | @Nullable private ArrayList<RemoteInput> mRemoteInputs; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1579 | private @SemanticAction int mSemanticAction; |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1580 | private boolean mIsContextual; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1581 | |
| 1582 | /** |
| 1583 | * Construct a new builder for {@link Action} object. |
| 1584 | * @param icon icon to show for this action |
| 1585 | * @param title the title of the action |
| 1586 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1587 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1588 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1589 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1590 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | /** |
| 1594 | * Construct a new builder for {@link Action} object. |
| 1595 | * @param icon icon to show for this action |
| 1596 | * @param title the title of the action |
| 1597 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1598 | */ |
| 1599 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1600 | this(icon, title, intent, new Bundle(), null, true, SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | /** |
| 1604 | * Construct a new builder for {@link Action} object using the fields from an |
| 1605 | * {@link Action}. |
| 1606 | * @param action the action to read fields from. |
| 1607 | */ |
| 1608 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1609 | this(action.getIcon(), action.title, action.actionIntent, |
| 1610 | new Bundle(action.mExtras), action.getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1611 | action.getAllowGeneratedReplies(), action.getSemanticAction()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
Gustav Sennton | e1fc87b | 2019-03-18 14:31:28 +0000 | [diff] [blame] | 1614 | private Builder(@Nullable Icon icon, @Nullable CharSequence title, |
| 1615 | @Nullable PendingIntent intent, @NonNull Bundle extras, |
| 1616 | @Nullable RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1617 | @SemanticAction int semanticAction) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1618 | mIcon = icon; |
| 1619 | mTitle = title; |
| 1620 | mIntent = intent; |
| 1621 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1622 | if (remoteInputs != null) { |
| 1623 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1624 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1625 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1626 | mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1627 | mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | /** |
| 1631 | * Merge additional metadata into this builder. |
| 1632 | * |
| 1633 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1634 | * |
| 1635 | * @see Notification.Action#extras |
| 1636 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1637 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1638 | public Builder addExtras(Bundle extras) { |
| 1639 | if (extras != null) { |
| 1640 | mExtras.putAll(extras); |
| 1641 | } |
| 1642 | return this; |
| 1643 | } |
| 1644 | |
| 1645 | /** |
| 1646 | * Get the metadata Bundle used by this Builder. |
| 1647 | * |
| 1648 | * <p>The returned Bundle is shared with this Builder. |
| 1649 | */ |
Gustav Sennton | e1fc87b | 2019-03-18 14:31:28 +0000 | [diff] [blame] | 1650 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1651 | public Bundle getExtras() { |
| 1652 | return mExtras; |
| 1653 | } |
| 1654 | |
| 1655 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1656 | * Add an input to be collected from the user when this action is sent. |
| 1657 | * Response values can be retrieved from the fired intent by using the |
| 1658 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1659 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1660 | * @return this object for method chaining |
| 1661 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1662 | @NonNull |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1663 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1664 | if (mRemoteInputs == null) { |
| 1665 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1666 | } |
| 1667 | mRemoteInputs.add(remoteInput); |
| 1668 | return this; |
| 1669 | } |
| 1670 | |
| 1671 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1672 | * Set whether the platform should automatically generate possible replies to add to |
| 1673 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1674 | * {@link RemoteInput}, this has no effect. |
| 1675 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1676 | * otherwise |
| 1677 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1678 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1679 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1680 | @NonNull |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1681 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1682 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1683 | return this; |
| 1684 | } |
| 1685 | |
| 1686 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1687 | * Sets the {@code SemanticAction} for this {@link Action}. A |
| 1688 | * {@code SemanticAction} denotes what an {@link Action}'s |
| 1689 | * {@link PendingIntent} will do (eg. reply, mark as read, delete, etc). |
| 1690 | * @param semanticAction a SemanticAction defined within {@link Action} with |
| 1691 | * {@code SEMANTIC_ACTION_} prefixes |
| 1692 | * @return this object for method chaining |
| 1693 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1694 | @NonNull |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1695 | public Builder setSemanticAction(@SemanticAction int semanticAction) { |
| 1696 | mSemanticAction = semanticAction; |
| 1697 | return this; |
| 1698 | } |
| 1699 | |
| 1700 | /** |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1701 | * Sets whether this {@link Action} is a contextual action, i.e. whether the action is |
| 1702 | * dependent on the notification message body. An example of a contextual action could |
| 1703 | * be an action opening a map application with an address shown in the notification. |
| 1704 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1705 | @NonNull |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1706 | public Builder setContextual(boolean isContextual) { |
| 1707 | mIsContextual = isContextual; |
| 1708 | return this; |
| 1709 | } |
| 1710 | |
| 1711 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1712 | * Apply an extender to this action builder. Extenders may be used to add |
| 1713 | * metadata or change options on this builder. |
| 1714 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1715 | @NonNull |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1716 | public Builder extend(Extender extender) { |
| 1717 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1718 | return this; |
| 1719 | } |
| 1720 | |
| 1721 | /** |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1722 | * Throws an NPE if we are building a contextual action missing one of the fields |
| 1723 | * necessary to display the action. |
| 1724 | */ |
| 1725 | private void checkContextualActionNullFields() { |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1726 | if (!mIsContextual) return; |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1727 | |
| 1728 | if (mIcon == null) { |
| 1729 | throw new NullPointerException("Contextual Actions must contain a valid icon"); |
| 1730 | } |
| 1731 | |
| 1732 | if (mIntent == null) { |
| 1733 | throw new NullPointerException( |
| 1734 | "Contextual Actions must contain a valid PendingIntent"); |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1739 | * Combine all of the options that have been set and return a new {@link Action} |
| 1740 | * object. |
| 1741 | * @return the built action |
| 1742 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1743 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1744 | public Action build() { |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1745 | checkContextualActionNullFields(); |
| 1746 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1747 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1748 | RemoteInput[] previousDataInputs = |
| 1749 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1750 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1751 | for (RemoteInput input : previousDataInputs) { |
| 1752 | dataOnlyInputs.add(input); |
| 1753 | } |
| 1754 | } |
| 1755 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1756 | if (mRemoteInputs != null) { |
| 1757 | for (RemoteInput input : mRemoteInputs) { |
| 1758 | if (input.isDataOnly()) { |
| 1759 | dataOnlyInputs.add(input); |
| 1760 | } else { |
| 1761 | textInputs.add(input); |
| 1762 | } |
| 1763 | } |
| 1764 | } |
| 1765 | if (!dataOnlyInputs.isEmpty()) { |
| 1766 | RemoteInput[] dataInputsArr = |
| 1767 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1768 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1769 | } |
| 1770 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1771 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1772 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1773 | mAllowGeneratedReplies, mSemanticAction, mIsContextual); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1774 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1775 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1776 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1777 | @Override |
| 1778 | public Action clone() { |
| 1779 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1780 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1781 | title, |
| 1782 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1783 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1784 | getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1785 | getAllowGeneratedReplies(), |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1786 | getSemanticAction(), |
| 1787 | isContextual()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1788 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1789 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1790 | @Override |
| 1791 | public int describeContents() { |
| 1792 | return 0; |
| 1793 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1794 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1795 | @Override |
| 1796 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1797 | final Icon ic = getIcon(); |
| 1798 | if (ic != null) { |
| 1799 | out.writeInt(1); |
| 1800 | ic.writeToParcel(out, 0); |
| 1801 | } else { |
| 1802 | out.writeInt(0); |
| 1803 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1804 | TextUtils.writeToParcel(title, out, flags); |
| 1805 | if (actionIntent != null) { |
| 1806 | out.writeInt(1); |
| 1807 | actionIntent.writeToParcel(out, flags); |
| 1808 | } else { |
| 1809 | out.writeInt(0); |
| 1810 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1811 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1812 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1813 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1814 | out.writeInt(mSemanticAction); |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1815 | out.writeInt(mIsContextual ? 1 : 0); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1816 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1817 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1818 | public static final @android.annotation.NonNull Parcelable.Creator<Action> CREATOR = |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1819 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1820 | public Action createFromParcel(Parcel in) { |
| 1821 | return new Action(in); |
| 1822 | } |
| 1823 | public Action[] newArray(int size) { |
| 1824 | return new Action[size]; |
| 1825 | } |
| 1826 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1827 | |
| 1828 | /** |
| 1829 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1830 | * metadata or change options on an action builder. |
| 1831 | */ |
| 1832 | public interface Extender { |
| 1833 | /** |
| 1834 | * Apply this extender to a notification action builder. |
| 1835 | * @param builder the builder to be modified. |
| 1836 | * @return the build object for chaining. |
| 1837 | */ |
| 1838 | public Builder extend(Builder builder); |
| 1839 | } |
| 1840 | |
| 1841 | /** |
| 1842 | * Wearable extender for notification actions. To add extensions to an action, |
| 1843 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1844 | * the {@code WearableExtender()} constructor and apply it to a |
| 1845 | * {@link android.app.Notification.Action.Builder} using |
| 1846 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1847 | * |
| 1848 | * <pre class="prettyprint"> |
| 1849 | * Notification.Action action = new Notification.Action.Builder( |
| 1850 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1851 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1852 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1853 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1854 | */ |
| 1855 | public static final class WearableExtender implements Extender { |
| 1856 | /** Notification action extra which contains wearable extensions */ |
| 1857 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1858 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1859 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1860 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1861 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1862 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1863 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1864 | |
| 1865 | // Flags bitwise-ored to mFlags |
| 1866 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1867 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1868 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1869 | |
| 1870 | // Default value for flags integer |
| 1871 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1872 | |
| 1873 | private int mFlags = DEFAULT_FLAGS; |
| 1874 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1875 | private CharSequence mInProgressLabel; |
| 1876 | private CharSequence mConfirmLabel; |
| 1877 | private CharSequence mCancelLabel; |
| 1878 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1879 | /** |
| 1880 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1881 | * options. |
| 1882 | */ |
| 1883 | public WearableExtender() { |
| 1884 | } |
| 1885 | |
| 1886 | /** |
| 1887 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1888 | * wearable options present in an existing notification action. |
| 1889 | * @param action the notification action to inspect. |
| 1890 | */ |
| 1891 | public WearableExtender(Action action) { |
| 1892 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1893 | if (wearableBundle != null) { |
| 1894 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1895 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1896 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1897 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | /** |
| 1902 | * Apply wearable extensions to a notification action that is being built. This is |
| 1903 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1904 | * method of {@link android.app.Notification.Action.Builder}. |
| 1905 | */ |
| 1906 | @Override |
| 1907 | public Action.Builder extend(Action.Builder builder) { |
| 1908 | Bundle wearableBundle = new Bundle(); |
| 1909 | |
| 1910 | if (mFlags != DEFAULT_FLAGS) { |
| 1911 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1912 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1913 | if (mInProgressLabel != null) { |
| 1914 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1915 | } |
| 1916 | if (mConfirmLabel != null) { |
| 1917 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1918 | } |
| 1919 | if (mCancelLabel != null) { |
| 1920 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1921 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1922 | |
| 1923 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1924 | return builder; |
| 1925 | } |
| 1926 | |
| 1927 | @Override |
| 1928 | public WearableExtender clone() { |
| 1929 | WearableExtender that = new WearableExtender(); |
| 1930 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1931 | that.mInProgressLabel = this.mInProgressLabel; |
| 1932 | that.mConfirmLabel = this.mConfirmLabel; |
| 1933 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1934 | return that; |
| 1935 | } |
| 1936 | |
| 1937 | /** |
| 1938 | * Set whether this action is available when the wearable device is not connected to |
| 1939 | * a companion device. The user can still trigger this action when the wearable device is |
| 1940 | * offline, but a visual hint will indicate that the action may not be available. |
| 1941 | * Defaults to true. |
| 1942 | */ |
| 1943 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1944 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1945 | return this; |
| 1946 | } |
| 1947 | |
| 1948 | /** |
| 1949 | * Get whether this action is available when the wearable device is not connected to |
| 1950 | * a companion device. The user can still trigger this action when the wearable device is |
| 1951 | * offline, but a visual hint will indicate that the action may not be available. |
| 1952 | * Defaults to true. |
| 1953 | */ |
| 1954 | public boolean isAvailableOffline() { |
| 1955 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1956 | } |
| 1957 | |
| 1958 | private void setFlag(int mask, boolean value) { |
| 1959 | if (value) { |
| 1960 | mFlags |= mask; |
| 1961 | } else { |
| 1962 | mFlags &= ~mask; |
| 1963 | } |
| 1964 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1965 | |
| 1966 | /** |
| 1967 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1968 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1969 | * |
| 1970 | * @param label the label to display while the action is being prepared to execute |
| 1971 | * @return this object for method chaining |
| 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 WearableExtender setInProgressLabel(CharSequence label) { |
| 1975 | mInProgressLabel = label; |
| 1976 | return this; |
| 1977 | } |
| 1978 | |
| 1979 | /** |
| 1980 | * Get the label to display while the wearable is preparing to automatically execute |
| 1981 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1982 | * |
| 1983 | * @return the label to display while the action is being prepared to execute |
| 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 CharSequence getInProgressLabel() { |
| 1987 | return mInProgressLabel; |
| 1988 | } |
| 1989 | |
| 1990 | /** |
| 1991 | * Set a label to display to confirm that the action should be executed. |
| 1992 | * This is usually an imperative verb like "Send". |
| 1993 | * |
| 1994 | * @param label the label to confirm the action should be executed |
| 1995 | * @return this object for method chaining |
| 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 WearableExtender setConfirmLabel(CharSequence label) { |
| 1999 | mConfirmLabel = label; |
| 2000 | return this; |
| 2001 | } |
| 2002 | |
| 2003 | /** |
| 2004 | * Get the label to display to confirm that the action should be executed. |
| 2005 | * This is usually an imperative verb like "Send". |
| 2006 | * |
| 2007 | * @return the label to confirm the action should be executed |
| 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 CharSequence getConfirmLabel() { |
| 2011 | return mConfirmLabel; |
| 2012 | } |
| 2013 | |
| 2014 | /** |
| 2015 | * Set a label to display to cancel the action. |
| 2016 | * This is usually an imperative verb, like "Cancel". |
| 2017 | * |
| 2018 | * @param label the label to display to cancel the action |
| 2019 | * @return this object for method chaining |
| 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 WearableExtender setCancelLabel(CharSequence label) { |
| 2023 | mCancelLabel = label; |
| 2024 | return this; |
| 2025 | } |
| 2026 | |
| 2027 | /** |
| 2028 | * Get the label to display to cancel the action. |
| 2029 | * This is usually an imperative verb like "Cancel". |
| 2030 | * |
| 2031 | * @return the label to display to cancel the action |
| 2032 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 2033 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 2034 | public CharSequence getCancelLabel() { |
| 2035 | return mCancelLabel; |
| 2036 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2037 | |
| 2038 | /** |
| 2039 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 2040 | * platform that it can generate the appropriate transitions. |
| 2041 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 2042 | * an activity and transitions should be generated, false otherwise. |
| 2043 | * @return this object for method chaining |
| 2044 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 2045 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2046 | boolean hintLaunchesActivity) { |
| 2047 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 2048 | return this; |
| 2049 | } |
| 2050 | |
| 2051 | /** |
| 2052 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 2053 | * platform that it can generate the appropriate transitions |
| 2054 | * @return {@code true} if the content intent will launch an activity and transitions |
| 2055 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 2056 | * never set. |
| 2057 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 2058 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2059 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 2060 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2061 | |
| 2062 | /** |
| 2063 | * Set a hint that this Action should be displayed inline. |
| 2064 | * |
| 2065 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 2066 | * otherwise |
| 2067 | * @return this object for method chaining |
| 2068 | */ |
| 2069 | public WearableExtender setHintDisplayActionInline( |
| 2070 | boolean hintDisplayInline) { |
| 2071 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 2072 | return this; |
| 2073 | } |
| 2074 | |
| 2075 | /** |
| 2076 | * Get a hint that this Action should be displayed inline. |
| 2077 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 2078 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2079 | * otherwise. The default value is {@code false} if this was never set. |
| 2080 | */ |
| 2081 | public boolean getHintDisplayActionInline() { |
| 2082 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 2083 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2084 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2085 | |
| 2086 | /** |
| 2087 | * Provides meaning to an {@link Action} that hints at what the associated |
| 2088 | * {@link PendingIntent} will do. For example, an {@link Action} with a |
| 2089 | * {@link PendingIntent} that replies to a text message notification may have the |
| 2090 | * {@link #SEMANTIC_ACTION_REPLY} {@code SemanticAction} set within it. |
| 2091 | * |
| 2092 | * @hide |
| 2093 | */ |
| 2094 | @IntDef(prefix = { "SEMANTIC_ACTION_" }, value = { |
| 2095 | SEMANTIC_ACTION_NONE, |
| 2096 | SEMANTIC_ACTION_REPLY, |
| 2097 | SEMANTIC_ACTION_MARK_AS_READ, |
| 2098 | SEMANTIC_ACTION_MARK_AS_UNREAD, |
| 2099 | SEMANTIC_ACTION_DELETE, |
| 2100 | SEMANTIC_ACTION_ARCHIVE, |
| 2101 | SEMANTIC_ACTION_MUTE, |
| 2102 | SEMANTIC_ACTION_UNMUTE, |
| 2103 | SEMANTIC_ACTION_THUMBS_UP, |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 2104 | SEMANTIC_ACTION_THUMBS_DOWN, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 2105 | SEMANTIC_ACTION_CALL |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2106 | }) |
| 2107 | @Retention(RetentionPolicy.SOURCE) |
| 2108 | public @interface SemanticAction {} |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2109 | } |
| 2110 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2111 | /** |
| 2112 | * Array of all {@link Action} structures attached to this notification by |
| 2113 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 2114 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 2115 | * interface for invoking actions. |
| 2116 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 2117 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2118 | |
| 2119 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2120 | * Replacement version of this notification whose content will be shown |
| 2121 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 2122 | * and {@link #VISIBILITY_PUBLIC}. |
| 2123 | */ |
| 2124 | public Notification publicVersion; |
| 2125 | |
| 2126 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2127 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2128 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2129 | */ |
| 2130 | public Notification() |
| 2131 | { |
| 2132 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2133 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2134 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | * @hide |
| 2139 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2140 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 2142 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 2143 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2144 | new Builder(context) |
| 2145 | .setWhen(when) |
| 2146 | .setSmallIcon(icon) |
| 2147 | .setTicker(tickerText) |
| 2148 | .setContentTitle(contentTitle) |
| 2149 | .setContentText(contentText) |
| 2150 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 2151 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | /** |
| 2155 | * Constructs a Notification object with the information needed to |
| 2156 | * have a status bar icon without the standard expanded view. |
| 2157 | * |
| 2158 | * @param icon The resource id of the icon to put in the status bar. |
| 2159 | * @param tickerText The text that flows by in the status bar when the notification first |
| 2160 | * activates. |
| 2161 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 2162 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2163 | * |
| 2164 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2165 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2166 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2167 | public Notification(int icon, CharSequence tickerText, long when) |
| 2168 | { |
| 2169 | this.icon = icon; |
| 2170 | this.tickerText = tickerText; |
| 2171 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2172 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | /** |
| 2176 | * Unflatten the notification from a parcel. |
| 2177 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2178 | @SuppressWarnings("unchecked") |
| 2179 | public Notification(Parcel parcel) { |
| 2180 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 2181 | // intents in extras are always written as the last entry. |
| 2182 | readFromParcelImpl(parcel); |
| 2183 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2184 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | { |
| 2189 | int version = parcel.readInt(); |
| 2190 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2191 | mWhitelistToken = parcel.readStrongBinder(); |
| 2192 | if (mWhitelistToken == null) { |
| 2193 | mWhitelistToken = processWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2194 | } |
| 2195 | // 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] | 2196 | parcel.setClassCookie(PendingIntent.class, mWhitelistToken); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2198 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2199 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2200 | if (parcel.readInt() != 0) { |
| 2201 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2202 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 2203 | icon = mSmallIcon.getResId(); |
| 2204 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2205 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | number = parcel.readInt(); |
| 2207 | if (parcel.readInt() != 0) { |
| 2208 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2209 | } |
| 2210 | if (parcel.readInt() != 0) { |
| 2211 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2212 | } |
| 2213 | if (parcel.readInt() != 0) { |
| 2214 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2215 | } |
| 2216 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2217 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2218 | } |
| 2219 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2221 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2222 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2223 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2224 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2225 | defaults = parcel.readInt(); |
| 2226 | flags = parcel.readInt(); |
| 2227 | if (parcel.readInt() != 0) { |
| 2228 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 2229 | } |
| 2230 | |
| 2231 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2232 | if (parcel.readInt() != 0) { |
| 2233 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 2234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2235 | vibrate = parcel.createLongArray(); |
| 2236 | ledARGB = parcel.readInt(); |
| 2237 | ledOnMS = parcel.readInt(); |
| 2238 | ledOffMS = parcel.readInt(); |
| 2239 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2240 | |
| 2241 | if (parcel.readInt() != 0) { |
| 2242 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2243 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2244 | |
| 2245 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2246 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2247 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2248 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2249 | mGroupKey = parcel.readString(); |
| 2250 | |
| 2251 | mSortKey = parcel.readString(); |
| 2252 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 2253 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2254 | fixDuplicateExtras(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2255 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2256 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 2257 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2258 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2259 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2260 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2261 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2262 | if (parcel.readInt() != 0) { |
| 2263 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2264 | } |
| 2265 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2266 | visibility = parcel.readInt(); |
| 2267 | |
| 2268 | if (parcel.readInt() != 0) { |
| 2269 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 2270 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2271 | |
| 2272 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2273 | |
| 2274 | if (parcel.readInt() != 0) { |
| 2275 | mChannelId = parcel.readString(); |
| 2276 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2277 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2278 | |
| 2279 | if (parcel.readInt() != 0) { |
| 2280 | mShortcutId = parcel.readString(); |
| 2281 | } |
| 2282 | |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2283 | if (parcel.readInt() != 0) { |
| 2284 | mLocusId = LocusId.CREATOR.createFromParcel(parcel); |
| 2285 | } |
| 2286 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2287 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2288 | |
| 2289 | if (parcel.readInt() != 0) { |
| 2290 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2291 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2292 | |
| 2293 | mGroupAlertBehavior = parcel.readInt(); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2294 | if (parcel.readInt() != 0) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2295 | mBubbleMetadata = BubbleMetadata.CREATOR.createFromParcel(parcel); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2296 | } |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2297 | |
| 2298 | mAllowSystemGeneratedContextualActions = parcel.readBoolean(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2299 | } |
| 2300 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2301 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2302 | public Notification clone() { |
| 2303 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2304 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2305 | return that; |
| 2306 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2307 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2308 | /** |
| 2309 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 2310 | * of this into that. |
| 2311 | * @hide |
| 2312 | */ |
| 2313 | public void cloneInto(Notification that, boolean heavy) { |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2314 | that.mWhitelistToken = this.mWhitelistToken; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2315 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2316 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2317 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2318 | that.number = this.number; |
| 2319 | |
| 2320 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 2321 | that.contentIntent = this.contentIntent; |
| 2322 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2323 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2324 | |
| 2325 | if (this.tickerText != null) { |
| 2326 | that.tickerText = this.tickerText.toString(); |
| 2327 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2328 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2329 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2330 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2331 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2332 | that.contentView = this.contentView.clone(); |
| 2333 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2334 | if (heavy && this.mLargeIcon != null) { |
| 2335 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2336 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 2337 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2338 | that.sound = this.sound; // android.net.Uri is immutable |
| 2339 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2340 | if (this.audioAttributes != null) { |
| 2341 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 2342 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2343 | |
| 2344 | final long[] vibrate = this.vibrate; |
| 2345 | if (vibrate != null) { |
| 2346 | final int N = vibrate.length; |
| 2347 | final long[] vib = that.vibrate = new long[N]; |
| 2348 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 2349 | } |
| 2350 | |
| 2351 | that.ledARGB = this.ledARGB; |
| 2352 | that.ledOnMS = this.ledOnMS; |
| 2353 | that.ledOffMS = this.ledOffMS; |
| 2354 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2355 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2356 | that.flags = this.flags; |
| 2357 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2358 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2359 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2360 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2361 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2362 | that.mGroupKey = this.mGroupKey; |
| 2363 | |
| 2364 | that.mSortKey = this.mSortKey; |
| 2365 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2366 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2367 | try { |
| 2368 | that.extras = new Bundle(this.extras); |
| 2369 | // will unparcel |
| 2370 | that.extras.size(); |
| 2371 | } catch (BadParcelableException e) { |
| 2372 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2373 | that.extras = null; |
| 2374 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2375 | } |
| 2376 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2377 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2378 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2381 | if (this.actions != null) { |
| 2382 | that.actions = new Action[this.actions.length]; |
| 2383 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 2384 | if ( this.actions[i] != null) { |
| 2385 | that.actions[i] = this.actions[i].clone(); |
| 2386 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2387 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2388 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2389 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2390 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2391 | that.bigContentView = this.bigContentView.clone(); |
| 2392 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2393 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2394 | if (heavy && this.headsUpContentView != null) { |
| 2395 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 2396 | } |
| 2397 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2398 | that.visibility = this.visibility; |
| 2399 | |
| 2400 | if (this.publicVersion != null) { |
| 2401 | that.publicVersion = new Notification(); |
| 2402 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2403 | } |
| 2404 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2405 | that.color = this.color; |
| 2406 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2407 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2408 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2409 | that.mShortcutId = this.mShortcutId; |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2410 | that.mLocusId = this.mLocusId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2411 | that.mBadgeIcon = this.mBadgeIcon; |
| 2412 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2413 | that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2414 | that.mBubbleMetadata = this.mBubbleMetadata; |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2415 | that.mAllowSystemGeneratedContextualActions = this.mAllowSystemGeneratedContextualActions; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2416 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2417 | if (!heavy) { |
| 2418 | that.lightenPayload(); // will clean out extras |
| 2419 | } |
| 2420 | } |
| 2421 | |
| 2422 | /** |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2423 | * Note all {@link Uri} that are referenced internally, with the expectation |
| 2424 | * that Uri permission grants will need to be issued to ensure the recipient |
| 2425 | * of this object is able to render its contents. |
| 2426 | * |
| 2427 | * @hide |
| 2428 | */ |
| 2429 | public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 2430 | visitor.accept(sound); |
| 2431 | |
| 2432 | if (tickerView != null) tickerView.visitUris(visitor); |
| 2433 | if (contentView != null) contentView.visitUris(visitor); |
| 2434 | if (bigContentView != null) bigContentView.visitUris(visitor); |
| 2435 | if (headsUpContentView != null) headsUpContentView.visitUris(visitor); |
| 2436 | |
| 2437 | if (extras != null) { |
| 2438 | visitor.accept(extras.getParcelable(EXTRA_AUDIO_CONTENTS_URI)); |
Robin Lee | d107af6 | 2018-04-27 13:55:56 +0200 | [diff] [blame] | 2439 | if (extras.containsKey(EXTRA_BACKGROUND_IMAGE_URI)) { |
| 2440 | visitor.accept(Uri.parse(extras.getString(EXTRA_BACKGROUND_IMAGE_URI))); |
| 2441 | } |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | if (MessagingStyle.class.equals(getNotificationStyle()) && extras != null) { |
| 2445 | final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 2446 | if (!ArrayUtils.isEmpty(messages)) { |
| 2447 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2448 | .getMessagesFromBundleArray(messages)) { |
| 2449 | visitor.accept(message.getDataUri()); |
| 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 2454 | if (!ArrayUtils.isEmpty(historic)) { |
| 2455 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2456 | .getMessagesFromBundleArray(historic)) { |
| 2457 | visitor.accept(message.getDataUri()); |
| 2458 | } |
| 2459 | } |
| 2460 | } |
| 2461 | } |
| 2462 | |
| 2463 | /** |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2464 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 2465 | * listeners when the full contents are not necessary. |
| 2466 | * @hide |
| 2467 | */ |
| 2468 | public final void lightenPayload() { |
| 2469 | tickerView = null; |
| 2470 | contentView = null; |
| 2471 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2472 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2473 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2474 | if (extras != null && !extras.isEmpty()) { |
| 2475 | final Set<String> keyset = extras.keySet(); |
| 2476 | final int N = keyset.size(); |
| 2477 | final String[] keys = keyset.toArray(new String[N]); |
| 2478 | for (int i=0; i<N; i++) { |
| 2479 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2480 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2481 | continue; |
| 2482 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2483 | final Object obj = extras.get(key); |
| 2484 | if (obj != null && |
| 2485 | ( obj instanceof Parcelable |
| 2486 | || obj instanceof Parcelable[] |
| 2487 | || obj instanceof SparseArray |
| 2488 | || obj instanceof ArrayList)) { |
| 2489 | extras.remove(key); |
| 2490 | } |
| 2491 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2492 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2495 | /** |
| 2496 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2497 | * means it had better not be some custom Parcelable implementation. |
| 2498 | * @hide |
| 2499 | */ |
| 2500 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2501 | if (cs == null) return cs; |
| 2502 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2503 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2504 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2505 | if (cs instanceof Parcelable) { |
| 2506 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2507 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2508 | return cs.toString(); |
| 2509 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2510 | return removeTextSizeSpans(cs); |
| 2511 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2512 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2513 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2514 | if (charSequence instanceof Spanned) { |
| 2515 | Spanned ss = (Spanned) charSequence; |
| 2516 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2517 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2518 | for (Object span : spans) { |
| 2519 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2520 | if (resultSpan instanceof CharacterStyle) { |
| 2521 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2522 | } |
| 2523 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2524 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2525 | resultSpan = new TextAppearanceSpan( |
| 2526 | originalSpan.getFamily(), |
| 2527 | originalSpan.getTextStyle(), |
| 2528 | -1, |
| 2529 | originalSpan.getTextColor(), |
| 2530 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2531 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2532 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2533 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2534 | } else { |
| 2535 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2536 | } |
| 2537 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2538 | ss.getSpanFlags(span)); |
| 2539 | } |
| 2540 | return builder; |
| 2541 | } |
| 2542 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2543 | } |
| 2544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | public int describeContents() { |
| 2546 | return 0; |
| 2547 | } |
| 2548 | |
| 2549 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2550 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2552 | public void writeToParcel(Parcel parcel, int flags) { |
| 2553 | // We need to mark all pending intents getting into the notification |
| 2554 | // system as being put there to later allow the notification ranker |
| 2555 | // to launch them and by doing so add the app to the battery saver white |
| 2556 | // list for a short period of time. The problem is that the system |
| 2557 | // cannot look into the extras as there may be parcelables there that |
| 2558 | // the platform does not know how to handle. To go around that we have |
| 2559 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2560 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2561 | if (collectPendingIntents) { |
| 2562 | PendingIntent.setOnMarshaledListener( |
| 2563 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2564 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2565 | if (allPendingIntents == null) { |
| 2566 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2567 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2568 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2569 | } |
| 2570 | }); |
| 2571 | } |
| 2572 | try { |
| 2573 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2574 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2575 | writeToParcelImpl(parcel, flags); |
| 2576 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2577 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2578 | } finally { |
| 2579 | if (collectPendingIntents) { |
| 2580 | PendingIntent.setOnMarshaledListener(null); |
| 2581 | } |
| 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2586 | parcel.writeInt(1); |
| 2587 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2588 | parcel.writeStrongBinder(mWhitelistToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2589 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2590 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2591 | if (mSmallIcon == null && icon != 0) { |
| 2592 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2593 | mSmallIcon = Icon.createWithResource("", icon); |
| 2594 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2595 | if (mSmallIcon != null) { |
| 2596 | parcel.writeInt(1); |
| 2597 | mSmallIcon.writeToParcel(parcel, 0); |
| 2598 | } else { |
| 2599 | parcel.writeInt(0); |
| 2600 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | parcel.writeInt(number); |
| 2602 | if (contentIntent != null) { |
| 2603 | parcel.writeInt(1); |
| 2604 | contentIntent.writeToParcel(parcel, 0); |
| 2605 | } else { |
| 2606 | parcel.writeInt(0); |
| 2607 | } |
| 2608 | if (deleteIntent != null) { |
| 2609 | parcel.writeInt(1); |
| 2610 | deleteIntent.writeToParcel(parcel, 0); |
| 2611 | } else { |
| 2612 | parcel.writeInt(0); |
| 2613 | } |
| 2614 | if (tickerText != null) { |
| 2615 | parcel.writeInt(1); |
| 2616 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2617 | } else { |
| 2618 | parcel.writeInt(0); |
| 2619 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2620 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2621 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2622 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2623 | } else { |
| 2624 | parcel.writeInt(0); |
| 2625 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2626 | if (contentView != null) { |
| 2627 | parcel.writeInt(1); |
| 2628 | contentView.writeToParcel(parcel, 0); |
| 2629 | } else { |
| 2630 | parcel.writeInt(0); |
| 2631 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2632 | if (mLargeIcon == null && largeIcon != null) { |
| 2633 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2634 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2635 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2636 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2637 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2638 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2639 | } else { |
| 2640 | parcel.writeInt(0); |
| 2641 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2642 | |
| 2643 | parcel.writeInt(defaults); |
| 2644 | parcel.writeInt(this.flags); |
| 2645 | |
| 2646 | if (sound != null) { |
| 2647 | parcel.writeInt(1); |
| 2648 | sound.writeToParcel(parcel, 0); |
| 2649 | } else { |
| 2650 | parcel.writeInt(0); |
| 2651 | } |
| 2652 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2653 | |
| 2654 | if (audioAttributes != null) { |
| 2655 | parcel.writeInt(1); |
| 2656 | audioAttributes.writeToParcel(parcel, 0); |
| 2657 | } else { |
| 2658 | parcel.writeInt(0); |
| 2659 | } |
| 2660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | parcel.writeLongArray(vibrate); |
| 2662 | parcel.writeInt(ledARGB); |
| 2663 | parcel.writeInt(ledOnMS); |
| 2664 | parcel.writeInt(ledOffMS); |
| 2665 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2666 | |
| 2667 | if (fullScreenIntent != null) { |
| 2668 | parcel.writeInt(1); |
| 2669 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2670 | } else { |
| 2671 | parcel.writeInt(0); |
| 2672 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2673 | |
| 2674 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2675 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2676 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2677 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2678 | parcel.writeString(mGroupKey); |
| 2679 | |
| 2680 | parcel.writeString(mSortKey); |
| 2681 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2682 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2683 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2684 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2685 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2686 | if (bigContentView != null) { |
| 2687 | parcel.writeInt(1); |
| 2688 | bigContentView.writeToParcel(parcel, 0); |
| 2689 | } else { |
| 2690 | parcel.writeInt(0); |
| 2691 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2692 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2693 | if (headsUpContentView != null) { |
| 2694 | parcel.writeInt(1); |
| 2695 | headsUpContentView.writeToParcel(parcel, 0); |
| 2696 | } else { |
| 2697 | parcel.writeInt(0); |
| 2698 | } |
| 2699 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2700 | parcel.writeInt(visibility); |
| 2701 | |
| 2702 | if (publicVersion != null) { |
| 2703 | parcel.writeInt(1); |
| 2704 | publicVersion.writeToParcel(parcel, 0); |
| 2705 | } else { |
| 2706 | parcel.writeInt(0); |
| 2707 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2708 | |
| 2709 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2710 | |
| 2711 | if (mChannelId != null) { |
| 2712 | parcel.writeInt(1); |
| 2713 | parcel.writeString(mChannelId); |
| 2714 | } else { |
| 2715 | parcel.writeInt(0); |
| 2716 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2717 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2718 | |
| 2719 | if (mShortcutId != null) { |
| 2720 | parcel.writeInt(1); |
| 2721 | parcel.writeString(mShortcutId); |
| 2722 | } else { |
| 2723 | parcel.writeInt(0); |
| 2724 | } |
| 2725 | |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2726 | if (mLocusId != null) { |
| 2727 | parcel.writeInt(1); |
| 2728 | mLocusId.writeToParcel(parcel, 0); |
| 2729 | } else { |
| 2730 | parcel.writeInt(0); |
| 2731 | } |
| 2732 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2733 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2734 | |
| 2735 | if (mSettingsText != null) { |
| 2736 | parcel.writeInt(1); |
| 2737 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2738 | } else { |
| 2739 | parcel.writeInt(0); |
| 2740 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2741 | |
| 2742 | parcel.writeInt(mGroupAlertBehavior); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2743 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2744 | if (mBubbleMetadata != null) { |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2745 | parcel.writeInt(1); |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2746 | mBubbleMetadata.writeToParcel(parcel, 0); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2747 | } else { |
| 2748 | parcel.writeInt(0); |
| 2749 | } |
| 2750 | |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2751 | parcel.writeBoolean(mAllowSystemGeneratedContextualActions); |
| 2752 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2753 | // 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] | 2754 | } |
| 2755 | |
| 2756 | /** |
| 2757 | * Parcelable.Creator that instantiates Notification objects |
| 2758 | */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 2759 | public static final @android.annotation.NonNull Parcelable.Creator<Notification> CREATOR |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2760 | = new Parcelable.Creator<Notification>() |
| 2761 | { |
| 2762 | public Notification createFromParcel(Parcel parcel) |
| 2763 | { |
| 2764 | return new Notification(parcel); |
| 2765 | } |
| 2766 | |
| 2767 | public Notification[] newArray(int size) |
| 2768 | { |
| 2769 | return new Notification[size]; |
| 2770 | } |
| 2771 | }; |
| 2772 | |
| 2773 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2774 | * @hide |
| 2775 | */ |
| 2776 | public static boolean areActionsVisiblyDifferent(Notification first, Notification second) { |
| 2777 | Notification.Action[] firstAs = first.actions; |
| 2778 | Notification.Action[] secondAs = second.actions; |
| 2779 | if (firstAs == null && secondAs != null || firstAs != null && secondAs == null) { |
| 2780 | return true; |
| 2781 | } |
| 2782 | if (firstAs != null && secondAs != null) { |
| 2783 | if (firstAs.length != secondAs.length) { |
| 2784 | return true; |
| 2785 | } |
| 2786 | for (int i = 0; i < firstAs.length; i++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2787 | if (!Objects.equals(String.valueOf(firstAs[i].title), |
| 2788 | String.valueOf(secondAs[i].title))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2789 | return true; |
| 2790 | } |
| 2791 | RemoteInput[] firstRs = firstAs[i].getRemoteInputs(); |
| 2792 | RemoteInput[] secondRs = secondAs[i].getRemoteInputs(); |
| 2793 | if (firstRs == null) { |
| 2794 | firstRs = new RemoteInput[0]; |
| 2795 | } |
| 2796 | if (secondRs == null) { |
| 2797 | secondRs = new RemoteInput[0]; |
| 2798 | } |
| 2799 | if (firstRs.length != secondRs.length) { |
| 2800 | return true; |
| 2801 | } |
| 2802 | for (int j = 0; j < firstRs.length; j++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2803 | if (!Objects.equals(String.valueOf(firstRs[j].getLabel()), |
| 2804 | String.valueOf(secondRs[j].getLabel()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2805 | return true; |
| 2806 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2807 | } |
| 2808 | } |
| 2809 | } |
| 2810 | return false; |
| 2811 | } |
| 2812 | |
| 2813 | /** |
| 2814 | * @hide |
| 2815 | */ |
| 2816 | public static boolean areStyledNotificationsVisiblyDifferent(Builder first, Builder second) { |
| 2817 | if (first.getStyle() == null) { |
| 2818 | return second.getStyle() != null; |
| 2819 | } |
| 2820 | if (second.getStyle() == null) { |
| 2821 | return true; |
| 2822 | } |
| 2823 | return first.getStyle().areNotificationsVisiblyDifferent(second.getStyle()); |
| 2824 | } |
| 2825 | |
| 2826 | /** |
| 2827 | * @hide |
| 2828 | */ |
| 2829 | public static boolean areRemoteViewsChanged(Builder first, Builder second) { |
Julia Reynolds | e5c6045 | 2018-04-30 14:41:36 -0400 | [diff] [blame] | 2830 | if (!Objects.equals(first.usesStandardHeader(), second.usesStandardHeader())) { |
| 2831 | return true; |
| 2832 | } |
| 2833 | |
| 2834 | if (areRemoteViewsChanged(first.mN.contentView, second.mN.contentView)) { |
| 2835 | return true; |
| 2836 | } |
| 2837 | if (areRemoteViewsChanged(first.mN.bigContentView, second.mN.bigContentView)) { |
| 2838 | return true; |
| 2839 | } |
| 2840 | if (areRemoteViewsChanged(first.mN.headsUpContentView, second.mN.headsUpContentView)) { |
| 2841 | return true; |
| 2842 | } |
| 2843 | |
| 2844 | return false; |
| 2845 | } |
| 2846 | |
| 2847 | private static boolean areRemoteViewsChanged(RemoteViews first, RemoteViews second) { |
| 2848 | if (first == null && second == null) { |
| 2849 | return false; |
| 2850 | } |
| 2851 | if (first == null && second != null || first != null && second == null) { |
| 2852 | return true; |
| 2853 | } |
| 2854 | |
| 2855 | if (!Objects.equals(first.getLayoutId(), second.getLayoutId())) { |
| 2856 | return true; |
| 2857 | } |
| 2858 | |
| 2859 | if (!Objects.equals(first.getSequenceNumber(), second.getSequenceNumber())) { |
| 2860 | return true; |
| 2861 | } |
| 2862 | |
| 2863 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | /** |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2867 | * Parcelling creates multiple copies of objects in {@code extras}. Fix them. |
| 2868 | * <p> |
| 2869 | * For backwards compatibility {@code extras} holds some references to "real" member data such |
| 2870 | * as {@link getLargeIcon()} which is mirrored by {@link #EXTRA_LARGE_ICON}. This is mostly |
| 2871 | * fine as long as the object stays in one process. |
| 2872 | * <p> |
| 2873 | * However, once the notification goes into a parcel each reference gets marshalled separately, |
| 2874 | * wasting memory. Especially with large images on Auto and TV, this is worth fixing. |
| 2875 | */ |
| 2876 | private void fixDuplicateExtras() { |
| 2877 | if (extras != null) { |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2878 | fixDuplicateExtra(mLargeIcon, EXTRA_LARGE_ICON); |
| 2879 | } |
| 2880 | } |
| 2881 | |
| 2882 | /** |
| 2883 | * If we find an extra that's exactly the same as one of the "real" fields but refers to a |
| 2884 | * separate object, replace it with the field's version to avoid holding duplicate copies. |
| 2885 | */ |
| 2886 | private void fixDuplicateExtra(@Nullable Parcelable original, @NonNull String extraName) { |
| 2887 | if (original != null && extras.getParcelable(extraName) != null) { |
| 2888 | extras.putParcelable(extraName, original); |
| 2889 | } |
| 2890 | } |
| 2891 | |
| 2892 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2894 | * layout. |
| 2895 | * |
| 2896 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2897 | * in the view.</p> |
| 2898 | * @param context The context for your application / activity. |
| 2899 | * @param contentTitle The title that goes in the expanded entry. |
| 2900 | * @param contentText The text that goes in the expanded entry. |
| 2901 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2902 | * If this is an activity, it must include the |
| 2903 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2904 | * that you take care of task management as described in the |
| 2905 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2906 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2907 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2908 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2909 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2911 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | public void setLatestEventInfo(Context context, |
| 2913 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2914 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2915 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2916 | new Throwable()); |
| 2917 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2918 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2919 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2920 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2921 | } |
| 2922 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2923 | // ensure that any information already set directly is preserved |
| 2924 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2925 | |
| 2926 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2928 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2929 | } |
| 2930 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2931 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2932 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2933 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2934 | |
| 2935 | 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] | 2936 | } |
| 2937 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2938 | /** |
| 2939 | * @hide |
| 2940 | */ |
| 2941 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2942 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | /** |
| 2946 | * @hide |
| 2947 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2948 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2949 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2950 | } |
| 2951 | |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 2952 | /** |
| 2953 | * @hide |
| 2954 | */ |
| 2955 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 2956 | long token = proto.start(fieldId); |
| 2957 | proto.write(NotificationProto.CHANNEL_ID, getChannelId()); |
| 2958 | proto.write(NotificationProto.HAS_TICKER_TEXT, this.tickerText != null); |
| 2959 | proto.write(NotificationProto.FLAGS, this.flags); |
| 2960 | proto.write(NotificationProto.COLOR, this.color); |
| 2961 | proto.write(NotificationProto.CATEGORY, this.category); |
| 2962 | proto.write(NotificationProto.GROUP_KEY, this.mGroupKey); |
| 2963 | proto.write(NotificationProto.SORT_KEY, this.mSortKey); |
| 2964 | if (this.actions != null) { |
| 2965 | proto.write(NotificationProto.ACTION_LENGTH, this.actions.length); |
| 2966 | } |
| 2967 | if (this.visibility >= VISIBILITY_SECRET && this.visibility <= VISIBILITY_PUBLIC) { |
| 2968 | proto.write(NotificationProto.VISIBILITY, this.visibility); |
| 2969 | } |
| 2970 | if (publicVersion != null) { |
| 2971 | publicVersion.writeToProto(proto, NotificationProto.PUBLIC_VERSION); |
| 2972 | } |
| 2973 | proto.end(token); |
| 2974 | } |
| 2975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | @Override |
| 2977 | public String toString() { |
| 2978 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2979 | sb.append("Notification(channel="); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2980 | sb.append(getChannelId()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2981 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2982 | sb.append(priority); |
| 2983 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2984 | if (contentView != null) { |
| 2985 | sb.append(contentView.getPackage()); |
| 2986 | sb.append("/0x"); |
| 2987 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2988 | } else { |
| 2989 | sb.append("null"); |
| 2990 | } |
| 2991 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2992 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2993 | sb.append("default"); |
| 2994 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | int N = this.vibrate.length-1; |
| 2996 | sb.append("["); |
| 2997 | for (int i=0; i<N; i++) { |
| 2998 | sb.append(this.vibrate[i]); |
| 2999 | sb.append(','); |
| 3000 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 3001 | if (N != -1) { |
| 3002 | sb.append(this.vibrate[N]); |
| 3003 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3004 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3005 | } else { |
| 3006 | sb.append("null"); |
| 3007 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3008 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 3009 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3010 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 3011 | } else if (this.sound != null) { |
| 3012 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3013 | } else { |
| 3014 | sb.append("null"); |
| 3015 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 3016 | if (this.tickerText != null) { |
| 3017 | sb.append(" tick"); |
| 3018 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3019 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3020 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3021 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 3022 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3023 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3024 | if (this.category != null) { |
| 3025 | sb.append(" category="); |
| 3026 | sb.append(this.category); |
| 3027 | } |
| 3028 | if (this.mGroupKey != null) { |
| 3029 | sb.append(" groupKey="); |
| 3030 | sb.append(this.mGroupKey); |
| 3031 | } |
| 3032 | if (this.mSortKey != null) { |
| 3033 | sb.append(" sortKey="); |
| 3034 | sb.append(this.mSortKey); |
| 3035 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3036 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 3037 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3038 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 3039 | } |
| 3040 | sb.append(" vis="); |
| 3041 | sb.append(visibilityToString(this.visibility)); |
| 3042 | if (this.publicVersion != null) { |
| 3043 | sb.append(" publicVersion="); |
| 3044 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3045 | } |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 3046 | if (this.mLocusId != null) { |
| 3047 | sb.append(" locusId="); |
| 3048 | sb.append(this.mLocusId); // LocusId.toString() is PII safe. |
| 3049 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3050 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3051 | return sb.toString(); |
| 3052 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3053 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 3054 | /** |
| 3055 | * {@hide} |
| 3056 | */ |
| 3057 | public static String visibilityToString(int vis) { |
| 3058 | switch (vis) { |
| 3059 | case VISIBILITY_PRIVATE: |
| 3060 | return "PRIVATE"; |
| 3061 | case VISIBILITY_PUBLIC: |
| 3062 | return "PUBLIC"; |
| 3063 | case VISIBILITY_SECRET: |
| 3064 | return "SECRET"; |
| 3065 | default: |
| 3066 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 3067 | } |
| 3068 | } |
| 3069 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3070 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 3071 | * {@hide} |
| 3072 | */ |
| 3073 | public static String priorityToString(@Priority int pri) { |
| 3074 | switch (pri) { |
| 3075 | case PRIORITY_MIN: |
| 3076 | return "MIN"; |
| 3077 | case PRIORITY_LOW: |
| 3078 | return "LOW"; |
| 3079 | case PRIORITY_DEFAULT: |
| 3080 | return "DEFAULT"; |
| 3081 | case PRIORITY_HIGH: |
| 3082 | return "HIGH"; |
| 3083 | case PRIORITY_MAX: |
| 3084 | return "MAX"; |
| 3085 | default: |
| 3086 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 3087 | } |
| 3088 | } |
| 3089 | |
Julia Reynolds | 6ad0aec | 2017-07-05 08:47:03 -0400 | [diff] [blame] | 3090 | /** |
| 3091 | * @hide |
| 3092 | */ |
| 3093 | public boolean hasCompletedProgress() { |
| 3094 | // not a progress notification; can't be complete |
| 3095 | if (!extras.containsKey(EXTRA_PROGRESS) |
| 3096 | || !extras.containsKey(EXTRA_PROGRESS_MAX)) { |
| 3097 | return false; |
| 3098 | } |
| 3099 | // many apps use max 0 for 'indeterminate'; not complete |
| 3100 | if (extras.getInt(EXTRA_PROGRESS_MAX) == 0) { |
| 3101 | return false; |
| 3102 | } |
| 3103 | return extras.getInt(EXTRA_PROGRESS) == extras.getInt(EXTRA_PROGRESS_MAX); |
| 3104 | } |
| 3105 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3106 | /** @removed */ |
| 3107 | @Deprecated |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 3108 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3109 | return mChannelId; |
| 3110 | } |
| 3111 | |
| 3112 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3113 | * Returns the id of the channel this notification posts to. |
| 3114 | */ |
| 3115 | public String getChannelId() { |
| 3116 | return mChannelId; |
| 3117 | } |
| 3118 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3119 | /** @removed */ |
| 3120 | @Deprecated |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3121 | public long getTimeout() { |
| 3122 | return mTimeout; |
| 3123 | } |
| 3124 | |
| 3125 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3126 | * Returns the duration from posting after which this notification should be canceled by the |
| 3127 | * system, if it's not canceled already. |
| 3128 | */ |
| 3129 | public long getTimeoutAfter() { |
| 3130 | return mTimeout; |
| 3131 | } |
| 3132 | |
| 3133 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3134 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 3135 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 3136 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 3137 | */ |
| 3138 | public int getBadgeIconType() { |
| 3139 | return mBadgeIcon; |
| 3140 | } |
| 3141 | |
| 3142 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3143 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3144 | * |
| 3145 | * <p>Used by some Launchers that display notification content to hide shortcuts that duplicate |
| 3146 | * notifications. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3147 | */ |
| 3148 | public String getShortcutId() { |
| 3149 | return mShortcutId; |
| 3150 | } |
| 3151 | |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 3152 | /** |
| 3153 | * Gets the {@link LocusId} associated with this notification. |
| 3154 | * |
| 3155 | * <p>Used by the device's intelligence services to correlate objects (such as |
| 3156 | * {@link ShortcutInfo} and {@link ContentCaptureContext}) that are correlated. |
| 3157 | */ |
| 3158 | @Nullable |
| 3159 | public LocusId getLocusId() { |
| 3160 | return mLocusId; |
| 3161 | } |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3162 | |
| 3163 | /** |
| 3164 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 3165 | */ |
| 3166 | public CharSequence getSettingsText() { |
| 3167 | return mSettingsText; |
| 3168 | } |
| 3169 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3170 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3171 | * Returns which type of notifications in a group are responsible for audibly alerting the |
| 3172 | * user. See {@link #GROUP_ALERT_ALL}, {@link #GROUP_ALERT_CHILDREN}, |
| 3173 | * {@link #GROUP_ALERT_SUMMARY}. |
| 3174 | */ |
| 3175 | public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 3176 | return mGroupAlertBehavior; |
| 3177 | } |
| 3178 | |
| 3179 | /** |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3180 | * Returns the bubble metadata that will be used to display app content in a floating window |
| 3181 | * over the existing foreground activity. |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3182 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 3183 | @Nullable |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3184 | public BubbleMetadata getBubbleMetadata() { |
| 3185 | return mBubbleMetadata; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3186 | } |
| 3187 | |
Gustav Sennton | 79ebf4b | 2018-12-19 10:31:51 +0000 | [diff] [blame] | 3188 | /** |
| 3189 | * Returns whether the platform is allowed (by the app developer) to generate contextual actions |
| 3190 | * for this notification. |
| 3191 | */ |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 3192 | public boolean getAllowSystemGeneratedContextualActions() { |
| 3193 | return mAllowSystemGeneratedContextualActions; |
| 3194 | } |
| 3195 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3196 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3197 | * The small icon representing this notification in the status bar and content view. |
| 3198 | * |
| 3199 | * @return the small icon representing this notification. |
| 3200 | * |
| 3201 | * @see Builder#getSmallIcon() |
| 3202 | * @see Builder#setSmallIcon(Icon) |
| 3203 | */ |
| 3204 | public Icon getSmallIcon() { |
| 3205 | return mSmallIcon; |
| 3206 | } |
| 3207 | |
| 3208 | /** |
| 3209 | * Used when notifying to clean up legacy small icons. |
| 3210 | * @hide |
| 3211 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3212 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3213 | public void setSmallIcon(Icon icon) { |
| 3214 | mSmallIcon = icon; |
| 3215 | } |
| 3216 | |
| 3217 | /** |
| 3218 | * The large icon shown in this notification's content view. |
| 3219 | * @see Builder#getLargeIcon() |
| 3220 | * @see Builder#setLargeIcon(Icon) |
| 3221 | */ |
| 3222 | public Icon getLargeIcon() { |
| 3223 | return mLargeIcon; |
| 3224 | } |
| 3225 | |
| 3226 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3227 | * @hide |
| 3228 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3229 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3230 | public boolean isGroupSummary() { |
| 3231 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 3232 | } |
| 3233 | |
| 3234 | /** |
| 3235 | * @hide |
| 3236 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3237 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3238 | public boolean isGroupChild() { |
| 3239 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 3240 | } |
| 3241 | |
| 3242 | /** |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3243 | * @hide |
| 3244 | */ |
| 3245 | public boolean suppressAlertingDueToGrouping() { |
| 3246 | if (isGroupSummary() |
| 3247 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { |
| 3248 | return true; |
| 3249 | } else if (isGroupChild() |
| 3250 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { |
| 3251 | return true; |
| 3252 | } |
| 3253 | return false; |
| 3254 | } |
| 3255 | |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 3256 | |
| 3257 | /** |
| 3258 | * Finds and returns a remote input and its corresponding action. |
| 3259 | * |
| 3260 | * @param requiresFreeform requires the remoteinput to allow freeform or not. |
| 3261 | * @return the result pair, {@code null} if no result is found. |
| 3262 | * |
| 3263 | * @hide |
| 3264 | */ |
| 3265 | @Nullable |
| 3266 | public Pair<RemoteInput, Action> findRemoteInputActionPair(boolean requiresFreeform) { |
| 3267 | if (actions == null) { |
| 3268 | return null; |
| 3269 | } |
| 3270 | for (Notification.Action action : actions) { |
| 3271 | if (action.getRemoteInputs() == null) { |
| 3272 | continue; |
| 3273 | } |
| 3274 | RemoteInput resultRemoteInput = null; |
| 3275 | for (RemoteInput remoteInput : action.getRemoteInputs()) { |
| 3276 | if (remoteInput.getAllowFreeFormInput() || !requiresFreeform) { |
| 3277 | resultRemoteInput = remoteInput; |
| 3278 | } |
| 3279 | } |
| 3280 | if (resultRemoteInput != null) { |
| 3281 | return Pair.create(resultRemoteInput, action); |
| 3282 | } |
| 3283 | } |
| 3284 | return null; |
| 3285 | } |
| 3286 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3287 | /** |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 3288 | * 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] | 3289 | * |
| 3290 | * @hide |
| 3291 | */ |
| 3292 | public List<Notification.Action> getContextualActions() { |
| 3293 | if (actions == null) return Collections.emptyList(); |
| 3294 | |
| 3295 | List<Notification.Action> contextualActions = new ArrayList<>(); |
| 3296 | for (Notification.Action action : actions) { |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 3297 | if (action.isContextual()) { |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 3298 | contextualActions.add(action); |
| 3299 | } |
| 3300 | } |
| 3301 | return contextualActions; |
| 3302 | } |
| 3303 | |
| 3304 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3305 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3306 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3307 | * 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] | 3308 | * content views using the platform's notification layout template. If your app supports |
| 3309 | * versions of Android as old as API level 4, you can instead use |
| 3310 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 3311 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 3312 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3313 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3314 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3315 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3316 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3317 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3318 | * .setContentTitle("New mail from " + sender.toString()) |
| 3319 | * .setContentText(subject) |
| 3320 | * .setSmallIcon(R.drawable.new_mail) |
| 3321 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3322 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3323 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3324 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3325 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3326 | /** |
| 3327 | * @hide |
| 3328 | */ |
| 3329 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 3330 | "android.rebuild.contentViewActionCount"; |
| 3331 | /** |
| 3332 | * @hide |
| 3333 | */ |
| 3334 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 3335 | = "android.rebuild.bigViewActionCount"; |
| 3336 | /** |
| 3337 | * @hide |
| 3338 | */ |
| 3339 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 3340 | = "android.rebuild.hudViewActionCount"; |
| 3341 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 3342 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 3343 | SystemProperties.getBoolean("notifications.only_title", true); |
| 3344 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3345 | /** |
| 3346 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3347 | * secondary text color when the background is light. |
| 3348 | */ |
| 3349 | private static final int LIGHTNESS_TEXT_DIFFERENCE_LIGHT = 20; |
| 3350 | |
| 3351 | /** |
| 3352 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3353 | * secondary text color when the background is dark. |
| 3354 | * A bit less then the above value, since it looks better on dark backgrounds. |
| 3355 | */ |
| 3356 | private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10; |
| 3357 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3358 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3359 | private Notification mN; |
| 3360 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3361 | private Style mStyle; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3362 | @UnsupportedAppUsage |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3363 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3364 | private ArrayList<Person> mPersonList = new ArrayList<>(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3365 | private ContrastColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3366 | private boolean mIsLegacy; |
| 3367 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3368 | |
| 3369 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3370 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 3371 | */ |
| 3372 | private int mCachedContrastColor = COLOR_INVALID; |
| 3373 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3374 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3375 | * Caches a ambient version of {@link #mCachedAmbientColorIsFor}. |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3376 | */ |
| 3377 | private int mCachedAmbientColor = COLOR_INVALID; |
| 3378 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3379 | /** |
| 3380 | * A neutral color color that can be used for icons. |
| 3381 | */ |
| 3382 | private int mNeutralColor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3383 | |
| 3384 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3385 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 3386 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 3387 | */ |
| 3388 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3389 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 3390 | private int mPrimaryTextColor = COLOR_INVALID; |
| 3391 | private int mSecondaryTextColor = COLOR_INVALID; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3392 | private int mBackgroundColor = COLOR_INVALID; |
| 3393 | private int mForegroundColor = COLOR_INVALID; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 3394 | /** |
| 3395 | * A temporary location where actions are stored. If != null the view originally has action |
| 3396 | * but doesn't have any for this inflation. |
| 3397 | */ |
| 3398 | private ArrayList<Action> mOriginalActions; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 3399 | private boolean mRebuildStyledRemoteViews; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3400 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3401 | private boolean mTintActionButtons; |
| 3402 | private boolean mInNightMode; |
| 3403 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3404 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3405 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3406 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3407 | * @param context |
| 3408 | * A {@link Context} that will be used by the Builder to construct the |
| 3409 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 3410 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3411 | * @param channelId |
| 3412 | * The constructed Notification will be posted on this |
| 3413 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 3414 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3415 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3416 | public Builder(Context context, String channelId) { |
| 3417 | this(context, (Notification) null); |
| 3418 | mN.mChannelId = channelId; |
| 3419 | } |
| 3420 | |
| 3421 | /** |
| 3422 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 3423 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 3424 | */ |
| 3425 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3426 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3427 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3428 | } |
| 3429 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3430 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3431 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3432 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3433 | public Builder(Context context, Notification toAdopt) { |
| 3434 | mContext = context; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3435 | Resources res = mContext.getResources(); |
| 3436 | mTintActionButtons = res.getBoolean(R.bool.config_tintNotificationActionButtons); |
| 3437 | |
| 3438 | if (res.getBoolean(R.bool.config_enableNightMode)) { |
| 3439 | Configuration currentConfig = res.getConfiguration(); |
| 3440 | mInNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 3441 | == Configuration.UI_MODE_NIGHT_YES; |
| 3442 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3443 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3444 | if (toAdopt == null) { |
| 3445 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3446 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 3447 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 3448 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3449 | mN.priority = PRIORITY_DEFAULT; |
| 3450 | mN.visibility = VISIBILITY_PRIVATE; |
| 3451 | } else { |
| 3452 | mN = toAdopt; |
| 3453 | if (mN.actions != null) { |
| 3454 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3455 | } |
| 3456 | |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3457 | if (mN.extras.containsKey(EXTRA_PEOPLE_LIST)) { |
| 3458 | ArrayList<Person> people = mN.extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 3459 | mPersonList.addAll(people); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3460 | } |
| 3461 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 3462 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 3463 | setSmallIcon(mN.icon); |
| 3464 | } |
| 3465 | |
| 3466 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 3467 | setLargeIcon(mN.largeIcon); |
| 3468 | } |
| 3469 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3470 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 3471 | if (!TextUtils.isEmpty(templateClass)) { |
| 3472 | final Class<? extends Style> styleClass |
| 3473 | = getNotificationStyleClass(templateClass); |
| 3474 | if (styleClass == null) { |
| 3475 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 3476 | } else { |
| 3477 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3478 | final Constructor<? extends Style> ctor = |
| 3479 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3480 | ctor.setAccessible(true); |
| 3481 | final Style style = ctor.newInstance(); |
| 3482 | style.restoreFromExtras(mN.extras); |
| 3483 | |
| 3484 | if (style != null) { |
| 3485 | setStyle(style); |
| 3486 | } |
| 3487 | } catch (Throwable t) { |
| 3488 | Log.e(TAG, "Could not create Style", t); |
| 3489 | } |
| 3490 | } |
| 3491 | } |
| 3492 | |
| 3493 | } |
| 3494 | } |
| 3495 | |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3496 | private ContrastColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3497 | if (mColorUtil == null) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3498 | mColorUtil = ContrastColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3499 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3500 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3504 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 3505 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 3506 | * the shortcut. |
| 3507 | * |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3508 | * This field will be ignored by Launchers that don't support badging, don't show |
| 3509 | * notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3510 | * |
| 3511 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 3512 | * supersedes |
| 3513 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3514 | @NonNull |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3515 | public Builder setShortcutId(String shortcutId) { |
| 3516 | mN.mShortcutId = shortcutId; |
| 3517 | return this; |
| 3518 | } |
| 3519 | |
| 3520 | /** |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 3521 | * Sets the {@link LocusId} associated with this notification. |
| 3522 | * |
| 3523 | * <p>This method should be called when the {@link LocusId} is used in other places (such |
| 3524 | * as {@link ShortcutInfo} and {@link ContentCaptureContext}) so the device's intelligence |
| 3525 | * services can correlate them. |
| 3526 | */ |
| 3527 | @NonNull |
| 3528 | public Builder setLocusId(@Nullable LocusId locusId) { |
| 3529 | mN.mLocusId = locusId; |
| 3530 | return this; |
| 3531 | } |
| 3532 | |
| 3533 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3534 | * Sets which icon to display as a badge for this notification. |
| 3535 | * |
| 3536 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 3537 | * {@link #BADGE_ICON_LARGE}. |
| 3538 | * |
| 3539 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 3540 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3541 | @NonNull |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 3542 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3543 | mN.mBadgeIcon = icon; |
| 3544 | return this; |
| 3545 | } |
| 3546 | |
| 3547 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3548 | * Sets the group alert behavior for this notification. Use this method to mute this |
| 3549 | * notification if alerts for this notification's group should be handled by a different |
| 3550 | * notification. This is only applicable for notifications that belong to a |
Julia Reynolds | 399d9bf | 2017-08-11 12:52:14 -0400 | [diff] [blame] | 3551 | * {@link #setGroup(String) group}. This must be called on all notifications you want to |
| 3552 | * mute. For example, if you want only the summary of your group to make noise, all |
| 3553 | * 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] | 3554 | * |
| 3555 | * <p> The default value is {@link #GROUP_ALERT_ALL}.</p> |
| 3556 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3557 | @NonNull |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3558 | public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 3559 | mN.mGroupAlertBehavior = groupAlertBehavior; |
| 3560 | return this; |
| 3561 | } |
| 3562 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3563 | /** |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3564 | * Sets the {@link BubbleMetadata} that will be used to display app content in a floating |
| 3565 | * window over the existing foreground activity. |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3566 | * |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3567 | * <p>This data will be ignored unless the notification is posted to a channel that |
| 3568 | * allows {@link NotificationChannel#canBubble() bubbles}.</p> |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3569 | * |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3570 | * <b>Notifications with a valid and allowed bubble metadata will display in collapsed state |
| 3571 | * outside of the notification shade on unlocked devices. When a user interacts with the |
| 3572 | * collapsed state, the bubble intent will be invoked and displayed.</b> |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3573 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3574 | @NonNull |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 3575 | public Builder setBubbleMetadata(@Nullable BubbleMetadata data) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3576 | mN.mBubbleMetadata = data; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3577 | return this; |
| 3578 | } |
| 3579 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3580 | /** @removed */ |
| 3581 | @Deprecated |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3582 | public Builder setChannel(String channelId) { |
| 3583 | mN.mChannelId = channelId; |
| 3584 | return this; |
| 3585 | } |
| 3586 | |
| 3587 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3588 | * Specifies the channel the notification should be delivered on. |
| 3589 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3590 | @NonNull |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3591 | public Builder setChannelId(String channelId) { |
| 3592 | mN.mChannelId = channelId; |
| 3593 | return this; |
| 3594 | } |
| 3595 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3596 | /** @removed */ |
| 3597 | @Deprecated |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 3598 | public Builder setTimeout(long durationMs) { |
| 3599 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3600 | return this; |
| 3601 | } |
| 3602 | |
| 3603 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3604 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 3605 | * if it is not already canceled. |
| 3606 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3607 | @NonNull |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3608 | public Builder setTimeoutAfter(long durationMs) { |
| 3609 | mN.mTimeout = durationMs; |
| 3610 | return this; |
| 3611 | } |
| 3612 | |
| 3613 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3614 | * 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] | 3615 | * |
| 3616 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 3617 | * shown anymore by default and must be opted into by using |
| 3618 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3619 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3620 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3621 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3622 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3623 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3624 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3625 | return this; |
| 3626 | } |
| 3627 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3628 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 3629 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3630 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3631 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 3632 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3633 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3634 | @NonNull |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3635 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3636 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3637 | return this; |
| 3638 | } |
| 3639 | |
| 3640 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3641 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3642 | * |
| 3643 | * 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] | 3644 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3645 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3646 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 3647 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3648 | * 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] | 3649 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3650 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3651 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3652 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3653 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3654 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3655 | @NonNull |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3656 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3657 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3658 | return this; |
| 3659 | } |
| 3660 | |
| 3661 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3662 | * Sets the Chronometer to count down instead of counting up. |
| 3663 | * |
| 3664 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 3665 | * If it isn't set the chronometer will count up. |
| 3666 | * |
| 3667 | * @see #setUsesChronometer(boolean) |
| 3668 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3669 | @NonNull |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3670 | public Builder setChronometerCountDown(boolean countDown) { |
| 3671 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3672 | return this; |
| 3673 | } |
| 3674 | |
| 3675 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3676 | * Set the small icon resource, which will be used to represent the notification in the |
| 3677 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3678 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3679 | |
| 3680 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 3681 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 3682 | * icon will be moved to the right-hand side. |
| 3683 | * |
| 3684 | |
| 3685 | * @param icon |
| 3686 | * A resource ID in the application's package of the drawable to use. |
| 3687 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3688 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3689 | @NonNull |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3690 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3691 | return setSmallIcon(icon != 0 |
| 3692 | ? Icon.createWithResource(mContext, icon) |
| 3693 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3694 | } |
| 3695 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3696 | /** |
| 3697 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 3698 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 3699 | * LevelListDrawable}. |
| 3700 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3701 | * @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] | 3702 | * @param level The level to use for the icon. |
| 3703 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3704 | * @see Notification#icon |
| 3705 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3706 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3707 | @NonNull |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3708 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3709 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3710 | return setSmallIcon(icon); |
| 3711 | } |
| 3712 | |
| 3713 | /** |
| 3714 | * 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] | 3715 | * status bar and content view (unless overridden there by a |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3716 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 3717 | * |
| 3718 | * @param icon An Icon object to use. |
| 3719 | * @see Notification#icon |
| 3720 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3721 | @NonNull |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3722 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3723 | mN.setSmallIcon(icon); |
| 3724 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 3725 | mN.icon = icon.getResId(); |
| 3726 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3727 | return this; |
| 3728 | } |
| 3729 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3730 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3731 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3732 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3733 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3734 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3735 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3736 | return this; |
| 3737 | } |
| 3738 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3739 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3740 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3741 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3742 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3743 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3744 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3745 | return this; |
| 3746 | } |
| 3747 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3748 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3749 | * This provides some additional information that is displayed in the notification. No |
| 3750 | * guarantees are given where exactly it is displayed. |
| 3751 | * |
| 3752 | * <p>This information should only be provided if it provides an essential |
| 3753 | * benefit to the understanding of the notification. The more text you provide the |
| 3754 | * less readable it becomes. For example, an email client should only provide the account |
| 3755 | * name here if more than one email account has been added.</p> |
| 3756 | * |
| 3757 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 3758 | * notification header area. |
| 3759 | * |
| 3760 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 3761 | * this will be shown in the third line of text in the platform notification template. |
| 3762 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 3763 | * same time on those versions; they occupy the same place. |
| 3764 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3765 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3766 | @NonNull |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3767 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3768 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3769 | return this; |
| 3770 | } |
| 3771 | |
| 3772 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3773 | * Provides text that will appear as a link to your application's settings. |
| 3774 | * |
| 3775 | * <p>This text does not appear within notification {@link Style templates} but may |
| 3776 | * appear when the user uses an affordance to learn more about the notification. |
| 3777 | * Additionally, this text will not appear unless you provide a valid link target by |
| 3778 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 3779 | * |
| 3780 | * <p>This text is meant to be concise description about what the user can customize |
| 3781 | * when they click on this link. The recommended maximum length is 40 characters. |
| 3782 | * @param text |
| 3783 | * @return |
| 3784 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3785 | @NonNull |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3786 | public Builder setSettingsText(CharSequence text) { |
| 3787 | mN.mSettingsText = safeCharSequence(text); |
| 3788 | return this; |
| 3789 | } |
| 3790 | |
| 3791 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3792 | * Set the remote input history. |
| 3793 | * |
| 3794 | * This should be set to the most recent inputs that have been sent |
| 3795 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 3796 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 3797 | * |
| 3798 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 3799 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 3800 | * and how much of each individual input is shown. |
| 3801 | * |
| 3802 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 3803 | * with a {@code RemoteInput}.</p> |
| 3804 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3805 | @NonNull |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3806 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 3807 | if (text == null) { |
| 3808 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 3809 | } else { |
| 3810 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 3811 | CharSequence[] safe = new CharSequence[N]; |
| 3812 | for (int i = 0; i < N; i++) { |
| 3813 | safe[i] = safeCharSequence(text[i]); |
| 3814 | } |
| 3815 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 3816 | } |
| 3817 | return this; |
| 3818 | } |
| 3819 | |
| 3820 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 3821 | * Sets whether remote history entries view should have a spinner. |
| 3822 | * @hide |
| 3823 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3824 | @NonNull |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 3825 | public Builder setShowRemoteInputSpinner(boolean showSpinner) { |
| 3826 | mN.extras.putBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER, showSpinner); |
| 3827 | return this; |
| 3828 | } |
| 3829 | |
| 3830 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 3831 | * Sets whether smart reply buttons should be hidden. |
| 3832 | * @hide |
| 3833 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3834 | @NonNull |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 3835 | public Builder setHideSmartReplies(boolean hideSmartReplies) { |
| 3836 | mN.extras.putBoolean(EXTRA_HIDE_SMART_REPLIES, hideSmartReplies); |
| 3837 | return this; |
| 3838 | } |
| 3839 | |
| 3840 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3841 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 3842 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3843 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3844 | @NonNull |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3845 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3846 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3847 | return this; |
| 3848 | } |
| 3849 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3850 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3851 | * A small piece of additional information pertaining to this notification. |
| 3852 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3853 | * The platform template will draw this on the last line of the notification, at the far |
| 3854 | * 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] | 3855 | * |
| 3856 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 3857 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 3858 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3859 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3860 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3861 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3862 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3863 | return this; |
| 3864 | } |
| 3865 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3866 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3867 | * Set the progress this notification represents. |
| 3868 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3869 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3870 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3871 | @NonNull |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3872 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3873 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3874 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3875 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3876 | return this; |
| 3877 | } |
| 3878 | |
| 3879 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3880 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3881 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3882 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3883 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3884 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3885 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3886 | return setCustomContentView(views); |
| 3887 | } |
| 3888 | |
| 3889 | /** |
| 3890 | * Supply custom RemoteViews to use instead of the platform template. |
| 3891 | * |
| 3892 | * This will override the layout that would otherwise be constructed by this Builder |
| 3893 | * object. |
| 3894 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3895 | @NonNull |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3896 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3897 | mN.contentView = contentView; |
| 3898 | return this; |
| 3899 | } |
| 3900 | |
| 3901 | /** |
| 3902 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3903 | * |
| 3904 | * This will override the expanded layout that would otherwise be constructed by this |
| 3905 | * Builder object. |
| 3906 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3907 | @NonNull |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3908 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3909 | mN.bigContentView = contentView; |
| 3910 | return this; |
| 3911 | } |
| 3912 | |
| 3913 | /** |
| 3914 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3915 | * |
| 3916 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3917 | * Builder object. |
| 3918 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3919 | @NonNull |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3920 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3921 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3922 | return this; |
| 3923 | } |
| 3924 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3925 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3926 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3927 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3928 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3929 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3930 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3931 | * 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] | 3932 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3933 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3934 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3935 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3936 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3937 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3938 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3939 | return this; |
| 3940 | } |
| 3941 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3942 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3943 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3944 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3945 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3946 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3947 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3948 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3949 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3950 | return this; |
| 3951 | } |
| 3952 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3953 | /** |
| 3954 | * An intent to launch instead of posting the notification to the status bar. |
| 3955 | * Only for use with extremely high-priority notifications demanding the user's |
| 3956 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3957 | * alarm clock that the user has explicitly set to a particular time. |
| 3958 | * If this facility is used for something else, please give the user an option |
| 3959 | * to turn it off and use a normal notification, as this can be extremely |
| 3960 | * disruptive. |
| 3961 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3962 | * <p> |
| 3963 | * The system UI may choose to display a heads-up notification, instead of |
| 3964 | * launching this intent, while the user is using the device. |
| 3965 | * </p> |
Julia Reynolds | 47fd15f | 2018-11-28 10:16:00 -0500 | [diff] [blame] | 3966 | * <p>Apps targeting {@link Build.VERSION_CODES#Q} and above will have to request |
| 3967 | * a permission ({@link android.Manifest.permission#USE_FULL_SCREEN_INTENT}) in order to |
| 3968 | * use full screen intents.</p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3969 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3970 | * @param intent The pending intent to launch. |
| 3971 | * @param highPriority Passing true will cause this notification to be sent |
| 3972 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3973 | * |
| 3974 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3975 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3976 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3977 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3978 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3979 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3980 | return this; |
| 3981 | } |
| 3982 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3983 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3984 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3985 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3986 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3987 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3988 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3989 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3990 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3991 | return this; |
| 3992 | } |
| 3993 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3994 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3995 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3996 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3997 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3998 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3999 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4000 | setTicker(tickerText); |
| 4001 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4002 | return this; |
| 4003 | } |
| 4004 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4005 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4006 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4007 | * |
| 4008 | * 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] | 4009 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 4010 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4011 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4012 | @NonNull |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4013 | public Builder setLargeIcon(Bitmap b) { |
| 4014 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 4015 | } |
| 4016 | |
| 4017 | /** |
| 4018 | * Add a large icon to the notification content view. |
| 4019 | * |
| 4020 | * In the platform template, this image will be shown on the left of the notification view |
| 4021 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 4022 | * badge atop the large icon). |
| 4023 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4024 | @NonNull |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4025 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4026 | mN.mLargeIcon = icon; |
| 4027 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4028 | return this; |
| 4029 | } |
| 4030 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4031 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4032 | * Set the sound to play. |
| 4033 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 4034 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 4035 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4036 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4037 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4038 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4039 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 4040 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4041 | mN.sound = sound; |
| 4042 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 4043 | return this; |
| 4044 | } |
| 4045 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4046 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4047 | * 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] | 4048 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4049 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 4050 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4051 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4052 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 4053 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4054 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 4055 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4056 | mN.sound = sound; |
| 4057 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4058 | return this; |
| 4059 | } |
| 4060 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4061 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 4062 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 4063 | * use during playback. |
| 4064 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4065 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 4066 | * @see Notification#sound |
| 4067 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4068 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 4069 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4070 | mN.sound = sound; |
| 4071 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 4072 | return this; |
| 4073 | } |
| 4074 | |
| 4075 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4076 | * Set the vibration pattern to use. |
| 4077 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4078 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 4079 | * <code>pattern</code> parameter. |
| 4080 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 4081 | * <p> |
| 4082 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 4083 | * </p> |
| 4084 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4085 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4086 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4087 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4088 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4089 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4090 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4091 | return this; |
| 4092 | } |
| 4093 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4094 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4095 | * Set the desired color for the indicator LED on the device, as well as the |
| 4096 | * blink duty cycle (specified in milliseconds). |
| 4097 | * |
| 4098 | |
| 4099 | * Not all devices will honor all (or even any) of these values. |
| 4100 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 4101 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4102 | * @see Notification#ledARGB |
| 4103 | * @see Notification#ledOnMS |
| 4104 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4105 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4106 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4107 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4108 | mN.ledARGB = argb; |
| 4109 | mN.ledOnMS = onMs; |
| 4110 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4111 | if (onMs != 0 || offMs != 0) { |
| 4112 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 4113 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4114 | return this; |
| 4115 | } |
| 4116 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4117 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4118 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4119 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4120 | |
| 4121 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 4122 | * must take care of canceling them. |
| 4123 | * |
| 4124 | |
| 4125 | * They are typically used to indicate a background task that the user is actively engaged |
| 4126 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 4127 | * (e.g., a file download, sync operation, active network connection). |
| 4128 | * |
| 4129 | |
| 4130 | * @see Notification#FLAG_ONGOING_EVENT |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4131 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4132 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4133 | public Builder setOngoing(boolean ongoing) { |
| 4134 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 4135 | return this; |
| 4136 | } |
| 4137 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4138 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4139 | * Set whether this notification should be colorized. When set, the color set with |
| 4140 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 4141 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4142 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 4143 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4144 | * <p> |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 4145 | * For most styles, the coloring will only be applied if the notification is for a |
| 4146 | * foreground service notification. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4147 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 4148 | * that have a media session attached there is no such requirement. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4149 | * |
Aurimas Liutikas | 7f69533 | 2018-05-31 21:07:32 -0700 | [diff] [blame] | 4150 | * @see #setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4151 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4152 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4153 | @NonNull |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4154 | public Builder setColorized(boolean colorize) { |
| 4155 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 4156 | return this; |
| 4157 | } |
| 4158 | |
| 4159 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4160 | * Set this flag if you would only like the sound, vibrate |
| 4161 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4162 | * |
| 4163 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4164 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4165 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4166 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 4167 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 4168 | return this; |
| 4169 | } |
| 4170 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4171 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4172 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4173 | * |
| 4174 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4175 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4176 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4177 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 4178 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4179 | return this; |
| 4180 | } |
| 4181 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4182 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 4183 | * Set whether or not this notification should not bridge to other devices. |
| 4184 | * |
| 4185 | * <p>Some notifications can be bridged to other devices for remote display. |
| 4186 | * This hint can be set to recommend this notification not be bridged. |
| 4187 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4188 | @NonNull |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 4189 | public Builder setLocalOnly(boolean localOnly) { |
| 4190 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 4191 | return this; |
| 4192 | } |
| 4193 | |
| 4194 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4195 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4196 | * <p> |
| 4197 | * The value should be one or more of the following fields combined with |
| 4198 | * bitwise-or: |
| 4199 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 4200 | * <p> |
| 4201 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4202 | * |
| 4203 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 4204 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4205 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4206 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4207 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4208 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4209 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4210 | return this; |
| 4211 | } |
| 4212 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4213 | /** |
| 4214 | * Set the priority of this notification. |
| 4215 | * |
| 4216 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4217 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4218 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4219 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4220 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4221 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4222 | return this; |
| 4223 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4224 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4225 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4226 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4227 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4228 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4229 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4230 | @NonNull |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4231 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4232 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4233 | return this; |
| 4234 | } |
| 4235 | |
| 4236 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4237 | * Add a person that is relevant to this notification. |
| 4238 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4239 | * <P> |
| 4240 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 4241 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4242 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4243 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4244 | * </P> |
| 4245 | * |
| 4246 | * <P> |
| 4247 | * The person should be specified by the {@code String} representation of a |
| 4248 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 4249 | * </P> |
| 4250 | * |
| 4251 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 4252 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 4253 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 4254 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4255 | * It is also possible to provide a URI with the schema {@code name:} in order to uniquely |
| 4256 | * identify a person without an entry in the contacts database. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4257 | * </P> |
| 4258 | * |
| 4259 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4260 | * @see Notification#EXTRA_PEOPLE |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4261 | * @deprecated use {@link #addPerson(Person)} |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4262 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4263 | public Builder addPerson(String uri) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 4264 | addPerson(new Person.Builder().setUri(uri).build()); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4265 | return this; |
| 4266 | } |
| 4267 | |
| 4268 | /** |
| 4269 | * Add a person that is relevant to this notification. |
| 4270 | * |
| 4271 | * <P> |
| 4272 | * Depending on user preferences, this annotation may allow the notification to pass |
| 4273 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4274 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4275 | * appear more prominently in the user interface. |
| 4276 | * </P> |
| 4277 | * |
| 4278 | * <P> |
| 4279 | * A person should usually contain a uri in order to benefit from the ranking boost. |
| 4280 | * However, even if no uri is provided, it's beneficial to provide other people in the |
| 4281 | * notification, such that listeners and voice only devices can announce and handle them |
| 4282 | * properly. |
| 4283 | * </P> |
| 4284 | * |
| 4285 | * @param person the person to add. |
| 4286 | * @see Notification#EXTRA_PEOPLE_LIST |
| 4287 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4288 | @NonNull |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4289 | public Builder addPerson(Person person) { |
| 4290 | mPersonList.add(person); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4291 | return this; |
| 4292 | } |
| 4293 | |
| 4294 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4295 | * Set this notification to be part of a group of notifications sharing the same key. |
| 4296 | * Grouped notifications may display in a cluster or stack on devices which |
| 4297 | * support such rendering. |
| 4298 | * |
| 4299 | * <p>To make this notification the summary for its group, also call |
| 4300 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 4301 | * {@link #setSortKey}. |
| 4302 | * @param groupKey The group key of the group. |
| 4303 | * @return this object for method chaining |
| 4304 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4305 | @NonNull |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4306 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4307 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4308 | return this; |
| 4309 | } |
| 4310 | |
| 4311 | /** |
| 4312 | * Set this notification to be the group summary for a group of notifications. |
| 4313 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4314 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 4315 | * 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] | 4316 | * @param isGroupSummary Whether this notification should be a group summary. |
| 4317 | * @return this object for method chaining |
| 4318 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4319 | @NonNull |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4320 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 4321 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 4322 | return this; |
| 4323 | } |
| 4324 | |
| 4325 | /** |
| 4326 | * Set a sort key that orders this notification among other notifications from the |
| 4327 | * same package. This can be useful if an external sort was already applied and an app |
| 4328 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 4329 | * value, although providing different priorities in addition to providing sort key may |
| 4330 | * cause this value to be ignored. |
| 4331 | * |
| 4332 | * <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] | 4333 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4334 | * |
| 4335 | * @see String#compareTo(String) |
| 4336 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4337 | @NonNull |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4338 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4339 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4340 | return this; |
| 4341 | } |
| 4342 | |
| 4343 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4344 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4345 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4346 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 4347 | * |
| 4348 | * @see Notification#extras |
| 4349 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4350 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4351 | public Builder addExtras(Bundle extras) { |
| 4352 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4353 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4354 | } |
| 4355 | return this; |
| 4356 | } |
| 4357 | |
| 4358 | /** |
| 4359 | * Set metadata for this notification. |
| 4360 | * |
| 4361 | * <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] | 4362 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4363 | * called. |
| 4364 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4365 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 4366 | * Use {@link #addExtras} to merge in metadata instead. |
| 4367 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4368 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4369 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4370 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4371 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4372 | if (extras != null) { |
| 4373 | mUserExtras = extras; |
| 4374 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4375 | return this; |
| 4376 | } |
| 4377 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4378 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4379 | * Get the current metadata Bundle used by this notification Builder. |
| 4380 | * |
| 4381 | * <p>The returned Bundle is shared with this Builder. |
| 4382 | * |
| 4383 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 4384 | * {@link #build()} is called. |
| 4385 | * |
| 4386 | * @see Notification#extras |
| 4387 | */ |
| 4388 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4389 | return mUserExtras; |
| 4390 | } |
| 4391 | |
| 4392 | private Bundle getAllExtras() { |
| 4393 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 4394 | saveExtras.putAll(mN.extras); |
| 4395 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4399 | * Add an action to this notification. Actions are typically displayed by |
| 4400 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4401 | * <p> |
| 4402 | * Every action must have an icon (32dp square and matching the |
| 4403 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4404 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4405 | * <p> |
| 4406 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4407 | * the order they were added. Actions will not be displayed when the notification is |
| 4408 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4409 | * 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] | 4410 | * |
| 4411 | * @param icon Resource ID of a drawable that represents the action. |
| 4412 | * @param title Text describing the action. |
| 4413 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4414 | * |
| 4415 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4416 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4417 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4418 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4419 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4420 | return this; |
| 4421 | } |
| 4422 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4423 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4424 | * Add an action to this notification. Actions are typically displayed by |
| 4425 | * the system as a button adjacent to the notification content. |
| 4426 | * <p> |
| 4427 | * Every action must have an icon (32dp square and matching the |
| 4428 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4429 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4430 | * <p> |
| 4431 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4432 | * the order they were added. Actions will not be displayed when the notification is |
| 4433 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4434 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 4435 | * |
| 4436 | * @param action The action to add. |
| 4437 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4438 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4439 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4440 | if (action != null) { |
| 4441 | mActions.add(action); |
| 4442 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4443 | return this; |
| 4444 | } |
| 4445 | |
| 4446 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4447 | * Alter the complete list of actions attached to this notification. |
| 4448 | * @see #addAction(Action). |
| 4449 | * |
| 4450 | * @param actions |
| 4451 | * @return |
| 4452 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4453 | @NonNull |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4454 | public Builder setActions(Action... actions) { |
| 4455 | mActions.clear(); |
| 4456 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4457 | if (actions[i] != null) { |
| 4458 | mActions.add(actions[i]); |
| 4459 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4460 | } |
| 4461 | return this; |
| 4462 | } |
| 4463 | |
| 4464 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4465 | * Add a rich notification style to be applied at build time. |
| 4466 | * |
| 4467 | * @param style Object responsible for modifying the notification style. |
| 4468 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4469 | @NonNull |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4470 | public Builder setStyle(Style style) { |
| 4471 | if (mStyle != style) { |
| 4472 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4473 | if (mStyle != null) { |
| 4474 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4475 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 4476 | } else { |
| 4477 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4478 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4479 | } |
| 4480 | return this; |
| 4481 | } |
| 4482 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4483 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 4484 | * Returns the style set by {@link #setStyle(Style)}. |
| 4485 | */ |
| 4486 | public Style getStyle() { |
| 4487 | return mStyle; |
| 4488 | } |
| 4489 | |
| 4490 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4491 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4492 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4493 | * @return The same Builder. |
| 4494 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4495 | @NonNull |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 4496 | public Builder setVisibility(@Visibility int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4497 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4498 | return this; |
| 4499 | } |
| 4500 | |
| 4501 | /** |
| 4502 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 4503 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 4504 | * @param n A replacement notification, presumably with some or all info redacted. |
| 4505 | * @return The same Builder. |
| 4506 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4507 | @NonNull |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4508 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4509 | if (n != null) { |
| 4510 | mN.publicVersion = new Notification(); |
| 4511 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 4512 | } else { |
| 4513 | mN.publicVersion = null; |
| 4514 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4515 | return this; |
| 4516 | } |
| 4517 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4518 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4519 | * Apply an extender to this notification builder. Extenders may be used to add |
| 4520 | * metadata or change options on this builder. |
| 4521 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4522 | @NonNull |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4523 | public Builder extend(Extender extender) { |
| 4524 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4525 | return this; |
| 4526 | } |
| 4527 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 4528 | /** |
| 4529 | * @hide |
| 4530 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4531 | @NonNull |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4532 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4533 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4534 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4535 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4536 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4537 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4538 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4539 | } |
| 4540 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4541 | /** |
| 4542 | * Sets {@link Notification#color}. |
| 4543 | * |
| 4544 | * @param argb The accent color to use |
| 4545 | * |
| 4546 | * @return The same Builder. |
| 4547 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4548 | @NonNull |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4549 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4550 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4551 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4552 | return this; |
| 4553 | } |
| 4554 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4555 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 4556 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 4557 | // This user can never be a badged profile, |
| 4558 | // and also includes USER_ALL system notifications. |
| 4559 | return null; |
| 4560 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 4561 | // Note: This assumes that the current user can read the profile badge of the |
| 4562 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 4563 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4564 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4565 | } |
| 4566 | |
| 4567 | private Bitmap getProfileBadge() { |
| 4568 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4569 | if (badge == null) { |
| 4570 | return null; |
| 4571 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4572 | final int size = mContext.getResources().getDimensionPixelSize( |
| 4573 | R.dimen.notification_badge_size); |
| 4574 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4575 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4576 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4577 | badge.draw(canvas); |
| 4578 | return bitmap; |
| 4579 | } |
| 4580 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4581 | private void bindProfileBadge(RemoteViews contentView, StandardTemplateParams p) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4582 | Bitmap profileBadge = getProfileBadge(); |
| 4583 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4584 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4585 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 4586 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4587 | if (isColorized(p)) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4588 | contentView.setDrawableTint(R.id.profile_badge, false, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4589 | getPrimaryTextColor(p), PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4590 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4591 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4592 | } |
| 4593 | |
Gus Prevas | bae5ba3 | 2018-11-28 15:45:13 -0500 | [diff] [blame] | 4594 | private void bindAlertedIcon(RemoteViews contentView, StandardTemplateParams p) { |
| 4595 | contentView.setDrawableTint( |
| 4596 | R.id.alerted_icon, |
| 4597 | false /* targetBackground */, |
| 4598 | getNeutralColor(p), |
| 4599 | PorterDuff.Mode.SRC_ATOP); |
| 4600 | } |
| 4601 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4602 | /** |
| 4603 | * @hide |
| 4604 | */ |
| 4605 | public boolean usesStandardHeader() { |
| 4606 | if (mN.mUsesStandardHeader) { |
| 4607 | return true; |
| 4608 | } |
| 4609 | if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.N) { |
| 4610 | if (mN.contentView == null && mN.bigContentView == null) { |
| 4611 | return true; |
| 4612 | } |
| 4613 | } |
| 4614 | boolean contentViewUsesHeader = mN.contentView == null |
| 4615 | || STANDARD_LAYOUTS.contains(mN.contentView.getLayoutId()); |
| 4616 | boolean bigContentViewUsesHeader = mN.bigContentView == null |
| 4617 | || STANDARD_LAYOUTS.contains(mN.bigContentView.getLayoutId()); |
| 4618 | return contentViewUsesHeader && bigContentViewUsesHeader; |
| 4619 | } |
| 4620 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4621 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4622 | resetNotificationHeader(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4623 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4624 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4625 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4626 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4627 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4628 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4629 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4630 | } |
| 4631 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4632 | /** |
| 4633 | * Resets the notification header to its original state |
| 4634 | */ |
| 4635 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 4636 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 4637 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 4638 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4639 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 4640 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4641 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 4642 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4643 | contentView.setViewVisibility(R.id.header_text_secondary, View.GONE); |
| 4644 | contentView.setTextViewText(R.id.header_text_secondary, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4645 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4646 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4647 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4648 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4649 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 4650 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 4651 | contentView.setViewVisibility(R.id.alerted_icon, View.GONE); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4652 | mN.mUsesStandardHeader = false; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4653 | } |
| 4654 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4655 | private RemoteViews applyStandardTemplate(int resId, TemplateBindResult result) { |
| 4656 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this), |
| 4657 | result); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4658 | } |
| 4659 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4660 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p, |
| 4661 | TemplateBindResult result) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 4662 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 4663 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4664 | resetStandardTemplate(contentView); |
| 4665 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4666 | final Bundle ex = mN.extras; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4667 | updateBackgroundColor(contentView, p); |
| 4668 | bindNotificationHeader(contentView, p); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4669 | bindLargeIconAndReply(contentView, p, result); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4670 | boolean showProgress = handleProgressBar(contentView, ex, p); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4671 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4672 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4673 | contentView.setTextViewText(R.id.title, processTextSpans(p.title)); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4674 | setTextViewColorPrimary(contentView, R.id.title, p); |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 4675 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 4676 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 4677 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4678 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4679 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4680 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 4681 | : com.android.internal.R.id.text; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4682 | contentView.setTextViewText(textId, processTextSpans(p.text)); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4683 | setTextViewColorSecondary(contentView, textId, p); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4684 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4685 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4686 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4687 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4688 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4689 | return contentView; |
| 4690 | } |
| 4691 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4692 | private CharSequence processTextSpans(CharSequence text) { |
Lucas Dupin | d3c9932 | 2018-09-27 10:22:29 -0700 | [diff] [blame] | 4693 | if (hasForegroundColor() || mInNightMode) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4694 | return ContrastColorUtil.clearColorSpans(text); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4695 | } |
| 4696 | return text; |
| 4697 | } |
| 4698 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4699 | private void setTextViewColorPrimary(RemoteViews contentView, int id, |
| 4700 | StandardTemplateParams p) { |
| 4701 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4702 | contentView.setTextColor(id, mPrimaryTextColor); |
| 4703 | } |
| 4704 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4705 | private boolean hasForegroundColor() { |
| 4706 | return mForegroundColor != COLOR_INVALID; |
| 4707 | } |
| 4708 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4709 | /** |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4710 | * Return the primary text color using the existing template params |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4711 | * @hide |
| 4712 | */ |
| 4713 | @VisibleForTesting |
| 4714 | public int getPrimaryTextColor() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4715 | return getPrimaryTextColor(mParams); |
| 4716 | } |
| 4717 | |
| 4718 | /** |
| 4719 | * @param p the template params to inflate this with |
| 4720 | * @return the primary text color |
| 4721 | * @hide |
| 4722 | */ |
| 4723 | @VisibleForTesting |
| 4724 | public int getPrimaryTextColor(StandardTemplateParams p) { |
| 4725 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4726 | return mPrimaryTextColor; |
| 4727 | } |
| 4728 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4729 | /** |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4730 | * Return the secondary text color using the existing template params |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4731 | * @hide |
| 4732 | */ |
| 4733 | @VisibleForTesting |
| 4734 | public int getSecondaryTextColor() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4735 | return getSecondaryTextColor(mParams); |
| 4736 | } |
| 4737 | |
| 4738 | /** |
| 4739 | * @param p the template params to inflate this with |
| 4740 | * @return the secondary text color |
| 4741 | * @hide |
| 4742 | */ |
| 4743 | @VisibleForTesting |
| 4744 | public int getSecondaryTextColor(StandardTemplateParams p) { |
| 4745 | ensureColors(p); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4746 | return mSecondaryTextColor; |
| 4747 | } |
| 4748 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4749 | private void setTextViewColorSecondary(RemoteViews contentView, int id, |
| 4750 | StandardTemplateParams p) { |
| 4751 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4752 | contentView.setTextColor(id, mSecondaryTextColor); |
| 4753 | } |
| 4754 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4755 | private void ensureColors(StandardTemplateParams p) { |
| 4756 | int backgroundColor = getBackgroundColor(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4757 | if (mPrimaryTextColor == COLOR_INVALID |
| 4758 | || mSecondaryTextColor == COLOR_INVALID |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4759 | || mTextColorsAreForBackground != backgroundColor) { |
| 4760 | mTextColorsAreForBackground = backgroundColor; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4761 | if (!hasForegroundColor() || !isColorized(p)) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4762 | mPrimaryTextColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 4763 | backgroundColor, mInNightMode); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4764 | mSecondaryTextColor = ContrastColorUtil.resolveSecondaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 4765 | backgroundColor, mInNightMode); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4766 | if (backgroundColor != COLOR_DEFAULT && isColorized(p)) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4767 | mPrimaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4768 | mPrimaryTextColor, backgroundColor, 4.5); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4769 | mSecondaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4770 | mSecondaryTextColor, backgroundColor, 4.5); |
| 4771 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4772 | } else { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4773 | double backLum = ContrastColorUtil.calculateLuminance(backgroundColor); |
| 4774 | double textLum = ContrastColorUtil.calculateLuminance(mForegroundColor); |
| 4775 | double contrast = ContrastColorUtil.calculateContrast(mForegroundColor, |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4776 | backgroundColor); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4777 | // We only respect the given colors if worst case Black or White still has |
| 4778 | // contrast |
| 4779 | boolean backgroundLight = backLum > textLum |
| 4780 | && satisfiesTextContrast(backgroundColor, Color.BLACK) |
| 4781 | || backLum <= textLum |
| 4782 | && !satisfiesTextContrast(backgroundColor, Color.WHITE); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4783 | if (contrast < 4.5f) { |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4784 | if (backgroundLight) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4785 | mSecondaryTextColor = ContrastColorUtil.findContrastColor( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4786 | mForegroundColor, |
| 4787 | backgroundColor, |
| 4788 | true /* findFG */, |
| 4789 | 4.5f); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4790 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4791 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_LIGHT); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4792 | } else { |
| 4793 | mSecondaryTextColor = |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4794 | ContrastColorUtil.findContrastColorAgainstDark( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4795 | mForegroundColor, |
| 4796 | backgroundColor, |
| 4797 | true /* findFG */, |
| 4798 | 4.5f); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4799 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4800 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4801 | } |
| 4802 | } else { |
| 4803 | mPrimaryTextColor = mForegroundColor; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4804 | mSecondaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4805 | mPrimaryTextColor, backgroundLight ? LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4806 | : LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4807 | if (ContrastColorUtil.calculateContrast(mSecondaryTextColor, |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4808 | backgroundColor) < 4.5f) { |
| 4809 | // oh well the secondary is not good enough |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4810 | if (backgroundLight) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4811 | mSecondaryTextColor = ContrastColorUtil.findContrastColor( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4812 | mSecondaryTextColor, |
| 4813 | backgroundColor, |
| 4814 | true /* findFG */, |
| 4815 | 4.5f); |
| 4816 | } else { |
| 4817 | mSecondaryTextColor |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4818 | = ContrastColorUtil.findContrastColorAgainstDark( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4819 | mSecondaryTextColor, |
| 4820 | backgroundColor, |
| 4821 | true /* findFG */, |
| 4822 | 4.5f); |
| 4823 | } |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4824 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4825 | mSecondaryTextColor, backgroundLight |
| 4826 | ? -LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4827 | : -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4828 | } |
| 4829 | } |
| 4830 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4831 | } |
| 4832 | } |
| 4833 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4834 | private void updateBackgroundColor(RemoteViews contentView, |
| 4835 | StandardTemplateParams p) { |
| 4836 | if (isColorized(p)) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4837 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4838 | getBackgroundColor(p)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4839 | } else { |
| 4840 | // Clear it! |
| 4841 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 4842 | 0); |
| 4843 | } |
| 4844 | } |
| 4845 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4846 | /** |
| 4847 | * @param remoteView the remote view to update the minheight in |
| 4848 | * @param hasMinHeight does it have a mimHeight |
| 4849 | * @hide |
| 4850 | */ |
| 4851 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 4852 | int minHeight = 0; |
| 4853 | if (hasMinHeight) { |
| 4854 | // we need to set the minHeight of the notification |
| 4855 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 4856 | com.android.internal.R.dimen.notification_min_content_height); |
| 4857 | } |
| 4858 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 4859 | } |
| 4860 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4861 | private boolean handleProgressBar(RemoteViews contentView, Bundle ex, |
| 4862 | StandardTemplateParams p) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4863 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4864 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 4865 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4866 | if (p.hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4867 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4868 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4869 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4870 | contentView.setProgressBackgroundTintList( |
| 4871 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 4872 | R.color.notification_progress_background_color))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4873 | if (getRawColor(p) != COLOR_DEFAULT) { |
| 4874 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor(p)); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4875 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 4876 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4877 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4878 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4879 | } else { |
| 4880 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4881 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 4882 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4883 | } |
| 4884 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4885 | private void bindLargeIconAndReply(RemoteViews contentView, StandardTemplateParams p, |
| 4886 | TemplateBindResult result) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4887 | boolean largeIconShown = bindLargeIcon(contentView, p); |
| 4888 | boolean replyIconShown = bindReplyIcon(contentView, p); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 4889 | boolean iconContainerVisible = largeIconShown || replyIconShown; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4890 | contentView.setViewVisibility(R.id.right_icon_container, |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 4891 | iconContainerVisible ? View.VISIBLE : View.GONE); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4892 | int marginEnd = calculateMarginEnd(largeIconShown, replyIconShown); |
| 4893 | contentView.setViewLayoutMarginEnd(R.id.line1, marginEnd); |
| 4894 | contentView.setViewLayoutMarginEnd(R.id.text, marginEnd); |
| 4895 | contentView.setViewLayoutMarginEnd(R.id.progress, marginEnd); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4896 | if (result != null) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4897 | result.setIconMarginEnd(marginEnd); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 4898 | result.setRightIconContainerVisible(iconContainerVisible); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4899 | } |
| 4900 | } |
| 4901 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4902 | private int calculateMarginEnd(boolean largeIconShown, boolean replyIconShown) { |
| 4903 | int marginEnd = 0; |
| 4904 | int contentMargin = mContext.getResources().getDimensionPixelSize( |
| 4905 | R.dimen.notification_content_margin_end); |
| 4906 | int iconSize = mContext.getResources().getDimensionPixelSize( |
| 4907 | R.dimen.notification_right_icon_size); |
| 4908 | if (replyIconShown) { |
| 4909 | // The size of the reply icon |
| 4910 | marginEnd += iconSize; |
| 4911 | |
| 4912 | int replyInset = mContext.getResources().getDimensionPixelSize( |
| 4913 | R.dimen.notification_reply_inset); |
| 4914 | // We're subtracting the inset of the reply icon to make sure it's |
| 4915 | // aligned nicely on the right, and remove it from the following padding |
| 4916 | marginEnd -= replyInset * 2; |
| 4917 | } |
| 4918 | if (largeIconShown) { |
| 4919 | // adding size of the right icon |
| 4920 | marginEnd += iconSize; |
| 4921 | |
| 4922 | if (replyIconShown) { |
| 4923 | // We also add some padding to the reply icon if it's around |
| 4924 | marginEnd += contentMargin; |
| 4925 | } |
| 4926 | } |
| 4927 | if (replyIconShown || largeIconShown) { |
| 4928 | // The padding to the content |
| 4929 | marginEnd += contentMargin; |
| 4930 | } |
| 4931 | return marginEnd; |
| 4932 | } |
| 4933 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4934 | /** |
| 4935 | * Bind the large icon. |
| 4936 | * @return if the largeIcon is visible |
| 4937 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4938 | private boolean bindLargeIcon(RemoteViews contentView, StandardTemplateParams p) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4939 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 4940 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 4941 | } |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4942 | boolean showLargeIcon = mN.mLargeIcon != null && !p.hideLargeIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4943 | if (showLargeIcon) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4944 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 4945 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4946 | processLargeLegacyIcon(mN.mLargeIcon, contentView, p); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4947 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4948 | return showLargeIcon; |
| 4949 | } |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4950 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4951 | /** |
| 4952 | * Bind the reply icon. |
| 4953 | * @return if the reply icon is visible |
| 4954 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4955 | private boolean bindReplyIcon(RemoteViews contentView, StandardTemplateParams p) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4956 | boolean actionVisible = !p.hideReplyIcon; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4957 | Action action = null; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4958 | if (actionVisible) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4959 | action = findReplyAction(); |
| 4960 | actionVisible = action != null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4961 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4962 | if (actionVisible) { |
| 4963 | contentView.setViewVisibility(R.id.reply_icon_action, View.VISIBLE); |
| 4964 | contentView.setDrawableTint(R.id.reply_icon_action, |
| 4965 | false /* targetBackground */, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4966 | getNeutralColor(p), |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4967 | PorterDuff.Mode.SRC_ATOP); |
| 4968 | contentView.setOnClickPendingIntent(R.id.reply_icon_action, action.actionIntent); |
| 4969 | contentView.setRemoteInputs(R.id.reply_icon_action, action.mRemoteInputs); |
| 4970 | } else { |
| 4971 | contentView.setRemoteInputs(R.id.reply_icon_action, null); |
| 4972 | } |
| 4973 | contentView.setViewVisibility(R.id.reply_icon_action, |
| 4974 | actionVisible ? View.VISIBLE : View.GONE); |
| 4975 | return actionVisible; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | private Action findReplyAction() { |
| 4979 | ArrayList<Action> actions = mActions; |
| 4980 | if (mOriginalActions != null) { |
| 4981 | actions = mOriginalActions; |
| 4982 | } |
| 4983 | int numActions = actions.size(); |
| 4984 | for (int i = 0; i < numActions; i++) { |
| 4985 | Action action = actions.get(i); |
| 4986 | if (hasValidRemoteInput(action)) { |
| 4987 | return action; |
| 4988 | } |
| 4989 | } |
| 4990 | return null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4991 | } |
| 4992 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4993 | private void bindNotificationHeader(RemoteViews contentView, StandardTemplateParams p) { |
| 4994 | bindSmallIcon(contentView, p); |
| 4995 | bindHeaderAppName(contentView, p); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4996 | bindHeaderText(contentView, p); |
| 4997 | bindHeaderTextSecondary(contentView, p); |
| 4998 | bindHeaderChronometerAndTime(contentView, p); |
| 4999 | bindProfileBadge(contentView, p); |
| 5000 | bindAlertedIcon(contentView, p); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5001 | bindActivePermissions(contentView, p); |
| 5002 | bindExpandButton(contentView, p); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 5003 | mN.mUsesStandardHeader = true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5004 | } |
| 5005 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5006 | private void bindActivePermissions(RemoteViews contentView, StandardTemplateParams p) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5007 | int color = getNeutralColor(p); |
Julia Reynolds | b887b23 | 2018-04-10 16:38:08 -0400 | [diff] [blame] | 5008 | contentView.setDrawableTint(R.id.camera, false, color, PorterDuff.Mode.SRC_ATOP); |
| 5009 | contentView.setDrawableTint(R.id.mic, false, color, PorterDuff.Mode.SRC_ATOP); |
| 5010 | contentView.setDrawableTint(R.id.overlay, false, color, PorterDuff.Mode.SRC_ATOP); |
| 5011 | } |
| 5012 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5013 | private void bindExpandButton(RemoteViews contentView, StandardTemplateParams p) { |
| 5014 | int color = isColorized(p) ? getPrimaryTextColor(p) : getSecondaryTextColor(p); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5015 | contentView.setDrawableTint(R.id.expand_button, false, color, |
| 5016 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5017 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5018 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5021 | private void bindHeaderChronometerAndTime(RemoteViews contentView, |
| 5022 | StandardTemplateParams p) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5023 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5024 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5025 | setTextViewColorSecondary(contentView, R.id.time_divider, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5026 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 5027 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 5028 | contentView.setLong(R.id.chronometer, "setBase", |
| 5029 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 5030 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5031 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 5032 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5033 | setTextViewColorSecondary(contentView, R.id.chronometer, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5034 | } else { |
| 5035 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 5036 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5037 | setTextViewColorSecondary(contentView, R.id.time, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5038 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5039 | } else { |
| 5040 | // We still want a time to be set but gone, such that we can show and hide it |
| 5041 | // on demand in case it's a child notification without anything in the header |
| 5042 | 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] | 5043 | } |
| 5044 | } |
| 5045 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5046 | private void bindHeaderText(RemoteViews contentView, StandardTemplateParams p) { |
| 5047 | CharSequence summaryText = p.summaryText; |
| 5048 | if (summaryText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5049 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5050 | summaryText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5051 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5052 | if (summaryText == null |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 5053 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 5054 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5055 | summaryText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 5056 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5057 | if (summaryText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5058 | // 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] | 5059 | contentView.setTextViewText(R.id.header_text, processTextSpans( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5060 | processLegacyText(summaryText))); |
| 5061 | setTextViewColorSecondary(contentView, R.id.header_text, p); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 5062 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 5063 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5064 | setTextViewColorSecondary(contentView, R.id.header_text_divider, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5065 | } |
| 5066 | } |
| 5067 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5068 | private void bindHeaderTextSecondary(RemoteViews contentView, StandardTemplateParams p) { |
| 5069 | if (!TextUtils.isEmpty(p.headerTextSecondary)) { |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 5070 | contentView.setTextViewText(R.id.header_text_secondary, processTextSpans( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5071 | processLegacyText(p.headerTextSecondary))); |
| 5072 | setTextViewColorSecondary(contentView, R.id.header_text_secondary, p); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 5073 | contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE); |
| 5074 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5075 | setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider, p); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 5076 | } |
| 5077 | } |
| 5078 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 5079 | /** |
| 5080 | * @hide |
| 5081 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5082 | @UnsupportedAppUsage |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 5083 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 5084 | CharSequence name = null; |
| 5085 | final PackageManager pm = mContext.getPackageManager(); |
| 5086 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 5087 | // only system packages which lump together a bunch of unrelated stuff |
| 5088 | // may substitute a different name to make the purpose of the |
| 5089 | // notification more clear. the correct package label should always |
| 5090 | // be accessible via SystemUI. |
| 5091 | final String pkg = mContext.getPackageName(); |
| 5092 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 5093 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 5094 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 5095 | name = subName; |
| 5096 | } else { |
| 5097 | Log.w(TAG, "warning: pkg " |
| 5098 | + pkg + " attempting to substitute app name '" + subName |
| 5099 | + "' without holding perm " |
| 5100 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 5101 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5102 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 5103 | if (TextUtils.isEmpty(name)) { |
| 5104 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 5105 | } |
| 5106 | if (TextUtils.isEmpty(name)) { |
| 5107 | // still nothing? |
| 5108 | return null; |
| 5109 | } |
| 5110 | |
| 5111 | return String.valueOf(name); |
| 5112 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5113 | private void bindHeaderAppName(RemoteViews contentView, StandardTemplateParams p) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 5114 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5115 | if (isColorized(p)) { |
| 5116 | setTextViewColorPrimary(contentView, R.id.app_name_text, p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5117 | } else { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5118 | contentView.setTextColor(R.id.app_name_text, getSecondaryTextColor(p)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5119 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5120 | } |
| 5121 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5122 | private boolean isColorized(StandardTemplateParams p) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5123 | return p.allowColorization && mN.isColorized(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5124 | } |
| 5125 | |
| 5126 | private void bindSmallIcon(RemoteViews contentView, StandardTemplateParams p) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5127 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 5128 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 5129 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5130 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5131 | contentView.setInt(R.id.icon, "setImageLevel", mN.iconLevel); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5132 | processSmallIconColor(mN.mSmallIcon, contentView, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5133 | } |
| 5134 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5135 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5136 | * @return true if the built notification will show the time or the chronometer; false |
| 5137 | * otherwise |
| 5138 | */ |
| 5139 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5140 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5141 | } |
| 5142 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5143 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 5144 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 5145 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5146 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5147 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5148 | |
| 5149 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 5150 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5151 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, View.GONE); |
| 5152 | big.setViewVisibility(R.id.notification_material_reply_progress, View.GONE); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5153 | |
| 5154 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 5155 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 5156 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 5157 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 5158 | |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 5159 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 5160 | R.dimen.notification_content_margin); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5161 | } |
| 5162 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5163 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 5164 | TemplateBindResult result) { |
| 5165 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this), |
| 5166 | result); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5169 | private static List<Notification.Action> filterOutContextualActions( |
| 5170 | List<Notification.Action> actions) { |
| 5171 | List<Notification.Action> nonContextualActions = new ArrayList<>(); |
| 5172 | for (Notification.Action action : actions) { |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 5173 | if (!action.isContextual()) { |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5174 | nonContextualActions.add(action); |
| 5175 | } |
| 5176 | } |
| 5177 | return nonContextualActions; |
| 5178 | } |
| 5179 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 5180 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5181 | StandardTemplateParams p, TemplateBindResult result) { |
| 5182 | RemoteViews big = applyStandardTemplate(layoutId, p, result); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5183 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5184 | resetStandardTemplateWithActions(big); |
| 5185 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5186 | boolean validRemoteInput = false; |
| 5187 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5188 | // In the UI contextual actions appear separately from the standard actions, so we |
| 5189 | // filter them out here. |
| 5190 | List<Notification.Action> nonContextualActions = filterOutContextualActions(mActions); |
| 5191 | |
| 5192 | int N = nonContextualActions.size(); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5193 | boolean emphazisedMode = mN.fullScreenIntent != null; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5194 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5195 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 5196 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5197 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 5198 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5199 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5200 | for (int i=0; i<N; i++) { |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5201 | Action action = nonContextualActions.get(i); |
| 5202 | |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 5203 | boolean actionHasValidInput = hasValidRemoteInput(action); |
| 5204 | validRemoteInput |= actionHasValidInput; |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5205 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5206 | final RemoteViews button = generateActionButton(action, emphazisedMode, p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5207 | if (actionHasValidInput && !emphazisedMode) { |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 5208 | // Clear the drawable |
| 5209 | button.setInt(R.id.action0, "setBackgroundResource", 0); |
| 5210 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5211 | big.addView(R.id.actions, button); |
| 5212 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 5213 | } else { |
| 5214 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5215 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5216 | |
| 5217 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5218 | if (validRemoteInput && replyText != null |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5219 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0]) |
| 5220 | && p.maxRemoteInputHistory > 0) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5221 | boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5222 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5223 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, |
| 5224 | View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5225 | big.setTextViewText(R.id.notification_material_reply_text_1, |
| 5226 | processTextSpans(replyText[0])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5227 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1, p); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5228 | big.setViewVisibility(R.id.notification_material_reply_progress, |
| 5229 | showSpinner ? View.VISIBLE : View.GONE); |
| 5230 | big.setProgressIndeterminateTintList( |
| 5231 | R.id.notification_material_reply_progress, |
| 5232 | ColorStateList.valueOf( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5233 | isColorized(p) ? getPrimaryTextColor(p) : resolveContrastColor(p))); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5234 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5235 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1]) |
| 5236 | && p.maxRemoteInputHistory > 1) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5237 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5238 | big.setTextViewText(R.id.notification_material_reply_text_2, |
| 5239 | processTextSpans(replyText[1])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5240 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2, p); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5241 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5242 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2]) |
| 5243 | && p.maxRemoteInputHistory > 2) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5244 | big.setViewVisibility( |
| 5245 | R.id.notification_material_reply_text_3, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5246 | big.setTextViewText(R.id.notification_material_reply_text_3, |
| 5247 | processTextSpans(replyText[2])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5248 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3, p); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5249 | } |
| 5250 | } |
| 5251 | } |
| 5252 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5253 | return big; |
| 5254 | } |
| 5255 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5256 | private boolean hasValidRemoteInput(Action action) { |
| 5257 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 5258 | // Weird actions |
| 5259 | return false; |
| 5260 | } |
| 5261 | |
| 5262 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 5263 | if (remoteInputs == null) { |
| 5264 | return false; |
| 5265 | } |
| 5266 | |
| 5267 | for (RemoteInput r : remoteInputs) { |
| 5268 | CharSequence[] choices = r.getChoices(); |
| 5269 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 5270 | return true; |
| 5271 | } |
| 5272 | } |
| 5273 | return false; |
| 5274 | } |
| 5275 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5276 | /** |
| 5277 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 5278 | * 1. Custom contentView from the caller |
| 5279 | * 2. Style's proposed content view |
| 5280 | * 3. Standard template view |
| 5281 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5282 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5283 | return createContentView(false /* increasedheight */ ); |
| 5284 | } |
| 5285 | |
| 5286 | /** |
| 5287 | * Construct a RemoteViews for the smaller content view. |
| 5288 | * |
| 5289 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5290 | * styles may support showing more then just that basic 1U size |
| 5291 | * and the system may decide to render important notifications |
| 5292 | * slightly bigger even when collapsed. |
| 5293 | * |
| 5294 | * @hide |
| 5295 | */ |
| 5296 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5297 | if (mN.contentView != null && useExistingRemoteView()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5298 | return mN.contentView; |
| 5299 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5300 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5301 | if (styleView != null) { |
| 5302 | return styleView; |
| 5303 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5304 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5305 | return applyStandardTemplate(getBaseLayoutResource(), null /* result */); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5306 | } |
| 5307 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5308 | private boolean useExistingRemoteView() { |
| 5309 | return mStyle == null || (!mStyle.displayCustomViewInline() |
| 5310 | && !mRebuildStyledRemoteViews); |
| 5311 | } |
| 5312 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5313 | /** |
| 5314 | * Construct a RemoteViews for the final big notification layout. |
| 5315 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5316 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5317 | RemoteViews result = null; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5318 | if (mN.bigContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5319 | return mN.bigContentView; |
| 5320 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5321 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 5322 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5323 | } else if (mActions.size() != 0) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5324 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5325 | null /* result */); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5326 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5327 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5328 | return result; |
| 5329 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5330 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5331 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 5332 | * Construct a RemoteViews for the final notification header only. This will not be |
| 5333 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5334 | * |
| 5335 | * @hide |
| 5336 | */ |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5337 | public RemoteViews makeNotificationHeader() { |
| 5338 | return makeNotificationHeader(mParams.reset().fillTextsFrom(this)); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5339 | } |
| 5340 | |
| 5341 | /** |
| 5342 | * Construct a RemoteViews for the final notification header only. This will not be |
| 5343 | * colorized. |
| 5344 | * |
| 5345 | * @param p the template params to inflate this with |
| 5346 | */ |
| 5347 | private RemoteViews makeNotificationHeader(StandardTemplateParams p) { |
| 5348 | // Headers on their own are never colorized |
| 5349 | p.disallowColorization(); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5350 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5351 | R.layout.notification_template_header); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5352 | resetNotificationHeader(header); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5353 | bindNotificationHeader(header, p); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5354 | return header; |
| 5355 | } |
| 5356 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5357 | /** |
| 5358 | * Construct a RemoteViews for the ambient version of the notification. |
| 5359 | * |
| 5360 | * @hide |
| 5361 | */ |
| 5362 | public RemoteViews makeAmbientNotification() { |
Selim Cinek | 0e06994 | 2019-01-24 16:09:41 -0800 | [diff] [blame] | 5363 | RemoteViews headsUpContentView = createHeadsUpContentView(false /* increasedHeight */); |
| 5364 | if (headsUpContentView != null) { |
| 5365 | return headsUpContentView; |
| 5366 | } |
| 5367 | return createContentView(); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5368 | } |
| 5369 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5370 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5371 | if (result != null) { |
| 5372 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 5373 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5374 | } |
| 5375 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5376 | /** |
| 5377 | * Adapt the Notification header if this view is used as an expanded view. |
| 5378 | * |
| 5379 | * @hide |
| 5380 | */ |
| 5381 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5382 | if (result != null) { |
| 5383 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 5384 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5385 | } |
| 5386 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5387 | /** |
| 5388 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5389 | * |
| 5390 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5391 | * styles may support showing more then just that basic 1U size |
| 5392 | * and the system may decide to render important notifications |
| 5393 | * slightly bigger even when collapsed. |
| 5394 | * |
| 5395 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5396 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5397 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5398 | if (mN.headsUpContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5399 | return mN.headsUpContentView; |
| 5400 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5401 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 5402 | if (styleView != null) { |
| 5403 | return styleView; |
| 5404 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5405 | } else if (mActions.size() == 0) { |
| 5406 | return null; |
| 5407 | } |
| 5408 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5409 | // We only want at most a single remote input history to be shown here, otherwise |
| 5410 | // the content would become squished. |
| 5411 | StandardTemplateParams p = mParams.reset().fillTextsFrom(this) |
| 5412 | .setMaxRemoteInputHistory(1); |
| 5413 | return applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5414 | p, |
| 5415 | null /* result */); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5416 | } |
| 5417 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5418 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5419 | * Construct a RemoteViews for the final heads-up notification layout. |
| 5420 | */ |
| 5421 | public RemoteViews createHeadsUpContentView() { |
| 5422 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 5423 | } |
| 5424 | |
| 5425 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5426 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5427 | * |
| 5428 | * @hide |
| 5429 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5430 | @UnsupportedAppUsage |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5431 | public RemoteViews makePublicContentView() { |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5432 | return makePublicView(false /* ambient */); |
| 5433 | } |
| 5434 | |
| 5435 | /** |
| 5436 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5437 | * |
| 5438 | * @hide |
| 5439 | */ |
| 5440 | public RemoteViews makePublicAmbientNotification() { |
| 5441 | return makePublicView(true /* ambient */); |
| 5442 | } |
| 5443 | |
| 5444 | private RemoteViews makePublicView(boolean ambient) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5445 | if (mN.publicVersion != null) { |
| 5446 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5447 | return ambient ? builder.makeAmbientNotification() : builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5448 | } |
| 5449 | Bundle savedBundle = mN.extras; |
| 5450 | Style style = mStyle; |
| 5451 | mStyle = null; |
| 5452 | Icon largeIcon = mN.mLargeIcon; |
| 5453 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5454 | Bitmap largeIconLegacy = mN.largeIcon; |
| 5455 | mN.largeIcon = null; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5456 | ArrayList<Action> actions = mActions; |
| 5457 | mActions = new ArrayList<>(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5458 | Bundle publicExtras = new Bundle(); |
| 5459 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 5460 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 5461 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 5462 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5463 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 5464 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | ed07b96 | 2018-04-30 14:39:35 -0700 | [diff] [blame] | 5465 | String appName = savedBundle.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 5466 | if (appName != null) { |
| 5467 | publicExtras.putString(EXTRA_SUBSTITUTE_APP_NAME, appName); |
| 5468 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5469 | mN.extras = publicExtras; |
Selim Cinek | 499c20f | 2017-07-20 14:06:09 -0700 | [diff] [blame] | 5470 | RemoteViews view; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5471 | view = makeNotificationHeader(); |
| 5472 | view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5473 | mN.extras = savedBundle; |
| 5474 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5475 | mN.largeIcon = largeIconLegacy; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5476 | mActions = actions; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5477 | mStyle = style; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5478 | return view; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5479 | } |
| 5480 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5481 | /** |
| 5482 | * Construct a content view for the display when low - priority |
| 5483 | * |
| 5484 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 5485 | * a new subtext is created consisting of the content of the |
| 5486 | * notification. |
| 5487 | * @hide |
| 5488 | */ |
| 5489 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5490 | StandardTemplateParams p = mParams.reset() |
| 5491 | .forceDefaultColor() |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5492 | .fillTextsFrom(this); |
| 5493 | if (!useRegularSubtext || TextUtils.isEmpty(mParams.summaryText)) { |
| 5494 | p.summaryText(createSummaryText()); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5495 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5496 | RemoteViews header = makeNotificationHeader(p); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 5497 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5498 | return header; |
| 5499 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5500 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5501 | private CharSequence createSummaryText() { |
| 5502 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 5503 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 5504 | return titleText; |
| 5505 | } |
| 5506 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 5507 | if (titleText == null) { |
| 5508 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 5509 | } |
| 5510 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5511 | if (titleText != null) { |
| 5512 | summary.append(bidi.unicodeWrap(titleText)); |
| 5513 | } |
| 5514 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 5515 | if (titleText != null && contentText != null) { |
| 5516 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 5517 | R.string.notification_header_divider_symbol_with_spaces))); |
| 5518 | } |
| 5519 | if (contentText != null) { |
| 5520 | summary.append(bidi.unicodeWrap(contentText)); |
| 5521 | } |
| 5522 | return summary; |
| 5523 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5524 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5525 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5526 | StandardTemplateParams p) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5527 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 5528 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5529 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 5530 | : tombstone ? getActionTombstoneLayoutResource() |
| 5531 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5532 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5533 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5534 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5535 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5536 | if (action.mRemoteInputs != null) { |
| 5537 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 5538 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5539 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5540 | // change the background bgColor |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5541 | CharSequence title = action.title; |
| 5542 | ColorStateList[] outResultColor = null; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5543 | int background = resolveBackgroundColor(p); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5544 | if (isLegacy()) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5545 | title = ContrastColorUtil.clearColorSpans(title); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5546 | } else { |
| 5547 | outResultColor = new ColorStateList[1]; |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5548 | title = ensureColorSpanContrast(title, background, outResultColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5549 | } |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5550 | button.setTextViewText(R.id.action0, processTextSpans(title)); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5551 | setTextViewColorPrimary(button, R.id.action0, p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5552 | int rippleColor; |
| 5553 | boolean hasColorOverride = outResultColor != null && outResultColor[0] != null; |
| 5554 | if (hasColorOverride) { |
| 5555 | // There's a span spanning the full text, let's take it and use it as the |
| 5556 | // background color |
| 5557 | background = outResultColor[0].getDefaultColor(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5558 | int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5559 | background, mInNightMode); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5560 | button.setTextColor(R.id.action0, textColor); |
| 5561 | rippleColor = textColor; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5562 | } else if (getRawColor(p) != COLOR_DEFAULT && !isColorized(p) |
| 5563 | && mTintActionButtons) { |
| 5564 | rippleColor = resolveContrastColor(p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5565 | button.setTextColor(R.id.action0, rippleColor); |
| 5566 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5567 | rippleColor = getPrimaryTextColor(p); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5568 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5569 | // We only want about 20% alpha for the ripple |
| 5570 | rippleColor = (rippleColor & 0x00ffffff) | 0x33000000; |
| 5571 | button.setColorStateList(R.id.action0, "setRippleColor", |
| 5572 | ColorStateList.valueOf(rippleColor)); |
| 5573 | button.setColorStateList(R.id.action0, "setButtonBackground", |
| 5574 | ColorStateList.valueOf(background)); |
| 5575 | button.setBoolean(R.id.action0, "setHasStroke", !hasColorOverride); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5576 | } else { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5577 | button.setTextViewText(R.id.action0, processTextSpans( |
| 5578 | processLegacyText(action.title))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5579 | if (isColorized(p)) { |
| 5580 | setTextViewColorPrimary(button, R.id.action0, p); |
| 5581 | } else if (getRawColor(p) != COLOR_DEFAULT && mTintActionButtons) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5582 | button.setTextColor(R.id.action0, resolveContrastColor(p)); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5583 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5584 | } |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 5585 | button.setIntTag(R.id.action0, R.id.notification_action_index_tag, |
| 5586 | mActions.indexOf(action)); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5587 | return button; |
| 5588 | } |
| 5589 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5590 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5591 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 5592 | * text if a span was found that spans over the whole text. |
| 5593 | * |
| 5594 | * @param charSequence the charSequence on which the spans are |
| 5595 | * @param background the background color to ensure the contrast against |
| 5596 | * @param outResultColor an array in which a color will be returned as the first element if |
| 5597 | * there exists a full length color span. |
| 5598 | * @return the contrasted charSequence |
| 5599 | */ |
| 5600 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 5601 | ColorStateList[] outResultColor) { |
| 5602 | if (charSequence instanceof Spanned) { |
| 5603 | Spanned ss = (Spanned) charSequence; |
| 5604 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 5605 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 5606 | for (Object span : spans) { |
| 5607 | Object resultSpan = span; |
| 5608 | int spanStart = ss.getSpanStart(span); |
| 5609 | int spanEnd = ss.getSpanEnd(span); |
| 5610 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 5611 | if (resultSpan instanceof CharacterStyle) { |
| 5612 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 5613 | } |
| 5614 | if (resultSpan instanceof TextAppearanceSpan) { |
| 5615 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 5616 | ColorStateList textColor = originalSpan.getTextColor(); |
| 5617 | if (textColor != null) { |
| 5618 | int[] colors = textColor.getColors(); |
| 5619 | int[] newColors = new int[colors.length]; |
| 5620 | for (int i = 0; i < newColors.length; i++) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5621 | newColors[i] = ContrastColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5622 | colors[i], background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5623 | } |
| 5624 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 5625 | newColors); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5626 | if (fullLength) { |
| 5627 | outResultColor[0] = textColor; |
| 5628 | // Let's drop the color from the span |
| 5629 | textColor = null; |
| 5630 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5631 | resultSpan = new TextAppearanceSpan( |
| 5632 | originalSpan.getFamily(), |
| 5633 | originalSpan.getTextStyle(), |
| 5634 | originalSpan.getTextSize(), |
| 5635 | textColor, |
| 5636 | originalSpan.getLinkTextColor()); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5637 | } |
| 5638 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 5639 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 5640 | int foregroundColor = originalSpan.getForegroundColor(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5641 | foregroundColor = ContrastColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5642 | foregroundColor, background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5643 | if (fullLength) { |
| 5644 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5645 | resultSpan = null; |
| 5646 | } else { |
| 5647 | resultSpan = new ForegroundColorSpan(foregroundColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5648 | } |
| 5649 | } else { |
| 5650 | resultSpan = span; |
| 5651 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5652 | if (resultSpan != null) { |
| 5653 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 5654 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5655 | } |
| 5656 | return builder; |
| 5657 | } |
| 5658 | return charSequence; |
| 5659 | } |
| 5660 | |
| 5661 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5662 | * @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] | 5663 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5664 | */ |
| 5665 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5666 | if (!mIsLegacyInitialized) { |
| 5667 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 5668 | < Build.VERSION_CODES.LOLLIPOP; |
| 5669 | mIsLegacyInitialized = true; |
| 5670 | } |
| 5671 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5672 | } |
| 5673 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5674 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 5675 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5676 | if (isAlreadyLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5677 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5678 | } else { |
| 5679 | return charSequence; |
| 5680 | } |
| 5681 | } |
| 5682 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5683 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5684 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5685 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5686 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5687 | StandardTemplateParams p) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5688 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5689 | int color; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5690 | if (isColorized(p)) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5691 | color = getPrimaryTextColor(p); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5692 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5693 | color = resolveContrastColor(p); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5694 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5695 | if (colorable) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5696 | contentView.setDrawableTint(R.id.icon, false, color, |
| 5697 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5698 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5699 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5700 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5701 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5702 | } |
| 5703 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5704 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5705 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5706 | * if it's grayscale). |
| 5707 | */ |
| 5708 | // TODO: also check bounds, transparency, that sort of thing. |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5709 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView, |
| 5710 | StandardTemplateParams p) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5711 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5712 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5713 | // resolve color will fall back to the default when legacy |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5714 | contentView.setDrawableTint(R.id.icon, false, resolveContrastColor(p), |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5715 | PorterDuff.Mode.SRC_ATOP); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 5716 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5717 | } |
| 5718 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 5719 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5720 | if (mN.color != COLOR_DEFAULT) { |
| 5721 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5722 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5723 | } |
| 5724 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5725 | int resolveContrastColor(StandardTemplateParams p) { |
| 5726 | int rawColor = getRawColor(p); |
| 5727 | if (mCachedContrastColorIsFor == rawColor && mCachedContrastColor != COLOR_INVALID) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5728 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5729 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5730 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5731 | int color; |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5732 | int background = mContext.getColor( |
| 5733 | com.android.internal.R.color.notification_material_background_color); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5734 | if (rawColor == COLOR_DEFAULT) { |
| 5735 | ensureColors(p); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5736 | color = ContrastColorUtil.resolveDefaultColor(mContext, background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5737 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5738 | color = ContrastColorUtil.resolveContrastColor(mContext, rawColor, |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5739 | background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5740 | } |
| 5741 | if (Color.alpha(color) < 255) { |
| 5742 | // 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] | 5743 | color = ContrastColorUtil.compositeColors(color, background); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5744 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5745 | mCachedContrastColorIsFor = rawColor; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5746 | return mCachedContrastColor = color; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5747 | } |
| 5748 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5749 | /** |
| 5750 | * Return the raw color of this Notification, which doesn't necessarily satisfy contrast. |
| 5751 | * |
| 5752 | * @see #resolveContrastColor(StandardTemplateParams) for the contrasted color |
| 5753 | * @param p the template params to inflate this with |
| 5754 | */ |
| 5755 | private int getRawColor(StandardTemplateParams p) { |
| 5756 | if (p.forceDefaultColor) { |
| 5757 | return COLOR_DEFAULT; |
| 5758 | } |
| 5759 | return mN.color; |
| 5760 | } |
| 5761 | |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5762 | int resolveNeutralColor() { |
| 5763 | if (mNeutralColor != COLOR_INVALID) { |
| 5764 | return mNeutralColor; |
| 5765 | } |
| 5766 | int background = mContext.getColor( |
| 5767 | com.android.internal.R.color.notification_material_background_color); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5768 | mNeutralColor = ContrastColorUtil.resolveDefaultColor(mContext, background, |
| 5769 | mInNightMode); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5770 | if (Color.alpha(mNeutralColor) < 255) { |
| 5771 | // 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] | 5772 | mNeutralColor = ContrastColorUtil.compositeColors(mNeutralColor, background); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5773 | } |
| 5774 | return mNeutralColor; |
| 5775 | } |
| 5776 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5777 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5778 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5779 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5780 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 5781 | @NonNull |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5782 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5783 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5784 | mN.actions = new Action[mActions.size()]; |
| 5785 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5786 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5787 | if (!mPersonList.isEmpty()) { |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 5788 | mN.extras.putParcelableArrayList(EXTRA_PEOPLE_LIST, mPersonList); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 5789 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5790 | if (mN.bigContentView != null || mN.contentView != null |
| 5791 | || mN.headsUpContentView != null) { |
| 5792 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 5793 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5794 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5795 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5796 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5797 | /** |
| 5798 | * Creates a Builder from an existing notification so further changes can be made. |
| 5799 | * @param context The context for your application / activity. |
| 5800 | * @param n The notification to create a Builder from. |
| 5801 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 5802 | @NonNull |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5803 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5804 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5805 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 5806 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5807 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5808 | if (applicationInfo != null) { |
| 5809 | try { |
| 5810 | builderContext = context.createApplicationContext(applicationInfo, |
| 5811 | Context.CONTEXT_RESTRICTED); |
| 5812 | } catch (NameNotFoundException e) { |
| 5813 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 5814 | builderContext = context; // try with our context |
| 5815 | } |
| 5816 | } else { |
| 5817 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5818 | } |
| 5819 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5820 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5821 | } |
| 5822 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5823 | /** |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 5824 | * Determines whether the platform can generate contextual actions for a notification. |
| 5825 | * By default this is true. |
| 5826 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 5827 | @NonNull |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 5828 | public Builder setAllowSystemGeneratedContextualActions(boolean allowed) { |
| 5829 | mN.mAllowSystemGeneratedContextualActions = allowed; |
| 5830 | return this; |
| 5831 | } |
| 5832 | |
| 5833 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5834 | * @deprecated Use {@link #build()} instead. |
| 5835 | */ |
| 5836 | @Deprecated |
| 5837 | public Notification getNotification() { |
| 5838 | return build(); |
| 5839 | } |
| 5840 | |
| 5841 | /** |
| 5842 | * Combine all of the options that have been set and return a new {@link Notification} |
| 5843 | * object. |
| 5844 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 5845 | @NonNull |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5846 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5847 | // first, add any extras from the calling code |
| 5848 | if (mUserExtras != null) { |
| 5849 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5850 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5851 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5852 | mN.creationTime = System.currentTimeMillis(); |
| 5853 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5854 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5855 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 5856 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5857 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5858 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5859 | if (mStyle != null) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5860 | mStyle.reduceImageSizes(mContext); |
| 5861 | mStyle.purgeResources(); |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 5862 | mStyle.validate(mContext); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5863 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5864 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5865 | mN.reduceImageSizes(mContext); |
| 5866 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5867 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5868 | && (useExistingRemoteView())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5869 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5870 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5871 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 5872 | mN.contentView.getSequenceNumber()); |
| 5873 | } |
| 5874 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5875 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5876 | if (mN.bigContentView != null) { |
| 5877 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 5878 | mN.bigContentView.getSequenceNumber()); |
| 5879 | } |
| 5880 | } |
| 5881 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5882 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5883 | if (mN.headsUpContentView != null) { |
| 5884 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 5885 | mN.headsUpContentView.getSequenceNumber()); |
| 5886 | } |
| 5887 | } |
| 5888 | } |
| 5889 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 5890 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 5891 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 5892 | } |
| 5893 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 5894 | mN.allPendingIntents = null; |
| 5895 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5896 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5897 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5898 | |
| 5899 | /** |
| 5900 | * Apply this Builder to an existing {@link Notification} object. |
| 5901 | * |
| 5902 | * @hide |
| 5903 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 5904 | @NonNull |
| 5905 | public Notification buildInto(@NonNull Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 5906 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5907 | return n; |
| 5908 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5909 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5910 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5911 | * 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] | 5912 | * change. Also removes extenders on low ram devices, as |
| 5913 | * {@link android.service.notification.NotificationListenerService} services are disabled. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5914 | * |
| 5915 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 5916 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5917 | * @hide |
| 5918 | */ |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5919 | public static Notification maybeCloneStrippedForDelivery(Notification n, boolean isLowRam, |
| 5920 | Context context) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5921 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5922 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5923 | // Only strip views for known Styles because we won't know how to |
| 5924 | // re-create them otherwise. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5925 | if (!isLowRam |
| 5926 | && !TextUtils.isEmpty(templateClass) |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5927 | && getNotificationStyleClass(templateClass) == null) { |
| 5928 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5929 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5930 | |
| 5931 | // Only strip unmodified BuilderRemoteViews. |
| 5932 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5933 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5934 | n.contentView.getSequenceNumber(); |
| 5935 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5936 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5937 | n.bigContentView.getSequenceNumber(); |
| 5938 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5939 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5940 | n.headsUpContentView.getSequenceNumber(); |
| 5941 | |
| 5942 | // Nothing to do here, no need to clone. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5943 | if (!isLowRam |
| 5944 | && !stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5945 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5946 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5947 | |
| 5948 | Notification clone = n.clone(); |
| 5949 | if (stripContentView) { |
| 5950 | clone.contentView = null; |
| 5951 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 5952 | } |
| 5953 | if (stripBigContentView) { |
| 5954 | clone.bigContentView = null; |
| 5955 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 5956 | } |
| 5957 | if (stripHeadsUpContentView) { |
| 5958 | clone.headsUpContentView = null; |
| 5959 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 5960 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5961 | if (isLowRam) { |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5962 | String[] allowedServices = context.getResources().getStringArray( |
| 5963 | R.array.config_allowedManagedServicesOnLowRamDevices); |
| 5964 | if (allowedServices.length == 0) { |
| 5965 | clone.extras.remove(Notification.TvExtender.EXTRA_TV_EXTENDER); |
| 5966 | clone.extras.remove(WearableExtender.EXTRA_WEARABLE_EXTENSIONS); |
| 5967 | clone.extras.remove(CarExtender.EXTRA_CAR_EXTENDER); |
| 5968 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5969 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5970 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5971 | } |
| 5972 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5973 | @UnsupportedAppUsage |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5974 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5975 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5976 | } |
| 5977 | |
| 5978 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5979 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5980 | } |
| 5981 | |
| 5982 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5983 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5984 | } |
| 5985 | |
| 5986 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5987 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5988 | } |
| 5989 | |
| 5990 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5991 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5992 | } |
| 5993 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5994 | private int getMessagingLayoutResource() { |
| 5995 | return R.layout.notification_template_material_messaging; |
| 5996 | } |
| 5997 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5998 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5999 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 6000 | } |
| 6001 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 6002 | private int getEmphasizedActionLayoutResource() { |
| 6003 | return R.layout.notification_material_action_emphasized; |
| 6004 | } |
| 6005 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 6006 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 6007 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 6008 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6009 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6010 | private int getBackgroundColor(StandardTemplateParams p) { |
| 6011 | if (isColorized(p)) { |
| 6012 | return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : getRawColor(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6013 | } else { |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 6014 | return COLOR_DEFAULT; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6015 | } |
| 6016 | } |
| 6017 | |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 6018 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 6019 | * 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] | 6020 | * @param p the template params to inflate this with |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 6021 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6022 | private int getNeutralColor(StandardTemplateParams p) { |
| 6023 | if (isColorized(p)) { |
| 6024 | return getSecondaryTextColor(p); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 6025 | } else { |
| 6026 | return resolveNeutralColor(); |
| 6027 | } |
| 6028 | } |
| 6029 | |
| 6030 | /** |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 6031 | * Same as getBackgroundColor but also resolved the default color to the background. |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6032 | * @param p the template params to inflate this with |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 6033 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6034 | private int resolveBackgroundColor(StandardTemplateParams p) { |
| 6035 | int backgroundColor = getBackgroundColor(p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 6036 | if (backgroundColor == COLOR_DEFAULT) { |
| 6037 | backgroundColor = mContext.getColor( |
| 6038 | com.android.internal.R.color.notification_material_background_color); |
| 6039 | } |
| 6040 | return backgroundColor; |
| 6041 | } |
| 6042 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 6043 | private boolean shouldTintActionButtons() { |
| 6044 | return mTintActionButtons; |
| 6045 | } |
| 6046 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6047 | private boolean textColorsNeedInversion() { |
| 6048 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 6049 | return false; |
| 6050 | } |
| 6051 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 6052 | return targetSdkVersion > Build.VERSION_CODES.M |
| 6053 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 6054 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6055 | |
| 6056 | /** |
| 6057 | * Set a color palette to be used as the background and textColors |
| 6058 | * |
| 6059 | * @param backgroundColor the color to be used as the background |
| 6060 | * @param foregroundColor the color to be used as the foreground |
| 6061 | * |
| 6062 | * @hide |
| 6063 | */ |
| 6064 | public void setColorPalette(int backgroundColor, int foregroundColor) { |
| 6065 | mBackgroundColor = backgroundColor; |
| 6066 | mForegroundColor = foregroundColor; |
| 6067 | mTextColorsAreForBackground = COLOR_INVALID; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6068 | ensureColors(mParams.reset().fillTextsFrom(this)); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6069 | } |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 6070 | |
| 6071 | /** |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 6072 | * Forces all styled remoteViews to be built from scratch and not use any cached |
| 6073 | * RemoteViews. |
| 6074 | * This is needed for legacy apps that are baking in their remoteviews into the |
| 6075 | * notification. |
| 6076 | * |
| 6077 | * @hide |
| 6078 | */ |
| 6079 | public void setRebuildStyledRemoteViews(boolean rebuild) { |
| 6080 | mRebuildStyledRemoteViews = rebuild; |
| 6081 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6082 | |
| 6083 | /** |
| 6084 | * Get the text that should be displayed in the statusBar when heads upped. This is |
| 6085 | * usually just the app name, but may be different depending on the style. |
| 6086 | * |
| 6087 | * @param publicMode If true, return a text that is safe to display in public. |
| 6088 | * |
| 6089 | * @hide |
| 6090 | */ |
| 6091 | public CharSequence getHeadsUpStatusBarText(boolean publicMode) { |
| 6092 | if (mStyle != null && !publicMode) { |
| 6093 | CharSequence text = mStyle.getHeadsUpStatusBarText(); |
| 6094 | if (!TextUtils.isEmpty(text)) { |
| 6095 | return text; |
| 6096 | } |
| 6097 | } |
| 6098 | return loadHeaderAppName(); |
| 6099 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6100 | } |
| 6101 | |
| 6102 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6103 | * Reduces the image sizes to conform to a maximum allowed size. This also processes all custom |
| 6104 | * remote views. |
| 6105 | * |
| 6106 | * @hide |
| 6107 | */ |
| 6108 | void reduceImageSizes(Context context) { |
| 6109 | if (extras.getBoolean(EXTRA_REDUCED_IMAGES)) { |
| 6110 | return; |
| 6111 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6112 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6113 | if (mLargeIcon != null || largeIcon != null) { |
| 6114 | Resources resources = context.getResources(); |
| 6115 | Class<? extends Style> style = getNotificationStyle(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6116 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6117 | ? R.dimen.notification_right_icon_size_low_ram |
| 6118 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6119 | int maxHeight = maxWidth; |
| 6120 | if (MediaStyle.class.equals(style) |
| 6121 | || DecoratedMediaCustomViewStyle.class.equals(style)) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6122 | maxHeight = resources.getDimensionPixelSize(isLowRam |
| 6123 | ? R.dimen.notification_media_image_max_height_low_ram |
| 6124 | : R.dimen.notification_media_image_max_height); |
| 6125 | maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6126 | ? R.dimen.notification_media_image_max_width_low_ram |
| 6127 | : R.dimen.notification_media_image_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6128 | } |
| 6129 | if (mLargeIcon != null) { |
| 6130 | mLargeIcon.scaleDownIfNecessary(maxWidth, maxHeight); |
| 6131 | } |
| 6132 | if (largeIcon != null) { |
| 6133 | largeIcon = Icon.scaleDownIfNecessary(largeIcon, maxWidth, maxHeight); |
| 6134 | } |
| 6135 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6136 | reduceImageSizesForRemoteView(contentView, context, isLowRam); |
| 6137 | reduceImageSizesForRemoteView(headsUpContentView, context, isLowRam); |
| 6138 | reduceImageSizesForRemoteView(bigContentView, context, isLowRam); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6139 | extras.putBoolean(EXTRA_REDUCED_IMAGES, true); |
| 6140 | } |
| 6141 | |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6142 | private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context, |
| 6143 | boolean isLowRam) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6144 | if (remoteView != null) { |
| 6145 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6146 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6147 | ? R.dimen.notification_custom_view_max_image_width_low_ram |
| 6148 | : R.dimen.notification_custom_view_max_image_width); |
| 6149 | int maxHeight = resources.getDimensionPixelSize(isLowRam |
| 6150 | ? R.dimen.notification_custom_view_max_image_height_low_ram |
| 6151 | : R.dimen.notification_custom_view_max_image_height); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6152 | remoteView.reduceImageSizes(maxWidth, maxHeight); |
| 6153 | } |
| 6154 | } |
| 6155 | |
| 6156 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6157 | * @return whether this notification is a foreground service notification |
Gus Prevas | b0c1a46 | 2018-11-05 11:06:15 -0500 | [diff] [blame] | 6158 | * @hide |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6159 | */ |
Gus Prevas | b0c1a46 | 2018-11-05 11:06:15 -0500 | [diff] [blame] | 6160 | public boolean isForegroundService() { |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6161 | return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6162 | } |
| 6163 | |
| 6164 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6165 | * @return whether this notification has a media session attached |
| 6166 | * @hide |
| 6167 | */ |
| 6168 | public boolean hasMediaSession() { |
| 6169 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 6170 | } |
| 6171 | |
| 6172 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6173 | * @return the style class of this notification |
| 6174 | * @hide |
| 6175 | */ |
| 6176 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 6177 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 6178 | |
| 6179 | if (!TextUtils.isEmpty(templateClass)) { |
| 6180 | return Notification.getNotificationStyleClass(templateClass); |
| 6181 | } |
| 6182 | return null; |
| 6183 | } |
| 6184 | |
| 6185 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6186 | * @return true if this notification is colorized. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6187 | * |
| 6188 | * @hide |
| 6189 | */ |
| 6190 | public boolean isColorized() { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6191 | if (isColorizedMedia()) { |
| 6192 | return true; |
| 6193 | } |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 6194 | return extras.getBoolean(EXTRA_COLORIZED) |
| 6195 | && (hasColorizedPermission() || isForegroundService()); |
| 6196 | } |
| 6197 | |
| 6198 | /** |
| 6199 | * Returns whether an app can colorize due to the android.permission.USE_COLORIZED_NOTIFICATIONS |
| 6200 | * permission. The permission is checked when a notification is enqueued. |
| 6201 | */ |
| 6202 | private boolean hasColorizedPermission() { |
| 6203 | return (flags & Notification.FLAG_CAN_COLORIZE) != 0; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | /** |
| 6207 | * @return true if this notification is colorized and it is a media notification |
| 6208 | * |
| 6209 | * @hide |
| 6210 | */ |
| 6211 | public boolean isColorizedMedia() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6212 | Class<? extends Style> style = getNotificationStyle(); |
| 6213 | if (MediaStyle.class.equals(style)) { |
| 6214 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 6215 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 6216 | return true; |
| 6217 | } |
| 6218 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 6219 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 6220 | return true; |
| 6221 | } |
| 6222 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6223 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6224 | } |
| 6225 | |
Selim Cinek | 0847acd | 2017-04-24 19:48:29 -0700 | [diff] [blame] | 6226 | |
| 6227 | /** |
| 6228 | * @return true if this is a media notification |
| 6229 | * |
| 6230 | * @hide |
| 6231 | */ |
| 6232 | public boolean isMediaNotification() { |
| 6233 | Class<? extends Style> style = getNotificationStyle(); |
| 6234 | if (MediaStyle.class.equals(style)) { |
| 6235 | return true; |
| 6236 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 6237 | return true; |
| 6238 | } |
| 6239 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6240 | } |
| 6241 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6242 | private boolean hasLargeIcon() { |
| 6243 | return mLargeIcon != null || largeIcon != null; |
| 6244 | } |
| 6245 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6246 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6247 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 6248 | * @hide |
| 6249 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6250 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 6251 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 6252 | } |
| 6253 | |
| 6254 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6255 | * @return true if the notification will show a chronometer; false otherwise |
| 6256 | * @hide |
| 6257 | */ |
| 6258 | public boolean showsChronometer() { |
| 6259 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 6260 | } |
| 6261 | |
| 6262 | /** |
Julia Reynolds | 7ca3307 | 2017-06-29 13:58:24 -0400 | [diff] [blame] | 6263 | * @removed |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 6264 | */ |
| 6265 | @SystemApi |
| 6266 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 6267 | Class<? extends Style>[] classes = new Class[] { |
| 6268 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 6269 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 6270 | MessagingStyle.class }; |
| 6271 | for (Class<? extends Style> innerClass : classes) { |
| 6272 | if (templateClass.equals(innerClass.getName())) { |
| 6273 | return innerClass; |
| 6274 | } |
| 6275 | } |
| 6276 | return null; |
| 6277 | } |
| 6278 | |
| 6279 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6280 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 6281 | * object. |
| 6282 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 6283 | public static abstract class Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 6284 | |
| 6285 | /** |
| 6286 | * The number of items allowed simulatanously in the remote input history. |
| 6287 | * @hide |
| 6288 | */ |
| 6289 | static final int MAX_REMOTE_INPUT_HISTORY_LINES = 3; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6290 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6291 | |
| 6292 | /** |
| 6293 | * @hide |
| 6294 | */ |
| 6295 | protected CharSequence mSummaryText = null; |
| 6296 | |
| 6297 | /** |
| 6298 | * @hide |
| 6299 | */ |
| 6300 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6301 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6302 | protected Builder mBuilder; |
| 6303 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6304 | /** |
| 6305 | * Overrides ContentTitle in the big form of the template. |
| 6306 | * This defaults to the value passed to setContentTitle(). |
| 6307 | */ |
| 6308 | protected void internalSetBigContentTitle(CharSequence title) { |
| 6309 | mBigContentTitle = title; |
| 6310 | } |
| 6311 | |
| 6312 | /** |
| 6313 | * Set the first line of text after the detail section in the big form of the template. |
| 6314 | */ |
| 6315 | protected void internalSetSummaryText(CharSequence cs) { |
| 6316 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 6317 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6318 | } |
| 6319 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6320 | public void setBuilder(Builder builder) { |
| 6321 | if (mBuilder != builder) { |
| 6322 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 6323 | if (mBuilder != null) { |
| 6324 | mBuilder.setStyle(this); |
| 6325 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6326 | } |
| 6327 | } |
| 6328 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6329 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6330 | if (mBuilder == null) { |
| 6331 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 6332 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6333 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6334 | |
| 6335 | protected RemoteViews getStandardView(int layoutId) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6336 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder); |
| 6337 | return getStandardView(layoutId, p, null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6338 | } |
| 6339 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6340 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6341 | /** |
| 6342 | * Get the standard view for this style. |
| 6343 | * |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6344 | * @param layoutId The layout id to use. |
| 6345 | * @param p the params for this inflation. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6346 | * @param result The result where template bind information is saved. |
| 6347 | * @return A remoteView for this style. |
| 6348 | * @hide |
| 6349 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6350 | protected RemoteViews getStandardView(int layoutId, StandardTemplateParams p, |
| 6351 | TemplateBindResult result) { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6352 | checkBuilder(); |
| 6353 | |
| 6354 | if (mBigContentTitle != null) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6355 | p.title = mBigContentTitle; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6356 | } |
| 6357 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6358 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId, p, |
| 6359 | result); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6360 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6361 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 6362 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 6363 | } else { |
| 6364 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6365 | } |
| 6366 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6367 | return contentView; |
| 6368 | } |
| 6369 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6370 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6371 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6372 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6373 | * |
| 6374 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6375 | * @hide |
| 6376 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6377 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6378 | return null; |
| 6379 | } |
| 6380 | |
| 6381 | /** |
| 6382 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 6383 | * @hide |
| 6384 | */ |
| 6385 | public RemoteViews makeBigContentView() { |
| 6386 | return null; |
| 6387 | } |
| 6388 | |
| 6389 | /** |
| 6390 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6391 | * |
| 6392 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6393 | * @hide |
| 6394 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6395 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6396 | return null; |
| 6397 | } |
| 6398 | |
| 6399 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6400 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6401 | * @hide |
| 6402 | */ |
| 6403 | public void addExtras(Bundle extras) { |
| 6404 | if (mSummaryTextSet) { |
| 6405 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 6406 | } |
| 6407 | if (mBigContentTitle != null) { |
| 6408 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 6409 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 6410 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6411 | } |
| 6412 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6413 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6414 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6415 | * @hide |
| 6416 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6417 | protected void restoreFromExtras(Bundle extras) { |
| 6418 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 6419 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 6420 | mSummaryTextSet = true; |
| 6421 | } |
| 6422 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 6423 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 6424 | } |
| 6425 | } |
| 6426 | |
| 6427 | |
| 6428 | /** |
| 6429 | * @hide |
| 6430 | */ |
| 6431 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6432 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6433 | return wip; |
| 6434 | } |
| 6435 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6436 | /** |
| 6437 | * @hide |
| 6438 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6439 | public void purgeResources() {} |
| 6440 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6441 | /** |
| 6442 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 6443 | * attached to. |
| 6444 | * |
| 6445 | * @return the fully constructed Notification. |
| 6446 | */ |
| 6447 | public Notification build() { |
| 6448 | checkBuilder(); |
| 6449 | return mBuilder.build(); |
| 6450 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6451 | |
| 6452 | /** |
| 6453 | * @hide |
| 6454 | * @return true if the style positions the progress bar on the second line; false if the |
| 6455 | * style hides the progress bar |
| 6456 | */ |
| 6457 | protected boolean hasProgress() { |
| 6458 | return true; |
| 6459 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6460 | |
| 6461 | /** |
| 6462 | * @hide |
| 6463 | * @return Whether we should put the summary be put into the notification header |
| 6464 | */ |
| 6465 | public boolean hasSummaryInHeader() { |
| 6466 | return true; |
| 6467 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6468 | |
| 6469 | /** |
| 6470 | * @hide |
| 6471 | * @return Whether custom content views are displayed inline in the style |
| 6472 | */ |
| 6473 | public boolean displayCustomViewInline() { |
| 6474 | return false; |
| 6475 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6476 | |
| 6477 | /** |
| 6478 | * Reduces the image sizes contained in this style. |
| 6479 | * |
| 6480 | * @hide |
| 6481 | */ |
| 6482 | public void reduceImageSizes(Context context) { |
| 6483 | } |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6484 | |
| 6485 | /** |
| 6486 | * Validate that this style was properly composed. This is called at build time. |
| 6487 | * @hide |
| 6488 | */ |
| 6489 | public void validate(Context context) { |
| 6490 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6491 | |
| 6492 | /** |
| 6493 | * @hide |
| 6494 | */ |
| 6495 | public abstract boolean areNotificationsVisiblyDifferent(Style other); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 6496 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6497 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6498 | * @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] | 6499 | * If {@code null} is returned, the default implementation will be used. |
| 6500 | * |
| 6501 | * @hide |
| 6502 | */ |
| 6503 | public CharSequence getHeadsUpStatusBarText() { |
| 6504 | return null; |
| 6505 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 6506 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6507 | |
| 6508 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6509 | * 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] | 6510 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6511 | * 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] | 6512 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6513 | * Notification notif = new Notification.Builder(mContext) |
| 6514 | * .setContentTitle("New photo from " + sender.toString()) |
| 6515 | * .setContentText(subject) |
| 6516 | * .setSmallIcon(R.drawable.new_post) |
| 6517 | * .setLargeIcon(aBitmap) |
| 6518 | * .setStyle(new Notification.BigPictureStyle() |
| 6519 | * .bigPicture(aBigBitmap)) |
| 6520 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6521 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6522 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6523 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6524 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6525 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6526 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6527 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6528 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6529 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6530 | public BigPictureStyle() { |
| 6531 | } |
| 6532 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6533 | /** |
| 6534 | * @deprecated use {@code BigPictureStyle()}. |
| 6535 | */ |
| 6536 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6537 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6538 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6539 | } |
| 6540 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6541 | /** |
| 6542 | * Overrides ContentTitle in the big form of the template. |
| 6543 | * This defaults to the value passed to setContentTitle(). |
| 6544 | */ |
| 6545 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6546 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6547 | return this; |
| 6548 | } |
| 6549 | |
| 6550 | /** |
| 6551 | * Set the first line of text after the detail section in the big form of the template. |
| 6552 | */ |
| 6553 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6554 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6555 | return this; |
| 6556 | } |
| 6557 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6558 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6559 | * @hide |
| 6560 | */ |
| 6561 | public Bitmap getBigPicture() { |
| 6562 | return mPicture; |
| 6563 | } |
| 6564 | |
| 6565 | /** |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6566 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 6567 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6568 | public BigPictureStyle bigPicture(Bitmap b) { |
| 6569 | mPicture = b; |
| 6570 | return this; |
| 6571 | } |
| 6572 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6573 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6574 | * Override the large icon when the big notification is shown. |
| 6575 | */ |
| 6576 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6577 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 6578 | } |
| 6579 | |
| 6580 | /** |
| 6581 | * Override the large icon when the big notification is shown. |
| 6582 | */ |
| 6583 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6584 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6585 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6586 | return this; |
| 6587 | } |
| 6588 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6589 | /** @hide */ |
| 6590 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 6591 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6592 | /** |
| 6593 | * @hide |
| 6594 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6595 | @Override |
| 6596 | public void purgeResources() { |
| 6597 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 6598 | if (mPicture != null && |
| 6599 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6600 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6601 | mPicture = mPicture.createAshmemBitmap(); |
| 6602 | } |
| 6603 | if (mBigLargeIcon != null) { |
| 6604 | mBigLargeIcon.convertToAshmem(); |
| 6605 | } |
| 6606 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6607 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6608 | /** |
| 6609 | * @hide |
| 6610 | */ |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6611 | @Override |
| 6612 | public void reduceImageSizes(Context context) { |
| 6613 | super.reduceImageSizes(context); |
| 6614 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6615 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6616 | if (mPicture != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6617 | int maxPictureWidth = resources.getDimensionPixelSize(isLowRam |
| 6618 | ? R.dimen.notification_big_picture_max_height_low_ram |
| 6619 | : R.dimen.notification_big_picture_max_height); |
| 6620 | int maxPictureHeight = resources.getDimensionPixelSize(isLowRam |
| 6621 | ? R.dimen.notification_big_picture_max_width_low_ram |
| 6622 | : R.dimen.notification_big_picture_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6623 | mPicture = Icon.scaleDownIfNecessary(mPicture, maxPictureWidth, maxPictureHeight); |
| 6624 | } |
| 6625 | if (mBigLargeIcon != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6626 | int rightIconSize = resources.getDimensionPixelSize(isLowRam |
| 6627 | ? R.dimen.notification_right_icon_size_low_ram |
| 6628 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6629 | mBigLargeIcon.scaleDownIfNecessary(rightIconSize, rightIconSize); |
| 6630 | } |
| 6631 | } |
| 6632 | |
| 6633 | /** |
| 6634 | * @hide |
| 6635 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6636 | public RemoteViews makeBigContentView() { |
| 6637 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6638 | // This covers the following cases: |
| 6639 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6640 | // mN.mLargeIcon |
| 6641 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6642 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6643 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6644 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6645 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 6646 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6647 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 6648 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 6649 | // for old listeners, this is in general non-null. |
| 6650 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 6651 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6652 | } |
| 6653 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6654 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6655 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource(), |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6656 | p, null /* result */); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6657 | if (mSummaryTextSet) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6658 | contentView.setTextViewText(R.id.text, mBuilder.processTextSpans( |
| 6659 | mBuilder.processLegacyText(mSummaryText))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6660 | mBuilder.setTextViewColorSecondary(contentView, R.id.text, p); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 6661 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6662 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6663 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 6664 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6665 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6666 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6667 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6668 | } |
| 6669 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6670 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6671 | return contentView; |
| 6672 | } |
| 6673 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6674 | /** |
| 6675 | * @hide |
| 6676 | */ |
| 6677 | public void addExtras(Bundle extras) { |
| 6678 | super.addExtras(extras); |
| 6679 | |
| 6680 | if (mBigLargeIconSet) { |
| 6681 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 6682 | } |
| 6683 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 6684 | } |
| 6685 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6686 | /** |
| 6687 | * @hide |
| 6688 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6689 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6690 | protected void restoreFromExtras(Bundle extras) { |
| 6691 | super.restoreFromExtras(extras); |
| 6692 | |
| 6693 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6694 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6695 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6696 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6697 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 6698 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6699 | |
| 6700 | /** |
| 6701 | * @hide |
| 6702 | */ |
| 6703 | @Override |
| 6704 | public boolean hasSummaryInHeader() { |
| 6705 | return false; |
| 6706 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6707 | |
| 6708 | /** |
| 6709 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6710 | * Note that we aren't actually comparing the contents of the bitmaps here, so this |
| 6711 | * 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] | 6712 | */ |
| 6713 | @Override |
| 6714 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6715 | if (other == null || getClass() != other.getClass()) { |
| 6716 | return true; |
| 6717 | } |
| 6718 | BigPictureStyle otherS = (BigPictureStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6719 | return areBitmapsObviouslyDifferent(getBigPicture(), otherS.getBigPicture()); |
| 6720 | } |
| 6721 | |
| 6722 | private static boolean areBitmapsObviouslyDifferent(Bitmap a, Bitmap b) { |
| 6723 | if (a == b) { |
| 6724 | return false; |
| 6725 | } |
| 6726 | if (a == null || b == null) { |
| 6727 | return true; |
| 6728 | } |
| 6729 | return a.getWidth() != b.getWidth() |
| 6730 | || a.getHeight() != b.getHeight() |
| 6731 | || a.getConfig() != b.getConfig() |
| 6732 | || a.getGenerationId() != b.getGenerationId(); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6733 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6734 | } |
| 6735 | |
| 6736 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6737 | * 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] | 6738 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6739 | * 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] | 6740 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6741 | * Notification notif = new Notification.Builder(mContext) |
| 6742 | * .setContentTitle("New mail from " + sender.toString()) |
| 6743 | * .setContentText(subject) |
| 6744 | * .setSmallIcon(R.drawable.new_mail) |
| 6745 | * .setLargeIcon(aBitmap) |
| 6746 | * .setStyle(new Notification.BigTextStyle() |
| 6747 | * .bigText(aVeryLongString)) |
| 6748 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6749 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6750 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6751 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6752 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6753 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6754 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6755 | private CharSequence mBigText; |
| 6756 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6757 | public BigTextStyle() { |
| 6758 | } |
| 6759 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6760 | /** |
| 6761 | * @deprecated use {@code BigTextStyle()}. |
| 6762 | */ |
| 6763 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6764 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6765 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6766 | } |
| 6767 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6768 | /** |
| 6769 | * Overrides ContentTitle in the big form of the template. |
| 6770 | * This defaults to the value passed to setContentTitle(). |
| 6771 | */ |
| 6772 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6773 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6774 | return this; |
| 6775 | } |
| 6776 | |
| 6777 | /** |
| 6778 | * Set the first line of text after the detail section in the big form of the template. |
| 6779 | */ |
| 6780 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6781 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6782 | return this; |
| 6783 | } |
| 6784 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6785 | /** |
| 6786 | * Provide the longer text to be displayed in the big form of the |
| 6787 | * template in place of the content text. |
| 6788 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6789 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6790 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6791 | return this; |
| 6792 | } |
| 6793 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6794 | /** |
| 6795 | * @hide |
| 6796 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6797 | public CharSequence getBigText() { |
| 6798 | return mBigText; |
| 6799 | } |
| 6800 | |
| 6801 | /** |
| 6802 | * @hide |
| 6803 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6804 | public void addExtras(Bundle extras) { |
| 6805 | super.addExtras(extras); |
| 6806 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6807 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 6808 | } |
| 6809 | |
| 6810 | /** |
| 6811 | * @hide |
| 6812 | */ |
| 6813 | @Override |
| 6814 | protected void restoreFromExtras(Bundle extras) { |
| 6815 | super.restoreFromExtras(extras); |
| 6816 | |
| 6817 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6818 | } |
| 6819 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6820 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6821 | * @param increasedHeight true if this layout be created with an increased height. |
| 6822 | * |
| 6823 | * @hide |
| 6824 | */ |
| 6825 | @Override |
| 6826 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6827 | if (increasedHeight) { |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6828 | mBuilder.mOriginalActions = mBuilder.mActions; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6829 | mBuilder.mActions = new ArrayList<>(); |
| 6830 | RemoteViews remoteViews = makeBigContentView(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6831 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6832 | mBuilder.mOriginalActions = null; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6833 | return remoteViews; |
| 6834 | } |
| 6835 | return super.makeContentView(increasedHeight); |
| 6836 | } |
| 6837 | |
| 6838 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6839 | * @hide |
| 6840 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6841 | @Override |
| 6842 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 6843 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 6844 | return makeBigContentView(); |
| 6845 | } |
| 6846 | return super.makeHeadsUpContentView(increasedHeight); |
| 6847 | } |
| 6848 | |
| 6849 | /** |
| 6850 | * @hide |
| 6851 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6852 | public RemoteViews makeBigContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6853 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder).text(null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6854 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6855 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource(), p, |
| 6856 | result); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 6857 | contentView.setInt(R.id.big_text, "setImageEndMargin", result.getIconMarginEnd()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6858 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 6859 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6860 | if (TextUtils.isEmpty(bigTextText)) { |
| 6861 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 6862 | // experience |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6863 | bigTextText = mBuilder.processLegacyText( |
| 6864 | mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT)); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6865 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6866 | contentView.setTextViewText(R.id.big_text, mBuilder.processTextSpans(bigTextText)); |
| 6867 | mBuilder.setTextViewColorSecondary(contentView, R.id.big_text, p); |
| 6868 | contentView.setViewVisibility(R.id.big_text, |
| 6869 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 6870 | contentView.setBoolean(R.id.big_text, "setHasImage", |
| 6871 | result.isRightIconContainerVisible()); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 6872 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6873 | return contentView; |
| 6874 | } |
| 6875 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6876 | /** |
| 6877 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6878 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6879 | */ |
| 6880 | @Override |
| 6881 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6882 | if (other == null || getClass() != other.getClass()) { |
| 6883 | return true; |
| 6884 | } |
| 6885 | BigTextStyle newS = (BigTextStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6886 | return !Objects.equals(String.valueOf(getBigText()), String.valueOf(newS.getBigText())); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6887 | } |
| 6888 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6889 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6890 | |
| 6891 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6892 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 6893 | * messages of varying types between any number of people. |
| 6894 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6895 | * <p> |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6896 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 6897 | * user will always see the normal notification view. |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6898 | * |
| 6899 | * <p> |
| 6900 | * If the app is targeting Android P and above, it is required to use the {@link Person} |
| 6901 | * class in order to get an optimal rendering of the notification and its avatars. For |
| 6902 | * conversations involving multiple people, the app should also make sure that it marks the |
| 6903 | * conversation as a group with {@link #setGroupConversation(boolean)}. |
| 6904 | * |
| 6905 | * <p> |
| 6906 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior. |
| 6907 | * Here's an example of how this may be used: |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6908 | * <pre class="prettyprint"> |
| 6909 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6910 | * Person user = new Person.Builder().setIcon(userIcon).setName(userName).build(); |
| 6911 | * MessagingStyle style = new MessagingStyle(user) |
| 6912 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getPerson()) |
| 6913 | * .addMessage(messages[2].getText(), messages[2].getTime(), messages[2].getPerson()) |
| 6914 | * .setGroupConversation(hasMultiplePeople()); |
| 6915 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6916 | * Notification noti = new Notification.Builder() |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6917 | * .setContentTitle("2 new messages with " + sender.toString()) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6918 | * .setContentText(subject) |
| 6919 | * .setSmallIcon(R.drawable.new_message) |
| 6920 | * .setLargeIcon(aBitmap) |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6921 | * .setStyle(style) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6922 | * .build(); |
| 6923 | * </pre> |
| 6924 | */ |
| 6925 | public static class MessagingStyle extends Style { |
| 6926 | |
| 6927 | /** |
| 6928 | * The maximum number of messages that will be retained in the Notification itself (the |
| 6929 | * number displayed is up to the platform). |
| 6930 | */ |
| 6931 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 6932 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6933 | @NonNull Person mUser; |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6934 | @Nullable CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6935 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6936 | List<Message> mHistoricMessages = new ArrayList<>(); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6937 | boolean mIsGroupConversation; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6938 | |
| 6939 | MessagingStyle() { |
| 6940 | } |
| 6941 | |
| 6942 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6943 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 6944 | * user before the posting app reposts the notification with those messages after they've |
| 6945 | * 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] | 6946 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6947 | * |
| 6948 | * @deprecated use {@code MessagingStyle(Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6949 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6950 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6951 | this(new Person.Builder().setName(userDisplayName).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6952 | } |
| 6953 | |
| 6954 | /** |
| 6955 | * @param user Required - The person displayed for any messages that are sent by the |
| 6956 | * user. Any messages added with {@link #addMessage(Notification.MessagingStyle.Message)} |
| 6957 | * 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] | 6958 | * by this user. The user also needs to have a valid name associated with it, which will |
| 6959 | * be enforced starting in Android P. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6960 | */ |
| 6961 | public MessagingStyle(@NonNull Person user) { |
| 6962 | mUser = user; |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | /** |
| 6966 | * Validate that this style was properly composed. This is called at build time. |
| 6967 | * @hide |
| 6968 | */ |
| 6969 | @Override |
| 6970 | public void validate(Context context) { |
| 6971 | super.validate(context); |
| 6972 | if (context.getApplicationInfo().targetSdkVersion |
| 6973 | >= Build.VERSION_CODES.P && (mUser == null || mUser.getName() == null)) { |
| 6974 | throw new RuntimeException("User must be valid and have a name."); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6975 | } |
| 6976 | } |
| 6977 | |
| 6978 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6979 | * @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] | 6980 | * If {@code null} is returned, the default implementation will be used. |
| 6981 | * |
| 6982 | * @hide |
| 6983 | */ |
| 6984 | @Override |
| 6985 | public CharSequence getHeadsUpStatusBarText() { |
| 6986 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
| 6987 | ? super.mBigContentTitle |
| 6988 | : mConversationTitle; |
| 6989 | if (!TextUtils.isEmpty(conversationTitle) && !hasOnlyWhiteSpaceSenders()) { |
| 6990 | return conversationTitle; |
| 6991 | } |
| 6992 | return null; |
| 6993 | } |
| 6994 | |
| 6995 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6996 | * @return the user to be displayed for any replies sent by the user |
| 6997 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6998 | @NonNull |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6999 | public Person getUser() { |
| 7000 | return mUser; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7001 | } |
| 7002 | |
| 7003 | /** |
| 7004 | * 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] | 7005 | * |
| 7006 | * @deprecated use {@link #getUser()} instead |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7007 | */ |
| 7008 | public CharSequence getUserDisplayName() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7009 | return mUser.getName(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7013 | * Sets the title to be displayed on this conversation. May be set to {@code null}. |
| 7014 | * |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7015 | * <p>This API's behavior was changed in SDK version {@link Build.VERSION_CODES#P}. If your |
| 7016 | * application's target version is less than {@link Build.VERSION_CODES#P}, setting a |
| 7017 | * conversation title to a non-null value will make {@link #isGroupConversation()} return |
| 7018 | * {@code true} and passing {@code null} will make it return {@code false}. In |
| 7019 | * {@link Build.VERSION_CODES#P} and beyond, use {@link #setGroupConversation(boolean)} |
| 7020 | * to set group conversation status. |
| 7021 | * |
| 7022 | * @param conversationTitle Title displayed for this conversation |
| 7023 | * @return this object for method chaining |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7024 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7025 | public MessagingStyle setConversationTitle(@Nullable CharSequence conversationTitle) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7026 | mConversationTitle = conversationTitle; |
| 7027 | return this; |
| 7028 | } |
| 7029 | |
| 7030 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7031 | * 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] | 7032 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7033 | @Nullable |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7034 | public CharSequence getConversationTitle() { |
| 7035 | return mConversationTitle; |
| 7036 | } |
| 7037 | |
| 7038 | /** |
| 7039 | * Adds a message for display by this notification. Convenience call for a simple |
| 7040 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 7041 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7042 | * @param timestamp Time at which the message arrived |
| 7043 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 7044 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 7045 | * the platform will insert {@link #getUserDisplayName()}. |
| 7046 | * Should be unique amongst all individuals in the conversation, and should be |
| 7047 | * consistent during re-posts of the notification. |
| 7048 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 7049 | * @see Message#Notification.MessagingStyle.Message(CharSequence, long, CharSequence) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7050 | * |
| 7051 | * @return this object for method chaining |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7052 | * |
| 7053 | * @deprecated use {@link #addMessage(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7054 | */ |
| 7055 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7056 | return addMessage(text, timestamp, |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7057 | sender == null ? null : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7058 | } |
| 7059 | |
| 7060 | /** |
| 7061 | * Adds a message for display by this notification. Convenience call for a simple |
| 7062 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 7063 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7064 | * @param timestamp Time at which the message arrived |
| 7065 | * @param sender The {@link Person} who sent the message. |
| 7066 | * Should be <code>null</code> for messages by the current user, in which case |
| 7067 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7068 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 7069 | * @see Message#Notification.MessagingStyle.Message(CharSequence, long, CharSequence) |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7070 | * |
| 7071 | * @return this object for method chaining |
| 7072 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 7073 | public MessagingStyle addMessage(@NonNull CharSequence text, long timestamp, |
| 7074 | @Nullable Person sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7075 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7076 | } |
| 7077 | |
| 7078 | /** |
| 7079 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7080 | * |
| 7081 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 7082 | * the newest last. |
| 7083 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7084 | * @param message The {@link Message} to be displayed |
| 7085 | * @return this object for method chaining |
| 7086 | */ |
| 7087 | public MessagingStyle addMessage(Message message) { |
| 7088 | mMessages.add(message); |
| 7089 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 7090 | mMessages.remove(0); |
| 7091 | } |
| 7092 | return this; |
| 7093 | } |
| 7094 | |
| 7095 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7096 | * Adds a {@link Message} for historic context in this notification. |
| 7097 | * |
| 7098 | * <p>Messages should be added as historic if they are not the main subject of the |
| 7099 | * notification but may give context to a conversation. The system may choose to present |
| 7100 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 7101 | * |
| 7102 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 7103 | * the newest last. |
| 7104 | * |
| 7105 | * @param message The historic {@link Message} to be added |
| 7106 | * @return this object for method chaining |
| 7107 | */ |
| 7108 | public MessagingStyle addHistoricMessage(Message message) { |
| 7109 | mHistoricMessages.add(message); |
| 7110 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 7111 | mHistoricMessages.remove(0); |
| 7112 | } |
| 7113 | return this; |
| 7114 | } |
| 7115 | |
| 7116 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7117 | * Gets the list of {@code Message} objects that represent the notification |
| 7118 | */ |
| 7119 | public List<Message> getMessages() { |
| 7120 | return mMessages; |
| 7121 | } |
| 7122 | |
| 7123 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7124 | * Gets the list of historic {@code Message}s in the notification. |
| 7125 | */ |
| 7126 | public List<Message> getHistoricMessages() { |
| 7127 | return mHistoricMessages; |
| 7128 | } |
| 7129 | |
| 7130 | /** |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7131 | * Sets whether this conversation notification represents a group. If the app is targeting |
| 7132 | * Android P, this is required if the app wants to display the largeIcon set with |
| 7133 | * {@link Notification.Builder#setLargeIcon(Bitmap)}, otherwise it will be hidden. |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7134 | * |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7135 | * @param isGroupConversation {@code true} if the conversation represents a group, |
| 7136 | * {@code false} otherwise. |
| 7137 | * @return this object for method chaining |
| 7138 | */ |
| 7139 | public MessagingStyle setGroupConversation(boolean isGroupConversation) { |
| 7140 | mIsGroupConversation = isGroupConversation; |
| 7141 | return this; |
| 7142 | } |
| 7143 | |
| 7144 | /** |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7145 | * Returns {@code true} if this notification represents a group conversation, otherwise |
| 7146 | * {@code false}. |
| 7147 | * |
| 7148 | * <p> If the application that generated this {@link MessagingStyle} targets an SDK version |
| 7149 | * less than {@link Build.VERSION_CODES#P}, this method becomes dependent on whether or |
| 7150 | * not the conversation title is set; returning {@code true} if the conversation title is |
| 7151 | * a non-null value, or {@code false} otherwise. From {@link Build.VERSION_CODES#P} forward, |
| 7152 | * this method returns what's set by {@link #setGroupConversation(boolean)} allowing for |
| 7153 | * named, non-group conversations. |
| 7154 | * |
| 7155 | * @see #setConversationTitle(CharSequence) |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7156 | */ |
| 7157 | public boolean isGroupConversation() { |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7158 | // When target SDK version is < P, a non-null conversation title dictates if this is |
| 7159 | // as group conversation. |
| 7160 | if (mBuilder != null |
| 7161 | && mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 7162 | < Build.VERSION_CODES.P) { |
| 7163 | return mConversationTitle != null; |
| 7164 | } |
| 7165 | |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7166 | return mIsGroupConversation; |
| 7167 | } |
| 7168 | |
| 7169 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7170 | * @hide |
| 7171 | */ |
| 7172 | @Override |
| 7173 | public void addExtras(Bundle extras) { |
| 7174 | super.addExtras(extras); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7175 | if (mUser != null) { |
| 7176 | // For legacy usages |
| 7177 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUser.getName()); |
| 7178 | extras.putParcelable(EXTRA_MESSAGING_PERSON, mUser); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7179 | } |
| 7180 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7181 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7182 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7183 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 7184 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7185 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7186 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 7187 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 7188 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7189 | |
| 7190 | fixTitleAndTextExtras(extras); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7191 | extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7192 | } |
| 7193 | |
| 7194 | private void fixTitleAndTextExtras(Bundle extras) { |
| 7195 | Message m = findLatestIncomingMessage(); |
| 7196 | CharSequence text = (m == null) ? null : m.mText; |
| 7197 | CharSequence sender = m == null ? null |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7198 | : m.mSender == null || TextUtils.isEmpty(m.mSender.getName()) |
| 7199 | ? mUser.getName() : m.mSender.getName(); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7200 | CharSequence title; |
| 7201 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 7202 | if (!TextUtils.isEmpty(sender)) { |
| 7203 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 7204 | title = mBuilder.mContext.getString( |
| 7205 | com.android.internal.R.string.notification_messaging_title_template, |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7206 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(sender)); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7207 | } else { |
| 7208 | title = mConversationTitle; |
| 7209 | } |
| 7210 | } else { |
| 7211 | title = sender; |
| 7212 | } |
| 7213 | |
| 7214 | if (title != null) { |
| 7215 | extras.putCharSequence(EXTRA_TITLE, title); |
| 7216 | } |
| 7217 | if (text != null) { |
| 7218 | extras.putCharSequence(EXTRA_TEXT, text); |
| 7219 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7220 | } |
| 7221 | |
| 7222 | /** |
| 7223 | * @hide |
| 7224 | */ |
| 7225 | @Override |
| 7226 | protected void restoreFromExtras(Bundle extras) { |
| 7227 | super.restoreFromExtras(extras); |
| 7228 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7229 | mUser = extras.getParcelable(EXTRA_MESSAGING_PERSON); |
| 7230 | if (mUser == null) { |
| 7231 | CharSequence displayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7232 | mUser = new Person.Builder().setName(displayName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7233 | } |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 7234 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7235 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7236 | mMessages = Message.getMessagesFromBundleArray(messages); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7237 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7238 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7239 | mIsGroupConversation = extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7240 | } |
| 7241 | |
| 7242 | /** |
| 7243 | * @hide |
| 7244 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7245 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7246 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7247 | mBuilder.mOriginalActions = mBuilder.mActions; |
| 7248 | mBuilder.mActions = new ArrayList<>(); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7249 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7250 | false /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7251 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 7252 | mBuilder.mOriginalActions = null; |
| 7253 | return remoteViews; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7254 | } |
| 7255 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7256 | /** |
| 7257 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7258 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7259 | */ |
| 7260 | @Override |
| 7261 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7262 | if (other == null || getClass() != other.getClass()) { |
| 7263 | return true; |
| 7264 | } |
| 7265 | MessagingStyle newS = (MessagingStyle) other; |
| 7266 | List<MessagingStyle.Message> oldMs = getMessages(); |
| 7267 | List<MessagingStyle.Message> newMs = newS.getMessages(); |
| 7268 | |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7269 | if (oldMs == null || newMs == null) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7270 | newMs = new ArrayList<>(); |
| 7271 | } |
| 7272 | |
| 7273 | int n = oldMs.size(); |
| 7274 | if (n != newMs.size()) { |
| 7275 | return true; |
| 7276 | } |
| 7277 | for (int i = 0; i < n; i++) { |
| 7278 | MessagingStyle.Message oldM = oldMs.get(i); |
| 7279 | MessagingStyle.Message newM = newMs.get(i); |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7280 | if (!Objects.equals( |
| 7281 | String.valueOf(oldM.getText()), |
| 7282 | String.valueOf(newM.getText()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7283 | return true; |
| 7284 | } |
| 7285 | if (!Objects.equals(oldM.getDataUri(), newM.getDataUri())) { |
| 7286 | return true; |
| 7287 | } |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7288 | String oldSender = String.valueOf(oldM.getSenderPerson() == null |
| 7289 | ? oldM.getSender() |
| 7290 | : oldM.getSenderPerson().getName()); |
| 7291 | String newSender = String.valueOf(newM.getSenderPerson() == null |
| 7292 | ? newM.getSender() |
| 7293 | : newM.getSenderPerson().getName()); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7294 | if (!Objects.equals(oldSender, newSender)) { |
| 7295 | return true; |
| 7296 | } |
| 7297 | |
| 7298 | String oldKey = oldM.getSenderPerson() == null |
| 7299 | ? null : oldM.getSenderPerson().getKey(); |
| 7300 | String newKey = newM.getSenderPerson() == null |
| 7301 | ? null : newM.getSenderPerson().getKey(); |
| 7302 | if (!Objects.equals(oldKey, newKey)) { |
| 7303 | return true; |
| 7304 | } |
| 7305 | // Other fields (like timestamp) intentionally excluded |
| 7306 | } |
| 7307 | return false; |
| 7308 | } |
| 7309 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7310 | private Message findLatestIncomingMessage() { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7311 | return findLatestIncomingMessage(mMessages); |
| 7312 | } |
| 7313 | |
| 7314 | /** |
| 7315 | * @hide |
| 7316 | */ |
| 7317 | @Nullable |
| 7318 | public static Message findLatestIncomingMessage( |
| 7319 | List<Message> messages) { |
| 7320 | for (int i = messages.size() - 1; i >= 0; i--) { |
| 7321 | Message m = messages.get(i); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7322 | // Incoming messages have a non-empty sender. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7323 | if (m.mSender != null && !TextUtils.isEmpty(m.mSender.getName())) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7324 | return m; |
| 7325 | } |
| 7326 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7327 | if (!messages.isEmpty()) { |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7328 | // No incoming messages, fall back to outgoing message |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7329 | return messages.get(messages.size() - 1); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7330 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7331 | return null; |
| 7332 | } |
| 7333 | |
| 7334 | /** |
| 7335 | * @hide |
| 7336 | */ |
| 7337 | @Override |
| 7338 | public RemoteViews makeBigContentView() { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7339 | return makeMessagingView(false /* displayImagesAtEnd */, true /* hideLargeIcon */); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7340 | } |
| 7341 | |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7342 | /** |
| 7343 | * Create a messaging layout. |
| 7344 | * |
| 7345 | * @param displayImagesAtEnd should images be displayed at the end of the content instead |
| 7346 | * of inline. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7347 | * @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] | 7348 | * @return the created remoteView. |
| 7349 | */ |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7350 | @NonNull |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7351 | private RemoteViews makeMessagingView(boolean displayImagesAtEnd, boolean hideRightIcons) { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7352 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7353 | ? super.mBigContentTitle |
| 7354 | : mConversationTitle; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7355 | boolean atLeastP = mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 7356 | >= Build.VERSION_CODES.P; |
| 7357 | boolean isOneToOne; |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7358 | CharSequence nameReplacement = null; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7359 | Icon avatarReplacement = null; |
| 7360 | if (!atLeastP) { |
| 7361 | isOneToOne = TextUtils.isEmpty(conversationTitle); |
| 7362 | avatarReplacement = mBuilder.mN.mLargeIcon; |
| 7363 | if (hasOnlyWhiteSpaceSenders()) { |
| 7364 | isOneToOne = true; |
| 7365 | nameReplacement = conversationTitle; |
| 7366 | conversationTitle = null; |
| 7367 | } |
| 7368 | } else { |
| 7369 | isOneToOne = !isGroupConversation(); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 7370 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7371 | TemplateBindResult bindResult = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7372 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).title( |
| 7373 | conversationTitle).text(null) |
| 7374 | .hideLargeIcon(hideRightIcons || isOneToOne) |
| 7375 | .hideReplyIcon(hideRightIcons) |
| 7376 | .headerTextSecondary(conversationTitle); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 7377 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7378 | mBuilder.getMessagingLayoutResource(), |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7379 | p, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7380 | bindResult); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7381 | addExtras(mBuilder.mN.extras); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7382 | // also update the end margin if there is an image |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7383 | contentView.setViewLayoutMarginEnd(R.id.notification_messaging, |
| 7384 | bindResult.getIconMarginEnd()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7385 | contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7386 | mBuilder.isColorized(p) ? mBuilder.getPrimaryTextColor(p) |
| 7387 | : mBuilder.resolveContrastColor(p)); |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 7388 | contentView.setInt(R.id.status_bar_latest_event_content, "setSenderTextColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7389 | mBuilder.getPrimaryTextColor(p)); |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 7390 | contentView.setInt(R.id.status_bar_latest_event_content, "setMessageTextColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7391 | mBuilder.getSecondaryTextColor(p)); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7392 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd", |
| 7393 | displayImagesAtEnd); |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7394 | contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement", |
| 7395 | avatarReplacement); |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7396 | contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement", |
| 7397 | nameReplacement); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7398 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne", |
| 7399 | isOneToOne); |
| 7400 | contentView.setBundle(R.id.status_bar_latest_event_content, "setData", |
| 7401 | mBuilder.mN.extras); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7402 | return contentView; |
| 7403 | } |
| 7404 | |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7405 | private boolean hasOnlyWhiteSpaceSenders() { |
| 7406 | for (int i = 0; i < mMessages.size(); i++) { |
| 7407 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7408 | Person sender = m.getSenderPerson(); |
| 7409 | if (sender != null && !isWhiteSpace(sender.getName())) { |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7410 | return false; |
| 7411 | } |
| 7412 | } |
| 7413 | return true; |
| 7414 | } |
| 7415 | |
| 7416 | private boolean isWhiteSpace(CharSequence sender) { |
| 7417 | if (TextUtils.isEmpty(sender)) { |
| 7418 | return true; |
| 7419 | } |
| 7420 | if (sender.toString().matches("^\\s*$")) { |
| 7421 | return true; |
| 7422 | } |
| 7423 | // Let's check if we only have 0 whitespace chars. Some apps did this as a workaround |
| 7424 | // For the presentation that we had. |
| 7425 | for (int i = 0; i < sender.length(); i++) { |
| 7426 | char c = sender.charAt(i); |
| 7427 | if (c != '\u200B') { |
| 7428 | return false; |
| 7429 | } |
| 7430 | } |
| 7431 | return true; |
| 7432 | } |
| 7433 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7434 | private CharSequence createConversationTitleFromMessages() { |
| 7435 | ArraySet<CharSequence> names = new ArraySet<>(); |
| 7436 | for (int i = 0; i < mMessages.size(); i++) { |
| 7437 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7438 | Person sender = m.getSenderPerson(); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7439 | if (sender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7440 | names.add(sender.getName()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7441 | } |
| 7442 | } |
| 7443 | SpannableStringBuilder title = new SpannableStringBuilder(); |
| 7444 | int size = names.size(); |
| 7445 | for (int i = 0; i < size; i++) { |
| 7446 | CharSequence name = names.valueAt(i); |
| 7447 | if (!TextUtils.isEmpty(title)) { |
| 7448 | title.append(", "); |
| 7449 | } |
| 7450 | title.append(BidiFormatter.getInstance().unicodeWrap(name)); |
| 7451 | } |
| 7452 | return title; |
| 7453 | } |
| 7454 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7455 | /** |
| 7456 | * @hide |
| 7457 | */ |
| 7458 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7459 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7460 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7461 | true /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7462 | remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1); |
| 7463 | return remoteViews; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7464 | } |
| 7465 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7466 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 7467 | return new TextAppearanceSpan(null, 0, 0, |
| 7468 | ColorStateList.valueOf(color), null); |
| 7469 | } |
| 7470 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7471 | public static final class Message { |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 7472 | /** @hide */ |
| 7473 | public static final String KEY_TEXT = "text"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7474 | static final String KEY_TIMESTAMP = "time"; |
| 7475 | static final String KEY_SENDER = "sender"; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7476 | static final String KEY_SENDER_PERSON = "sender_person"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7477 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 7478 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7479 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7480 | static final String KEY_REMOTE_INPUT_HISTORY = "remote_input_history"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7481 | |
| 7482 | private final CharSequence mText; |
| 7483 | private final long mTimestamp; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7484 | @Nullable |
| 7485 | private final Person mSender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7486 | /** True if this message was generated from the extra |
| 7487 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY} |
| 7488 | */ |
| 7489 | private final boolean mRemoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7490 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7491 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7492 | private String mDataMimeType; |
| 7493 | private Uri mDataUri; |
| 7494 | |
| 7495 | /** |
| 7496 | * Constructor |
| 7497 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7498 | * @param timestamp Time at which the message arrived |
| 7499 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 7500 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 7501 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 7502 | * Should be unique amongst all individuals in the conversation, and should be |
| 7503 | * consistent during re-posts of the notification. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7504 | * |
| 7505 | * @deprecated use {@code Message(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7506 | */ |
| 7507 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7508 | this(text, timestamp, sender == null ? null |
| 7509 | : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | /** |
| 7513 | * Constructor |
| 7514 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7515 | * @param timestamp Time at which the message arrived |
| 7516 | * @param sender The {@link Person} who sent the message. |
| 7517 | * Should be <code>null</code> for messages by the current user, in which case |
| 7518 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7519 | * <p> |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7520 | * The person provided should contain an Icon, set with |
| 7521 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7522 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7523 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7524 | * to differentiate between the different users. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7525 | * </p> |
| 7526 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 7527 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7528 | this(text, timestamp, sender, false /* remoteHistory */); |
| 7529 | } |
| 7530 | |
| 7531 | /** |
| 7532 | * Constructor |
| 7533 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7534 | * @param timestamp Time at which the message arrived |
| 7535 | * @param sender The {@link Person} who sent the message. |
| 7536 | * Should be <code>null</code> for messages by the current user, in which case |
| 7537 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7538 | * @param remoteInputHistory True if the messages was generated from the extra |
| 7539 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7540 | * <p> |
| 7541 | * The person provided should contain an Icon, set with |
| 7542 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7543 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7544 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7545 | * to differentiate between the different users. |
| 7546 | * </p> |
| 7547 | * @hide |
| 7548 | */ |
| 7549 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender, |
| 7550 | boolean remoteInputHistory) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7551 | mText = text; |
| 7552 | mTimestamp = timestamp; |
| 7553 | mSender = sender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7554 | mRemoteInputHistory = remoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7555 | } |
| 7556 | |
| 7557 | /** |
| 7558 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 7559 | * where the platform doesn't support the MIME type, the original text provided in the |
| 7560 | * constructor will be used. |
| 7561 | * @param dataMimeType The MIME type of the content. See |
| 7562 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 7563 | * types on Android and Android Wear. |
| 7564 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 7565 | * <p class="note"> |
| 7566 | * <ol> |
| 7567 | * <li>Notification Listeners including the System UI need permission to access the |
| 7568 | * data the Uri points to. The recommended ways to do this are:</li> |
| 7569 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 7570 | * the correct permission to access your provider. The preferred mechanism for |
| 7571 | * providing access is to use per-URI permissions which are temporary and only |
| 7572 | * grant access to the receiving application. An easy way to create a |
| 7573 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 7574 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 7575 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 7576 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 7577 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 7578 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 7579 | * Note that once added to the system MediaStore the content is accessible to any |
| 7580 | * app on the device.</li> |
| 7581 | * </ol> |
| 7582 | * @return this object for method chaining |
| 7583 | */ |
| 7584 | public Message setData(String dataMimeType, Uri dataUri) { |
| 7585 | mDataMimeType = dataMimeType; |
| 7586 | mDataUri = dataUri; |
| 7587 | return this; |
| 7588 | } |
| 7589 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7590 | /** |
| 7591 | * Get the text to be used for this message, or the fallback text if a type and content |
| 7592 | * Uri have been set |
| 7593 | */ |
| 7594 | public CharSequence getText() { |
| 7595 | return mText; |
| 7596 | } |
| 7597 | |
| 7598 | /** |
| 7599 | * Get the time at which this message arrived |
| 7600 | */ |
| 7601 | public long getTimestamp() { |
| 7602 | return mTimestamp; |
| 7603 | } |
| 7604 | |
| 7605 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7606 | * Get the extras Bundle for this message. |
| 7607 | */ |
| 7608 | public Bundle getExtras() { |
| 7609 | return mExtras; |
| 7610 | } |
| 7611 | |
| 7612 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7613 | * 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] | 7614 | * |
| 7615 | * @deprecated use {@link #getSenderPerson()} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7616 | */ |
| 7617 | public CharSequence getSender() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7618 | return mSender == null ? null : mSender.getName(); |
| 7619 | } |
| 7620 | |
| 7621 | /** |
| 7622 | * Get the sender associated with this message. |
| 7623 | */ |
| 7624 | @Nullable |
| 7625 | public Person getSenderPerson() { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7626 | return mSender; |
| 7627 | } |
| 7628 | |
| 7629 | /** |
| 7630 | * Get the MIME type of the data pointed to by the Uri |
| 7631 | */ |
| 7632 | public String getDataMimeType() { |
| 7633 | return mDataMimeType; |
| 7634 | } |
| 7635 | |
| 7636 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 7637 | * 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] | 7638 | * {@see #getText()} is used. |
| 7639 | */ |
| 7640 | public Uri getDataUri() { |
| 7641 | return mDataUri; |
| 7642 | } |
| 7643 | |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7644 | /** |
| 7645 | * @return True if the message was generated from |
| 7646 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7647 | * @hide |
| 7648 | */ |
| 7649 | public boolean isRemoteInputHistory() { |
| 7650 | return mRemoteInputHistory; |
| 7651 | } |
| 7652 | |
Beverly | e98937a | 2018-11-15 10:18:57 -0500 | [diff] [blame] | 7653 | /** |
| 7654 | * @hide |
| 7655 | */ |
| 7656 | @VisibleForTesting |
| 7657 | public Bundle toBundle() { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7658 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7659 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7660 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7661 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7662 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7663 | if (mSender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7664 | // Legacy listeners need this |
| 7665 | bundle.putCharSequence(KEY_SENDER, mSender.getName()); |
| 7666 | bundle.putParcelable(KEY_SENDER_PERSON, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7667 | } |
| 7668 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7669 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7670 | } |
| 7671 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7672 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7673 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7674 | if (mExtras != null) { |
| 7675 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 7676 | } |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7677 | if (mRemoteInputHistory) { |
| 7678 | bundle.putBoolean(KEY_REMOTE_INPUT_HISTORY, mRemoteInputHistory); |
| 7679 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7680 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7681 | } |
| 7682 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7683 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 7684 | Bundle[] bundles = new Bundle[messages.size()]; |
| 7685 | final int N = messages.size(); |
| 7686 | for (int i = 0; i < N; i++) { |
| 7687 | bundles[i] = messages.get(i).toBundle(); |
| 7688 | } |
| 7689 | return bundles; |
| 7690 | } |
| 7691 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7692 | /** |
| 7693 | * @return A list of messages read from the bundles. |
| 7694 | * |
| 7695 | * @hide |
| 7696 | */ |
| 7697 | public static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
| 7698 | if (bundles == null) { |
| 7699 | return new ArrayList<>(); |
| 7700 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7701 | List<Message> messages = new ArrayList<>(bundles.length); |
| 7702 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7703 | if (bundles[i] instanceof Bundle) { |
| 7704 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 7705 | if (message != null) { |
| 7706 | messages.add(message); |
| 7707 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7708 | } |
| 7709 | } |
| 7710 | return messages; |
| 7711 | } |
| 7712 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 7713 | /** |
| 7714 | * @return The message that is stored in the bundle or null if the message couldn't be |
| 7715 | * resolved. |
| 7716 | * |
| 7717 | * @hide |
| 7718 | */ |
| 7719 | @Nullable |
| 7720 | public static Message getMessageFromBundle(Bundle bundle) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7721 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 7722 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7723 | return null; |
| 7724 | } else { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7725 | |
| 7726 | Person senderPerson = bundle.getParcelable(KEY_SENDER_PERSON); |
| 7727 | if (senderPerson == null) { |
| 7728 | // Legacy apps that use compat don't actually provide the sender objects |
| 7729 | // We need to fix the compat version to provide people / use |
| 7730 | // the native api instead |
| 7731 | CharSequence senderName = bundle.getCharSequence(KEY_SENDER); |
| 7732 | if (senderName != null) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7733 | senderPerson = new Person.Builder().setName(senderName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7734 | } |
| 7735 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7736 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7737 | bundle.getLong(KEY_TIMESTAMP), |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7738 | senderPerson, |
| 7739 | bundle.getBoolean(KEY_REMOTE_INPUT_HISTORY, false)); |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7740 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 7741 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7742 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 7743 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7744 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7745 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 7746 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 7747 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7748 | return message; |
| 7749 | } |
| 7750 | } catch (ClassCastException e) { |
| 7751 | return null; |
| 7752 | } |
| 7753 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7754 | } |
| 7755 | } |
| 7756 | |
| 7757 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7758 | * 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] | 7759 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7760 | * 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] | 7761 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7762 | * Notification notif = new Notification.Builder(mContext) |
| 7763 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 7764 | * .setContentText(subject) |
| 7765 | * .setSmallIcon(R.drawable.new_mail) |
| 7766 | * .setLargeIcon(aBitmap) |
| 7767 | * .setStyle(new Notification.InboxStyle() |
| 7768 | * .addLine(str1) |
| 7769 | * .addLine(str2) |
| 7770 | * .setContentTitle("") |
| 7771 | * .setSummaryText("+3 more")) |
| 7772 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7773 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 7774 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7775 | * @see Notification#bigContentView |
| 7776 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7777 | public static class InboxStyle extends Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7778 | |
| 7779 | /** |
| 7780 | * The number of lines of remote input history allowed until we start reducing lines. |
| 7781 | */ |
| 7782 | private static final int NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION = 1; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7783 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 7784 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7785 | public InboxStyle() { |
| 7786 | } |
| 7787 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7788 | /** |
| 7789 | * @deprecated use {@code InboxStyle()}. |
| 7790 | */ |
| 7791 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7792 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7793 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7794 | } |
| 7795 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7796 | /** |
| 7797 | * Overrides ContentTitle in the big form of the template. |
| 7798 | * This defaults to the value passed to setContentTitle(). |
| 7799 | */ |
| 7800 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7801 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7802 | return this; |
| 7803 | } |
| 7804 | |
| 7805 | /** |
| 7806 | * Set the first line of text after the detail section in the big form of the template. |
| 7807 | */ |
| 7808 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7809 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7810 | return this; |
| 7811 | } |
| 7812 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 7813 | /** |
| 7814 | * Append a line to the digest section of the Inbox notification. |
| 7815 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7816 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7817 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7818 | return this; |
| 7819 | } |
| 7820 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7821 | /** |
| 7822 | * @hide |
| 7823 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7824 | public ArrayList<CharSequence> getLines() { |
| 7825 | return mTexts; |
| 7826 | } |
| 7827 | |
| 7828 | /** |
| 7829 | * @hide |
| 7830 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7831 | public void addExtras(Bundle extras) { |
| 7832 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7833 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7834 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 7835 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 7836 | } |
| 7837 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7838 | /** |
| 7839 | * @hide |
| 7840 | */ |
| 7841 | @Override |
| 7842 | protected void restoreFromExtras(Bundle extras) { |
| 7843 | super.restoreFromExtras(extras); |
| 7844 | |
| 7845 | mTexts.clear(); |
| 7846 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 7847 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 7848 | } |
| 7849 | } |
| 7850 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7851 | /** |
| 7852 | * @hide |
| 7853 | */ |
| 7854 | public RemoteViews makeBigContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7855 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder).text(null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7856 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7857 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource(), p, result); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7858 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7859 | 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] | 7860 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7861 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 7862 | // Make sure all rows are gone in case we reuse a view. |
| 7863 | for (int rowId : rowIds) { |
| 7864 | contentView.setViewVisibility(rowId, View.GONE); |
| 7865 | } |
| 7866 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7867 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7868 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7869 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7870 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7871 | int onlyViewId = 0; |
| 7872 | int maxRows = rowIds.length; |
| 7873 | if (mBuilder.mActions.size() > 0) { |
| 7874 | maxRows--; |
| 7875 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7876 | CharSequence[] remoteInputHistory = mBuilder.mN.extras.getCharSequenceArray( |
| 7877 | EXTRA_REMOTE_INPUT_HISTORY); |
| 7878 | if (remoteInputHistory != null |
| 7879 | && remoteInputHistory.length > NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION) { |
| 7880 | // Let's remove some messages to make room for the remote input history. |
| 7881 | // 1 is always able to fit, but let's remove them if they are 2 or 3 |
| 7882 | int numRemoteInputs = Math.min(remoteInputHistory.length, |
| 7883 | MAX_REMOTE_INPUT_HISTORY_LINES); |
| 7884 | int totalNumRows = mTexts.size() + numRemoteInputs |
| 7885 | - NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION; |
| 7886 | if (totalNumRows > maxRows) { |
| 7887 | int overflow = totalNumRows - maxRows; |
| 7888 | if (mTexts.size() > maxRows) { |
| 7889 | // Heuristic: if the Texts don't fit anyway, we'll rather drop the last |
| 7890 | // few messages, even with the remote input |
| 7891 | maxRows -= overflow; |
| 7892 | } else { |
| 7893 | // otherwise we drop the first messages |
| 7894 | i = overflow; |
| 7895 | } |
| 7896 | } |
| 7897 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7898 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7899 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7900 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7901 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 7902 | contentView.setTextViewText(rowIds[i], |
| 7903 | mBuilder.processTextSpans(mBuilder.processLegacyText(str))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7904 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i], p); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7905 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7906 | handleInboxImageMargin(contentView, rowIds[i], first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7907 | result.getIconMarginEnd()); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7908 | if (first) { |
| 7909 | onlyViewId = rowIds[i]; |
| 7910 | } else { |
| 7911 | onlyViewId = 0; |
| 7912 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7913 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7914 | } |
| 7915 | i++; |
| 7916 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7917 | if (onlyViewId != 0) { |
| 7918 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 7919 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7920 | R.dimen.notification_text_margin_top); |
| 7921 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 7922 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7923 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7924 | return contentView; |
| 7925 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7926 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7927 | /** |
| 7928 | * @hide |
| 7929 | */ |
| 7930 | @Override |
| 7931 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7932 | if (other == null || getClass() != other.getClass()) { |
| 7933 | return true; |
| 7934 | } |
| 7935 | InboxStyle newS = (InboxStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7936 | |
| 7937 | final ArrayList<CharSequence> myLines = getLines(); |
| 7938 | final ArrayList<CharSequence> newLines = newS.getLines(); |
| 7939 | final int n = myLines.size(); |
| 7940 | if (n != newLines.size()) { |
| 7941 | return true; |
| 7942 | } |
| 7943 | |
| 7944 | for (int i = 0; i < n; i++) { |
| 7945 | if (!Objects.equals( |
| 7946 | String.valueOf(myLines.get(i)), |
| 7947 | String.valueOf(newLines.get(i)))) { |
| 7948 | return true; |
| 7949 | } |
| 7950 | } |
| 7951 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7952 | } |
| 7953 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7954 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7955 | int marginEndValue) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7956 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7957 | if (first) { |
| 7958 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 7959 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 7960 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7961 | if (!hasProgress) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7962 | endMargin = marginEndValue; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7963 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7964 | } |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7965 | contentView.setViewLayoutMarginEnd(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7966 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7967 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7968 | |
| 7969 | /** |
| 7970 | * Notification style for media playback notifications. |
| 7971 | * |
| 7972 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 7973 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 7974 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7975 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 7976 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 7977 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7978 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7979 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 7980 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 7981 | * {@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] | 7982 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7983 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7984 | * Notifications created with MediaStyle will have their category set to |
| 7985 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 7986 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7987 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7988 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 7989 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7990 | * the System UI can identify this as a notification representing an active media session |
| 7991 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 7992 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7993 | * <p> |
| 7994 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 7995 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 7996 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 7997 | * <p> |
| 7998 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7999 | * To use this style with your Notification, feed it to |
| 8000 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8001 | * <pre class="prettyprint"> |
| 8002 | * Notification noti = new Notification.Builder() |
| 8003 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 8004 | * .setContentTitle("Track title") |
| 8005 | * .setContentText("Artist - Album") |
| 8006 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 8007 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 8008 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8009 | * .build(); |
| 8010 | * </pre> |
| 8011 | * |
| 8012 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8013 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8014 | */ |
| 8015 | public static class MediaStyle extends Style { |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8016 | // Changing max media buttons requires also changing templates |
| 8017 | // (notification_template_material_media and notification_template_material_big_media). |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8018 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8019 | static final int MAX_MEDIA_BUTTONS = 5; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8020 | @IdRes private static final int[] MEDIA_BUTTON_IDS = { |
| 8021 | R.id.action0, |
| 8022 | R.id.action1, |
| 8023 | R.id.action2, |
| 8024 | R.id.action3, |
| 8025 | R.id.action4, |
| 8026 | }; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8027 | |
| 8028 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 8029 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8030 | |
| 8031 | public MediaStyle() { |
| 8032 | } |
| 8033 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 8034 | /** |
| 8035 | * @deprecated use {@code MediaStyle()}. |
| 8036 | */ |
| 8037 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8038 | public MediaStyle(Builder builder) { |
| 8039 | setBuilder(builder); |
| 8040 | } |
| 8041 | |
| 8042 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8043 | * 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] | 8044 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8045 | * |
| 8046 | * @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] | 8047 | */ |
| 8048 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 8049 | mActionsToShowInCompact = actions; |
| 8050 | return this; |
| 8051 | } |
| 8052 | |
| 8053 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 8054 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 8055 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8056 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 8057 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8058 | mToken = token; |
| 8059 | return this; |
| 8060 | } |
| 8061 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8062 | /** |
| 8063 | * @hide |
| 8064 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8065 | @Override |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 8066 | @UnsupportedAppUsage |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8067 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8068 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 8069 | if (wip.category == null) { |
| 8070 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 8071 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8072 | return wip; |
| 8073 | } |
| 8074 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8075 | /** |
| 8076 | * @hide |
| 8077 | */ |
| 8078 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8079 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 8080 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8081 | } |
| 8082 | |
| 8083 | /** |
| 8084 | * @hide |
| 8085 | */ |
| 8086 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 8087 | public RemoteViews makeBigContentView() { |
| 8088 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8089 | } |
| 8090 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8091 | /** |
| 8092 | * @hide |
| 8093 | */ |
| 8094 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8095 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8096 | RemoteViews expanded = makeMediaBigContentView(); |
| 8097 | return expanded != null ? expanded : makeMediaContentView(); |
| 8098 | } |
| 8099 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8100 | /** @hide */ |
| 8101 | @Override |
| 8102 | public void addExtras(Bundle extras) { |
| 8103 | super.addExtras(extras); |
| 8104 | |
| 8105 | if (mToken != null) { |
| 8106 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 8107 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 8108 | if (mActionsToShowInCompact != null) { |
| 8109 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 8110 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8111 | } |
| 8112 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8113 | /** |
| 8114 | * @hide |
| 8115 | */ |
| 8116 | @Override |
| 8117 | protected void restoreFromExtras(Bundle extras) { |
| 8118 | super.restoreFromExtras(extras); |
| 8119 | |
| 8120 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 8121 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 8122 | } |
| 8123 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 8124 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 8125 | } |
| 8126 | } |
| 8127 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8128 | /** |
| 8129 | * @hide |
| 8130 | */ |
| 8131 | @Override |
| 8132 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8133 | if (other == null || getClass() != other.getClass()) { |
| 8134 | return true; |
| 8135 | } |
| 8136 | // All fields to compare are on the Notification object |
| 8137 | return false; |
| 8138 | } |
| 8139 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8140 | private void bindMediaActionButton(RemoteViews container, @IdRes int buttonId, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8141 | Action action, StandardTemplateParams p) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8142 | final boolean tombstone = (action.actionIntent == null); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8143 | container.setViewVisibility(buttonId, View.VISIBLE); |
| 8144 | container.setImageViewIcon(buttonId, action.getIcon()); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 8145 | |
| 8146 | // If the action buttons should not be tinted, then just use the default |
| 8147 | // notification color. Otherwise, just use the passed-in color. |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8148 | Resources resources = mBuilder.mContext.getResources(); |
| 8149 | Configuration currentConfig = resources.getConfiguration(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 8150 | boolean inNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 8151 | == Configuration.UI_MODE_NIGHT_YES; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8152 | int tintColor = mBuilder.shouldTintActionButtons() || mBuilder.isColorized(p) |
| 8153 | ? getActionColor(p) |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 8154 | : ContrastColorUtil.resolveColor(mBuilder.mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 8155 | Notification.COLOR_DEFAULT, inNightMode); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 8156 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8157 | container.setDrawableTint(buttonId, false, tintColor, |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 8158 | PorterDuff.Mode.SRC_ATOP); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8159 | |
| 8160 | final TypedArray typedArray = mBuilder.mContext.obtainStyledAttributes( |
| 8161 | new int[]{ android.R.attr.colorControlHighlight }); |
| 8162 | int rippleAlpha = Color.alpha(typedArray.getColor(0, 0)); |
| 8163 | typedArray.recycle(); |
| 8164 | int rippleColor = Color.argb(rippleAlpha, Color.red(tintColor), Color.green(tintColor), |
| 8165 | Color.blue(tintColor)); |
| 8166 | container.setRippleDrawableColor(buttonId, ColorStateList.valueOf(rippleColor)); |
| 8167 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8168 | if (!tombstone) { |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8169 | container.setOnClickPendingIntent(buttonId, action.actionIntent); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8170 | } |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8171 | container.setContentDescription(buttonId, action.title); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8172 | } |
| 8173 | |
| 8174 | private RemoteViews makeMediaContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8175 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).fillTextsFrom( |
| 8176 | mBuilder); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8177 | RemoteViews view = mBuilder.applyStandardTemplate( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8178 | R.layout.notification_template_material_media, p, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8179 | null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8180 | |
| 8181 | final int numActions = mBuilder.mActions.size(); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8182 | final int numActionsToShow = mActionsToShowInCompact == null |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8183 | ? 0 |
| 8184 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8185 | if (numActionsToShow > numActions) { |
| 8186 | throw new IllegalArgumentException(String.format( |
| 8187 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 8188 | numActions, numActions - 1)); |
| 8189 | } |
| 8190 | for (int i = 0; i < MAX_MEDIA_BUTTONS_IN_COMPACT; i++) { |
| 8191 | if (i < numActionsToShow) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8192 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8193 | bindMediaActionButton(view, MEDIA_BUTTON_IDS[i], action, p); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8194 | } else { |
| 8195 | view.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8196 | } |
| 8197 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 8198 | handleImage(view); |
| 8199 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8200 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8201 | if (mBuilder.mN.hasLargeIcon()) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8202 | endMargin = R.dimen.notification_media_image_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 8203 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8204 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8205 | return view; |
| 8206 | } |
| 8207 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8208 | private int getActionColor(StandardTemplateParams p) { |
| 8209 | return mBuilder.isColorized(p) ? mBuilder.getPrimaryTextColor(p) |
| 8210 | : mBuilder.resolveContrastColor(p); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8211 | } |
| 8212 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8213 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8214 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8215 | // Dont add an expanded view if there is no more content to be revealed |
| 8216 | int actionsInCompact = mActionsToShowInCompact == null |
| 8217 | ? 0 |
| 8218 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8219 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8220 | return null; |
| 8221 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8222 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).fillTextsFrom( |
| 8223 | mBuilder); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8224 | RemoteViews big = mBuilder.applyStandardTemplate( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8225 | R.layout.notification_template_material_big_media, p , null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8226 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8227 | for (int i = 0; i < MAX_MEDIA_BUTTONS; i++) { |
| 8228 | if (i < actionCount) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8229 | bindMediaActionButton(big, MEDIA_BUTTON_IDS[i], mBuilder.mActions.get(i), p); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8230 | } else { |
| 8231 | big.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8232 | } |
| 8233 | } |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 8234 | bindMediaActionButton(big, R.id.media_seamless, new Action(R.drawable.ic_media_seamless, |
| 8235 | mBuilder.mContext.getString( |
| 8236 | com.android.internal.R.string.ext_media_seamless_action), null), p); |
| 8237 | big.setViewVisibility(R.id.media_seamless, View.GONE); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8238 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8239 | return big; |
| 8240 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8241 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8242 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8243 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8244 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 8245 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8246 | } |
| 8247 | } |
| 8248 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8249 | /** |
| 8250 | * @hide |
| 8251 | */ |
| 8252 | @Override |
| 8253 | protected boolean hasProgress() { |
| 8254 | return false; |
| 8255 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8256 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8257 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8258 | /** |
| 8259 | * Notification style for custom views that are decorated by the system |
| 8260 | * |
| 8261 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 8262 | * style and still obtain system decorations like the notification header with the expand |
| 8263 | * affordance and actions. |
| 8264 | * |
| 8265 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8266 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8267 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8268 | * corresponding custom views to display. |
| 8269 | * |
| 8270 | * To use this style with your Notification, feed it to |
| 8271 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8272 | * <pre class="prettyprint"> |
| 8273 | * Notification noti = new Notification.Builder() |
| 8274 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8275 | * .setLargeIcon(albumArtBitmap)) |
| 8276 | * .setCustomContentView(contentView); |
| 8277 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 8278 | * .build(); |
| 8279 | * </pre> |
| 8280 | */ |
| 8281 | public static class DecoratedCustomViewStyle extends Style { |
| 8282 | |
| 8283 | public DecoratedCustomViewStyle() { |
| 8284 | } |
| 8285 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8286 | /** |
| 8287 | * @hide |
| 8288 | */ |
| 8289 | public boolean displayCustomViewInline() { |
| 8290 | return true; |
| 8291 | } |
| 8292 | |
| 8293 | /** |
| 8294 | * @hide |
| 8295 | */ |
| 8296 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8297 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8298 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 8299 | } |
| 8300 | |
| 8301 | /** |
| 8302 | * @hide |
| 8303 | */ |
| 8304 | @Override |
| 8305 | public RemoteViews makeBigContentView() { |
| 8306 | return makeDecoratedBigContentView(); |
| 8307 | } |
| 8308 | |
| 8309 | /** |
| 8310 | * @hide |
| 8311 | */ |
| 8312 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8313 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8314 | return makeDecoratedHeadsUpContentView(); |
| 8315 | } |
| 8316 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8317 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 8318 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 8319 | ? mBuilder.mN.contentView |
| 8320 | : mBuilder.mN.headsUpContentView; |
| 8321 | if (mBuilder.mActions.size() == 0) { |
| 8322 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 8323 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8324 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8325 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8326 | mBuilder.getBigBaseLayoutResource(), result); |
| 8327 | buildIntoRemoteViewContent(remoteViews, headsUpContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8328 | return remoteViews; |
| 8329 | } |
| 8330 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8331 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8332 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8333 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8334 | mBuilder.getBaseLayoutResource(), result); |
| 8335 | buildIntoRemoteViewContent(remoteViews, customContent, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8336 | return remoteViews; |
| 8337 | } |
| 8338 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8339 | private RemoteViews makeDecoratedBigContentView() { |
| 8340 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 8341 | ? mBuilder.mN.contentView |
| 8342 | : mBuilder.mN.bigContentView; |
| 8343 | if (mBuilder.mActions.size() == 0) { |
| 8344 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 8345 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8346 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8347 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8348 | mBuilder.getBigBaseLayoutResource(), result); |
| 8349 | buildIntoRemoteViewContent(remoteViews, bigContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8350 | return remoteViews; |
| 8351 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8352 | |
| 8353 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8354 | RemoteViews customContent, TemplateBindResult result) { |
Selim Cinek | 6fe4a10 | 2019-01-25 14:38:24 -0800 | [diff] [blame] | 8355 | int childIndex = -1; |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8356 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8357 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8358 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8359 | customContent = customContent.clone(); |
Anthony Chen | 8f5f358 | 2017-04-11 11:18:37 -0700 | [diff] [blame] | 8360 | remoteViews.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress); |
| 8361 | remoteViews.addView(R.id.notification_main_column, customContent, 0 /* index */); |
Sunny Goyal | c12d31c | 2018-11-12 16:29:18 -0800 | [diff] [blame] | 8362 | remoteViews.addFlags(RemoteViews.FLAG_REAPPLY_DISALLOWED); |
Selim Cinek | 6fe4a10 | 2019-01-25 14:38:24 -0800 | [diff] [blame] | 8363 | childIndex = 0; |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8364 | } |
Selim Cinek | 6fe4a10 | 2019-01-25 14:38:24 -0800 | [diff] [blame] | 8365 | remoteViews.setIntTag(R.id.notification_main_column, |
| 8366 | com.android.internal.R.id.notification_custom_view_index_tag, |
| 8367 | childIndex); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8368 | // also update the end margin if there is an image |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8369 | Resources resources = mBuilder.mContext.getResources(); |
| 8370 | int endMargin = resources.getDimensionPixelSize( |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 8371 | R.dimen.notification_content_margin_end) + result.getIconMarginEnd(); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8372 | remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8373 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8374 | |
| 8375 | /** |
| 8376 | * @hide |
| 8377 | */ |
| 8378 | @Override |
| 8379 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8380 | if (other == null || getClass() != other.getClass()) { |
| 8381 | return true; |
| 8382 | } |
| 8383 | // Comparison done for all custom RemoteViews, independent of style |
| 8384 | return false; |
| 8385 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8386 | } |
| 8387 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8388 | /** |
| 8389 | * Notification style for media custom views that are decorated by the system |
| 8390 | * |
| 8391 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 8392 | * this style and still obtain system decorations like the notification header with the expand |
| 8393 | * affordance and actions. |
| 8394 | * |
| 8395 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8396 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8397 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8398 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8399 | * <p> |
| 8400 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 8401 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 8402 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8403 | * To use this style with your Notification, feed it to |
| 8404 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8405 | * <pre class="prettyprint"> |
| 8406 | * Notification noti = new Notification.Builder() |
| 8407 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8408 | * .setLargeIcon(albumArtBitmap)) |
| 8409 | * .setCustomContentView(contentView); |
| 8410 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 8411 | * .setMediaSession(mySession)) |
| 8412 | * .build(); |
| 8413 | * </pre> |
| 8414 | * |
| 8415 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 8416 | * @see android.app.Notification.MediaStyle |
| 8417 | */ |
| 8418 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 8419 | |
| 8420 | public DecoratedMediaCustomViewStyle() { |
| 8421 | } |
| 8422 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8423 | /** |
| 8424 | * @hide |
| 8425 | */ |
| 8426 | public boolean displayCustomViewInline() { |
| 8427 | return true; |
| 8428 | } |
| 8429 | |
| 8430 | /** |
| 8431 | * @hide |
| 8432 | */ |
| 8433 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8434 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 8435 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8436 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8437 | mBuilder.mN.contentView); |
| 8438 | } |
| 8439 | |
| 8440 | /** |
| 8441 | * @hide |
| 8442 | */ |
| 8443 | @Override |
| 8444 | public RemoteViews makeBigContentView() { |
| 8445 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 8446 | ? mBuilder.mN.bigContentView |
| 8447 | : mBuilder.mN.contentView; |
| 8448 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8449 | } |
| 8450 | |
| 8451 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 8452 | RemoteViews remoteViews = super.makeBigContentView(); |
| 8453 | if (remoteViews != null) { |
| 8454 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 8455 | customRemoteView); |
| 8456 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8457 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8458 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8459 | customRemoteView); |
| 8460 | } else { |
| 8461 | return null; |
| 8462 | } |
| 8463 | } |
| 8464 | |
| 8465 | /** |
| 8466 | * @hide |
| 8467 | */ |
| 8468 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8469 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8470 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 8471 | ? mBuilder.mN.headsUpContentView |
| 8472 | : mBuilder.mN.contentView; |
| 8473 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8474 | } |
| 8475 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8476 | /** |
| 8477 | * @hide |
| 8478 | */ |
| 8479 | @Override |
| 8480 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8481 | if (other == null || getClass() != other.getClass()) { |
| 8482 | return true; |
| 8483 | } |
| 8484 | // Comparison done for all custom RemoteViews, independent of style |
| 8485 | return false; |
| 8486 | } |
| 8487 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8488 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 8489 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8490 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8491 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8492 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8493 | customContent = customContent.clone(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8494 | customContent.overrideTextColors(mBuilder.getPrimaryTextColor(mBuilder.mParams)); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8495 | remoteViews.removeAllViews(id); |
| 8496 | remoteViews.addView(id, customContent); |
Sunny Goyal | c12d31c | 2018-11-12 16:29:18 -0800 | [diff] [blame] | 8497 | remoteViews.addFlags(RemoteViews.FLAG_REAPPLY_DISALLOWED); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8498 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8499 | return remoteViews; |
| 8500 | } |
| 8501 | } |
| 8502 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8503 | /** |
| 8504 | * Encapsulates the information needed to display a notification as a bubble. |
| 8505 | * |
| 8506 | * <p>A bubble is used to display app content in a floating window over the existing |
| 8507 | * foreground activity. A bubble has a collapsed state represented by an icon, |
| 8508 | * {@link BubbleMetadata.Builder#setIcon(Icon)} and an expanded state which is populated |
| 8509 | * via {@link BubbleMetadata.Builder#setIntent(PendingIntent)}.</p> |
| 8510 | * |
| 8511 | * <b>Notifications with a valid and allowed bubble will display in collapsed state |
| 8512 | * outside of the notification shade on unlocked devices. When a user interacts with the |
| 8513 | * collapsed bubble, the bubble intent will be invoked and displayed.</b> |
| 8514 | * |
| 8515 | * @see Notification.Builder#setBubbleMetadata(BubbleMetadata) |
| 8516 | */ |
| 8517 | public static final class BubbleMetadata implements Parcelable { |
| 8518 | |
| 8519 | private PendingIntent mPendingIntent; |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8520 | private PendingIntent mDeleteIntent; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8521 | private Icon mIcon; |
| 8522 | private int mDesiredHeight; |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8523 | @DimenRes private int mDesiredHeightResId; |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8524 | private int mFlags; |
| 8525 | |
| 8526 | /** |
| 8527 | * If set and the app creating the bubble is in the foreground, the bubble will be posted |
| 8528 | * in its expanded state, with the contents of {@link #getIntent()} in a floating window. |
| 8529 | * |
| 8530 | * <p>If the app creating the bubble is not in the foreground this flag has no effect.</p> |
| 8531 | * |
| 8532 | * <p>Generally this flag should only be set if the user has performed an action to request |
| 8533 | * or create a bubble.</p> |
| 8534 | */ |
| 8535 | private static final int FLAG_AUTO_EXPAND_BUBBLE = 0x00000001; |
| 8536 | |
| 8537 | /** |
| 8538 | * If set and the app creating the bubble is in the foreground, the bubble will be posted |
| 8539 | * <b>without</b> the associated notification in the notification shade. Subsequent update |
| 8540 | * notifications to this bubble will post a notification in the shade. |
| 8541 | * |
| 8542 | * <p>If the app creating the bubble is not in the foreground this flag has no effect.</p> |
| 8543 | * |
| 8544 | * <p>Generally this flag should only be set if the user has performed an action to request |
| 8545 | * or create a bubble.</p> |
| 8546 | */ |
| 8547 | private static final int FLAG_SUPPRESS_INITIAL_NOTIFICATION = 0x00000002; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8548 | |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8549 | private BubbleMetadata(PendingIntent expandIntent, PendingIntent deleteIntent, |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8550 | Icon icon, int height, @DimenRes int heightResId) { |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8551 | mPendingIntent = expandIntent; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8552 | mIcon = icon; |
| 8553 | mDesiredHeight = height; |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8554 | mDesiredHeightResId = heightResId; |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8555 | mDeleteIntent = deleteIntent; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8556 | } |
| 8557 | |
| 8558 | private BubbleMetadata(Parcel in) { |
| 8559 | mPendingIntent = PendingIntent.CREATOR.createFromParcel(in); |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8560 | mIcon = Icon.CREATOR.createFromParcel(in); |
| 8561 | mDesiredHeight = in.readInt(); |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8562 | mFlags = in.readInt(); |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8563 | if (in.readInt() != 0) { |
| 8564 | mDeleteIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 8565 | } |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8566 | mDesiredHeightResId = in.readInt(); |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8567 | } |
| 8568 | |
| 8569 | /** |
| 8570 | * @return the pending intent used to populate the floating window for this bubble. |
| 8571 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8572 | @NonNull |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8573 | public PendingIntent getIntent() { |
| 8574 | return mPendingIntent; |
| 8575 | } |
| 8576 | |
| 8577 | /** |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8578 | * @return the pending intent to send when the bubble is dismissed by a user, if one exists. |
| 8579 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8580 | @Nullable |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8581 | public PendingIntent getDeleteIntent() { |
| 8582 | return mDeleteIntent; |
| 8583 | } |
| 8584 | |
| 8585 | /** |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8586 | * @return the title that will appear along with the app content defined by |
| 8587 | * {@link #getIntent()} for this bubble. |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8588 | * |
| 8589 | * @deprecated titles are no longer required or shown. |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8590 | */ |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8591 | @Deprecated |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8592 | public CharSequence getTitle() { |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8593 | return ""; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8594 | } |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8595 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8596 | /** |
| 8597 | * @return the icon that will be displayed for this bubble when it is collapsed. |
| 8598 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8599 | @NonNull |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8600 | public Icon getIcon() { |
| 8601 | return mIcon; |
| 8602 | } |
| 8603 | |
| 8604 | /** |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8605 | * @return the ideal height, in DPs, for the floating window that app content defined by |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8606 | * {@link #getIntent()} for this bubble. |
| 8607 | */ |
| 8608 | public int getDesiredHeight() { |
| 8609 | return mDesiredHeight; |
| 8610 | } |
| 8611 | |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8612 | /** |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8613 | * @return the resId of ideal height for the floating window that app content defined by |
| 8614 | * {@link #getIntent()} for this bubble. |
| 8615 | */ |
| 8616 | @DimenRes |
| 8617 | public int getDesiredHeightResId() { |
| 8618 | return mDesiredHeightResId; |
| 8619 | } |
| 8620 | |
| 8621 | /** |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8622 | * @return whether this bubble should auto expand when it is posted. |
| 8623 | * |
| 8624 | * @see BubbleMetadata.Builder#setAutoExpandBubble(boolean) |
| 8625 | */ |
| 8626 | public boolean getAutoExpandBubble() { |
| 8627 | return (mFlags & FLAG_AUTO_EXPAND_BUBBLE) != 0; |
| 8628 | } |
| 8629 | |
| 8630 | /** |
| 8631 | * @return whether this bubble should suppress the initial notification when it is posted. |
| 8632 | * |
| 8633 | * @see BubbleMetadata.Builder#setSuppressInitialNotification(boolean) |
| 8634 | */ |
| 8635 | public boolean getSuppressInitialNotification() { |
| 8636 | return (mFlags & FLAG_SUPPRESS_INITIAL_NOTIFICATION) != 0; |
| 8637 | } |
| 8638 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 8639 | public static final @android.annotation.NonNull Parcelable.Creator<BubbleMetadata> CREATOR = |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8640 | new Parcelable.Creator<BubbleMetadata>() { |
| 8641 | |
| 8642 | @Override |
| 8643 | public BubbleMetadata createFromParcel(Parcel source) { |
| 8644 | return new BubbleMetadata(source); |
| 8645 | } |
| 8646 | |
| 8647 | @Override |
| 8648 | public BubbleMetadata[] newArray(int size) { |
| 8649 | return new BubbleMetadata[size]; |
| 8650 | } |
| 8651 | }; |
| 8652 | |
| 8653 | @Override |
| 8654 | public int describeContents() { |
| 8655 | return 0; |
| 8656 | } |
| 8657 | |
| 8658 | @Override |
| 8659 | public void writeToParcel(Parcel out, int flags) { |
| 8660 | mPendingIntent.writeToParcel(out, 0); |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8661 | mIcon.writeToParcel(out, 0); |
| 8662 | out.writeInt(mDesiredHeight); |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8663 | out.writeInt(mFlags); |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8664 | out.writeInt(mDeleteIntent != null ? 1 : 0); |
| 8665 | if (mDeleteIntent != null) { |
| 8666 | mDeleteIntent.writeToParcel(out, 0); |
| 8667 | } |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8668 | out.writeInt(mDesiredHeightResId); |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8669 | } |
| 8670 | |
| 8671 | private void setFlags(int flags) { |
| 8672 | mFlags = flags; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8673 | } |
| 8674 | |
| 8675 | /** |
| 8676 | * Builder to construct a {@link BubbleMetadata} object. |
| 8677 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8678 | public static final class Builder { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8679 | |
| 8680 | private PendingIntent mPendingIntent; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8681 | private Icon mIcon; |
| 8682 | private int mDesiredHeight; |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8683 | @DimenRes private int mDesiredHeightResId; |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8684 | private int mFlags; |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8685 | private PendingIntent mDeleteIntent; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8686 | |
| 8687 | /** |
| 8688 | * Constructs a new builder object. |
| 8689 | */ |
| 8690 | public Builder() { |
| 8691 | } |
| 8692 | |
| 8693 | /** |
| 8694 | * Sets the intent that will be used when the bubble is expanded. This will display the |
| 8695 | * app content in a floating window over the existing foreground activity. |
| 8696 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8697 | @NonNull |
| 8698 | public BubbleMetadata.Builder setIntent(@NonNull PendingIntent intent) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8699 | if (intent == null) { |
| 8700 | throw new IllegalArgumentException("Bubble requires non-null pending intent"); |
| 8701 | } |
| 8702 | mPendingIntent = intent; |
| 8703 | return this; |
| 8704 | } |
| 8705 | |
| 8706 | /** |
| 8707 | * Sets the title that will appear along with the app content for this bubble. |
| 8708 | * |
| 8709 | * <p>A title is required and should expect to fit on a single line and make sense when |
| 8710 | * shown with the content defined by {@link #setIntent(PendingIntent)}.</p> |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8711 | * |
| 8712 | * @deprecated titles are no longer required or shown. |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8713 | */ |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8714 | @Deprecated |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8715 | public BubbleMetadata.Builder setTitle(CharSequence title) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8716 | return this; |
| 8717 | } |
| 8718 | |
| 8719 | /** |
| 8720 | * Sets the icon that will represent the bubble when it is collapsed. |
| 8721 | * |
| 8722 | * <p>An icon is required and should be representative of the content within the bubble. |
| 8723 | * If your app produces multiple bubbles, the image should be unique for each of them. |
| 8724 | * </p> |
| 8725 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8726 | @NonNull |
| 8727 | public BubbleMetadata.Builder setIcon(@NonNull Icon icon) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8728 | if (icon == null) { |
| 8729 | throw new IllegalArgumentException("Bubbles require non-null icon"); |
| 8730 | } |
| 8731 | mIcon = icon; |
| 8732 | return this; |
| 8733 | } |
| 8734 | |
| 8735 | /** |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8736 | * Sets the desired height in DPs for the app content defined by |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8737 | * {@link #setIntent(PendingIntent)}, this height may not be respected if there is not |
| 8738 | * enough space on the screen or if the provided height is too small to be useful. |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8739 | * <p> |
| 8740 | * If {@link #setDesiredHeightResId(int)} was previously called on this builder, the |
| 8741 | * previous value set will be cleared after calling this method, and this value will |
| 8742 | * be used instead. |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8743 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8744 | @NonNull |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8745 | public BubbleMetadata.Builder setDesiredHeight(int height) { |
| 8746 | mDesiredHeight = Math.max(height, 0); |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8747 | mDesiredHeightResId = 0; |
| 8748 | return this; |
| 8749 | } |
| 8750 | |
| 8751 | |
| 8752 | /** |
| 8753 | * Sets the desired height via resId for the app content defined by |
| 8754 | * {@link #setIntent(PendingIntent)}, this height may not be respected if there is not |
| 8755 | * enough space on the screen or if the provided height is too small to be useful. |
| 8756 | * <p> |
| 8757 | * If {@link #setDesiredHeight(int)} was previously called on this builder, the |
| 8758 | * previous value set will be cleared after calling this method, and this value will |
| 8759 | * be used instead. |
| 8760 | */ |
| 8761 | @NonNull |
| 8762 | public BubbleMetadata.Builder setDesiredHeightResId(@DimenRes int heightResId) { |
| 8763 | mDesiredHeightResId = heightResId; |
| 8764 | mDesiredHeight = 0; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8765 | return this; |
| 8766 | } |
| 8767 | |
| 8768 | /** |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8769 | * If set and the app creating the bubble is in the foreground, the bubble will be |
| 8770 | * posted in its expanded state, with the contents of {@link #getIntent()} in a |
| 8771 | * floating window. |
| 8772 | * |
| 8773 | * <p>If the app creating the bubble is not in the foreground this flag has no effect. |
| 8774 | * </p> |
| 8775 | * |
| 8776 | * <p>Generally this flag should only be set if the user has performed an action to |
| 8777 | * request or create a bubble.</p> |
| 8778 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8779 | @NonNull |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8780 | public BubbleMetadata.Builder setAutoExpandBubble(boolean shouldExpand) { |
| 8781 | setFlag(FLAG_AUTO_EXPAND_BUBBLE, shouldExpand); |
| 8782 | return this; |
| 8783 | } |
| 8784 | |
| 8785 | /** |
| 8786 | * If set and the app creating the bubble is in the foreground, the bubble will be |
| 8787 | * posted <b>without</b> the associated notification in the notification shade. |
| 8788 | * Subsequent update notifications to this bubble will post a notification in the shade. |
| 8789 | * |
| 8790 | * <p>If the app creating the bubble is not in the foreground this flag has no effect. |
| 8791 | * </p> |
| 8792 | * |
| 8793 | * <p>Generally this flag should only be set if the user has performed an action to |
| 8794 | * request or create a bubble.</p> |
| 8795 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8796 | @NonNull |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8797 | public BubbleMetadata.Builder setSuppressInitialNotification( |
| 8798 | boolean shouldSupressNotif) { |
| 8799 | setFlag(FLAG_SUPPRESS_INITIAL_NOTIFICATION, shouldSupressNotif); |
| 8800 | return this; |
| 8801 | } |
| 8802 | |
| 8803 | /** |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8804 | * Sets an optional intent to send when this bubble is explicitly removed by the user. |
| 8805 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8806 | @NonNull |
| 8807 | public BubbleMetadata.Builder setDeleteIntent(@Nullable PendingIntent deleteIntent) { |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8808 | mDeleteIntent = deleteIntent; |
| 8809 | return this; |
| 8810 | } |
| 8811 | |
| 8812 | /** |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8813 | * Creates the {@link BubbleMetadata} defined by this builder. |
| 8814 | * <p>Will throw {@link IllegalStateException} if required fields have not been set |
| 8815 | * on this builder.</p> |
| 8816 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame] | 8817 | @NonNull |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8818 | public BubbleMetadata build() { |
| 8819 | if (mPendingIntent == null) { |
| 8820 | throw new IllegalStateException("Must supply pending intent to bubble"); |
| 8821 | } |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8822 | if (mIcon == null) { |
| 8823 | throw new IllegalStateException("Must supply an icon for the bubble"); |
| 8824 | } |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8825 | BubbleMetadata data = new BubbleMetadata(mPendingIntent, mDeleteIntent, |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame^] | 8826 | mIcon, mDesiredHeight, mDesiredHeightResId); |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8827 | data.setFlags(mFlags); |
| 8828 | return data; |
| 8829 | } |
| 8830 | |
| 8831 | /** |
| 8832 | * @hide |
| 8833 | */ |
| 8834 | public BubbleMetadata.Builder setFlag(int mask, boolean value) { |
| 8835 | if (value) { |
| 8836 | mFlags |= mask; |
| 8837 | } else { |
| 8838 | mFlags &= ~mask; |
| 8839 | } |
| 8840 | return this; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8841 | } |
| 8842 | } |
| 8843 | } |
| 8844 | |
| 8845 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8846 | // When adding a new Style subclass here, don't forget to update |
| 8847 | // Builder.getNotificationStyleClass. |
| 8848 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8849 | /** |
| 8850 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 8851 | * metadata or change options on a notification builder. |
| 8852 | */ |
| 8853 | public interface Extender { |
| 8854 | /** |
| 8855 | * Apply this extender to a notification builder. |
| 8856 | * @param builder the builder to be modified. |
| 8857 | * @return the build object for chaining. |
| 8858 | */ |
| 8859 | public Builder extend(Builder builder); |
| 8860 | } |
| 8861 | |
| 8862 | /** |
| 8863 | * Helper class to add wearable extensions to notifications. |
| 8864 | * <p class="note"> See |
| 8865 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 8866 | * for Android Wear</a> for more information on how to use this class. |
| 8867 | * <p> |
| 8868 | * To create a notification with wearable extensions: |
| 8869 | * <ol> |
| 8870 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 8871 | * properties. |
| 8872 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 8873 | * <li>Set wearable-specific properties using the |
| 8874 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 8875 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 8876 | * notification. |
| 8877 | * <li>Post the notification to the notification system with the |
| 8878 | * {@code NotificationManager.notify(...)} methods. |
| 8879 | * </ol> |
| 8880 | * |
| 8881 | * <pre class="prettyprint"> |
| 8882 | * Notification notif = new Notification.Builder(mContext) |
| 8883 | * .setContentTitle("New mail from " + sender.toString()) |
| 8884 | * .setContentText(subject) |
| 8885 | * .setSmallIcon(R.drawable.new_mail) |
| 8886 | * .extend(new Notification.WearableExtender() |
| 8887 | * .setContentIcon(R.drawable.new_mail)) |
| 8888 | * .build(); |
| 8889 | * NotificationManager notificationManger = |
| 8890 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 8891 | * notificationManger.notify(0, notif);</pre> |
| 8892 | * |
| 8893 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 8894 | * {@code WearableExtender(Notification)} constructor, |
| 8895 | * and then using the {@code get} methods to access values. |
| 8896 | * |
| 8897 | * <pre class="prettyprint"> |
| 8898 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 8899 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8900 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8901 | */ |
| 8902 | public static final class WearableExtender implements Extender { |
| 8903 | /** |
| 8904 | * Sentinel value for an action index that is unset. |
| 8905 | */ |
| 8906 | public static final int UNSET_ACTION_INDEX = -1; |
| 8907 | |
| 8908 | /** |
| 8909 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 8910 | * default sizing. |
| 8911 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 8912 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8913 | * on their content. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8914 | * |
| 8915 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8916 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8917 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8918 | public static final int SIZE_DEFAULT = 0; |
| 8919 | |
| 8920 | /** |
| 8921 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8922 | * with an extra small size. |
| 8923 | * <p>This value is only applicable for custom display notifications created using |
| 8924 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8925 | * |
| 8926 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8927 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8928 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8929 | public static final int SIZE_XSMALL = 1; |
| 8930 | |
| 8931 | /** |
| 8932 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8933 | * with a small size. |
| 8934 | * <p>This value is only applicable for custom display notifications created using |
| 8935 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8936 | * |
| 8937 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8938 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8939 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8940 | public static final int SIZE_SMALL = 2; |
| 8941 | |
| 8942 | /** |
| 8943 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8944 | * with a medium size. |
| 8945 | * <p>This value is only applicable for custom display notifications created using |
| 8946 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8947 | * |
| 8948 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8949 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8950 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8951 | public static final int SIZE_MEDIUM = 3; |
| 8952 | |
| 8953 | /** |
| 8954 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8955 | * with a large size. |
| 8956 | * <p>This value is only applicable for custom display notifications created using |
| 8957 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8958 | * |
| 8959 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8960 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8961 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8962 | public static final int SIZE_LARGE = 4; |
| 8963 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8964 | /** |
| 8965 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8966 | * full screen. |
| 8967 | * <p>This value is only applicable for custom display notifications created using |
| 8968 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8969 | * |
| 8970 | * @deprecated Display intents are no longer supported. |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8971 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8972 | @Deprecated |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8973 | public static final int SIZE_FULL_SCREEN = 5; |
| 8974 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8975 | /** |
| 8976 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 8977 | * short amount of time when this notification is displayed on the screen. This |
| 8978 | * is the default value. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8979 | * |
| 8980 | * @deprecated This feature is no longer supported. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8981 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8982 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8983 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 8984 | |
| 8985 | /** |
| 8986 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 8987 | * 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] | 8988 | * |
| 8989 | * @deprecated This feature is no longer supported. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8990 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8991 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8992 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 8993 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8994 | /** Notification extra which contains wearable extensions */ |
| 8995 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 8996 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 8997 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8998 | private static final String KEY_ACTIONS = "actions"; |
| 8999 | private static final String KEY_FLAGS = "flags"; |
| 9000 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 9001 | private static final String KEY_PAGES = "pages"; |
| 9002 | private static final String KEY_BACKGROUND = "background"; |
| 9003 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 9004 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 9005 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 9006 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 9007 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 9008 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9009 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9010 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9011 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9012 | |
| 9013 | // Flags bitwise-ored to mFlags |
| 9014 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 9015 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 9016 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 9017 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9018 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9019 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9020 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9021 | |
| 9022 | // Default value for flags integer |
| 9023 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 9024 | |
| 9025 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 9026 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 9027 | |
| 9028 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 9029 | private int mFlags = DEFAULT_FLAGS; |
| 9030 | private PendingIntent mDisplayIntent; |
| 9031 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 9032 | private Bitmap mBackground; |
| 9033 | private int mContentIcon; |
| 9034 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 9035 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 9036 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 9037 | private int mCustomContentHeight; |
| 9038 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9039 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9040 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9041 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9042 | |
| 9043 | /** |
| 9044 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 9045 | * options. |
| 9046 | */ |
| 9047 | public WearableExtender() { |
| 9048 | } |
| 9049 | |
| 9050 | public WearableExtender(Notification notif) { |
| 9051 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 9052 | if (wearableBundle != null) { |
| 9053 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 9054 | if (actions != null) { |
| 9055 | mActions.addAll(actions); |
| 9056 | } |
| 9057 | |
| 9058 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 9059 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 9060 | |
| 9061 | Notification[] pages = getNotificationArrayFromBundle( |
| 9062 | wearableBundle, KEY_PAGES); |
| 9063 | if (pages != null) { |
| 9064 | Collections.addAll(mPages, pages); |
| 9065 | } |
| 9066 | |
| 9067 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 9068 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 9069 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 9070 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 9071 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 9072 | UNSET_ACTION_INDEX); |
| 9073 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 9074 | SIZE_DEFAULT); |
| 9075 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 9076 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9077 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9078 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9079 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9080 | } |
| 9081 | } |
| 9082 | |
| 9083 | /** |
| 9084 | * Apply wearable extensions to a notification that is being built. This is typically |
| 9085 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 9086 | * {@link android.app.Notification.Builder}. |
| 9087 | */ |
| 9088 | @Override |
| 9089 | public Notification.Builder extend(Notification.Builder builder) { |
| 9090 | Bundle wearableBundle = new Bundle(); |
| 9091 | |
| 9092 | if (!mActions.isEmpty()) { |
| 9093 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 9094 | } |
| 9095 | if (mFlags != DEFAULT_FLAGS) { |
| 9096 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 9097 | } |
| 9098 | if (mDisplayIntent != null) { |
| 9099 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 9100 | } |
| 9101 | if (!mPages.isEmpty()) { |
| 9102 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 9103 | new Notification[mPages.size()])); |
| 9104 | } |
| 9105 | if (mBackground != null) { |
| 9106 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 9107 | } |
| 9108 | if (mContentIcon != 0) { |
| 9109 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 9110 | } |
| 9111 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 9112 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 9113 | } |
| 9114 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 9115 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 9116 | mContentActionIndex); |
| 9117 | } |
| 9118 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 9119 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 9120 | } |
| 9121 | if (mCustomContentHeight != 0) { |
| 9122 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 9123 | } |
| 9124 | if (mGravity != DEFAULT_GRAVITY) { |
| 9125 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 9126 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9127 | if (mHintScreenTimeout != 0) { |
| 9128 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 9129 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9130 | if (mDismissalId != null) { |
| 9131 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 9132 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9133 | if (mBridgeTag != null) { |
| 9134 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 9135 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9136 | |
| 9137 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 9138 | return builder; |
| 9139 | } |
| 9140 | |
| 9141 | @Override |
| 9142 | public WearableExtender clone() { |
| 9143 | WearableExtender that = new WearableExtender(); |
| 9144 | that.mActions = new ArrayList<Action>(this.mActions); |
| 9145 | that.mFlags = this.mFlags; |
| 9146 | that.mDisplayIntent = this.mDisplayIntent; |
| 9147 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 9148 | that.mBackground = this.mBackground; |
| 9149 | that.mContentIcon = this.mContentIcon; |
| 9150 | that.mContentIconGravity = this.mContentIconGravity; |
| 9151 | that.mContentActionIndex = this.mContentActionIndex; |
| 9152 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 9153 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 9154 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9155 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9156 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9157 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9158 | return that; |
| 9159 | } |
| 9160 | |
| 9161 | /** |
| 9162 | * Add a wearable action to this notification. |
| 9163 | * |
| 9164 | * <p>When wearable actions are added using this method, the set of actions that |
| 9165 | * show on a wearable device splits from devices that only show actions added |
| 9166 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 9167 | * of which actions display on different devices. |
| 9168 | * |
| 9169 | * @param action the action to add to this notification |
| 9170 | * @return this object for method chaining |
| 9171 | * @see android.app.Notification.Action |
| 9172 | */ |
| 9173 | public WearableExtender addAction(Action action) { |
| 9174 | mActions.add(action); |
| 9175 | return this; |
| 9176 | } |
| 9177 | |
| 9178 | /** |
| 9179 | * Adds wearable actions to this notification. |
| 9180 | * |
| 9181 | * <p>When wearable actions are added using this method, the set of actions that |
| 9182 | * show on a wearable device splits from devices that only show actions added |
| 9183 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 9184 | * of which actions display on different devices. |
| 9185 | * |
| 9186 | * @param actions the actions to add to this notification |
| 9187 | * @return this object for method chaining |
| 9188 | * @see android.app.Notification.Action |
| 9189 | */ |
| 9190 | public WearableExtender addActions(List<Action> actions) { |
| 9191 | mActions.addAll(actions); |
| 9192 | return this; |
| 9193 | } |
| 9194 | |
| 9195 | /** |
| 9196 | * Clear all wearable actions present on this builder. |
| 9197 | * @return this object for method chaining. |
| 9198 | * @see #addAction |
| 9199 | */ |
| 9200 | public WearableExtender clearActions() { |
| 9201 | mActions.clear(); |
| 9202 | return this; |
| 9203 | } |
| 9204 | |
| 9205 | /** |
| 9206 | * Get the wearable actions present on this notification. |
| 9207 | */ |
| 9208 | public List<Action> getActions() { |
| 9209 | return mActions; |
| 9210 | } |
| 9211 | |
| 9212 | /** |
| 9213 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9214 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 9215 | * |
| 9216 | * <pre class="prettyprint"> |
| 9217 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 9218 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 9219 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 9220 | * Notification notif = new Notification.Builder(context) |
| 9221 | * .extend(new Notification.WearableExtender() |
| 9222 | * .setDisplayIntent(displayPendingIntent) |
| 9223 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 9224 | * .build();</pre> |
| 9225 | * |
| 9226 | * <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] | 9227 | * should have an empty task affinity. It is also recommended to use the device |
| 9228 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9229 | * |
| 9230 | * <p>Example AndroidManifest.xml entry: |
| 9231 | * <pre class="prettyprint"> |
| 9232 | * <activity android:name="com.example.MyDisplayActivity" |
| 9233 | * android:exported="true" |
| 9234 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 9235 | * android:taskAffinity="" |
| 9236 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9237 | * |
| 9238 | * @param intent the {@link PendingIntent} for an activity |
| 9239 | * @return this object for method chaining |
| 9240 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9241 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9242 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9243 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9244 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 9245 | mDisplayIntent = intent; |
| 9246 | return this; |
| 9247 | } |
| 9248 | |
| 9249 | /** |
| 9250 | * Get the intent to launch inside of an activity view when displaying this |
| 9251 | * notification. This {@code PendingIntent} should be for an activity. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9252 | * |
| 9253 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9254 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9255 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9256 | public PendingIntent getDisplayIntent() { |
| 9257 | return mDisplayIntent; |
| 9258 | } |
| 9259 | |
| 9260 | /** |
| 9261 | * Add an additional page of content to display with this notification. The current |
| 9262 | * notification forms the first page, and pages added using this function form |
| 9263 | * subsequent pages. This field can be used to separate a notification into multiple |
| 9264 | * sections. |
| 9265 | * |
| 9266 | * @param page the notification to add as another page |
| 9267 | * @return this object for method chaining |
| 9268 | * @see android.app.Notification.WearableExtender#getPages |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9269 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9270 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9271 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9272 | public WearableExtender addPage(Notification page) { |
| 9273 | mPages.add(page); |
| 9274 | return this; |
| 9275 | } |
| 9276 | |
| 9277 | /** |
| 9278 | * Add additional pages of content to display with this notification. The current |
| 9279 | * notification forms the first page, and pages added using this function form |
| 9280 | * subsequent pages. This field can be used to separate a notification into multiple |
| 9281 | * sections. |
| 9282 | * |
| 9283 | * @param pages a list of notifications |
| 9284 | * @return this object for method chaining |
| 9285 | * @see android.app.Notification.WearableExtender#getPages |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9286 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9287 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9288 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9289 | public WearableExtender addPages(List<Notification> pages) { |
| 9290 | mPages.addAll(pages); |
| 9291 | return this; |
| 9292 | } |
| 9293 | |
| 9294 | /** |
| 9295 | * Clear all additional pages present on this builder. |
| 9296 | * @return this object for method chaining. |
| 9297 | * @see #addPage |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9298 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9299 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9300 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9301 | public WearableExtender clearPages() { |
| 9302 | mPages.clear(); |
| 9303 | return this; |
| 9304 | } |
| 9305 | |
| 9306 | /** |
| 9307 | * Get the array of additional pages of content for displaying this notification. The |
| 9308 | * current notification forms the first page, and elements within this array form |
| 9309 | * subsequent pages. This field can be used to separate a notification into multiple |
| 9310 | * sections. |
| 9311 | * @return the pages for this notification |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9312 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9313 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9314 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9315 | public List<Notification> getPages() { |
| 9316 | return mPages; |
| 9317 | } |
| 9318 | |
| 9319 | /** |
| 9320 | * Set a background image to be displayed behind the notification content. |
| 9321 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 9322 | * will work with any notification style. |
| 9323 | * |
| 9324 | * @param background the background bitmap |
| 9325 | * @return this object for method chaining |
| 9326 | * @see android.app.Notification.WearableExtender#getBackground |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9327 | * @deprecated Background images are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9328 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9329 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9330 | public WearableExtender setBackground(Bitmap background) { |
| 9331 | mBackground = background; |
| 9332 | return this; |
| 9333 | } |
| 9334 | |
| 9335 | /** |
| 9336 | * Get a background image to be displayed behind the notification content. |
| 9337 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 9338 | * will work with any notification style. |
| 9339 | * |
| 9340 | * @return the background image |
| 9341 | * @see android.app.Notification.WearableExtender#setBackground |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9342 | * @deprecated Background images are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9343 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9344 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9345 | public Bitmap getBackground() { |
| 9346 | return mBackground; |
| 9347 | } |
| 9348 | |
| 9349 | /** |
| 9350 | * Set an icon that goes with the content of this notification. |
| 9351 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9352 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9353 | public WearableExtender setContentIcon(int icon) { |
| 9354 | mContentIcon = icon; |
| 9355 | return this; |
| 9356 | } |
| 9357 | |
| 9358 | /** |
| 9359 | * Get an icon that goes with the content of this notification. |
| 9360 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9361 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9362 | public int getContentIcon() { |
| 9363 | return mContentIcon; |
| 9364 | } |
| 9365 | |
| 9366 | /** |
| 9367 | * Set the gravity that the content icon should have within the notification display. |
| 9368 | * Supported values include {@link android.view.Gravity#START} and |
| 9369 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 9370 | * @see #setContentIcon |
| 9371 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9372 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9373 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 9374 | mContentIconGravity = contentIconGravity; |
| 9375 | return this; |
| 9376 | } |
| 9377 | |
| 9378 | /** |
| 9379 | * Get the gravity that the content icon should have within the notification display. |
| 9380 | * Supported values include {@link android.view.Gravity#START} and |
| 9381 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 9382 | * @see #getContentIcon |
| 9383 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9384 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9385 | public int getContentIconGravity() { |
| 9386 | return mContentIconGravity; |
| 9387 | } |
| 9388 | |
| 9389 | /** |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9390 | * Set an action from this notification's actions as the primary action. If the action has a |
| 9391 | * {@link RemoteInput} associated with it, shortcuts to the options for that input are shown |
| 9392 | * directly on the notification. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9393 | * |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9394 | * @param actionIndex The index of the primary action. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9395 | * If wearable actions were added to the main notification, this index |
| 9396 | * will apply to that list, otherwise it will apply to the regular |
| 9397 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9398 | */ |
| 9399 | public WearableExtender setContentAction(int actionIndex) { |
| 9400 | mContentActionIndex = actionIndex; |
| 9401 | return this; |
| 9402 | } |
| 9403 | |
| 9404 | /** |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9405 | * Get the index of the notification action, if any, that was specified as the primary |
| 9406 | * action. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9407 | * |
| 9408 | * <p>If wearable specific actions were added to the main notification, this index will |
| 9409 | * 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] | 9410 | * |
| 9411 | * @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] | 9412 | */ |
| 9413 | public int getContentAction() { |
| 9414 | return mContentActionIndex; |
| 9415 | } |
| 9416 | |
| 9417 | /** |
| 9418 | * Set the gravity that this notification should have within the available viewport space. |
| 9419 | * Supported values include {@link android.view.Gravity#TOP}, |
| 9420 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 9421 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 9422 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9423 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9424 | public WearableExtender setGravity(int gravity) { |
| 9425 | mGravity = gravity; |
| 9426 | return this; |
| 9427 | } |
| 9428 | |
| 9429 | /** |
| 9430 | * Get the gravity that this notification should have within the available viewport space. |
| 9431 | * Supported values include {@link android.view.Gravity#TOP}, |
| 9432 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 9433 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 9434 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9435 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9436 | public int getGravity() { |
| 9437 | return mGravity; |
| 9438 | } |
| 9439 | |
| 9440 | /** |
| 9441 | * Set the custom size preset for the display of this notification out of the available |
| 9442 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 9443 | * {@link #SIZE_LARGE}. |
| 9444 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 9445 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 9446 | * documentation for the preset in question. See also |
| 9447 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 9448 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9449 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9450 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 9451 | mCustomSizePreset = sizePreset; |
| 9452 | return this; |
| 9453 | } |
| 9454 | |
| 9455 | /** |
| 9456 | * Get the custom size preset for the display of this notification out of the available |
| 9457 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 9458 | * {@link #SIZE_LARGE}. |
| 9459 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 9460 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 9461 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 9462 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9463 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9464 | public int getCustomSizePreset() { |
| 9465 | return mCustomSizePreset; |
| 9466 | } |
| 9467 | |
| 9468 | /** |
| 9469 | * Set the custom height in pixels for the display of this notification's content. |
| 9470 | * <p>This option is only available for custom display notifications created |
| 9471 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 9472 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 9473 | * {@link #getCustomContentHeight}. |
| 9474 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9475 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9476 | public WearableExtender setCustomContentHeight(int height) { |
| 9477 | mCustomContentHeight = height; |
| 9478 | return this; |
| 9479 | } |
| 9480 | |
| 9481 | /** |
| 9482 | * Get the custom height in pixels for the display of this notification's content. |
| 9483 | * <p>This option is only available for custom display notifications created |
| 9484 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 9485 | * {@link #setCustomContentHeight}. |
| 9486 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9487 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9488 | public int getCustomContentHeight() { |
| 9489 | return mCustomContentHeight; |
| 9490 | } |
| 9491 | |
| 9492 | /** |
| 9493 | * Set whether the scrolling position for the contents of this notification should start |
| 9494 | * at the bottom of the contents instead of the top when the contents are too long to |
| 9495 | * display within the screen. Default is false (start scroll at the top). |
| 9496 | */ |
| 9497 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 9498 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 9499 | return this; |
| 9500 | } |
| 9501 | |
| 9502 | /** |
| 9503 | * Get whether the scrolling position for the contents of this notification should start |
| 9504 | * at the bottom of the contents instead of the top when the contents are too long to |
| 9505 | * display within the screen. Default is false (start scroll at the top). |
| 9506 | */ |
| 9507 | public boolean getStartScrollBottom() { |
| 9508 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 9509 | } |
| 9510 | |
| 9511 | /** |
| 9512 | * Set whether the content intent is available when the wearable device is not connected |
| 9513 | * to a companion device. The user can still trigger this intent when the wearable device |
| 9514 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 9515 | * Defaults to true. |
| 9516 | */ |
| 9517 | public WearableExtender setContentIntentAvailableOffline( |
| 9518 | boolean contentIntentAvailableOffline) { |
| 9519 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 9520 | return this; |
| 9521 | } |
| 9522 | |
| 9523 | /** |
| 9524 | * Get whether the content intent is available when the wearable device is not connected |
| 9525 | * to a companion device. The user can still trigger this intent when the wearable device |
| 9526 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 9527 | * Defaults to true. |
| 9528 | */ |
| 9529 | public boolean getContentIntentAvailableOffline() { |
| 9530 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 9531 | } |
| 9532 | |
| 9533 | /** |
| 9534 | * Set a hint that this notification's icon should not be displayed. |
| 9535 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 9536 | * @return this object for method chaining |
| 9537 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9538 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9539 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 9540 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 9541 | return this; |
| 9542 | } |
| 9543 | |
| 9544 | /** |
| 9545 | * Get a hint that this notification's icon should not be displayed. |
| 9546 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 9547 | * The default value is {@code false} if this was never set. |
| 9548 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9549 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9550 | public boolean getHintHideIcon() { |
| 9551 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 9552 | } |
| 9553 | |
| 9554 | /** |
| 9555 | * Set a visual hint that only the background image of this notification should be |
| 9556 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 9557 | * to sub-pages added using {@link #addPage}. |
| 9558 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9559 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9560 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 9561 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 9562 | return this; |
| 9563 | } |
| 9564 | |
| 9565 | /** |
| 9566 | * Get a visual hint that only the background image of this notification should be |
| 9567 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 9568 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 9569 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9570 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9571 | public boolean getHintShowBackgroundOnly() { |
| 9572 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 9573 | } |
| 9574 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9575 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 9576 | * Set a hint that this notification's background should not be clipped if possible, |
| 9577 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 9578 | * 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] | 9579 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 9580 | * @return this object for method chaining |
| 9581 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9582 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9583 | public WearableExtender setHintAvoidBackgroundClipping( |
| 9584 | boolean hintAvoidBackgroundClipping) { |
| 9585 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 9586 | return this; |
| 9587 | } |
| 9588 | |
| 9589 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 9590 | * Get a hint that this notification's background should not be clipped if possible, |
| 9591 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 9592 | * 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] | 9593 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 9594 | * otherwise. The default value is {@code false} if this was never set. |
| 9595 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9596 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9597 | public boolean getHintAvoidBackgroundClipping() { |
| 9598 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 9599 | } |
| 9600 | |
| 9601 | /** |
| 9602 | * Set a hint that the screen should remain on for at least this duration when |
| 9603 | * this notification is displayed on the screen. |
| 9604 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 9605 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 9606 | * @return this object for method chaining |
| 9607 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9608 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9609 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 9610 | mHintScreenTimeout = timeout; |
| 9611 | return this; |
| 9612 | } |
| 9613 | |
| 9614 | /** |
| 9615 | * Get the duration, in milliseconds, that the screen should remain on for |
| 9616 | * when this notification is displayed. |
| 9617 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 9618 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 9619 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9620 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9621 | public int getHintScreenTimeout() { |
| 9622 | return mHintScreenTimeout; |
| 9623 | } |
| 9624 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9625 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9626 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 9627 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 9628 | * qr codes, as well as other simple black-and-white tickets. |
| 9629 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 9630 | * @return this object for method chaining |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9631 | * @deprecated This feature is no longer supported. |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9632 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9633 | @Deprecated |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9634 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 9635 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 9636 | return this; |
| 9637 | } |
| 9638 | |
| 9639 | /** |
| 9640 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 9641 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 9642 | * qr codes, as well as other simple black-and-white tickets. |
| 9643 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 9644 | * otherwise. The default value is {@code false} if this was never set. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9645 | * @deprecated This feature is no longer supported. |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9646 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9647 | @Deprecated |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9648 | public boolean getHintAmbientBigPicture() { |
| 9649 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 9650 | } |
| 9651 | |
| 9652 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9653 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 9654 | * directly, telling the platform that it can generate the appropriate transitions. |
| 9655 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 9656 | * an activity and transitions should be generated, false otherwise. |
| 9657 | * @return this object for method chaining |
| 9658 | */ |
| 9659 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 9660 | boolean hintContentIntentLaunchesActivity) { |
| 9661 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 9662 | return this; |
| 9663 | } |
| 9664 | |
| 9665 | /** |
| 9666 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 9667 | * directly, telling the platform that it can generate the appropriate transitions |
| 9668 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 9669 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 9670 | */ |
| 9671 | public boolean getHintContentIntentLaunchesActivity() { |
| 9672 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 9673 | } |
| 9674 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9675 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9676 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 9677 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 9678 | * 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] | 9679 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9680 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9681 | * @param dismissalId the dismissal id of the notification. |
| 9682 | * @return this object for method chaining |
| 9683 | */ |
| 9684 | public WearableExtender setDismissalId(String dismissalId) { |
| 9685 | mDismissalId = dismissalId; |
| 9686 | return this; |
| 9687 | } |
| 9688 | |
| 9689 | /** |
| 9690 | * Returns the dismissal id of the notification. |
| 9691 | * @return the dismissal id of the notification or null if it has not been set. |
| 9692 | */ |
| 9693 | public String getDismissalId() { |
| 9694 | return mDismissalId; |
| 9695 | } |
| 9696 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9697 | /** |
| 9698 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 9699 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 9700 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 9701 | * Features to Notifications</a> for more information. |
| 9702 | * @param bridgeTag the bridge tag of the notification. |
| 9703 | * @return this object for method chaining |
| 9704 | */ |
| 9705 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 9706 | mBridgeTag = bridgeTag; |
| 9707 | return this; |
| 9708 | } |
| 9709 | |
| 9710 | /** |
| 9711 | * Returns the bridge tag of the notification. |
| 9712 | * @return the bridge tag or null if not present. |
| 9713 | */ |
| 9714 | public String getBridgeTag() { |
| 9715 | return mBridgeTag; |
| 9716 | } |
| 9717 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9718 | private void setFlag(int mask, boolean value) { |
| 9719 | if (value) { |
| 9720 | mFlags |= mask; |
| 9721 | } else { |
| 9722 | mFlags &= ~mask; |
| 9723 | } |
| 9724 | } |
| 9725 | } |
| 9726 | |
| 9727 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9728 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 9729 | * with car extensions: |
| 9730 | * |
| 9731 | * <ol> |
| 9732 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 9733 | * properties. |
| 9734 | * <li>Create a {@link CarExtender}. |
| 9735 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 9736 | * {@link CarExtender}. |
| 9737 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9738 | * to apply the extensions to a notification. |
| 9739 | * </ol> |
| 9740 | * |
| 9741 | * <pre class="prettyprint"> |
| 9742 | * Notification notification = new Notification.Builder(context) |
| 9743 | * ... |
| 9744 | * .extend(new CarExtender() |
| 9745 | * .set*(...)) |
| 9746 | * .build(); |
| 9747 | * </pre> |
| 9748 | * |
| 9749 | * <p>Car extensions can be accessed on an existing notification by using the |
| 9750 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 9751 | * to access values. |
| 9752 | */ |
| 9753 | public static final class CarExtender implements Extender { |
| 9754 | private static final String TAG = "CarExtender"; |
| 9755 | |
| 9756 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 9757 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 9758 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 9759 | private static final String EXTRA_COLOR = "app_color"; |
| 9760 | |
| 9761 | private Bitmap mLargeIcon; |
| 9762 | private UnreadConversation mUnreadConversation; |
| 9763 | private int mColor = Notification.COLOR_DEFAULT; |
| 9764 | |
| 9765 | /** |
| 9766 | * Create a {@link CarExtender} with default options. |
| 9767 | */ |
| 9768 | public CarExtender() { |
| 9769 | } |
| 9770 | |
| 9771 | /** |
| 9772 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 9773 | * |
| 9774 | * @param notif The notification from which to copy options. |
| 9775 | */ |
| 9776 | public CarExtender(Notification notif) { |
| 9777 | Bundle carBundle = notif.extras == null ? |
| 9778 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 9779 | if (carBundle != null) { |
| 9780 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 9781 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 9782 | |
| 9783 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 9784 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 9785 | } |
| 9786 | } |
| 9787 | |
| 9788 | /** |
| 9789 | * Apply car extensions to a notification that is being built. This is typically called by |
| 9790 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9791 | * method of {@link Notification.Builder}. |
| 9792 | */ |
| 9793 | @Override |
| 9794 | public Notification.Builder extend(Notification.Builder builder) { |
| 9795 | Bundle carExtensions = new Bundle(); |
| 9796 | |
| 9797 | if (mLargeIcon != null) { |
| 9798 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 9799 | } |
| 9800 | if (mColor != Notification.COLOR_DEFAULT) { |
| 9801 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 9802 | } |
| 9803 | |
| 9804 | if (mUnreadConversation != null) { |
| 9805 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 9806 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 9807 | } |
| 9808 | |
| 9809 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 9810 | return builder; |
| 9811 | } |
| 9812 | |
| 9813 | /** |
| 9814 | * Sets the accent color to use when Android Auto presents the notification. |
| 9815 | * |
| 9816 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 9817 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 9818 | * automotive setting. This method can be used to override the color provided in the |
| 9819 | * notification in such a situation. |
| 9820 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9821 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9822 | mColor = color; |
| 9823 | return this; |
| 9824 | } |
| 9825 | |
| 9826 | /** |
| 9827 | * Gets the accent color. |
| 9828 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 9829 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9830 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9831 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9832 | public int getColor() { |
| 9833 | return mColor; |
| 9834 | } |
| 9835 | |
| 9836 | /** |
| 9837 | * Sets the large icon of the car notification. |
| 9838 | * |
| 9839 | * If no large icon is set in the extender, Android Auto will display the icon |
| 9840 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 9841 | * |
| 9842 | * @param largeIcon The large icon to use in the car notification. |
| 9843 | * @return This object for method chaining. |
| 9844 | */ |
| 9845 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 9846 | mLargeIcon = largeIcon; |
| 9847 | return this; |
| 9848 | } |
| 9849 | |
| 9850 | /** |
| 9851 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 9852 | * |
| 9853 | * @return The large icon for the car notification. |
| 9854 | * @see CarExtender#setLargeIcon |
| 9855 | */ |
| 9856 | public Bitmap getLargeIcon() { |
| 9857 | return mLargeIcon; |
| 9858 | } |
| 9859 | |
| 9860 | /** |
| 9861 | * Sets the unread conversation in a message notification. |
| 9862 | * |
| 9863 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 9864 | * @return This object for method chaining. |
| 9865 | */ |
| 9866 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 9867 | mUnreadConversation = unreadConversation; |
| 9868 | return this; |
| 9869 | } |
| 9870 | |
| 9871 | /** |
| 9872 | * Returns the unread conversation conveyed by this notification. |
| 9873 | * @see #setUnreadConversation(UnreadConversation) |
| 9874 | */ |
| 9875 | public UnreadConversation getUnreadConversation() { |
| 9876 | return mUnreadConversation; |
| 9877 | } |
| 9878 | |
| 9879 | /** |
| 9880 | * A class which holds the unread messages from a conversation. |
| 9881 | */ |
| 9882 | public static class UnreadConversation { |
| 9883 | private static final String KEY_AUTHOR = "author"; |
| 9884 | private static final String KEY_TEXT = "text"; |
| 9885 | private static final String KEY_MESSAGES = "messages"; |
| 9886 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 9887 | private static final String KEY_ON_REPLY = "on_reply"; |
| 9888 | private static final String KEY_ON_READ = "on_read"; |
| 9889 | private static final String KEY_PARTICIPANTS = "participants"; |
| 9890 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 9891 | |
| 9892 | private final String[] mMessages; |
| 9893 | private final RemoteInput mRemoteInput; |
| 9894 | private final PendingIntent mReplyPendingIntent; |
| 9895 | private final PendingIntent mReadPendingIntent; |
| 9896 | private final String[] mParticipants; |
| 9897 | private final long mLatestTimestamp; |
| 9898 | |
| 9899 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 9900 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 9901 | String[] participants, long latestTimestamp) { |
| 9902 | mMessages = messages; |
| 9903 | mRemoteInput = remoteInput; |
| 9904 | mReadPendingIntent = readPendingIntent; |
| 9905 | mReplyPendingIntent = replyPendingIntent; |
| 9906 | mParticipants = participants; |
| 9907 | mLatestTimestamp = latestTimestamp; |
| 9908 | } |
| 9909 | |
| 9910 | /** |
| 9911 | * Gets the list of messages conveyed by this notification. |
| 9912 | */ |
| 9913 | public String[] getMessages() { |
| 9914 | return mMessages; |
| 9915 | } |
| 9916 | |
| 9917 | /** |
| 9918 | * Gets the remote input that will be used to convey the response to a message list, or |
| 9919 | * null if no such remote input exists. |
| 9920 | */ |
| 9921 | public RemoteInput getRemoteInput() { |
| 9922 | return mRemoteInput; |
| 9923 | } |
| 9924 | |
| 9925 | /** |
| 9926 | * Gets the pending intent that will be triggered when the user replies to this |
| 9927 | * notification. |
| 9928 | */ |
| 9929 | public PendingIntent getReplyPendingIntent() { |
| 9930 | return mReplyPendingIntent; |
| 9931 | } |
| 9932 | |
| 9933 | /** |
| 9934 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 9935 | * in this object's message list. |
| 9936 | */ |
| 9937 | public PendingIntent getReadPendingIntent() { |
| 9938 | return mReadPendingIntent; |
| 9939 | } |
| 9940 | |
| 9941 | /** |
| 9942 | * Gets the participants in the conversation. |
| 9943 | */ |
| 9944 | public String[] getParticipants() { |
| 9945 | return mParticipants; |
| 9946 | } |
| 9947 | |
| 9948 | /** |
| 9949 | * Gets the firs participant in the conversation. |
| 9950 | */ |
| 9951 | public String getParticipant() { |
| 9952 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 9953 | } |
| 9954 | |
| 9955 | /** |
| 9956 | * Gets the timestamp of the conversation. |
| 9957 | */ |
| 9958 | public long getLatestTimestamp() { |
| 9959 | return mLatestTimestamp; |
| 9960 | } |
| 9961 | |
| 9962 | Bundle getBundleForUnreadConversation() { |
| 9963 | Bundle b = new Bundle(); |
| 9964 | String author = null; |
| 9965 | if (mParticipants != null && mParticipants.length > 1) { |
| 9966 | author = mParticipants[0]; |
| 9967 | } |
| 9968 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 9969 | for (int i = 0; i < messages.length; i++) { |
| 9970 | Bundle m = new Bundle(); |
| 9971 | m.putString(KEY_TEXT, mMessages[i]); |
| 9972 | m.putString(KEY_AUTHOR, author); |
| 9973 | messages[i] = m; |
| 9974 | } |
| 9975 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 9976 | if (mRemoteInput != null) { |
| 9977 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 9978 | } |
| 9979 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 9980 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 9981 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 9982 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 9983 | return b; |
| 9984 | } |
| 9985 | |
| 9986 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 9987 | if (b == null) { |
| 9988 | return null; |
| 9989 | } |
| 9990 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 9991 | String[] messages = null; |
| 9992 | if (parcelableMessages != null) { |
| 9993 | String[] tmp = new String[parcelableMessages.length]; |
| 9994 | boolean success = true; |
| 9995 | for (int i = 0; i < tmp.length; i++) { |
| 9996 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 9997 | success = false; |
| 9998 | break; |
| 9999 | } |
| 10000 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 10001 | if (tmp[i] == null) { |
| 10002 | success = false; |
| 10003 | break; |
| 10004 | } |
| 10005 | } |
| 10006 | if (success) { |
| 10007 | messages = tmp; |
| 10008 | } else { |
| 10009 | return null; |
| 10010 | } |
| 10011 | } |
| 10012 | |
| 10013 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 10014 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 10015 | |
| 10016 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 10017 | |
| 10018 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 10019 | if (participants == null || participants.length != 1) { |
| 10020 | return null; |
| 10021 | } |
| 10022 | |
| 10023 | return new UnreadConversation(messages, |
| 10024 | remoteInput, |
| 10025 | onReply, |
| 10026 | onRead, |
| 10027 | participants, b.getLong(KEY_TIMESTAMP)); |
| 10028 | } |
| 10029 | }; |
| 10030 | |
| 10031 | /** |
| 10032 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 10033 | */ |
| 10034 | public static class Builder { |
| 10035 | private final List<String> mMessages = new ArrayList<String>(); |
| 10036 | private final String mParticipant; |
| 10037 | private RemoteInput mRemoteInput; |
| 10038 | private PendingIntent mReadPendingIntent; |
| 10039 | private PendingIntent mReplyPendingIntent; |
| 10040 | private long mLatestTimestamp; |
| 10041 | |
| 10042 | /** |
| 10043 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 10044 | * |
| 10045 | * @param name The name of the other participant in the conversation. |
| 10046 | */ |
| 10047 | public Builder(String name) { |
| 10048 | mParticipant = name; |
| 10049 | } |
| 10050 | |
| 10051 | /** |
| 10052 | * Appends a new unread message to the list of messages for this conversation. |
| 10053 | * |
| 10054 | * The messages should be added from oldest to newest. |
| 10055 | * |
| 10056 | * @param message The text of the new unread message. |
| 10057 | * @return This object for method chaining. |
| 10058 | */ |
| 10059 | public Builder addMessage(String message) { |
| 10060 | mMessages.add(message); |
| 10061 | return this; |
| 10062 | } |
| 10063 | |
| 10064 | /** |
| 10065 | * Sets the pending intent and remote input which will convey the reply to this |
| 10066 | * notification. |
| 10067 | * |
| 10068 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 10069 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 10070 | * @return This object for method chaining. |
| 10071 | * |
| 10072 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 10073 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 10074 | */ |
| 10075 | public Builder setReplyAction( |
| 10076 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 10077 | mRemoteInput = remoteInput; |
| 10078 | mReplyPendingIntent = pendingIntent; |
| 10079 | |
| 10080 | return this; |
| 10081 | } |
| 10082 | |
| 10083 | /** |
| 10084 | * Sets the pending intent that will be sent once the messages in this notification |
| 10085 | * are read. |
| 10086 | * |
| 10087 | * @param pendingIntent The pending intent to use. |
| 10088 | * @return This object for method chaining. |
| 10089 | */ |
| 10090 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 10091 | mReadPendingIntent = pendingIntent; |
| 10092 | return this; |
| 10093 | } |
| 10094 | |
| 10095 | /** |
| 10096 | * Sets the timestamp of the most recent message in an unread conversation. |
| 10097 | * |
| 10098 | * If a messaging notification has been posted by your application and has not |
| 10099 | * yet been cancelled, posting a later notification with the same id and tag |
| 10100 | * but without a newer timestamp may result in Android Auto not displaying a |
| 10101 | * heads up notification for the later notification. |
| 10102 | * |
| 10103 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 10104 | * @return This object for method chaining. |
| 10105 | */ |
| 10106 | public Builder setLatestTimestamp(long timestamp) { |
| 10107 | mLatestTimestamp = timestamp; |
| 10108 | return this; |
| 10109 | } |
| 10110 | |
| 10111 | /** |
| 10112 | * Builds a new unread conversation object. |
| 10113 | * |
| 10114 | * @return The new unread conversation object. |
| 10115 | */ |
| 10116 | public UnreadConversation build() { |
| 10117 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 10118 | String[] participants = { mParticipant }; |
| 10119 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 10120 | mReadPendingIntent, participants, mLatestTimestamp); |
| 10121 | } |
| 10122 | } |
| 10123 | } |
| 10124 | |
| 10125 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10126 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 10127 | * with a TV extension: |
| 10128 | * |
| 10129 | * <ol> |
| 10130 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 10131 | * <li>Create a {@link TvExtender}. |
| 10132 | * <li>Set TV-specific properties using the {@code set} methods of |
| 10133 | * {@link TvExtender}. |
| 10134 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 10135 | * to apply the extension to a notification. |
| 10136 | * </ol> |
| 10137 | * |
| 10138 | * <pre class="prettyprint"> |
| 10139 | * Notification notification = new Notification.Builder(context) |
| 10140 | * ... |
| 10141 | * .extend(new TvExtender() |
| 10142 | * .set*(...)) |
| 10143 | * .build(); |
| 10144 | * </pre> |
| 10145 | * |
| 10146 | * <p>TV extensions can be accessed on an existing notification by using the |
| 10147 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 10148 | * to access values. |
| 10149 | * |
| 10150 | * @hide |
| 10151 | */ |
| 10152 | @SystemApi |
| 10153 | public static final class TvExtender implements Extender { |
| 10154 | private static final String TAG = "TvExtender"; |
| 10155 | |
| 10156 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 10157 | private static final String EXTRA_FLAGS = "flags"; |
| 10158 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 10159 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10160 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10161 | private static final String EXTRA_SUPPRESS_SHOW_OVER_APPS = "suppressShowOverApps"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10162 | |
| 10163 | // Flags bitwise-ored to mFlags |
| 10164 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 10165 | |
| 10166 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10167 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10168 | private PendingIntent mContentIntent; |
| 10169 | private PendingIntent mDeleteIntent; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10170 | private boolean mSuppressShowOverApps; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10171 | |
| 10172 | /** |
| 10173 | * Create a {@link TvExtender} with default options. |
| 10174 | */ |
| 10175 | public TvExtender() { |
| 10176 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 10177 | } |
| 10178 | |
| 10179 | /** |
| 10180 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 10181 | * |
| 10182 | * @param notif The notification from which to copy options. |
| 10183 | */ |
| 10184 | public TvExtender(Notification notif) { |
| 10185 | Bundle bundle = notif.extras == null ? |
| 10186 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 10187 | if (bundle != null) { |
| 10188 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10189 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10190 | mSuppressShowOverApps = bundle.getBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10191 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 10192 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 10193 | } |
| 10194 | } |
| 10195 | |
| 10196 | /** |
| 10197 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 10198 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 10199 | * method of {@link Notification.Builder}. |
| 10200 | */ |
| 10201 | @Override |
| 10202 | public Notification.Builder extend(Notification.Builder builder) { |
| 10203 | Bundle bundle = new Bundle(); |
| 10204 | |
| 10205 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10206 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10207 | bundle.putBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS, mSuppressShowOverApps); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10208 | if (mContentIntent != null) { |
| 10209 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 10210 | } |
| 10211 | |
| 10212 | if (mDeleteIntent != null) { |
| 10213 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 10214 | } |
| 10215 | |
| 10216 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 10217 | return builder; |
| 10218 | } |
| 10219 | |
| 10220 | /** |
| 10221 | * Returns true if this notification should be shown on TV. This method return true |
| 10222 | * if the notification was extended with a TvExtender. |
| 10223 | */ |
| 10224 | public boolean isAvailableOnTv() { |
| 10225 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 10226 | } |
| 10227 | |
| 10228 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10229 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 10230 | * It can be different from the channel that the notification is delivered to when |
| 10231 | * posting on a non-TV device. |
| 10232 | */ |
| 10233 | public TvExtender setChannel(String channelId) { |
| 10234 | mChannelId = channelId; |
| 10235 | return this; |
| 10236 | } |
| 10237 | |
| 10238 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 10239 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 10240 | * It can be different from the channel that the notification is delivered to when |
| 10241 | * posting on a non-TV device. |
| 10242 | */ |
| 10243 | public TvExtender setChannelId(String channelId) { |
| 10244 | mChannelId = channelId; |
| 10245 | return this; |
| 10246 | } |
| 10247 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 10248 | /** @removed */ |
| 10249 | @Deprecated |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10250 | public String getChannel() { |
| 10251 | return mChannelId; |
| 10252 | } |
| 10253 | |
| 10254 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 10255 | * Returns the id of the channel this notification posts to on TV. |
| 10256 | */ |
| 10257 | public String getChannelId() { |
| 10258 | return mChannelId; |
| 10259 | } |
| 10260 | |
| 10261 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10262 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 10263 | * If provided, it is used instead of the content intent specified |
| 10264 | * at the level of Notification. |
| 10265 | */ |
| 10266 | public TvExtender setContentIntent(PendingIntent intent) { |
| 10267 | mContentIntent = intent; |
| 10268 | return this; |
| 10269 | } |
| 10270 | |
| 10271 | /** |
| 10272 | * Returns the TV-specific content intent. If this method returns null, the |
| 10273 | * main content intent on the notification should be used. |
| 10274 | * |
| 10275 | * @see {@link Notification#contentIntent} |
| 10276 | */ |
| 10277 | public PendingIntent getContentIntent() { |
| 10278 | return mContentIntent; |
| 10279 | } |
| 10280 | |
| 10281 | /** |
| 10282 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 10283 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 10284 | * at the level of Notification. |
| 10285 | */ |
| 10286 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 10287 | mDeleteIntent = intent; |
| 10288 | return this; |
| 10289 | } |
| 10290 | |
| 10291 | /** |
| 10292 | * Returns the TV-specific delete intent. If this method returns null, the |
| 10293 | * main delete intent on the notification should be used. |
| 10294 | * |
| 10295 | * @see {@link Notification#deleteIntent} |
| 10296 | */ |
| 10297 | public PendingIntent getDeleteIntent() { |
| 10298 | return mDeleteIntent; |
| 10299 | } |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10300 | |
| 10301 | /** |
| 10302 | * Specifies whether this notification should suppress showing a message over top of apps |
| 10303 | * outside of the launcher. |
| 10304 | */ |
| 10305 | public TvExtender setSuppressShowOverApps(boolean suppress) { |
| 10306 | mSuppressShowOverApps = suppress; |
| 10307 | return this; |
| 10308 | } |
| 10309 | |
| 10310 | /** |
| 10311 | * Returns true if this notification should not show messages over top of apps |
| 10312 | * outside of the launcher. |
| 10313 | */ |
| 10314 | public boolean getSuppressShowOverApps() { |
| 10315 | return mSuppressShowOverApps; |
| 10316 | } |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10317 | } |
| 10318 | |
| 10319 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 10320 | * Get an array of Notification objects from a parcelable array bundle field. |
| 10321 | * Update the bundle to have a typed array so fetches in the future don't need |
| 10322 | * to do an array copy. |
| 10323 | */ |
| 10324 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 10325 | Parcelable[] array = bundle.getParcelableArray(key); |
| 10326 | if (array instanceof Notification[] || array == null) { |
| 10327 | return (Notification[]) array; |
| 10328 | } |
| 10329 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 10330 | Notification[].class); |
| 10331 | bundle.putParcelableArray(key, typedArray); |
| 10332 | return typedArray; |
| 10333 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 10334 | |
| 10335 | private static class BuilderRemoteViews extends RemoteViews { |
| 10336 | public BuilderRemoteViews(Parcel parcel) { |
| 10337 | super(parcel); |
| 10338 | } |
| 10339 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 10340 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 10341 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 10342 | } |
| 10343 | |
| 10344 | @Override |
| 10345 | public BuilderRemoteViews clone() { |
| 10346 | Parcel p = Parcel.obtain(); |
| 10347 | writeToParcel(p, 0); |
| 10348 | p.setDataPosition(0); |
| 10349 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 10350 | p.recycle(); |
| 10351 | return brv; |
| 10352 | } |
| 10353 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10354 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10355 | /** |
| 10356 | * A result object where information about the template that was created is saved. |
| 10357 | */ |
| 10358 | private static class TemplateBindResult { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10359 | int mIconMarginEnd; |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 10360 | boolean mRightIconContainerVisible; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10361 | |
| 10362 | /** |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10363 | * 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] | 10364 | * with the right actions. |
| 10365 | */ |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10366 | public int getIconMarginEnd() { |
| 10367 | return mIconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10368 | } |
| 10369 | |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 10370 | /** |
| 10371 | * Is the icon container visible on the right size because of the reply button or the |
| 10372 | * right icon. |
| 10373 | */ |
| 10374 | public boolean isRightIconContainerVisible() { |
| 10375 | return mRightIconContainerVisible; |
| 10376 | } |
| 10377 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10378 | public void setIconMarginEnd(int iconMarginEnd) { |
| 10379 | this.mIconMarginEnd = iconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10380 | } |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 10381 | |
| 10382 | public void setRightIconContainerVisible(boolean iconContainerVisible) { |
| 10383 | mRightIconContainerVisible = iconContainerVisible; |
| 10384 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10385 | } |
| 10386 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10387 | private static class StandardTemplateParams { |
| 10388 | boolean hasProgress = true; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10389 | CharSequence title; |
| 10390 | CharSequence text; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 10391 | CharSequence headerTextSecondary; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10392 | CharSequence summaryText; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 10393 | int maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10394 | boolean hideLargeIcon; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10395 | boolean hideReplyIcon; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10396 | boolean allowColorization = true; |
| 10397 | boolean forceDefaultColor = false; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10398 | |
| 10399 | final StandardTemplateParams reset() { |
| 10400 | hasProgress = true; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10401 | title = null; |
| 10402 | text = null; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10403 | summaryText = null; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 10404 | headerTextSecondary = null; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 10405 | maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10406 | allowColorization = true; |
| 10407 | forceDefaultColor = false; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10408 | return this; |
| 10409 | } |
| 10410 | |
| 10411 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 10412 | this.hasProgress = hasProgress; |
| 10413 | return this; |
| 10414 | } |
| 10415 | |
| 10416 | final StandardTemplateParams title(CharSequence title) { |
| 10417 | this.title = title; |
| 10418 | return this; |
| 10419 | } |
| 10420 | |
| 10421 | final StandardTemplateParams text(CharSequence text) { |
| 10422 | this.text = text; |
| 10423 | return this; |
| 10424 | } |
| 10425 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10426 | final StandardTemplateParams summaryText(CharSequence text) { |
| 10427 | this.summaryText = text; |
| 10428 | return this; |
| 10429 | } |
| 10430 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 10431 | final StandardTemplateParams headerTextSecondary(CharSequence text) { |
| 10432 | this.headerTextSecondary = text; |
| 10433 | return this; |
| 10434 | } |
| 10435 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10436 | final StandardTemplateParams hideLargeIcon(boolean hideLargeIcon) { |
| 10437 | this.hideLargeIcon = hideLargeIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10438 | return this; |
| 10439 | } |
| 10440 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10441 | final StandardTemplateParams hideReplyIcon(boolean hideReplyIcon) { |
| 10442 | this.hideReplyIcon = hideReplyIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10443 | return this; |
| 10444 | } |
| 10445 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10446 | final StandardTemplateParams disallowColorization() { |
| 10447 | this.allowColorization = false; |
| 10448 | return this; |
| 10449 | } |
| 10450 | |
| 10451 | final StandardTemplateParams forceDefaultColor() { |
| 10452 | this.forceDefaultColor = true; |
| 10453 | return this; |
| 10454 | } |
| 10455 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10456 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 10457 | Bundle extras = b.mN.extras; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 10458 | this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE)); |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 10459 | |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 10460 | CharSequence text = extras.getCharSequence(EXTRA_BIG_TEXT); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 10461 | if (TextUtils.isEmpty(text)) { |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 10462 | text = extras.getCharSequence(EXTRA_TEXT); |
| 10463 | } |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 10464 | this.text = b.processLegacyText(text); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10465 | this.summaryText = extras.getCharSequence(EXTRA_SUB_TEXT); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10466 | return this; |
| 10467 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 10468 | |
| 10469 | /** |
| 10470 | * Set the maximum lines of remote input history lines allowed. |
| 10471 | * @param maxRemoteInputHistory The number of lines. |
| 10472 | * @return The builder for method chaining. |
| 10473 | */ |
| 10474 | public StandardTemplateParams setMaxRemoteInputHistory(int maxRemoteInputHistory) { |
| 10475 | this.maxRemoteInputHistory = maxRemoteInputHistory; |
| 10476 | return this; |
| 10477 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10478 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10479 | } |