The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 19 | import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast; |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 20 | |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 21 | import android.annotation.ColorInt; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 22 | import android.annotation.DrawableRes; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 23 | import android.annotation.IdRes; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 24 | import android.annotation.IntDef; |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 27 | import android.annotation.RequiresPermission; |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 28 | import android.annotation.SdkConstant; |
| 29 | import android.annotation.SdkConstant.SdkConstantType; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 30 | import android.annotation.SystemApi; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 31 | import android.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 34 | import android.content.LocusId; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 35 | import android.content.pm.ApplicationInfo; |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 37 | import android.content.pm.PackageManager.NameNotFoundException; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 38 | import android.content.pm.ShortcutInfo; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 39 | import android.content.res.ColorStateList; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 40 | import android.content.res.Configuration; |
| 41 | import android.content.res.Resources; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 42 | import android.content.res.TypedArray; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 43 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 44 | import android.graphics.Canvas; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 45 | import android.graphics.Color; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 46 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 47 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 48 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 49 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 50 | import android.media.AudioManager; |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 51 | import android.media.PlayerBase; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 52 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 54 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 55 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 56 | import android.os.Bundle; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 57 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.os.Parcel; |
| 59 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 60 | import android.os.SystemClock; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 61 | import android.os.SystemProperties; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 62 | import android.os.UserHandle; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 63 | import android.text.BidiFormatter; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 64 | import android.text.SpannableStringBuilder; |
| 65 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 67 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 68 | import android.text.style.CharacterStyle; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 69 | import android.text.style.ForegroundColorSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 70 | import android.text.style.RelativeSizeSpan; |
| 71 | import android.text.style.TextAppearanceSpan; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 72 | import android.util.ArraySet; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 73 | import android.util.Log; |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 74 | import android.util.Pair; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 75 | import android.util.SparseArray; |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 76 | import android.util.proto.ProtoOutputStream; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 77 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 78 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 79 | import android.view.View; |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 80 | import android.view.ViewGroup; |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 81 | import android.view.contentcapture.ContentCaptureContext; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 82 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import android.widget.RemoteViews; |
| 84 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 85 | import com.android.internal.R; |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 86 | import com.android.internal.annotations.VisibleForTesting; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 87 | import com.android.internal.util.ArrayUtils; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 88 | import com.android.internal.util.ContrastColorUtil; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 89 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 90 | import java.lang.annotation.Retention; |
| 91 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 92 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 93 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 94 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 95 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 96 | import java.util.List; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 97 | import java.util.Objects; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 98 | import java.util.Set; |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 99 | import java.util.function.Consumer; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | /** |
| 102 | * A class that represents how a persistent notification is to be presented to |
| 103 | * the user using the {@link android.app.NotificationManager}. |
| 104 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 105 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 106 | * easier to construct Notifications.</p> |
| 107 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 108 | * <div class="special reference"> |
| 109 | * <h3>Developer Guides</h3> |
| 110 | * <p>For a guide to creating notifications, read the |
| 111 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 112 | * developer guide.</p> |
| 113 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | */ |
| 115 | public class Notification implements Parcelable |
| 116 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 117 | private static final String TAG = "Notification"; |
| 118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 120 | * 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] | 121 | * containing application. |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 122 | */ |
| 123 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 124 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 125 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 126 | |
| 127 | /** |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 128 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 129 | * 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] | 130 | * what settings should be shown in the target app. |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 131 | */ |
| 132 | public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 133 | |
| 134 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 135 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 005c8b9 | 2017-08-24 10:35:53 -0400 | [diff] [blame] | 136 | * contain a {@link NotificationChannelGroup#getId() group id} that can be used to narrow down |
| 137 | * what settings should be shown in the target app. |
| 138 | */ |
| 139 | public static final String EXTRA_CHANNEL_GROUP_ID = "android.intent.extra.CHANNEL_GROUP_ID"; |
| 140 | |
| 141 | /** |
| 142 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 143 | * contain the tag provided to {@link NotificationManager#notify(String, int, Notification)} |
| 144 | * that can be used to narrow down what settings should be shown in the target app. |
| 145 | */ |
| 146 | public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 147 | |
| 148 | /** |
| 149 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 150 | * contain the id provided to {@link NotificationManager#notify(String, int, Notification)} |
| 151 | * that can be used to narrow down what settings should be shown in the target app. |
| 152 | */ |
| 153 | public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 154 | |
| 155 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | * Use all default values (where applicable). |
| 157 | */ |
| 158 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | /** |
| 161 | * Use the default notification sound. This will ignore any given |
| 162 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 163 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 164 | * <p> |
| 165 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 166 | * </p> |
| 167 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 169 | */ |
| 170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | public static final int DEFAULT_SOUND = 1; |
| 172 | |
| 173 | /** |
| 174 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 175 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 176 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 177 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 178 | * <p> |
| 179 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 180 | * </p> |
| 181 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 183 | */ |
| 184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | /** |
| 188 | * Use the default notification lights. This will ignore the |
| 189 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 190 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 191 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 193 | */ |
| 194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 198 | * Maximum length of CharSequences accepted by Builder and friends. |
| 199 | * |
| 200 | * <p> |
| 201 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 202 | */ |
| 203 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 204 | |
| 205 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 206 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 207 | */ |
| 208 | private static final int MAX_REPLY_HISTORY = 5; |
| 209 | |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 210 | /** |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 211 | * Maximum number of (generic) action buttons in a notification (contextual action buttons are |
| 212 | * handled separately). |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 213 | * @hide |
| 214 | */ |
| 215 | public static final int MAX_ACTION_BUTTONS = 3; |
Selim Cinek | de4de0e | 2018-01-24 16:21:07 -0800 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * If the notification contained an unsent draft for a RemoteInput when the user clicked on it, |
| 219 | * we're adding the draft as a String extra to the {@link #contentIntent} using this key. |
| 220 | * |
| 221 | * <p>Apps may use this extra to prepopulate text fields in the app, where the user usually |
| 222 | * sends messages.</p> |
| 223 | */ |
| 224 | public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; |
| 225 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 226 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 227 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 228 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 229 | * Default value: {@link System#currentTimeMillis() Now}. |
| 230 | * |
| 231 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 232 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 233 | * 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] | 234 | * timestamped according to when the activity began. |
| 235 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 236 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 237 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 238 | * <ul> |
| 239 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 240 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 241 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 242 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 243 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 244 | * <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] | 245 | * </ul> |
| 246 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 247 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 248 | * anymore by default and must be opted into by using |
| 249 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | */ |
| 251 | public long when; |
| 252 | |
| 253 | /** |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 254 | * The creation time of the notification |
| 255 | */ |
| 256 | private long creationTime; |
| 257 | |
| 258 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | * 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] | 260 | * |
| 261 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 263 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 264 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | public int icon; |
| 266 | |
| 267 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 268 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 269 | * leave it at its default value of 0. |
| 270 | * |
| 271 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 272 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 273 | */ |
| 274 | public int iconLevel; |
| 275 | |
| 276 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 277 | * The number of events that this notification represents. For example, in a new mail |
| 278 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 279 | * |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 280 | * 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] | 281 | * Starting with {@link android.os.Build.VERSION_CODES#O}, the number may be displayed as a |
| 282 | * badge icon in Launchers that support badging. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | */ |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 284 | public int number = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | |
| 286 | /** |
| 287 | * The intent to execute when the expanded status entry is clicked. If |
| 288 | * this is an activity, it must include the |
| 289 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 290 | * that you take care of task management as described in the |
| 291 | * <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] | 292 | * Stack</a> document. In particular, make sure to read the notification section |
| 293 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 294 | * Notifications</a> for the correct ways to launch an application from a |
| 295 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | */ |
| 297 | public PendingIntent contentIntent; |
| 298 | |
| 299 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 300 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 301 | * the "Clear All" button or by swiping it away individually. |
| 302 | * |
| 303 | * This probably shouldn't be launching an activity since several of those will be sent |
| 304 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | */ |
| 306 | public PendingIntent deleteIntent; |
| 307 | |
| 308 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 309 | * 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] | 310 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 311 | * <p> |
| 312 | * The system UI may choose to display a heads-up notification, instead of |
| 313 | * launching this intent, while the user is using the device. |
| 314 | * </p> |
| 315 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 316 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 317 | */ |
| 318 | public PendingIntent fullScreenIntent; |
| 319 | |
| 320 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 321 | * Text that summarizes this notification for accessibility services. |
| 322 | * |
| 323 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 324 | * accessibility services (where it serves as an audible announcement of the notification's |
| 325 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 326 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 327 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | */ |
| 329 | public CharSequence tickerText; |
| 330 | |
| 331 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 332 | * Formerly, a view showing the {@link #tickerText}. |
| 333 | * |
| 334 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 335 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 336 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 337 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 338 | |
| 339 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 340 | * The view that will represent this notification in the notification list (which is pulled |
| 341 | * down from the status bar). |
| 342 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 343 | * As of N, this field may be null. The notification view is determined by the inputs |
| 344 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 345 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 347 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | public RemoteViews contentView; |
| 349 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 350 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 351 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 352 | * opportunity to show more detail. The system UI may choose to show this |
| 353 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 354 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 355 | * 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] | 356 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 357 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 358 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 359 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 360 | public RemoteViews bigContentView; |
| 361 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 362 | |
| 363 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 364 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 365 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 366 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 367 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 368 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 369 | * 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] | 370 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 371 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 372 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 373 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 374 | public RemoteViews headsUpContentView; |
| 375 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 376 | private boolean mUsesStandardHeader; |
| 377 | |
| 378 | private static final ArraySet<Integer> STANDARD_LAYOUTS = new ArraySet<>(); |
| 379 | static { |
| 380 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_base); |
| 381 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_base); |
| 382 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_picture); |
| 383 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text); |
| 384 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_inbox); |
| 385 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging); |
| 386 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_media); |
| 387 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 388 | STANDARD_LAYOUTS.add(R.layout.notification_template_header); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 389 | } |
| 390 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 391 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 392 | * A large bitmap to be shown in the notification content area. |
| 393 | * |
| 394 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 396 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 397 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | |
| 399 | /** |
| 400 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 401 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 403 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 404 | * </p> |
| 405 | * |
| 406 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 407 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 409 | * @deprecated use {@link NotificationChannel#getSound()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 411 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | public Uri sound; |
| 413 | |
| 414 | /** |
| 415 | * Use this constant as the value for audioStreamType to request that |
| 416 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 417 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 418 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 419 | * @deprecated Use {@link NotificationChannel#getAudioAttributes()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 421 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | public static final int STREAM_DEFAULT = -1; |
| 423 | |
| 424 | /** |
| 425 | * The audio stream type to use when playing the sound. |
| 426 | * Should be one of the STREAM_ constants from |
| 427 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 428 | * |
| 429 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 431 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | public int audioStreamType = STREAM_DEFAULT; |
| 433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 435 | * The default value of {@link #audioAttributes}. |
| 436 | */ |
| 437 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 438 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 439 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 440 | .build(); |
| 441 | |
| 442 | /** |
| 443 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 444 | * |
| 445 | * @deprecated use {@link NotificationChannel#getAudioAttributes()} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 446 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 447 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 448 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 449 | |
| 450 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 451 | * The pattern with which to vibrate. |
| 452 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | * <p> |
| 454 | * To vibrate the default pattern, see {@link #defaults}. |
| 455 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 456 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | * @see android.os.Vibrator#vibrate(long[],int) |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 458 | * @deprecated use {@link NotificationChannel#getVibrationPattern()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 460 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | public long[] vibrate; |
| 462 | |
| 463 | /** |
| 464 | * The color of the led. The hardware will do its best approximation. |
| 465 | * |
| 466 | * @see #FLAG_SHOW_LIGHTS |
| 467 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 468 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 470 | @ColorInt |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 471 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | public int ledARGB; |
| 473 | |
| 474 | /** |
| 475 | * The number of milliseconds for the LED to be on while it's flashing. |
| 476 | * The hardware will do its best approximation. |
| 477 | * |
| 478 | * @see #FLAG_SHOW_LIGHTS |
| 479 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 480 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 482 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | public int ledOnMS; |
| 484 | |
| 485 | /** |
| 486 | * The number of milliseconds for the LED to be off while it's flashing. |
| 487 | * The hardware will do its best approximation. |
| 488 | * |
| 489 | * @see #FLAG_SHOW_LIGHTS |
| 490 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 491 | * |
| 492 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 494 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | public int ledOffMS; |
| 496 | |
| 497 | /** |
| 498 | * Specifies which values should be taken from the defaults. |
| 499 | * <p> |
| 500 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 501 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 502 | * values, use {@link #DEFAULT_ALL}. |
| 503 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 504 | * |
| 505 | * @deprecated use {@link NotificationChannel#getSound()} and |
| 506 | * {@link NotificationChannel#shouldShowLights()} and |
| 507 | * {@link NotificationChannel#shouldVibrate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 509 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | public int defaults; |
| 511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | /** |
| 513 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 514 | * set if you want the LED on for this notification. |
| 515 | * <ul> |
| 516 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 517 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 518 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 519 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 520 | * be on and off to ledOnMS and ledOffMS.</li> |
| 521 | * </ul> |
| 522 | * <p> |
| 523 | * 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] | 524 | * 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] | 525 | * because they will be set to values that work on any given hardware. |
| 526 | * <p> |
| 527 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 528 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 529 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 531 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 533 | |
| 534 | /** |
| 535 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 536 | * set if this notification is in reference to something that is ongoing, |
| 537 | * like a phone call. It should not be set if this notification is in |
| 538 | * reference to something that happened at a particular point in time, |
| 539 | * like a missed phone call. |
| 540 | */ |
| 541 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 542 | |
| 543 | /** |
| 544 | * 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] | 545 | * the audio will be repeated until the notification is |
| 546 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | */ |
| 548 | public static final int FLAG_INSISTENT = 0x00000004; |
| 549 | |
| 550 | /** |
| 551 | * 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] | 552 | * set if you would only like the sound, vibrate and ticker to be played |
| 553 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | */ |
| 555 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 556 | |
| 557 | /** |
| 558 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 559 | * 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] | 560 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | */ |
| 562 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 563 | |
| 564 | /** |
| 565 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 566 | * set if the notification should not be canceled when the user clicks |
| 567 | * the Clear all button. |
| 568 | */ |
| 569 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 570 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 571 | /** |
| 572 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 573 | * set if this notification represents a currently running service. This |
| 574 | * will normally be set for you by {@link Service#startForeground}. |
| 575 | */ |
| 576 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 577 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 578 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 579 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 580 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 581 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 582 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 583 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 584 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 585 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 586 | /** |
| 587 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 588 | * set if this notification is relevant to the current device only |
| 589 | * and it is not recommended that it bridge to other devices. |
| 590 | */ |
| 591 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 592 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 593 | /** |
| 594 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 595 | * set if this notification is the group summary for a group of notifications. |
| 596 | * Grouped notifications may display in a cluster or stack on devices which |
| 597 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 598 | */ |
| 599 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 600 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 601 | /** |
| 602 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 603 | * set if this notification is the group summary for an auto-group of notifications. |
| 604 | * |
| 605 | * @hide |
| 606 | */ |
| 607 | @SystemApi |
| 608 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 609 | |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 610 | /** |
| 611 | * @hide |
| 612 | */ |
| 613 | public static final int FLAG_CAN_COLORIZE = 0x00000800; |
| 614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | public int flags; |
| 616 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 617 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 618 | @IntDef(prefix = { "PRIORITY_" }, value = { |
| 619 | PRIORITY_DEFAULT, |
| 620 | PRIORITY_LOW, |
| 621 | PRIORITY_MIN, |
| 622 | PRIORITY_HIGH, |
| 623 | PRIORITY_MAX |
| 624 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 625 | @Retention(RetentionPolicy.SOURCE) |
| 626 | public @interface Priority {} |
| 627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 629 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 630 | * notifications, use this value for all notifications. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 631 | * |
| 632 | * @deprecated use {@link NotificationManager#IMPORTANCE_DEFAULT} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 633 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 634 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 635 | public static final int PRIORITY_DEFAULT = 0; |
| 636 | |
| 637 | /** |
| 638 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 639 | * items smaller, or at a different position in the list, compared with your app's |
| 640 | * {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 641 | * |
| 642 | * @deprecated use {@link NotificationManager#IMPORTANCE_LOW} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 643 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 644 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 645 | public static final int PRIORITY_LOW = -1; |
| 646 | |
| 647 | /** |
| 648 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 649 | * circumstances, such as detailed notification logs. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 650 | * |
| 651 | * @deprecated use {@link NotificationManager#IMPORTANCE_MIN} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 652 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 653 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 654 | public static final int PRIORITY_MIN = -2; |
| 655 | |
| 656 | /** |
| 657 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 658 | * show these items larger, or at a different position in notification lists, compared with |
| 659 | * your app's {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 660 | * |
| 661 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 662 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 663 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 664 | public static final int PRIORITY_HIGH = 1; |
| 665 | |
| 666 | /** |
| 667 | * Highest {@link #priority}, for your application's most important items that require the |
| 668 | * user's prompt attention or input. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 669 | * |
| 670 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 671 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 672 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 673 | public static final int PRIORITY_MAX = 2; |
| 674 | |
| 675 | /** |
| 676 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 677 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 678 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 679 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 680 | * 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] | 681 | * system will make a determination about how to interpret this priority when presenting |
| 682 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 683 | * |
| 684 | * <p> |
| 685 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 686 | * as a heads-up notification. |
| 687 | * </p> |
| 688 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 689 | * @deprecated use {@link NotificationChannel#getImportance()} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 690 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 691 | @Priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 692 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 693 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 694 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 695 | /** |
| 696 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 697 | * to be applied by the standard Style templates when presenting this notification. |
| 698 | * |
| 699 | * The current template design constructs a colorful header image by overlaying the |
| 700 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 701 | * ignored. |
| 702 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 703 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 704 | public int color = COLOR_DEFAULT; |
| 705 | |
| 706 | /** |
| 707 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 708 | * any special color but instead use default colors when presenting this notification. |
| 709 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 710 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 711 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 712 | |
| 713 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 714 | * 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] | 715 | * @hide |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 716 | */ |
| 717 | @ColorInt |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 718 | public static final int COLOR_INVALID = 1; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 719 | |
| 720 | /** |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 721 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 722 | * 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] | 723 | * lockscreen). |
| 724 | * |
| 725 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 726 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 727 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 728 | * the appropriate user. |
| 729 | * |
| 730 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 731 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 732 | * To modify the public version of this notification—for example, to redact some portions—see |
| 733 | * {@link Builder#setPublicVersion(Notification)}. |
| 734 | * |
| 735 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 736 | * and ticker until the user has bypassed the lockscreen. |
| 737 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 738 | public @Visibility int visibility; |
| 739 | |
| 740 | /** @hide */ |
| 741 | @IntDef(prefix = { "VISIBILITY_" }, value = { |
| 742 | VISIBILITY_PUBLIC, |
| 743 | VISIBILITY_PRIVATE, |
| 744 | VISIBILITY_SECRET, |
| 745 | }) |
| 746 | @Retention(RetentionPolicy.SOURCE) |
| 747 | public @interface Visibility {} |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 748 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 749 | /** |
| 750 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 751 | * |
| 752 | * {@see #visibility} |
| 753 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 754 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 755 | |
| 756 | /** |
| 757 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 758 | * private information on secure lockscreens. |
| 759 | * |
| 760 | * {@see #visibility} |
| 761 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 762 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 763 | |
| 764 | /** |
| 765 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 766 | * |
| 767 | * {@see #visibility} |
| 768 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 769 | public static final int VISIBILITY_SECRET = -1; |
| 770 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 771 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 772 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 773 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 774 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 775 | |
| 776 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 777 | * Notification category: map turn-by-turn navigation. |
| 778 | */ |
| 779 | public static final String CATEGORY_NAVIGATION = "navigation"; |
| 780 | |
| 781 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 782 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 783 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 784 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 785 | |
| 786 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 787 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 788 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 789 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 790 | |
| 791 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 792 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 793 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 794 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 795 | |
| 796 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 797 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 798 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 799 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 800 | |
| 801 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 802 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 803 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 804 | public static final String CATEGORY_ALARM = "alarm"; |
| 805 | |
| 806 | /** |
| 807 | * Notification category: progress of a long-running background operation. |
| 808 | */ |
| 809 | public static final String CATEGORY_PROGRESS = "progress"; |
| 810 | |
| 811 | /** |
| 812 | * Notification category: social network or sharing update. |
| 813 | */ |
| 814 | public static final String CATEGORY_SOCIAL = "social"; |
| 815 | |
| 816 | /** |
| 817 | * Notification category: error in background operation or authentication status. |
| 818 | */ |
| 819 | public static final String CATEGORY_ERROR = "err"; |
| 820 | |
| 821 | /** |
| 822 | * Notification category: media transport control for playback. |
| 823 | */ |
| 824 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 825 | |
| 826 | /** |
| 827 | * Notification category: system or device status update. Reserved for system use. |
| 828 | */ |
| 829 | public static final String CATEGORY_SYSTEM = "sys"; |
| 830 | |
| 831 | /** |
| 832 | * Notification category: indication of running background service. |
| 833 | */ |
| 834 | public static final String CATEGORY_SERVICE = "service"; |
| 835 | |
| 836 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 837 | * Notification category: a specific, timely recommendation for a single thing. |
| 838 | * For example, a news app might want to recommend a news story it believes the user will |
| 839 | * want to read next. |
| 840 | */ |
| 841 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 842 | |
| 843 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 844 | * Notification category: ongoing information about device or contextual status. |
| 845 | */ |
| 846 | public static final String CATEGORY_STATUS = "status"; |
| 847 | |
| 848 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 849 | * Notification category: user-scheduled reminder. |
| 850 | */ |
| 851 | public static final String CATEGORY_REMINDER = "reminder"; |
| 852 | |
| 853 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 854 | * Notification category: extreme car emergencies. |
| 855 | * @hide |
| 856 | */ |
| 857 | @SystemApi |
| 858 | public static final String CATEGORY_CAR_EMERGENCY = "car_emergency"; |
| 859 | |
| 860 | /** |
| 861 | * Notification category: car warnings. |
| 862 | * @hide |
| 863 | */ |
| 864 | @SystemApi |
| 865 | public static final String CATEGORY_CAR_WARNING = "car_warning"; |
| 866 | |
| 867 | /** |
| 868 | * Notification category: general car system information. |
| 869 | * @hide |
| 870 | */ |
| 871 | @SystemApi |
| 872 | public static final String CATEGORY_CAR_INFORMATION = "car_information"; |
| 873 | |
| 874 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 875 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 876 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 877 | */ |
| 878 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 879 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 880 | @UnsupportedAppUsage |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 881 | private String mGroupKey; |
| 882 | |
| 883 | /** |
| 884 | * Get the key used to group this notification into a cluster or stack |
| 885 | * with other notifications on devices which support such rendering. |
| 886 | */ |
| 887 | public String getGroup() { |
| 888 | return mGroupKey; |
| 889 | } |
| 890 | |
| 891 | private String mSortKey; |
| 892 | |
| 893 | /** |
| 894 | * Get a sort key that orders this notification among other notifications from the |
| 895 | * same package. This can be useful if an external sort was already applied and an app |
| 896 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 897 | * value, although providing different priorities in addition to providing sort key may |
| 898 | * cause this value to be ignored. |
| 899 | * |
| 900 | * <p>This sort key can also be used to order members of a notification group. See |
| 901 | * {@link Builder#setGroup}. |
| 902 | * |
| 903 | * @see String#compareTo(String) |
| 904 | */ |
| 905 | public String getSortKey() { |
| 906 | return mSortKey; |
| 907 | } |
| 908 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 909 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 910 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 911 | * <p> |
| 912 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 913 | * APIs, and are intended to be used by |
| 914 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 915 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 916 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 917 | public Bundle extras = new Bundle(); |
| 918 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 919 | /** |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 920 | * All pending intents in the notification as the system needs to be able to access them but |
| 921 | * 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] | 922 | * custom parcelable objects. |
| 923 | * |
| 924 | * @hide |
| 925 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 926 | @UnsupportedAppUsage |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 927 | public ArraySet<PendingIntent> allPendingIntents; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 928 | |
| 929 | /** |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 930 | * Token identifying the notification that is applying doze/bgcheck whitelisting to the |
| 931 | * pending intents inside of it, so only those will get the behavior. |
| 932 | * |
| 933 | * @hide |
| 934 | */ |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 935 | private IBinder mWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 936 | |
| 937 | /** |
| 938 | * Must be set by a process to start associating tokens with Notification objects |
| 939 | * coming in to it. This is set by NotificationManagerService. |
| 940 | * |
| 941 | * @hide |
| 942 | */ |
| 943 | static public IBinder processWhitelistToken; |
| 944 | |
| 945 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 946 | * {@link #extras} key: this is the title of the notification, |
| 947 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 948 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 949 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 950 | |
| 951 | /** |
| 952 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 953 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 954 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 955 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 956 | |
| 957 | /** |
| 958 | * {@link #extras} key: this is the main text payload, as supplied to |
| 959 | * {@link Builder#setContentText(CharSequence)}. |
| 960 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 961 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 962 | |
| 963 | /** |
| 964 | * {@link #extras} key: this is a third line of text, as supplied to |
| 965 | * {@link Builder#setSubText(CharSequence)}. |
| 966 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 967 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 968 | |
| 969 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 970 | * {@link #extras} key: this is the remote input history, as supplied to |
| 971 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
Adrian Roos | 005e774 | 2016-04-13 15:02:20 -0700 | [diff] [blame] | 972 | * |
| 973 | * Apps can fill this through {@link Builder#setRemoteInputHistory(CharSequence[])} |
| 974 | * with the most recent inputs that have been sent through a {@link RemoteInput} of this |
| 975 | * Notification and are expected to clear it once the it is no longer relevant (e.g. for chat |
| 976 | * notifications once the other party has responded). |
| 977 | * |
| 978 | * The extra with this key is of type CharSequence[] and contains the most recent entry at |
| 979 | * the 0 index, the second most recent at the 1 index, etc. |
| 980 | * |
| 981 | * @see Builder#setRemoteInputHistory(CharSequence[]) |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 982 | */ |
| 983 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 984 | |
| 985 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 986 | * {@link #extras} key: boolean as supplied to |
| 987 | * {@link Builder#setShowRemoteInputSpinner(boolean)}. |
| 988 | * |
| 989 | * If set to true, then the view displaying the remote input history from |
| 990 | * {@link Builder#setRemoteInputHistory(CharSequence[])} will have a progress spinner. |
| 991 | * |
| 992 | * @see Builder#setShowRemoteInputSpinner(boolean) |
| 993 | * @hide |
| 994 | */ |
| 995 | public static final String EXTRA_SHOW_REMOTE_INPUT_SPINNER = "android.remoteInputSpinner"; |
| 996 | |
| 997 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 998 | * {@link #extras} key: boolean as supplied to |
| 999 | * {@link Builder#setHideSmartReplies(boolean)}. |
| 1000 | * |
| 1001 | * If set to true, then any smart reply buttons will be hidden. |
| 1002 | * |
| 1003 | * @see Builder#setHideSmartReplies(boolean) |
| 1004 | * @hide |
| 1005 | */ |
| 1006 | public static final String EXTRA_HIDE_SMART_REPLIES = "android.hideSmartReplies"; |
| 1007 | |
| 1008 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1009 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 1010 | * {@link Builder#setContentInfo(CharSequence)}. |
| 1011 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1012 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1013 | |
| 1014 | /** |
| 1015 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 1016 | * alongside expanded notifications, as supplied to (e.g.) |
| 1017 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 1018 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1019 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1020 | |
| 1021 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1022 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 1023 | * {@link BigTextStyle} notification, as supplied to |
| 1024 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 1025 | */ |
| 1026 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 1027 | |
| 1028 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1029 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 1030 | * supplied to {@link Builder#setSmallIcon(int)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1031 | * |
| 1032 | * @deprecated Use {@link #getSmallIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1033 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1034 | @Deprecated |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1035 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1036 | |
| 1037 | /** |
| 1038 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 1039 | * notification payload, as |
| 1040 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1041 | * |
| 1042 | * @deprecated Use {@link #getLargeIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1043 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1044 | @Deprecated |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1045 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1046 | |
| 1047 | /** |
| 1048 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 1049 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 1050 | * shown in its expanded form, as supplied to |
| 1051 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 1052 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1053 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1054 | |
| 1055 | /** |
| 1056 | * {@link #extras} key: this is the progress value supplied to |
| 1057 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1058 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1059 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1060 | |
| 1061 | /** |
| 1062 | * {@link #extras} key: this is the maximum value supplied to |
| 1063 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1064 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1065 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1066 | |
| 1067 | /** |
| 1068 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 1069 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1070 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1071 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1072 | |
| 1073 | /** |
| 1074 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 1075 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 1076 | * {@link Builder#setUsesChronometer(boolean)}. |
| 1077 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1078 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1079 | |
| 1080 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1081 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 1082 | * 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] | 1083 | * This extra is a boolean. The default is false. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1084 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1085 | public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1086 | |
| 1087 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1088 | * {@link #extras} key: whether {@link #when} should be shown, |
| 1089 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 1090 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1091 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1092 | |
| 1093 | /** |
| 1094 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 1095 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 1096 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1097 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1098 | |
| 1099 | /** |
| 1100 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 1101 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 1102 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1103 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1104 | |
| 1105 | /** |
| 1106 | * {@link #extras} key: A string representing the name of the specific |
| 1107 | * {@link android.app.Notification.Style} used to create this notification. |
| 1108 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 1109 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1110 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1111 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 1112 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 1113 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1114 | * |
| 1115 | * @deprecated the actual objects are now in {@link #EXTRA_PEOPLE_LIST} |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1116 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1117 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1118 | |
| 1119 | /** |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1120 | * {@link #extras} key: An arrayList of {@link Person} objects containing the people that |
| 1121 | * this notification relates to. |
| 1122 | */ |
| 1123 | public static final String EXTRA_PEOPLE_LIST = "android.people.list"; |
| 1124 | |
| 1125 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1126 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 1127 | * Only available to notifications coming from the android package. |
| 1128 | * @hide |
| 1129 | */ |
Maurice Lam | 96c1003 | 2017-03-29 15:42:38 -0700 | [diff] [blame] | 1130 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1131 | @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1132 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 1133 | |
| 1134 | /** |
Robin Lee | d107af6 | 2018-04-27 13:55:56 +0200 | [diff] [blame] | 1135 | * {@link #extras} key: |
| 1136 | * flat {@link String} representation of a {@link android.content.ContentUris content URI} |
| 1137 | * pointing to an image that can be displayed in the background when the notification is |
| 1138 | * selected. Used on television platforms. The URI must point to an image stream suitable for |
| 1139 | * passing into {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1140 | * BitmapFactory.decodeStream}; all other content types will be ignored. |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1141 | */ |
| 1142 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1143 | |
| 1144 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1145 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 1146 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1147 | * {@link android.app.Notification.MediaStyle} notification. |
| 1148 | */ |
| 1149 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1150 | |
| 1151 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 1152 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 1153 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 1154 | */ |
| 1155 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1156 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 1157 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1158 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 1159 | * direct replies |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1160 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1161 | * {@link CharSequence} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1162 | * |
| 1163 | * @deprecated use {@link #EXTRA_MESSAGING_PERSON} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1164 | */ |
| 1165 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1166 | |
| 1167 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1168 | * {@link #extras} key: the person to be displayed for all messages sent by the user including |
| 1169 | * direct replies |
| 1170 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1171 | * {@link Person} |
| 1172 | */ |
| 1173 | public static final String EXTRA_MESSAGING_PERSON = "android.messagingUser"; |
| 1174 | |
| 1175 | /** |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1176 | * {@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] | 1177 | * represented by a {@link android.app.Notification.MessagingStyle} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1178 | */ |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1179 | public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1180 | |
| 1181 | /** |
| 1182 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 1183 | * bundles provided by a |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1184 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1185 | * array of bundles. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1186 | */ |
| 1187 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 1188 | |
| 1189 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 1190 | * {@link #extras} key: an array of |
| 1191 | * {@link android.app.Notification.MessagingStyle#addHistoricMessage historic} |
| 1192 | * {@link android.app.Notification.MessagingStyle.Message} bundles provided by a |
| 1193 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1194 | * array of bundles. |
| 1195 | */ |
| 1196 | public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1197 | |
| 1198 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 1199 | * {@link #extras} key: whether the {@link android.app.Notification.MessagingStyle} notification |
| 1200 | * represents a group conversation. |
| 1201 | */ |
| 1202 | public static final String EXTRA_IS_GROUP_CONVERSATION = "android.isGroupConversation"; |
| 1203 | |
| 1204 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1205 | * {@link #extras} key: whether the notification should be colorized as |
| 1206 | * supplied to {@link Builder#setColorized(boolean)}}. |
| 1207 | */ |
| 1208 | public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1209 | |
| 1210 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1211 | * @hide |
| 1212 | */ |
| 1213 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1214 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 1215 | /** |
| 1216 | * @hide |
| 1217 | */ |
| 1218 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1219 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1220 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 1221 | * @hide |
| 1222 | */ |
| 1223 | public static final String EXTRA_REDUCED_IMAGES = "android.reduced.images"; |
| 1224 | |
| 1225 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1226 | * {@link #extras} key: the audio contents of this notification. |
| 1227 | * |
| 1228 | * This is for use when rendering the notification on an audio-focused interface; |
| 1229 | * the audio contents are a complete sound sample that contains the contents/body of the |
| 1230 | * notification. This may be used in substitute of a Text-to-Speech reading of the |
| 1231 | * notification. For example if the notification represents a voice message this should point |
| 1232 | * to the audio of that message. |
| 1233 | * |
| 1234 | * The data stored under this key should be a String representation of a Uri that contains the |
| 1235 | * audio contents in one of the following formats: WAV, PCM 16-bit, AMR-WB. |
| 1236 | * |
| 1237 | * This extra is unnecessary if you are using {@code MessagingStyle} since each {@code Message} |
| 1238 | * has a field for holding data URI. That field can be used for audio. |
| 1239 | * See {@code Message#setData}. |
| 1240 | * |
| 1241 | * Example usage: |
| 1242 | * <pre> |
| 1243 | * {@code |
| 1244 | * Notification.Builder myBuilder = (build your Notification as normal); |
| 1245 | * myBuilder.getExtras().putString(EXTRA_AUDIO_CONTENTS_URI, myAudioUri.toString()); |
| 1246 | * } |
| 1247 | * </pre> |
| 1248 | */ |
| 1249 | public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1250 | |
Dan Sandler | 80eaa59 | 2016-04-14 23:34:54 -0400 | [diff] [blame] | 1251 | /** @hide */ |
| 1252 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1253 | @RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME) |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1254 | public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1255 | |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1256 | /** |
Julia Reynolds | 3c7de11 | 2018-03-28 09:33:13 -0400 | [diff] [blame] | 1257 | * This is set on the notifications shown by system_server about apps running foreground |
| 1258 | * services. It indicates that the notification should be shown |
| 1259 | * only if any of the given apps do not already have a properly tagged |
| 1260 | * {@link #FLAG_FOREGROUND_SERVICE} notification currently visible to the user. |
| 1261 | * This is a string array of all package names of the apps. |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1262 | * @hide |
| 1263 | */ |
| 1264 | public static final String EXTRA_FOREGROUND_APPS = "android.foregroundApps"; |
| 1265 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1266 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1267 | private Icon mSmallIcon; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1268 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1269 | private Icon mLargeIcon; |
| 1270 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1271 | @UnsupportedAppUsage |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1272 | private String mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1273 | private long mTimeout; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1274 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1275 | private String mShortcutId; |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 1276 | private LocusId mLocusId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1277 | private CharSequence mSettingsText; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1278 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 1279 | private BubbleMetadata mBubbleMetadata; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 1280 | |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1281 | /** @hide */ |
| 1282 | @IntDef(prefix = { "GROUP_ALERT_" }, value = { |
| 1283 | GROUP_ALERT_ALL, GROUP_ALERT_CHILDREN, GROUP_ALERT_SUMMARY |
| 1284 | }) |
| 1285 | @Retention(RetentionPolicy.SOURCE) |
| 1286 | public @interface GroupAlertBehavior {} |
| 1287 | |
| 1288 | /** |
| 1289 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all notifications in a |
| 1290 | * group with sound or vibration ought to make sound or vibrate (respectively), so this |
| 1291 | * notification will not be muted when it is in a group. |
| 1292 | */ |
| 1293 | public static final int GROUP_ALERT_ALL = 0; |
| 1294 | |
| 1295 | /** |
| 1296 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all children |
| 1297 | * notification in a group should be silenced (no sound or vibration) even if they are posted |
| 1298 | * 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] | 1299 | * mute this notification if this notification is a group child. This must be applied to all |
| 1300 | * children notifications you want to mute. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1301 | * |
| 1302 | * <p> For example, you might want to use this constant if you post a number of children |
| 1303 | * notifications at once (say, after a periodic sync), and only need to notify the user |
| 1304 | * audibly once. |
| 1305 | */ |
| 1306 | public static final int GROUP_ALERT_SUMMARY = 1; |
| 1307 | |
| 1308 | /** |
| 1309 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that the summary |
| 1310 | * notification in a group should be silenced (no sound or vibration) even if they are |
| 1311 | * posted to a {@link NotificationChannel} that has sound and/or vibration. Use this constant |
| 1312 | * to mute this notification if this notification is a group summary. |
| 1313 | * |
| 1314 | * <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] | 1315 | * in your group have content and the summary is only used to visually group notifications |
| 1316 | * rather than to alert the user that new information is available. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1317 | */ |
| 1318 | public static final int GROUP_ALERT_CHILDREN = 2; |
| 1319 | |
Julia Reynolds | 2f431e2 | 2017-06-07 14:12:09 +0000 | [diff] [blame] | 1320 | private int mGroupAlertBehavior = GROUP_ALERT_ALL; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1321 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1322 | /** |
| 1323 | * If this notification is being shown as a badge, always show as a number. |
| 1324 | */ |
| 1325 | public static final int BADGE_ICON_NONE = 0; |
| 1326 | |
| 1327 | /** |
| 1328 | * If this notification is being shown as a badge, use the {@link #getSmallIcon()} to |
| 1329 | * represent this notification. |
| 1330 | */ |
| 1331 | public static final int BADGE_ICON_SMALL = 1; |
| 1332 | |
| 1333 | /** |
| 1334 | * If this notification is being shown as a badge, use the {@link #getLargeIcon()} to |
| 1335 | * represent this notification. |
| 1336 | */ |
| 1337 | public static final int BADGE_ICON_LARGE = 2; |
Julia Reynolds | 7d5b4da | 2017-03-20 10:18:49 -0400 | [diff] [blame] | 1338 | private int mBadgeIcon = BADGE_ICON_NONE; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1339 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1340 | /** |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 1341 | * Determines whether the platform can generate contextual actions for a notification. |
| 1342 | */ |
| 1343 | private boolean mAllowSystemGeneratedContextualActions = true; |
| 1344 | |
| 1345 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1346 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 1347 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 1348 | * selected by the user. |
| 1349 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1350 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 1351 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 1352 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1353 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1354 | public static class Action implements Parcelable { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1355 | /** |
| 1356 | * {@link #extras} key: Keys to a {@link Parcelable} {@link ArrayList} of |
| 1357 | * {@link RemoteInput}s. |
| 1358 | * |
| 1359 | * This is intended for {@link RemoteInput}s that only accept data, meaning |
| 1360 | * {@link RemoteInput#getAllowFreeFormInput} is false, {@link RemoteInput#getChoices} |
| 1361 | * is null or empty, and {@link RemoteInput#getAllowedDataTypes is non-null and not |
| 1362 | * empty. These {@link RemoteInput}s will be ignored by devices that do not |
| 1363 | * support non-text-based {@link RemoteInput}s. See {@link Builder#build}. |
| 1364 | * |
| 1365 | * You can test if a RemoteInput matches these constraints using |
| 1366 | * {@link RemoteInput#isDataOnly}. |
| 1367 | */ |
| 1368 | private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1369 | |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1370 | /** |
| 1371 | * {@link }: No semantic action defined. |
| 1372 | */ |
| 1373 | public static final int SEMANTIC_ACTION_NONE = 0; |
| 1374 | |
| 1375 | /** |
| 1376 | * {@code SemanticAction}: Reply to a conversation, chat, group, or wherever replies |
| 1377 | * may be appropriate. |
| 1378 | */ |
| 1379 | public static final int SEMANTIC_ACTION_REPLY = 1; |
| 1380 | |
| 1381 | /** |
| 1382 | * {@code SemanticAction}: Mark content as read. |
| 1383 | */ |
| 1384 | public static final int SEMANTIC_ACTION_MARK_AS_READ = 2; |
| 1385 | |
| 1386 | /** |
| 1387 | * {@code SemanticAction}: Mark content as unread. |
| 1388 | */ |
| 1389 | public static final int SEMANTIC_ACTION_MARK_AS_UNREAD = 3; |
| 1390 | |
| 1391 | /** |
| 1392 | * {@code SemanticAction}: Delete the content associated with the notification. This |
| 1393 | * could mean deleting an email, message, etc. |
| 1394 | */ |
| 1395 | public static final int SEMANTIC_ACTION_DELETE = 4; |
| 1396 | |
| 1397 | /** |
| 1398 | * {@code SemanticAction}: Archive the content associated with the notification. This |
| 1399 | * could mean archiving an email, message, etc. |
| 1400 | */ |
| 1401 | public static final int SEMANTIC_ACTION_ARCHIVE = 5; |
| 1402 | |
| 1403 | /** |
| 1404 | * {@code SemanticAction}: Mute the content associated with the notification. This could |
| 1405 | * mean silencing a conversation or currently playing media. |
| 1406 | */ |
| 1407 | public static final int SEMANTIC_ACTION_MUTE = 6; |
| 1408 | |
| 1409 | /** |
| 1410 | * {@code SemanticAction}: Unmute the content associated with the notification. This could |
| 1411 | * mean un-silencing a conversation or currently playing media. |
| 1412 | */ |
| 1413 | public static final int SEMANTIC_ACTION_UNMUTE = 7; |
| 1414 | |
| 1415 | /** |
| 1416 | * {@code SemanticAction}: Mark content with a thumbs up. |
| 1417 | */ |
| 1418 | public static final int SEMANTIC_ACTION_THUMBS_UP = 8; |
| 1419 | |
| 1420 | /** |
| 1421 | * {@code SemanticAction}: Mark content with a thumbs down. |
| 1422 | */ |
| 1423 | public static final int SEMANTIC_ACTION_THUMBS_DOWN = 9; |
| 1424 | |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 1425 | /** |
| 1426 | * {@code SemanticAction}: Call a contact, group, etc. |
| 1427 | */ |
| 1428 | public static final int SEMANTIC_ACTION_CALL = 10; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1429 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1430 | private final Bundle mExtras; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1431 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1432 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1433 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1434 | private boolean mAllowGeneratedReplies = true; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1435 | private final @SemanticAction int mSemanticAction; |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1436 | private final boolean mIsContextual; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1437 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1438 | /** |
| 1439 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1440 | * |
| 1441 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1442 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1443 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1444 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1445 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1446 | /** |
| 1447 | * Title of the action. |
| 1448 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1449 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1450 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1451 | /** |
| 1452 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1453 | * may be rendered in a disabled presentation by the system UI. |
| 1454 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1455 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1456 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1457 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1458 | if (in.readInt() != 0) { |
| 1459 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1460 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1461 | icon = mIcon.getResId(); |
| 1462 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1463 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1464 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1465 | if (in.readInt() == 1) { |
| 1466 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1467 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1468 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1469 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1470 | mAllowGeneratedReplies = in.readInt() == 1; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1471 | mSemanticAction = in.readInt(); |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1472 | mIsContextual = in.readInt() == 1; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1473 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1474 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1475 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1476 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1477 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1478 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1479 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1480 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1481 | SEMANTIC_ACTION_NONE, false /* isContextual */); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1484 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1485 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1486 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1487 | @SemanticAction int semanticAction, boolean isContextual) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1488 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1489 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1490 | this.icon = icon.getResId(); |
| 1491 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1492 | this.title = title; |
| 1493 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1494 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1495 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1496 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1497 | this.mSemanticAction = semanticAction; |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1498 | this.mIsContextual = isContextual; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1502 | * Return an icon representing the action. |
| 1503 | */ |
| 1504 | public Icon getIcon() { |
| 1505 | if (mIcon == null && icon != 0) { |
| 1506 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1507 | mIcon = Icon.createWithResource("", icon); |
| 1508 | } |
| 1509 | return mIcon; |
| 1510 | } |
| 1511 | |
| 1512 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1513 | * Get additional metadata carried around with this Action. |
| 1514 | */ |
| 1515 | public Bundle getExtras() { |
| 1516 | return mExtras; |
| 1517 | } |
| 1518 | |
| 1519 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1520 | * Return whether the platform should automatically generate possible replies for this |
| 1521 | * {@link Action} |
| 1522 | */ |
| 1523 | public boolean getAllowGeneratedReplies() { |
| 1524 | return mAllowGeneratedReplies; |
| 1525 | } |
| 1526 | |
| 1527 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1528 | * 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] | 1529 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1530 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1531 | */ |
| 1532 | public RemoteInput[] getRemoteInputs() { |
| 1533 | return mRemoteInputs; |
| 1534 | } |
| 1535 | |
| 1536 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1537 | * Returns the {@code SemanticAction} associated with this {@link Action}. A |
| 1538 | * {@code SemanticAction} denotes what an {@link Action}'s {@link PendingIntent} will do |
| 1539 | * (eg. reply, mark as read, delete, etc). |
| 1540 | */ |
| 1541 | public @SemanticAction int getSemanticAction() { |
| 1542 | return mSemanticAction; |
| 1543 | } |
| 1544 | |
| 1545 | /** |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1546 | * Returns whether this is a contextual Action, i.e. whether the action is dependent on the |
| 1547 | * notification message body. An example of a contextual action could be an action opening a |
| 1548 | * map application with an address shown in the notification. |
| 1549 | */ |
| 1550 | public boolean isContextual() { |
| 1551 | return mIsContextual; |
| 1552 | } |
| 1553 | |
| 1554 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1555 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1556 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1557 | * {@link RemoteInput#isDataOnly}. |
| 1558 | * |
Shane Brennan | f670d6c | 2017-04-25 13:05:45 -0700 | [diff] [blame] | 1559 | * Returns null if there are no data-only remote inputs. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1560 | * |
| 1561 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1562 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1563 | */ |
| 1564 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1565 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1566 | } |
| 1567 | |
| 1568 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1569 | * Builder class for {@link Action} objects. |
| 1570 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1571 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1572 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1573 | private final CharSequence mTitle; |
| 1574 | private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1575 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1576 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1577 | private ArrayList<RemoteInput> mRemoteInputs; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1578 | private @SemanticAction int mSemanticAction; |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1579 | private boolean mIsContextual; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1580 | |
| 1581 | /** |
| 1582 | * Construct a new builder for {@link Action} object. |
| 1583 | * @param icon icon to show for this action |
| 1584 | * @param title the title of the action |
| 1585 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1586 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1587 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1588 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1589 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | /** |
| 1593 | * Construct a new builder for {@link Action} object. |
| 1594 | * @param icon icon to show for this action |
| 1595 | * @param title the title of the action |
| 1596 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1597 | */ |
| 1598 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1599 | this(icon, title, intent, new Bundle(), null, true, SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | /** |
| 1603 | * Construct a new builder for {@link Action} object using the fields from an |
| 1604 | * {@link Action}. |
| 1605 | * @param action the action to read fields from. |
| 1606 | */ |
| 1607 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1608 | this(action.getIcon(), action.title, action.actionIntent, |
| 1609 | new Bundle(action.mExtras), action.getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1610 | action.getAllowGeneratedReplies(), action.getSemanticAction()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1613 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1614 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1615 | @SemanticAction int semanticAction) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1616 | mIcon = icon; |
| 1617 | mTitle = title; |
| 1618 | mIntent = intent; |
| 1619 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1620 | if (remoteInputs != null) { |
| 1621 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1622 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1623 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1624 | mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1625 | mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | /** |
| 1629 | * Merge additional metadata into this builder. |
| 1630 | * |
| 1631 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1632 | * |
| 1633 | * @see Notification.Action#extras |
| 1634 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1635 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1636 | public Builder addExtras(Bundle extras) { |
| 1637 | if (extras != null) { |
| 1638 | mExtras.putAll(extras); |
| 1639 | } |
| 1640 | return this; |
| 1641 | } |
| 1642 | |
| 1643 | /** |
| 1644 | * Get the metadata Bundle used by this Builder. |
| 1645 | * |
| 1646 | * <p>The returned Bundle is shared with this Builder. |
| 1647 | */ |
| 1648 | public Bundle getExtras() { |
| 1649 | return mExtras; |
| 1650 | } |
| 1651 | |
| 1652 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1653 | * Add an input to be collected from the user when this action is sent. |
| 1654 | * Response values can be retrieved from the fired intent by using the |
| 1655 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1656 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1657 | * @return this object for method chaining |
| 1658 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1659 | @NonNull |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1660 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1661 | if (mRemoteInputs == null) { |
| 1662 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1663 | } |
| 1664 | mRemoteInputs.add(remoteInput); |
| 1665 | return this; |
| 1666 | } |
| 1667 | |
| 1668 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1669 | * Set whether the platform should automatically generate possible replies to add to |
| 1670 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1671 | * {@link RemoteInput}, this has no effect. |
| 1672 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1673 | * otherwise |
| 1674 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1675 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1676 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1677 | @NonNull |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1678 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1679 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1680 | return this; |
| 1681 | } |
| 1682 | |
| 1683 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1684 | * Sets the {@code SemanticAction} for this {@link Action}. A |
| 1685 | * {@code SemanticAction} denotes what an {@link Action}'s |
| 1686 | * {@link PendingIntent} will do (eg. reply, mark as read, delete, etc). |
| 1687 | * @param semanticAction a SemanticAction defined within {@link Action} with |
| 1688 | * {@code SEMANTIC_ACTION_} prefixes |
| 1689 | * @return this object for method chaining |
| 1690 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1691 | @NonNull |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1692 | public Builder setSemanticAction(@SemanticAction int semanticAction) { |
| 1693 | mSemanticAction = semanticAction; |
| 1694 | return this; |
| 1695 | } |
| 1696 | |
| 1697 | /** |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1698 | * Sets whether this {@link Action} is a contextual action, i.e. whether the action is |
| 1699 | * dependent on the notification message body. An example of a contextual action could |
| 1700 | * be an action opening a map application with an address shown in the notification. |
| 1701 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1702 | @NonNull |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1703 | public Builder setContextual(boolean isContextual) { |
| 1704 | mIsContextual = isContextual; |
| 1705 | return this; |
| 1706 | } |
| 1707 | |
| 1708 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1709 | * Apply an extender to this action builder. Extenders may be used to add |
| 1710 | * metadata or change options on this builder. |
| 1711 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1712 | @NonNull |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1713 | public Builder extend(Extender extender) { |
| 1714 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1715 | return this; |
| 1716 | } |
| 1717 | |
| 1718 | /** |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1719 | * Throws an NPE if we are building a contextual action missing one of the fields |
| 1720 | * necessary to display the action. |
| 1721 | */ |
| 1722 | private void checkContextualActionNullFields() { |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1723 | if (!mIsContextual) return; |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1724 | |
| 1725 | if (mIcon == null) { |
| 1726 | throw new NullPointerException("Contextual Actions must contain a valid icon"); |
| 1727 | } |
| 1728 | |
| 1729 | if (mIntent == null) { |
| 1730 | throw new NullPointerException( |
| 1731 | "Contextual Actions must contain a valid PendingIntent"); |
| 1732 | } |
| 1733 | } |
| 1734 | |
| 1735 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1736 | * Combine all of the options that have been set and return a new {@link Action} |
| 1737 | * object. |
| 1738 | * @return the built action |
| 1739 | */ |
Gustav Sennton | 44a2313 | 2019-02-28 18:02:52 +0000 | [diff] [blame] | 1740 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1741 | public Action build() { |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1742 | checkContextualActionNullFields(); |
| 1743 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1744 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1745 | RemoteInput[] previousDataInputs = |
| 1746 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1747 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1748 | for (RemoteInput input : previousDataInputs) { |
| 1749 | dataOnlyInputs.add(input); |
| 1750 | } |
| 1751 | } |
| 1752 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1753 | if (mRemoteInputs != null) { |
| 1754 | for (RemoteInput input : mRemoteInputs) { |
| 1755 | if (input.isDataOnly()) { |
| 1756 | dataOnlyInputs.add(input); |
| 1757 | } else { |
| 1758 | textInputs.add(input); |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | if (!dataOnlyInputs.isEmpty()) { |
| 1763 | RemoteInput[] dataInputsArr = |
| 1764 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1765 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1766 | } |
| 1767 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1768 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1769 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1770 | mAllowGeneratedReplies, mSemanticAction, mIsContextual); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1771 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1772 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1773 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1774 | @Override |
| 1775 | public Action clone() { |
| 1776 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1777 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1778 | title, |
| 1779 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1780 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1781 | getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1782 | getAllowGeneratedReplies(), |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1783 | getSemanticAction(), |
| 1784 | isContextual()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1785 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1786 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1787 | @Override |
| 1788 | public int describeContents() { |
| 1789 | return 0; |
| 1790 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1791 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1792 | @Override |
| 1793 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1794 | final Icon ic = getIcon(); |
| 1795 | if (ic != null) { |
| 1796 | out.writeInt(1); |
| 1797 | ic.writeToParcel(out, 0); |
| 1798 | } else { |
| 1799 | out.writeInt(0); |
| 1800 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1801 | TextUtils.writeToParcel(title, out, flags); |
| 1802 | if (actionIntent != null) { |
| 1803 | out.writeInt(1); |
| 1804 | actionIntent.writeToParcel(out, flags); |
| 1805 | } else { |
| 1806 | out.writeInt(0); |
| 1807 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1808 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1809 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1810 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1811 | out.writeInt(mSemanticAction); |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 1812 | out.writeInt(mIsContextual ? 1 : 0); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1813 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1814 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1815 | public static final @android.annotation.NonNull Parcelable.Creator<Action> CREATOR = |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1816 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1817 | public Action createFromParcel(Parcel in) { |
| 1818 | return new Action(in); |
| 1819 | } |
| 1820 | public Action[] newArray(int size) { |
| 1821 | return new Action[size]; |
| 1822 | } |
| 1823 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1824 | |
| 1825 | /** |
| 1826 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1827 | * metadata or change options on an action builder. |
| 1828 | */ |
| 1829 | public interface Extender { |
| 1830 | /** |
| 1831 | * Apply this extender to a notification action builder. |
| 1832 | * @param builder the builder to be modified. |
| 1833 | * @return the build object for chaining. |
| 1834 | */ |
| 1835 | public Builder extend(Builder builder); |
| 1836 | } |
| 1837 | |
| 1838 | /** |
| 1839 | * Wearable extender for notification actions. To add extensions to an action, |
| 1840 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1841 | * the {@code WearableExtender()} constructor and apply it to a |
| 1842 | * {@link android.app.Notification.Action.Builder} using |
| 1843 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1844 | * |
| 1845 | * <pre class="prettyprint"> |
| 1846 | * Notification.Action action = new Notification.Action.Builder( |
| 1847 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1848 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1849 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1850 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1851 | */ |
| 1852 | public static final class WearableExtender implements Extender { |
| 1853 | /** Notification action extra which contains wearable extensions */ |
| 1854 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1855 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1856 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1857 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1858 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1859 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1860 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1861 | |
| 1862 | // Flags bitwise-ored to mFlags |
| 1863 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1864 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1865 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1866 | |
| 1867 | // Default value for flags integer |
| 1868 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1869 | |
| 1870 | private int mFlags = DEFAULT_FLAGS; |
| 1871 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1872 | private CharSequence mInProgressLabel; |
| 1873 | private CharSequence mConfirmLabel; |
| 1874 | private CharSequence mCancelLabel; |
| 1875 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1876 | /** |
| 1877 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1878 | * options. |
| 1879 | */ |
| 1880 | public WearableExtender() { |
| 1881 | } |
| 1882 | |
| 1883 | /** |
| 1884 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1885 | * wearable options present in an existing notification action. |
| 1886 | * @param action the notification action to inspect. |
| 1887 | */ |
| 1888 | public WearableExtender(Action action) { |
| 1889 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1890 | if (wearableBundle != null) { |
| 1891 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1892 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1893 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1894 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | /** |
| 1899 | * Apply wearable extensions to a notification action that is being built. This is |
| 1900 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1901 | * method of {@link android.app.Notification.Action.Builder}. |
| 1902 | */ |
| 1903 | @Override |
| 1904 | public Action.Builder extend(Action.Builder builder) { |
| 1905 | Bundle wearableBundle = new Bundle(); |
| 1906 | |
| 1907 | if (mFlags != DEFAULT_FLAGS) { |
| 1908 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1909 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1910 | if (mInProgressLabel != null) { |
| 1911 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1912 | } |
| 1913 | if (mConfirmLabel != null) { |
| 1914 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1915 | } |
| 1916 | if (mCancelLabel != null) { |
| 1917 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1918 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1919 | |
| 1920 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1921 | return builder; |
| 1922 | } |
| 1923 | |
| 1924 | @Override |
| 1925 | public WearableExtender clone() { |
| 1926 | WearableExtender that = new WearableExtender(); |
| 1927 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1928 | that.mInProgressLabel = this.mInProgressLabel; |
| 1929 | that.mConfirmLabel = this.mConfirmLabel; |
| 1930 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1931 | return that; |
| 1932 | } |
| 1933 | |
| 1934 | /** |
| 1935 | * Set whether this action is available when the wearable device is not connected to |
| 1936 | * a companion device. The user can still trigger this action when the wearable device is |
| 1937 | * offline, but a visual hint will indicate that the action may not be available. |
| 1938 | * Defaults to true. |
| 1939 | */ |
| 1940 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1941 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1942 | return this; |
| 1943 | } |
| 1944 | |
| 1945 | /** |
| 1946 | * Get whether this action is available when the wearable device is not connected to |
| 1947 | * a companion device. The user can still trigger this action when the wearable device is |
| 1948 | * offline, but a visual hint will indicate that the action may not be available. |
| 1949 | * Defaults to true. |
| 1950 | */ |
| 1951 | public boolean isAvailableOffline() { |
| 1952 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1953 | } |
| 1954 | |
| 1955 | private void setFlag(int mask, boolean value) { |
| 1956 | if (value) { |
| 1957 | mFlags |= mask; |
| 1958 | } else { |
| 1959 | mFlags &= ~mask; |
| 1960 | } |
| 1961 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1962 | |
| 1963 | /** |
| 1964 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1965 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1966 | * |
| 1967 | * @param label the label to display while the action is being prepared to execute |
| 1968 | * @return this object for method chaining |
| 1969 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1970 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1971 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1972 | mInProgressLabel = label; |
| 1973 | return this; |
| 1974 | } |
| 1975 | |
| 1976 | /** |
| 1977 | * Get the label to display while the wearable is preparing to automatically execute |
| 1978 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1979 | * |
| 1980 | * @return the label to display while the action is being prepared to execute |
| 1981 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1982 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1983 | public CharSequence getInProgressLabel() { |
| 1984 | return mInProgressLabel; |
| 1985 | } |
| 1986 | |
| 1987 | /** |
| 1988 | * Set a label to display to confirm that the action should be executed. |
| 1989 | * This is usually an imperative verb like "Send". |
| 1990 | * |
| 1991 | * @param label the label to confirm the action should be executed |
| 1992 | * @return this object for method chaining |
| 1993 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1994 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1995 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1996 | mConfirmLabel = label; |
| 1997 | return this; |
| 1998 | } |
| 1999 | |
| 2000 | /** |
| 2001 | * Get the label to display to confirm that the action should be executed. |
| 2002 | * This is usually an imperative verb like "Send". |
| 2003 | * |
| 2004 | * @return the label to confirm the action should be executed |
| 2005 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 2006 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 2007 | public CharSequence getConfirmLabel() { |
| 2008 | return mConfirmLabel; |
| 2009 | } |
| 2010 | |
| 2011 | /** |
| 2012 | * Set a label to display to cancel the action. |
| 2013 | * This is usually an imperative verb, like "Cancel". |
| 2014 | * |
| 2015 | * @param label the label to display to cancel the action |
| 2016 | * @return this object for method chaining |
| 2017 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 2018 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 2019 | public WearableExtender setCancelLabel(CharSequence label) { |
| 2020 | mCancelLabel = label; |
| 2021 | return this; |
| 2022 | } |
| 2023 | |
| 2024 | /** |
| 2025 | * Get the label to display to cancel the action. |
| 2026 | * This is usually an imperative verb like "Cancel". |
| 2027 | * |
| 2028 | * @return the label to display to cancel the action |
| 2029 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 2030 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 2031 | public CharSequence getCancelLabel() { |
| 2032 | return mCancelLabel; |
| 2033 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2034 | |
| 2035 | /** |
| 2036 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 2037 | * platform that it can generate the appropriate transitions. |
| 2038 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 2039 | * an activity and transitions should be generated, false otherwise. |
| 2040 | * @return this object for method chaining |
| 2041 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 2042 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2043 | boolean hintLaunchesActivity) { |
| 2044 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 2045 | return this; |
| 2046 | } |
| 2047 | |
| 2048 | /** |
| 2049 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 2050 | * platform that it can generate the appropriate transitions |
| 2051 | * @return {@code true} if the content intent will launch an activity and transitions |
| 2052 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 2053 | * never set. |
| 2054 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 2055 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2056 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 2057 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2058 | |
| 2059 | /** |
| 2060 | * Set a hint that this Action should be displayed inline. |
| 2061 | * |
| 2062 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 2063 | * otherwise |
| 2064 | * @return this object for method chaining |
| 2065 | */ |
| 2066 | public WearableExtender setHintDisplayActionInline( |
| 2067 | boolean hintDisplayInline) { |
| 2068 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 2069 | return this; |
| 2070 | } |
| 2071 | |
| 2072 | /** |
| 2073 | * Get a hint that this Action should be displayed inline. |
| 2074 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 2075 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2076 | * otherwise. The default value is {@code false} if this was never set. |
| 2077 | */ |
| 2078 | public boolean getHintDisplayActionInline() { |
| 2079 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 2080 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2081 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2082 | |
| 2083 | /** |
| 2084 | * Provides meaning to an {@link Action} that hints at what the associated |
| 2085 | * {@link PendingIntent} will do. For example, an {@link Action} with a |
| 2086 | * {@link PendingIntent} that replies to a text message notification may have the |
| 2087 | * {@link #SEMANTIC_ACTION_REPLY} {@code SemanticAction} set within it. |
| 2088 | * |
| 2089 | * @hide |
| 2090 | */ |
| 2091 | @IntDef(prefix = { "SEMANTIC_ACTION_" }, value = { |
| 2092 | SEMANTIC_ACTION_NONE, |
| 2093 | SEMANTIC_ACTION_REPLY, |
| 2094 | SEMANTIC_ACTION_MARK_AS_READ, |
| 2095 | SEMANTIC_ACTION_MARK_AS_UNREAD, |
| 2096 | SEMANTIC_ACTION_DELETE, |
| 2097 | SEMANTIC_ACTION_ARCHIVE, |
| 2098 | SEMANTIC_ACTION_MUTE, |
| 2099 | SEMANTIC_ACTION_UNMUTE, |
| 2100 | SEMANTIC_ACTION_THUMBS_UP, |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 2101 | SEMANTIC_ACTION_THUMBS_DOWN, |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 2102 | SEMANTIC_ACTION_CALL |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2103 | }) |
| 2104 | @Retention(RetentionPolicy.SOURCE) |
| 2105 | public @interface SemanticAction {} |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2106 | } |
| 2107 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2108 | /** |
| 2109 | * Array of all {@link Action} structures attached to this notification by |
| 2110 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 2111 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 2112 | * interface for invoking actions. |
| 2113 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 2114 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2115 | |
| 2116 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2117 | * Replacement version of this notification whose content will be shown |
| 2118 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 2119 | * and {@link #VISIBILITY_PUBLIC}. |
| 2120 | */ |
| 2121 | public Notification publicVersion; |
| 2122 | |
| 2123 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2124 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2125 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | */ |
| 2127 | public Notification() |
| 2128 | { |
| 2129 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2130 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2131 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | * @hide |
| 2136 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2137 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 2139 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 2140 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2141 | new Builder(context) |
| 2142 | .setWhen(when) |
| 2143 | .setSmallIcon(icon) |
| 2144 | .setTicker(tickerText) |
| 2145 | .setContentTitle(contentTitle) |
| 2146 | .setContentText(contentText) |
| 2147 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 2148 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | /** |
| 2152 | * Constructs a Notification object with the information needed to |
| 2153 | * have a status bar icon without the standard expanded view. |
| 2154 | * |
| 2155 | * @param icon The resource id of the icon to put in the status bar. |
| 2156 | * @param tickerText The text that flows by in the status bar when the notification first |
| 2157 | * activates. |
| 2158 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 2159 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2160 | * |
| 2161 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2163 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2164 | public Notification(int icon, CharSequence tickerText, long when) |
| 2165 | { |
| 2166 | this.icon = icon; |
| 2167 | this.tickerText = tickerText; |
| 2168 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2169 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | /** |
| 2173 | * Unflatten the notification from a parcel. |
| 2174 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2175 | @SuppressWarnings("unchecked") |
| 2176 | public Notification(Parcel parcel) { |
| 2177 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 2178 | // intents in extras are always written as the last entry. |
| 2179 | readFromParcelImpl(parcel); |
| 2180 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2181 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | { |
| 2186 | int version = parcel.readInt(); |
| 2187 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2188 | mWhitelistToken = parcel.readStrongBinder(); |
| 2189 | if (mWhitelistToken == null) { |
| 2190 | mWhitelistToken = processWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2191 | } |
| 2192 | // 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] | 2193 | parcel.setClassCookie(PendingIntent.class, mWhitelistToken); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2195 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2196 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2197 | if (parcel.readInt() != 0) { |
| 2198 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2199 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 2200 | icon = mSmallIcon.getResId(); |
| 2201 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2202 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2203 | number = parcel.readInt(); |
| 2204 | if (parcel.readInt() != 0) { |
| 2205 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2206 | } |
| 2207 | if (parcel.readInt() != 0) { |
| 2208 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2209 | } |
| 2210 | if (parcel.readInt() != 0) { |
| 2211 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2212 | } |
| 2213 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2214 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2215 | } |
| 2216 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2217 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2218 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2219 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2220 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2221 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2222 | defaults = parcel.readInt(); |
| 2223 | flags = parcel.readInt(); |
| 2224 | if (parcel.readInt() != 0) { |
| 2225 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 2226 | } |
| 2227 | |
| 2228 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2229 | if (parcel.readInt() != 0) { |
| 2230 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 2231 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2232 | vibrate = parcel.createLongArray(); |
| 2233 | ledARGB = parcel.readInt(); |
| 2234 | ledOnMS = parcel.readInt(); |
| 2235 | ledOffMS = parcel.readInt(); |
| 2236 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2237 | |
| 2238 | if (parcel.readInt() != 0) { |
| 2239 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2240 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2241 | |
| 2242 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2243 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2244 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2245 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2246 | mGroupKey = parcel.readString(); |
| 2247 | |
| 2248 | mSortKey = parcel.readString(); |
| 2249 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 2250 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2251 | fixDuplicateExtras(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2252 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2253 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 2254 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2255 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2256 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2257 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2258 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2259 | if (parcel.readInt() != 0) { |
| 2260 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2261 | } |
| 2262 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2263 | visibility = parcel.readInt(); |
| 2264 | |
| 2265 | if (parcel.readInt() != 0) { |
| 2266 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 2267 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2268 | |
| 2269 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2270 | |
| 2271 | if (parcel.readInt() != 0) { |
| 2272 | mChannelId = parcel.readString(); |
| 2273 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2274 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2275 | |
| 2276 | if (parcel.readInt() != 0) { |
| 2277 | mShortcutId = parcel.readString(); |
| 2278 | } |
| 2279 | |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2280 | if (parcel.readInt() != 0) { |
| 2281 | mLocusId = LocusId.CREATOR.createFromParcel(parcel); |
| 2282 | } |
| 2283 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2284 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2285 | |
| 2286 | if (parcel.readInt() != 0) { |
| 2287 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2288 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2289 | |
| 2290 | mGroupAlertBehavior = parcel.readInt(); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2291 | if (parcel.readInt() != 0) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2292 | mBubbleMetadata = BubbleMetadata.CREATOR.createFromParcel(parcel); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2293 | } |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2294 | |
| 2295 | mAllowSystemGeneratedContextualActions = parcel.readBoolean(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2296 | } |
| 2297 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2298 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2299 | public Notification clone() { |
| 2300 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2301 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2302 | return that; |
| 2303 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2304 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2305 | /** |
| 2306 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 2307 | * of this into that. |
| 2308 | * @hide |
| 2309 | */ |
| 2310 | public void cloneInto(Notification that, boolean heavy) { |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2311 | that.mWhitelistToken = this.mWhitelistToken; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2312 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2313 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2314 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2315 | that.number = this.number; |
| 2316 | |
| 2317 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 2318 | that.contentIntent = this.contentIntent; |
| 2319 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2320 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2321 | |
| 2322 | if (this.tickerText != null) { |
| 2323 | that.tickerText = this.tickerText.toString(); |
| 2324 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2325 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2326 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2327 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2328 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2329 | that.contentView = this.contentView.clone(); |
| 2330 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2331 | if (heavy && this.mLargeIcon != null) { |
| 2332 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2333 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 2334 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2335 | that.sound = this.sound; // android.net.Uri is immutable |
| 2336 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2337 | if (this.audioAttributes != null) { |
| 2338 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 2339 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2340 | |
| 2341 | final long[] vibrate = this.vibrate; |
| 2342 | if (vibrate != null) { |
| 2343 | final int N = vibrate.length; |
| 2344 | final long[] vib = that.vibrate = new long[N]; |
| 2345 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 2346 | } |
| 2347 | |
| 2348 | that.ledARGB = this.ledARGB; |
| 2349 | that.ledOnMS = this.ledOnMS; |
| 2350 | that.ledOffMS = this.ledOffMS; |
| 2351 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2352 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2353 | that.flags = this.flags; |
| 2354 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2355 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2356 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2357 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2358 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2359 | that.mGroupKey = this.mGroupKey; |
| 2360 | |
| 2361 | that.mSortKey = this.mSortKey; |
| 2362 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2363 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2364 | try { |
| 2365 | that.extras = new Bundle(this.extras); |
| 2366 | // will unparcel |
| 2367 | that.extras.size(); |
| 2368 | } catch (BadParcelableException e) { |
| 2369 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2370 | that.extras = null; |
| 2371 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2372 | } |
| 2373 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2374 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2375 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2378 | if (this.actions != null) { |
| 2379 | that.actions = new Action[this.actions.length]; |
| 2380 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 2381 | if ( this.actions[i] != null) { |
| 2382 | that.actions[i] = this.actions[i].clone(); |
| 2383 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2384 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2385 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2386 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2387 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2388 | that.bigContentView = this.bigContentView.clone(); |
| 2389 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2390 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2391 | if (heavy && this.headsUpContentView != null) { |
| 2392 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 2393 | } |
| 2394 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2395 | that.visibility = this.visibility; |
| 2396 | |
| 2397 | if (this.publicVersion != null) { |
| 2398 | that.publicVersion = new Notification(); |
| 2399 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2400 | } |
| 2401 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2402 | that.color = this.color; |
| 2403 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2404 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2405 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2406 | that.mShortcutId = this.mShortcutId; |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2407 | that.mLocusId = this.mLocusId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2408 | that.mBadgeIcon = this.mBadgeIcon; |
| 2409 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2410 | that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2411 | that.mBubbleMetadata = this.mBubbleMetadata; |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2412 | that.mAllowSystemGeneratedContextualActions = this.mAllowSystemGeneratedContextualActions; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2413 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2414 | if (!heavy) { |
| 2415 | that.lightenPayload(); // will clean out extras |
| 2416 | } |
| 2417 | } |
| 2418 | |
| 2419 | /** |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2420 | * Note all {@link Uri} that are referenced internally, with the expectation |
| 2421 | * that Uri permission grants will need to be issued to ensure the recipient |
| 2422 | * of this object is able to render its contents. |
| 2423 | * |
| 2424 | * @hide |
| 2425 | */ |
| 2426 | public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 2427 | visitor.accept(sound); |
| 2428 | |
| 2429 | if (tickerView != null) tickerView.visitUris(visitor); |
| 2430 | if (contentView != null) contentView.visitUris(visitor); |
| 2431 | if (bigContentView != null) bigContentView.visitUris(visitor); |
| 2432 | if (headsUpContentView != null) headsUpContentView.visitUris(visitor); |
| 2433 | |
| 2434 | if (extras != null) { |
| 2435 | visitor.accept(extras.getParcelable(EXTRA_AUDIO_CONTENTS_URI)); |
Robin Lee | d107af6 | 2018-04-27 13:55:56 +0200 | [diff] [blame] | 2436 | if (extras.containsKey(EXTRA_BACKGROUND_IMAGE_URI)) { |
| 2437 | visitor.accept(Uri.parse(extras.getString(EXTRA_BACKGROUND_IMAGE_URI))); |
| 2438 | } |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | if (MessagingStyle.class.equals(getNotificationStyle()) && extras != null) { |
| 2442 | final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 2443 | if (!ArrayUtils.isEmpty(messages)) { |
| 2444 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2445 | .getMessagesFromBundleArray(messages)) { |
| 2446 | visitor.accept(message.getDataUri()); |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 2451 | if (!ArrayUtils.isEmpty(historic)) { |
| 2452 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2453 | .getMessagesFromBundleArray(historic)) { |
| 2454 | visitor.accept(message.getDataUri()); |
| 2455 | } |
| 2456 | } |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | /** |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2461 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 2462 | * listeners when the full contents are not necessary. |
| 2463 | * @hide |
| 2464 | */ |
| 2465 | public final void lightenPayload() { |
| 2466 | tickerView = null; |
| 2467 | contentView = null; |
| 2468 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2469 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2470 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2471 | if (extras != null && !extras.isEmpty()) { |
| 2472 | final Set<String> keyset = extras.keySet(); |
| 2473 | final int N = keyset.size(); |
| 2474 | final String[] keys = keyset.toArray(new String[N]); |
| 2475 | for (int i=0; i<N; i++) { |
| 2476 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2477 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2478 | continue; |
| 2479 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2480 | final Object obj = extras.get(key); |
| 2481 | if (obj != null && |
| 2482 | ( obj instanceof Parcelable |
| 2483 | || obj instanceof Parcelable[] |
| 2484 | || obj instanceof SparseArray |
| 2485 | || obj instanceof ArrayList)) { |
| 2486 | extras.remove(key); |
| 2487 | } |
| 2488 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2489 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2490 | } |
| 2491 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2492 | /** |
| 2493 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2494 | * means it had better not be some custom Parcelable implementation. |
| 2495 | * @hide |
| 2496 | */ |
| 2497 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2498 | if (cs == null) return cs; |
| 2499 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2500 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2501 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2502 | if (cs instanceof Parcelable) { |
| 2503 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2504 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2505 | return cs.toString(); |
| 2506 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2507 | return removeTextSizeSpans(cs); |
| 2508 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2509 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2510 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2511 | if (charSequence instanceof Spanned) { |
| 2512 | Spanned ss = (Spanned) charSequence; |
| 2513 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2514 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2515 | for (Object span : spans) { |
| 2516 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2517 | if (resultSpan instanceof CharacterStyle) { |
| 2518 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2519 | } |
| 2520 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2521 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2522 | resultSpan = new TextAppearanceSpan( |
| 2523 | originalSpan.getFamily(), |
| 2524 | originalSpan.getTextStyle(), |
| 2525 | -1, |
| 2526 | originalSpan.getTextColor(), |
| 2527 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2528 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2529 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2530 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2531 | } else { |
| 2532 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2533 | } |
| 2534 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2535 | ss.getSpanFlags(span)); |
| 2536 | } |
| 2537 | return builder; |
| 2538 | } |
| 2539 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2540 | } |
| 2541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | public int describeContents() { |
| 2543 | return 0; |
| 2544 | } |
| 2545 | |
| 2546 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2547 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2548 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2549 | public void writeToParcel(Parcel parcel, int flags) { |
| 2550 | // We need to mark all pending intents getting into the notification |
| 2551 | // system as being put there to later allow the notification ranker |
| 2552 | // to launch them and by doing so add the app to the battery saver white |
| 2553 | // list for a short period of time. The problem is that the system |
| 2554 | // cannot look into the extras as there may be parcelables there that |
| 2555 | // the platform does not know how to handle. To go around that we have |
| 2556 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2557 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2558 | if (collectPendingIntents) { |
| 2559 | PendingIntent.setOnMarshaledListener( |
| 2560 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2561 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2562 | if (allPendingIntents == null) { |
| 2563 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2564 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2565 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2566 | } |
| 2567 | }); |
| 2568 | } |
| 2569 | try { |
| 2570 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2571 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2572 | writeToParcelImpl(parcel, flags); |
| 2573 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2574 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2575 | } finally { |
| 2576 | if (collectPendingIntents) { |
| 2577 | PendingIntent.setOnMarshaledListener(null); |
| 2578 | } |
| 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2583 | parcel.writeInt(1); |
| 2584 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2585 | parcel.writeStrongBinder(mWhitelistToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2586 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2587 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2588 | if (mSmallIcon == null && icon != 0) { |
| 2589 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2590 | mSmallIcon = Icon.createWithResource("", icon); |
| 2591 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2592 | if (mSmallIcon != null) { |
| 2593 | parcel.writeInt(1); |
| 2594 | mSmallIcon.writeToParcel(parcel, 0); |
| 2595 | } else { |
| 2596 | parcel.writeInt(0); |
| 2597 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | parcel.writeInt(number); |
| 2599 | if (contentIntent != null) { |
| 2600 | parcel.writeInt(1); |
| 2601 | contentIntent.writeToParcel(parcel, 0); |
| 2602 | } else { |
| 2603 | parcel.writeInt(0); |
| 2604 | } |
| 2605 | if (deleteIntent != null) { |
| 2606 | parcel.writeInt(1); |
| 2607 | deleteIntent.writeToParcel(parcel, 0); |
| 2608 | } else { |
| 2609 | parcel.writeInt(0); |
| 2610 | } |
| 2611 | if (tickerText != null) { |
| 2612 | parcel.writeInt(1); |
| 2613 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2614 | } else { |
| 2615 | parcel.writeInt(0); |
| 2616 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2617 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2618 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2619 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2620 | } else { |
| 2621 | parcel.writeInt(0); |
| 2622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2623 | if (contentView != null) { |
| 2624 | parcel.writeInt(1); |
| 2625 | contentView.writeToParcel(parcel, 0); |
| 2626 | } else { |
| 2627 | parcel.writeInt(0); |
| 2628 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2629 | if (mLargeIcon == null && largeIcon != null) { |
| 2630 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2631 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2632 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2633 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2634 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2635 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2636 | } else { |
| 2637 | parcel.writeInt(0); |
| 2638 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2639 | |
| 2640 | parcel.writeInt(defaults); |
| 2641 | parcel.writeInt(this.flags); |
| 2642 | |
| 2643 | if (sound != null) { |
| 2644 | parcel.writeInt(1); |
| 2645 | sound.writeToParcel(parcel, 0); |
| 2646 | } else { |
| 2647 | parcel.writeInt(0); |
| 2648 | } |
| 2649 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2650 | |
| 2651 | if (audioAttributes != null) { |
| 2652 | parcel.writeInt(1); |
| 2653 | audioAttributes.writeToParcel(parcel, 0); |
| 2654 | } else { |
| 2655 | parcel.writeInt(0); |
| 2656 | } |
| 2657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | parcel.writeLongArray(vibrate); |
| 2659 | parcel.writeInt(ledARGB); |
| 2660 | parcel.writeInt(ledOnMS); |
| 2661 | parcel.writeInt(ledOffMS); |
| 2662 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2663 | |
| 2664 | if (fullScreenIntent != null) { |
| 2665 | parcel.writeInt(1); |
| 2666 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2667 | } else { |
| 2668 | parcel.writeInt(0); |
| 2669 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2670 | |
| 2671 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2672 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2673 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2674 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2675 | parcel.writeString(mGroupKey); |
| 2676 | |
| 2677 | parcel.writeString(mSortKey); |
| 2678 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2679 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2680 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2681 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2682 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2683 | if (bigContentView != null) { |
| 2684 | parcel.writeInt(1); |
| 2685 | bigContentView.writeToParcel(parcel, 0); |
| 2686 | } else { |
| 2687 | parcel.writeInt(0); |
| 2688 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2689 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2690 | if (headsUpContentView != null) { |
| 2691 | parcel.writeInt(1); |
| 2692 | headsUpContentView.writeToParcel(parcel, 0); |
| 2693 | } else { |
| 2694 | parcel.writeInt(0); |
| 2695 | } |
| 2696 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2697 | parcel.writeInt(visibility); |
| 2698 | |
| 2699 | if (publicVersion != null) { |
| 2700 | parcel.writeInt(1); |
| 2701 | publicVersion.writeToParcel(parcel, 0); |
| 2702 | } else { |
| 2703 | parcel.writeInt(0); |
| 2704 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2705 | |
| 2706 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2707 | |
| 2708 | if (mChannelId != null) { |
| 2709 | parcel.writeInt(1); |
| 2710 | parcel.writeString(mChannelId); |
| 2711 | } else { |
| 2712 | parcel.writeInt(0); |
| 2713 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2714 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2715 | |
| 2716 | if (mShortcutId != null) { |
| 2717 | parcel.writeInt(1); |
| 2718 | parcel.writeString(mShortcutId); |
| 2719 | } else { |
| 2720 | parcel.writeInt(0); |
| 2721 | } |
| 2722 | |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 2723 | if (mLocusId != null) { |
| 2724 | parcel.writeInt(1); |
| 2725 | mLocusId.writeToParcel(parcel, 0); |
| 2726 | } else { |
| 2727 | parcel.writeInt(0); |
| 2728 | } |
| 2729 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2730 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2731 | |
| 2732 | if (mSettingsText != null) { |
| 2733 | parcel.writeInt(1); |
| 2734 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2735 | } else { |
| 2736 | parcel.writeInt(0); |
| 2737 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2738 | |
| 2739 | parcel.writeInt(mGroupAlertBehavior); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2740 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2741 | if (mBubbleMetadata != null) { |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2742 | parcel.writeInt(1); |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 2743 | mBubbleMetadata.writeToParcel(parcel, 0); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2744 | } else { |
| 2745 | parcel.writeInt(0); |
| 2746 | } |
| 2747 | |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2748 | parcel.writeBoolean(mAllowSystemGeneratedContextualActions); |
| 2749 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2750 | // 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] | 2751 | } |
| 2752 | |
| 2753 | /** |
| 2754 | * Parcelable.Creator that instantiates Notification objects |
| 2755 | */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 2756 | 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] | 2757 | = new Parcelable.Creator<Notification>() |
| 2758 | { |
| 2759 | public Notification createFromParcel(Parcel parcel) |
| 2760 | { |
| 2761 | return new Notification(parcel); |
| 2762 | } |
| 2763 | |
| 2764 | public Notification[] newArray(int size) |
| 2765 | { |
| 2766 | return new Notification[size]; |
| 2767 | } |
| 2768 | }; |
| 2769 | |
| 2770 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2771 | * @hide |
| 2772 | */ |
| 2773 | public static boolean areActionsVisiblyDifferent(Notification first, Notification second) { |
| 2774 | Notification.Action[] firstAs = first.actions; |
| 2775 | Notification.Action[] secondAs = second.actions; |
| 2776 | if (firstAs == null && secondAs != null || firstAs != null && secondAs == null) { |
| 2777 | return true; |
| 2778 | } |
| 2779 | if (firstAs != null && secondAs != null) { |
| 2780 | if (firstAs.length != secondAs.length) { |
| 2781 | return true; |
| 2782 | } |
| 2783 | for (int i = 0; i < firstAs.length; i++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2784 | if (!Objects.equals(String.valueOf(firstAs[i].title), |
| 2785 | String.valueOf(secondAs[i].title))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2786 | return true; |
| 2787 | } |
| 2788 | RemoteInput[] firstRs = firstAs[i].getRemoteInputs(); |
| 2789 | RemoteInput[] secondRs = secondAs[i].getRemoteInputs(); |
| 2790 | if (firstRs == null) { |
| 2791 | firstRs = new RemoteInput[0]; |
| 2792 | } |
| 2793 | if (secondRs == null) { |
| 2794 | secondRs = new RemoteInput[0]; |
| 2795 | } |
| 2796 | if (firstRs.length != secondRs.length) { |
| 2797 | return true; |
| 2798 | } |
| 2799 | for (int j = 0; j < firstRs.length; j++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2800 | if (!Objects.equals(String.valueOf(firstRs[j].getLabel()), |
| 2801 | String.valueOf(secondRs[j].getLabel()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2802 | return true; |
| 2803 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2804 | } |
| 2805 | } |
| 2806 | } |
| 2807 | return false; |
| 2808 | } |
| 2809 | |
| 2810 | /** |
| 2811 | * @hide |
| 2812 | */ |
| 2813 | public static boolean areStyledNotificationsVisiblyDifferent(Builder first, Builder second) { |
| 2814 | if (first.getStyle() == null) { |
| 2815 | return second.getStyle() != null; |
| 2816 | } |
| 2817 | if (second.getStyle() == null) { |
| 2818 | return true; |
| 2819 | } |
| 2820 | return first.getStyle().areNotificationsVisiblyDifferent(second.getStyle()); |
| 2821 | } |
| 2822 | |
| 2823 | /** |
| 2824 | * @hide |
| 2825 | */ |
| 2826 | public static boolean areRemoteViewsChanged(Builder first, Builder second) { |
Julia Reynolds | e5c6045 | 2018-04-30 14:41:36 -0400 | [diff] [blame] | 2827 | if (!Objects.equals(first.usesStandardHeader(), second.usesStandardHeader())) { |
| 2828 | return true; |
| 2829 | } |
| 2830 | |
| 2831 | if (areRemoteViewsChanged(first.mN.contentView, second.mN.contentView)) { |
| 2832 | return true; |
| 2833 | } |
| 2834 | if (areRemoteViewsChanged(first.mN.bigContentView, second.mN.bigContentView)) { |
| 2835 | return true; |
| 2836 | } |
| 2837 | if (areRemoteViewsChanged(first.mN.headsUpContentView, second.mN.headsUpContentView)) { |
| 2838 | return true; |
| 2839 | } |
| 2840 | |
| 2841 | return false; |
| 2842 | } |
| 2843 | |
| 2844 | private static boolean areRemoteViewsChanged(RemoteViews first, RemoteViews second) { |
| 2845 | if (first == null && second == null) { |
| 2846 | return false; |
| 2847 | } |
| 2848 | if (first == null && second != null || first != null && second == null) { |
| 2849 | return true; |
| 2850 | } |
| 2851 | |
| 2852 | if (!Objects.equals(first.getLayoutId(), second.getLayoutId())) { |
| 2853 | return true; |
| 2854 | } |
| 2855 | |
| 2856 | if (!Objects.equals(first.getSequenceNumber(), second.getSequenceNumber())) { |
| 2857 | return true; |
| 2858 | } |
| 2859 | |
| 2860 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | /** |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2864 | * Parcelling creates multiple copies of objects in {@code extras}. Fix them. |
| 2865 | * <p> |
| 2866 | * For backwards compatibility {@code extras} holds some references to "real" member data such |
| 2867 | * as {@link getLargeIcon()} which is mirrored by {@link #EXTRA_LARGE_ICON}. This is mostly |
| 2868 | * fine as long as the object stays in one process. |
| 2869 | * <p> |
| 2870 | * However, once the notification goes into a parcel each reference gets marshalled separately, |
| 2871 | * wasting memory. Especially with large images on Auto and TV, this is worth fixing. |
| 2872 | */ |
| 2873 | private void fixDuplicateExtras() { |
| 2874 | if (extras != null) { |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2875 | fixDuplicateExtra(mLargeIcon, EXTRA_LARGE_ICON); |
| 2876 | } |
| 2877 | } |
| 2878 | |
| 2879 | /** |
| 2880 | * If we find an extra that's exactly the same as one of the "real" fields but refers to a |
| 2881 | * separate object, replace it with the field's version to avoid holding duplicate copies. |
| 2882 | */ |
| 2883 | private void fixDuplicateExtra(@Nullable Parcelable original, @NonNull String extraName) { |
| 2884 | if (original != null && extras.getParcelable(extraName) != null) { |
| 2885 | extras.putParcelable(extraName, original); |
| 2886 | } |
| 2887 | } |
| 2888 | |
| 2889 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2890 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2891 | * layout. |
| 2892 | * |
| 2893 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2894 | * in the view.</p> |
| 2895 | * @param context The context for your application / activity. |
| 2896 | * @param contentTitle The title that goes in the expanded entry. |
| 2897 | * @param contentText The text that goes in the expanded entry. |
| 2898 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2899 | * If this is an activity, it must include the |
| 2900 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2901 | * that you take care of task management as described in the |
| 2902 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2903 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2904 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2905 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2906 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2908 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | public void setLatestEventInfo(Context context, |
| 2910 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2911 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2912 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2913 | new Throwable()); |
| 2914 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2915 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2916 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2917 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2918 | } |
| 2919 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2920 | // ensure that any information already set directly is preserved |
| 2921 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2922 | |
| 2923 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2924 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2925 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2926 | } |
| 2927 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2928 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2929 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2930 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2931 | |
| 2932 | 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] | 2933 | } |
| 2934 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2935 | /** |
| 2936 | * @hide |
| 2937 | */ |
| 2938 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2939 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | /** |
| 2943 | * @hide |
| 2944 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2945 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2946 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2947 | } |
| 2948 | |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 2949 | /** |
| 2950 | * @hide |
| 2951 | */ |
| 2952 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 2953 | long token = proto.start(fieldId); |
| 2954 | proto.write(NotificationProto.CHANNEL_ID, getChannelId()); |
| 2955 | proto.write(NotificationProto.HAS_TICKER_TEXT, this.tickerText != null); |
| 2956 | proto.write(NotificationProto.FLAGS, this.flags); |
| 2957 | proto.write(NotificationProto.COLOR, this.color); |
| 2958 | proto.write(NotificationProto.CATEGORY, this.category); |
| 2959 | proto.write(NotificationProto.GROUP_KEY, this.mGroupKey); |
| 2960 | proto.write(NotificationProto.SORT_KEY, this.mSortKey); |
| 2961 | if (this.actions != null) { |
| 2962 | proto.write(NotificationProto.ACTION_LENGTH, this.actions.length); |
| 2963 | } |
| 2964 | if (this.visibility >= VISIBILITY_SECRET && this.visibility <= VISIBILITY_PUBLIC) { |
| 2965 | proto.write(NotificationProto.VISIBILITY, this.visibility); |
| 2966 | } |
| 2967 | if (publicVersion != null) { |
| 2968 | publicVersion.writeToProto(proto, NotificationProto.PUBLIC_VERSION); |
| 2969 | } |
| 2970 | proto.end(token); |
| 2971 | } |
| 2972 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2973 | @Override |
| 2974 | public String toString() { |
| 2975 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2976 | sb.append("Notification(channel="); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2977 | sb.append(getChannelId()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2978 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2979 | sb.append(priority); |
| 2980 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2981 | if (contentView != null) { |
| 2982 | sb.append(contentView.getPackage()); |
| 2983 | sb.append("/0x"); |
| 2984 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2985 | } else { |
| 2986 | sb.append("null"); |
| 2987 | } |
| 2988 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2989 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2990 | sb.append("default"); |
| 2991 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2992 | int N = this.vibrate.length-1; |
| 2993 | sb.append("["); |
| 2994 | for (int i=0; i<N; i++) { |
| 2995 | sb.append(this.vibrate[i]); |
| 2996 | sb.append(','); |
| 2997 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 2998 | if (N != -1) { |
| 2999 | sb.append(this.vibrate[N]); |
| 3000 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3001 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | } else { |
| 3003 | sb.append("null"); |
| 3004 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3005 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 3006 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 3008 | } else if (this.sound != null) { |
| 3009 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3010 | } else { |
| 3011 | sb.append("null"); |
| 3012 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 3013 | if (this.tickerText != null) { |
| 3014 | sb.append(" tick"); |
| 3015 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3016 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3017 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3018 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 3019 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3020 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3021 | if (this.category != null) { |
| 3022 | sb.append(" category="); |
| 3023 | sb.append(this.category); |
| 3024 | } |
| 3025 | if (this.mGroupKey != null) { |
| 3026 | sb.append(" groupKey="); |
| 3027 | sb.append(this.mGroupKey); |
| 3028 | } |
| 3029 | if (this.mSortKey != null) { |
| 3030 | sb.append(" sortKey="); |
| 3031 | sb.append(this.mSortKey); |
| 3032 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3033 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 3034 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3035 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 3036 | } |
| 3037 | sb.append(" vis="); |
| 3038 | sb.append(visibilityToString(this.visibility)); |
| 3039 | if (this.publicVersion != null) { |
| 3040 | sb.append(" publicVersion="); |
| 3041 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3042 | } |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 3043 | if (this.mLocusId != null) { |
| 3044 | sb.append(" locusId="); |
| 3045 | sb.append(this.mLocusId); // LocusId.toString() is PII safe. |
| 3046 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3047 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3048 | return sb.toString(); |
| 3049 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3050 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 3051 | /** |
| 3052 | * {@hide} |
| 3053 | */ |
| 3054 | public static String visibilityToString(int vis) { |
| 3055 | switch (vis) { |
| 3056 | case VISIBILITY_PRIVATE: |
| 3057 | return "PRIVATE"; |
| 3058 | case VISIBILITY_PUBLIC: |
| 3059 | return "PUBLIC"; |
| 3060 | case VISIBILITY_SECRET: |
| 3061 | return "SECRET"; |
| 3062 | default: |
| 3063 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 3064 | } |
| 3065 | } |
| 3066 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3067 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 3068 | * {@hide} |
| 3069 | */ |
| 3070 | public static String priorityToString(@Priority int pri) { |
| 3071 | switch (pri) { |
| 3072 | case PRIORITY_MIN: |
| 3073 | return "MIN"; |
| 3074 | case PRIORITY_LOW: |
| 3075 | return "LOW"; |
| 3076 | case PRIORITY_DEFAULT: |
| 3077 | return "DEFAULT"; |
| 3078 | case PRIORITY_HIGH: |
| 3079 | return "HIGH"; |
| 3080 | case PRIORITY_MAX: |
| 3081 | return "MAX"; |
| 3082 | default: |
| 3083 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 3084 | } |
| 3085 | } |
| 3086 | |
Julia Reynolds | 6ad0aec | 2017-07-05 08:47:03 -0400 | [diff] [blame] | 3087 | /** |
| 3088 | * @hide |
| 3089 | */ |
| 3090 | public boolean hasCompletedProgress() { |
| 3091 | // not a progress notification; can't be complete |
| 3092 | if (!extras.containsKey(EXTRA_PROGRESS) |
| 3093 | || !extras.containsKey(EXTRA_PROGRESS_MAX)) { |
| 3094 | return false; |
| 3095 | } |
| 3096 | // many apps use max 0 for 'indeterminate'; not complete |
| 3097 | if (extras.getInt(EXTRA_PROGRESS_MAX) == 0) { |
| 3098 | return false; |
| 3099 | } |
| 3100 | return extras.getInt(EXTRA_PROGRESS) == extras.getInt(EXTRA_PROGRESS_MAX); |
| 3101 | } |
| 3102 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3103 | /** @removed */ |
| 3104 | @Deprecated |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 3105 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3106 | return mChannelId; |
| 3107 | } |
| 3108 | |
| 3109 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3110 | * Returns the id of the channel this notification posts to. |
| 3111 | */ |
| 3112 | public String getChannelId() { |
| 3113 | return mChannelId; |
| 3114 | } |
| 3115 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3116 | /** @removed */ |
| 3117 | @Deprecated |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3118 | public long getTimeout() { |
| 3119 | return mTimeout; |
| 3120 | } |
| 3121 | |
| 3122 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3123 | * Returns the duration from posting after which this notification should be canceled by the |
| 3124 | * system, if it's not canceled already. |
| 3125 | */ |
| 3126 | public long getTimeoutAfter() { |
| 3127 | return mTimeout; |
| 3128 | } |
| 3129 | |
| 3130 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3131 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 3132 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 3133 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 3134 | */ |
| 3135 | public int getBadgeIconType() { |
| 3136 | return mBadgeIcon; |
| 3137 | } |
| 3138 | |
| 3139 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3140 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3141 | * |
| 3142 | * <p>Used by some Launchers that display notification content to hide shortcuts that duplicate |
| 3143 | * notifications. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3144 | */ |
| 3145 | public String getShortcutId() { |
| 3146 | return mShortcutId; |
| 3147 | } |
| 3148 | |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 3149 | /** |
| 3150 | * Gets the {@link LocusId} associated with this notification. |
| 3151 | * |
| 3152 | * <p>Used by the device's intelligence services to correlate objects (such as |
| 3153 | * {@link ShortcutInfo} and {@link ContentCaptureContext}) that are correlated. |
| 3154 | */ |
| 3155 | @Nullable |
| 3156 | public LocusId getLocusId() { |
| 3157 | return mLocusId; |
| 3158 | } |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3159 | |
| 3160 | /** |
| 3161 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 3162 | */ |
| 3163 | public CharSequence getSettingsText() { |
| 3164 | return mSettingsText; |
| 3165 | } |
| 3166 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3167 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3168 | * Returns which type of notifications in a group are responsible for audibly alerting the |
| 3169 | * user. See {@link #GROUP_ALERT_ALL}, {@link #GROUP_ALERT_CHILDREN}, |
| 3170 | * {@link #GROUP_ALERT_SUMMARY}. |
| 3171 | */ |
| 3172 | public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 3173 | return mGroupAlertBehavior; |
| 3174 | } |
| 3175 | |
| 3176 | /** |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3177 | * Returns the bubble metadata that will be used to display app content in a floating window |
| 3178 | * over the existing foreground activity. |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3179 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 3180 | @Nullable |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3181 | public BubbleMetadata getBubbleMetadata() { |
| 3182 | return mBubbleMetadata; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3183 | } |
| 3184 | |
Gustav Sennton | 79ebf4b | 2018-12-19 10:31:51 +0000 | [diff] [blame] | 3185 | /** |
| 3186 | * Returns whether the platform is allowed (by the app developer) to generate contextual actions |
| 3187 | * for this notification. |
| 3188 | */ |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 3189 | public boolean getAllowSystemGeneratedContextualActions() { |
| 3190 | return mAllowSystemGeneratedContextualActions; |
| 3191 | } |
| 3192 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3193 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3194 | * The small icon representing this notification in the status bar and content view. |
| 3195 | * |
| 3196 | * @return the small icon representing this notification. |
| 3197 | * |
| 3198 | * @see Builder#getSmallIcon() |
| 3199 | * @see Builder#setSmallIcon(Icon) |
| 3200 | */ |
| 3201 | public Icon getSmallIcon() { |
| 3202 | return mSmallIcon; |
| 3203 | } |
| 3204 | |
| 3205 | /** |
| 3206 | * Used when notifying to clean up legacy small icons. |
| 3207 | * @hide |
| 3208 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3209 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3210 | public void setSmallIcon(Icon icon) { |
| 3211 | mSmallIcon = icon; |
| 3212 | } |
| 3213 | |
| 3214 | /** |
| 3215 | * The large icon shown in this notification's content view. |
| 3216 | * @see Builder#getLargeIcon() |
| 3217 | * @see Builder#setLargeIcon(Icon) |
| 3218 | */ |
| 3219 | public Icon getLargeIcon() { |
| 3220 | return mLargeIcon; |
| 3221 | } |
| 3222 | |
| 3223 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3224 | * @hide |
| 3225 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3226 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3227 | public boolean isGroupSummary() { |
| 3228 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * @hide |
| 3233 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3234 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3235 | public boolean isGroupChild() { |
| 3236 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 3237 | } |
| 3238 | |
| 3239 | /** |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3240 | * @hide |
| 3241 | */ |
| 3242 | public boolean suppressAlertingDueToGrouping() { |
| 3243 | if (isGroupSummary() |
| 3244 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { |
| 3245 | return true; |
| 3246 | } else if (isGroupChild() |
| 3247 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { |
| 3248 | return true; |
| 3249 | } |
| 3250 | return false; |
| 3251 | } |
| 3252 | |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 3253 | |
| 3254 | /** |
| 3255 | * Finds and returns a remote input and its corresponding action. |
| 3256 | * |
| 3257 | * @param requiresFreeform requires the remoteinput to allow freeform or not. |
| 3258 | * @return the result pair, {@code null} if no result is found. |
| 3259 | * |
| 3260 | * @hide |
| 3261 | */ |
| 3262 | @Nullable |
| 3263 | public Pair<RemoteInput, Action> findRemoteInputActionPair(boolean requiresFreeform) { |
| 3264 | if (actions == null) { |
| 3265 | return null; |
| 3266 | } |
| 3267 | for (Notification.Action action : actions) { |
| 3268 | if (action.getRemoteInputs() == null) { |
| 3269 | continue; |
| 3270 | } |
| 3271 | RemoteInput resultRemoteInput = null; |
| 3272 | for (RemoteInput remoteInput : action.getRemoteInputs()) { |
| 3273 | if (remoteInput.getAllowFreeFormInput() || !requiresFreeform) { |
| 3274 | resultRemoteInput = remoteInput; |
| 3275 | } |
| 3276 | } |
| 3277 | if (resultRemoteInput != null) { |
| 3278 | return Pair.create(resultRemoteInput, action); |
| 3279 | } |
| 3280 | } |
| 3281 | return null; |
| 3282 | } |
| 3283 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3284 | /** |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 3285 | * 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] | 3286 | * |
| 3287 | * @hide |
| 3288 | */ |
| 3289 | public List<Notification.Action> getContextualActions() { |
| 3290 | if (actions == null) return Collections.emptyList(); |
| 3291 | |
| 3292 | List<Notification.Action> contextualActions = new ArrayList<>(); |
| 3293 | for (Notification.Action action : actions) { |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 3294 | if (action.isContextual()) { |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 3295 | contextualActions.add(action); |
| 3296 | } |
| 3297 | } |
| 3298 | return contextualActions; |
| 3299 | } |
| 3300 | |
| 3301 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3302 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3303 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3304 | * 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] | 3305 | * content views using the platform's notification layout template. If your app supports |
| 3306 | * versions of Android as old as API level 4, you can instead use |
| 3307 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 3308 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 3309 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3310 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3311 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3312 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3313 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3314 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3315 | * .setContentTitle("New mail from " + sender.toString()) |
| 3316 | * .setContentText(subject) |
| 3317 | * .setSmallIcon(R.drawable.new_mail) |
| 3318 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3319 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3320 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3321 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3322 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3323 | /** |
| 3324 | * @hide |
| 3325 | */ |
| 3326 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 3327 | "android.rebuild.contentViewActionCount"; |
| 3328 | /** |
| 3329 | * @hide |
| 3330 | */ |
| 3331 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 3332 | = "android.rebuild.bigViewActionCount"; |
| 3333 | /** |
| 3334 | * @hide |
| 3335 | */ |
| 3336 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 3337 | = "android.rebuild.hudViewActionCount"; |
| 3338 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 3339 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 3340 | SystemProperties.getBoolean("notifications.only_title", true); |
| 3341 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3342 | /** |
| 3343 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3344 | * secondary text color when the background is light. |
| 3345 | */ |
| 3346 | private static final int LIGHTNESS_TEXT_DIFFERENCE_LIGHT = 20; |
| 3347 | |
| 3348 | /** |
| 3349 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3350 | * secondary text color when the background is dark. |
| 3351 | * A bit less then the above value, since it looks better on dark backgrounds. |
| 3352 | */ |
| 3353 | private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10; |
| 3354 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3355 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3356 | private Notification mN; |
| 3357 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3358 | private Style mStyle; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3359 | @UnsupportedAppUsage |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3360 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3361 | private ArrayList<Person> mPersonList = new ArrayList<>(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3362 | private ContrastColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3363 | private boolean mIsLegacy; |
| 3364 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3365 | |
| 3366 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3367 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 3368 | */ |
| 3369 | private int mCachedContrastColor = COLOR_INVALID; |
| 3370 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3371 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3372 | * Caches a ambient version of {@link #mCachedAmbientColorIsFor}. |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3373 | */ |
| 3374 | private int mCachedAmbientColor = COLOR_INVALID; |
| 3375 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3376 | /** |
| 3377 | * A neutral color color that can be used for icons. |
| 3378 | */ |
| 3379 | private int mNeutralColor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3380 | |
| 3381 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3382 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 3383 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 3384 | */ |
| 3385 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3386 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 3387 | private int mPrimaryTextColor = COLOR_INVALID; |
| 3388 | private int mSecondaryTextColor = COLOR_INVALID; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3389 | private int mBackgroundColor = COLOR_INVALID; |
| 3390 | private int mForegroundColor = COLOR_INVALID; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 3391 | /** |
| 3392 | * A temporary location where actions are stored. If != null the view originally has action |
| 3393 | * but doesn't have any for this inflation. |
| 3394 | */ |
| 3395 | private ArrayList<Action> mOriginalActions; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 3396 | private boolean mRebuildStyledRemoteViews; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3397 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3398 | private boolean mTintActionButtons; |
| 3399 | private boolean mInNightMode; |
| 3400 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3401 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3402 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3403 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3404 | * @param context |
| 3405 | * A {@link Context} that will be used by the Builder to construct the |
| 3406 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 3407 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3408 | * @param channelId |
| 3409 | * The constructed Notification will be posted on this |
| 3410 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 3411 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3412 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3413 | public Builder(Context context, String channelId) { |
| 3414 | this(context, (Notification) null); |
| 3415 | mN.mChannelId = channelId; |
| 3416 | } |
| 3417 | |
| 3418 | /** |
| 3419 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 3420 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 3421 | */ |
| 3422 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3423 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3424 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3425 | } |
| 3426 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3427 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3428 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3429 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3430 | public Builder(Context context, Notification toAdopt) { |
| 3431 | mContext = context; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3432 | Resources res = mContext.getResources(); |
| 3433 | mTintActionButtons = res.getBoolean(R.bool.config_tintNotificationActionButtons); |
| 3434 | |
| 3435 | if (res.getBoolean(R.bool.config_enableNightMode)) { |
| 3436 | Configuration currentConfig = res.getConfiguration(); |
| 3437 | mInNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 3438 | == Configuration.UI_MODE_NIGHT_YES; |
| 3439 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3440 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3441 | if (toAdopt == null) { |
| 3442 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3443 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 3444 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 3445 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3446 | mN.priority = PRIORITY_DEFAULT; |
| 3447 | mN.visibility = VISIBILITY_PRIVATE; |
| 3448 | } else { |
| 3449 | mN = toAdopt; |
| 3450 | if (mN.actions != null) { |
| 3451 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3452 | } |
| 3453 | |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3454 | if (mN.extras.containsKey(EXTRA_PEOPLE_LIST)) { |
| 3455 | ArrayList<Person> people = mN.extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 3456 | mPersonList.addAll(people); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3457 | } |
| 3458 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 3459 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 3460 | setSmallIcon(mN.icon); |
| 3461 | } |
| 3462 | |
| 3463 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 3464 | setLargeIcon(mN.largeIcon); |
| 3465 | } |
| 3466 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3467 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 3468 | if (!TextUtils.isEmpty(templateClass)) { |
| 3469 | final Class<? extends Style> styleClass |
| 3470 | = getNotificationStyleClass(templateClass); |
| 3471 | if (styleClass == null) { |
| 3472 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 3473 | } else { |
| 3474 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3475 | final Constructor<? extends Style> ctor = |
| 3476 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3477 | ctor.setAccessible(true); |
| 3478 | final Style style = ctor.newInstance(); |
| 3479 | style.restoreFromExtras(mN.extras); |
| 3480 | |
| 3481 | if (style != null) { |
| 3482 | setStyle(style); |
| 3483 | } |
| 3484 | } catch (Throwable t) { |
| 3485 | Log.e(TAG, "Could not create Style", t); |
| 3486 | } |
| 3487 | } |
| 3488 | } |
| 3489 | |
| 3490 | } |
| 3491 | } |
| 3492 | |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3493 | private ContrastColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3494 | if (mColorUtil == null) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3495 | mColorUtil = ContrastColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3496 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3497 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3501 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 3502 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 3503 | * the shortcut. |
| 3504 | * |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3505 | * This field will be ignored by Launchers that don't support badging, don't show |
| 3506 | * notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3507 | * |
| 3508 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 3509 | * supersedes |
| 3510 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3511 | @NonNull |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3512 | public Builder setShortcutId(String shortcutId) { |
| 3513 | mN.mShortcutId = shortcutId; |
| 3514 | return this; |
| 3515 | } |
| 3516 | |
| 3517 | /** |
Felipe Leme | 90205ef | 2019-03-05 09:59:52 -0800 | [diff] [blame] | 3518 | * Sets the {@link LocusId} associated with this notification. |
| 3519 | * |
| 3520 | * <p>This method should be called when the {@link LocusId} is used in other places (such |
| 3521 | * as {@link ShortcutInfo} and {@link ContentCaptureContext}) so the device's intelligence |
| 3522 | * services can correlate them. |
| 3523 | */ |
| 3524 | @NonNull |
| 3525 | public Builder setLocusId(@Nullable LocusId locusId) { |
| 3526 | mN.mLocusId = locusId; |
| 3527 | return this; |
| 3528 | } |
| 3529 | |
| 3530 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3531 | * Sets which icon to display as a badge for this notification. |
| 3532 | * |
| 3533 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 3534 | * {@link #BADGE_ICON_LARGE}. |
| 3535 | * |
| 3536 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 3537 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3538 | @NonNull |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 3539 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3540 | mN.mBadgeIcon = icon; |
| 3541 | return this; |
| 3542 | } |
| 3543 | |
| 3544 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3545 | * Sets the group alert behavior for this notification. Use this method to mute this |
| 3546 | * notification if alerts for this notification's group should be handled by a different |
| 3547 | * notification. This is only applicable for notifications that belong to a |
Julia Reynolds | 399d9bf | 2017-08-11 12:52:14 -0400 | [diff] [blame] | 3548 | * {@link #setGroup(String) group}. This must be called on all notifications you want to |
| 3549 | * mute. For example, if you want only the summary of your group to make noise, all |
| 3550 | * 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] | 3551 | * |
| 3552 | * <p> The default value is {@link #GROUP_ALERT_ALL}.</p> |
| 3553 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3554 | @NonNull |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3555 | public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 3556 | mN.mGroupAlertBehavior = groupAlertBehavior; |
| 3557 | return this; |
| 3558 | } |
| 3559 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3560 | /** |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3561 | * Sets the {@link BubbleMetadata} that will be used to display app content in a floating |
| 3562 | * window over the existing foreground activity. |
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 | * <p>This data will be ignored unless the notification is posted to a channel that |
| 3565 | * allows {@link NotificationChannel#canBubble() bubbles}.</p> |
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 | * <b>Notifications with a valid and allowed bubble metadata will display in collapsed state |
| 3568 | * outside of the notification shade on unlocked devices. When a user interacts with the |
| 3569 | * collapsed state, the bubble intent will be invoked and displayed.</b> |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3570 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3571 | @NonNull |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 3572 | public Builder setBubbleMetadata(@Nullable BubbleMetadata data) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 3573 | mN.mBubbleMetadata = data; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3574 | return this; |
| 3575 | } |
| 3576 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3577 | /** @removed */ |
| 3578 | @Deprecated |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3579 | public Builder setChannel(String channelId) { |
| 3580 | mN.mChannelId = channelId; |
| 3581 | return this; |
| 3582 | } |
| 3583 | |
| 3584 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3585 | * Specifies the channel the notification should be delivered on. |
| 3586 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3587 | @NonNull |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3588 | public Builder setChannelId(String channelId) { |
| 3589 | mN.mChannelId = channelId; |
| 3590 | return this; |
| 3591 | } |
| 3592 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3593 | /** @removed */ |
| 3594 | @Deprecated |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 3595 | public Builder setTimeout(long durationMs) { |
| 3596 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3597 | return this; |
| 3598 | } |
| 3599 | |
| 3600 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3601 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 3602 | * if it is not already canceled. |
| 3603 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3604 | @NonNull |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3605 | public Builder setTimeoutAfter(long durationMs) { |
| 3606 | mN.mTimeout = durationMs; |
| 3607 | return this; |
| 3608 | } |
| 3609 | |
| 3610 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3611 | * 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] | 3612 | * |
| 3613 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 3614 | * shown anymore by default and must be opted into by using |
| 3615 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3616 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3617 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3618 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3619 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3620 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3621 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3622 | return this; |
| 3623 | } |
| 3624 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3625 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 3626 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3627 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3628 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 3629 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3630 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3631 | @NonNull |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3632 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3633 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3634 | return this; |
| 3635 | } |
| 3636 | |
| 3637 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3638 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3639 | * |
| 3640 | * 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] | 3641 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3642 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3643 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 3644 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3645 | * 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] | 3646 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3647 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3648 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3649 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3650 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3651 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3652 | @NonNull |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3653 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3654 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3655 | return this; |
| 3656 | } |
| 3657 | |
| 3658 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3659 | * Sets the Chronometer to count down instead of counting up. |
| 3660 | * |
| 3661 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 3662 | * If it isn't set the chronometer will count up. |
| 3663 | * |
| 3664 | * @see #setUsesChronometer(boolean) |
| 3665 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3666 | @NonNull |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3667 | public Builder setChronometerCountDown(boolean countDown) { |
| 3668 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3669 | return this; |
| 3670 | } |
| 3671 | |
| 3672 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3673 | * Set the small icon resource, which will be used to represent the notification in the |
| 3674 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3675 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3676 | |
| 3677 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 3678 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 3679 | * icon will be moved to the right-hand side. |
| 3680 | * |
| 3681 | |
| 3682 | * @param icon |
| 3683 | * A resource ID in the application's package of the drawable to use. |
| 3684 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3685 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3686 | @NonNull |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3687 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3688 | return setSmallIcon(icon != 0 |
| 3689 | ? Icon.createWithResource(mContext, icon) |
| 3690 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3691 | } |
| 3692 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3693 | /** |
| 3694 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 3695 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 3696 | * LevelListDrawable}. |
| 3697 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3698 | * @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] | 3699 | * @param level The level to use for the icon. |
| 3700 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3701 | * @see Notification#icon |
| 3702 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3703 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3704 | @NonNull |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3705 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3706 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3707 | return setSmallIcon(icon); |
| 3708 | } |
| 3709 | |
| 3710 | /** |
| 3711 | * 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] | 3712 | * status bar and content view (unless overridden there by a |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3713 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 3714 | * |
| 3715 | * @param icon An Icon object to use. |
| 3716 | * @see Notification#icon |
| 3717 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3718 | @NonNull |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3719 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3720 | mN.setSmallIcon(icon); |
| 3721 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 3722 | mN.icon = icon.getResId(); |
| 3723 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3724 | return this; |
| 3725 | } |
| 3726 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3727 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3728 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3729 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3730 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3731 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3732 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3733 | return this; |
| 3734 | } |
| 3735 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3736 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3737 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3738 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3739 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3740 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3741 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3742 | return this; |
| 3743 | } |
| 3744 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3745 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3746 | * This provides some additional information that is displayed in the notification. No |
| 3747 | * guarantees are given where exactly it is displayed. |
| 3748 | * |
| 3749 | * <p>This information should only be provided if it provides an essential |
| 3750 | * benefit to the understanding of the notification. The more text you provide the |
| 3751 | * less readable it becomes. For example, an email client should only provide the account |
| 3752 | * name here if more than one email account has been added.</p> |
| 3753 | * |
| 3754 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 3755 | * notification header area. |
| 3756 | * |
| 3757 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 3758 | * this will be shown in the third line of text in the platform notification template. |
| 3759 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 3760 | * same time on those versions; they occupy the same place. |
| 3761 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3762 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3763 | @NonNull |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3764 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3765 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3766 | return this; |
| 3767 | } |
| 3768 | |
| 3769 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3770 | * Provides text that will appear as a link to your application's settings. |
| 3771 | * |
| 3772 | * <p>This text does not appear within notification {@link Style templates} but may |
| 3773 | * appear when the user uses an affordance to learn more about the notification. |
| 3774 | * Additionally, this text will not appear unless you provide a valid link target by |
| 3775 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 3776 | * |
| 3777 | * <p>This text is meant to be concise description about what the user can customize |
| 3778 | * when they click on this link. The recommended maximum length is 40 characters. |
| 3779 | * @param text |
| 3780 | * @return |
| 3781 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3782 | @NonNull |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3783 | public Builder setSettingsText(CharSequence text) { |
| 3784 | mN.mSettingsText = safeCharSequence(text); |
| 3785 | return this; |
| 3786 | } |
| 3787 | |
| 3788 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3789 | * Set the remote input history. |
| 3790 | * |
| 3791 | * This should be set to the most recent inputs that have been sent |
| 3792 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 3793 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 3794 | * |
| 3795 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 3796 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 3797 | * and how much of each individual input is shown. |
| 3798 | * |
| 3799 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 3800 | * with a {@code RemoteInput}.</p> |
| 3801 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3802 | @NonNull |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3803 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 3804 | if (text == null) { |
| 3805 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 3806 | } else { |
| 3807 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 3808 | CharSequence[] safe = new CharSequence[N]; |
| 3809 | for (int i = 0; i < N; i++) { |
| 3810 | safe[i] = safeCharSequence(text[i]); |
| 3811 | } |
| 3812 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 3813 | } |
| 3814 | return this; |
| 3815 | } |
| 3816 | |
| 3817 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 3818 | * Sets whether remote history entries view should have a spinner. |
| 3819 | * @hide |
| 3820 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3821 | @NonNull |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 3822 | public Builder setShowRemoteInputSpinner(boolean showSpinner) { |
| 3823 | mN.extras.putBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER, showSpinner); |
| 3824 | return this; |
| 3825 | } |
| 3826 | |
| 3827 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 3828 | * Sets whether smart reply buttons should be hidden. |
| 3829 | * @hide |
| 3830 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3831 | @NonNull |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 3832 | public Builder setHideSmartReplies(boolean hideSmartReplies) { |
| 3833 | mN.extras.putBoolean(EXTRA_HIDE_SMART_REPLIES, hideSmartReplies); |
| 3834 | return this; |
| 3835 | } |
| 3836 | |
| 3837 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3838 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 3839 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3840 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3841 | @NonNull |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3842 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3843 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3844 | return this; |
| 3845 | } |
| 3846 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3847 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3848 | * A small piece of additional information pertaining to this notification. |
| 3849 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3850 | * The platform template will draw this on the last line of the notification, at the far |
| 3851 | * 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] | 3852 | * |
| 3853 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 3854 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 3855 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3856 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3857 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3858 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3859 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3860 | return this; |
| 3861 | } |
| 3862 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3863 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3864 | * Set the progress this notification represents. |
| 3865 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3866 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3867 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3868 | @NonNull |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3869 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3870 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3871 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3872 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3873 | return this; |
| 3874 | } |
| 3875 | |
| 3876 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3877 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3878 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3879 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3880 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3881 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3882 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3883 | return setCustomContentView(views); |
| 3884 | } |
| 3885 | |
| 3886 | /** |
| 3887 | * Supply custom RemoteViews to use instead of the platform template. |
| 3888 | * |
| 3889 | * This will override the layout that would otherwise be constructed by this Builder |
| 3890 | * object. |
| 3891 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3892 | @NonNull |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3893 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3894 | mN.contentView = contentView; |
| 3895 | return this; |
| 3896 | } |
| 3897 | |
| 3898 | /** |
| 3899 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3900 | * |
| 3901 | * This will override the expanded layout that would otherwise be constructed by this |
| 3902 | * Builder object. |
| 3903 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3904 | @NonNull |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3905 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3906 | mN.bigContentView = contentView; |
| 3907 | return this; |
| 3908 | } |
| 3909 | |
| 3910 | /** |
| 3911 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3912 | * |
| 3913 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3914 | * Builder object. |
| 3915 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3916 | @NonNull |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3917 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3918 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3919 | return this; |
| 3920 | } |
| 3921 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3922 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3923 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3924 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3925 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3926 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3927 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3928 | * 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] | 3929 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3930 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3931 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3932 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3933 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3934 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3935 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3936 | return this; |
| 3937 | } |
| 3938 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3939 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3940 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3941 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3942 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3943 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3944 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3945 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3946 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3947 | return this; |
| 3948 | } |
| 3949 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3950 | /** |
| 3951 | * An intent to launch instead of posting the notification to the status bar. |
| 3952 | * Only for use with extremely high-priority notifications demanding the user's |
| 3953 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3954 | * alarm clock that the user has explicitly set to a particular time. |
| 3955 | * If this facility is used for something else, please give the user an option |
| 3956 | * to turn it off and use a normal notification, as this can be extremely |
| 3957 | * disruptive. |
| 3958 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3959 | * <p> |
| 3960 | * The system UI may choose to display a heads-up notification, instead of |
| 3961 | * launching this intent, while the user is using the device. |
| 3962 | * </p> |
Julia Reynolds | 47fd15f | 2018-11-28 10:16:00 -0500 | [diff] [blame] | 3963 | * <p>Apps targeting {@link Build.VERSION_CODES#Q} and above will have to request |
| 3964 | * a permission ({@link android.Manifest.permission#USE_FULL_SCREEN_INTENT}) in order to |
| 3965 | * use full screen intents.</p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3966 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3967 | * @param intent The pending intent to launch. |
| 3968 | * @param highPriority Passing true will cause this notification to be sent |
| 3969 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3970 | * |
| 3971 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3972 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3973 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3974 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3975 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3976 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3977 | return this; |
| 3978 | } |
| 3979 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3980 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3981 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3982 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3983 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3984 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 3985 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3986 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3987 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3988 | return this; |
| 3989 | } |
| 3990 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3991 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3992 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3996 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3997 | setTicker(tickerText); |
| 3998 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3999 | return this; |
| 4000 | } |
| 4001 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4002 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4003 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4004 | * |
| 4005 | * 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] | 4006 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 4007 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4008 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4009 | @NonNull |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4010 | public Builder setLargeIcon(Bitmap b) { |
| 4011 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 4012 | } |
| 4013 | |
| 4014 | /** |
| 4015 | * Add a large icon to the notification content view. |
| 4016 | * |
| 4017 | * In the platform template, this image will be shown on the left of the notification view |
| 4018 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 4019 | * badge atop the large icon). |
| 4020 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4021 | @NonNull |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4022 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4023 | mN.mLargeIcon = icon; |
| 4024 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4025 | return this; |
| 4026 | } |
| 4027 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4028 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4029 | * Set the sound to play. |
| 4030 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 4031 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 4032 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4033 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4034 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4035 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4036 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 4037 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4038 | mN.sound = sound; |
| 4039 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 4040 | return this; |
| 4041 | } |
| 4042 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4043 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4044 | * 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] | 4045 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4046 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 4047 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4048 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4049 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 4050 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4051 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 4052 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4053 | mN.sound = sound; |
| 4054 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4055 | return this; |
| 4056 | } |
| 4057 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4058 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 4059 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 4060 | * use during playback. |
| 4061 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4062 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 4063 | * @see Notification#sound |
| 4064 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4065 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 4066 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4067 | mN.sound = sound; |
| 4068 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 4069 | return this; |
| 4070 | } |
| 4071 | |
| 4072 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4073 | * Set the vibration pattern to use. |
| 4074 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4075 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 4076 | * <code>pattern</code> parameter. |
| 4077 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 4078 | * <p> |
| 4079 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 4080 | * </p> |
| 4081 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4082 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4083 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4084 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4085 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4086 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4087 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4088 | return this; |
| 4089 | } |
| 4090 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4091 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4092 | * Set the desired color for the indicator LED on the device, as well as the |
| 4093 | * blink duty cycle (specified in milliseconds). |
| 4094 | * |
| 4095 | |
| 4096 | * Not all devices will honor all (or even any) of these values. |
| 4097 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 4098 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4099 | * @see Notification#ledARGB |
| 4100 | * @see Notification#ledOnMS |
| 4101 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4102 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4103 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4104 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4105 | mN.ledARGB = argb; |
| 4106 | mN.ledOnMS = onMs; |
| 4107 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4108 | if (onMs != 0 || offMs != 0) { |
| 4109 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 4110 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4111 | return this; |
| 4112 | } |
| 4113 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4114 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4115 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4116 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4117 | |
| 4118 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 4119 | * must take care of canceling them. |
| 4120 | * |
| 4121 | |
| 4122 | * They are typically used to indicate a background task that the user is actively engaged |
| 4123 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 4124 | * (e.g., a file download, sync operation, active network connection). |
| 4125 | * |
| 4126 | |
| 4127 | * @see Notification#FLAG_ONGOING_EVENT |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4128 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4129 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4130 | public Builder setOngoing(boolean ongoing) { |
| 4131 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 4132 | return this; |
| 4133 | } |
| 4134 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4135 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4136 | * Set whether this notification should be colorized. When set, the color set with |
| 4137 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 4138 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4139 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 4140 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4141 | * <p> |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 4142 | * For most styles, the coloring will only be applied if the notification is for a |
| 4143 | * foreground service notification. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4144 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 4145 | * that have a media session attached there is no such requirement. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4146 | * |
Aurimas Liutikas | 7f69533 | 2018-05-31 21:07:32 -0700 | [diff] [blame] | 4147 | * @see #setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4148 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4149 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4150 | @NonNull |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4151 | public Builder setColorized(boolean colorize) { |
| 4152 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 4153 | return this; |
| 4154 | } |
| 4155 | |
| 4156 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4157 | * Set this flag if you would only like the sound, vibrate |
| 4158 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4159 | * |
| 4160 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4161 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4162 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4163 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 4164 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 4165 | return this; |
| 4166 | } |
| 4167 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4168 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4169 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4170 | * |
| 4171 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4172 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4173 | @NonNull |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4174 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 4175 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4176 | return this; |
| 4177 | } |
| 4178 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4179 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 4180 | * Set whether or not this notification should not bridge to other devices. |
| 4181 | * |
| 4182 | * <p>Some notifications can be bridged to other devices for remote display. |
| 4183 | * This hint can be set to recommend this notification not be bridged. |
| 4184 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4185 | @NonNull |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 4186 | public Builder setLocalOnly(boolean localOnly) { |
| 4187 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 4188 | return this; |
| 4189 | } |
| 4190 | |
| 4191 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4192 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4193 | * <p> |
| 4194 | * The value should be one or more of the following fields combined with |
| 4195 | * bitwise-or: |
| 4196 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 4197 | * <p> |
| 4198 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4199 | * |
| 4200 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 4201 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4202 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4203 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4204 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4205 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4206 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4207 | return this; |
| 4208 | } |
| 4209 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4210 | /** |
| 4211 | * Set the priority of this notification. |
| 4212 | * |
| 4213 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4214 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4215 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4216 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4217 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4218 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4219 | return this; |
| 4220 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4221 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4222 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4223 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4224 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4225 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4226 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4227 | @NonNull |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4228 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4229 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4230 | return this; |
| 4231 | } |
| 4232 | |
| 4233 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4234 | * Add a person that is relevant to this notification. |
| 4235 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4236 | * <P> |
| 4237 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 4238 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4239 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4240 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4241 | * </P> |
| 4242 | * |
| 4243 | * <P> |
| 4244 | * The person should be specified by the {@code String} representation of a |
| 4245 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 4246 | * </P> |
| 4247 | * |
| 4248 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 4249 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 4250 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 4251 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4252 | * It is also possible to provide a URI with the schema {@code name:} in order to uniquely |
| 4253 | * identify a person without an entry in the contacts database. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4254 | * </P> |
| 4255 | * |
| 4256 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4257 | * @see Notification#EXTRA_PEOPLE |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4258 | * @deprecated use {@link #addPerson(Person)} |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4259 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4260 | public Builder addPerson(String uri) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 4261 | addPerson(new Person.Builder().setUri(uri).build()); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4262 | return this; |
| 4263 | } |
| 4264 | |
| 4265 | /** |
| 4266 | * Add a person that is relevant to this notification. |
| 4267 | * |
| 4268 | * <P> |
| 4269 | * Depending on user preferences, this annotation may allow the notification to pass |
| 4270 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4271 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4272 | * appear more prominently in the user interface. |
| 4273 | * </P> |
| 4274 | * |
| 4275 | * <P> |
| 4276 | * A person should usually contain a uri in order to benefit from the ranking boost. |
| 4277 | * However, even if no uri is provided, it's beneficial to provide other people in the |
| 4278 | * notification, such that listeners and voice only devices can announce and handle them |
| 4279 | * properly. |
| 4280 | * </P> |
| 4281 | * |
| 4282 | * @param person the person to add. |
| 4283 | * @see Notification#EXTRA_PEOPLE_LIST |
| 4284 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4285 | @NonNull |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4286 | public Builder addPerson(Person person) { |
| 4287 | mPersonList.add(person); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4288 | return this; |
| 4289 | } |
| 4290 | |
| 4291 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4292 | * Set this notification to be part of a group of notifications sharing the same key. |
| 4293 | * Grouped notifications may display in a cluster or stack on devices which |
| 4294 | * support such rendering. |
| 4295 | * |
| 4296 | * <p>To make this notification the summary for its group, also call |
| 4297 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 4298 | * {@link #setSortKey}. |
| 4299 | * @param groupKey The group key of the group. |
| 4300 | * @return this object for method chaining |
| 4301 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4302 | @NonNull |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4303 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4304 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4305 | return this; |
| 4306 | } |
| 4307 | |
| 4308 | /** |
| 4309 | * Set this notification to be the group summary for a group of notifications. |
| 4310 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4311 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 4312 | * 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] | 4313 | * @param isGroupSummary Whether this notification should be a group summary. |
| 4314 | * @return this object for method chaining |
| 4315 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4316 | @NonNull |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4317 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 4318 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 4319 | return this; |
| 4320 | } |
| 4321 | |
| 4322 | /** |
| 4323 | * Set a sort key that orders this notification among other notifications from the |
| 4324 | * same package. This can be useful if an external sort was already applied and an app |
| 4325 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 4326 | * value, although providing different priorities in addition to providing sort key may |
| 4327 | * cause this value to be ignored. |
| 4328 | * |
| 4329 | * <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] | 4330 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4331 | * |
| 4332 | * @see String#compareTo(String) |
| 4333 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4334 | @NonNull |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4335 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4336 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4337 | return this; |
| 4338 | } |
| 4339 | |
| 4340 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4341 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4342 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4343 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 4344 | * |
| 4345 | * @see Notification#extras |
| 4346 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4347 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4348 | public Builder addExtras(Bundle extras) { |
| 4349 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4350 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4351 | } |
| 4352 | return this; |
| 4353 | } |
| 4354 | |
| 4355 | /** |
| 4356 | * Set metadata for this notification. |
| 4357 | * |
| 4358 | * <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] | 4359 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4360 | * called. |
| 4361 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4362 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 4363 | * Use {@link #addExtras} to merge in metadata instead. |
| 4364 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4365 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4366 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4367 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4368 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4369 | if (extras != null) { |
| 4370 | mUserExtras = extras; |
| 4371 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4372 | return this; |
| 4373 | } |
| 4374 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4375 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4376 | * Get the current metadata Bundle used by this notification Builder. |
| 4377 | * |
| 4378 | * <p>The returned Bundle is shared with this Builder. |
| 4379 | * |
| 4380 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 4381 | * {@link #build()} is called. |
| 4382 | * |
| 4383 | * @see Notification#extras |
| 4384 | */ |
| 4385 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4386 | return mUserExtras; |
| 4387 | } |
| 4388 | |
| 4389 | private Bundle getAllExtras() { |
| 4390 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 4391 | saveExtras.putAll(mN.extras); |
| 4392 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4396 | * Add an action to this notification. Actions are typically displayed by |
| 4397 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4398 | * <p> |
| 4399 | * Every action must have an icon (32dp square and matching the |
| 4400 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4401 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4402 | * <p> |
| 4403 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4404 | * the order they were added. Actions will not be displayed when the notification is |
| 4405 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4406 | * 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] | 4407 | * |
| 4408 | * @param icon Resource ID of a drawable that represents the action. |
| 4409 | * @param title Text describing the action. |
| 4410 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4411 | * |
| 4412 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4413 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4414 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4415 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4416 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4417 | return this; |
| 4418 | } |
| 4419 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4420 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4421 | * Add an action to this notification. Actions are typically displayed by |
| 4422 | * the system as a button adjacent to the notification content. |
| 4423 | * <p> |
| 4424 | * Every action must have an icon (32dp square and matching the |
| 4425 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4426 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4427 | * <p> |
| 4428 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4429 | * the order they were added. Actions will not be displayed when the notification is |
| 4430 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4431 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 4432 | * |
| 4433 | * @param action The action to add. |
| 4434 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4435 | @NonNull |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4436 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4437 | if (action != null) { |
| 4438 | mActions.add(action); |
| 4439 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4440 | return this; |
| 4441 | } |
| 4442 | |
| 4443 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4444 | * Alter the complete list of actions attached to this notification. |
| 4445 | * @see #addAction(Action). |
| 4446 | * |
| 4447 | * @param actions |
| 4448 | * @return |
| 4449 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4450 | @NonNull |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4451 | public Builder setActions(Action... actions) { |
| 4452 | mActions.clear(); |
| 4453 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4454 | if (actions[i] != null) { |
| 4455 | mActions.add(actions[i]); |
| 4456 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4457 | } |
| 4458 | return this; |
| 4459 | } |
| 4460 | |
| 4461 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4462 | * Add a rich notification style to be applied at build time. |
| 4463 | * |
| 4464 | * @param style Object responsible for modifying the notification style. |
| 4465 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4466 | @NonNull |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4467 | public Builder setStyle(Style style) { |
| 4468 | if (mStyle != style) { |
| 4469 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4470 | if (mStyle != null) { |
| 4471 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4472 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 4473 | } else { |
| 4474 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4475 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4476 | } |
| 4477 | return this; |
| 4478 | } |
| 4479 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4480 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 4481 | * Returns the style set by {@link #setStyle(Style)}. |
| 4482 | */ |
| 4483 | public Style getStyle() { |
| 4484 | return mStyle; |
| 4485 | } |
| 4486 | |
| 4487 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4488 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4489 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4490 | * @return The same Builder. |
| 4491 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4492 | @NonNull |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 4493 | public Builder setVisibility(@Visibility int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4494 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4495 | return this; |
| 4496 | } |
| 4497 | |
| 4498 | /** |
| 4499 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 4500 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 4501 | * @param n A replacement notification, presumably with some or all info redacted. |
| 4502 | * @return The same Builder. |
| 4503 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4504 | @NonNull |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4505 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4506 | if (n != null) { |
| 4507 | mN.publicVersion = new Notification(); |
| 4508 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 4509 | } else { |
| 4510 | mN.publicVersion = null; |
| 4511 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4512 | return this; |
| 4513 | } |
| 4514 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4515 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4516 | * Apply an extender to this notification builder. Extenders may be used to add |
| 4517 | * metadata or change options on this builder. |
| 4518 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4519 | @NonNull |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4520 | public Builder extend(Extender extender) { |
| 4521 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4522 | return this; |
| 4523 | } |
| 4524 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 4525 | /** |
| 4526 | * @hide |
| 4527 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4528 | @NonNull |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4529 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4530 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4531 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4532 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4533 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4534 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4535 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4536 | } |
| 4537 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4538 | /** |
| 4539 | * Sets {@link Notification#color}. |
| 4540 | * |
| 4541 | * @param argb The accent color to use |
| 4542 | * |
| 4543 | * @return The same Builder. |
| 4544 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 4545 | @NonNull |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4546 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4547 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4548 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4549 | return this; |
| 4550 | } |
| 4551 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4552 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 4553 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 4554 | // This user can never be a badged profile, |
| 4555 | // and also includes USER_ALL system notifications. |
| 4556 | return null; |
| 4557 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 4558 | // Note: This assumes that the current user can read the profile badge of the |
| 4559 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 4560 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4561 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | private Bitmap getProfileBadge() { |
| 4565 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4566 | if (badge == null) { |
| 4567 | return null; |
| 4568 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4569 | final int size = mContext.getResources().getDimensionPixelSize( |
| 4570 | R.dimen.notification_badge_size); |
| 4571 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4572 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4573 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4574 | badge.draw(canvas); |
| 4575 | return bitmap; |
| 4576 | } |
| 4577 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4578 | private void bindProfileBadge(RemoteViews contentView, StandardTemplateParams p) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4579 | Bitmap profileBadge = getProfileBadge(); |
| 4580 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4581 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4582 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 4583 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4584 | if (isColorized(p)) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4585 | contentView.setDrawableTint(R.id.profile_badge, false, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4586 | getPrimaryTextColor(p), PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4587 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4588 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4589 | } |
| 4590 | |
Gus Prevas | bae5ba3 | 2018-11-28 15:45:13 -0500 | [diff] [blame] | 4591 | private void bindAlertedIcon(RemoteViews contentView, StandardTemplateParams p) { |
| 4592 | contentView.setDrawableTint( |
| 4593 | R.id.alerted_icon, |
| 4594 | false /* targetBackground */, |
| 4595 | getNeutralColor(p), |
| 4596 | PorterDuff.Mode.SRC_ATOP); |
| 4597 | } |
| 4598 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4599 | /** |
| 4600 | * @hide |
| 4601 | */ |
| 4602 | public boolean usesStandardHeader() { |
| 4603 | if (mN.mUsesStandardHeader) { |
| 4604 | return true; |
| 4605 | } |
| 4606 | if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.N) { |
| 4607 | if (mN.contentView == null && mN.bigContentView == null) { |
| 4608 | return true; |
| 4609 | } |
| 4610 | } |
| 4611 | boolean contentViewUsesHeader = mN.contentView == null |
| 4612 | || STANDARD_LAYOUTS.contains(mN.contentView.getLayoutId()); |
| 4613 | boolean bigContentViewUsesHeader = mN.bigContentView == null |
| 4614 | || STANDARD_LAYOUTS.contains(mN.bigContentView.getLayoutId()); |
| 4615 | return contentViewUsesHeader && bigContentViewUsesHeader; |
| 4616 | } |
| 4617 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4618 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4619 | resetNotificationHeader(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4620 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4621 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4622 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4623 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4624 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4625 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4626 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4627 | } |
| 4628 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4629 | /** |
| 4630 | * Resets the notification header to its original state |
| 4631 | */ |
| 4632 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 4633 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 4634 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 4635 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4636 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 4637 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4638 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 4639 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4640 | contentView.setViewVisibility(R.id.header_text_secondary, View.GONE); |
| 4641 | contentView.setTextViewText(R.id.header_text_secondary, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4642 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4643 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4644 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4645 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4646 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 4647 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 4648 | contentView.setViewVisibility(R.id.alerted_icon, View.GONE); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4649 | mN.mUsesStandardHeader = false; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4650 | } |
| 4651 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4652 | private RemoteViews applyStandardTemplate(int resId, TemplateBindResult result) { |
| 4653 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this), |
| 4654 | result); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4655 | } |
| 4656 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4657 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p, |
| 4658 | TemplateBindResult result) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 4659 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 4660 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4661 | resetStandardTemplate(contentView); |
| 4662 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4663 | final Bundle ex = mN.extras; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4664 | updateBackgroundColor(contentView, p); |
| 4665 | bindNotificationHeader(contentView, p); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4666 | bindLargeIconAndReply(contentView, p, result); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4667 | boolean showProgress = handleProgressBar(contentView, ex, p); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4668 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4669 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4670 | contentView.setTextViewText(R.id.title, processTextSpans(p.title)); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4671 | setTextViewColorPrimary(contentView, R.id.title, p); |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 4672 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 4673 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 4674 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4675 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4676 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4677 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 4678 | : com.android.internal.R.id.text; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4679 | contentView.setTextViewText(textId, processTextSpans(p.text)); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4680 | setTextViewColorSecondary(contentView, textId, p); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4681 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4682 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4683 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4684 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4685 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4686 | return contentView; |
| 4687 | } |
| 4688 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4689 | private CharSequence processTextSpans(CharSequence text) { |
Lucas Dupin | d3c9932 | 2018-09-27 10:22:29 -0700 | [diff] [blame] | 4690 | if (hasForegroundColor() || mInNightMode) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4691 | return ContrastColorUtil.clearColorSpans(text); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4692 | } |
| 4693 | return text; |
| 4694 | } |
| 4695 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4696 | private void setTextViewColorPrimary(RemoteViews contentView, int id, |
| 4697 | StandardTemplateParams p) { |
| 4698 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4699 | contentView.setTextColor(id, mPrimaryTextColor); |
| 4700 | } |
| 4701 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4702 | private boolean hasForegroundColor() { |
| 4703 | return mForegroundColor != COLOR_INVALID; |
| 4704 | } |
| 4705 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4706 | /** |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4707 | * Return the primary text color using the existing template params |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4708 | * @hide |
| 4709 | */ |
| 4710 | @VisibleForTesting |
| 4711 | public int getPrimaryTextColor() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4712 | return getPrimaryTextColor(mParams); |
| 4713 | } |
| 4714 | |
| 4715 | /** |
| 4716 | * @param p the template params to inflate this with |
| 4717 | * @return the primary text color |
| 4718 | * @hide |
| 4719 | */ |
| 4720 | @VisibleForTesting |
| 4721 | public int getPrimaryTextColor(StandardTemplateParams p) { |
| 4722 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4723 | return mPrimaryTextColor; |
| 4724 | } |
| 4725 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4726 | /** |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4727 | * Return the secondary text color using the existing template params |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4728 | * @hide |
| 4729 | */ |
| 4730 | @VisibleForTesting |
| 4731 | public int getSecondaryTextColor() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4732 | return getSecondaryTextColor(mParams); |
| 4733 | } |
| 4734 | |
| 4735 | /** |
| 4736 | * @param p the template params to inflate this with |
| 4737 | * @return the secondary text color |
| 4738 | * @hide |
| 4739 | */ |
| 4740 | @VisibleForTesting |
| 4741 | public int getSecondaryTextColor(StandardTemplateParams p) { |
| 4742 | ensureColors(p); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4743 | return mSecondaryTextColor; |
| 4744 | } |
| 4745 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4746 | private void setTextViewColorSecondary(RemoteViews contentView, int id, |
| 4747 | StandardTemplateParams p) { |
| 4748 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4749 | contentView.setTextColor(id, mSecondaryTextColor); |
| 4750 | } |
| 4751 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4752 | private void ensureColors(StandardTemplateParams p) { |
| 4753 | int backgroundColor = getBackgroundColor(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4754 | if (mPrimaryTextColor == COLOR_INVALID |
| 4755 | || mSecondaryTextColor == COLOR_INVALID |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4756 | || mTextColorsAreForBackground != backgroundColor) { |
| 4757 | mTextColorsAreForBackground = backgroundColor; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4758 | if (!hasForegroundColor() || !isColorized(p)) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4759 | mPrimaryTextColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 4760 | backgroundColor, mInNightMode); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4761 | mSecondaryTextColor = ContrastColorUtil.resolveSecondaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 4762 | backgroundColor, mInNightMode); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4763 | if (backgroundColor != COLOR_DEFAULT && isColorized(p)) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4764 | mPrimaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4765 | mPrimaryTextColor, backgroundColor, 4.5); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4766 | mSecondaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4767 | mSecondaryTextColor, backgroundColor, 4.5); |
| 4768 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4769 | } else { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4770 | double backLum = ContrastColorUtil.calculateLuminance(backgroundColor); |
| 4771 | double textLum = ContrastColorUtil.calculateLuminance(mForegroundColor); |
| 4772 | double contrast = ContrastColorUtil.calculateContrast(mForegroundColor, |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4773 | backgroundColor); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4774 | // We only respect the given colors if worst case Black or White still has |
| 4775 | // contrast |
| 4776 | boolean backgroundLight = backLum > textLum |
| 4777 | && satisfiesTextContrast(backgroundColor, Color.BLACK) |
| 4778 | || backLum <= textLum |
| 4779 | && !satisfiesTextContrast(backgroundColor, Color.WHITE); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4780 | if (contrast < 4.5f) { |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4781 | if (backgroundLight) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4782 | mSecondaryTextColor = ContrastColorUtil.findContrastColor( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4783 | mForegroundColor, |
| 4784 | backgroundColor, |
| 4785 | true /* findFG */, |
| 4786 | 4.5f); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4787 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4788 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_LIGHT); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4789 | } else { |
| 4790 | mSecondaryTextColor = |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4791 | ContrastColorUtil.findContrastColorAgainstDark( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4792 | mForegroundColor, |
| 4793 | backgroundColor, |
| 4794 | true /* findFG */, |
| 4795 | 4.5f); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4796 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4797 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4798 | } |
| 4799 | } else { |
| 4800 | mPrimaryTextColor = mForegroundColor; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4801 | mSecondaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4802 | mPrimaryTextColor, backgroundLight ? LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4803 | : LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4804 | if (ContrastColorUtil.calculateContrast(mSecondaryTextColor, |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4805 | backgroundColor) < 4.5f) { |
| 4806 | // oh well the secondary is not good enough |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4807 | if (backgroundLight) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4808 | mSecondaryTextColor = ContrastColorUtil.findContrastColor( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4809 | mSecondaryTextColor, |
| 4810 | backgroundColor, |
| 4811 | true /* findFG */, |
| 4812 | 4.5f); |
| 4813 | } else { |
| 4814 | mSecondaryTextColor |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4815 | = ContrastColorUtil.findContrastColorAgainstDark( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4816 | mSecondaryTextColor, |
| 4817 | backgroundColor, |
| 4818 | true /* findFG */, |
| 4819 | 4.5f); |
| 4820 | } |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4821 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4822 | mSecondaryTextColor, backgroundLight |
| 4823 | ? -LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4824 | : -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4825 | } |
| 4826 | } |
| 4827 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4828 | } |
| 4829 | } |
| 4830 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4831 | private void updateBackgroundColor(RemoteViews contentView, |
| 4832 | StandardTemplateParams p) { |
| 4833 | if (isColorized(p)) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4834 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4835 | getBackgroundColor(p)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4836 | } else { |
| 4837 | // Clear it! |
| 4838 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 4839 | 0); |
| 4840 | } |
| 4841 | } |
| 4842 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4843 | /** |
| 4844 | * @param remoteView the remote view to update the minheight in |
| 4845 | * @param hasMinHeight does it have a mimHeight |
| 4846 | * @hide |
| 4847 | */ |
| 4848 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 4849 | int minHeight = 0; |
| 4850 | if (hasMinHeight) { |
| 4851 | // we need to set the minHeight of the notification |
| 4852 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 4853 | com.android.internal.R.dimen.notification_min_content_height); |
| 4854 | } |
| 4855 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 4856 | } |
| 4857 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4858 | private boolean handleProgressBar(RemoteViews contentView, Bundle ex, |
| 4859 | StandardTemplateParams p) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4860 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4861 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 4862 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4863 | if (p.hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4864 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4865 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4866 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4867 | contentView.setProgressBackgroundTintList( |
| 4868 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 4869 | R.color.notification_progress_background_color))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4870 | if (getRawColor(p) != COLOR_DEFAULT) { |
| 4871 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor(p)); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4872 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 4873 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4874 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4875 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4876 | } else { |
| 4877 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4878 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 4879 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4880 | } |
| 4881 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4882 | private void bindLargeIconAndReply(RemoteViews contentView, StandardTemplateParams p, |
| 4883 | TemplateBindResult result) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4884 | boolean largeIconShown = bindLargeIcon(contentView, p); |
| 4885 | boolean replyIconShown = bindReplyIcon(contentView, p); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 4886 | boolean iconContainerVisible = largeIconShown || replyIconShown; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4887 | contentView.setViewVisibility(R.id.right_icon_container, |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 4888 | iconContainerVisible ? View.VISIBLE : View.GONE); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4889 | int marginEnd = calculateMarginEnd(largeIconShown, replyIconShown); |
| 4890 | contentView.setViewLayoutMarginEnd(R.id.line1, marginEnd); |
| 4891 | contentView.setViewLayoutMarginEnd(R.id.text, marginEnd); |
| 4892 | contentView.setViewLayoutMarginEnd(R.id.progress, marginEnd); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4893 | if (result != null) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4894 | result.setIconMarginEnd(marginEnd); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 4895 | result.setRightIconContainerVisible(iconContainerVisible); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4896 | } |
| 4897 | } |
| 4898 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4899 | private int calculateMarginEnd(boolean largeIconShown, boolean replyIconShown) { |
| 4900 | int marginEnd = 0; |
| 4901 | int contentMargin = mContext.getResources().getDimensionPixelSize( |
| 4902 | R.dimen.notification_content_margin_end); |
| 4903 | int iconSize = mContext.getResources().getDimensionPixelSize( |
| 4904 | R.dimen.notification_right_icon_size); |
| 4905 | if (replyIconShown) { |
| 4906 | // The size of the reply icon |
| 4907 | marginEnd += iconSize; |
| 4908 | |
| 4909 | int replyInset = mContext.getResources().getDimensionPixelSize( |
| 4910 | R.dimen.notification_reply_inset); |
| 4911 | // We're subtracting the inset of the reply icon to make sure it's |
| 4912 | // aligned nicely on the right, and remove it from the following padding |
| 4913 | marginEnd -= replyInset * 2; |
| 4914 | } |
| 4915 | if (largeIconShown) { |
| 4916 | // adding size of the right icon |
| 4917 | marginEnd += iconSize; |
| 4918 | |
| 4919 | if (replyIconShown) { |
| 4920 | // We also add some padding to the reply icon if it's around |
| 4921 | marginEnd += contentMargin; |
| 4922 | } |
| 4923 | } |
| 4924 | if (replyIconShown || largeIconShown) { |
| 4925 | // The padding to the content |
| 4926 | marginEnd += contentMargin; |
| 4927 | } |
| 4928 | return marginEnd; |
| 4929 | } |
| 4930 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4931 | /** |
| 4932 | * Bind the large icon. |
| 4933 | * @return if the largeIcon is visible |
| 4934 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4935 | private boolean bindLargeIcon(RemoteViews contentView, StandardTemplateParams p) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4936 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 4937 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 4938 | } |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4939 | boolean showLargeIcon = mN.mLargeIcon != null && !p.hideLargeIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4940 | if (showLargeIcon) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4941 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 4942 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4943 | processLargeLegacyIcon(mN.mLargeIcon, contentView, p); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4944 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4945 | return showLargeIcon; |
| 4946 | } |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4947 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4948 | /** |
| 4949 | * Bind the reply icon. |
| 4950 | * @return if the reply icon is visible |
| 4951 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4952 | private boolean bindReplyIcon(RemoteViews contentView, StandardTemplateParams p) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4953 | boolean actionVisible = !p.hideReplyIcon; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4954 | Action action = null; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4955 | if (actionVisible) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4956 | action = findReplyAction(); |
| 4957 | actionVisible = action != null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4958 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4959 | if (actionVisible) { |
| 4960 | contentView.setViewVisibility(R.id.reply_icon_action, View.VISIBLE); |
| 4961 | contentView.setDrawableTint(R.id.reply_icon_action, |
| 4962 | false /* targetBackground */, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4963 | getNeutralColor(p), |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4964 | PorterDuff.Mode.SRC_ATOP); |
| 4965 | contentView.setOnClickPendingIntent(R.id.reply_icon_action, action.actionIntent); |
| 4966 | contentView.setRemoteInputs(R.id.reply_icon_action, action.mRemoteInputs); |
| 4967 | } else { |
| 4968 | contentView.setRemoteInputs(R.id.reply_icon_action, null); |
| 4969 | } |
| 4970 | contentView.setViewVisibility(R.id.reply_icon_action, |
| 4971 | actionVisible ? View.VISIBLE : View.GONE); |
| 4972 | return actionVisible; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | private Action findReplyAction() { |
| 4976 | ArrayList<Action> actions = mActions; |
| 4977 | if (mOriginalActions != null) { |
| 4978 | actions = mOriginalActions; |
| 4979 | } |
| 4980 | int numActions = actions.size(); |
| 4981 | for (int i = 0; i < numActions; i++) { |
| 4982 | Action action = actions.get(i); |
| 4983 | if (hasValidRemoteInput(action)) { |
| 4984 | return action; |
| 4985 | } |
| 4986 | } |
| 4987 | return null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4988 | } |
| 4989 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4990 | private void bindNotificationHeader(RemoteViews contentView, StandardTemplateParams p) { |
| 4991 | bindSmallIcon(contentView, p); |
| 4992 | bindHeaderAppName(contentView, p); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 4993 | bindHeaderText(contentView, p); |
| 4994 | bindHeaderTextSecondary(contentView, p); |
| 4995 | bindHeaderChronometerAndTime(contentView, p); |
| 4996 | bindProfileBadge(contentView, p); |
| 4997 | bindAlertedIcon(contentView, p); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4998 | bindActivePermissions(contentView, p); |
| 4999 | bindExpandButton(contentView, p); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 5000 | mN.mUsesStandardHeader = true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5001 | } |
| 5002 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5003 | private void bindActivePermissions(RemoteViews contentView, StandardTemplateParams p) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5004 | int color = getNeutralColor(p); |
Julia Reynolds | b887b23 | 2018-04-10 16:38:08 -0400 | [diff] [blame] | 5005 | contentView.setDrawableTint(R.id.camera, false, color, PorterDuff.Mode.SRC_ATOP); |
| 5006 | contentView.setDrawableTint(R.id.mic, false, color, PorterDuff.Mode.SRC_ATOP); |
| 5007 | contentView.setDrawableTint(R.id.overlay, false, color, PorterDuff.Mode.SRC_ATOP); |
| 5008 | } |
| 5009 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5010 | private void bindExpandButton(RemoteViews contentView, StandardTemplateParams p) { |
| 5011 | int color = isColorized(p) ? getPrimaryTextColor(p) : getSecondaryTextColor(p); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5012 | contentView.setDrawableTint(R.id.expand_button, false, color, |
| 5013 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5014 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5015 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5016 | } |
| 5017 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5018 | private void bindHeaderChronometerAndTime(RemoteViews contentView, |
| 5019 | StandardTemplateParams p) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5020 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5021 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5022 | setTextViewColorSecondary(contentView, R.id.time_divider, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5023 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 5024 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 5025 | contentView.setLong(R.id.chronometer, "setBase", |
| 5026 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 5027 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5028 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 5029 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5030 | setTextViewColorSecondary(contentView, R.id.chronometer, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5031 | } else { |
| 5032 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 5033 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5034 | setTextViewColorSecondary(contentView, R.id.time, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5035 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5036 | } else { |
| 5037 | // We still want a time to be set but gone, such that we can show and hide it |
| 5038 | // on demand in case it's a child notification without anything in the header |
| 5039 | 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] | 5040 | } |
| 5041 | } |
| 5042 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5043 | private void bindHeaderText(RemoteViews contentView, StandardTemplateParams p) { |
| 5044 | CharSequence summaryText = p.summaryText; |
| 5045 | if (summaryText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5046 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5047 | summaryText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5048 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5049 | if (summaryText == null |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 5050 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 5051 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5052 | summaryText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 5053 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5054 | if (summaryText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5055 | // 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] | 5056 | contentView.setTextViewText(R.id.header_text, processTextSpans( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5057 | processLegacyText(summaryText))); |
| 5058 | setTextViewColorSecondary(contentView, R.id.header_text, p); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 5059 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 5060 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5061 | setTextViewColorSecondary(contentView, R.id.header_text_divider, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5062 | } |
| 5063 | } |
| 5064 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5065 | private void bindHeaderTextSecondary(RemoteViews contentView, StandardTemplateParams p) { |
| 5066 | if (!TextUtils.isEmpty(p.headerTextSecondary)) { |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 5067 | contentView.setTextViewText(R.id.header_text_secondary, processTextSpans( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5068 | processLegacyText(p.headerTextSecondary))); |
| 5069 | setTextViewColorSecondary(contentView, R.id.header_text_secondary, p); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 5070 | contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE); |
| 5071 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5072 | setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider, p); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 5073 | } |
| 5074 | } |
| 5075 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 5076 | /** |
| 5077 | * @hide |
| 5078 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5079 | @UnsupportedAppUsage |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 5080 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 5081 | CharSequence name = null; |
| 5082 | final PackageManager pm = mContext.getPackageManager(); |
| 5083 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 5084 | // only system packages which lump together a bunch of unrelated stuff |
| 5085 | // may substitute a different name to make the purpose of the |
| 5086 | // notification more clear. the correct package label should always |
| 5087 | // be accessible via SystemUI. |
| 5088 | final String pkg = mContext.getPackageName(); |
| 5089 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 5090 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 5091 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 5092 | name = subName; |
| 5093 | } else { |
| 5094 | Log.w(TAG, "warning: pkg " |
| 5095 | + pkg + " attempting to substitute app name '" + subName |
| 5096 | + "' without holding perm " |
| 5097 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 5098 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5099 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 5100 | if (TextUtils.isEmpty(name)) { |
| 5101 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 5102 | } |
| 5103 | if (TextUtils.isEmpty(name)) { |
| 5104 | // still nothing? |
| 5105 | return null; |
| 5106 | } |
| 5107 | |
| 5108 | return String.valueOf(name); |
| 5109 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5110 | private void bindHeaderAppName(RemoteViews contentView, StandardTemplateParams p) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 5111 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5112 | if (isColorized(p)) { |
| 5113 | setTextViewColorPrimary(contentView, R.id.app_name_text, p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5114 | } else { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5115 | contentView.setTextColor(R.id.app_name_text, getSecondaryTextColor(p)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5116 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5117 | } |
| 5118 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5119 | private boolean isColorized(StandardTemplateParams p) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5120 | return p.allowColorization && mN.isColorized(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | private void bindSmallIcon(RemoteViews contentView, StandardTemplateParams p) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5124 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 5125 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 5126 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5127 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5128 | contentView.setInt(R.id.icon, "setImageLevel", mN.iconLevel); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5129 | processSmallIconColor(mN.mSmallIcon, contentView, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5130 | } |
| 5131 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5132 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5133 | * @return true if the built notification will show the time or the chronometer; false |
| 5134 | * otherwise |
| 5135 | */ |
| 5136 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5137 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5138 | } |
| 5139 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5140 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 5141 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 5142 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5143 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5144 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5145 | |
| 5146 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 5147 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5148 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, View.GONE); |
| 5149 | big.setViewVisibility(R.id.notification_material_reply_progress, View.GONE); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5150 | |
| 5151 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 5152 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 5153 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 5154 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 5155 | |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 5156 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 5157 | R.dimen.notification_content_margin); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5158 | } |
| 5159 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5160 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 5161 | TemplateBindResult result) { |
| 5162 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this), |
| 5163 | result); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5166 | private static List<Notification.Action> filterOutContextualActions( |
| 5167 | List<Notification.Action> actions) { |
| 5168 | List<Notification.Action> nonContextualActions = new ArrayList<>(); |
| 5169 | for (Notification.Action action : actions) { |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 5170 | if (!action.isContextual()) { |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5171 | nonContextualActions.add(action); |
| 5172 | } |
| 5173 | } |
| 5174 | return nonContextualActions; |
| 5175 | } |
| 5176 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 5177 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5178 | StandardTemplateParams p, TemplateBindResult result) { |
| 5179 | RemoteViews big = applyStandardTemplate(layoutId, p, result); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5180 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5181 | resetStandardTemplateWithActions(big); |
| 5182 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5183 | boolean validRemoteInput = false; |
| 5184 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5185 | // In the UI contextual actions appear separately from the standard actions, so we |
| 5186 | // filter them out here. |
| 5187 | List<Notification.Action> nonContextualActions = filterOutContextualActions(mActions); |
| 5188 | |
| 5189 | int N = nonContextualActions.size(); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5190 | boolean emphazisedMode = mN.fullScreenIntent != null; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5191 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5192 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 5193 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5194 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 5195 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5196 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5197 | for (int i=0; i<N; i++) { |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5198 | Action action = nonContextualActions.get(i); |
| 5199 | |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 5200 | boolean actionHasValidInput = hasValidRemoteInput(action); |
| 5201 | validRemoteInput |= actionHasValidInput; |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5202 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5203 | final RemoteViews button = generateActionButton(action, emphazisedMode, p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5204 | if (actionHasValidInput && !emphazisedMode) { |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 5205 | // Clear the drawable |
| 5206 | button.setInt(R.id.action0, "setBackgroundResource", 0); |
| 5207 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5208 | big.addView(R.id.actions, button); |
| 5209 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 5210 | } else { |
| 5211 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5212 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5213 | |
| 5214 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5215 | if (validRemoteInput && replyText != null |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5216 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0]) |
| 5217 | && p.maxRemoteInputHistory > 0) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5218 | boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5219 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5220 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, |
| 5221 | View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5222 | big.setTextViewText(R.id.notification_material_reply_text_1, |
| 5223 | processTextSpans(replyText[0])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5224 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1, p); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5225 | big.setViewVisibility(R.id.notification_material_reply_progress, |
| 5226 | showSpinner ? View.VISIBLE : View.GONE); |
| 5227 | big.setProgressIndeterminateTintList( |
| 5228 | R.id.notification_material_reply_progress, |
| 5229 | ColorStateList.valueOf( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5230 | isColorized(p) ? getPrimaryTextColor(p) : resolveContrastColor(p))); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5231 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5232 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1]) |
| 5233 | && p.maxRemoteInputHistory > 1) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5234 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5235 | big.setTextViewText(R.id.notification_material_reply_text_2, |
| 5236 | processTextSpans(replyText[1])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5237 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2, p); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5238 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5239 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2]) |
| 5240 | && p.maxRemoteInputHistory > 2) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5241 | big.setViewVisibility( |
| 5242 | R.id.notification_material_reply_text_3, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5243 | big.setTextViewText(R.id.notification_material_reply_text_3, |
| 5244 | processTextSpans(replyText[2])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5245 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3, p); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5246 | } |
| 5247 | } |
| 5248 | } |
| 5249 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5250 | return big; |
| 5251 | } |
| 5252 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5253 | private boolean hasValidRemoteInput(Action action) { |
| 5254 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 5255 | // Weird actions |
| 5256 | return false; |
| 5257 | } |
| 5258 | |
| 5259 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 5260 | if (remoteInputs == null) { |
| 5261 | return false; |
| 5262 | } |
| 5263 | |
| 5264 | for (RemoteInput r : remoteInputs) { |
| 5265 | CharSequence[] choices = r.getChoices(); |
| 5266 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 5267 | return true; |
| 5268 | } |
| 5269 | } |
| 5270 | return false; |
| 5271 | } |
| 5272 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5273 | /** |
| 5274 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 5275 | * 1. Custom contentView from the caller |
| 5276 | * 2. Style's proposed content view |
| 5277 | * 3. Standard template view |
| 5278 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5279 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5280 | return createContentView(false /* increasedheight */ ); |
| 5281 | } |
| 5282 | |
| 5283 | /** |
| 5284 | * Construct a RemoteViews for the smaller content view. |
| 5285 | * |
| 5286 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5287 | * styles may support showing more then just that basic 1U size |
| 5288 | * and the system may decide to render important notifications |
| 5289 | * slightly bigger even when collapsed. |
| 5290 | * |
| 5291 | * @hide |
| 5292 | */ |
| 5293 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5294 | if (mN.contentView != null && useExistingRemoteView()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5295 | return mN.contentView; |
| 5296 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5297 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5298 | if (styleView != null) { |
| 5299 | return styleView; |
| 5300 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5301 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5302 | return applyStandardTemplate(getBaseLayoutResource(), null /* result */); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5303 | } |
| 5304 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5305 | private boolean useExistingRemoteView() { |
| 5306 | return mStyle == null || (!mStyle.displayCustomViewInline() |
| 5307 | && !mRebuildStyledRemoteViews); |
| 5308 | } |
| 5309 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5310 | /** |
| 5311 | * Construct a RemoteViews for the final big notification layout. |
| 5312 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5313 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5314 | RemoteViews result = null; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5315 | if (mN.bigContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5316 | return mN.bigContentView; |
| 5317 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5318 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 5319 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5320 | } else if (mActions.size() != 0) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5321 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5322 | null /* result */); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5323 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5324 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5325 | return result; |
| 5326 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5327 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5328 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 5329 | * Construct a RemoteViews for the final notification header only. This will not be |
| 5330 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5331 | * |
| 5332 | * @hide |
| 5333 | */ |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5334 | public RemoteViews makeNotificationHeader() { |
| 5335 | return makeNotificationHeader(mParams.reset().fillTextsFrom(this)); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | /** |
| 5339 | * Construct a RemoteViews for the final notification header only. This will not be |
| 5340 | * colorized. |
| 5341 | * |
| 5342 | * @param p the template params to inflate this with |
| 5343 | */ |
| 5344 | private RemoteViews makeNotificationHeader(StandardTemplateParams p) { |
| 5345 | // Headers on their own are never colorized |
| 5346 | p.disallowColorization(); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5347 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5348 | R.layout.notification_template_header); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5349 | resetNotificationHeader(header); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5350 | bindNotificationHeader(header, p); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5351 | return header; |
| 5352 | } |
| 5353 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5354 | /** |
| 5355 | * Construct a RemoteViews for the ambient version of the notification. |
| 5356 | * |
| 5357 | * @hide |
| 5358 | */ |
| 5359 | public RemoteViews makeAmbientNotification() { |
Selim Cinek | 0e06994 | 2019-01-24 16:09:41 -0800 | [diff] [blame] | 5360 | RemoteViews headsUpContentView = createHeadsUpContentView(false /* increasedHeight */); |
| 5361 | if (headsUpContentView != null) { |
| 5362 | return headsUpContentView; |
| 5363 | } |
| 5364 | return createContentView(); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5365 | } |
| 5366 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5367 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5368 | if (result != null) { |
| 5369 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 5370 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5371 | } |
| 5372 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5373 | /** |
| 5374 | * Adapt the Notification header if this view is used as an expanded view. |
| 5375 | * |
| 5376 | * @hide |
| 5377 | */ |
| 5378 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5379 | if (result != null) { |
| 5380 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 5381 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5382 | } |
| 5383 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5384 | /** |
| 5385 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5386 | * |
| 5387 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5388 | * styles may support showing more then just that basic 1U size |
| 5389 | * and the system may decide to render important notifications |
| 5390 | * slightly bigger even when collapsed. |
| 5391 | * |
| 5392 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5393 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5394 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5395 | if (mN.headsUpContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5396 | return mN.headsUpContentView; |
| 5397 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5398 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 5399 | if (styleView != null) { |
| 5400 | return styleView; |
| 5401 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5402 | } else if (mActions.size() == 0) { |
| 5403 | return null; |
| 5404 | } |
| 5405 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5406 | // We only want at most a single remote input history to be shown here, otherwise |
| 5407 | // the content would become squished. |
| 5408 | StandardTemplateParams p = mParams.reset().fillTextsFrom(this) |
| 5409 | .setMaxRemoteInputHistory(1); |
| 5410 | return applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5411 | p, |
| 5412 | null /* result */); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5413 | } |
| 5414 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5415 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5416 | * Construct a RemoteViews for the final heads-up notification layout. |
| 5417 | */ |
| 5418 | public RemoteViews createHeadsUpContentView() { |
| 5419 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 5420 | } |
| 5421 | |
| 5422 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5423 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5424 | * |
| 5425 | * @hide |
| 5426 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5427 | @UnsupportedAppUsage |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5428 | public RemoteViews makePublicContentView() { |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5429 | return makePublicView(false /* ambient */); |
| 5430 | } |
| 5431 | |
| 5432 | /** |
| 5433 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5434 | * |
| 5435 | * @hide |
| 5436 | */ |
| 5437 | public RemoteViews makePublicAmbientNotification() { |
| 5438 | return makePublicView(true /* ambient */); |
| 5439 | } |
| 5440 | |
| 5441 | private RemoteViews makePublicView(boolean ambient) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5442 | if (mN.publicVersion != null) { |
| 5443 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5444 | return ambient ? builder.makeAmbientNotification() : builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5445 | } |
| 5446 | Bundle savedBundle = mN.extras; |
| 5447 | Style style = mStyle; |
| 5448 | mStyle = null; |
| 5449 | Icon largeIcon = mN.mLargeIcon; |
| 5450 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5451 | Bitmap largeIconLegacy = mN.largeIcon; |
| 5452 | mN.largeIcon = null; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5453 | ArrayList<Action> actions = mActions; |
| 5454 | mActions = new ArrayList<>(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5455 | Bundle publicExtras = new Bundle(); |
| 5456 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 5457 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 5458 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 5459 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5460 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 5461 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | ed07b96 | 2018-04-30 14:39:35 -0700 | [diff] [blame] | 5462 | String appName = savedBundle.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 5463 | if (appName != null) { |
| 5464 | publicExtras.putString(EXTRA_SUBSTITUTE_APP_NAME, appName); |
| 5465 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5466 | mN.extras = publicExtras; |
Selim Cinek | 499c20f | 2017-07-20 14:06:09 -0700 | [diff] [blame] | 5467 | RemoteViews view; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5468 | view = makeNotificationHeader(); |
| 5469 | view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5470 | mN.extras = savedBundle; |
| 5471 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5472 | mN.largeIcon = largeIconLegacy; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5473 | mActions = actions; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5474 | mStyle = style; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5475 | return view; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5476 | } |
| 5477 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5478 | /** |
| 5479 | * Construct a content view for the display when low - priority |
| 5480 | * |
| 5481 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 5482 | * a new subtext is created consisting of the content of the |
| 5483 | * notification. |
| 5484 | * @hide |
| 5485 | */ |
| 5486 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5487 | StandardTemplateParams p = mParams.reset() |
| 5488 | .forceDefaultColor() |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5489 | .fillTextsFrom(this); |
| 5490 | if (!useRegularSubtext || TextUtils.isEmpty(mParams.summaryText)) { |
| 5491 | p.summaryText(createSummaryText()); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5492 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5493 | RemoteViews header = makeNotificationHeader(p); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 5494 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5495 | return header; |
| 5496 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5497 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5498 | private CharSequence createSummaryText() { |
| 5499 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 5500 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 5501 | return titleText; |
| 5502 | } |
| 5503 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 5504 | if (titleText == null) { |
| 5505 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 5506 | } |
| 5507 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5508 | if (titleText != null) { |
| 5509 | summary.append(bidi.unicodeWrap(titleText)); |
| 5510 | } |
| 5511 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 5512 | if (titleText != null && contentText != null) { |
| 5513 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 5514 | R.string.notification_header_divider_symbol_with_spaces))); |
| 5515 | } |
| 5516 | if (contentText != null) { |
| 5517 | summary.append(bidi.unicodeWrap(contentText)); |
| 5518 | } |
| 5519 | return summary; |
| 5520 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5521 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5522 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5523 | StandardTemplateParams p) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5524 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 5525 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5526 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 5527 | : tombstone ? getActionTombstoneLayoutResource() |
| 5528 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5529 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5530 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5531 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5532 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5533 | if (action.mRemoteInputs != null) { |
| 5534 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 5535 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5536 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5537 | // change the background bgColor |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5538 | CharSequence title = action.title; |
| 5539 | ColorStateList[] outResultColor = null; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5540 | int background = resolveBackgroundColor(p); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5541 | if (isLegacy()) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5542 | title = ContrastColorUtil.clearColorSpans(title); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5543 | } else { |
| 5544 | outResultColor = new ColorStateList[1]; |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5545 | title = ensureColorSpanContrast(title, background, outResultColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5546 | } |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5547 | button.setTextViewText(R.id.action0, processTextSpans(title)); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5548 | setTextViewColorPrimary(button, R.id.action0, p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5549 | int rippleColor; |
| 5550 | boolean hasColorOverride = outResultColor != null && outResultColor[0] != null; |
| 5551 | if (hasColorOverride) { |
| 5552 | // There's a span spanning the full text, let's take it and use it as the |
| 5553 | // background color |
| 5554 | background = outResultColor[0].getDefaultColor(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5555 | int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5556 | background, mInNightMode); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5557 | button.setTextColor(R.id.action0, textColor); |
| 5558 | rippleColor = textColor; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5559 | } else if (getRawColor(p) != COLOR_DEFAULT && !isColorized(p) |
| 5560 | && mTintActionButtons) { |
| 5561 | rippleColor = resolveContrastColor(p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5562 | button.setTextColor(R.id.action0, rippleColor); |
| 5563 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5564 | rippleColor = getPrimaryTextColor(p); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5565 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5566 | // We only want about 20% alpha for the ripple |
| 5567 | rippleColor = (rippleColor & 0x00ffffff) | 0x33000000; |
| 5568 | button.setColorStateList(R.id.action0, "setRippleColor", |
| 5569 | ColorStateList.valueOf(rippleColor)); |
| 5570 | button.setColorStateList(R.id.action0, "setButtonBackground", |
| 5571 | ColorStateList.valueOf(background)); |
| 5572 | button.setBoolean(R.id.action0, "setHasStroke", !hasColorOverride); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5573 | } else { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5574 | button.setTextViewText(R.id.action0, processTextSpans( |
| 5575 | processLegacyText(action.title))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5576 | if (isColorized(p)) { |
| 5577 | setTextViewColorPrimary(button, R.id.action0, p); |
| 5578 | } else if (getRawColor(p) != COLOR_DEFAULT && mTintActionButtons) { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5579 | button.setTextColor(R.id.action0, resolveContrastColor(p)); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5580 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5581 | } |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 5582 | button.setIntTag(R.id.action0, R.id.notification_action_index_tag, |
| 5583 | mActions.indexOf(action)); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5584 | return button; |
| 5585 | } |
| 5586 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5587 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5588 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 5589 | * text if a span was found that spans over the whole text. |
| 5590 | * |
| 5591 | * @param charSequence the charSequence on which the spans are |
| 5592 | * @param background the background color to ensure the contrast against |
| 5593 | * @param outResultColor an array in which a color will be returned as the first element if |
| 5594 | * there exists a full length color span. |
| 5595 | * @return the contrasted charSequence |
| 5596 | */ |
| 5597 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 5598 | ColorStateList[] outResultColor) { |
| 5599 | if (charSequence instanceof Spanned) { |
| 5600 | Spanned ss = (Spanned) charSequence; |
| 5601 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 5602 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 5603 | for (Object span : spans) { |
| 5604 | Object resultSpan = span; |
| 5605 | int spanStart = ss.getSpanStart(span); |
| 5606 | int spanEnd = ss.getSpanEnd(span); |
| 5607 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 5608 | if (resultSpan instanceof CharacterStyle) { |
| 5609 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 5610 | } |
| 5611 | if (resultSpan instanceof TextAppearanceSpan) { |
| 5612 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 5613 | ColorStateList textColor = originalSpan.getTextColor(); |
| 5614 | if (textColor != null) { |
| 5615 | int[] colors = textColor.getColors(); |
| 5616 | int[] newColors = new int[colors.length]; |
| 5617 | for (int i = 0; i < newColors.length; i++) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5618 | newColors[i] = ContrastColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5619 | colors[i], background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5620 | } |
| 5621 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 5622 | newColors); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5623 | if (fullLength) { |
| 5624 | outResultColor[0] = textColor; |
| 5625 | // Let's drop the color from the span |
| 5626 | textColor = null; |
| 5627 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5628 | resultSpan = new TextAppearanceSpan( |
| 5629 | originalSpan.getFamily(), |
| 5630 | originalSpan.getTextStyle(), |
| 5631 | originalSpan.getTextSize(), |
| 5632 | textColor, |
| 5633 | originalSpan.getLinkTextColor()); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5634 | } |
| 5635 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 5636 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 5637 | int foregroundColor = originalSpan.getForegroundColor(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5638 | foregroundColor = ContrastColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5639 | foregroundColor, background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5640 | if (fullLength) { |
| 5641 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5642 | resultSpan = null; |
| 5643 | } else { |
| 5644 | resultSpan = new ForegroundColorSpan(foregroundColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5645 | } |
| 5646 | } else { |
| 5647 | resultSpan = span; |
| 5648 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5649 | if (resultSpan != null) { |
| 5650 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 5651 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5652 | } |
| 5653 | return builder; |
| 5654 | } |
| 5655 | return charSequence; |
| 5656 | } |
| 5657 | |
| 5658 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5659 | * @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] | 5660 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5661 | */ |
| 5662 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5663 | if (!mIsLegacyInitialized) { |
| 5664 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 5665 | < Build.VERSION_CODES.LOLLIPOP; |
| 5666 | mIsLegacyInitialized = true; |
| 5667 | } |
| 5668 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5669 | } |
| 5670 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5671 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 5672 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5673 | if (isAlreadyLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5674 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5675 | } else { |
| 5676 | return charSequence; |
| 5677 | } |
| 5678 | } |
| 5679 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5680 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5681 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5682 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5683 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5684 | StandardTemplateParams p) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5685 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5686 | int color; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 5687 | if (isColorized(p)) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5688 | color = getPrimaryTextColor(p); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5689 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5690 | color = resolveContrastColor(p); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5691 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5692 | if (colorable) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5693 | contentView.setDrawableTint(R.id.icon, false, color, |
| 5694 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5695 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5696 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5697 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5698 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5699 | } |
| 5700 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5701 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5702 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5703 | * if it's grayscale). |
| 5704 | */ |
| 5705 | // TODO: also check bounds, transparency, that sort of thing. |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5706 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView, |
| 5707 | StandardTemplateParams p) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5708 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5709 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5710 | // resolve color will fall back to the default when legacy |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5711 | contentView.setDrawableTint(R.id.icon, false, resolveContrastColor(p), |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5712 | PorterDuff.Mode.SRC_ATOP); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 5713 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5714 | } |
| 5715 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 5716 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5717 | if (mN.color != COLOR_DEFAULT) { |
| 5718 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5719 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5720 | } |
| 5721 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5722 | int resolveContrastColor(StandardTemplateParams p) { |
| 5723 | int rawColor = getRawColor(p); |
| 5724 | if (mCachedContrastColorIsFor == rawColor && mCachedContrastColor != COLOR_INVALID) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5725 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5726 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5727 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5728 | int color; |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5729 | int background = mContext.getColor( |
| 5730 | com.android.internal.R.color.notification_material_background_color); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5731 | if (rawColor == COLOR_DEFAULT) { |
| 5732 | ensureColors(p); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5733 | color = ContrastColorUtil.resolveDefaultColor(mContext, background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5734 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5735 | color = ContrastColorUtil.resolveContrastColor(mContext, rawColor, |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5736 | background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5737 | } |
| 5738 | if (Color.alpha(color) < 255) { |
| 5739 | // 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] | 5740 | color = ContrastColorUtil.compositeColors(color, background); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5741 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5742 | mCachedContrastColorIsFor = rawColor; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5743 | return mCachedContrastColor = color; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5744 | } |
| 5745 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5746 | /** |
| 5747 | * Return the raw color of this Notification, which doesn't necessarily satisfy contrast. |
| 5748 | * |
| 5749 | * @see #resolveContrastColor(StandardTemplateParams) for the contrasted color |
| 5750 | * @param p the template params to inflate this with |
| 5751 | */ |
| 5752 | private int getRawColor(StandardTemplateParams p) { |
| 5753 | if (p.forceDefaultColor) { |
| 5754 | return COLOR_DEFAULT; |
| 5755 | } |
| 5756 | return mN.color; |
| 5757 | } |
| 5758 | |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5759 | int resolveNeutralColor() { |
| 5760 | if (mNeutralColor != COLOR_INVALID) { |
| 5761 | return mNeutralColor; |
| 5762 | } |
| 5763 | int background = mContext.getColor( |
| 5764 | com.android.internal.R.color.notification_material_background_color); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5765 | mNeutralColor = ContrastColorUtil.resolveDefaultColor(mContext, background, |
| 5766 | mInNightMode); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5767 | if (Color.alpha(mNeutralColor) < 255) { |
| 5768 | // 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] | 5769 | mNeutralColor = ContrastColorUtil.compositeColors(mNeutralColor, background); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5770 | } |
| 5771 | return mNeutralColor; |
| 5772 | } |
| 5773 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5774 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5775 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5776 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5777 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 5778 | @NonNull |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5779 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5780 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5781 | mN.actions = new Action[mActions.size()]; |
| 5782 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5783 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5784 | if (!mPersonList.isEmpty()) { |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 5785 | mN.extras.putParcelableArrayList(EXTRA_PEOPLE_LIST, mPersonList); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 5786 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5787 | if (mN.bigContentView != null || mN.contentView != null |
| 5788 | || mN.headsUpContentView != null) { |
| 5789 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 5790 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5791 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5792 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5793 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5794 | /** |
| 5795 | * Creates a Builder from an existing notification so further changes can be made. |
| 5796 | * @param context The context for your application / activity. |
| 5797 | * @param n The notification to create a Builder from. |
| 5798 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 5799 | @NonNull |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5800 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5801 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5802 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 5803 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5804 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5805 | if (applicationInfo != null) { |
| 5806 | try { |
| 5807 | builderContext = context.createApplicationContext(applicationInfo, |
| 5808 | Context.CONTEXT_RESTRICTED); |
| 5809 | } catch (NameNotFoundException e) { |
| 5810 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 5811 | builderContext = context; // try with our context |
| 5812 | } |
| 5813 | } else { |
| 5814 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5815 | } |
| 5816 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5817 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5818 | } |
| 5819 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5820 | /** |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 5821 | * Determines whether the platform can generate contextual actions for a notification. |
| 5822 | * By default this is true. |
| 5823 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 5824 | @NonNull |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 5825 | public Builder setAllowSystemGeneratedContextualActions(boolean allowed) { |
| 5826 | mN.mAllowSystemGeneratedContextualActions = allowed; |
| 5827 | return this; |
| 5828 | } |
| 5829 | |
| 5830 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5831 | * @deprecated Use {@link #build()} instead. |
| 5832 | */ |
| 5833 | @Deprecated |
| 5834 | public Notification getNotification() { |
| 5835 | return build(); |
| 5836 | } |
| 5837 | |
| 5838 | /** |
| 5839 | * Combine all of the options that have been set and return a new {@link Notification} |
| 5840 | * object. |
| 5841 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 5842 | @NonNull |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5843 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5844 | // first, add any extras from the calling code |
| 5845 | if (mUserExtras != null) { |
| 5846 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5847 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5848 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5849 | mN.creationTime = System.currentTimeMillis(); |
| 5850 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5851 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5852 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 5853 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5854 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5855 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5856 | if (mStyle != null) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5857 | mStyle.reduceImageSizes(mContext); |
| 5858 | mStyle.purgeResources(); |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 5859 | mStyle.validate(mContext); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5860 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5861 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5862 | mN.reduceImageSizes(mContext); |
| 5863 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5864 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5865 | && (useExistingRemoteView())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5866 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5867 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5868 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 5869 | mN.contentView.getSequenceNumber()); |
| 5870 | } |
| 5871 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5872 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5873 | if (mN.bigContentView != null) { |
| 5874 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 5875 | mN.bigContentView.getSequenceNumber()); |
| 5876 | } |
| 5877 | } |
| 5878 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5879 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5880 | if (mN.headsUpContentView != null) { |
| 5881 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 5882 | mN.headsUpContentView.getSequenceNumber()); |
| 5883 | } |
| 5884 | } |
| 5885 | } |
| 5886 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 5887 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 5888 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 5889 | } |
| 5890 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 5891 | mN.allPendingIntents = null; |
| 5892 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5893 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5894 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5895 | |
| 5896 | /** |
| 5897 | * Apply this Builder to an existing {@link Notification} object. |
| 5898 | * |
| 5899 | * @hide |
| 5900 | */ |
Gustav Sennton | 625bcab | 2019-02-28 18:17:38 +0000 | [diff] [blame] | 5901 | @NonNull |
| 5902 | public Notification buildInto(@NonNull Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 5903 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5904 | return n; |
| 5905 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5906 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5907 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5908 | * 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] | 5909 | * change. Also removes extenders on low ram devices, as |
| 5910 | * {@link android.service.notification.NotificationListenerService} services are disabled. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5911 | * |
| 5912 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 5913 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5914 | * @hide |
| 5915 | */ |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5916 | public static Notification maybeCloneStrippedForDelivery(Notification n, boolean isLowRam, |
| 5917 | Context context) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5918 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5919 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5920 | // Only strip views for known Styles because we won't know how to |
| 5921 | // re-create them otherwise. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5922 | if (!isLowRam |
| 5923 | && !TextUtils.isEmpty(templateClass) |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5924 | && getNotificationStyleClass(templateClass) == null) { |
| 5925 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5926 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5927 | |
| 5928 | // Only strip unmodified BuilderRemoteViews. |
| 5929 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5930 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5931 | n.contentView.getSequenceNumber(); |
| 5932 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5933 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5934 | n.bigContentView.getSequenceNumber(); |
| 5935 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5936 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5937 | n.headsUpContentView.getSequenceNumber(); |
| 5938 | |
| 5939 | // Nothing to do here, no need to clone. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5940 | if (!isLowRam |
| 5941 | && !stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5942 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5943 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5944 | |
| 5945 | Notification clone = n.clone(); |
| 5946 | if (stripContentView) { |
| 5947 | clone.contentView = null; |
| 5948 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 5949 | } |
| 5950 | if (stripBigContentView) { |
| 5951 | clone.bigContentView = null; |
| 5952 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 5953 | } |
| 5954 | if (stripHeadsUpContentView) { |
| 5955 | clone.headsUpContentView = null; |
| 5956 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 5957 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5958 | if (isLowRam) { |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5959 | String[] allowedServices = context.getResources().getStringArray( |
| 5960 | R.array.config_allowedManagedServicesOnLowRamDevices); |
| 5961 | if (allowedServices.length == 0) { |
| 5962 | clone.extras.remove(Notification.TvExtender.EXTRA_TV_EXTENDER); |
| 5963 | clone.extras.remove(WearableExtender.EXTRA_WEARABLE_EXTENSIONS); |
| 5964 | clone.extras.remove(CarExtender.EXTRA_CAR_EXTENDER); |
| 5965 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5966 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5967 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5968 | } |
| 5969 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5970 | @UnsupportedAppUsage |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5971 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5972 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5973 | } |
| 5974 | |
| 5975 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5976 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5977 | } |
| 5978 | |
| 5979 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5980 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5981 | } |
| 5982 | |
| 5983 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5984 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5985 | } |
| 5986 | |
| 5987 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5988 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5989 | } |
| 5990 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5991 | private int getMessagingLayoutResource() { |
| 5992 | return R.layout.notification_template_material_messaging; |
| 5993 | } |
| 5994 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5995 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5996 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5997 | } |
| 5998 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5999 | private int getEmphasizedActionLayoutResource() { |
| 6000 | return R.layout.notification_material_action_emphasized; |
| 6001 | } |
| 6002 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 6003 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 6004 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 6005 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6006 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6007 | private int getBackgroundColor(StandardTemplateParams p) { |
| 6008 | if (isColorized(p)) { |
| 6009 | return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : getRawColor(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6010 | } else { |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 6011 | return COLOR_DEFAULT; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6012 | } |
| 6013 | } |
| 6014 | |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 6015 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 6016 | * 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] | 6017 | * @param p the template params to inflate this with |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 6018 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6019 | private int getNeutralColor(StandardTemplateParams p) { |
| 6020 | if (isColorized(p)) { |
| 6021 | return getSecondaryTextColor(p); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 6022 | } else { |
| 6023 | return resolveNeutralColor(); |
| 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | /** |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 6028 | * Same as getBackgroundColor but also resolved the default color to the background. |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6029 | * @param p the template params to inflate this with |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 6030 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6031 | private int resolveBackgroundColor(StandardTemplateParams p) { |
| 6032 | int backgroundColor = getBackgroundColor(p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 6033 | if (backgroundColor == COLOR_DEFAULT) { |
| 6034 | backgroundColor = mContext.getColor( |
| 6035 | com.android.internal.R.color.notification_material_background_color); |
| 6036 | } |
| 6037 | return backgroundColor; |
| 6038 | } |
| 6039 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 6040 | private boolean shouldTintActionButtons() { |
| 6041 | return mTintActionButtons; |
| 6042 | } |
| 6043 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6044 | private boolean textColorsNeedInversion() { |
| 6045 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 6046 | return false; |
| 6047 | } |
| 6048 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 6049 | return targetSdkVersion > Build.VERSION_CODES.M |
| 6050 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 6051 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6052 | |
| 6053 | /** |
| 6054 | * Set a color palette to be used as the background and textColors |
| 6055 | * |
| 6056 | * @param backgroundColor the color to be used as the background |
| 6057 | * @param foregroundColor the color to be used as the foreground |
| 6058 | * |
| 6059 | * @hide |
| 6060 | */ |
| 6061 | public void setColorPalette(int backgroundColor, int foregroundColor) { |
| 6062 | mBackgroundColor = backgroundColor; |
| 6063 | mForegroundColor = foregroundColor; |
| 6064 | mTextColorsAreForBackground = COLOR_INVALID; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6065 | ensureColors(mParams.reset().fillTextsFrom(this)); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6066 | } |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 6067 | |
| 6068 | /** |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 6069 | * Forces all styled remoteViews to be built from scratch and not use any cached |
| 6070 | * RemoteViews. |
| 6071 | * This is needed for legacy apps that are baking in their remoteviews into the |
| 6072 | * notification. |
| 6073 | * |
| 6074 | * @hide |
| 6075 | */ |
| 6076 | public void setRebuildStyledRemoteViews(boolean rebuild) { |
| 6077 | mRebuildStyledRemoteViews = rebuild; |
| 6078 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6079 | |
| 6080 | /** |
| 6081 | * Get the text that should be displayed in the statusBar when heads upped. This is |
| 6082 | * usually just the app name, but may be different depending on the style. |
| 6083 | * |
| 6084 | * @param publicMode If true, return a text that is safe to display in public. |
| 6085 | * |
| 6086 | * @hide |
| 6087 | */ |
| 6088 | public CharSequence getHeadsUpStatusBarText(boolean publicMode) { |
| 6089 | if (mStyle != null && !publicMode) { |
| 6090 | CharSequence text = mStyle.getHeadsUpStatusBarText(); |
| 6091 | if (!TextUtils.isEmpty(text)) { |
| 6092 | return text; |
| 6093 | } |
| 6094 | } |
| 6095 | return loadHeaderAppName(); |
| 6096 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6100 | * Reduces the image sizes to conform to a maximum allowed size. This also processes all custom |
| 6101 | * remote views. |
| 6102 | * |
| 6103 | * @hide |
| 6104 | */ |
| 6105 | void reduceImageSizes(Context context) { |
| 6106 | if (extras.getBoolean(EXTRA_REDUCED_IMAGES)) { |
| 6107 | return; |
| 6108 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6109 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6110 | if (mLargeIcon != null || largeIcon != null) { |
| 6111 | Resources resources = context.getResources(); |
| 6112 | Class<? extends Style> style = getNotificationStyle(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6113 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6114 | ? R.dimen.notification_right_icon_size_low_ram |
| 6115 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6116 | int maxHeight = maxWidth; |
| 6117 | if (MediaStyle.class.equals(style) |
| 6118 | || DecoratedMediaCustomViewStyle.class.equals(style)) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6119 | maxHeight = resources.getDimensionPixelSize(isLowRam |
| 6120 | ? R.dimen.notification_media_image_max_height_low_ram |
| 6121 | : R.dimen.notification_media_image_max_height); |
| 6122 | maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6123 | ? R.dimen.notification_media_image_max_width_low_ram |
| 6124 | : R.dimen.notification_media_image_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6125 | } |
| 6126 | if (mLargeIcon != null) { |
| 6127 | mLargeIcon.scaleDownIfNecessary(maxWidth, maxHeight); |
| 6128 | } |
| 6129 | if (largeIcon != null) { |
| 6130 | largeIcon = Icon.scaleDownIfNecessary(largeIcon, maxWidth, maxHeight); |
| 6131 | } |
| 6132 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6133 | reduceImageSizesForRemoteView(contentView, context, isLowRam); |
| 6134 | reduceImageSizesForRemoteView(headsUpContentView, context, isLowRam); |
| 6135 | reduceImageSizesForRemoteView(bigContentView, context, isLowRam); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6136 | extras.putBoolean(EXTRA_REDUCED_IMAGES, true); |
| 6137 | } |
| 6138 | |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6139 | private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context, |
| 6140 | boolean isLowRam) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6141 | if (remoteView != null) { |
| 6142 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6143 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6144 | ? R.dimen.notification_custom_view_max_image_width_low_ram |
| 6145 | : R.dimen.notification_custom_view_max_image_width); |
| 6146 | int maxHeight = resources.getDimensionPixelSize(isLowRam |
| 6147 | ? R.dimen.notification_custom_view_max_image_height_low_ram |
| 6148 | : R.dimen.notification_custom_view_max_image_height); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6149 | remoteView.reduceImageSizes(maxWidth, maxHeight); |
| 6150 | } |
| 6151 | } |
| 6152 | |
| 6153 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6154 | * @return whether this notification is a foreground service notification |
Gus Prevas | b0c1a46 | 2018-11-05 11:06:15 -0500 | [diff] [blame] | 6155 | * @hide |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6156 | */ |
Gus Prevas | b0c1a46 | 2018-11-05 11:06:15 -0500 | [diff] [blame] | 6157 | public boolean isForegroundService() { |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6158 | return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6159 | } |
| 6160 | |
| 6161 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6162 | * @return whether this notification has a media session attached |
| 6163 | * @hide |
| 6164 | */ |
| 6165 | public boolean hasMediaSession() { |
| 6166 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 6167 | } |
| 6168 | |
| 6169 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6170 | * @return the style class of this notification |
| 6171 | * @hide |
| 6172 | */ |
| 6173 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 6174 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 6175 | |
| 6176 | if (!TextUtils.isEmpty(templateClass)) { |
| 6177 | return Notification.getNotificationStyleClass(templateClass); |
| 6178 | } |
| 6179 | return null; |
| 6180 | } |
| 6181 | |
| 6182 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6183 | * @return true if this notification is colorized. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6184 | * |
| 6185 | * @hide |
| 6186 | */ |
| 6187 | public boolean isColorized() { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6188 | if (isColorizedMedia()) { |
| 6189 | return true; |
| 6190 | } |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 6191 | return extras.getBoolean(EXTRA_COLORIZED) |
| 6192 | && (hasColorizedPermission() || isForegroundService()); |
| 6193 | } |
| 6194 | |
| 6195 | /** |
| 6196 | * Returns whether an app can colorize due to the android.permission.USE_COLORIZED_NOTIFICATIONS |
| 6197 | * permission. The permission is checked when a notification is enqueued. |
| 6198 | */ |
| 6199 | private boolean hasColorizedPermission() { |
| 6200 | return (flags & Notification.FLAG_CAN_COLORIZE) != 0; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | /** |
| 6204 | * @return true if this notification is colorized and it is a media notification |
| 6205 | * |
| 6206 | * @hide |
| 6207 | */ |
| 6208 | public boolean isColorizedMedia() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6209 | Class<? extends Style> style = getNotificationStyle(); |
| 6210 | if (MediaStyle.class.equals(style)) { |
| 6211 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 6212 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 6213 | return true; |
| 6214 | } |
| 6215 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 6216 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 6217 | return true; |
| 6218 | } |
| 6219 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6220 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6221 | } |
| 6222 | |
Selim Cinek | 0847acd | 2017-04-24 19:48:29 -0700 | [diff] [blame] | 6223 | |
| 6224 | /** |
| 6225 | * @return true if this is a media notification |
| 6226 | * |
| 6227 | * @hide |
| 6228 | */ |
| 6229 | public boolean isMediaNotification() { |
| 6230 | Class<? extends Style> style = getNotificationStyle(); |
| 6231 | if (MediaStyle.class.equals(style)) { |
| 6232 | return true; |
| 6233 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 6234 | return true; |
| 6235 | } |
| 6236 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6237 | } |
| 6238 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6239 | private boolean hasLargeIcon() { |
| 6240 | return mLargeIcon != null || largeIcon != null; |
| 6241 | } |
| 6242 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6243 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6244 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 6245 | * @hide |
| 6246 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6247 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 6248 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 6249 | } |
| 6250 | |
| 6251 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6252 | * @return true if the notification will show a chronometer; false otherwise |
| 6253 | * @hide |
| 6254 | */ |
| 6255 | public boolean showsChronometer() { |
| 6256 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 6257 | } |
| 6258 | |
| 6259 | /** |
Julia Reynolds | 7ca3307 | 2017-06-29 13:58:24 -0400 | [diff] [blame] | 6260 | * @removed |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 6261 | */ |
| 6262 | @SystemApi |
| 6263 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 6264 | Class<? extends Style>[] classes = new Class[] { |
| 6265 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 6266 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 6267 | MessagingStyle.class }; |
| 6268 | for (Class<? extends Style> innerClass : classes) { |
| 6269 | if (templateClass.equals(innerClass.getName())) { |
| 6270 | return innerClass; |
| 6271 | } |
| 6272 | } |
| 6273 | return null; |
| 6274 | } |
| 6275 | |
| 6276 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6277 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 6278 | * object. |
| 6279 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 6280 | public static abstract class Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 6281 | |
| 6282 | /** |
| 6283 | * The number of items allowed simulatanously in the remote input history. |
| 6284 | * @hide |
| 6285 | */ |
| 6286 | static final int MAX_REMOTE_INPUT_HISTORY_LINES = 3; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6287 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6288 | |
| 6289 | /** |
| 6290 | * @hide |
| 6291 | */ |
| 6292 | protected CharSequence mSummaryText = null; |
| 6293 | |
| 6294 | /** |
| 6295 | * @hide |
| 6296 | */ |
| 6297 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6298 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6299 | protected Builder mBuilder; |
| 6300 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6301 | /** |
| 6302 | * Overrides ContentTitle in the big form of the template. |
| 6303 | * This defaults to the value passed to setContentTitle(). |
| 6304 | */ |
| 6305 | protected void internalSetBigContentTitle(CharSequence title) { |
| 6306 | mBigContentTitle = title; |
| 6307 | } |
| 6308 | |
| 6309 | /** |
| 6310 | * Set the first line of text after the detail section in the big form of the template. |
| 6311 | */ |
| 6312 | protected void internalSetSummaryText(CharSequence cs) { |
| 6313 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 6314 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6315 | } |
| 6316 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6317 | public void setBuilder(Builder builder) { |
| 6318 | if (mBuilder != builder) { |
| 6319 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 6320 | if (mBuilder != null) { |
| 6321 | mBuilder.setStyle(this); |
| 6322 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6323 | } |
| 6324 | } |
| 6325 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6326 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6327 | if (mBuilder == null) { |
| 6328 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 6329 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6330 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6331 | |
| 6332 | protected RemoteViews getStandardView(int layoutId) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6333 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder); |
| 6334 | return getStandardView(layoutId, p, null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6335 | } |
| 6336 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6337 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6338 | /** |
| 6339 | * Get the standard view for this style. |
| 6340 | * |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6341 | * @param layoutId The layout id to use. |
| 6342 | * @param p the params for this inflation. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6343 | * @param result The result where template bind information is saved. |
| 6344 | * @return A remoteView for this style. |
| 6345 | * @hide |
| 6346 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6347 | protected RemoteViews getStandardView(int layoutId, StandardTemplateParams p, |
| 6348 | TemplateBindResult result) { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6349 | checkBuilder(); |
| 6350 | |
| 6351 | if (mBigContentTitle != null) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6352 | p.title = mBigContentTitle; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6353 | } |
| 6354 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6355 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId, p, |
| 6356 | result); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6357 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6358 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 6359 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 6360 | } else { |
| 6361 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6362 | } |
| 6363 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6364 | return contentView; |
| 6365 | } |
| 6366 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6367 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6368 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6369 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6370 | * |
| 6371 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6372 | * @hide |
| 6373 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6374 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6375 | return null; |
| 6376 | } |
| 6377 | |
| 6378 | /** |
| 6379 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 6380 | * @hide |
| 6381 | */ |
| 6382 | public RemoteViews makeBigContentView() { |
| 6383 | return null; |
| 6384 | } |
| 6385 | |
| 6386 | /** |
| 6387 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6388 | * |
| 6389 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6390 | * @hide |
| 6391 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6392 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6393 | return null; |
| 6394 | } |
| 6395 | |
| 6396 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6397 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6398 | * @hide |
| 6399 | */ |
| 6400 | public void addExtras(Bundle extras) { |
| 6401 | if (mSummaryTextSet) { |
| 6402 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 6403 | } |
| 6404 | if (mBigContentTitle != null) { |
| 6405 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 6406 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 6407 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6408 | } |
| 6409 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6410 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6411 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6412 | * @hide |
| 6413 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6414 | protected void restoreFromExtras(Bundle extras) { |
| 6415 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 6416 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 6417 | mSummaryTextSet = true; |
| 6418 | } |
| 6419 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 6420 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | |
| 6425 | /** |
| 6426 | * @hide |
| 6427 | */ |
| 6428 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6429 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6430 | return wip; |
| 6431 | } |
| 6432 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6433 | /** |
| 6434 | * @hide |
| 6435 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6436 | public void purgeResources() {} |
| 6437 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6438 | /** |
| 6439 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 6440 | * attached to. |
| 6441 | * |
| 6442 | * @return the fully constructed Notification. |
| 6443 | */ |
| 6444 | public Notification build() { |
| 6445 | checkBuilder(); |
| 6446 | return mBuilder.build(); |
| 6447 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6448 | |
| 6449 | /** |
| 6450 | * @hide |
| 6451 | * @return true if the style positions the progress bar on the second line; false if the |
| 6452 | * style hides the progress bar |
| 6453 | */ |
| 6454 | protected boolean hasProgress() { |
| 6455 | return true; |
| 6456 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6457 | |
| 6458 | /** |
| 6459 | * @hide |
| 6460 | * @return Whether we should put the summary be put into the notification header |
| 6461 | */ |
| 6462 | public boolean hasSummaryInHeader() { |
| 6463 | return true; |
| 6464 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6465 | |
| 6466 | /** |
| 6467 | * @hide |
| 6468 | * @return Whether custom content views are displayed inline in the style |
| 6469 | */ |
| 6470 | public boolean displayCustomViewInline() { |
| 6471 | return false; |
| 6472 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6473 | |
| 6474 | /** |
| 6475 | * Reduces the image sizes contained in this style. |
| 6476 | * |
| 6477 | * @hide |
| 6478 | */ |
| 6479 | public void reduceImageSizes(Context context) { |
| 6480 | } |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6481 | |
| 6482 | /** |
| 6483 | * Validate that this style was properly composed. This is called at build time. |
| 6484 | * @hide |
| 6485 | */ |
| 6486 | public void validate(Context context) { |
| 6487 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6488 | |
| 6489 | /** |
| 6490 | * @hide |
| 6491 | */ |
| 6492 | public abstract boolean areNotificationsVisiblyDifferent(Style other); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 6493 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6494 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6495 | * @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] | 6496 | * If {@code null} is returned, the default implementation will be used. |
| 6497 | * |
| 6498 | * @hide |
| 6499 | */ |
| 6500 | public CharSequence getHeadsUpStatusBarText() { |
| 6501 | return null; |
| 6502 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 6503 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6504 | |
| 6505 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6506 | * 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] | 6507 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6508 | * 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] | 6509 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6510 | * Notification notif = new Notification.Builder(mContext) |
| 6511 | * .setContentTitle("New photo from " + sender.toString()) |
| 6512 | * .setContentText(subject) |
| 6513 | * .setSmallIcon(R.drawable.new_post) |
| 6514 | * .setLargeIcon(aBitmap) |
| 6515 | * .setStyle(new Notification.BigPictureStyle() |
| 6516 | * .bigPicture(aBigBitmap)) |
| 6517 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6518 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6519 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6520 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6521 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6522 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6523 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6524 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6525 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6526 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6527 | public BigPictureStyle() { |
| 6528 | } |
| 6529 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6530 | /** |
| 6531 | * @deprecated use {@code BigPictureStyle()}. |
| 6532 | */ |
| 6533 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6534 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6535 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6536 | } |
| 6537 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6538 | /** |
| 6539 | * Overrides ContentTitle in the big form of the template. |
| 6540 | * This defaults to the value passed to setContentTitle(). |
| 6541 | */ |
| 6542 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6543 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6544 | return this; |
| 6545 | } |
| 6546 | |
| 6547 | /** |
| 6548 | * Set the first line of text after the detail section in the big form of the template. |
| 6549 | */ |
| 6550 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6551 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6552 | return this; |
| 6553 | } |
| 6554 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6555 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6556 | * @hide |
| 6557 | */ |
| 6558 | public Bitmap getBigPicture() { |
| 6559 | return mPicture; |
| 6560 | } |
| 6561 | |
| 6562 | /** |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6563 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 6564 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6565 | public BigPictureStyle bigPicture(Bitmap b) { |
| 6566 | mPicture = b; |
| 6567 | return this; |
| 6568 | } |
| 6569 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6570 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6571 | * Override the large icon when the big notification is shown. |
| 6572 | */ |
| 6573 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6574 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 6575 | } |
| 6576 | |
| 6577 | /** |
| 6578 | * Override the large icon when the big notification is shown. |
| 6579 | */ |
| 6580 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6581 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6582 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6583 | return this; |
| 6584 | } |
| 6585 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6586 | /** @hide */ |
| 6587 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 6588 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6589 | /** |
| 6590 | * @hide |
| 6591 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6592 | @Override |
| 6593 | public void purgeResources() { |
| 6594 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 6595 | if (mPicture != null && |
| 6596 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6597 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6598 | mPicture = mPicture.createAshmemBitmap(); |
| 6599 | } |
| 6600 | if (mBigLargeIcon != null) { |
| 6601 | mBigLargeIcon.convertToAshmem(); |
| 6602 | } |
| 6603 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6604 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6605 | /** |
| 6606 | * @hide |
| 6607 | */ |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6608 | @Override |
| 6609 | public void reduceImageSizes(Context context) { |
| 6610 | super.reduceImageSizes(context); |
| 6611 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6612 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6613 | if (mPicture != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6614 | int maxPictureWidth = resources.getDimensionPixelSize(isLowRam |
| 6615 | ? R.dimen.notification_big_picture_max_height_low_ram |
| 6616 | : R.dimen.notification_big_picture_max_height); |
| 6617 | int maxPictureHeight = resources.getDimensionPixelSize(isLowRam |
| 6618 | ? R.dimen.notification_big_picture_max_width_low_ram |
| 6619 | : R.dimen.notification_big_picture_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6620 | mPicture = Icon.scaleDownIfNecessary(mPicture, maxPictureWidth, maxPictureHeight); |
| 6621 | } |
| 6622 | if (mBigLargeIcon != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6623 | int rightIconSize = resources.getDimensionPixelSize(isLowRam |
| 6624 | ? R.dimen.notification_right_icon_size_low_ram |
| 6625 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6626 | mBigLargeIcon.scaleDownIfNecessary(rightIconSize, rightIconSize); |
| 6627 | } |
| 6628 | } |
| 6629 | |
| 6630 | /** |
| 6631 | * @hide |
| 6632 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6633 | public RemoteViews makeBigContentView() { |
| 6634 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6635 | // This covers the following cases: |
| 6636 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6637 | // mN.mLargeIcon |
| 6638 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6639 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6640 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6641 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6642 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 6643 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6644 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 6645 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 6646 | // for old listeners, this is in general non-null. |
| 6647 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 6648 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6649 | } |
| 6650 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6651 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6652 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource(), |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6653 | p, null /* result */); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6654 | if (mSummaryTextSet) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6655 | contentView.setTextViewText(R.id.text, mBuilder.processTextSpans( |
| 6656 | mBuilder.processLegacyText(mSummaryText))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6657 | mBuilder.setTextViewColorSecondary(contentView, R.id.text, p); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 6658 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6659 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6660 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 6661 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6662 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6663 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6664 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6665 | } |
| 6666 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6667 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6668 | return contentView; |
| 6669 | } |
| 6670 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6671 | /** |
| 6672 | * @hide |
| 6673 | */ |
| 6674 | public void addExtras(Bundle extras) { |
| 6675 | super.addExtras(extras); |
| 6676 | |
| 6677 | if (mBigLargeIconSet) { |
| 6678 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 6679 | } |
| 6680 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 6681 | } |
| 6682 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6683 | /** |
| 6684 | * @hide |
| 6685 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6686 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6687 | protected void restoreFromExtras(Bundle extras) { |
| 6688 | super.restoreFromExtras(extras); |
| 6689 | |
| 6690 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6691 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6692 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6693 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6694 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 6695 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6696 | |
| 6697 | /** |
| 6698 | * @hide |
| 6699 | */ |
| 6700 | @Override |
| 6701 | public boolean hasSummaryInHeader() { |
| 6702 | return false; |
| 6703 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6704 | |
| 6705 | /** |
| 6706 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6707 | * Note that we aren't actually comparing the contents of the bitmaps here, so this |
| 6708 | * 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] | 6709 | */ |
| 6710 | @Override |
| 6711 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6712 | if (other == null || getClass() != other.getClass()) { |
| 6713 | return true; |
| 6714 | } |
| 6715 | BigPictureStyle otherS = (BigPictureStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6716 | return areBitmapsObviouslyDifferent(getBigPicture(), otherS.getBigPicture()); |
| 6717 | } |
| 6718 | |
| 6719 | private static boolean areBitmapsObviouslyDifferent(Bitmap a, Bitmap b) { |
| 6720 | if (a == b) { |
| 6721 | return false; |
| 6722 | } |
| 6723 | if (a == null || b == null) { |
| 6724 | return true; |
| 6725 | } |
| 6726 | return a.getWidth() != b.getWidth() |
| 6727 | || a.getHeight() != b.getHeight() |
| 6728 | || a.getConfig() != b.getConfig() |
| 6729 | || a.getGenerationId() != b.getGenerationId(); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6730 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6731 | } |
| 6732 | |
| 6733 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6734 | * 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] | 6735 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6736 | * 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] | 6737 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6738 | * Notification notif = new Notification.Builder(mContext) |
| 6739 | * .setContentTitle("New mail from " + sender.toString()) |
| 6740 | * .setContentText(subject) |
| 6741 | * .setSmallIcon(R.drawable.new_mail) |
| 6742 | * .setLargeIcon(aBitmap) |
| 6743 | * .setStyle(new Notification.BigTextStyle() |
| 6744 | * .bigText(aVeryLongString)) |
| 6745 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6746 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6747 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6748 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6749 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6750 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6751 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6752 | private CharSequence mBigText; |
| 6753 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6754 | public BigTextStyle() { |
| 6755 | } |
| 6756 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6757 | /** |
| 6758 | * @deprecated use {@code BigTextStyle()}. |
| 6759 | */ |
| 6760 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6761 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6762 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6763 | } |
| 6764 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6765 | /** |
| 6766 | * Overrides ContentTitle in the big form of the template. |
| 6767 | * This defaults to the value passed to setContentTitle(). |
| 6768 | */ |
| 6769 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6770 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6771 | return this; |
| 6772 | } |
| 6773 | |
| 6774 | /** |
| 6775 | * Set the first line of text after the detail section in the big form of the template. |
| 6776 | */ |
| 6777 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6778 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6779 | return this; |
| 6780 | } |
| 6781 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6782 | /** |
| 6783 | * Provide the longer text to be displayed in the big form of the |
| 6784 | * template in place of the content text. |
| 6785 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6786 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6787 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6788 | return this; |
| 6789 | } |
| 6790 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6791 | /** |
| 6792 | * @hide |
| 6793 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6794 | public CharSequence getBigText() { |
| 6795 | return mBigText; |
| 6796 | } |
| 6797 | |
| 6798 | /** |
| 6799 | * @hide |
| 6800 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6801 | public void addExtras(Bundle extras) { |
| 6802 | super.addExtras(extras); |
| 6803 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6804 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 6805 | } |
| 6806 | |
| 6807 | /** |
| 6808 | * @hide |
| 6809 | */ |
| 6810 | @Override |
| 6811 | protected void restoreFromExtras(Bundle extras) { |
| 6812 | super.restoreFromExtras(extras); |
| 6813 | |
| 6814 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6815 | } |
| 6816 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6817 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6818 | * @param increasedHeight true if this layout be created with an increased height. |
| 6819 | * |
| 6820 | * @hide |
| 6821 | */ |
| 6822 | @Override |
| 6823 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6824 | if (increasedHeight) { |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6825 | mBuilder.mOriginalActions = mBuilder.mActions; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6826 | mBuilder.mActions = new ArrayList<>(); |
| 6827 | RemoteViews remoteViews = makeBigContentView(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6828 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6829 | mBuilder.mOriginalActions = null; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6830 | return remoteViews; |
| 6831 | } |
| 6832 | return super.makeContentView(increasedHeight); |
| 6833 | } |
| 6834 | |
| 6835 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6836 | * @hide |
| 6837 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6838 | @Override |
| 6839 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 6840 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 6841 | return makeBigContentView(); |
| 6842 | } |
| 6843 | return super.makeHeadsUpContentView(increasedHeight); |
| 6844 | } |
| 6845 | |
| 6846 | /** |
| 6847 | * @hide |
| 6848 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6849 | public RemoteViews makeBigContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6850 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder).text(null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6851 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6852 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource(), p, |
| 6853 | result); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 6854 | contentView.setInt(R.id.big_text, "setImageEndMargin", result.getIconMarginEnd()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6855 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 6856 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6857 | if (TextUtils.isEmpty(bigTextText)) { |
| 6858 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 6859 | // experience |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6860 | bigTextText = mBuilder.processLegacyText( |
| 6861 | mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT)); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6862 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6863 | contentView.setTextViewText(R.id.big_text, mBuilder.processTextSpans(bigTextText)); |
| 6864 | mBuilder.setTextViewColorSecondary(contentView, R.id.big_text, p); |
| 6865 | contentView.setViewVisibility(R.id.big_text, |
| 6866 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 6867 | contentView.setBoolean(R.id.big_text, "setHasImage", |
| 6868 | result.isRightIconContainerVisible()); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 6869 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6870 | return contentView; |
| 6871 | } |
| 6872 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6873 | /** |
| 6874 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6875 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6876 | */ |
| 6877 | @Override |
| 6878 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6879 | if (other == null || getClass() != other.getClass()) { |
| 6880 | return true; |
| 6881 | } |
| 6882 | BigTextStyle newS = (BigTextStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6883 | return !Objects.equals(String.valueOf(getBigText()), String.valueOf(newS.getBigText())); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6884 | } |
| 6885 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6886 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6887 | |
| 6888 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6889 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 6890 | * messages of varying types between any number of people. |
| 6891 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6892 | * <p> |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6893 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 6894 | * user will always see the normal notification view. |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6895 | * |
| 6896 | * <p> |
| 6897 | * If the app is targeting Android P and above, it is required to use the {@link Person} |
| 6898 | * class in order to get an optimal rendering of the notification and its avatars. For |
| 6899 | * conversations involving multiple people, the app should also make sure that it marks the |
| 6900 | * conversation as a group with {@link #setGroupConversation(boolean)}. |
| 6901 | * |
| 6902 | * <p> |
| 6903 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior. |
| 6904 | * Here's an example of how this may be used: |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6905 | * <pre class="prettyprint"> |
| 6906 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6907 | * Person user = new Person.Builder().setIcon(userIcon).setName(userName).build(); |
| 6908 | * MessagingStyle style = new MessagingStyle(user) |
| 6909 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getPerson()) |
| 6910 | * .addMessage(messages[2].getText(), messages[2].getTime(), messages[2].getPerson()) |
| 6911 | * .setGroupConversation(hasMultiplePeople()); |
| 6912 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6913 | * Notification noti = new Notification.Builder() |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6914 | * .setContentTitle("2 new messages with " + sender.toString()) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6915 | * .setContentText(subject) |
| 6916 | * .setSmallIcon(R.drawable.new_message) |
| 6917 | * .setLargeIcon(aBitmap) |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6918 | * .setStyle(style) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6919 | * .build(); |
| 6920 | * </pre> |
| 6921 | */ |
| 6922 | public static class MessagingStyle extends Style { |
| 6923 | |
| 6924 | /** |
| 6925 | * The maximum number of messages that will be retained in the Notification itself (the |
| 6926 | * number displayed is up to the platform). |
| 6927 | */ |
| 6928 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 6929 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6930 | @NonNull Person mUser; |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6931 | @Nullable CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6932 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6933 | List<Message> mHistoricMessages = new ArrayList<>(); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6934 | boolean mIsGroupConversation; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6935 | |
| 6936 | MessagingStyle() { |
| 6937 | } |
| 6938 | |
| 6939 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6940 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 6941 | * user before the posting app reposts the notification with those messages after they've |
| 6942 | * 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] | 6943 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6944 | * |
| 6945 | * @deprecated use {@code MessagingStyle(Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6946 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6947 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6948 | this(new Person.Builder().setName(userDisplayName).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6949 | } |
| 6950 | |
| 6951 | /** |
| 6952 | * @param user Required - The person displayed for any messages that are sent by the |
| 6953 | * user. Any messages added with {@link #addMessage(Notification.MessagingStyle.Message)} |
| 6954 | * 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] | 6955 | * by this user. The user also needs to have a valid name associated with it, which will |
| 6956 | * be enforced starting in Android P. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6957 | */ |
| 6958 | public MessagingStyle(@NonNull Person user) { |
| 6959 | mUser = user; |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6960 | } |
| 6961 | |
| 6962 | /** |
| 6963 | * Validate that this style was properly composed. This is called at build time. |
| 6964 | * @hide |
| 6965 | */ |
| 6966 | @Override |
| 6967 | public void validate(Context context) { |
| 6968 | super.validate(context); |
| 6969 | if (context.getApplicationInfo().targetSdkVersion |
| 6970 | >= Build.VERSION_CODES.P && (mUser == null || mUser.getName() == null)) { |
| 6971 | throw new RuntimeException("User must be valid and have a name."); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6972 | } |
| 6973 | } |
| 6974 | |
| 6975 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6976 | * @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] | 6977 | * If {@code null} is returned, the default implementation will be used. |
| 6978 | * |
| 6979 | * @hide |
| 6980 | */ |
| 6981 | @Override |
| 6982 | public CharSequence getHeadsUpStatusBarText() { |
| 6983 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
| 6984 | ? super.mBigContentTitle |
| 6985 | : mConversationTitle; |
| 6986 | if (!TextUtils.isEmpty(conversationTitle) && !hasOnlyWhiteSpaceSenders()) { |
| 6987 | return conversationTitle; |
| 6988 | } |
| 6989 | return null; |
| 6990 | } |
| 6991 | |
| 6992 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6993 | * @return the user to be displayed for any replies sent by the user |
| 6994 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6995 | @NonNull |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6996 | public Person getUser() { |
| 6997 | return mUser; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6998 | } |
| 6999 | |
| 7000 | /** |
| 7001 | * 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] | 7002 | * |
| 7003 | * @deprecated use {@link #getUser()} instead |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7004 | */ |
| 7005 | public CharSequence getUserDisplayName() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7006 | return mUser.getName(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7007 | } |
| 7008 | |
| 7009 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7010 | * Sets the title to be displayed on this conversation. May be set to {@code null}. |
| 7011 | * |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7012 | * <p>This API's behavior was changed in SDK version {@link Build.VERSION_CODES#P}. If your |
| 7013 | * application's target version is less than {@link Build.VERSION_CODES#P}, setting a |
| 7014 | * conversation title to a non-null value will make {@link #isGroupConversation()} return |
| 7015 | * {@code true} and passing {@code null} will make it return {@code false}. In |
| 7016 | * {@link Build.VERSION_CODES#P} and beyond, use {@link #setGroupConversation(boolean)} |
| 7017 | * to set group conversation status. |
| 7018 | * |
| 7019 | * @param conversationTitle Title displayed for this conversation |
| 7020 | * @return this object for method chaining |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7021 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7022 | public MessagingStyle setConversationTitle(@Nullable CharSequence conversationTitle) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7023 | mConversationTitle = conversationTitle; |
| 7024 | return this; |
| 7025 | } |
| 7026 | |
| 7027 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7028 | * 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] | 7029 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7030 | @Nullable |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7031 | public CharSequence getConversationTitle() { |
| 7032 | return mConversationTitle; |
| 7033 | } |
| 7034 | |
| 7035 | /** |
| 7036 | * Adds a message for display by this notification. Convenience call for a simple |
| 7037 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 7038 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7039 | * @param timestamp Time at which the message arrived |
| 7040 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 7041 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 7042 | * the platform will insert {@link #getUserDisplayName()}. |
| 7043 | * Should be unique amongst all individuals in the conversation, and should be |
| 7044 | * consistent during re-posts of the notification. |
| 7045 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 7046 | * @see Message#Notification.MessagingStyle.Message(CharSequence, long, CharSequence) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7047 | * |
| 7048 | * @return this object for method chaining |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7049 | * |
| 7050 | * @deprecated use {@link #addMessage(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7051 | */ |
| 7052 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7053 | return addMessage(text, timestamp, |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7054 | sender == null ? null : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7055 | } |
| 7056 | |
| 7057 | /** |
| 7058 | * Adds a message for display by this notification. Convenience call for a simple |
| 7059 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 7060 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7061 | * @param timestamp Time at which the message arrived |
| 7062 | * @param sender The {@link Person} who sent the message. |
| 7063 | * Should be <code>null</code> for messages by the current user, in which case |
| 7064 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7065 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 7066 | * @see Message#Notification.MessagingStyle.Message(CharSequence, long, CharSequence) |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7067 | * |
| 7068 | * @return this object for method chaining |
| 7069 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 7070 | public MessagingStyle addMessage(@NonNull CharSequence text, long timestamp, |
| 7071 | @Nullable Person sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7072 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7073 | } |
| 7074 | |
| 7075 | /** |
| 7076 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7077 | * |
| 7078 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 7079 | * the newest last. |
| 7080 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7081 | * @param message The {@link Message} to be displayed |
| 7082 | * @return this object for method chaining |
| 7083 | */ |
| 7084 | public MessagingStyle addMessage(Message message) { |
| 7085 | mMessages.add(message); |
| 7086 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 7087 | mMessages.remove(0); |
| 7088 | } |
| 7089 | return this; |
| 7090 | } |
| 7091 | |
| 7092 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7093 | * Adds a {@link Message} for historic context in this notification. |
| 7094 | * |
| 7095 | * <p>Messages should be added as historic if they are not the main subject of the |
| 7096 | * notification but may give context to a conversation. The system may choose to present |
| 7097 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 7098 | * |
| 7099 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 7100 | * the newest last. |
| 7101 | * |
| 7102 | * @param message The historic {@link Message} to be added |
| 7103 | * @return this object for method chaining |
| 7104 | */ |
| 7105 | public MessagingStyle addHistoricMessage(Message message) { |
| 7106 | mHistoricMessages.add(message); |
| 7107 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 7108 | mHistoricMessages.remove(0); |
| 7109 | } |
| 7110 | return this; |
| 7111 | } |
| 7112 | |
| 7113 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7114 | * Gets the list of {@code Message} objects that represent the notification |
| 7115 | */ |
| 7116 | public List<Message> getMessages() { |
| 7117 | return mMessages; |
| 7118 | } |
| 7119 | |
| 7120 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7121 | * Gets the list of historic {@code Message}s in the notification. |
| 7122 | */ |
| 7123 | public List<Message> getHistoricMessages() { |
| 7124 | return mHistoricMessages; |
| 7125 | } |
| 7126 | |
| 7127 | /** |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7128 | * Sets whether this conversation notification represents a group. If the app is targeting |
| 7129 | * Android P, this is required if the app wants to display the largeIcon set with |
| 7130 | * {@link Notification.Builder#setLargeIcon(Bitmap)}, otherwise it will be hidden. |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7131 | * |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7132 | * @param isGroupConversation {@code true} if the conversation represents a group, |
| 7133 | * {@code false} otherwise. |
| 7134 | * @return this object for method chaining |
| 7135 | */ |
| 7136 | public MessagingStyle setGroupConversation(boolean isGroupConversation) { |
| 7137 | mIsGroupConversation = isGroupConversation; |
| 7138 | return this; |
| 7139 | } |
| 7140 | |
| 7141 | /** |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7142 | * Returns {@code true} if this notification represents a group conversation, otherwise |
| 7143 | * {@code false}. |
| 7144 | * |
| 7145 | * <p> If the application that generated this {@link MessagingStyle} targets an SDK version |
| 7146 | * less than {@link Build.VERSION_CODES#P}, this method becomes dependent on whether or |
| 7147 | * not the conversation title is set; returning {@code true} if the conversation title is |
| 7148 | * a non-null value, or {@code false} otherwise. From {@link Build.VERSION_CODES#P} forward, |
| 7149 | * this method returns what's set by {@link #setGroupConversation(boolean)} allowing for |
| 7150 | * named, non-group conversations. |
| 7151 | * |
| 7152 | * @see #setConversationTitle(CharSequence) |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7153 | */ |
| 7154 | public boolean isGroupConversation() { |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7155 | // When target SDK version is < P, a non-null conversation title dictates if this is |
| 7156 | // as group conversation. |
| 7157 | if (mBuilder != null |
| 7158 | && mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 7159 | < Build.VERSION_CODES.P) { |
| 7160 | return mConversationTitle != null; |
| 7161 | } |
| 7162 | |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7163 | return mIsGroupConversation; |
| 7164 | } |
| 7165 | |
| 7166 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7167 | * @hide |
| 7168 | */ |
| 7169 | @Override |
| 7170 | public void addExtras(Bundle extras) { |
| 7171 | super.addExtras(extras); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7172 | if (mUser != null) { |
| 7173 | // For legacy usages |
| 7174 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUser.getName()); |
| 7175 | extras.putParcelable(EXTRA_MESSAGING_PERSON, mUser); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7176 | } |
| 7177 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7178 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7179 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7180 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 7181 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7182 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7183 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 7184 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 7185 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7186 | |
| 7187 | fixTitleAndTextExtras(extras); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7188 | extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7189 | } |
| 7190 | |
| 7191 | private void fixTitleAndTextExtras(Bundle extras) { |
| 7192 | Message m = findLatestIncomingMessage(); |
| 7193 | CharSequence text = (m == null) ? null : m.mText; |
| 7194 | CharSequence sender = m == null ? null |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7195 | : m.mSender == null || TextUtils.isEmpty(m.mSender.getName()) |
| 7196 | ? mUser.getName() : m.mSender.getName(); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7197 | CharSequence title; |
| 7198 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 7199 | if (!TextUtils.isEmpty(sender)) { |
| 7200 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 7201 | title = mBuilder.mContext.getString( |
| 7202 | com.android.internal.R.string.notification_messaging_title_template, |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7203 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(sender)); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7204 | } else { |
| 7205 | title = mConversationTitle; |
| 7206 | } |
| 7207 | } else { |
| 7208 | title = sender; |
| 7209 | } |
| 7210 | |
| 7211 | if (title != null) { |
| 7212 | extras.putCharSequence(EXTRA_TITLE, title); |
| 7213 | } |
| 7214 | if (text != null) { |
| 7215 | extras.putCharSequence(EXTRA_TEXT, text); |
| 7216 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7217 | } |
| 7218 | |
| 7219 | /** |
| 7220 | * @hide |
| 7221 | */ |
| 7222 | @Override |
| 7223 | protected void restoreFromExtras(Bundle extras) { |
| 7224 | super.restoreFromExtras(extras); |
| 7225 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7226 | mUser = extras.getParcelable(EXTRA_MESSAGING_PERSON); |
| 7227 | if (mUser == null) { |
| 7228 | CharSequence displayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7229 | mUser = new Person.Builder().setName(displayName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7230 | } |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 7231 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7232 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7233 | mMessages = Message.getMessagesFromBundleArray(messages); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7234 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7235 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7236 | mIsGroupConversation = extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7237 | } |
| 7238 | |
| 7239 | /** |
| 7240 | * @hide |
| 7241 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7242 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7243 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7244 | mBuilder.mOriginalActions = mBuilder.mActions; |
| 7245 | mBuilder.mActions = new ArrayList<>(); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7246 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7247 | false /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7248 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 7249 | mBuilder.mOriginalActions = null; |
| 7250 | return remoteViews; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7251 | } |
| 7252 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7253 | /** |
| 7254 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7255 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7256 | */ |
| 7257 | @Override |
| 7258 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7259 | if (other == null || getClass() != other.getClass()) { |
| 7260 | return true; |
| 7261 | } |
| 7262 | MessagingStyle newS = (MessagingStyle) other; |
| 7263 | List<MessagingStyle.Message> oldMs = getMessages(); |
| 7264 | List<MessagingStyle.Message> newMs = newS.getMessages(); |
| 7265 | |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7266 | if (oldMs == null || newMs == null) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7267 | newMs = new ArrayList<>(); |
| 7268 | } |
| 7269 | |
| 7270 | int n = oldMs.size(); |
| 7271 | if (n != newMs.size()) { |
| 7272 | return true; |
| 7273 | } |
| 7274 | for (int i = 0; i < n; i++) { |
| 7275 | MessagingStyle.Message oldM = oldMs.get(i); |
| 7276 | MessagingStyle.Message newM = newMs.get(i); |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7277 | if (!Objects.equals( |
| 7278 | String.valueOf(oldM.getText()), |
| 7279 | String.valueOf(newM.getText()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7280 | return true; |
| 7281 | } |
| 7282 | if (!Objects.equals(oldM.getDataUri(), newM.getDataUri())) { |
| 7283 | return true; |
| 7284 | } |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7285 | String oldSender = String.valueOf(oldM.getSenderPerson() == null |
| 7286 | ? oldM.getSender() |
| 7287 | : oldM.getSenderPerson().getName()); |
| 7288 | String newSender = String.valueOf(newM.getSenderPerson() == null |
| 7289 | ? newM.getSender() |
| 7290 | : newM.getSenderPerson().getName()); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7291 | if (!Objects.equals(oldSender, newSender)) { |
| 7292 | return true; |
| 7293 | } |
| 7294 | |
| 7295 | String oldKey = oldM.getSenderPerson() == null |
| 7296 | ? null : oldM.getSenderPerson().getKey(); |
| 7297 | String newKey = newM.getSenderPerson() == null |
| 7298 | ? null : newM.getSenderPerson().getKey(); |
| 7299 | if (!Objects.equals(oldKey, newKey)) { |
| 7300 | return true; |
| 7301 | } |
| 7302 | // Other fields (like timestamp) intentionally excluded |
| 7303 | } |
| 7304 | return false; |
| 7305 | } |
| 7306 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7307 | private Message findLatestIncomingMessage() { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7308 | return findLatestIncomingMessage(mMessages); |
| 7309 | } |
| 7310 | |
| 7311 | /** |
| 7312 | * @hide |
| 7313 | */ |
| 7314 | @Nullable |
| 7315 | public static Message findLatestIncomingMessage( |
| 7316 | List<Message> messages) { |
| 7317 | for (int i = messages.size() - 1; i >= 0; i--) { |
| 7318 | Message m = messages.get(i); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7319 | // Incoming messages have a non-empty sender. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7320 | if (m.mSender != null && !TextUtils.isEmpty(m.mSender.getName())) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7321 | return m; |
| 7322 | } |
| 7323 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7324 | if (!messages.isEmpty()) { |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7325 | // No incoming messages, fall back to outgoing message |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7326 | return messages.get(messages.size() - 1); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7327 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7328 | return null; |
| 7329 | } |
| 7330 | |
| 7331 | /** |
| 7332 | * @hide |
| 7333 | */ |
| 7334 | @Override |
| 7335 | public RemoteViews makeBigContentView() { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7336 | return makeMessagingView(false /* displayImagesAtEnd */, true /* hideLargeIcon */); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7337 | } |
| 7338 | |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7339 | /** |
| 7340 | * Create a messaging layout. |
| 7341 | * |
| 7342 | * @param displayImagesAtEnd should images be displayed at the end of the content instead |
| 7343 | * of inline. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7344 | * @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] | 7345 | * @return the created remoteView. |
| 7346 | */ |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7347 | @NonNull |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7348 | private RemoteViews makeMessagingView(boolean displayImagesAtEnd, boolean hideRightIcons) { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7349 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7350 | ? super.mBigContentTitle |
| 7351 | : mConversationTitle; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7352 | boolean atLeastP = mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 7353 | >= Build.VERSION_CODES.P; |
| 7354 | boolean isOneToOne; |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7355 | CharSequence nameReplacement = null; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7356 | Icon avatarReplacement = null; |
| 7357 | if (!atLeastP) { |
| 7358 | isOneToOne = TextUtils.isEmpty(conversationTitle); |
| 7359 | avatarReplacement = mBuilder.mN.mLargeIcon; |
| 7360 | if (hasOnlyWhiteSpaceSenders()) { |
| 7361 | isOneToOne = true; |
| 7362 | nameReplacement = conversationTitle; |
| 7363 | conversationTitle = null; |
| 7364 | } |
| 7365 | } else { |
| 7366 | isOneToOne = !isGroupConversation(); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 7367 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7368 | TemplateBindResult bindResult = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7369 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).title( |
| 7370 | conversationTitle).text(null) |
| 7371 | .hideLargeIcon(hideRightIcons || isOneToOne) |
| 7372 | .hideReplyIcon(hideRightIcons) |
| 7373 | .headerTextSecondary(conversationTitle); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 7374 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7375 | mBuilder.getMessagingLayoutResource(), |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7376 | p, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7377 | bindResult); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7378 | addExtras(mBuilder.mN.extras); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7379 | // also update the end margin if there is an image |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7380 | contentView.setViewLayoutMarginEnd(R.id.notification_messaging, |
| 7381 | bindResult.getIconMarginEnd()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7382 | contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7383 | mBuilder.isColorized(p) ? mBuilder.getPrimaryTextColor(p) |
| 7384 | : mBuilder.resolveContrastColor(p)); |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 7385 | contentView.setInt(R.id.status_bar_latest_event_content, "setSenderTextColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7386 | mBuilder.getPrimaryTextColor(p)); |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 7387 | contentView.setInt(R.id.status_bar_latest_event_content, "setMessageTextColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7388 | mBuilder.getSecondaryTextColor(p)); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7389 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd", |
| 7390 | displayImagesAtEnd); |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7391 | contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement", |
| 7392 | avatarReplacement); |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7393 | contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement", |
| 7394 | nameReplacement); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7395 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne", |
| 7396 | isOneToOne); |
| 7397 | contentView.setBundle(R.id.status_bar_latest_event_content, "setData", |
| 7398 | mBuilder.mN.extras); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7399 | return contentView; |
| 7400 | } |
| 7401 | |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7402 | private boolean hasOnlyWhiteSpaceSenders() { |
| 7403 | for (int i = 0; i < mMessages.size(); i++) { |
| 7404 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7405 | Person sender = m.getSenderPerson(); |
| 7406 | if (sender != null && !isWhiteSpace(sender.getName())) { |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7407 | return false; |
| 7408 | } |
| 7409 | } |
| 7410 | return true; |
| 7411 | } |
| 7412 | |
| 7413 | private boolean isWhiteSpace(CharSequence sender) { |
| 7414 | if (TextUtils.isEmpty(sender)) { |
| 7415 | return true; |
| 7416 | } |
| 7417 | if (sender.toString().matches("^\\s*$")) { |
| 7418 | return true; |
| 7419 | } |
| 7420 | // Let's check if we only have 0 whitespace chars. Some apps did this as a workaround |
| 7421 | // For the presentation that we had. |
| 7422 | for (int i = 0; i < sender.length(); i++) { |
| 7423 | char c = sender.charAt(i); |
| 7424 | if (c != '\u200B') { |
| 7425 | return false; |
| 7426 | } |
| 7427 | } |
| 7428 | return true; |
| 7429 | } |
| 7430 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7431 | private CharSequence createConversationTitleFromMessages() { |
| 7432 | ArraySet<CharSequence> names = new ArraySet<>(); |
| 7433 | for (int i = 0; i < mMessages.size(); i++) { |
| 7434 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7435 | Person sender = m.getSenderPerson(); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7436 | if (sender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7437 | names.add(sender.getName()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7438 | } |
| 7439 | } |
| 7440 | SpannableStringBuilder title = new SpannableStringBuilder(); |
| 7441 | int size = names.size(); |
| 7442 | for (int i = 0; i < size; i++) { |
| 7443 | CharSequence name = names.valueAt(i); |
| 7444 | if (!TextUtils.isEmpty(title)) { |
| 7445 | title.append(", "); |
| 7446 | } |
| 7447 | title.append(BidiFormatter.getInstance().unicodeWrap(name)); |
| 7448 | } |
| 7449 | return title; |
| 7450 | } |
| 7451 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7452 | /** |
| 7453 | * @hide |
| 7454 | */ |
| 7455 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7456 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7457 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7458 | true /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7459 | remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1); |
| 7460 | return remoteViews; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7461 | } |
| 7462 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7463 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 7464 | return new TextAppearanceSpan(null, 0, 0, |
| 7465 | ColorStateList.valueOf(color), null); |
| 7466 | } |
| 7467 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7468 | public static final class Message { |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 7469 | /** @hide */ |
| 7470 | public static final String KEY_TEXT = "text"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7471 | static final String KEY_TIMESTAMP = "time"; |
| 7472 | static final String KEY_SENDER = "sender"; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7473 | static final String KEY_SENDER_PERSON = "sender_person"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7474 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 7475 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7476 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7477 | static final String KEY_REMOTE_INPUT_HISTORY = "remote_input_history"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7478 | |
| 7479 | private final CharSequence mText; |
| 7480 | private final long mTimestamp; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7481 | @Nullable |
| 7482 | private final Person mSender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7483 | /** True if this message was generated from the extra |
| 7484 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY} |
| 7485 | */ |
| 7486 | private final boolean mRemoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7487 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7488 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7489 | private String mDataMimeType; |
| 7490 | private Uri mDataUri; |
| 7491 | |
| 7492 | /** |
| 7493 | * Constructor |
| 7494 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7495 | * @param timestamp Time at which the message arrived |
| 7496 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 7497 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 7498 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 7499 | * Should be unique amongst all individuals in the conversation, and should be |
| 7500 | * consistent during re-posts of the notification. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7501 | * |
| 7502 | * @deprecated use {@code Message(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7503 | */ |
| 7504 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7505 | this(text, timestamp, sender == null ? null |
| 7506 | : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7507 | } |
| 7508 | |
| 7509 | /** |
| 7510 | * Constructor |
| 7511 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7512 | * @param timestamp Time at which the message arrived |
| 7513 | * @param sender The {@link Person} who sent the message. |
| 7514 | * Should be <code>null</code> for messages by the current user, in which case |
| 7515 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7516 | * <p> |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7517 | * The person provided should contain an Icon, set with |
| 7518 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7519 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7520 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7521 | * to differentiate between the different users. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7522 | * </p> |
| 7523 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 7524 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7525 | this(text, timestamp, sender, false /* remoteHistory */); |
| 7526 | } |
| 7527 | |
| 7528 | /** |
| 7529 | * Constructor |
| 7530 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7531 | * @param timestamp Time at which the message arrived |
| 7532 | * @param sender The {@link Person} who sent the message. |
| 7533 | * Should be <code>null</code> for messages by the current user, in which case |
| 7534 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7535 | * @param remoteInputHistory True if the messages was generated from the extra |
| 7536 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7537 | * <p> |
| 7538 | * The person provided should contain an Icon, set with |
| 7539 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7540 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7541 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7542 | * to differentiate between the different users. |
| 7543 | * </p> |
| 7544 | * @hide |
| 7545 | */ |
| 7546 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender, |
| 7547 | boolean remoteInputHistory) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7548 | mText = text; |
| 7549 | mTimestamp = timestamp; |
| 7550 | mSender = sender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7551 | mRemoteInputHistory = remoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7552 | } |
| 7553 | |
| 7554 | /** |
| 7555 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 7556 | * where the platform doesn't support the MIME type, the original text provided in the |
| 7557 | * constructor will be used. |
| 7558 | * @param dataMimeType The MIME type of the content. See |
| 7559 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 7560 | * types on Android and Android Wear. |
| 7561 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 7562 | * <p class="note"> |
| 7563 | * <ol> |
| 7564 | * <li>Notification Listeners including the System UI need permission to access the |
| 7565 | * data the Uri points to. The recommended ways to do this are:</li> |
| 7566 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 7567 | * the correct permission to access your provider. The preferred mechanism for |
| 7568 | * providing access is to use per-URI permissions which are temporary and only |
| 7569 | * grant access to the receiving application. An easy way to create a |
| 7570 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 7571 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 7572 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 7573 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 7574 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 7575 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 7576 | * Note that once added to the system MediaStore the content is accessible to any |
| 7577 | * app on the device.</li> |
| 7578 | * </ol> |
| 7579 | * @return this object for method chaining |
| 7580 | */ |
| 7581 | public Message setData(String dataMimeType, Uri dataUri) { |
| 7582 | mDataMimeType = dataMimeType; |
| 7583 | mDataUri = dataUri; |
| 7584 | return this; |
| 7585 | } |
| 7586 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7587 | /** |
| 7588 | * Get the text to be used for this message, or the fallback text if a type and content |
| 7589 | * Uri have been set |
| 7590 | */ |
| 7591 | public CharSequence getText() { |
| 7592 | return mText; |
| 7593 | } |
| 7594 | |
| 7595 | /** |
| 7596 | * Get the time at which this message arrived |
| 7597 | */ |
| 7598 | public long getTimestamp() { |
| 7599 | return mTimestamp; |
| 7600 | } |
| 7601 | |
| 7602 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7603 | * Get the extras Bundle for this message. |
| 7604 | */ |
| 7605 | public Bundle getExtras() { |
| 7606 | return mExtras; |
| 7607 | } |
| 7608 | |
| 7609 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7610 | * 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] | 7611 | * |
| 7612 | * @deprecated use {@link #getSenderPerson()} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7613 | */ |
| 7614 | public CharSequence getSender() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7615 | return mSender == null ? null : mSender.getName(); |
| 7616 | } |
| 7617 | |
| 7618 | /** |
| 7619 | * Get the sender associated with this message. |
| 7620 | */ |
| 7621 | @Nullable |
| 7622 | public Person getSenderPerson() { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7623 | return mSender; |
| 7624 | } |
| 7625 | |
| 7626 | /** |
| 7627 | * Get the MIME type of the data pointed to by the Uri |
| 7628 | */ |
| 7629 | public String getDataMimeType() { |
| 7630 | return mDataMimeType; |
| 7631 | } |
| 7632 | |
| 7633 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 7634 | * 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] | 7635 | * {@see #getText()} is used. |
| 7636 | */ |
| 7637 | public Uri getDataUri() { |
| 7638 | return mDataUri; |
| 7639 | } |
| 7640 | |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7641 | /** |
| 7642 | * @return True if the message was generated from |
| 7643 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7644 | * @hide |
| 7645 | */ |
| 7646 | public boolean isRemoteInputHistory() { |
| 7647 | return mRemoteInputHistory; |
| 7648 | } |
| 7649 | |
Beverly | e98937a | 2018-11-15 10:18:57 -0500 | [diff] [blame] | 7650 | /** |
| 7651 | * @hide |
| 7652 | */ |
| 7653 | @VisibleForTesting |
| 7654 | public Bundle toBundle() { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7655 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7656 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7657 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7658 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7659 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7660 | if (mSender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7661 | // Legacy listeners need this |
| 7662 | bundle.putCharSequence(KEY_SENDER, mSender.getName()); |
| 7663 | bundle.putParcelable(KEY_SENDER_PERSON, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7664 | } |
| 7665 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7666 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7667 | } |
| 7668 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7669 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7670 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7671 | if (mExtras != null) { |
| 7672 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 7673 | } |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7674 | if (mRemoteInputHistory) { |
| 7675 | bundle.putBoolean(KEY_REMOTE_INPUT_HISTORY, mRemoteInputHistory); |
| 7676 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7677 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7678 | } |
| 7679 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7680 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 7681 | Bundle[] bundles = new Bundle[messages.size()]; |
| 7682 | final int N = messages.size(); |
| 7683 | for (int i = 0; i < N; i++) { |
| 7684 | bundles[i] = messages.get(i).toBundle(); |
| 7685 | } |
| 7686 | return bundles; |
| 7687 | } |
| 7688 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7689 | /** |
| 7690 | * @return A list of messages read from the bundles. |
| 7691 | * |
| 7692 | * @hide |
| 7693 | */ |
| 7694 | public static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
| 7695 | if (bundles == null) { |
| 7696 | return new ArrayList<>(); |
| 7697 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7698 | List<Message> messages = new ArrayList<>(bundles.length); |
| 7699 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7700 | if (bundles[i] instanceof Bundle) { |
| 7701 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 7702 | if (message != null) { |
| 7703 | messages.add(message); |
| 7704 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7705 | } |
| 7706 | } |
| 7707 | return messages; |
| 7708 | } |
| 7709 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 7710 | /** |
| 7711 | * @return The message that is stored in the bundle or null if the message couldn't be |
| 7712 | * resolved. |
| 7713 | * |
| 7714 | * @hide |
| 7715 | */ |
| 7716 | @Nullable |
| 7717 | public static Message getMessageFromBundle(Bundle bundle) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7718 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 7719 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7720 | return null; |
| 7721 | } else { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7722 | |
| 7723 | Person senderPerson = bundle.getParcelable(KEY_SENDER_PERSON); |
| 7724 | if (senderPerson == null) { |
| 7725 | // Legacy apps that use compat don't actually provide the sender objects |
| 7726 | // We need to fix the compat version to provide people / use |
| 7727 | // the native api instead |
| 7728 | CharSequence senderName = bundle.getCharSequence(KEY_SENDER); |
| 7729 | if (senderName != null) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7730 | senderPerson = new Person.Builder().setName(senderName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7731 | } |
| 7732 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7733 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7734 | bundle.getLong(KEY_TIMESTAMP), |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7735 | senderPerson, |
| 7736 | bundle.getBoolean(KEY_REMOTE_INPUT_HISTORY, false)); |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7737 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 7738 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7739 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 7740 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7741 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7742 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 7743 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 7744 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7745 | return message; |
| 7746 | } |
| 7747 | } catch (ClassCastException e) { |
| 7748 | return null; |
| 7749 | } |
| 7750 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7751 | } |
| 7752 | } |
| 7753 | |
| 7754 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7755 | * 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] | 7756 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7757 | * 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] | 7758 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7759 | * Notification notif = new Notification.Builder(mContext) |
| 7760 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 7761 | * .setContentText(subject) |
| 7762 | * .setSmallIcon(R.drawable.new_mail) |
| 7763 | * .setLargeIcon(aBitmap) |
| 7764 | * .setStyle(new Notification.InboxStyle() |
| 7765 | * .addLine(str1) |
| 7766 | * .addLine(str2) |
| 7767 | * .setContentTitle("") |
| 7768 | * .setSummaryText("+3 more")) |
| 7769 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7770 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 7771 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7772 | * @see Notification#bigContentView |
| 7773 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7774 | public static class InboxStyle extends Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7775 | |
| 7776 | /** |
| 7777 | * The number of lines of remote input history allowed until we start reducing lines. |
| 7778 | */ |
| 7779 | private static final int NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION = 1; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7780 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 7781 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7782 | public InboxStyle() { |
| 7783 | } |
| 7784 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7785 | /** |
| 7786 | * @deprecated use {@code InboxStyle()}. |
| 7787 | */ |
| 7788 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7789 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7790 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7791 | } |
| 7792 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7793 | /** |
| 7794 | * Overrides ContentTitle in the big form of the template. |
| 7795 | * This defaults to the value passed to setContentTitle(). |
| 7796 | */ |
| 7797 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7798 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7799 | return this; |
| 7800 | } |
| 7801 | |
| 7802 | /** |
| 7803 | * Set the first line of text after the detail section in the big form of the template. |
| 7804 | */ |
| 7805 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7806 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7807 | return this; |
| 7808 | } |
| 7809 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 7810 | /** |
| 7811 | * Append a line to the digest section of the Inbox notification. |
| 7812 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7813 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7814 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7815 | return this; |
| 7816 | } |
| 7817 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7818 | /** |
| 7819 | * @hide |
| 7820 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7821 | public ArrayList<CharSequence> getLines() { |
| 7822 | return mTexts; |
| 7823 | } |
| 7824 | |
| 7825 | /** |
| 7826 | * @hide |
| 7827 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7828 | public void addExtras(Bundle extras) { |
| 7829 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7830 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7831 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 7832 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 7833 | } |
| 7834 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7835 | /** |
| 7836 | * @hide |
| 7837 | */ |
| 7838 | @Override |
| 7839 | protected void restoreFromExtras(Bundle extras) { |
| 7840 | super.restoreFromExtras(extras); |
| 7841 | |
| 7842 | mTexts.clear(); |
| 7843 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 7844 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 7845 | } |
| 7846 | } |
| 7847 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7848 | /** |
| 7849 | * @hide |
| 7850 | */ |
| 7851 | public RemoteViews makeBigContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7852 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder).text(null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7853 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7854 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource(), p, result); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7855 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7856 | 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] | 7857 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7858 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 7859 | // Make sure all rows are gone in case we reuse a view. |
| 7860 | for (int rowId : rowIds) { |
| 7861 | contentView.setViewVisibility(rowId, View.GONE); |
| 7862 | } |
| 7863 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7864 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7865 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7866 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7867 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7868 | int onlyViewId = 0; |
| 7869 | int maxRows = rowIds.length; |
| 7870 | if (mBuilder.mActions.size() > 0) { |
| 7871 | maxRows--; |
| 7872 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7873 | CharSequence[] remoteInputHistory = mBuilder.mN.extras.getCharSequenceArray( |
| 7874 | EXTRA_REMOTE_INPUT_HISTORY); |
| 7875 | if (remoteInputHistory != null |
| 7876 | && remoteInputHistory.length > NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION) { |
| 7877 | // Let's remove some messages to make room for the remote input history. |
| 7878 | // 1 is always able to fit, but let's remove them if they are 2 or 3 |
| 7879 | int numRemoteInputs = Math.min(remoteInputHistory.length, |
| 7880 | MAX_REMOTE_INPUT_HISTORY_LINES); |
| 7881 | int totalNumRows = mTexts.size() + numRemoteInputs |
| 7882 | - NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION; |
| 7883 | if (totalNumRows > maxRows) { |
| 7884 | int overflow = totalNumRows - maxRows; |
| 7885 | if (mTexts.size() > maxRows) { |
| 7886 | // Heuristic: if the Texts don't fit anyway, we'll rather drop the last |
| 7887 | // few messages, even with the remote input |
| 7888 | maxRows -= overflow; |
| 7889 | } else { |
| 7890 | // otherwise we drop the first messages |
| 7891 | i = overflow; |
| 7892 | } |
| 7893 | } |
| 7894 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7895 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7896 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7897 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7898 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 7899 | contentView.setTextViewText(rowIds[i], |
| 7900 | mBuilder.processTextSpans(mBuilder.processLegacyText(str))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7901 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i], p); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7902 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7903 | handleInboxImageMargin(contentView, rowIds[i], first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7904 | result.getIconMarginEnd()); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7905 | if (first) { |
| 7906 | onlyViewId = rowIds[i]; |
| 7907 | } else { |
| 7908 | onlyViewId = 0; |
| 7909 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7910 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7911 | } |
| 7912 | i++; |
| 7913 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7914 | if (onlyViewId != 0) { |
| 7915 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 7916 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7917 | R.dimen.notification_text_margin_top); |
| 7918 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 7919 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7920 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7921 | return contentView; |
| 7922 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7923 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7924 | /** |
| 7925 | * @hide |
| 7926 | */ |
| 7927 | @Override |
| 7928 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7929 | if (other == null || getClass() != other.getClass()) { |
| 7930 | return true; |
| 7931 | } |
| 7932 | InboxStyle newS = (InboxStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7933 | |
| 7934 | final ArrayList<CharSequence> myLines = getLines(); |
| 7935 | final ArrayList<CharSequence> newLines = newS.getLines(); |
| 7936 | final int n = myLines.size(); |
| 7937 | if (n != newLines.size()) { |
| 7938 | return true; |
| 7939 | } |
| 7940 | |
| 7941 | for (int i = 0; i < n; i++) { |
| 7942 | if (!Objects.equals( |
| 7943 | String.valueOf(myLines.get(i)), |
| 7944 | String.valueOf(newLines.get(i)))) { |
| 7945 | return true; |
| 7946 | } |
| 7947 | } |
| 7948 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7949 | } |
| 7950 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7951 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7952 | int marginEndValue) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7953 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7954 | if (first) { |
| 7955 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 7956 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 7957 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7958 | if (!hasProgress) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7959 | endMargin = marginEndValue; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7960 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7961 | } |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7962 | contentView.setViewLayoutMarginEnd(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7963 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7964 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7965 | |
| 7966 | /** |
| 7967 | * Notification style for media playback notifications. |
| 7968 | * |
| 7969 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 7970 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 7971 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7972 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 7973 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 7974 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7975 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7976 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 7977 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 7978 | * {@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] | 7979 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7980 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7981 | * Notifications created with MediaStyle will have their category set to |
| 7982 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 7983 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7984 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7985 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 7986 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7987 | * the System UI can identify this as a notification representing an active media session |
| 7988 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 7989 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7990 | * <p> |
| 7991 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 7992 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 7993 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 7994 | * <p> |
| 7995 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7996 | * To use this style with your Notification, feed it to |
| 7997 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7998 | * <pre class="prettyprint"> |
| 7999 | * Notification noti = new Notification.Builder() |
| 8000 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 8001 | * .setContentTitle("Track title") |
| 8002 | * .setContentText("Artist - Album") |
| 8003 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 8004 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 8005 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8006 | * .build(); |
| 8007 | * </pre> |
| 8008 | * |
| 8009 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8010 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8011 | */ |
| 8012 | public static class MediaStyle extends Style { |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8013 | // Changing max media buttons requires also changing templates |
| 8014 | // (notification_template_material_media and notification_template_material_big_media). |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8015 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8016 | static final int MAX_MEDIA_BUTTONS = 5; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8017 | @IdRes private static final int[] MEDIA_BUTTON_IDS = { |
| 8018 | R.id.action0, |
| 8019 | R.id.action1, |
| 8020 | R.id.action2, |
| 8021 | R.id.action3, |
| 8022 | R.id.action4, |
| 8023 | }; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8024 | |
| 8025 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 8026 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8027 | |
| 8028 | public MediaStyle() { |
| 8029 | } |
| 8030 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 8031 | /** |
| 8032 | * @deprecated use {@code MediaStyle()}. |
| 8033 | */ |
| 8034 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8035 | public MediaStyle(Builder builder) { |
| 8036 | setBuilder(builder); |
| 8037 | } |
| 8038 | |
| 8039 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8040 | * 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] | 8041 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8042 | * |
| 8043 | * @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] | 8044 | */ |
| 8045 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 8046 | mActionsToShowInCompact = actions; |
| 8047 | return this; |
| 8048 | } |
| 8049 | |
| 8050 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 8051 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 8052 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8053 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 8054 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8055 | mToken = token; |
| 8056 | return this; |
| 8057 | } |
| 8058 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8059 | /** |
| 8060 | * @hide |
| 8061 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8062 | @Override |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 8063 | @UnsupportedAppUsage |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8064 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8065 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 8066 | if (wip.category == null) { |
| 8067 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 8068 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8069 | return wip; |
| 8070 | } |
| 8071 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8072 | /** |
| 8073 | * @hide |
| 8074 | */ |
| 8075 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8076 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 8077 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8078 | } |
| 8079 | |
| 8080 | /** |
| 8081 | * @hide |
| 8082 | */ |
| 8083 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 8084 | public RemoteViews makeBigContentView() { |
| 8085 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8086 | } |
| 8087 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8088 | /** |
| 8089 | * @hide |
| 8090 | */ |
| 8091 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8092 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8093 | RemoteViews expanded = makeMediaBigContentView(); |
| 8094 | return expanded != null ? expanded : makeMediaContentView(); |
| 8095 | } |
| 8096 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8097 | /** @hide */ |
| 8098 | @Override |
| 8099 | public void addExtras(Bundle extras) { |
| 8100 | super.addExtras(extras); |
| 8101 | |
| 8102 | if (mToken != null) { |
| 8103 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 8104 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 8105 | if (mActionsToShowInCompact != null) { |
| 8106 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 8107 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8108 | } |
| 8109 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8110 | /** |
| 8111 | * @hide |
| 8112 | */ |
| 8113 | @Override |
| 8114 | protected void restoreFromExtras(Bundle extras) { |
| 8115 | super.restoreFromExtras(extras); |
| 8116 | |
| 8117 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 8118 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 8119 | } |
| 8120 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 8121 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 8122 | } |
| 8123 | } |
| 8124 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8125 | /** |
| 8126 | * @hide |
| 8127 | */ |
| 8128 | @Override |
| 8129 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8130 | if (other == null || getClass() != other.getClass()) { |
| 8131 | return true; |
| 8132 | } |
| 8133 | // All fields to compare are on the Notification object |
| 8134 | return false; |
| 8135 | } |
| 8136 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8137 | private void bindMediaActionButton(RemoteViews container, @IdRes int buttonId, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8138 | Action action, StandardTemplateParams p) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8139 | final boolean tombstone = (action.actionIntent == null); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8140 | container.setViewVisibility(buttonId, View.VISIBLE); |
| 8141 | container.setImageViewIcon(buttonId, action.getIcon()); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 8142 | |
| 8143 | // If the action buttons should not be tinted, then just use the default |
| 8144 | // notification color. Otherwise, just use the passed-in color. |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8145 | Resources resources = mBuilder.mContext.getResources(); |
| 8146 | Configuration currentConfig = resources.getConfiguration(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 8147 | boolean inNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 8148 | == Configuration.UI_MODE_NIGHT_YES; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8149 | int tintColor = mBuilder.shouldTintActionButtons() || mBuilder.isColorized(p) |
| 8150 | ? getActionColor(p) |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 8151 | : ContrastColorUtil.resolveColor(mBuilder.mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 8152 | Notification.COLOR_DEFAULT, inNightMode); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 8153 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8154 | container.setDrawableTint(buttonId, false, tintColor, |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 8155 | PorterDuff.Mode.SRC_ATOP); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8156 | |
| 8157 | final TypedArray typedArray = mBuilder.mContext.obtainStyledAttributes( |
| 8158 | new int[]{ android.R.attr.colorControlHighlight }); |
| 8159 | int rippleAlpha = Color.alpha(typedArray.getColor(0, 0)); |
| 8160 | typedArray.recycle(); |
| 8161 | int rippleColor = Color.argb(rippleAlpha, Color.red(tintColor), Color.green(tintColor), |
| 8162 | Color.blue(tintColor)); |
| 8163 | container.setRippleDrawableColor(buttonId, ColorStateList.valueOf(rippleColor)); |
| 8164 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8165 | if (!tombstone) { |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8166 | container.setOnClickPendingIntent(buttonId, action.actionIntent); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8167 | } |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8168 | container.setContentDescription(buttonId, action.title); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8169 | } |
| 8170 | |
| 8171 | private RemoteViews makeMediaContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8172 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).fillTextsFrom( |
| 8173 | mBuilder); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8174 | RemoteViews view = mBuilder.applyStandardTemplate( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8175 | R.layout.notification_template_material_media, p, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8176 | null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8177 | |
| 8178 | final int numActions = mBuilder.mActions.size(); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8179 | final int numActionsToShow = mActionsToShowInCompact == null |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8180 | ? 0 |
| 8181 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8182 | if (numActionsToShow > numActions) { |
| 8183 | throw new IllegalArgumentException(String.format( |
| 8184 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 8185 | numActions, numActions - 1)); |
| 8186 | } |
| 8187 | for (int i = 0; i < MAX_MEDIA_BUTTONS_IN_COMPACT; i++) { |
| 8188 | if (i < numActionsToShow) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8189 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8190 | bindMediaActionButton(view, MEDIA_BUTTON_IDS[i], action, p); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8191 | } else { |
| 8192 | view.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8193 | } |
| 8194 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 8195 | handleImage(view); |
| 8196 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8197 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8198 | if (mBuilder.mN.hasLargeIcon()) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8199 | endMargin = R.dimen.notification_media_image_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 8200 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8201 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8202 | return view; |
| 8203 | } |
| 8204 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8205 | private int getActionColor(StandardTemplateParams p) { |
| 8206 | return mBuilder.isColorized(p) ? mBuilder.getPrimaryTextColor(p) |
| 8207 | : mBuilder.resolveContrastColor(p); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8208 | } |
| 8209 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8210 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8211 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8212 | // Dont add an expanded view if there is no more content to be revealed |
| 8213 | int actionsInCompact = mActionsToShowInCompact == null |
| 8214 | ? 0 |
| 8215 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8216 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8217 | return null; |
| 8218 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8219 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).fillTextsFrom( |
| 8220 | mBuilder); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8221 | RemoteViews big = mBuilder.applyStandardTemplate( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8222 | R.layout.notification_template_material_big_media, p , null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8223 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8224 | for (int i = 0; i < MAX_MEDIA_BUTTONS; i++) { |
| 8225 | if (i < actionCount) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8226 | bindMediaActionButton(big, MEDIA_BUTTON_IDS[i], mBuilder.mActions.get(i), p); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8227 | } else { |
| 8228 | big.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8229 | } |
| 8230 | } |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 8231 | bindMediaActionButton(big, R.id.media_seamless, new Action(R.drawable.ic_media_seamless, |
| 8232 | mBuilder.mContext.getString( |
| 8233 | com.android.internal.R.string.ext_media_seamless_action), null), p); |
| 8234 | big.setViewVisibility(R.id.media_seamless, View.GONE); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8235 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8236 | return big; |
| 8237 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8238 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8239 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8240 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8241 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 8242 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8243 | } |
| 8244 | } |
| 8245 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8246 | /** |
| 8247 | * @hide |
| 8248 | */ |
| 8249 | @Override |
| 8250 | protected boolean hasProgress() { |
| 8251 | return false; |
| 8252 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8253 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8254 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8255 | /** |
| 8256 | * Notification style for custom views that are decorated by the system |
| 8257 | * |
| 8258 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 8259 | * style and still obtain system decorations like the notification header with the expand |
| 8260 | * affordance and actions. |
| 8261 | * |
| 8262 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8263 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8264 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8265 | * corresponding custom views to display. |
| 8266 | * |
| 8267 | * To use this style with your Notification, feed it to |
| 8268 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8269 | * <pre class="prettyprint"> |
| 8270 | * Notification noti = new Notification.Builder() |
| 8271 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8272 | * .setLargeIcon(albumArtBitmap)) |
| 8273 | * .setCustomContentView(contentView); |
| 8274 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 8275 | * .build(); |
| 8276 | * </pre> |
| 8277 | */ |
| 8278 | public static class DecoratedCustomViewStyle extends Style { |
| 8279 | |
| 8280 | public DecoratedCustomViewStyle() { |
| 8281 | } |
| 8282 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8283 | /** |
| 8284 | * @hide |
| 8285 | */ |
| 8286 | public boolean displayCustomViewInline() { |
| 8287 | return true; |
| 8288 | } |
| 8289 | |
| 8290 | /** |
| 8291 | * @hide |
| 8292 | */ |
| 8293 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8294 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8295 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 8296 | } |
| 8297 | |
| 8298 | /** |
| 8299 | * @hide |
| 8300 | */ |
| 8301 | @Override |
| 8302 | public RemoteViews makeBigContentView() { |
| 8303 | return makeDecoratedBigContentView(); |
| 8304 | } |
| 8305 | |
| 8306 | /** |
| 8307 | * @hide |
| 8308 | */ |
| 8309 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8310 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8311 | return makeDecoratedHeadsUpContentView(); |
| 8312 | } |
| 8313 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8314 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 8315 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 8316 | ? mBuilder.mN.contentView |
| 8317 | : mBuilder.mN.headsUpContentView; |
| 8318 | if (mBuilder.mActions.size() == 0) { |
| 8319 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 8320 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8321 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8322 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8323 | mBuilder.getBigBaseLayoutResource(), result); |
| 8324 | buildIntoRemoteViewContent(remoteViews, headsUpContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8325 | return remoteViews; |
| 8326 | } |
| 8327 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8328 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8329 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8330 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8331 | mBuilder.getBaseLayoutResource(), result); |
| 8332 | buildIntoRemoteViewContent(remoteViews, customContent, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8333 | return remoteViews; |
| 8334 | } |
| 8335 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8336 | private RemoteViews makeDecoratedBigContentView() { |
| 8337 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 8338 | ? mBuilder.mN.contentView |
| 8339 | : mBuilder.mN.bigContentView; |
| 8340 | if (mBuilder.mActions.size() == 0) { |
| 8341 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 8342 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8343 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8344 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8345 | mBuilder.getBigBaseLayoutResource(), result); |
| 8346 | buildIntoRemoteViewContent(remoteViews, bigContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8347 | return remoteViews; |
| 8348 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8349 | |
| 8350 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8351 | RemoteViews customContent, TemplateBindResult result) { |
Selim Cinek | 6fe4a10 | 2019-01-25 14:38:24 -0800 | [diff] [blame] | 8352 | int childIndex = -1; |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8353 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8354 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8355 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8356 | customContent = customContent.clone(); |
Anthony Chen | 8f5f358 | 2017-04-11 11:18:37 -0700 | [diff] [blame] | 8357 | remoteViews.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress); |
| 8358 | remoteViews.addView(R.id.notification_main_column, customContent, 0 /* index */); |
Sunny Goyal | c12d31c | 2018-11-12 16:29:18 -0800 | [diff] [blame] | 8359 | remoteViews.addFlags(RemoteViews.FLAG_REAPPLY_DISALLOWED); |
Selim Cinek | 6fe4a10 | 2019-01-25 14:38:24 -0800 | [diff] [blame] | 8360 | childIndex = 0; |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8361 | } |
Selim Cinek | 6fe4a10 | 2019-01-25 14:38:24 -0800 | [diff] [blame] | 8362 | remoteViews.setIntTag(R.id.notification_main_column, |
| 8363 | com.android.internal.R.id.notification_custom_view_index_tag, |
| 8364 | childIndex); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8365 | // also update the end margin if there is an image |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8366 | Resources resources = mBuilder.mContext.getResources(); |
| 8367 | int endMargin = resources.getDimensionPixelSize( |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 8368 | R.dimen.notification_content_margin_end) + result.getIconMarginEnd(); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8369 | remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8370 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8371 | |
| 8372 | /** |
| 8373 | * @hide |
| 8374 | */ |
| 8375 | @Override |
| 8376 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8377 | if (other == null || getClass() != other.getClass()) { |
| 8378 | return true; |
| 8379 | } |
| 8380 | // Comparison done for all custom RemoteViews, independent of style |
| 8381 | return false; |
| 8382 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8383 | } |
| 8384 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8385 | /** |
| 8386 | * Notification style for media custom views that are decorated by the system |
| 8387 | * |
| 8388 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 8389 | * this style and still obtain system decorations like the notification header with the expand |
| 8390 | * affordance and actions. |
| 8391 | * |
| 8392 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8393 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8394 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8395 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8396 | * <p> |
| 8397 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 8398 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 8399 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8400 | * To use this style with your Notification, feed it to |
| 8401 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8402 | * <pre class="prettyprint"> |
| 8403 | * Notification noti = new Notification.Builder() |
| 8404 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8405 | * .setLargeIcon(albumArtBitmap)) |
| 8406 | * .setCustomContentView(contentView); |
| 8407 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 8408 | * .setMediaSession(mySession)) |
| 8409 | * .build(); |
| 8410 | * </pre> |
| 8411 | * |
| 8412 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 8413 | * @see android.app.Notification.MediaStyle |
| 8414 | */ |
| 8415 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 8416 | |
| 8417 | public DecoratedMediaCustomViewStyle() { |
| 8418 | } |
| 8419 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8420 | /** |
| 8421 | * @hide |
| 8422 | */ |
| 8423 | public boolean displayCustomViewInline() { |
| 8424 | return true; |
| 8425 | } |
| 8426 | |
| 8427 | /** |
| 8428 | * @hide |
| 8429 | */ |
| 8430 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8431 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 8432 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8433 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8434 | mBuilder.mN.contentView); |
| 8435 | } |
| 8436 | |
| 8437 | /** |
| 8438 | * @hide |
| 8439 | */ |
| 8440 | @Override |
| 8441 | public RemoteViews makeBigContentView() { |
| 8442 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 8443 | ? mBuilder.mN.bigContentView |
| 8444 | : mBuilder.mN.contentView; |
| 8445 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8446 | } |
| 8447 | |
| 8448 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 8449 | RemoteViews remoteViews = super.makeBigContentView(); |
| 8450 | if (remoteViews != null) { |
| 8451 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 8452 | customRemoteView); |
| 8453 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8454 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8455 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8456 | customRemoteView); |
| 8457 | } else { |
| 8458 | return null; |
| 8459 | } |
| 8460 | } |
| 8461 | |
| 8462 | /** |
| 8463 | * @hide |
| 8464 | */ |
| 8465 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8466 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8467 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 8468 | ? mBuilder.mN.headsUpContentView |
| 8469 | : mBuilder.mN.contentView; |
| 8470 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8471 | } |
| 8472 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8473 | /** |
| 8474 | * @hide |
| 8475 | */ |
| 8476 | @Override |
| 8477 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8478 | if (other == null || getClass() != other.getClass()) { |
| 8479 | return true; |
| 8480 | } |
| 8481 | // Comparison done for all custom RemoteViews, independent of style |
| 8482 | return false; |
| 8483 | } |
| 8484 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8485 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 8486 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8487 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8488 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8489 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8490 | customContent = customContent.clone(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8491 | customContent.overrideTextColors(mBuilder.getPrimaryTextColor(mBuilder.mParams)); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8492 | remoteViews.removeAllViews(id); |
| 8493 | remoteViews.addView(id, customContent); |
Sunny Goyal | c12d31c | 2018-11-12 16:29:18 -0800 | [diff] [blame] | 8494 | remoteViews.addFlags(RemoteViews.FLAG_REAPPLY_DISALLOWED); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8495 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8496 | return remoteViews; |
| 8497 | } |
| 8498 | } |
| 8499 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8500 | /** |
| 8501 | * Encapsulates the information needed to display a notification as a bubble. |
| 8502 | * |
| 8503 | * <p>A bubble is used to display app content in a floating window over the existing |
| 8504 | * foreground activity. A bubble has a collapsed state represented by an icon, |
| 8505 | * {@link BubbleMetadata.Builder#setIcon(Icon)} and an expanded state which is populated |
| 8506 | * via {@link BubbleMetadata.Builder#setIntent(PendingIntent)}.</p> |
| 8507 | * |
| 8508 | * <b>Notifications with a valid and allowed bubble will display in collapsed state |
| 8509 | * outside of the notification shade on unlocked devices. When a user interacts with the |
| 8510 | * collapsed bubble, the bubble intent will be invoked and displayed.</b> |
| 8511 | * |
| 8512 | * @see Notification.Builder#setBubbleMetadata(BubbleMetadata) |
| 8513 | */ |
| 8514 | public static final class BubbleMetadata implements Parcelable { |
| 8515 | |
| 8516 | private PendingIntent mPendingIntent; |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8517 | private PendingIntent mDeleteIntent; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8518 | private Icon mIcon; |
| 8519 | private int mDesiredHeight; |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8520 | private int mFlags; |
| 8521 | |
| 8522 | /** |
| 8523 | * If set and the app creating the bubble is in the foreground, the bubble will be posted |
| 8524 | * in its expanded state, with the contents of {@link #getIntent()} in a floating window. |
| 8525 | * |
| 8526 | * <p>If the app creating the bubble is not in the foreground this flag has no effect.</p> |
| 8527 | * |
| 8528 | * <p>Generally this flag should only be set if the user has performed an action to request |
| 8529 | * or create a bubble.</p> |
| 8530 | */ |
| 8531 | private static final int FLAG_AUTO_EXPAND_BUBBLE = 0x00000001; |
| 8532 | |
| 8533 | /** |
| 8534 | * If set and the app creating the bubble is in the foreground, the bubble will be posted |
| 8535 | * <b>without</b> the associated notification in the notification shade. Subsequent update |
| 8536 | * notifications to this bubble will post a notification in the shade. |
| 8537 | * |
| 8538 | * <p>If the app creating the bubble is not in the foreground this flag has no effect.</p> |
| 8539 | * |
| 8540 | * <p>Generally this flag should only be set if the user has performed an action to request |
| 8541 | * or create a bubble.</p> |
| 8542 | */ |
| 8543 | private static final int FLAG_SUPPRESS_INITIAL_NOTIFICATION = 0x00000002; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8544 | |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8545 | private BubbleMetadata(PendingIntent expandIntent, PendingIntent deleteIntent, |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8546 | Icon icon, int height) { |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8547 | mPendingIntent = expandIntent; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8548 | mIcon = icon; |
| 8549 | mDesiredHeight = height; |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8550 | mDeleteIntent = deleteIntent; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8551 | } |
| 8552 | |
| 8553 | private BubbleMetadata(Parcel in) { |
| 8554 | mPendingIntent = PendingIntent.CREATOR.createFromParcel(in); |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8555 | mIcon = Icon.CREATOR.createFromParcel(in); |
| 8556 | mDesiredHeight = in.readInt(); |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8557 | mFlags = in.readInt(); |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8558 | if (in.readInt() != 0) { |
| 8559 | mDeleteIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 8560 | } |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8561 | } |
| 8562 | |
| 8563 | /** |
| 8564 | * @return the pending intent used to populate the floating window for this bubble. |
| 8565 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8566 | @NonNull |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8567 | public PendingIntent getIntent() { |
| 8568 | return mPendingIntent; |
| 8569 | } |
| 8570 | |
| 8571 | /** |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8572 | * @return the pending intent to send when the bubble is dismissed by a user, if one exists. |
| 8573 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8574 | @Nullable |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8575 | public PendingIntent getDeleteIntent() { |
| 8576 | return mDeleteIntent; |
| 8577 | } |
| 8578 | |
| 8579 | /** |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8580 | * @return the title that will appear along with the app content defined by |
| 8581 | * {@link #getIntent()} for this bubble. |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8582 | * |
| 8583 | * @deprecated titles are no longer required or shown. |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8584 | */ |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8585 | @Deprecated |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8586 | public CharSequence getTitle() { |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8587 | return ""; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8588 | } |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8589 | |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8590 | /** |
| 8591 | * @return the icon that will be displayed for this bubble when it is collapsed. |
| 8592 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8593 | @NonNull |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8594 | public Icon getIcon() { |
| 8595 | return mIcon; |
| 8596 | } |
| 8597 | |
| 8598 | /** |
| 8599 | * @return the ideal height for the floating window that app content defined by |
| 8600 | * {@link #getIntent()} for this bubble. |
| 8601 | */ |
| 8602 | public int getDesiredHeight() { |
| 8603 | return mDesiredHeight; |
| 8604 | } |
| 8605 | |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8606 | /** |
| 8607 | * @return whether this bubble should auto expand when it is posted. |
| 8608 | * |
| 8609 | * @see BubbleMetadata.Builder#setAutoExpandBubble(boolean) |
| 8610 | */ |
| 8611 | public boolean getAutoExpandBubble() { |
| 8612 | return (mFlags & FLAG_AUTO_EXPAND_BUBBLE) != 0; |
| 8613 | } |
| 8614 | |
| 8615 | /** |
| 8616 | * @return whether this bubble should suppress the initial notification when it is posted. |
| 8617 | * |
| 8618 | * @see BubbleMetadata.Builder#setSuppressInitialNotification(boolean) |
| 8619 | */ |
| 8620 | public boolean getSuppressInitialNotification() { |
| 8621 | return (mFlags & FLAG_SUPPRESS_INITIAL_NOTIFICATION) != 0; |
| 8622 | } |
| 8623 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 8624 | public static final @android.annotation.NonNull Parcelable.Creator<BubbleMetadata> CREATOR = |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8625 | new Parcelable.Creator<BubbleMetadata>() { |
| 8626 | |
| 8627 | @Override |
| 8628 | public BubbleMetadata createFromParcel(Parcel source) { |
| 8629 | return new BubbleMetadata(source); |
| 8630 | } |
| 8631 | |
| 8632 | @Override |
| 8633 | public BubbleMetadata[] newArray(int size) { |
| 8634 | return new BubbleMetadata[size]; |
| 8635 | } |
| 8636 | }; |
| 8637 | |
| 8638 | @Override |
| 8639 | public int describeContents() { |
| 8640 | return 0; |
| 8641 | } |
| 8642 | |
| 8643 | @Override |
| 8644 | public void writeToParcel(Parcel out, int flags) { |
| 8645 | mPendingIntent.writeToParcel(out, 0); |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8646 | mIcon.writeToParcel(out, 0); |
| 8647 | out.writeInt(mDesiredHeight); |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8648 | out.writeInt(mFlags); |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8649 | out.writeInt(mDeleteIntent != null ? 1 : 0); |
| 8650 | if (mDeleteIntent != null) { |
| 8651 | mDeleteIntent.writeToParcel(out, 0); |
| 8652 | } |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8653 | } |
| 8654 | |
| 8655 | private void setFlags(int flags) { |
| 8656 | mFlags = flags; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8657 | } |
| 8658 | |
| 8659 | /** |
| 8660 | * Builder to construct a {@link BubbleMetadata} object. |
| 8661 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8662 | public static final class Builder { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8663 | |
| 8664 | private PendingIntent mPendingIntent; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8665 | private Icon mIcon; |
| 8666 | private int mDesiredHeight; |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8667 | private int mFlags; |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8668 | private PendingIntent mDeleteIntent; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8669 | |
| 8670 | /** |
| 8671 | * Constructs a new builder object. |
| 8672 | */ |
| 8673 | public Builder() { |
| 8674 | } |
| 8675 | |
| 8676 | /** |
| 8677 | * Sets the intent that will be used when the bubble is expanded. This will display the |
| 8678 | * app content in a floating window over the existing foreground activity. |
| 8679 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8680 | @NonNull |
| 8681 | public BubbleMetadata.Builder setIntent(@NonNull PendingIntent intent) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8682 | if (intent == null) { |
| 8683 | throw new IllegalArgumentException("Bubble requires non-null pending intent"); |
| 8684 | } |
| 8685 | mPendingIntent = intent; |
| 8686 | return this; |
| 8687 | } |
| 8688 | |
| 8689 | /** |
| 8690 | * Sets the title that will appear along with the app content for this bubble. |
| 8691 | * |
| 8692 | * <p>A title is required and should expect to fit on a single line and make sense when |
| 8693 | * shown with the content defined by {@link #setIntent(PendingIntent)}.</p> |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8694 | * |
| 8695 | * @deprecated titles are no longer required or shown. |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8696 | */ |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8697 | @Deprecated |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8698 | public BubbleMetadata.Builder setTitle(CharSequence title) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8699 | return this; |
| 8700 | } |
| 8701 | |
| 8702 | /** |
| 8703 | * Sets the icon that will represent the bubble when it is collapsed. |
| 8704 | * |
| 8705 | * <p>An icon is required and should be representative of the content within the bubble. |
| 8706 | * If your app produces multiple bubbles, the image should be unique for each of them. |
| 8707 | * </p> |
| 8708 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8709 | @NonNull |
| 8710 | public BubbleMetadata.Builder setIcon(@NonNull Icon icon) { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8711 | if (icon == null) { |
| 8712 | throw new IllegalArgumentException("Bubbles require non-null icon"); |
| 8713 | } |
| 8714 | mIcon = icon; |
| 8715 | return this; |
| 8716 | } |
| 8717 | |
| 8718 | /** |
| 8719 | * Sets the desired height for the app content defined by |
| 8720 | * {@link #setIntent(PendingIntent)}, this height may not be respected if there is not |
| 8721 | * enough space on the screen or if the provided height is too small to be useful. |
| 8722 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8723 | @NonNull |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8724 | public BubbleMetadata.Builder setDesiredHeight(int height) { |
| 8725 | mDesiredHeight = Math.max(height, 0); |
| 8726 | return this; |
| 8727 | } |
| 8728 | |
| 8729 | /** |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8730 | * If set and the app creating the bubble is in the foreground, the bubble will be |
| 8731 | * posted in its expanded state, with the contents of {@link #getIntent()} in a |
| 8732 | * floating window. |
| 8733 | * |
| 8734 | * <p>If the app creating the bubble is not in the foreground this flag has no effect. |
| 8735 | * </p> |
| 8736 | * |
| 8737 | * <p>Generally this flag should only be set if the user has performed an action to |
| 8738 | * request or create a bubble.</p> |
| 8739 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8740 | @NonNull |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8741 | public BubbleMetadata.Builder setAutoExpandBubble(boolean shouldExpand) { |
| 8742 | setFlag(FLAG_AUTO_EXPAND_BUBBLE, shouldExpand); |
| 8743 | return this; |
| 8744 | } |
| 8745 | |
| 8746 | /** |
| 8747 | * If set and the app creating the bubble is in the foreground, the bubble will be |
| 8748 | * posted <b>without</b> the associated notification in the notification shade. |
| 8749 | * Subsequent update notifications to this bubble will post a notification in the shade. |
| 8750 | * |
| 8751 | * <p>If the app creating the bubble is not in the foreground this flag has no effect. |
| 8752 | * </p> |
| 8753 | * |
| 8754 | * <p>Generally this flag should only be set if the user has performed an action to |
| 8755 | * request or create a bubble.</p> |
| 8756 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8757 | @NonNull |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8758 | public BubbleMetadata.Builder setSuppressInitialNotification( |
| 8759 | boolean shouldSupressNotif) { |
| 8760 | setFlag(FLAG_SUPPRESS_INITIAL_NOTIFICATION, shouldSupressNotif); |
| 8761 | return this; |
| 8762 | } |
| 8763 | |
| 8764 | /** |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8765 | * Sets an optional intent to send when this bubble is explicitly removed by the user. |
| 8766 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8767 | @NonNull |
| 8768 | public BubbleMetadata.Builder setDeleteIntent(@Nullable PendingIntent deleteIntent) { |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8769 | mDeleteIntent = deleteIntent; |
| 8770 | return this; |
| 8771 | } |
| 8772 | |
| 8773 | /** |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8774 | * Creates the {@link BubbleMetadata} defined by this builder. |
| 8775 | * <p>Will throw {@link IllegalStateException} if required fields have not been set |
| 8776 | * on this builder.</p> |
| 8777 | */ |
Mady Mellor | cf8f1b2 | 2019-03-07 14:08:21 -0800 | [diff] [blame^] | 8778 | @NonNull |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8779 | public BubbleMetadata build() { |
| 8780 | if (mPendingIntent == null) { |
| 8781 | throw new IllegalStateException("Must supply pending intent to bubble"); |
| 8782 | } |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8783 | if (mIcon == null) { |
| 8784 | throw new IllegalStateException("Must supply an icon for the bubble"); |
| 8785 | } |
Mady Mellor | 138f4c9 | 2019-02-20 16:12:17 -0800 | [diff] [blame] | 8786 | BubbleMetadata data = new BubbleMetadata(mPendingIntent, mDeleteIntent, |
Mady Mellor | 1ab4aa8 | 2019-02-19 16:41:55 -0800 | [diff] [blame] | 8787 | mIcon, mDesiredHeight); |
Mady Mellor | 0157ff2 | 2019-01-24 15:31:48 -0800 | [diff] [blame] | 8788 | data.setFlags(mFlags); |
| 8789 | return data; |
| 8790 | } |
| 8791 | |
| 8792 | /** |
| 8793 | * @hide |
| 8794 | */ |
| 8795 | public BubbleMetadata.Builder setFlag(int mask, boolean value) { |
| 8796 | if (value) { |
| 8797 | mFlags |= mask; |
| 8798 | } else { |
| 8799 | mFlags &= ~mask; |
| 8800 | } |
| 8801 | return this; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 8802 | } |
| 8803 | } |
| 8804 | } |
| 8805 | |
| 8806 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8807 | // When adding a new Style subclass here, don't forget to update |
| 8808 | // Builder.getNotificationStyleClass. |
| 8809 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8810 | /** |
| 8811 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 8812 | * metadata or change options on a notification builder. |
| 8813 | */ |
| 8814 | public interface Extender { |
| 8815 | /** |
| 8816 | * Apply this extender to a notification builder. |
| 8817 | * @param builder the builder to be modified. |
| 8818 | * @return the build object for chaining. |
| 8819 | */ |
| 8820 | public Builder extend(Builder builder); |
| 8821 | } |
| 8822 | |
| 8823 | /** |
| 8824 | * Helper class to add wearable extensions to notifications. |
| 8825 | * <p class="note"> See |
| 8826 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 8827 | * for Android Wear</a> for more information on how to use this class. |
| 8828 | * <p> |
| 8829 | * To create a notification with wearable extensions: |
| 8830 | * <ol> |
| 8831 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 8832 | * properties. |
| 8833 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 8834 | * <li>Set wearable-specific properties using the |
| 8835 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 8836 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 8837 | * notification. |
| 8838 | * <li>Post the notification to the notification system with the |
| 8839 | * {@code NotificationManager.notify(...)} methods. |
| 8840 | * </ol> |
| 8841 | * |
| 8842 | * <pre class="prettyprint"> |
| 8843 | * Notification notif = new Notification.Builder(mContext) |
| 8844 | * .setContentTitle("New mail from " + sender.toString()) |
| 8845 | * .setContentText(subject) |
| 8846 | * .setSmallIcon(R.drawable.new_mail) |
| 8847 | * .extend(new Notification.WearableExtender() |
| 8848 | * .setContentIcon(R.drawable.new_mail)) |
| 8849 | * .build(); |
| 8850 | * NotificationManager notificationManger = |
| 8851 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 8852 | * notificationManger.notify(0, notif);</pre> |
| 8853 | * |
| 8854 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 8855 | * {@code WearableExtender(Notification)} constructor, |
| 8856 | * and then using the {@code get} methods to access values. |
| 8857 | * |
| 8858 | * <pre class="prettyprint"> |
| 8859 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 8860 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8861 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8862 | */ |
| 8863 | public static final class WearableExtender implements Extender { |
| 8864 | /** |
| 8865 | * Sentinel value for an action index that is unset. |
| 8866 | */ |
| 8867 | public static final int UNSET_ACTION_INDEX = -1; |
| 8868 | |
| 8869 | /** |
| 8870 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 8871 | * default sizing. |
| 8872 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 8873 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8874 | * on their content. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8875 | * |
| 8876 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8877 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8878 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8879 | public static final int SIZE_DEFAULT = 0; |
| 8880 | |
| 8881 | /** |
| 8882 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8883 | * with an extra small size. |
| 8884 | * <p>This value is only applicable for custom display notifications created using |
| 8885 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8886 | * |
| 8887 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8888 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8889 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8890 | public static final int SIZE_XSMALL = 1; |
| 8891 | |
| 8892 | /** |
| 8893 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8894 | * with a small size. |
| 8895 | * <p>This value is only applicable for custom display notifications created using |
| 8896 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8897 | * |
| 8898 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8899 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8900 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8901 | public static final int SIZE_SMALL = 2; |
| 8902 | |
| 8903 | /** |
| 8904 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8905 | * with a medium size. |
| 8906 | * <p>This value is only applicable for custom display notifications created using |
| 8907 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8908 | * |
| 8909 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8910 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8911 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8912 | public static final int SIZE_MEDIUM = 3; |
| 8913 | |
| 8914 | /** |
| 8915 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8916 | * with a large size. |
| 8917 | * <p>This value is only applicable for custom display notifications created using |
| 8918 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8919 | * |
| 8920 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8921 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8922 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8923 | public static final int SIZE_LARGE = 4; |
| 8924 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8925 | /** |
| 8926 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8927 | * full screen. |
| 8928 | * <p>This value is only applicable for custom display notifications created using |
| 8929 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8930 | * |
| 8931 | * @deprecated Display intents are no longer supported. |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8932 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8933 | @Deprecated |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8934 | public static final int SIZE_FULL_SCREEN = 5; |
| 8935 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8936 | /** |
| 8937 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 8938 | * short amount of time when this notification is displayed on the screen. This |
| 8939 | * is the default value. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8940 | * |
| 8941 | * @deprecated This feature is no longer supported. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8942 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8943 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8944 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 8945 | |
| 8946 | /** |
| 8947 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 8948 | * 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] | 8949 | * |
| 8950 | * @deprecated This feature is no longer supported. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8951 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8952 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8953 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 8954 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8955 | /** Notification extra which contains wearable extensions */ |
| 8956 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 8957 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 8958 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8959 | private static final String KEY_ACTIONS = "actions"; |
| 8960 | private static final String KEY_FLAGS = "flags"; |
| 8961 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 8962 | private static final String KEY_PAGES = "pages"; |
| 8963 | private static final String KEY_BACKGROUND = "background"; |
| 8964 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 8965 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 8966 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 8967 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 8968 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 8969 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8970 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8971 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8972 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8973 | |
| 8974 | // Flags bitwise-ored to mFlags |
| 8975 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 8976 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 8977 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 8978 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8979 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 8980 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8981 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8982 | |
| 8983 | // Default value for flags integer |
| 8984 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 8985 | |
| 8986 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 8987 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 8988 | |
| 8989 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 8990 | private int mFlags = DEFAULT_FLAGS; |
| 8991 | private PendingIntent mDisplayIntent; |
| 8992 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 8993 | private Bitmap mBackground; |
| 8994 | private int mContentIcon; |
| 8995 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 8996 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 8997 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 8998 | private int mCustomContentHeight; |
| 8999 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9000 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9001 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9002 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9003 | |
| 9004 | /** |
| 9005 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 9006 | * options. |
| 9007 | */ |
| 9008 | public WearableExtender() { |
| 9009 | } |
| 9010 | |
| 9011 | public WearableExtender(Notification notif) { |
| 9012 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 9013 | if (wearableBundle != null) { |
| 9014 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 9015 | if (actions != null) { |
| 9016 | mActions.addAll(actions); |
| 9017 | } |
| 9018 | |
| 9019 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 9020 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 9021 | |
| 9022 | Notification[] pages = getNotificationArrayFromBundle( |
| 9023 | wearableBundle, KEY_PAGES); |
| 9024 | if (pages != null) { |
| 9025 | Collections.addAll(mPages, pages); |
| 9026 | } |
| 9027 | |
| 9028 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 9029 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 9030 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 9031 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 9032 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 9033 | UNSET_ACTION_INDEX); |
| 9034 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 9035 | SIZE_DEFAULT); |
| 9036 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 9037 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9038 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9039 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9040 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9041 | } |
| 9042 | } |
| 9043 | |
| 9044 | /** |
| 9045 | * Apply wearable extensions to a notification that is being built. This is typically |
| 9046 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 9047 | * {@link android.app.Notification.Builder}. |
| 9048 | */ |
| 9049 | @Override |
| 9050 | public Notification.Builder extend(Notification.Builder builder) { |
| 9051 | Bundle wearableBundle = new Bundle(); |
| 9052 | |
| 9053 | if (!mActions.isEmpty()) { |
| 9054 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 9055 | } |
| 9056 | if (mFlags != DEFAULT_FLAGS) { |
| 9057 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 9058 | } |
| 9059 | if (mDisplayIntent != null) { |
| 9060 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 9061 | } |
| 9062 | if (!mPages.isEmpty()) { |
| 9063 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 9064 | new Notification[mPages.size()])); |
| 9065 | } |
| 9066 | if (mBackground != null) { |
| 9067 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 9068 | } |
| 9069 | if (mContentIcon != 0) { |
| 9070 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 9071 | } |
| 9072 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 9073 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 9074 | } |
| 9075 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 9076 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 9077 | mContentActionIndex); |
| 9078 | } |
| 9079 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 9080 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 9081 | } |
| 9082 | if (mCustomContentHeight != 0) { |
| 9083 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 9084 | } |
| 9085 | if (mGravity != DEFAULT_GRAVITY) { |
| 9086 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 9087 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9088 | if (mHintScreenTimeout != 0) { |
| 9089 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 9090 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9091 | if (mDismissalId != null) { |
| 9092 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 9093 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9094 | if (mBridgeTag != null) { |
| 9095 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 9096 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9097 | |
| 9098 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 9099 | return builder; |
| 9100 | } |
| 9101 | |
| 9102 | @Override |
| 9103 | public WearableExtender clone() { |
| 9104 | WearableExtender that = new WearableExtender(); |
| 9105 | that.mActions = new ArrayList<Action>(this.mActions); |
| 9106 | that.mFlags = this.mFlags; |
| 9107 | that.mDisplayIntent = this.mDisplayIntent; |
| 9108 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 9109 | that.mBackground = this.mBackground; |
| 9110 | that.mContentIcon = this.mContentIcon; |
| 9111 | that.mContentIconGravity = this.mContentIconGravity; |
| 9112 | that.mContentActionIndex = this.mContentActionIndex; |
| 9113 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 9114 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 9115 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9116 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9117 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9118 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9119 | return that; |
| 9120 | } |
| 9121 | |
| 9122 | /** |
| 9123 | * Add a wearable action to this notification. |
| 9124 | * |
| 9125 | * <p>When wearable actions are added using this method, the set of actions that |
| 9126 | * show on a wearable device splits from devices that only show actions added |
| 9127 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 9128 | * of which actions display on different devices. |
| 9129 | * |
| 9130 | * @param action the action to add to this notification |
| 9131 | * @return this object for method chaining |
| 9132 | * @see android.app.Notification.Action |
| 9133 | */ |
| 9134 | public WearableExtender addAction(Action action) { |
| 9135 | mActions.add(action); |
| 9136 | return this; |
| 9137 | } |
| 9138 | |
| 9139 | /** |
| 9140 | * Adds wearable actions to this notification. |
| 9141 | * |
| 9142 | * <p>When wearable actions are added using this method, the set of actions that |
| 9143 | * show on a wearable device splits from devices that only show actions added |
| 9144 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 9145 | * of which actions display on different devices. |
| 9146 | * |
| 9147 | * @param actions the actions to add to this notification |
| 9148 | * @return this object for method chaining |
| 9149 | * @see android.app.Notification.Action |
| 9150 | */ |
| 9151 | public WearableExtender addActions(List<Action> actions) { |
| 9152 | mActions.addAll(actions); |
| 9153 | return this; |
| 9154 | } |
| 9155 | |
| 9156 | /** |
| 9157 | * Clear all wearable actions present on this builder. |
| 9158 | * @return this object for method chaining. |
| 9159 | * @see #addAction |
| 9160 | */ |
| 9161 | public WearableExtender clearActions() { |
| 9162 | mActions.clear(); |
| 9163 | return this; |
| 9164 | } |
| 9165 | |
| 9166 | /** |
| 9167 | * Get the wearable actions present on this notification. |
| 9168 | */ |
| 9169 | public List<Action> getActions() { |
| 9170 | return mActions; |
| 9171 | } |
| 9172 | |
| 9173 | /** |
| 9174 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9175 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 9176 | * |
| 9177 | * <pre class="prettyprint"> |
| 9178 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 9179 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 9180 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 9181 | * Notification notif = new Notification.Builder(context) |
| 9182 | * .extend(new Notification.WearableExtender() |
| 9183 | * .setDisplayIntent(displayPendingIntent) |
| 9184 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 9185 | * .build();</pre> |
| 9186 | * |
| 9187 | * <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] | 9188 | * should have an empty task affinity. It is also recommended to use the device |
| 9189 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9190 | * |
| 9191 | * <p>Example AndroidManifest.xml entry: |
| 9192 | * <pre class="prettyprint"> |
| 9193 | * <activity android:name="com.example.MyDisplayActivity" |
| 9194 | * android:exported="true" |
| 9195 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 9196 | * android:taskAffinity="" |
| 9197 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9198 | * |
| 9199 | * @param intent the {@link PendingIntent} for an activity |
| 9200 | * @return this object for method chaining |
| 9201 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9202 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9203 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9204 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9205 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 9206 | mDisplayIntent = intent; |
| 9207 | return this; |
| 9208 | } |
| 9209 | |
| 9210 | /** |
| 9211 | * Get the intent to launch inside of an activity view when displaying this |
| 9212 | * notification. This {@code PendingIntent} should be for an activity. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9213 | * |
| 9214 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9215 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9216 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9217 | public PendingIntent getDisplayIntent() { |
| 9218 | return mDisplayIntent; |
| 9219 | } |
| 9220 | |
| 9221 | /** |
| 9222 | * Add an additional page of content to display with this notification. The current |
| 9223 | * notification forms the first page, and pages added using this function form |
| 9224 | * subsequent pages. This field can be used to separate a notification into multiple |
| 9225 | * sections. |
| 9226 | * |
| 9227 | * @param page the notification to add as another page |
| 9228 | * @return this object for method chaining |
| 9229 | * @see android.app.Notification.WearableExtender#getPages |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9230 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9231 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9232 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9233 | public WearableExtender addPage(Notification page) { |
| 9234 | mPages.add(page); |
| 9235 | return this; |
| 9236 | } |
| 9237 | |
| 9238 | /** |
| 9239 | * Add additional pages of content to display with this notification. The current |
| 9240 | * notification forms the first page, and pages added using this function form |
| 9241 | * subsequent pages. This field can be used to separate a notification into multiple |
| 9242 | * sections. |
| 9243 | * |
| 9244 | * @param pages a list of notifications |
| 9245 | * @return this object for method chaining |
| 9246 | * @see android.app.Notification.WearableExtender#getPages |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9247 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9248 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9249 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9250 | public WearableExtender addPages(List<Notification> pages) { |
| 9251 | mPages.addAll(pages); |
| 9252 | return this; |
| 9253 | } |
| 9254 | |
| 9255 | /** |
| 9256 | * Clear all additional pages present on this builder. |
| 9257 | * @return this object for method chaining. |
| 9258 | * @see #addPage |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9259 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9260 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9261 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9262 | public WearableExtender clearPages() { |
| 9263 | mPages.clear(); |
| 9264 | return this; |
| 9265 | } |
| 9266 | |
| 9267 | /** |
| 9268 | * Get the array of additional pages of content for displaying this notification. The |
| 9269 | * current notification forms the first page, and elements within this array form |
| 9270 | * subsequent pages. This field can be used to separate a notification into multiple |
| 9271 | * sections. |
| 9272 | * @return the pages for this notification |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9273 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9274 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9275 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9276 | public List<Notification> getPages() { |
| 9277 | return mPages; |
| 9278 | } |
| 9279 | |
| 9280 | /** |
| 9281 | * Set a background image to be displayed behind the notification content. |
| 9282 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 9283 | * will work with any notification style. |
| 9284 | * |
| 9285 | * @param background the background bitmap |
| 9286 | * @return this object for method chaining |
| 9287 | * @see android.app.Notification.WearableExtender#getBackground |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9288 | * @deprecated Background images are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9289 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9290 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9291 | public WearableExtender setBackground(Bitmap background) { |
| 9292 | mBackground = background; |
| 9293 | return this; |
| 9294 | } |
| 9295 | |
| 9296 | /** |
| 9297 | * Get a background image to be displayed behind the notification content. |
| 9298 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 9299 | * will work with any notification style. |
| 9300 | * |
| 9301 | * @return the background image |
| 9302 | * @see android.app.Notification.WearableExtender#setBackground |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9303 | * @deprecated Background images are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9304 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9305 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9306 | public Bitmap getBackground() { |
| 9307 | return mBackground; |
| 9308 | } |
| 9309 | |
| 9310 | /** |
| 9311 | * Set an icon that goes with the content of this notification. |
| 9312 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9313 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9314 | public WearableExtender setContentIcon(int icon) { |
| 9315 | mContentIcon = icon; |
| 9316 | return this; |
| 9317 | } |
| 9318 | |
| 9319 | /** |
| 9320 | * Get an icon that goes with the content of this notification. |
| 9321 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9322 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9323 | public int getContentIcon() { |
| 9324 | return mContentIcon; |
| 9325 | } |
| 9326 | |
| 9327 | /** |
| 9328 | * Set the gravity that the content icon should have within the notification display. |
| 9329 | * Supported values include {@link android.view.Gravity#START} and |
| 9330 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 9331 | * @see #setContentIcon |
| 9332 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9333 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9334 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 9335 | mContentIconGravity = contentIconGravity; |
| 9336 | return this; |
| 9337 | } |
| 9338 | |
| 9339 | /** |
| 9340 | * Get the gravity that the content icon should have within the notification display. |
| 9341 | * Supported values include {@link android.view.Gravity#START} and |
| 9342 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 9343 | * @see #getContentIcon |
| 9344 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9345 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9346 | public int getContentIconGravity() { |
| 9347 | return mContentIconGravity; |
| 9348 | } |
| 9349 | |
| 9350 | /** |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9351 | * Set an action from this notification's actions as the primary action. If the action has a |
| 9352 | * {@link RemoteInput} associated with it, shortcuts to the options for that input are shown |
| 9353 | * directly on the notification. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9354 | * |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9355 | * @param actionIndex The index of the primary action. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9356 | * If wearable actions were added to the main notification, this index |
| 9357 | * will apply to that list, otherwise it will apply to the regular |
| 9358 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9359 | */ |
| 9360 | public WearableExtender setContentAction(int actionIndex) { |
| 9361 | mContentActionIndex = actionIndex; |
| 9362 | return this; |
| 9363 | } |
| 9364 | |
| 9365 | /** |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9366 | * Get the index of the notification action, if any, that was specified as the primary |
| 9367 | * action. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 9368 | * |
| 9369 | * <p>If wearable specific actions were added to the main notification, this index will |
| 9370 | * 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] | 9371 | * |
| 9372 | * @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] | 9373 | */ |
| 9374 | public int getContentAction() { |
| 9375 | return mContentActionIndex; |
| 9376 | } |
| 9377 | |
| 9378 | /** |
| 9379 | * Set the gravity that this notification should have within the available viewport space. |
| 9380 | * Supported values include {@link android.view.Gravity#TOP}, |
| 9381 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 9382 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 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 WearableExtender setGravity(int gravity) { |
| 9386 | mGravity = gravity; |
| 9387 | return this; |
| 9388 | } |
| 9389 | |
| 9390 | /** |
| 9391 | * Get the gravity that this notification should have within the available viewport space. |
| 9392 | * Supported values include {@link android.view.Gravity#TOP}, |
| 9393 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 9394 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 9395 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9396 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9397 | public int getGravity() { |
| 9398 | return mGravity; |
| 9399 | } |
| 9400 | |
| 9401 | /** |
| 9402 | * Set the custom size preset for the display of this notification out of the available |
| 9403 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 9404 | * {@link #SIZE_LARGE}. |
| 9405 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 9406 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 9407 | * documentation for the preset in question. See also |
| 9408 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 9409 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9410 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9411 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 9412 | mCustomSizePreset = sizePreset; |
| 9413 | return this; |
| 9414 | } |
| 9415 | |
| 9416 | /** |
| 9417 | * Get the custom size preset for the display of this notification out of the available |
| 9418 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 9419 | * {@link #SIZE_LARGE}. |
| 9420 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 9421 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 9422 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 9423 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9424 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9425 | public int getCustomSizePreset() { |
| 9426 | return mCustomSizePreset; |
| 9427 | } |
| 9428 | |
| 9429 | /** |
| 9430 | * Set the custom height in pixels for the display of this notification's content. |
| 9431 | * <p>This option is only available for custom display notifications created |
| 9432 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 9433 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 9434 | * {@link #getCustomContentHeight}. |
| 9435 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9436 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9437 | public WearableExtender setCustomContentHeight(int height) { |
| 9438 | mCustomContentHeight = height; |
| 9439 | return this; |
| 9440 | } |
| 9441 | |
| 9442 | /** |
| 9443 | * Get the custom height in pixels for the display of this notification's content. |
| 9444 | * <p>This option is only available for custom display notifications created |
| 9445 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 9446 | * {@link #setCustomContentHeight}. |
| 9447 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9448 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9449 | public int getCustomContentHeight() { |
| 9450 | return mCustomContentHeight; |
| 9451 | } |
| 9452 | |
| 9453 | /** |
| 9454 | * Set whether the scrolling position for the contents of this notification should start |
| 9455 | * at the bottom of the contents instead of the top when the contents are too long to |
| 9456 | * display within the screen. Default is false (start scroll at the top). |
| 9457 | */ |
| 9458 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 9459 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 9460 | return this; |
| 9461 | } |
| 9462 | |
| 9463 | /** |
| 9464 | * Get whether the scrolling position for the contents of this notification should start |
| 9465 | * at the bottom of the contents instead of the top when the contents are too long to |
| 9466 | * display within the screen. Default is false (start scroll at the top). |
| 9467 | */ |
| 9468 | public boolean getStartScrollBottom() { |
| 9469 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 9470 | } |
| 9471 | |
| 9472 | /** |
| 9473 | * Set whether the content intent is available when the wearable device is not connected |
| 9474 | * to a companion device. The user can still trigger this intent when the wearable device |
| 9475 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 9476 | * Defaults to true. |
| 9477 | */ |
| 9478 | public WearableExtender setContentIntentAvailableOffline( |
| 9479 | boolean contentIntentAvailableOffline) { |
| 9480 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 9481 | return this; |
| 9482 | } |
| 9483 | |
| 9484 | /** |
| 9485 | * Get whether the content intent is available when the wearable device is not connected |
| 9486 | * to a companion device. The user can still trigger this intent when the wearable device |
| 9487 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 9488 | * Defaults to true. |
| 9489 | */ |
| 9490 | public boolean getContentIntentAvailableOffline() { |
| 9491 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 9492 | } |
| 9493 | |
| 9494 | /** |
| 9495 | * Set a hint that this notification's icon should not be displayed. |
| 9496 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 9497 | * @return this object for method chaining |
| 9498 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9499 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9500 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 9501 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 9502 | return this; |
| 9503 | } |
| 9504 | |
| 9505 | /** |
| 9506 | * Get a hint that this notification's icon should not be displayed. |
| 9507 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 9508 | * The default value is {@code false} if this was never set. |
| 9509 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9510 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9511 | public boolean getHintHideIcon() { |
| 9512 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 9513 | } |
| 9514 | |
| 9515 | /** |
| 9516 | * Set a visual hint that only the background image of this notification should be |
| 9517 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 9518 | * to sub-pages added using {@link #addPage}. |
| 9519 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9520 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9521 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 9522 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 9523 | return this; |
| 9524 | } |
| 9525 | |
| 9526 | /** |
| 9527 | * Get a visual hint that only the background image of this notification should be |
| 9528 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 9529 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 9530 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9531 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9532 | public boolean getHintShowBackgroundOnly() { |
| 9533 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 9534 | } |
| 9535 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9536 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 9537 | * Set a hint that this notification's background should not be clipped if possible, |
| 9538 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 9539 | * 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] | 9540 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 9541 | * @return this object for method chaining |
| 9542 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9543 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9544 | public WearableExtender setHintAvoidBackgroundClipping( |
| 9545 | boolean hintAvoidBackgroundClipping) { |
| 9546 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 9547 | return this; |
| 9548 | } |
| 9549 | |
| 9550 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 9551 | * Get a hint that this notification's background should not be clipped if possible, |
| 9552 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 9553 | * 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] | 9554 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 9555 | * otherwise. The default value is {@code false} if this was never set. |
| 9556 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9557 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9558 | public boolean getHintAvoidBackgroundClipping() { |
| 9559 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 9560 | } |
| 9561 | |
| 9562 | /** |
| 9563 | * Set a hint that the screen should remain on for at least this duration when |
| 9564 | * this notification is displayed on the screen. |
| 9565 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 9566 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 9567 | * @return this object for method chaining |
| 9568 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9569 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9570 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 9571 | mHintScreenTimeout = timeout; |
| 9572 | return this; |
| 9573 | } |
| 9574 | |
| 9575 | /** |
| 9576 | * Get the duration, in milliseconds, that the screen should remain on for |
| 9577 | * when this notification is displayed. |
| 9578 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 9579 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 9580 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9581 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9582 | public int getHintScreenTimeout() { |
| 9583 | return mHintScreenTimeout; |
| 9584 | } |
| 9585 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9586 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9587 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 9588 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 9589 | * qr codes, as well as other simple black-and-white tickets. |
| 9590 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 9591 | * @return this object for method chaining |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9592 | * @deprecated This feature is no longer supported. |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9593 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9594 | @Deprecated |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9595 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 9596 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 9597 | return this; |
| 9598 | } |
| 9599 | |
| 9600 | /** |
| 9601 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 9602 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 9603 | * qr codes, as well as other simple black-and-white tickets. |
| 9604 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 9605 | * otherwise. The default value is {@code false} if this was never set. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9606 | * @deprecated This feature is no longer supported. |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9607 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9608 | @Deprecated |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9609 | public boolean getHintAmbientBigPicture() { |
| 9610 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 9611 | } |
| 9612 | |
| 9613 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9614 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 9615 | * directly, telling the platform that it can generate the appropriate transitions. |
| 9616 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 9617 | * an activity and transitions should be generated, false otherwise. |
| 9618 | * @return this object for method chaining |
| 9619 | */ |
| 9620 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 9621 | boolean hintContentIntentLaunchesActivity) { |
| 9622 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 9623 | return this; |
| 9624 | } |
| 9625 | |
| 9626 | /** |
| 9627 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 9628 | * directly, telling the platform that it can generate the appropriate transitions |
| 9629 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 9630 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 9631 | */ |
| 9632 | public boolean getHintContentIntentLaunchesActivity() { |
| 9633 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 9634 | } |
| 9635 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9636 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9637 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 9638 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 9639 | * 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] | 9640 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9641 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9642 | * @param dismissalId the dismissal id of the notification. |
| 9643 | * @return this object for method chaining |
| 9644 | */ |
| 9645 | public WearableExtender setDismissalId(String dismissalId) { |
| 9646 | mDismissalId = dismissalId; |
| 9647 | return this; |
| 9648 | } |
| 9649 | |
| 9650 | /** |
| 9651 | * Returns the dismissal id of the notification. |
| 9652 | * @return the dismissal id of the notification or null if it has not been set. |
| 9653 | */ |
| 9654 | public String getDismissalId() { |
| 9655 | return mDismissalId; |
| 9656 | } |
| 9657 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9658 | /** |
| 9659 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 9660 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 9661 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 9662 | * Features to Notifications</a> for more information. |
| 9663 | * @param bridgeTag the bridge tag of the notification. |
| 9664 | * @return this object for method chaining |
| 9665 | */ |
| 9666 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 9667 | mBridgeTag = bridgeTag; |
| 9668 | return this; |
| 9669 | } |
| 9670 | |
| 9671 | /** |
| 9672 | * Returns the bridge tag of the notification. |
| 9673 | * @return the bridge tag or null if not present. |
| 9674 | */ |
| 9675 | public String getBridgeTag() { |
| 9676 | return mBridgeTag; |
| 9677 | } |
| 9678 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9679 | private void setFlag(int mask, boolean value) { |
| 9680 | if (value) { |
| 9681 | mFlags |= mask; |
| 9682 | } else { |
| 9683 | mFlags &= ~mask; |
| 9684 | } |
| 9685 | } |
| 9686 | } |
| 9687 | |
| 9688 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9689 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 9690 | * with car extensions: |
| 9691 | * |
| 9692 | * <ol> |
| 9693 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 9694 | * properties. |
| 9695 | * <li>Create a {@link CarExtender}. |
| 9696 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 9697 | * {@link CarExtender}. |
| 9698 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9699 | * to apply the extensions to a notification. |
| 9700 | * </ol> |
| 9701 | * |
| 9702 | * <pre class="prettyprint"> |
| 9703 | * Notification notification = new Notification.Builder(context) |
| 9704 | * ... |
| 9705 | * .extend(new CarExtender() |
| 9706 | * .set*(...)) |
| 9707 | * .build(); |
| 9708 | * </pre> |
| 9709 | * |
| 9710 | * <p>Car extensions can be accessed on an existing notification by using the |
| 9711 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 9712 | * to access values. |
| 9713 | */ |
| 9714 | public static final class CarExtender implements Extender { |
| 9715 | private static final String TAG = "CarExtender"; |
| 9716 | |
| 9717 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 9718 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 9719 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 9720 | private static final String EXTRA_COLOR = "app_color"; |
| 9721 | |
| 9722 | private Bitmap mLargeIcon; |
| 9723 | private UnreadConversation mUnreadConversation; |
| 9724 | private int mColor = Notification.COLOR_DEFAULT; |
| 9725 | |
| 9726 | /** |
| 9727 | * Create a {@link CarExtender} with default options. |
| 9728 | */ |
| 9729 | public CarExtender() { |
| 9730 | } |
| 9731 | |
| 9732 | /** |
| 9733 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 9734 | * |
| 9735 | * @param notif The notification from which to copy options. |
| 9736 | */ |
| 9737 | public CarExtender(Notification notif) { |
| 9738 | Bundle carBundle = notif.extras == null ? |
| 9739 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 9740 | if (carBundle != null) { |
| 9741 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 9742 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 9743 | |
| 9744 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 9745 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 9746 | } |
| 9747 | } |
| 9748 | |
| 9749 | /** |
| 9750 | * Apply car extensions to a notification that is being built. This is typically called by |
| 9751 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9752 | * method of {@link Notification.Builder}. |
| 9753 | */ |
| 9754 | @Override |
| 9755 | public Notification.Builder extend(Notification.Builder builder) { |
| 9756 | Bundle carExtensions = new Bundle(); |
| 9757 | |
| 9758 | if (mLargeIcon != null) { |
| 9759 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 9760 | } |
| 9761 | if (mColor != Notification.COLOR_DEFAULT) { |
| 9762 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 9763 | } |
| 9764 | |
| 9765 | if (mUnreadConversation != null) { |
| 9766 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 9767 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 9768 | } |
| 9769 | |
| 9770 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 9771 | return builder; |
| 9772 | } |
| 9773 | |
| 9774 | /** |
| 9775 | * Sets the accent color to use when Android Auto presents the notification. |
| 9776 | * |
| 9777 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 9778 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 9779 | * automotive setting. This method can be used to override the color provided in the |
| 9780 | * notification in such a situation. |
| 9781 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9782 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9783 | mColor = color; |
| 9784 | return this; |
| 9785 | } |
| 9786 | |
| 9787 | /** |
| 9788 | * Gets the accent color. |
| 9789 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 9790 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9791 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9792 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9793 | public int getColor() { |
| 9794 | return mColor; |
| 9795 | } |
| 9796 | |
| 9797 | /** |
| 9798 | * Sets the large icon of the car notification. |
| 9799 | * |
| 9800 | * If no large icon is set in the extender, Android Auto will display the icon |
| 9801 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 9802 | * |
| 9803 | * @param largeIcon The large icon to use in the car notification. |
| 9804 | * @return This object for method chaining. |
| 9805 | */ |
| 9806 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 9807 | mLargeIcon = largeIcon; |
| 9808 | return this; |
| 9809 | } |
| 9810 | |
| 9811 | /** |
| 9812 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 9813 | * |
| 9814 | * @return The large icon for the car notification. |
| 9815 | * @see CarExtender#setLargeIcon |
| 9816 | */ |
| 9817 | public Bitmap getLargeIcon() { |
| 9818 | return mLargeIcon; |
| 9819 | } |
| 9820 | |
| 9821 | /** |
| 9822 | * Sets the unread conversation in a message notification. |
| 9823 | * |
| 9824 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 9825 | * @return This object for method chaining. |
| 9826 | */ |
| 9827 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 9828 | mUnreadConversation = unreadConversation; |
| 9829 | return this; |
| 9830 | } |
| 9831 | |
| 9832 | /** |
| 9833 | * Returns the unread conversation conveyed by this notification. |
| 9834 | * @see #setUnreadConversation(UnreadConversation) |
| 9835 | */ |
| 9836 | public UnreadConversation getUnreadConversation() { |
| 9837 | return mUnreadConversation; |
| 9838 | } |
| 9839 | |
| 9840 | /** |
| 9841 | * A class which holds the unread messages from a conversation. |
| 9842 | */ |
| 9843 | public static class UnreadConversation { |
| 9844 | private static final String KEY_AUTHOR = "author"; |
| 9845 | private static final String KEY_TEXT = "text"; |
| 9846 | private static final String KEY_MESSAGES = "messages"; |
| 9847 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 9848 | private static final String KEY_ON_REPLY = "on_reply"; |
| 9849 | private static final String KEY_ON_READ = "on_read"; |
| 9850 | private static final String KEY_PARTICIPANTS = "participants"; |
| 9851 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 9852 | |
| 9853 | private final String[] mMessages; |
| 9854 | private final RemoteInput mRemoteInput; |
| 9855 | private final PendingIntent mReplyPendingIntent; |
| 9856 | private final PendingIntent mReadPendingIntent; |
| 9857 | private final String[] mParticipants; |
| 9858 | private final long mLatestTimestamp; |
| 9859 | |
| 9860 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 9861 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 9862 | String[] participants, long latestTimestamp) { |
| 9863 | mMessages = messages; |
| 9864 | mRemoteInput = remoteInput; |
| 9865 | mReadPendingIntent = readPendingIntent; |
| 9866 | mReplyPendingIntent = replyPendingIntent; |
| 9867 | mParticipants = participants; |
| 9868 | mLatestTimestamp = latestTimestamp; |
| 9869 | } |
| 9870 | |
| 9871 | /** |
| 9872 | * Gets the list of messages conveyed by this notification. |
| 9873 | */ |
| 9874 | public String[] getMessages() { |
| 9875 | return mMessages; |
| 9876 | } |
| 9877 | |
| 9878 | /** |
| 9879 | * Gets the remote input that will be used to convey the response to a message list, or |
| 9880 | * null if no such remote input exists. |
| 9881 | */ |
| 9882 | public RemoteInput getRemoteInput() { |
| 9883 | return mRemoteInput; |
| 9884 | } |
| 9885 | |
| 9886 | /** |
| 9887 | * Gets the pending intent that will be triggered when the user replies to this |
| 9888 | * notification. |
| 9889 | */ |
| 9890 | public PendingIntent getReplyPendingIntent() { |
| 9891 | return mReplyPendingIntent; |
| 9892 | } |
| 9893 | |
| 9894 | /** |
| 9895 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 9896 | * in this object's message list. |
| 9897 | */ |
| 9898 | public PendingIntent getReadPendingIntent() { |
| 9899 | return mReadPendingIntent; |
| 9900 | } |
| 9901 | |
| 9902 | /** |
| 9903 | * Gets the participants in the conversation. |
| 9904 | */ |
| 9905 | public String[] getParticipants() { |
| 9906 | return mParticipants; |
| 9907 | } |
| 9908 | |
| 9909 | /** |
| 9910 | * Gets the firs participant in the conversation. |
| 9911 | */ |
| 9912 | public String getParticipant() { |
| 9913 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 9914 | } |
| 9915 | |
| 9916 | /** |
| 9917 | * Gets the timestamp of the conversation. |
| 9918 | */ |
| 9919 | public long getLatestTimestamp() { |
| 9920 | return mLatestTimestamp; |
| 9921 | } |
| 9922 | |
| 9923 | Bundle getBundleForUnreadConversation() { |
| 9924 | Bundle b = new Bundle(); |
| 9925 | String author = null; |
| 9926 | if (mParticipants != null && mParticipants.length > 1) { |
| 9927 | author = mParticipants[0]; |
| 9928 | } |
| 9929 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 9930 | for (int i = 0; i < messages.length; i++) { |
| 9931 | Bundle m = new Bundle(); |
| 9932 | m.putString(KEY_TEXT, mMessages[i]); |
| 9933 | m.putString(KEY_AUTHOR, author); |
| 9934 | messages[i] = m; |
| 9935 | } |
| 9936 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 9937 | if (mRemoteInput != null) { |
| 9938 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 9939 | } |
| 9940 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 9941 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 9942 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 9943 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 9944 | return b; |
| 9945 | } |
| 9946 | |
| 9947 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 9948 | if (b == null) { |
| 9949 | return null; |
| 9950 | } |
| 9951 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 9952 | String[] messages = null; |
| 9953 | if (parcelableMessages != null) { |
| 9954 | String[] tmp = new String[parcelableMessages.length]; |
| 9955 | boolean success = true; |
| 9956 | for (int i = 0; i < tmp.length; i++) { |
| 9957 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 9958 | success = false; |
| 9959 | break; |
| 9960 | } |
| 9961 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 9962 | if (tmp[i] == null) { |
| 9963 | success = false; |
| 9964 | break; |
| 9965 | } |
| 9966 | } |
| 9967 | if (success) { |
| 9968 | messages = tmp; |
| 9969 | } else { |
| 9970 | return null; |
| 9971 | } |
| 9972 | } |
| 9973 | |
| 9974 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 9975 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 9976 | |
| 9977 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 9978 | |
| 9979 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 9980 | if (participants == null || participants.length != 1) { |
| 9981 | return null; |
| 9982 | } |
| 9983 | |
| 9984 | return new UnreadConversation(messages, |
| 9985 | remoteInput, |
| 9986 | onReply, |
| 9987 | onRead, |
| 9988 | participants, b.getLong(KEY_TIMESTAMP)); |
| 9989 | } |
| 9990 | }; |
| 9991 | |
| 9992 | /** |
| 9993 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 9994 | */ |
| 9995 | public static class Builder { |
| 9996 | private final List<String> mMessages = new ArrayList<String>(); |
| 9997 | private final String mParticipant; |
| 9998 | private RemoteInput mRemoteInput; |
| 9999 | private PendingIntent mReadPendingIntent; |
| 10000 | private PendingIntent mReplyPendingIntent; |
| 10001 | private long mLatestTimestamp; |
| 10002 | |
| 10003 | /** |
| 10004 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 10005 | * |
| 10006 | * @param name The name of the other participant in the conversation. |
| 10007 | */ |
| 10008 | public Builder(String name) { |
| 10009 | mParticipant = name; |
| 10010 | } |
| 10011 | |
| 10012 | /** |
| 10013 | * Appends a new unread message to the list of messages for this conversation. |
| 10014 | * |
| 10015 | * The messages should be added from oldest to newest. |
| 10016 | * |
| 10017 | * @param message The text of the new unread message. |
| 10018 | * @return This object for method chaining. |
| 10019 | */ |
| 10020 | public Builder addMessage(String message) { |
| 10021 | mMessages.add(message); |
| 10022 | return this; |
| 10023 | } |
| 10024 | |
| 10025 | /** |
| 10026 | * Sets the pending intent and remote input which will convey the reply to this |
| 10027 | * notification. |
| 10028 | * |
| 10029 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 10030 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 10031 | * @return This object for method chaining. |
| 10032 | * |
| 10033 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 10034 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 10035 | */ |
| 10036 | public Builder setReplyAction( |
| 10037 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 10038 | mRemoteInput = remoteInput; |
| 10039 | mReplyPendingIntent = pendingIntent; |
| 10040 | |
| 10041 | return this; |
| 10042 | } |
| 10043 | |
| 10044 | /** |
| 10045 | * Sets the pending intent that will be sent once the messages in this notification |
| 10046 | * are read. |
| 10047 | * |
| 10048 | * @param pendingIntent The pending intent to use. |
| 10049 | * @return This object for method chaining. |
| 10050 | */ |
| 10051 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 10052 | mReadPendingIntent = pendingIntent; |
| 10053 | return this; |
| 10054 | } |
| 10055 | |
| 10056 | /** |
| 10057 | * Sets the timestamp of the most recent message in an unread conversation. |
| 10058 | * |
| 10059 | * If a messaging notification has been posted by your application and has not |
| 10060 | * yet been cancelled, posting a later notification with the same id and tag |
| 10061 | * but without a newer timestamp may result in Android Auto not displaying a |
| 10062 | * heads up notification for the later notification. |
| 10063 | * |
| 10064 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 10065 | * @return This object for method chaining. |
| 10066 | */ |
| 10067 | public Builder setLatestTimestamp(long timestamp) { |
| 10068 | mLatestTimestamp = timestamp; |
| 10069 | return this; |
| 10070 | } |
| 10071 | |
| 10072 | /** |
| 10073 | * Builds a new unread conversation object. |
| 10074 | * |
| 10075 | * @return The new unread conversation object. |
| 10076 | */ |
| 10077 | public UnreadConversation build() { |
| 10078 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 10079 | String[] participants = { mParticipant }; |
| 10080 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 10081 | mReadPendingIntent, participants, mLatestTimestamp); |
| 10082 | } |
| 10083 | } |
| 10084 | } |
| 10085 | |
| 10086 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10087 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 10088 | * with a TV extension: |
| 10089 | * |
| 10090 | * <ol> |
| 10091 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 10092 | * <li>Create a {@link TvExtender}. |
| 10093 | * <li>Set TV-specific properties using the {@code set} methods of |
| 10094 | * {@link TvExtender}. |
| 10095 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 10096 | * to apply the extension to a notification. |
| 10097 | * </ol> |
| 10098 | * |
| 10099 | * <pre class="prettyprint"> |
| 10100 | * Notification notification = new Notification.Builder(context) |
| 10101 | * ... |
| 10102 | * .extend(new TvExtender() |
| 10103 | * .set*(...)) |
| 10104 | * .build(); |
| 10105 | * </pre> |
| 10106 | * |
| 10107 | * <p>TV extensions can be accessed on an existing notification by using the |
| 10108 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 10109 | * to access values. |
| 10110 | * |
| 10111 | * @hide |
| 10112 | */ |
| 10113 | @SystemApi |
| 10114 | public static final class TvExtender implements Extender { |
| 10115 | private static final String TAG = "TvExtender"; |
| 10116 | |
| 10117 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 10118 | private static final String EXTRA_FLAGS = "flags"; |
| 10119 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 10120 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10121 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10122 | private static final String EXTRA_SUPPRESS_SHOW_OVER_APPS = "suppressShowOverApps"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10123 | |
| 10124 | // Flags bitwise-ored to mFlags |
| 10125 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 10126 | |
| 10127 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10128 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10129 | private PendingIntent mContentIntent; |
| 10130 | private PendingIntent mDeleteIntent; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10131 | private boolean mSuppressShowOverApps; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10132 | |
| 10133 | /** |
| 10134 | * Create a {@link TvExtender} with default options. |
| 10135 | */ |
| 10136 | public TvExtender() { |
| 10137 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 10138 | } |
| 10139 | |
| 10140 | /** |
| 10141 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 10142 | * |
| 10143 | * @param notif The notification from which to copy options. |
| 10144 | */ |
| 10145 | public TvExtender(Notification notif) { |
| 10146 | Bundle bundle = notif.extras == null ? |
| 10147 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 10148 | if (bundle != null) { |
| 10149 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10150 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10151 | mSuppressShowOverApps = bundle.getBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10152 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 10153 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 10154 | } |
| 10155 | } |
| 10156 | |
| 10157 | /** |
| 10158 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 10159 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 10160 | * method of {@link Notification.Builder}. |
| 10161 | */ |
| 10162 | @Override |
| 10163 | public Notification.Builder extend(Notification.Builder builder) { |
| 10164 | Bundle bundle = new Bundle(); |
| 10165 | |
| 10166 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10167 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10168 | bundle.putBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS, mSuppressShowOverApps); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10169 | if (mContentIntent != null) { |
| 10170 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 10171 | } |
| 10172 | |
| 10173 | if (mDeleteIntent != null) { |
| 10174 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 10175 | } |
| 10176 | |
| 10177 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 10178 | return builder; |
| 10179 | } |
| 10180 | |
| 10181 | /** |
| 10182 | * Returns true if this notification should be shown on TV. This method return true |
| 10183 | * if the notification was extended with a TvExtender. |
| 10184 | */ |
| 10185 | public boolean isAvailableOnTv() { |
| 10186 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 10187 | } |
| 10188 | |
| 10189 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10190 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 10191 | * It can be different from the channel that the notification is delivered to when |
| 10192 | * posting on a non-TV device. |
| 10193 | */ |
| 10194 | public TvExtender setChannel(String channelId) { |
| 10195 | mChannelId = channelId; |
| 10196 | return this; |
| 10197 | } |
| 10198 | |
| 10199 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 10200 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 10201 | * It can be different from the channel that the notification is delivered to when |
| 10202 | * posting on a non-TV device. |
| 10203 | */ |
| 10204 | public TvExtender setChannelId(String channelId) { |
| 10205 | mChannelId = channelId; |
| 10206 | return this; |
| 10207 | } |
| 10208 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 10209 | /** @removed */ |
| 10210 | @Deprecated |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 10211 | public String getChannel() { |
| 10212 | return mChannelId; |
| 10213 | } |
| 10214 | |
| 10215 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 10216 | * Returns the id of the channel this notification posts to on TV. |
| 10217 | */ |
| 10218 | public String getChannelId() { |
| 10219 | return mChannelId; |
| 10220 | } |
| 10221 | |
| 10222 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10223 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 10224 | * If provided, it is used instead of the content intent specified |
| 10225 | * at the level of Notification. |
| 10226 | */ |
| 10227 | public TvExtender setContentIntent(PendingIntent intent) { |
| 10228 | mContentIntent = intent; |
| 10229 | return this; |
| 10230 | } |
| 10231 | |
| 10232 | /** |
| 10233 | * Returns the TV-specific content intent. If this method returns null, the |
| 10234 | * main content intent on the notification should be used. |
| 10235 | * |
| 10236 | * @see {@link Notification#contentIntent} |
| 10237 | */ |
| 10238 | public PendingIntent getContentIntent() { |
| 10239 | return mContentIntent; |
| 10240 | } |
| 10241 | |
| 10242 | /** |
| 10243 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 10244 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 10245 | * at the level of Notification. |
| 10246 | */ |
| 10247 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 10248 | mDeleteIntent = intent; |
| 10249 | return this; |
| 10250 | } |
| 10251 | |
| 10252 | /** |
| 10253 | * Returns the TV-specific delete intent. If this method returns null, the |
| 10254 | * main delete intent on the notification should be used. |
| 10255 | * |
| 10256 | * @see {@link Notification#deleteIntent} |
| 10257 | */ |
| 10258 | public PendingIntent getDeleteIntent() { |
| 10259 | return mDeleteIntent; |
| 10260 | } |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 10261 | |
| 10262 | /** |
| 10263 | * Specifies whether this notification should suppress showing a message over top of apps |
| 10264 | * outside of the launcher. |
| 10265 | */ |
| 10266 | public TvExtender setSuppressShowOverApps(boolean suppress) { |
| 10267 | mSuppressShowOverApps = suppress; |
| 10268 | return this; |
| 10269 | } |
| 10270 | |
| 10271 | /** |
| 10272 | * Returns true if this notification should not show messages over top of apps |
| 10273 | * outside of the launcher. |
| 10274 | */ |
| 10275 | public boolean getSuppressShowOverApps() { |
| 10276 | return mSuppressShowOverApps; |
| 10277 | } |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 10278 | } |
| 10279 | |
| 10280 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 10281 | * Get an array of Notification objects from a parcelable array bundle field. |
| 10282 | * Update the bundle to have a typed array so fetches in the future don't need |
| 10283 | * to do an array copy. |
| 10284 | */ |
| 10285 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 10286 | Parcelable[] array = bundle.getParcelableArray(key); |
| 10287 | if (array instanceof Notification[] || array == null) { |
| 10288 | return (Notification[]) array; |
| 10289 | } |
| 10290 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 10291 | Notification[].class); |
| 10292 | bundle.putParcelableArray(key, typedArray); |
| 10293 | return typedArray; |
| 10294 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 10295 | |
| 10296 | private static class BuilderRemoteViews extends RemoteViews { |
| 10297 | public BuilderRemoteViews(Parcel parcel) { |
| 10298 | super(parcel); |
| 10299 | } |
| 10300 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 10301 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 10302 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 10303 | } |
| 10304 | |
| 10305 | @Override |
| 10306 | public BuilderRemoteViews clone() { |
| 10307 | Parcel p = Parcel.obtain(); |
| 10308 | writeToParcel(p, 0); |
| 10309 | p.setDataPosition(0); |
| 10310 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 10311 | p.recycle(); |
| 10312 | return brv; |
| 10313 | } |
| 10314 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10315 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10316 | /** |
| 10317 | * A result object where information about the template that was created is saved. |
| 10318 | */ |
| 10319 | private static class TemplateBindResult { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10320 | int mIconMarginEnd; |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 10321 | boolean mRightIconContainerVisible; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10322 | |
| 10323 | /** |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10324 | * 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] | 10325 | * with the right actions. |
| 10326 | */ |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10327 | public int getIconMarginEnd() { |
| 10328 | return mIconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10329 | } |
| 10330 | |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 10331 | /** |
| 10332 | * Is the icon container visible on the right size because of the reply button or the |
| 10333 | * right icon. |
| 10334 | */ |
| 10335 | public boolean isRightIconContainerVisible() { |
| 10336 | return mRightIconContainerVisible; |
| 10337 | } |
| 10338 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 10339 | public void setIconMarginEnd(int iconMarginEnd) { |
| 10340 | this.mIconMarginEnd = iconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10341 | } |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame] | 10342 | |
| 10343 | public void setRightIconContainerVisible(boolean iconContainerVisible) { |
| 10344 | mRightIconContainerVisible = iconContainerVisible; |
| 10345 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10346 | } |
| 10347 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10348 | private static class StandardTemplateParams { |
| 10349 | boolean hasProgress = true; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10350 | CharSequence title; |
| 10351 | CharSequence text; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 10352 | CharSequence headerTextSecondary; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10353 | CharSequence summaryText; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 10354 | int maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10355 | boolean hideLargeIcon; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10356 | boolean hideReplyIcon; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10357 | boolean allowColorization = true; |
| 10358 | boolean forceDefaultColor = false; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10359 | |
| 10360 | final StandardTemplateParams reset() { |
| 10361 | hasProgress = true; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10362 | title = null; |
| 10363 | text = null; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10364 | summaryText = null; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 10365 | headerTextSecondary = null; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 10366 | maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10367 | allowColorization = true; |
| 10368 | forceDefaultColor = false; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10369 | return this; |
| 10370 | } |
| 10371 | |
| 10372 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 10373 | this.hasProgress = hasProgress; |
| 10374 | return this; |
| 10375 | } |
| 10376 | |
| 10377 | final StandardTemplateParams title(CharSequence title) { |
| 10378 | this.title = title; |
| 10379 | return this; |
| 10380 | } |
| 10381 | |
| 10382 | final StandardTemplateParams text(CharSequence text) { |
| 10383 | this.text = text; |
| 10384 | return this; |
| 10385 | } |
| 10386 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10387 | final StandardTemplateParams summaryText(CharSequence text) { |
| 10388 | this.summaryText = text; |
| 10389 | return this; |
| 10390 | } |
| 10391 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 10392 | final StandardTemplateParams headerTextSecondary(CharSequence text) { |
| 10393 | this.headerTextSecondary = text; |
| 10394 | return this; |
| 10395 | } |
| 10396 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10397 | final StandardTemplateParams hideLargeIcon(boolean hideLargeIcon) { |
| 10398 | this.hideLargeIcon = hideLargeIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10399 | return this; |
| 10400 | } |
| 10401 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10402 | final StandardTemplateParams hideReplyIcon(boolean hideReplyIcon) { |
| 10403 | this.hideReplyIcon = hideReplyIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10404 | return this; |
| 10405 | } |
| 10406 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10407 | final StandardTemplateParams disallowColorization() { |
| 10408 | this.allowColorization = false; |
| 10409 | return this; |
| 10410 | } |
| 10411 | |
| 10412 | final StandardTemplateParams forceDefaultColor() { |
| 10413 | this.forceDefaultColor = true; |
| 10414 | return this; |
| 10415 | } |
| 10416 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10417 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 10418 | Bundle extras = b.mN.extras; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 10419 | this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE)); |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 10420 | |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 10421 | CharSequence text = extras.getCharSequence(EXTRA_BIG_TEXT); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 10422 | if (TextUtils.isEmpty(text)) { |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 10423 | text = extras.getCharSequence(EXTRA_TEXT); |
| 10424 | } |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 10425 | this.text = b.processLegacyText(text); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10426 | this.summaryText = extras.getCharSequence(EXTRA_SUB_TEXT); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10427 | return this; |
| 10428 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 10429 | |
| 10430 | /** |
| 10431 | * Set the maximum lines of remote input history lines allowed. |
| 10432 | * @param maxRemoteInputHistory The number of lines. |
| 10433 | * @return The builder for method chaining. |
| 10434 | */ |
| 10435 | public StandardTemplateParams setMaxRemoteInputHistory(int maxRemoteInputHistory) { |
| 10436 | this.maxRemoteInputHistory = maxRemoteInputHistory; |
| 10437 | return this; |
| 10438 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10439 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10440 | } |