The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 19 | import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast; |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 20 | |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 21 | import android.annotation.ColorInt; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 22 | import android.annotation.DrawableRes; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 23 | import android.annotation.IdRes; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 24 | import android.annotation.IntDef; |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 27 | import android.annotation.RequiresPermission; |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 28 | import android.annotation.SdkConstant; |
| 29 | import android.annotation.SdkConstant.SdkConstantType; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 30 | import android.annotation.SystemApi; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 31 | import android.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 36 | import android.content.pm.PackageManager.NameNotFoundException; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 37 | import android.content.pm.ShortcutInfo; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 38 | import android.content.res.ColorStateList; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 39 | import android.content.res.Configuration; |
| 40 | import android.content.res.Resources; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 41 | import android.content.res.TypedArray; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 42 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 43 | import android.graphics.Canvas; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 44 | import android.graphics.Color; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 45 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 46 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 47 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 48 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 49 | import android.media.AudioManager; |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 50 | import android.media.PlayerBase; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 51 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 53 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 54 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 55 | import android.os.Bundle; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 56 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.os.Parcel; |
| 58 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 59 | import android.os.SystemClock; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 60 | import android.os.SystemProperties; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 61 | import android.os.UserHandle; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 62 | import android.text.BidiFormatter; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 63 | import android.text.SpannableStringBuilder; |
| 64 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 66 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 67 | import android.text.style.CharacterStyle; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 68 | import android.text.style.ForegroundColorSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 69 | import android.text.style.RelativeSizeSpan; |
| 70 | import android.text.style.TextAppearanceSpan; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 71 | import android.util.ArraySet; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 72 | import android.util.Log; |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 73 | import android.util.Pair; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 74 | import android.util.SparseArray; |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 75 | import android.util.proto.ProtoOutputStream; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 76 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 77 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 78 | import android.view.View; |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 79 | import android.view.ViewGroup; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 80 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import android.widget.RemoteViews; |
| 82 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 83 | import com.android.internal.R; |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 84 | import com.android.internal.annotations.VisibleForTesting; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 85 | import com.android.internal.util.ArrayUtils; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 86 | import com.android.internal.util.ContrastColorUtil; |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 87 | import com.android.internal.util.Preconditions; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 88 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 89 | import java.lang.annotation.Retention; |
| 90 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 91 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 92 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 93 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 94 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 95 | import java.util.List; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 96 | import java.util.Objects; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 97 | import java.util.Set; |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 98 | import java.util.function.Consumer; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 99 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | /** |
| 101 | * A class that represents how a persistent notification is to be presented to |
| 102 | * the user using the {@link android.app.NotificationManager}. |
| 103 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 104 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 105 | * easier to construct Notifications.</p> |
| 106 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 107 | * <div class="special reference"> |
| 108 | * <h3>Developer Guides</h3> |
| 109 | * <p>For a guide to creating notifications, read the |
| 110 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 111 | * developer guide.</p> |
| 112 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | */ |
| 114 | public class Notification implements Parcelable |
| 115 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 116 | private static final String TAG = "Notification"; |
| 117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 119 | * An activity that provides a user interface for adjusting notification preferences for its |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 120 | * containing application. |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 121 | */ |
| 122 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 123 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 124 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 125 | |
| 126 | /** |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 127 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 128 | * contain a {@link NotificationChannel#getId() channel id} that can be used to narrow down |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 129 | * what settings should be shown in the target app. |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 130 | */ |
| 131 | public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 132 | |
| 133 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 134 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 005c8b9 | 2017-08-24 10:35:53 -0400 | [diff] [blame] | 135 | * contain a {@link NotificationChannelGroup#getId() group id} that can be used to narrow down |
| 136 | * what settings should be shown in the target app. |
| 137 | */ |
| 138 | public static final String EXTRA_CHANNEL_GROUP_ID = "android.intent.extra.CHANNEL_GROUP_ID"; |
| 139 | |
| 140 | /** |
| 141 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 142 | * contain the tag provided to {@link NotificationManager#notify(String, int, Notification)} |
| 143 | * that can be used to narrow down what settings should be shown in the target app. |
| 144 | */ |
| 145 | public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 146 | |
| 147 | /** |
| 148 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 149 | * contain the id provided to {@link NotificationManager#notify(String, int, Notification)} |
| 150 | * that can be used to narrow down what settings should be shown in the target app. |
| 151 | */ |
| 152 | public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 153 | |
| 154 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | * Use all default values (where applicable). |
| 156 | */ |
| 157 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | /** |
| 160 | * Use the default notification sound. This will ignore any given |
| 161 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 162 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 163 | * <p> |
| 164 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 165 | * </p> |
| 166 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 168 | */ |
| 169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | public static final int DEFAULT_SOUND = 1; |
| 171 | |
| 172 | /** |
| 173 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 174 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 175 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 176 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 177 | * <p> |
| 178 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 179 | * </p> |
| 180 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 182 | */ |
| 183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | /** |
| 187 | * Use the default notification lights. This will ignore the |
| 188 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 189 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 190 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 192 | */ |
| 193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 197 | * Maximum length of CharSequences accepted by Builder and friends. |
| 198 | * |
| 199 | * <p> |
| 200 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 201 | */ |
| 202 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 203 | |
| 204 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 205 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 206 | */ |
| 207 | private static final int MAX_REPLY_HISTORY = 5; |
| 208 | |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 209 | /** |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 210 | * Maximum number of (generic) action buttons in a notification (contextual action buttons are |
| 211 | * handled separately). |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 212 | * @hide |
| 213 | */ |
| 214 | public static final int MAX_ACTION_BUTTONS = 3; |
Selim Cinek | de4de0e | 2018-01-24 16:21:07 -0800 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * If the notification contained an unsent draft for a RemoteInput when the user clicked on it, |
| 218 | * we're adding the draft as a String extra to the {@link #contentIntent} using this key. |
| 219 | * |
| 220 | * <p>Apps may use this extra to prepopulate text fields in the app, where the user usually |
| 221 | * sends messages.</p> |
| 222 | */ |
| 223 | public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; |
| 224 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 225 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 226 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 227 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 228 | * Default value: {@link System#currentTimeMillis() Now}. |
| 229 | * |
| 230 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 231 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 232 | * yet to occur but about which the user is being informed). Indefinite events should be |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 233 | * timestamped according to when the activity began. |
| 234 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 235 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 236 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 237 | * <ul> |
| 238 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 239 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 240 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 241 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 242 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 243 | * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 244 | * </ul> |
| 245 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 246 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 247 | * anymore by default and must be opted into by using |
| 248 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | */ |
| 250 | public long when; |
| 251 | |
| 252 | /** |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 253 | * The creation time of the notification |
| 254 | */ |
| 255 | private long creationTime; |
| 256 | |
| 257 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | * The resource id of a drawable to use as the icon in the status bar. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 259 | * |
| 260 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 262 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 263 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | public int icon; |
| 265 | |
| 266 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 267 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 268 | * leave it at its default value of 0. |
| 269 | * |
| 270 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 271 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 272 | */ |
| 273 | public int iconLevel; |
| 274 | |
| 275 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 276 | * The number of events that this notification represents. For example, in a new mail |
| 277 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 278 | * |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 279 | * The system may or may not use this field to modify the appearance of the notification. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 280 | * Starting with {@link android.os.Build.VERSION_CODES#O}, the number may be displayed as a |
| 281 | * badge icon in Launchers that support badging. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | */ |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 283 | public int number = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | |
| 285 | /** |
| 286 | * The intent to execute when the expanded status entry is clicked. If |
| 287 | * this is an activity, it must include the |
| 288 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 289 | * that you take care of task management as described in the |
| 290 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
Dianne Hackborn | 6ceca58 | 2012-01-10 15:24:26 -0800 | [diff] [blame] | 291 | * Stack</a> document. In particular, make sure to read the notification section |
| 292 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 293 | * Notifications</a> for the correct ways to launch an application from a |
| 294 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | */ |
| 296 | public PendingIntent contentIntent; |
| 297 | |
| 298 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 299 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 300 | * the "Clear All" button or by swiping it away individually. |
| 301 | * |
| 302 | * This probably shouldn't be launching an activity since several of those will be sent |
| 303 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | */ |
| 305 | public PendingIntent deleteIntent; |
| 306 | |
| 307 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 308 | * An intent to launch instead of posting the notification to the status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 309 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 310 | * <p> |
| 311 | * The system UI may choose to display a heads-up notification, instead of |
| 312 | * launching this intent, while the user is using the device. |
| 313 | * </p> |
| 314 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 315 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 316 | */ |
| 317 | public PendingIntent fullScreenIntent; |
| 318 | |
| 319 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 320 | * Text that summarizes this notification for accessibility services. |
| 321 | * |
| 322 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 323 | * accessibility services (where it serves as an audible announcement of the notification's |
| 324 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 325 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 326 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | */ |
| 328 | public CharSequence tickerText; |
| 329 | |
| 330 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 331 | * Formerly, a view showing the {@link #tickerText}. |
| 332 | * |
| 333 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 334 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 335 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 336 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 337 | |
| 338 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 339 | * The view that will represent this notification in the notification list (which is pulled |
| 340 | * down from the status bar). |
| 341 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 342 | * As of N, this field may be null. The notification view is determined by the inputs |
| 343 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 344 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 346 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | public RemoteViews contentView; |
| 348 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 349 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 350 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 351 | * opportunity to show more detail. The system UI may choose to show this |
| 352 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 353 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 354 | * As of N, this field may be null. The expanded notification view is determined by the |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 355 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 356 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 357 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 358 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 359 | public RemoteViews bigContentView; |
| 360 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 361 | |
| 362 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 363 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 364 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 365 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 366 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 367 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 368 | * As of N, this field may be null. The heads-up notification view is determined by the |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 369 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 370 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 371 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 372 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 373 | public RemoteViews headsUpContentView; |
| 374 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 375 | private boolean mUsesStandardHeader; |
| 376 | |
| 377 | private static final ArraySet<Integer> STANDARD_LAYOUTS = new ArraySet<>(); |
| 378 | static { |
| 379 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_base); |
| 380 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_base); |
| 381 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_picture); |
| 382 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text); |
| 383 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_inbox); |
| 384 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging); |
| 385 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_media); |
| 386 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media); |
| 387 | STANDARD_LAYOUTS.add(R.layout.notification_template_ambient_header); |
| 388 | STANDARD_LAYOUTS.add(R.layout.notification_template_header); |
| 389 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_ambient); |
| 390 | } |
| 391 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 392 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 393 | * A large bitmap to be shown in the notification content area. |
| 394 | * |
| 395 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 397 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 398 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | |
| 400 | /** |
| 401 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 402 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 404 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 405 | * </p> |
| 406 | * |
| 407 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 408 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 410 | * @deprecated use {@link NotificationChannel#getSound()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 412 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | public Uri sound; |
| 414 | |
| 415 | /** |
| 416 | * Use this constant as the value for audioStreamType to request that |
| 417 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 418 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 419 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 420 | * @deprecated Use {@link NotificationChannel#getAudioAttributes()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 422 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | public static final int STREAM_DEFAULT = -1; |
| 424 | |
| 425 | /** |
| 426 | * The audio stream type to use when playing the sound. |
| 427 | * Should be one of the STREAM_ constants from |
| 428 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 429 | * |
| 430 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 432 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | public int audioStreamType = STREAM_DEFAULT; |
| 434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 436 | * The default value of {@link #audioAttributes}. |
| 437 | */ |
| 438 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 439 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 440 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 441 | .build(); |
| 442 | |
| 443 | /** |
| 444 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 445 | * |
| 446 | * @deprecated use {@link NotificationChannel#getAudioAttributes()} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 447 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 448 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 449 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 450 | |
| 451 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 452 | * The pattern with which to vibrate. |
| 453 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | * <p> |
| 455 | * To vibrate the default pattern, see {@link #defaults}. |
| 456 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 457 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | * @see android.os.Vibrator#vibrate(long[],int) |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 459 | * @deprecated use {@link NotificationChannel#getVibrationPattern()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 461 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | public long[] vibrate; |
| 463 | |
| 464 | /** |
| 465 | * The color of the led. The hardware will do its best approximation. |
| 466 | * |
| 467 | * @see #FLAG_SHOW_LIGHTS |
| 468 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 469 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 471 | @ColorInt |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 472 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | public int ledARGB; |
| 474 | |
| 475 | /** |
| 476 | * The number of milliseconds for the LED to be on while it's flashing. |
| 477 | * The hardware will do its best approximation. |
| 478 | * |
| 479 | * @see #FLAG_SHOW_LIGHTS |
| 480 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 481 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 483 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | public int ledOnMS; |
| 485 | |
| 486 | /** |
| 487 | * The number of milliseconds for the LED to be off while it's flashing. |
| 488 | * The hardware will do its best approximation. |
| 489 | * |
| 490 | * @see #FLAG_SHOW_LIGHTS |
| 491 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 492 | * |
| 493 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 495 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | public int ledOffMS; |
| 497 | |
| 498 | /** |
| 499 | * Specifies which values should be taken from the defaults. |
| 500 | * <p> |
| 501 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 502 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 503 | * values, use {@link #DEFAULT_ALL}. |
| 504 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 505 | * |
| 506 | * @deprecated use {@link NotificationChannel#getSound()} and |
| 507 | * {@link NotificationChannel#shouldShowLights()} and |
| 508 | * {@link NotificationChannel#shouldVibrate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 510 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | public int defaults; |
| 512 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | /** |
| 514 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 515 | * set if you want the LED on for this notification. |
| 516 | * <ul> |
| 517 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 518 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 519 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 520 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 521 | * be on and off to ledOnMS and ledOffMS.</li> |
| 522 | * </ul> |
| 523 | * <p> |
| 524 | * Since hardware varies, you are not guaranteed that any of the values |
Ricardo Loo Foronda | f8f6d0a | 2018-01-25 08:42:43 -0800 | [diff] [blame] | 525 | * you pass are honored exactly. Use the system defaults if possible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | * because they will be set to values that work on any given hardware. |
| 527 | * <p> |
| 528 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 529 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 530 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 532 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 534 | |
| 535 | /** |
| 536 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 537 | * set if this notification is in reference to something that is ongoing, |
| 538 | * like a phone call. It should not be set if this notification is in |
| 539 | * reference to something that happened at a particular point in time, |
| 540 | * like a missed phone call. |
| 541 | */ |
| 542 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 543 | |
| 544 | /** |
| 545 | * Bit to be bitwise-ored into the {@link #flags} field that if set, |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 546 | * the audio will be repeated until the notification is |
| 547 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | */ |
| 549 | public static final int FLAG_INSISTENT = 0x00000004; |
| 550 | |
| 551 | /** |
| 552 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
Griff Hazen | 293977b | 2014-04-28 08:37:20 -0700 | [diff] [blame] | 553 | * set if you would only like the sound, vibrate and ticker to be played |
| 554 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | */ |
| 556 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 557 | |
| 558 | /** |
| 559 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 560 | * set if the notification should be canceled when it is clicked by the |
Daniel Sandler | 8aa9ae6 | 2012-12-04 23:31:47 -0500 | [diff] [blame] | 561 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | */ |
| 563 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 564 | |
| 565 | /** |
| 566 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 567 | * set if the notification should not be canceled when the user clicks |
| 568 | * the Clear all button. |
| 569 | */ |
| 570 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 571 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 572 | /** |
| 573 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 574 | * set if this notification represents a currently running service. This |
| 575 | * will normally be set for you by {@link Service#startForeground}. |
| 576 | */ |
| 577 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 578 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 579 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 580 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 581 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 582 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 583 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 584 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 585 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 586 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 587 | /** |
| 588 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 589 | * set if this notification is relevant to the current device only |
| 590 | * and it is not recommended that it bridge to other devices. |
| 591 | */ |
| 592 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 593 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 594 | /** |
| 595 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 596 | * set if this notification is the group summary for a group of notifications. |
| 597 | * Grouped notifications may display in a cluster or stack on devices which |
| 598 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 599 | */ |
| 600 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 601 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 602 | /** |
| 603 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 604 | * set if this notification is the group summary for an auto-group of notifications. |
| 605 | * |
| 606 | * @hide |
| 607 | */ |
| 608 | @SystemApi |
| 609 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 610 | |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 611 | /** |
| 612 | * @hide |
| 613 | */ |
| 614 | public static final int FLAG_CAN_COLORIZE = 0x00000800; |
| 615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | public int flags; |
| 617 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 618 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 619 | @IntDef(prefix = { "PRIORITY_" }, value = { |
| 620 | PRIORITY_DEFAULT, |
| 621 | PRIORITY_LOW, |
| 622 | PRIORITY_MIN, |
| 623 | PRIORITY_HIGH, |
| 624 | PRIORITY_MAX |
| 625 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 626 | @Retention(RetentionPolicy.SOURCE) |
| 627 | public @interface Priority {} |
| 628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 630 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 631 | * notifications, use this value for all notifications. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 632 | * |
| 633 | * @deprecated use {@link NotificationManager#IMPORTANCE_DEFAULT} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 634 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 635 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 636 | public static final int PRIORITY_DEFAULT = 0; |
| 637 | |
| 638 | /** |
| 639 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 640 | * items smaller, or at a different position in the list, compared with your app's |
| 641 | * {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 642 | * |
| 643 | * @deprecated use {@link NotificationManager#IMPORTANCE_LOW} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 644 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 645 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 646 | public static final int PRIORITY_LOW = -1; |
| 647 | |
| 648 | /** |
| 649 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 650 | * circumstances, such as detailed notification logs. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 651 | * |
| 652 | * @deprecated use {@link NotificationManager#IMPORTANCE_MIN} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 653 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 654 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 655 | public static final int PRIORITY_MIN = -2; |
| 656 | |
| 657 | /** |
| 658 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 659 | * show these items larger, or at a different position in notification lists, compared with |
| 660 | * your app's {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 661 | * |
| 662 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 663 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 664 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 665 | public static final int PRIORITY_HIGH = 1; |
| 666 | |
| 667 | /** |
| 668 | * Highest {@link #priority}, for your application's most important items that require the |
| 669 | * user's prompt attention or input. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 670 | * |
| 671 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 672 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 673 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 674 | public static final int PRIORITY_MAX = 2; |
| 675 | |
| 676 | /** |
| 677 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 678 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 679 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 680 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 681 | * situations, while the user might be interrupted for a higher-priority notification. The |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 682 | * system will make a determination about how to interpret this priority when presenting |
| 683 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 684 | * |
| 685 | * <p> |
| 686 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 687 | * as a heads-up notification. |
| 688 | * </p> |
| 689 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 690 | * @deprecated use {@link NotificationChannel#getImportance()} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 691 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 692 | @Priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 693 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 694 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 695 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 696 | /** |
| 697 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 698 | * to be applied by the standard Style templates when presenting this notification. |
| 699 | * |
| 700 | * The current template design constructs a colorful header image by overlaying the |
| 701 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 702 | * ignored. |
| 703 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 704 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 705 | public int color = COLOR_DEFAULT; |
| 706 | |
| 707 | /** |
| 708 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 709 | * any special color but instead use default colors when presenting this notification. |
| 710 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 711 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 712 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 713 | |
| 714 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 715 | * Special value of {@link #color} used as a place holder for an invalid color. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 716 | * @hide |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 717 | */ |
| 718 | @ColorInt |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 719 | public static final int COLOR_INVALID = 1; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 720 | |
| 721 | /** |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 722 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 723 | * the notification's presence and contents in untrusted situations (namely, on the secure |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 724 | * lockscreen). |
| 725 | * |
| 726 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 727 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 728 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 729 | * the appropriate user. |
| 730 | * |
| 731 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 732 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 733 | * To modify the public version of this notification—for example, to redact some portions—see |
| 734 | * {@link Builder#setPublicVersion(Notification)}. |
| 735 | * |
| 736 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 737 | * and ticker until the user has bypassed the lockscreen. |
| 738 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 739 | public @Visibility int visibility; |
| 740 | |
| 741 | /** @hide */ |
| 742 | @IntDef(prefix = { "VISIBILITY_" }, value = { |
| 743 | VISIBILITY_PUBLIC, |
| 744 | VISIBILITY_PRIVATE, |
| 745 | VISIBILITY_SECRET, |
| 746 | }) |
| 747 | @Retention(RetentionPolicy.SOURCE) |
| 748 | public @interface Visibility {} |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 749 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 750 | /** |
| 751 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 752 | * |
| 753 | * {@see #visibility} |
| 754 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 755 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 756 | |
| 757 | /** |
| 758 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 759 | * private information on secure lockscreens. |
| 760 | * |
| 761 | * {@see #visibility} |
| 762 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 763 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 764 | |
| 765 | /** |
| 766 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 767 | * |
| 768 | * {@see #visibility} |
| 769 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 770 | public static final int VISIBILITY_SECRET = -1; |
| 771 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 772 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 773 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 774 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 775 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 776 | |
| 777 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 778 | * Notification category: map turn-by-turn navigation. |
| 779 | */ |
| 780 | public static final String CATEGORY_NAVIGATION = "navigation"; |
| 781 | |
| 782 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 783 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 784 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 785 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 786 | |
| 787 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 788 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 789 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 790 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 791 | |
| 792 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 793 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 794 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 795 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 796 | |
| 797 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 798 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 799 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 800 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 801 | |
| 802 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 803 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 804 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 805 | public static final String CATEGORY_ALARM = "alarm"; |
| 806 | |
| 807 | /** |
| 808 | * Notification category: progress of a long-running background operation. |
| 809 | */ |
| 810 | public static final String CATEGORY_PROGRESS = "progress"; |
| 811 | |
| 812 | /** |
| 813 | * Notification category: social network or sharing update. |
| 814 | */ |
| 815 | public static final String CATEGORY_SOCIAL = "social"; |
| 816 | |
| 817 | /** |
| 818 | * Notification category: error in background operation or authentication status. |
| 819 | */ |
| 820 | public static final String CATEGORY_ERROR = "err"; |
| 821 | |
| 822 | /** |
| 823 | * Notification category: media transport control for playback. |
| 824 | */ |
| 825 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 826 | |
| 827 | /** |
| 828 | * Notification category: system or device status update. Reserved for system use. |
| 829 | */ |
| 830 | public static final String CATEGORY_SYSTEM = "sys"; |
| 831 | |
| 832 | /** |
| 833 | * Notification category: indication of running background service. |
| 834 | */ |
| 835 | public static final String CATEGORY_SERVICE = "service"; |
| 836 | |
| 837 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 838 | * Notification category: a specific, timely recommendation for a single thing. |
| 839 | * For example, a news app might want to recommend a news story it believes the user will |
| 840 | * want to read next. |
| 841 | */ |
| 842 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 843 | |
| 844 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 845 | * Notification category: ongoing information about device or contextual status. |
| 846 | */ |
| 847 | public static final String CATEGORY_STATUS = "status"; |
| 848 | |
| 849 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 850 | * Notification category: user-scheduled reminder. |
| 851 | */ |
| 852 | public static final String CATEGORY_REMINDER = "reminder"; |
| 853 | |
| 854 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 855 | * Notification category: extreme car emergencies. |
| 856 | * @hide |
| 857 | */ |
| 858 | @SystemApi |
| 859 | public static final String CATEGORY_CAR_EMERGENCY = "car_emergency"; |
| 860 | |
| 861 | /** |
| 862 | * Notification category: car warnings. |
| 863 | * @hide |
| 864 | */ |
| 865 | @SystemApi |
| 866 | public static final String CATEGORY_CAR_WARNING = "car_warning"; |
| 867 | |
| 868 | /** |
| 869 | * Notification category: general car system information. |
| 870 | * @hide |
| 871 | */ |
| 872 | @SystemApi |
| 873 | public static final String CATEGORY_CAR_INFORMATION = "car_information"; |
| 874 | |
| 875 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 876 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 877 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 878 | */ |
| 879 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 880 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 881 | @UnsupportedAppUsage |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 882 | private String mGroupKey; |
| 883 | |
| 884 | /** |
| 885 | * Get the key used to group this notification into a cluster or stack |
| 886 | * with other notifications on devices which support such rendering. |
| 887 | */ |
| 888 | public String getGroup() { |
| 889 | return mGroupKey; |
| 890 | } |
| 891 | |
| 892 | private String mSortKey; |
| 893 | |
| 894 | /** |
| 895 | * Get a sort key that orders this notification among other notifications from the |
| 896 | * same package. This can be useful if an external sort was already applied and an app |
| 897 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 898 | * value, although providing different priorities in addition to providing sort key may |
| 899 | * cause this value to be ignored. |
| 900 | * |
| 901 | * <p>This sort key can also be used to order members of a notification group. See |
| 902 | * {@link Builder#setGroup}. |
| 903 | * |
| 904 | * @see String#compareTo(String) |
| 905 | */ |
| 906 | public String getSortKey() { |
| 907 | return mSortKey; |
| 908 | } |
| 909 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 910 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 911 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 912 | * <p> |
| 913 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 914 | * APIs, and are intended to be used by |
| 915 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 916 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 917 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 918 | public Bundle extras = new Bundle(); |
| 919 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 920 | /** |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 921 | * All pending intents in the notification as the system needs to be able to access them but |
| 922 | * touching the extras bundle in the system process is not safe because the bundle may contain |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 923 | * custom parcelable objects. |
| 924 | * |
| 925 | * @hide |
| 926 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 927 | @UnsupportedAppUsage |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 928 | public ArraySet<PendingIntent> allPendingIntents; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 929 | |
| 930 | /** |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 931 | * Token identifying the notification that is applying doze/bgcheck whitelisting to the |
| 932 | * pending intents inside of it, so only those will get the behavior. |
| 933 | * |
| 934 | * @hide |
| 935 | */ |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 936 | private IBinder mWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 937 | |
| 938 | /** |
| 939 | * Must be set by a process to start associating tokens with Notification objects |
| 940 | * coming in to it. This is set by NotificationManagerService. |
| 941 | * |
| 942 | * @hide |
| 943 | */ |
| 944 | static public IBinder processWhitelistToken; |
| 945 | |
| 946 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 947 | * {@link #extras} key: this is the title of the notification, |
| 948 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 949 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 950 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 951 | |
| 952 | /** |
| 953 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 954 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 955 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 956 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 957 | |
| 958 | /** |
| 959 | * {@link #extras} key: this is the main text payload, as supplied to |
| 960 | * {@link Builder#setContentText(CharSequence)}. |
| 961 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 962 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 963 | |
| 964 | /** |
| 965 | * {@link #extras} key: this is a third line of text, as supplied to |
| 966 | * {@link Builder#setSubText(CharSequence)}. |
| 967 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 968 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 969 | |
| 970 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 971 | * {@link #extras} key: this is the remote input history, as supplied to |
| 972 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
Adrian Roos | 005e774 | 2016-04-13 15:02:20 -0700 | [diff] [blame] | 973 | * |
| 974 | * Apps can fill this through {@link Builder#setRemoteInputHistory(CharSequence[])} |
| 975 | * with the most recent inputs that have been sent through a {@link RemoteInput} of this |
| 976 | * Notification and are expected to clear it once the it is no longer relevant (e.g. for chat |
| 977 | * notifications once the other party has responded). |
| 978 | * |
| 979 | * The extra with this key is of type CharSequence[] and contains the most recent entry at |
| 980 | * the 0 index, the second most recent at the 1 index, etc. |
| 981 | * |
| 982 | * @see Builder#setRemoteInputHistory(CharSequence[]) |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 983 | */ |
| 984 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 985 | |
| 986 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 987 | * {@link #extras} key: boolean as supplied to |
| 988 | * {@link Builder#setShowRemoteInputSpinner(boolean)}. |
| 989 | * |
| 990 | * If set to true, then the view displaying the remote input history from |
| 991 | * {@link Builder#setRemoteInputHistory(CharSequence[])} will have a progress spinner. |
| 992 | * |
| 993 | * @see Builder#setShowRemoteInputSpinner(boolean) |
| 994 | * @hide |
| 995 | */ |
| 996 | public static final String EXTRA_SHOW_REMOTE_INPUT_SPINNER = "android.remoteInputSpinner"; |
| 997 | |
| 998 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 999 | * {@link #extras} key: boolean as supplied to |
| 1000 | * {@link Builder#setHideSmartReplies(boolean)}. |
| 1001 | * |
| 1002 | * If set to true, then any smart reply buttons will be hidden. |
| 1003 | * |
| 1004 | * @see Builder#setHideSmartReplies(boolean) |
| 1005 | * @hide |
| 1006 | */ |
| 1007 | public static final String EXTRA_HIDE_SMART_REPLIES = "android.hideSmartReplies"; |
| 1008 | |
| 1009 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1010 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 1011 | * {@link Builder#setContentInfo(CharSequence)}. |
| 1012 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1013 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1014 | |
| 1015 | /** |
| 1016 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 1017 | * alongside expanded notifications, as supplied to (e.g.) |
| 1018 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 1019 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1020 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1021 | |
| 1022 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1023 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 1024 | * {@link BigTextStyle} notification, as supplied to |
| 1025 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 1026 | */ |
| 1027 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 1028 | |
| 1029 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1030 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 1031 | * supplied to {@link Builder#setSmallIcon(int)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1032 | * |
| 1033 | * @deprecated Use {@link #getSmallIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1034 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1035 | @Deprecated |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1036 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1037 | |
| 1038 | /** |
| 1039 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 1040 | * notification payload, as |
| 1041 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1042 | * |
| 1043 | * @deprecated Use {@link #getLargeIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1044 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1045 | @Deprecated |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1046 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1047 | |
| 1048 | /** |
| 1049 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 1050 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 1051 | * shown in its expanded form, as supplied to |
| 1052 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 1053 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1054 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1055 | |
| 1056 | /** |
| 1057 | * {@link #extras} key: this is the progress value supplied to |
| 1058 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1059 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1060 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1061 | |
| 1062 | /** |
| 1063 | * {@link #extras} key: this is the maximum value supplied to |
| 1064 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1065 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1066 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1067 | |
| 1068 | /** |
| 1069 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 1070 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1071 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1072 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1073 | |
| 1074 | /** |
| 1075 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 1076 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 1077 | * {@link Builder#setUsesChronometer(boolean)}. |
| 1078 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1079 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1080 | |
| 1081 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1082 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 1083 | * instead of counting up. Is only relevant if key {@link #EXTRA_SHOW_CHRONOMETER} is present. |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1084 | * This extra is a boolean. The default is false. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1085 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1086 | public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1087 | |
| 1088 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1089 | * {@link #extras} key: whether {@link #when} should be shown, |
| 1090 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 1091 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1092 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1093 | |
| 1094 | /** |
| 1095 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 1096 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 1097 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1098 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1099 | |
| 1100 | /** |
| 1101 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 1102 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 1103 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1104 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1105 | |
| 1106 | /** |
| 1107 | * {@link #extras} key: A string representing the name of the specific |
| 1108 | * {@link android.app.Notification.Style} used to create this notification. |
| 1109 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 1110 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1111 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1112 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 1113 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 1114 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1115 | * |
| 1116 | * @deprecated the actual objects are now in {@link #EXTRA_PEOPLE_LIST} |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1117 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1118 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1119 | |
| 1120 | /** |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1121 | * {@link #extras} key: An arrayList of {@link Person} objects containing the people that |
| 1122 | * this notification relates to. |
| 1123 | */ |
| 1124 | public static final String EXTRA_PEOPLE_LIST = "android.people.list"; |
| 1125 | |
| 1126 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1127 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 1128 | * Only available to notifications coming from the android package. |
| 1129 | * @hide |
| 1130 | */ |
Maurice Lam | 96c1003 | 2017-03-29 15:42:38 -0700 | [diff] [blame] | 1131 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1132 | @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1133 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 1134 | |
| 1135 | /** |
Robin Lee | d107af6 | 2018-04-27 13:55:56 +0200 | [diff] [blame] | 1136 | * {@link #extras} key: |
| 1137 | * flat {@link String} representation of a {@link android.content.ContentUris content URI} |
| 1138 | * pointing to an image that can be displayed in the background when the notification is |
| 1139 | * selected. Used on television platforms. The URI must point to an image stream suitable for |
| 1140 | * passing into {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1141 | * BitmapFactory.decodeStream}; all other content types will be ignored. |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1142 | */ |
| 1143 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1144 | |
| 1145 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1146 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 1147 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1148 | * {@link android.app.Notification.MediaStyle} notification. |
| 1149 | */ |
| 1150 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1151 | |
| 1152 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 1153 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 1154 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 1155 | */ |
| 1156 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1157 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 1158 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1159 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 1160 | * direct replies |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1161 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1162 | * {@link CharSequence} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1163 | * |
| 1164 | * @deprecated use {@link #EXTRA_MESSAGING_PERSON} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1165 | */ |
| 1166 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1167 | |
| 1168 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1169 | * {@link #extras} key: the person to be displayed for all messages sent by the user including |
| 1170 | * direct replies |
| 1171 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1172 | * {@link Person} |
| 1173 | */ |
| 1174 | public static final String EXTRA_MESSAGING_PERSON = "android.messagingUser"; |
| 1175 | |
| 1176 | /** |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1177 | * {@link #extras} key: a {@link CharSequence} to be displayed as the title to a conversation |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1178 | * represented by a {@link android.app.Notification.MessagingStyle} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1179 | */ |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1180 | public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1181 | |
| 1182 | /** |
| 1183 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 1184 | * bundles provided by a |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1185 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1186 | * array of bundles. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1187 | */ |
| 1188 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 1189 | |
| 1190 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 1191 | * {@link #extras} key: an array of |
| 1192 | * {@link android.app.Notification.MessagingStyle#addHistoricMessage historic} |
| 1193 | * {@link android.app.Notification.MessagingStyle.Message} bundles provided by a |
| 1194 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1195 | * array of bundles. |
| 1196 | */ |
| 1197 | public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1198 | |
| 1199 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 1200 | * {@link #extras} key: whether the {@link android.app.Notification.MessagingStyle} notification |
| 1201 | * represents a group conversation. |
| 1202 | */ |
| 1203 | public static final String EXTRA_IS_GROUP_CONVERSATION = "android.isGroupConversation"; |
| 1204 | |
| 1205 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1206 | * {@link #extras} key: whether the notification should be colorized as |
| 1207 | * supplied to {@link Builder#setColorized(boolean)}}. |
| 1208 | */ |
| 1209 | public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1210 | |
| 1211 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1212 | * @hide |
| 1213 | */ |
| 1214 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1215 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 1216 | /** |
| 1217 | * @hide |
| 1218 | */ |
| 1219 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1220 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1221 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 1222 | * @hide |
| 1223 | */ |
| 1224 | public static final String EXTRA_REDUCED_IMAGES = "android.reduced.images"; |
| 1225 | |
| 1226 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1227 | * {@link #extras} key: the audio contents of this notification. |
| 1228 | * |
| 1229 | * This is for use when rendering the notification on an audio-focused interface; |
| 1230 | * the audio contents are a complete sound sample that contains the contents/body of the |
| 1231 | * notification. This may be used in substitute of a Text-to-Speech reading of the |
| 1232 | * notification. For example if the notification represents a voice message this should point |
| 1233 | * to the audio of that message. |
| 1234 | * |
| 1235 | * The data stored under this key should be a String representation of a Uri that contains the |
| 1236 | * audio contents in one of the following formats: WAV, PCM 16-bit, AMR-WB. |
| 1237 | * |
| 1238 | * This extra is unnecessary if you are using {@code MessagingStyle} since each {@code Message} |
| 1239 | * has a field for holding data URI. That field can be used for audio. |
| 1240 | * See {@code Message#setData}. |
| 1241 | * |
| 1242 | * Example usage: |
| 1243 | * <pre> |
| 1244 | * {@code |
| 1245 | * Notification.Builder myBuilder = (build your Notification as normal); |
| 1246 | * myBuilder.getExtras().putString(EXTRA_AUDIO_CONTENTS_URI, myAudioUri.toString()); |
| 1247 | * } |
| 1248 | * </pre> |
| 1249 | */ |
| 1250 | public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1251 | |
Dan Sandler | 80eaa59 | 2016-04-14 23:34:54 -0400 | [diff] [blame] | 1252 | /** @hide */ |
| 1253 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1254 | @RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME) |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1255 | public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1256 | |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1257 | /** |
Julia Reynolds | 3c7de11 | 2018-03-28 09:33:13 -0400 | [diff] [blame] | 1258 | * This is set on the notifications shown by system_server about apps running foreground |
| 1259 | * services. It indicates that the notification should be shown |
| 1260 | * only if any of the given apps do not already have a properly tagged |
| 1261 | * {@link #FLAG_FOREGROUND_SERVICE} notification currently visible to the user. |
| 1262 | * This is a string array of all package names of the apps. |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1263 | * @hide |
| 1264 | */ |
| 1265 | public static final String EXTRA_FOREGROUND_APPS = "android.foregroundApps"; |
| 1266 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1267 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1268 | private Icon mSmallIcon; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1269 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1270 | private Icon mLargeIcon; |
| 1271 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1272 | @UnsupportedAppUsage |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1273 | private String mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1274 | private long mTimeout; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1275 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1276 | private String mShortcutId; |
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 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 1279 | private PendingIntent mAppOverlayIntent; |
| 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 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 1430 | /** |
| 1431 | * {@code SemanticAction}: Contextual action - dependent on the current notification. E.g. |
| 1432 | * open a Map application with an address shown in the notification. |
| 1433 | */ |
| 1434 | public static final int SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION = 11; |
| 1435 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1436 | private final Bundle mExtras; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1437 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1438 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1439 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1440 | private boolean mAllowGeneratedReplies = true; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1441 | private final @SemanticAction int mSemanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1442 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1443 | /** |
| 1444 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1445 | * |
| 1446 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1447 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1448 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1449 | public int icon; |
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 | * Title of the action. |
| 1453 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1454 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1455 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1456 | /** |
| 1457 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1458 | * may be rendered in a disabled presentation by the system UI. |
| 1459 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1460 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1461 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1462 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1463 | if (in.readInt() != 0) { |
| 1464 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1465 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1466 | icon = mIcon.getResId(); |
| 1467 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1468 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1469 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1470 | if (in.readInt() == 1) { |
| 1471 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1472 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1473 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1474 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1475 | mAllowGeneratedReplies = in.readInt() == 1; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1476 | mSemanticAction = in.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1477 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1478 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1479 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1480 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1481 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1482 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1483 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1484 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true, |
| 1485 | SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1488 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1489 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1490 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1491 | @SemanticAction int semanticAction) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1492 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1493 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1494 | this.icon = icon.getResId(); |
| 1495 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1496 | this.title = title; |
| 1497 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1498 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1499 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1500 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1501 | this.mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1505 | * Return an icon representing the action. |
| 1506 | */ |
| 1507 | public Icon getIcon() { |
| 1508 | if (mIcon == null && icon != 0) { |
| 1509 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1510 | mIcon = Icon.createWithResource("", icon); |
| 1511 | } |
| 1512 | return mIcon; |
| 1513 | } |
| 1514 | |
| 1515 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1516 | * Get additional metadata carried around with this Action. |
| 1517 | */ |
| 1518 | public Bundle getExtras() { |
| 1519 | return mExtras; |
| 1520 | } |
| 1521 | |
| 1522 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1523 | * Return whether the platform should automatically generate possible replies for this |
| 1524 | * {@link Action} |
| 1525 | */ |
| 1526 | public boolean getAllowGeneratedReplies() { |
| 1527 | return mAllowGeneratedReplies; |
| 1528 | } |
| 1529 | |
| 1530 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1531 | * 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] | 1532 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1533 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1534 | */ |
| 1535 | public RemoteInput[] getRemoteInputs() { |
| 1536 | return mRemoteInputs; |
| 1537 | } |
| 1538 | |
| 1539 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1540 | * Returns the {@code SemanticAction} associated with this {@link Action}. A |
| 1541 | * {@code SemanticAction} denotes what an {@link Action}'s {@link PendingIntent} will do |
| 1542 | * (eg. reply, mark as read, delete, etc). |
| 1543 | */ |
| 1544 | public @SemanticAction int getSemanticAction() { |
| 1545 | return mSemanticAction; |
| 1546 | } |
| 1547 | |
| 1548 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1549 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1550 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1551 | * {@link RemoteInput#isDataOnly}. |
| 1552 | * |
Shane Brennan | f670d6c | 2017-04-25 13:05:45 -0700 | [diff] [blame] | 1553 | * Returns null if there are no data-only remote inputs. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1554 | * |
| 1555 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1556 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1557 | */ |
| 1558 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1559 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1560 | } |
| 1561 | |
| 1562 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1563 | * Builder class for {@link Action} objects. |
| 1564 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1565 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1566 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1567 | private final CharSequence mTitle; |
| 1568 | private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1569 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1570 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1571 | private ArrayList<RemoteInput> mRemoteInputs; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1572 | private @SemanticAction int mSemanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1573 | |
| 1574 | /** |
| 1575 | * Construct a new builder for {@link Action} object. |
| 1576 | * @param icon icon to show for this action |
| 1577 | * @param title the title of the action |
| 1578 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1579 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1580 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1581 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1582 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | /** |
| 1586 | * Construct a new builder for {@link Action} object. |
| 1587 | * @param icon icon to show for this action |
| 1588 | * @param title the title of the action |
| 1589 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1590 | */ |
| 1591 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1592 | this(icon, title, intent, new Bundle(), null, true, SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | /** |
| 1596 | * Construct a new builder for {@link Action} object using the fields from an |
| 1597 | * {@link Action}. |
| 1598 | * @param action the action to read fields from. |
| 1599 | */ |
| 1600 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1601 | this(action.getIcon(), action.title, action.actionIntent, |
| 1602 | new Bundle(action.mExtras), action.getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1603 | action.getAllowGeneratedReplies(), action.getSemanticAction()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1606 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1607 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1608 | @SemanticAction int semanticAction) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1609 | mIcon = icon; |
| 1610 | mTitle = title; |
| 1611 | mIntent = intent; |
| 1612 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1613 | if (remoteInputs != null) { |
| 1614 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1615 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1616 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1617 | mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1618 | mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | /** |
| 1622 | * Merge additional metadata into this builder. |
| 1623 | * |
| 1624 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1625 | * |
| 1626 | * @see Notification.Action#extras |
| 1627 | */ |
| 1628 | public Builder addExtras(Bundle extras) { |
| 1629 | if (extras != null) { |
| 1630 | mExtras.putAll(extras); |
| 1631 | } |
| 1632 | return this; |
| 1633 | } |
| 1634 | |
| 1635 | /** |
| 1636 | * Get the metadata Bundle used by this Builder. |
| 1637 | * |
| 1638 | * <p>The returned Bundle is shared with this Builder. |
| 1639 | */ |
| 1640 | public Bundle getExtras() { |
| 1641 | return mExtras; |
| 1642 | } |
| 1643 | |
| 1644 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1645 | * Add an input to be collected from the user when this action is sent. |
| 1646 | * Response values can be retrieved from the fired intent by using the |
| 1647 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1648 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1649 | * @return this object for method chaining |
| 1650 | */ |
| 1651 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1652 | if (mRemoteInputs == null) { |
| 1653 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1654 | } |
| 1655 | mRemoteInputs.add(remoteInput); |
| 1656 | return this; |
| 1657 | } |
| 1658 | |
| 1659 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1660 | * Set whether the platform should automatically generate possible replies to add to |
| 1661 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1662 | * {@link RemoteInput}, this has no effect. |
| 1663 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1664 | * otherwise |
| 1665 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1666 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1667 | */ |
| 1668 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1669 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1670 | return this; |
| 1671 | } |
| 1672 | |
| 1673 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1674 | * Sets the {@code SemanticAction} for this {@link Action}. A |
| 1675 | * {@code SemanticAction} denotes what an {@link Action}'s |
| 1676 | * {@link PendingIntent} will do (eg. reply, mark as read, delete, etc). |
| 1677 | * @param semanticAction a SemanticAction defined within {@link Action} with |
| 1678 | * {@code SEMANTIC_ACTION_} prefixes |
| 1679 | * @return this object for method chaining |
| 1680 | */ |
| 1681 | public Builder setSemanticAction(@SemanticAction int semanticAction) { |
| 1682 | mSemanticAction = semanticAction; |
| 1683 | return this; |
| 1684 | } |
| 1685 | |
| 1686 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1687 | * Apply an extender to this action builder. Extenders may be used to add |
| 1688 | * metadata or change options on this builder. |
| 1689 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1690 | public Builder extend(Extender extender) { |
| 1691 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1692 | return this; |
| 1693 | } |
| 1694 | |
| 1695 | /** |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1696 | * Throws an NPE if we are building a contextual action missing one of the fields |
| 1697 | * necessary to display the action. |
| 1698 | */ |
| 1699 | private void checkContextualActionNullFields() { |
| 1700 | if (mSemanticAction != SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION) return; |
| 1701 | |
| 1702 | if (mIcon == null) { |
| 1703 | throw new NullPointerException("Contextual Actions must contain a valid icon"); |
| 1704 | } |
| 1705 | |
| 1706 | if (mIntent == null) { |
| 1707 | throw new NullPointerException( |
| 1708 | "Contextual Actions must contain a valid PendingIntent"); |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1713 | * Combine all of the options that have been set and return a new {@link Action} |
| 1714 | * object. |
| 1715 | * @return the built action |
| 1716 | */ |
| 1717 | public Action build() { |
Gustav Sennton | c98b163 | 2018-11-23 12:26:15 +0000 | [diff] [blame] | 1718 | checkContextualActionNullFields(); |
| 1719 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1720 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1721 | RemoteInput[] previousDataInputs = |
| 1722 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1723 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1724 | for (RemoteInput input : previousDataInputs) { |
| 1725 | dataOnlyInputs.add(input); |
| 1726 | } |
| 1727 | } |
| 1728 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1729 | if (mRemoteInputs != null) { |
| 1730 | for (RemoteInput input : mRemoteInputs) { |
| 1731 | if (input.isDataOnly()) { |
| 1732 | dataOnlyInputs.add(input); |
| 1733 | } else { |
| 1734 | textInputs.add(input); |
| 1735 | } |
| 1736 | } |
| 1737 | } |
| 1738 | if (!dataOnlyInputs.isEmpty()) { |
| 1739 | RemoteInput[] dataInputsArr = |
| 1740 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1741 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1742 | } |
| 1743 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1744 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1745 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1746 | mAllowGeneratedReplies, mSemanticAction); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1747 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1748 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1749 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1750 | @Override |
| 1751 | public Action clone() { |
| 1752 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1753 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1754 | title, |
| 1755 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1756 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1757 | getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1758 | getAllowGeneratedReplies(), |
| 1759 | getSemanticAction()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1760 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1761 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1762 | @Override |
| 1763 | public int describeContents() { |
| 1764 | return 0; |
| 1765 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1766 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1767 | @Override |
| 1768 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1769 | final Icon ic = getIcon(); |
| 1770 | if (ic != null) { |
| 1771 | out.writeInt(1); |
| 1772 | ic.writeToParcel(out, 0); |
| 1773 | } else { |
| 1774 | out.writeInt(0); |
| 1775 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1776 | TextUtils.writeToParcel(title, out, flags); |
| 1777 | if (actionIntent != null) { |
| 1778 | out.writeInt(1); |
| 1779 | actionIntent.writeToParcel(out, flags); |
| 1780 | } else { |
| 1781 | out.writeInt(0); |
| 1782 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1783 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1784 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1785 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1786 | out.writeInt(mSemanticAction); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1787 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1788 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1789 | public static final Parcelable.Creator<Action> CREATOR = |
| 1790 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1791 | public Action createFromParcel(Parcel in) { |
| 1792 | return new Action(in); |
| 1793 | } |
| 1794 | public Action[] newArray(int size) { |
| 1795 | return new Action[size]; |
| 1796 | } |
| 1797 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1798 | |
| 1799 | /** |
| 1800 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1801 | * metadata or change options on an action builder. |
| 1802 | */ |
| 1803 | public interface Extender { |
| 1804 | /** |
| 1805 | * Apply this extender to a notification action builder. |
| 1806 | * @param builder the builder to be modified. |
| 1807 | * @return the build object for chaining. |
| 1808 | */ |
| 1809 | public Builder extend(Builder builder); |
| 1810 | } |
| 1811 | |
| 1812 | /** |
| 1813 | * Wearable extender for notification actions. To add extensions to an action, |
| 1814 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1815 | * the {@code WearableExtender()} constructor and apply it to a |
| 1816 | * {@link android.app.Notification.Action.Builder} using |
| 1817 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1818 | * |
| 1819 | * <pre class="prettyprint"> |
| 1820 | * Notification.Action action = new Notification.Action.Builder( |
| 1821 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1822 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1823 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1824 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1825 | */ |
| 1826 | public static final class WearableExtender implements Extender { |
| 1827 | /** Notification action extra which contains wearable extensions */ |
| 1828 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1829 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1830 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1831 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1832 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1833 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1834 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1835 | |
| 1836 | // Flags bitwise-ored to mFlags |
| 1837 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1838 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1839 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1840 | |
| 1841 | // Default value for flags integer |
| 1842 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1843 | |
| 1844 | private int mFlags = DEFAULT_FLAGS; |
| 1845 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1846 | private CharSequence mInProgressLabel; |
| 1847 | private CharSequence mConfirmLabel; |
| 1848 | private CharSequence mCancelLabel; |
| 1849 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1850 | /** |
| 1851 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1852 | * options. |
| 1853 | */ |
| 1854 | public WearableExtender() { |
| 1855 | } |
| 1856 | |
| 1857 | /** |
| 1858 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1859 | * wearable options present in an existing notification action. |
| 1860 | * @param action the notification action to inspect. |
| 1861 | */ |
| 1862 | public WearableExtender(Action action) { |
| 1863 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1864 | if (wearableBundle != null) { |
| 1865 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1866 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1867 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1868 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | /** |
| 1873 | * Apply wearable extensions to a notification action that is being built. This is |
| 1874 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1875 | * method of {@link android.app.Notification.Action.Builder}. |
| 1876 | */ |
| 1877 | @Override |
| 1878 | public Action.Builder extend(Action.Builder builder) { |
| 1879 | Bundle wearableBundle = new Bundle(); |
| 1880 | |
| 1881 | if (mFlags != DEFAULT_FLAGS) { |
| 1882 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1883 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1884 | if (mInProgressLabel != null) { |
| 1885 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1886 | } |
| 1887 | if (mConfirmLabel != null) { |
| 1888 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1889 | } |
| 1890 | if (mCancelLabel != null) { |
| 1891 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1892 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1893 | |
| 1894 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1895 | return builder; |
| 1896 | } |
| 1897 | |
| 1898 | @Override |
| 1899 | public WearableExtender clone() { |
| 1900 | WearableExtender that = new WearableExtender(); |
| 1901 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1902 | that.mInProgressLabel = this.mInProgressLabel; |
| 1903 | that.mConfirmLabel = this.mConfirmLabel; |
| 1904 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1905 | return that; |
| 1906 | } |
| 1907 | |
| 1908 | /** |
| 1909 | * Set whether this action is available when the wearable device is not connected to |
| 1910 | * a companion device. The user can still trigger this action when the wearable device is |
| 1911 | * offline, but a visual hint will indicate that the action may not be available. |
| 1912 | * Defaults to true. |
| 1913 | */ |
| 1914 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1915 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1916 | return this; |
| 1917 | } |
| 1918 | |
| 1919 | /** |
| 1920 | * Get whether this action is available when the wearable device is not connected to |
| 1921 | * a companion device. The user can still trigger this action when the wearable device is |
| 1922 | * offline, but a visual hint will indicate that the action may not be available. |
| 1923 | * Defaults to true. |
| 1924 | */ |
| 1925 | public boolean isAvailableOffline() { |
| 1926 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1927 | } |
| 1928 | |
| 1929 | private void setFlag(int mask, boolean value) { |
| 1930 | if (value) { |
| 1931 | mFlags |= mask; |
| 1932 | } else { |
| 1933 | mFlags &= ~mask; |
| 1934 | } |
| 1935 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1936 | |
| 1937 | /** |
| 1938 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1939 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1940 | * |
| 1941 | * @param label the label to display while the action is being prepared to execute |
| 1942 | * @return this object for method chaining |
| 1943 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1944 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1945 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1946 | mInProgressLabel = label; |
| 1947 | return this; |
| 1948 | } |
| 1949 | |
| 1950 | /** |
| 1951 | * Get the label to display while the wearable is preparing to automatically execute |
| 1952 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1953 | * |
| 1954 | * @return the label to display while the action is being prepared to execute |
| 1955 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1956 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1957 | public CharSequence getInProgressLabel() { |
| 1958 | return mInProgressLabel; |
| 1959 | } |
| 1960 | |
| 1961 | /** |
| 1962 | * Set a label to display to confirm that the action should be executed. |
| 1963 | * This is usually an imperative verb like "Send". |
| 1964 | * |
| 1965 | * @param label the label to confirm the action should be executed |
| 1966 | * @return this object for method chaining |
| 1967 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1968 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1969 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1970 | mConfirmLabel = label; |
| 1971 | return this; |
| 1972 | } |
| 1973 | |
| 1974 | /** |
| 1975 | * Get the label to display to confirm that the action should be executed. |
| 1976 | * This is usually an imperative verb like "Send". |
| 1977 | * |
| 1978 | * @return the label to confirm the action should be executed |
| 1979 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1980 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1981 | public CharSequence getConfirmLabel() { |
| 1982 | return mConfirmLabel; |
| 1983 | } |
| 1984 | |
| 1985 | /** |
| 1986 | * Set a label to display to cancel the action. |
| 1987 | * This is usually an imperative verb, like "Cancel". |
| 1988 | * |
| 1989 | * @param label the label to display to cancel the action |
| 1990 | * @return this object for method chaining |
| 1991 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1992 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1993 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1994 | mCancelLabel = label; |
| 1995 | return this; |
| 1996 | } |
| 1997 | |
| 1998 | /** |
| 1999 | * Get the label to display to cancel the action. |
| 2000 | * This is usually an imperative verb like "Cancel". |
| 2001 | * |
| 2002 | * @return the label to display to cancel the action |
| 2003 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 2004 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 2005 | public CharSequence getCancelLabel() { |
| 2006 | return mCancelLabel; |
| 2007 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2008 | |
| 2009 | /** |
| 2010 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 2011 | * platform that it can generate the appropriate transitions. |
| 2012 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 2013 | * an activity and transitions should be generated, false otherwise. |
| 2014 | * @return this object for method chaining |
| 2015 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 2016 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2017 | boolean hintLaunchesActivity) { |
| 2018 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 2019 | return this; |
| 2020 | } |
| 2021 | |
| 2022 | /** |
| 2023 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 2024 | * platform that it can generate the appropriate transitions |
| 2025 | * @return {@code true} if the content intent will launch an activity and transitions |
| 2026 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 2027 | * never set. |
| 2028 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 2029 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2030 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 2031 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2032 | |
| 2033 | /** |
| 2034 | * Set a hint that this Action should be displayed inline. |
| 2035 | * |
| 2036 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 2037 | * otherwise |
| 2038 | * @return this object for method chaining |
| 2039 | */ |
| 2040 | public WearableExtender setHintDisplayActionInline( |
| 2041 | boolean hintDisplayInline) { |
| 2042 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 2043 | return this; |
| 2044 | } |
| 2045 | |
| 2046 | /** |
| 2047 | * Get a hint that this Action should be displayed inline. |
| 2048 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 2049 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2050 | * otherwise. The default value is {@code false} if this was never set. |
| 2051 | */ |
| 2052 | public boolean getHintDisplayActionInline() { |
| 2053 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 2054 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2055 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2056 | |
| 2057 | /** |
| 2058 | * Provides meaning to an {@link Action} that hints at what the associated |
| 2059 | * {@link PendingIntent} will do. For example, an {@link Action} with a |
| 2060 | * {@link PendingIntent} that replies to a text message notification may have the |
| 2061 | * {@link #SEMANTIC_ACTION_REPLY} {@code SemanticAction} set within it. |
| 2062 | * |
| 2063 | * @hide |
| 2064 | */ |
| 2065 | @IntDef(prefix = { "SEMANTIC_ACTION_" }, value = { |
| 2066 | SEMANTIC_ACTION_NONE, |
| 2067 | SEMANTIC_ACTION_REPLY, |
| 2068 | SEMANTIC_ACTION_MARK_AS_READ, |
| 2069 | SEMANTIC_ACTION_MARK_AS_UNREAD, |
| 2070 | SEMANTIC_ACTION_DELETE, |
| 2071 | SEMANTIC_ACTION_ARCHIVE, |
| 2072 | SEMANTIC_ACTION_MUTE, |
| 2073 | SEMANTIC_ACTION_UNMUTE, |
| 2074 | SEMANTIC_ACTION_THUMBS_UP, |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 2075 | SEMANTIC_ACTION_THUMBS_DOWN, |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 2076 | SEMANTIC_ACTION_CALL, |
| 2077 | SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2078 | }) |
| 2079 | @Retention(RetentionPolicy.SOURCE) |
| 2080 | public @interface SemanticAction {} |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2081 | } |
| 2082 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2083 | /** |
| 2084 | * Array of all {@link Action} structures attached to this notification by |
| 2085 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 2086 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 2087 | * interface for invoking actions. |
| 2088 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 2089 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2090 | |
| 2091 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2092 | * Replacement version of this notification whose content will be shown |
| 2093 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 2094 | * and {@link #VISIBILITY_PUBLIC}. |
| 2095 | */ |
| 2096 | public Notification publicVersion; |
| 2097 | |
| 2098 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2099 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2100 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2101 | */ |
| 2102 | public Notification() |
| 2103 | { |
| 2104 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2105 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2106 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | * @hide |
| 2111 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2112 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2113 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 2114 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 2115 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2116 | new Builder(context) |
| 2117 | .setWhen(when) |
| 2118 | .setSmallIcon(icon) |
| 2119 | .setTicker(tickerText) |
| 2120 | .setContentTitle(contentTitle) |
| 2121 | .setContentText(contentText) |
| 2122 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 2123 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | /** |
| 2127 | * Constructs a Notification object with the information needed to |
| 2128 | * have a status bar icon without the standard expanded view. |
| 2129 | * |
| 2130 | * @param icon The resource id of the icon to put in the status bar. |
| 2131 | * @param tickerText The text that flows by in the status bar when the notification first |
| 2132 | * activates. |
| 2133 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 2134 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2135 | * |
| 2136 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2137 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2138 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2139 | public Notification(int icon, CharSequence tickerText, long when) |
| 2140 | { |
| 2141 | this.icon = icon; |
| 2142 | this.tickerText = tickerText; |
| 2143 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2144 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | /** |
| 2148 | * Unflatten the notification from a parcel. |
| 2149 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2150 | @SuppressWarnings("unchecked") |
| 2151 | public Notification(Parcel parcel) { |
| 2152 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 2153 | // intents in extras are always written as the last entry. |
| 2154 | readFromParcelImpl(parcel); |
| 2155 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2156 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2160 | { |
| 2161 | int version = parcel.readInt(); |
| 2162 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2163 | mWhitelistToken = parcel.readStrongBinder(); |
| 2164 | if (mWhitelistToken == null) { |
| 2165 | mWhitelistToken = processWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2166 | } |
| 2167 | // 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] | 2168 | parcel.setClassCookie(PendingIntent.class, mWhitelistToken); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2171 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2172 | if (parcel.readInt() != 0) { |
| 2173 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2174 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 2175 | icon = mSmallIcon.getResId(); |
| 2176 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2177 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2178 | number = parcel.readInt(); |
| 2179 | if (parcel.readInt() != 0) { |
| 2180 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2181 | } |
| 2182 | if (parcel.readInt() != 0) { |
| 2183 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2184 | } |
| 2185 | if (parcel.readInt() != 0) { |
| 2186 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2187 | } |
| 2188 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2189 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2190 | } |
| 2191 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2192 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2193 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2194 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2195 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2196 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2197 | defaults = parcel.readInt(); |
| 2198 | flags = parcel.readInt(); |
| 2199 | if (parcel.readInt() != 0) { |
| 2200 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 2201 | } |
| 2202 | |
| 2203 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2204 | if (parcel.readInt() != 0) { |
| 2205 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 2206 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2207 | vibrate = parcel.createLongArray(); |
| 2208 | ledARGB = parcel.readInt(); |
| 2209 | ledOnMS = parcel.readInt(); |
| 2210 | ledOffMS = parcel.readInt(); |
| 2211 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2212 | |
| 2213 | if (parcel.readInt() != 0) { |
| 2214 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2215 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2216 | |
| 2217 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2218 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2219 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2220 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2221 | mGroupKey = parcel.readString(); |
| 2222 | |
| 2223 | mSortKey = parcel.readString(); |
| 2224 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 2225 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2226 | fixDuplicateExtras(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2227 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2228 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 2229 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2230 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2231 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2232 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2233 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2234 | if (parcel.readInt() != 0) { |
| 2235 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2236 | } |
| 2237 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2238 | visibility = parcel.readInt(); |
| 2239 | |
| 2240 | if (parcel.readInt() != 0) { |
| 2241 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 2242 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2243 | |
| 2244 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2245 | |
| 2246 | if (parcel.readInt() != 0) { |
| 2247 | mChannelId = parcel.readString(); |
| 2248 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2249 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2250 | |
| 2251 | if (parcel.readInt() != 0) { |
| 2252 | mShortcutId = parcel.readString(); |
| 2253 | } |
| 2254 | |
| 2255 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2256 | |
| 2257 | if (parcel.readInt() != 0) { |
| 2258 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2259 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2260 | |
| 2261 | mGroupAlertBehavior = parcel.readInt(); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2262 | if (parcel.readInt() != 0) { |
| 2263 | mAppOverlayIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2264 | } |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2265 | |
| 2266 | mAllowSystemGeneratedContextualActions = parcel.readBoolean(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | } |
| 2268 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2269 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2270 | public Notification clone() { |
| 2271 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2272 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2273 | return that; |
| 2274 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2275 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2276 | /** |
| 2277 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 2278 | * of this into that. |
| 2279 | * @hide |
| 2280 | */ |
| 2281 | public void cloneInto(Notification that, boolean heavy) { |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2282 | that.mWhitelistToken = this.mWhitelistToken; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2283 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2284 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2285 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2286 | that.number = this.number; |
| 2287 | |
| 2288 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 2289 | that.contentIntent = this.contentIntent; |
| 2290 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2291 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2292 | |
| 2293 | if (this.tickerText != null) { |
| 2294 | that.tickerText = this.tickerText.toString(); |
| 2295 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2296 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2297 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2298 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2299 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2300 | that.contentView = this.contentView.clone(); |
| 2301 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2302 | if (heavy && this.mLargeIcon != null) { |
| 2303 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2304 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 2305 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2306 | that.sound = this.sound; // android.net.Uri is immutable |
| 2307 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2308 | if (this.audioAttributes != null) { |
| 2309 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 2310 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2311 | |
| 2312 | final long[] vibrate = this.vibrate; |
| 2313 | if (vibrate != null) { |
| 2314 | final int N = vibrate.length; |
| 2315 | final long[] vib = that.vibrate = new long[N]; |
| 2316 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 2317 | } |
| 2318 | |
| 2319 | that.ledARGB = this.ledARGB; |
| 2320 | that.ledOnMS = this.ledOnMS; |
| 2321 | that.ledOffMS = this.ledOffMS; |
| 2322 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2323 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2324 | that.flags = this.flags; |
| 2325 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2326 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2327 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2328 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2329 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2330 | that.mGroupKey = this.mGroupKey; |
| 2331 | |
| 2332 | that.mSortKey = this.mSortKey; |
| 2333 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2334 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2335 | try { |
| 2336 | that.extras = new Bundle(this.extras); |
| 2337 | // will unparcel |
| 2338 | that.extras.size(); |
| 2339 | } catch (BadParcelableException e) { |
| 2340 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2341 | that.extras = null; |
| 2342 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2343 | } |
| 2344 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2345 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2346 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2349 | if (this.actions != null) { |
| 2350 | that.actions = new Action[this.actions.length]; |
| 2351 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 2352 | if ( this.actions[i] != null) { |
| 2353 | that.actions[i] = this.actions[i].clone(); |
| 2354 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2355 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2356 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2357 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2358 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2359 | that.bigContentView = this.bigContentView.clone(); |
| 2360 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2361 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2362 | if (heavy && this.headsUpContentView != null) { |
| 2363 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 2364 | } |
| 2365 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2366 | that.visibility = this.visibility; |
| 2367 | |
| 2368 | if (this.publicVersion != null) { |
| 2369 | that.publicVersion = new Notification(); |
| 2370 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2371 | } |
| 2372 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2373 | that.color = this.color; |
| 2374 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2375 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2376 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2377 | that.mShortcutId = this.mShortcutId; |
| 2378 | that.mBadgeIcon = this.mBadgeIcon; |
| 2379 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2380 | that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2381 | that.mAppOverlayIntent = this.mAppOverlayIntent; |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2382 | that.mAllowSystemGeneratedContextualActions = this.mAllowSystemGeneratedContextualActions; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2383 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2384 | if (!heavy) { |
| 2385 | that.lightenPayload(); // will clean out extras |
| 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | /** |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2390 | * Note all {@link Uri} that are referenced internally, with the expectation |
| 2391 | * that Uri permission grants will need to be issued to ensure the recipient |
| 2392 | * of this object is able to render its contents. |
| 2393 | * |
| 2394 | * @hide |
| 2395 | */ |
| 2396 | public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 2397 | visitor.accept(sound); |
| 2398 | |
| 2399 | if (tickerView != null) tickerView.visitUris(visitor); |
| 2400 | if (contentView != null) contentView.visitUris(visitor); |
| 2401 | if (bigContentView != null) bigContentView.visitUris(visitor); |
| 2402 | if (headsUpContentView != null) headsUpContentView.visitUris(visitor); |
| 2403 | |
| 2404 | if (extras != null) { |
| 2405 | visitor.accept(extras.getParcelable(EXTRA_AUDIO_CONTENTS_URI)); |
Robin Lee | d107af6 | 2018-04-27 13:55:56 +0200 | [diff] [blame] | 2406 | if (extras.containsKey(EXTRA_BACKGROUND_IMAGE_URI)) { |
| 2407 | visitor.accept(Uri.parse(extras.getString(EXTRA_BACKGROUND_IMAGE_URI))); |
| 2408 | } |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | if (MessagingStyle.class.equals(getNotificationStyle()) && extras != null) { |
| 2412 | final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 2413 | if (!ArrayUtils.isEmpty(messages)) { |
| 2414 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2415 | .getMessagesFromBundleArray(messages)) { |
| 2416 | visitor.accept(message.getDataUri()); |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 2421 | if (!ArrayUtils.isEmpty(historic)) { |
| 2422 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2423 | .getMessagesFromBundleArray(historic)) { |
| 2424 | visitor.accept(message.getDataUri()); |
| 2425 | } |
| 2426 | } |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | /** |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2431 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 2432 | * listeners when the full contents are not necessary. |
| 2433 | * @hide |
| 2434 | */ |
| 2435 | public final void lightenPayload() { |
| 2436 | tickerView = null; |
| 2437 | contentView = null; |
| 2438 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2439 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2440 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2441 | if (extras != null && !extras.isEmpty()) { |
| 2442 | final Set<String> keyset = extras.keySet(); |
| 2443 | final int N = keyset.size(); |
| 2444 | final String[] keys = keyset.toArray(new String[N]); |
| 2445 | for (int i=0; i<N; i++) { |
| 2446 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2447 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2448 | continue; |
| 2449 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2450 | final Object obj = extras.get(key); |
| 2451 | if (obj != null && |
| 2452 | ( obj instanceof Parcelable |
| 2453 | || obj instanceof Parcelable[] |
| 2454 | || obj instanceof SparseArray |
| 2455 | || obj instanceof ArrayList)) { |
| 2456 | extras.remove(key); |
| 2457 | } |
| 2458 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2459 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2462 | /** |
| 2463 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2464 | * means it had better not be some custom Parcelable implementation. |
| 2465 | * @hide |
| 2466 | */ |
| 2467 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2468 | if (cs == null) return cs; |
| 2469 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2470 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2471 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2472 | if (cs instanceof Parcelable) { |
| 2473 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2474 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2475 | return cs.toString(); |
| 2476 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2477 | return removeTextSizeSpans(cs); |
| 2478 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2479 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2480 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2481 | if (charSequence instanceof Spanned) { |
| 2482 | Spanned ss = (Spanned) charSequence; |
| 2483 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2484 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2485 | for (Object span : spans) { |
| 2486 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2487 | if (resultSpan instanceof CharacterStyle) { |
| 2488 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2489 | } |
| 2490 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2491 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2492 | resultSpan = new TextAppearanceSpan( |
| 2493 | originalSpan.getFamily(), |
| 2494 | originalSpan.getTextStyle(), |
| 2495 | -1, |
| 2496 | originalSpan.getTextColor(), |
| 2497 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2498 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2499 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2500 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2501 | } else { |
| 2502 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2503 | } |
| 2504 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2505 | ss.getSpanFlags(span)); |
| 2506 | } |
| 2507 | return builder; |
| 2508 | } |
| 2509 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2510 | } |
| 2511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | public int describeContents() { |
| 2513 | return 0; |
| 2514 | } |
| 2515 | |
| 2516 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2517 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2518 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2519 | public void writeToParcel(Parcel parcel, int flags) { |
| 2520 | // We need to mark all pending intents getting into the notification |
| 2521 | // system as being put there to later allow the notification ranker |
| 2522 | // to launch them and by doing so add the app to the battery saver white |
| 2523 | // list for a short period of time. The problem is that the system |
| 2524 | // cannot look into the extras as there may be parcelables there that |
| 2525 | // the platform does not know how to handle. To go around that we have |
| 2526 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2527 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2528 | if (collectPendingIntents) { |
| 2529 | PendingIntent.setOnMarshaledListener( |
| 2530 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2531 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2532 | if (allPendingIntents == null) { |
| 2533 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2534 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2535 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2536 | } |
| 2537 | }); |
| 2538 | } |
| 2539 | try { |
| 2540 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2541 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2542 | writeToParcelImpl(parcel, flags); |
| 2543 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2544 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2545 | } finally { |
| 2546 | if (collectPendingIntents) { |
| 2547 | PendingIntent.setOnMarshaledListener(null); |
| 2548 | } |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2553 | parcel.writeInt(1); |
| 2554 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2555 | parcel.writeStrongBinder(mWhitelistToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2556 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2557 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2558 | if (mSmallIcon == null && icon != 0) { |
| 2559 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2560 | mSmallIcon = Icon.createWithResource("", icon); |
| 2561 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2562 | if (mSmallIcon != null) { |
| 2563 | parcel.writeInt(1); |
| 2564 | mSmallIcon.writeToParcel(parcel, 0); |
| 2565 | } else { |
| 2566 | parcel.writeInt(0); |
| 2567 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2568 | parcel.writeInt(number); |
| 2569 | if (contentIntent != null) { |
| 2570 | parcel.writeInt(1); |
| 2571 | contentIntent.writeToParcel(parcel, 0); |
| 2572 | } else { |
| 2573 | parcel.writeInt(0); |
| 2574 | } |
| 2575 | if (deleteIntent != null) { |
| 2576 | parcel.writeInt(1); |
| 2577 | deleteIntent.writeToParcel(parcel, 0); |
| 2578 | } else { |
| 2579 | parcel.writeInt(0); |
| 2580 | } |
| 2581 | if (tickerText != null) { |
| 2582 | parcel.writeInt(1); |
| 2583 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2584 | } else { |
| 2585 | parcel.writeInt(0); |
| 2586 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2587 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2588 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2589 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2590 | } else { |
| 2591 | parcel.writeInt(0); |
| 2592 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2593 | if (contentView != null) { |
| 2594 | parcel.writeInt(1); |
| 2595 | contentView.writeToParcel(parcel, 0); |
| 2596 | } else { |
| 2597 | parcel.writeInt(0); |
| 2598 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2599 | if (mLargeIcon == null && largeIcon != null) { |
| 2600 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2601 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2602 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2603 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2604 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2605 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2606 | } else { |
| 2607 | parcel.writeInt(0); |
| 2608 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2609 | |
| 2610 | parcel.writeInt(defaults); |
| 2611 | parcel.writeInt(this.flags); |
| 2612 | |
| 2613 | if (sound != null) { |
| 2614 | parcel.writeInt(1); |
| 2615 | sound.writeToParcel(parcel, 0); |
| 2616 | } else { |
| 2617 | parcel.writeInt(0); |
| 2618 | } |
| 2619 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2620 | |
| 2621 | if (audioAttributes != null) { |
| 2622 | parcel.writeInt(1); |
| 2623 | audioAttributes.writeToParcel(parcel, 0); |
| 2624 | } else { |
| 2625 | parcel.writeInt(0); |
| 2626 | } |
| 2627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2628 | parcel.writeLongArray(vibrate); |
| 2629 | parcel.writeInt(ledARGB); |
| 2630 | parcel.writeInt(ledOnMS); |
| 2631 | parcel.writeInt(ledOffMS); |
| 2632 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2633 | |
| 2634 | if (fullScreenIntent != null) { |
| 2635 | parcel.writeInt(1); |
| 2636 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2637 | } else { |
| 2638 | parcel.writeInt(0); |
| 2639 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2640 | |
| 2641 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2642 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2643 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2644 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2645 | parcel.writeString(mGroupKey); |
| 2646 | |
| 2647 | parcel.writeString(mSortKey); |
| 2648 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2649 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2650 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2651 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2652 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2653 | if (bigContentView != null) { |
| 2654 | parcel.writeInt(1); |
| 2655 | bigContentView.writeToParcel(parcel, 0); |
| 2656 | } else { |
| 2657 | parcel.writeInt(0); |
| 2658 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2659 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2660 | if (headsUpContentView != null) { |
| 2661 | parcel.writeInt(1); |
| 2662 | headsUpContentView.writeToParcel(parcel, 0); |
| 2663 | } else { |
| 2664 | parcel.writeInt(0); |
| 2665 | } |
| 2666 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2667 | parcel.writeInt(visibility); |
| 2668 | |
| 2669 | if (publicVersion != null) { |
| 2670 | parcel.writeInt(1); |
| 2671 | publicVersion.writeToParcel(parcel, 0); |
| 2672 | } else { |
| 2673 | parcel.writeInt(0); |
| 2674 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2675 | |
| 2676 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2677 | |
| 2678 | if (mChannelId != null) { |
| 2679 | parcel.writeInt(1); |
| 2680 | parcel.writeString(mChannelId); |
| 2681 | } else { |
| 2682 | parcel.writeInt(0); |
| 2683 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2684 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2685 | |
| 2686 | if (mShortcutId != null) { |
| 2687 | parcel.writeInt(1); |
| 2688 | parcel.writeString(mShortcutId); |
| 2689 | } else { |
| 2690 | parcel.writeInt(0); |
| 2691 | } |
| 2692 | |
| 2693 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2694 | |
| 2695 | if (mSettingsText != null) { |
| 2696 | parcel.writeInt(1); |
| 2697 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2698 | } else { |
| 2699 | parcel.writeInt(0); |
| 2700 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2701 | |
| 2702 | parcel.writeInt(mGroupAlertBehavior); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2703 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2704 | if (mAppOverlayIntent != null) { |
| 2705 | parcel.writeInt(1); |
| 2706 | mAppOverlayIntent.writeToParcel(parcel, 0); |
| 2707 | } else { |
| 2708 | parcel.writeInt(0); |
| 2709 | } |
| 2710 | |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 2711 | parcel.writeBoolean(mAllowSystemGeneratedContextualActions); |
| 2712 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2713 | // 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] | 2714 | } |
| 2715 | |
| 2716 | /** |
| 2717 | * Parcelable.Creator that instantiates Notification objects |
| 2718 | */ |
| 2719 | public static final Parcelable.Creator<Notification> CREATOR |
| 2720 | = new Parcelable.Creator<Notification>() |
| 2721 | { |
| 2722 | public Notification createFromParcel(Parcel parcel) |
| 2723 | { |
| 2724 | return new Notification(parcel); |
| 2725 | } |
| 2726 | |
| 2727 | public Notification[] newArray(int size) |
| 2728 | { |
| 2729 | return new Notification[size]; |
| 2730 | } |
| 2731 | }; |
| 2732 | |
| 2733 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2734 | * @hide |
| 2735 | */ |
| 2736 | public static boolean areActionsVisiblyDifferent(Notification first, Notification second) { |
| 2737 | Notification.Action[] firstAs = first.actions; |
| 2738 | Notification.Action[] secondAs = second.actions; |
| 2739 | if (firstAs == null && secondAs != null || firstAs != null && secondAs == null) { |
| 2740 | return true; |
| 2741 | } |
| 2742 | if (firstAs != null && secondAs != null) { |
| 2743 | if (firstAs.length != secondAs.length) { |
| 2744 | return true; |
| 2745 | } |
| 2746 | for (int i = 0; i < firstAs.length; i++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2747 | if (!Objects.equals(String.valueOf(firstAs[i].title), |
| 2748 | String.valueOf(secondAs[i].title))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2749 | return true; |
| 2750 | } |
| 2751 | RemoteInput[] firstRs = firstAs[i].getRemoteInputs(); |
| 2752 | RemoteInput[] secondRs = secondAs[i].getRemoteInputs(); |
| 2753 | if (firstRs == null) { |
| 2754 | firstRs = new RemoteInput[0]; |
| 2755 | } |
| 2756 | if (secondRs == null) { |
| 2757 | secondRs = new RemoteInput[0]; |
| 2758 | } |
| 2759 | if (firstRs.length != secondRs.length) { |
| 2760 | return true; |
| 2761 | } |
| 2762 | for (int j = 0; j < firstRs.length; j++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2763 | if (!Objects.equals(String.valueOf(firstRs[j].getLabel()), |
| 2764 | String.valueOf(secondRs[j].getLabel()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2765 | return true; |
| 2766 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2767 | } |
| 2768 | } |
| 2769 | } |
| 2770 | return false; |
| 2771 | } |
| 2772 | |
| 2773 | /** |
| 2774 | * @hide |
| 2775 | */ |
| 2776 | public static boolean areStyledNotificationsVisiblyDifferent(Builder first, Builder second) { |
| 2777 | if (first.getStyle() == null) { |
| 2778 | return second.getStyle() != null; |
| 2779 | } |
| 2780 | if (second.getStyle() == null) { |
| 2781 | return true; |
| 2782 | } |
| 2783 | return first.getStyle().areNotificationsVisiblyDifferent(second.getStyle()); |
| 2784 | } |
| 2785 | |
| 2786 | /** |
| 2787 | * @hide |
| 2788 | */ |
| 2789 | public static boolean areRemoteViewsChanged(Builder first, Builder second) { |
Julia Reynolds | e5c6045 | 2018-04-30 14:41:36 -0400 | [diff] [blame] | 2790 | if (!Objects.equals(first.usesStandardHeader(), second.usesStandardHeader())) { |
| 2791 | return true; |
| 2792 | } |
| 2793 | |
| 2794 | if (areRemoteViewsChanged(first.mN.contentView, second.mN.contentView)) { |
| 2795 | return true; |
| 2796 | } |
| 2797 | if (areRemoteViewsChanged(first.mN.bigContentView, second.mN.bigContentView)) { |
| 2798 | return true; |
| 2799 | } |
| 2800 | if (areRemoteViewsChanged(first.mN.headsUpContentView, second.mN.headsUpContentView)) { |
| 2801 | return true; |
| 2802 | } |
| 2803 | |
| 2804 | return false; |
| 2805 | } |
| 2806 | |
| 2807 | private static boolean areRemoteViewsChanged(RemoteViews first, RemoteViews second) { |
| 2808 | if (first == null && second == null) { |
| 2809 | return false; |
| 2810 | } |
| 2811 | if (first == null && second != null || first != null && second == null) { |
| 2812 | return true; |
| 2813 | } |
| 2814 | |
| 2815 | if (!Objects.equals(first.getLayoutId(), second.getLayoutId())) { |
| 2816 | return true; |
| 2817 | } |
| 2818 | |
| 2819 | if (!Objects.equals(first.getSequenceNumber(), second.getSequenceNumber())) { |
| 2820 | return true; |
| 2821 | } |
| 2822 | |
| 2823 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | /** |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2827 | * Parcelling creates multiple copies of objects in {@code extras}. Fix them. |
| 2828 | * <p> |
| 2829 | * For backwards compatibility {@code extras} holds some references to "real" member data such |
| 2830 | * as {@link getLargeIcon()} which is mirrored by {@link #EXTRA_LARGE_ICON}. This is mostly |
| 2831 | * fine as long as the object stays in one process. |
| 2832 | * <p> |
| 2833 | * However, once the notification goes into a parcel each reference gets marshalled separately, |
| 2834 | * wasting memory. Especially with large images on Auto and TV, this is worth fixing. |
| 2835 | */ |
| 2836 | private void fixDuplicateExtras() { |
| 2837 | if (extras != null) { |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2838 | fixDuplicateExtra(mLargeIcon, EXTRA_LARGE_ICON); |
| 2839 | } |
| 2840 | } |
| 2841 | |
| 2842 | /** |
| 2843 | * If we find an extra that's exactly the same as one of the "real" fields but refers to a |
| 2844 | * separate object, replace it with the field's version to avoid holding duplicate copies. |
| 2845 | */ |
| 2846 | private void fixDuplicateExtra(@Nullable Parcelable original, @NonNull String extraName) { |
| 2847 | if (original != null && extras.getParcelable(extraName) != null) { |
| 2848 | extras.putParcelable(extraName, original); |
| 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2854 | * layout. |
| 2855 | * |
| 2856 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2857 | * in the view.</p> |
| 2858 | * @param context The context for your application / activity. |
| 2859 | * @param contentTitle The title that goes in the expanded entry. |
| 2860 | * @param contentText The text that goes in the expanded entry. |
| 2861 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2862 | * If this is an activity, it must include the |
| 2863 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2864 | * that you take care of task management as described in the |
| 2865 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2866 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2867 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2868 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2869 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2871 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2872 | public void setLatestEventInfo(Context context, |
| 2873 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2874 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2875 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2876 | new Throwable()); |
| 2877 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2878 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2879 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2880 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2881 | } |
| 2882 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2883 | // ensure that any information already set directly is preserved |
| 2884 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2885 | |
| 2886 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2888 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | } |
| 2890 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2891 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2892 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2893 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2894 | |
| 2895 | 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] | 2896 | } |
| 2897 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2898 | /** |
| 2899 | * @hide |
| 2900 | */ |
| 2901 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2902 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | /** |
| 2906 | * @hide |
| 2907 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2908 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2909 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2910 | } |
| 2911 | |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 2912 | /** |
| 2913 | * @hide |
| 2914 | */ |
| 2915 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 2916 | long token = proto.start(fieldId); |
| 2917 | proto.write(NotificationProto.CHANNEL_ID, getChannelId()); |
| 2918 | proto.write(NotificationProto.HAS_TICKER_TEXT, this.tickerText != null); |
| 2919 | proto.write(NotificationProto.FLAGS, this.flags); |
| 2920 | proto.write(NotificationProto.COLOR, this.color); |
| 2921 | proto.write(NotificationProto.CATEGORY, this.category); |
| 2922 | proto.write(NotificationProto.GROUP_KEY, this.mGroupKey); |
| 2923 | proto.write(NotificationProto.SORT_KEY, this.mSortKey); |
| 2924 | if (this.actions != null) { |
| 2925 | proto.write(NotificationProto.ACTION_LENGTH, this.actions.length); |
| 2926 | } |
| 2927 | if (this.visibility >= VISIBILITY_SECRET && this.visibility <= VISIBILITY_PUBLIC) { |
| 2928 | proto.write(NotificationProto.VISIBILITY, this.visibility); |
| 2929 | } |
| 2930 | if (publicVersion != null) { |
| 2931 | publicVersion.writeToProto(proto, NotificationProto.PUBLIC_VERSION); |
| 2932 | } |
| 2933 | proto.end(token); |
| 2934 | } |
| 2935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2936 | @Override |
| 2937 | public String toString() { |
| 2938 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2939 | sb.append("Notification(channel="); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2940 | sb.append(getChannelId()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2941 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2942 | sb.append(priority); |
| 2943 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2944 | if (contentView != null) { |
| 2945 | sb.append(contentView.getPackage()); |
| 2946 | sb.append("/0x"); |
| 2947 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2948 | } else { |
| 2949 | sb.append("null"); |
| 2950 | } |
| 2951 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2952 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2953 | sb.append("default"); |
| 2954 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2955 | int N = this.vibrate.length-1; |
| 2956 | sb.append("["); |
| 2957 | for (int i=0; i<N; i++) { |
| 2958 | sb.append(this.vibrate[i]); |
| 2959 | sb.append(','); |
| 2960 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 2961 | if (N != -1) { |
| 2962 | sb.append(this.vibrate[N]); |
| 2963 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2964 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | } else { |
| 2966 | sb.append("null"); |
| 2967 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2968 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2969 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2970 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2971 | } else if (this.sound != null) { |
| 2972 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2973 | } else { |
| 2974 | sb.append("null"); |
| 2975 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 2976 | if (this.tickerText != null) { |
| 2977 | sb.append(" tick"); |
| 2978 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2979 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2980 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2981 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2982 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2983 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2984 | if (this.category != null) { |
| 2985 | sb.append(" category="); |
| 2986 | sb.append(this.category); |
| 2987 | } |
| 2988 | if (this.mGroupKey != null) { |
| 2989 | sb.append(" groupKey="); |
| 2990 | sb.append(this.mGroupKey); |
| 2991 | } |
| 2992 | if (this.mSortKey != null) { |
| 2993 | sb.append(" sortKey="); |
| 2994 | sb.append(this.mSortKey); |
| 2995 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2996 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2997 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2998 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2999 | } |
| 3000 | sb.append(" vis="); |
| 3001 | sb.append(visibilityToString(this.visibility)); |
| 3002 | if (this.publicVersion != null) { |
| 3003 | sb.append(" publicVersion="); |
| 3004 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3005 | } |
| 3006 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | return sb.toString(); |
| 3008 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3009 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 3010 | /** |
| 3011 | * {@hide} |
| 3012 | */ |
| 3013 | public static String visibilityToString(int vis) { |
| 3014 | switch (vis) { |
| 3015 | case VISIBILITY_PRIVATE: |
| 3016 | return "PRIVATE"; |
| 3017 | case VISIBILITY_PUBLIC: |
| 3018 | return "PUBLIC"; |
| 3019 | case VISIBILITY_SECRET: |
| 3020 | return "SECRET"; |
| 3021 | default: |
| 3022 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 3023 | } |
| 3024 | } |
| 3025 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3026 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 3027 | * {@hide} |
| 3028 | */ |
| 3029 | public static String priorityToString(@Priority int pri) { |
| 3030 | switch (pri) { |
| 3031 | case PRIORITY_MIN: |
| 3032 | return "MIN"; |
| 3033 | case PRIORITY_LOW: |
| 3034 | return "LOW"; |
| 3035 | case PRIORITY_DEFAULT: |
| 3036 | return "DEFAULT"; |
| 3037 | case PRIORITY_HIGH: |
| 3038 | return "HIGH"; |
| 3039 | case PRIORITY_MAX: |
| 3040 | return "MAX"; |
| 3041 | default: |
| 3042 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 3043 | } |
| 3044 | } |
| 3045 | |
Julia Reynolds | 6ad0aec | 2017-07-05 08:47:03 -0400 | [diff] [blame] | 3046 | /** |
| 3047 | * @hide |
| 3048 | */ |
| 3049 | public boolean hasCompletedProgress() { |
| 3050 | // not a progress notification; can't be complete |
| 3051 | if (!extras.containsKey(EXTRA_PROGRESS) |
| 3052 | || !extras.containsKey(EXTRA_PROGRESS_MAX)) { |
| 3053 | return false; |
| 3054 | } |
| 3055 | // many apps use max 0 for 'indeterminate'; not complete |
| 3056 | if (extras.getInt(EXTRA_PROGRESS_MAX) == 0) { |
| 3057 | return false; |
| 3058 | } |
| 3059 | return extras.getInt(EXTRA_PROGRESS) == extras.getInt(EXTRA_PROGRESS_MAX); |
| 3060 | } |
| 3061 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3062 | /** @removed */ |
| 3063 | @Deprecated |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 3064 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3065 | return mChannelId; |
| 3066 | } |
| 3067 | |
| 3068 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3069 | * Returns the id of the channel this notification posts to. |
| 3070 | */ |
| 3071 | public String getChannelId() { |
| 3072 | return mChannelId; |
| 3073 | } |
| 3074 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3075 | /** @removed */ |
| 3076 | @Deprecated |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3077 | public long getTimeout() { |
| 3078 | return mTimeout; |
| 3079 | } |
| 3080 | |
| 3081 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3082 | * Returns the duration from posting after which this notification should be canceled by the |
| 3083 | * system, if it's not canceled already. |
| 3084 | */ |
| 3085 | public long getTimeoutAfter() { |
| 3086 | return mTimeout; |
| 3087 | } |
| 3088 | |
| 3089 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3090 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 3091 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 3092 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 3093 | */ |
| 3094 | public int getBadgeIconType() { |
| 3095 | return mBadgeIcon; |
| 3096 | } |
| 3097 | |
| 3098 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3099 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3100 | * |
| 3101 | * <p>Used by some Launchers that display notification content to hide shortcuts that duplicate |
| 3102 | * notifications. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3103 | */ |
| 3104 | public String getShortcutId() { |
| 3105 | return mShortcutId; |
| 3106 | } |
| 3107 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3108 | |
| 3109 | /** |
| 3110 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 3111 | */ |
| 3112 | public CharSequence getSettingsText() { |
| 3113 | return mSettingsText; |
| 3114 | } |
| 3115 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3116 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3117 | * Returns which type of notifications in a group are responsible for audibly alerting the |
| 3118 | * user. See {@link #GROUP_ALERT_ALL}, {@link #GROUP_ALERT_CHILDREN}, |
| 3119 | * {@link #GROUP_ALERT_SUMMARY}. |
| 3120 | */ |
| 3121 | public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 3122 | return mGroupAlertBehavior; |
| 3123 | } |
| 3124 | |
| 3125 | /** |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3126 | * Returns the intent that will be used to display app content in a floating window over the |
| 3127 | * existing foreground activity. |
| 3128 | */ |
| 3129 | public PendingIntent getAppOverlayIntent() { |
| 3130 | return mAppOverlayIntent; |
| 3131 | } |
| 3132 | |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 3133 | public boolean getAllowSystemGeneratedContextualActions() { |
| 3134 | return mAllowSystemGeneratedContextualActions; |
| 3135 | } |
| 3136 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3137 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3138 | * The small icon representing this notification in the status bar and content view. |
| 3139 | * |
| 3140 | * @return the small icon representing this notification. |
| 3141 | * |
| 3142 | * @see Builder#getSmallIcon() |
| 3143 | * @see Builder#setSmallIcon(Icon) |
| 3144 | */ |
| 3145 | public Icon getSmallIcon() { |
| 3146 | return mSmallIcon; |
| 3147 | } |
| 3148 | |
| 3149 | /** |
| 3150 | * Used when notifying to clean up legacy small icons. |
| 3151 | * @hide |
| 3152 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3153 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3154 | public void setSmallIcon(Icon icon) { |
| 3155 | mSmallIcon = icon; |
| 3156 | } |
| 3157 | |
| 3158 | /** |
| 3159 | * The large icon shown in this notification's content view. |
| 3160 | * @see Builder#getLargeIcon() |
| 3161 | * @see Builder#setLargeIcon(Icon) |
| 3162 | */ |
| 3163 | public Icon getLargeIcon() { |
| 3164 | return mLargeIcon; |
| 3165 | } |
| 3166 | |
| 3167 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3168 | * @hide |
| 3169 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3170 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3171 | public boolean isGroupSummary() { |
| 3172 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 3173 | } |
| 3174 | |
| 3175 | /** |
| 3176 | * @hide |
| 3177 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3178 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3179 | public boolean isGroupChild() { |
| 3180 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 3181 | } |
| 3182 | |
| 3183 | /** |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3184 | * @hide |
| 3185 | */ |
| 3186 | public boolean suppressAlertingDueToGrouping() { |
| 3187 | if (isGroupSummary() |
| 3188 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { |
| 3189 | return true; |
| 3190 | } else if (isGroupChild() |
| 3191 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { |
| 3192 | return true; |
| 3193 | } |
| 3194 | return false; |
| 3195 | } |
| 3196 | |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 3197 | |
| 3198 | /** |
| 3199 | * Finds and returns a remote input and its corresponding action. |
| 3200 | * |
| 3201 | * @param requiresFreeform requires the remoteinput to allow freeform or not. |
| 3202 | * @return the result pair, {@code null} if no result is found. |
| 3203 | * |
| 3204 | * @hide |
| 3205 | */ |
| 3206 | @Nullable |
| 3207 | public Pair<RemoteInput, Action> findRemoteInputActionPair(boolean requiresFreeform) { |
| 3208 | if (actions == null) { |
| 3209 | return null; |
| 3210 | } |
| 3211 | for (Notification.Action action : actions) { |
| 3212 | if (action.getRemoteInputs() == null) { |
| 3213 | continue; |
| 3214 | } |
| 3215 | RemoteInput resultRemoteInput = null; |
| 3216 | for (RemoteInput remoteInput : action.getRemoteInputs()) { |
| 3217 | if (remoteInput.getAllowFreeFormInput() || !requiresFreeform) { |
| 3218 | resultRemoteInput = remoteInput; |
| 3219 | } |
| 3220 | } |
| 3221 | if (resultRemoteInput != null) { |
| 3222 | return Pair.create(resultRemoteInput, action); |
| 3223 | } |
| 3224 | } |
| 3225 | return null; |
| 3226 | } |
| 3227 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3228 | /** |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 3229 | * Returns the actions that are contextual (marked as SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION) out |
| 3230 | * of the actions in this notification. |
| 3231 | * |
| 3232 | * @hide |
| 3233 | */ |
| 3234 | public List<Notification.Action> getContextualActions() { |
| 3235 | if (actions == null) return Collections.emptyList(); |
| 3236 | |
| 3237 | List<Notification.Action> contextualActions = new ArrayList<>(); |
| 3238 | for (Notification.Action action : actions) { |
| 3239 | if (action.getSemanticAction() |
| 3240 | == Notification.Action.SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION) { |
| 3241 | contextualActions.add(action); |
| 3242 | } |
| 3243 | } |
| 3244 | return contextualActions; |
| 3245 | } |
| 3246 | |
| 3247 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3248 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3249 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3250 | * 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] | 3251 | * content views using the platform's notification layout template. If your app supports |
| 3252 | * versions of Android as old as API level 4, you can instead use |
| 3253 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 3254 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 3255 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3256 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3257 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3258 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3259 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3260 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3261 | * .setContentTitle("New mail from " + sender.toString()) |
| 3262 | * .setContentText(subject) |
| 3263 | * .setSmallIcon(R.drawable.new_mail) |
| 3264 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3265 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3266 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3267 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3268 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3269 | /** |
| 3270 | * @hide |
| 3271 | */ |
| 3272 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 3273 | "android.rebuild.contentViewActionCount"; |
| 3274 | /** |
| 3275 | * @hide |
| 3276 | */ |
| 3277 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 3278 | = "android.rebuild.bigViewActionCount"; |
| 3279 | /** |
| 3280 | * @hide |
| 3281 | */ |
| 3282 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 3283 | = "android.rebuild.hudViewActionCount"; |
| 3284 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 3285 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 3286 | SystemProperties.getBoolean("notifications.only_title", true); |
| 3287 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3288 | /** |
| 3289 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3290 | * secondary text color when the background is light. |
| 3291 | */ |
| 3292 | private static final int LIGHTNESS_TEXT_DIFFERENCE_LIGHT = 20; |
| 3293 | |
| 3294 | /** |
| 3295 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3296 | * secondary text color when the background is dark. |
| 3297 | * A bit less then the above value, since it looks better on dark backgrounds. |
| 3298 | */ |
| 3299 | private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10; |
| 3300 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3301 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3302 | private Notification mN; |
| 3303 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3304 | private Style mStyle; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3305 | @UnsupportedAppUsage |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3306 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3307 | private ArrayList<Person> mPersonList = new ArrayList<>(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3308 | private ContrastColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3309 | private boolean mIsLegacy; |
| 3310 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3311 | |
| 3312 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3313 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 3314 | */ |
| 3315 | private int mCachedContrastColor = COLOR_INVALID; |
| 3316 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3317 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3318 | * Caches a ambient version of {@link #mCachedAmbientColorIsFor}. |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3319 | */ |
| 3320 | private int mCachedAmbientColor = COLOR_INVALID; |
| 3321 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3322 | /** |
| 3323 | * A neutral color color that can be used for icons. |
| 3324 | */ |
| 3325 | private int mNeutralColor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3326 | |
| 3327 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3328 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 3329 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 3330 | */ |
| 3331 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3332 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 3333 | private int mPrimaryTextColor = COLOR_INVALID; |
| 3334 | private int mSecondaryTextColor = COLOR_INVALID; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3335 | private int mBackgroundColor = COLOR_INVALID; |
| 3336 | private int mForegroundColor = COLOR_INVALID; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 3337 | /** |
| 3338 | * A temporary location where actions are stored. If != null the view originally has action |
| 3339 | * but doesn't have any for this inflation. |
| 3340 | */ |
| 3341 | private ArrayList<Action> mOriginalActions; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 3342 | private boolean mRebuildStyledRemoteViews; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3343 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3344 | private boolean mTintActionButtons; |
| 3345 | private boolean mInNightMode; |
| 3346 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3347 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3348 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3349 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3350 | * @param context |
| 3351 | * A {@link Context} that will be used by the Builder to construct the |
| 3352 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 3353 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3354 | * @param channelId |
| 3355 | * The constructed Notification will be posted on this |
| 3356 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 3357 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3358 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3359 | public Builder(Context context, String channelId) { |
| 3360 | this(context, (Notification) null); |
| 3361 | mN.mChannelId = channelId; |
| 3362 | } |
| 3363 | |
| 3364 | /** |
| 3365 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 3366 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 3367 | */ |
| 3368 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3369 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3370 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3371 | } |
| 3372 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3373 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3374 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3375 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3376 | public Builder(Context context, Notification toAdopt) { |
| 3377 | mContext = context; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3378 | Resources res = mContext.getResources(); |
| 3379 | mTintActionButtons = res.getBoolean(R.bool.config_tintNotificationActionButtons); |
| 3380 | |
| 3381 | if (res.getBoolean(R.bool.config_enableNightMode)) { |
| 3382 | Configuration currentConfig = res.getConfiguration(); |
| 3383 | mInNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 3384 | == Configuration.UI_MODE_NIGHT_YES; |
| 3385 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3386 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3387 | if (toAdopt == null) { |
| 3388 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3389 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 3390 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 3391 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3392 | mN.priority = PRIORITY_DEFAULT; |
| 3393 | mN.visibility = VISIBILITY_PRIVATE; |
| 3394 | } else { |
| 3395 | mN = toAdopt; |
| 3396 | if (mN.actions != null) { |
| 3397 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3398 | } |
| 3399 | |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3400 | if (mN.extras.containsKey(EXTRA_PEOPLE_LIST)) { |
| 3401 | ArrayList<Person> people = mN.extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 3402 | mPersonList.addAll(people); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3403 | } |
| 3404 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 3405 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 3406 | setSmallIcon(mN.icon); |
| 3407 | } |
| 3408 | |
| 3409 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 3410 | setLargeIcon(mN.largeIcon); |
| 3411 | } |
| 3412 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3413 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 3414 | if (!TextUtils.isEmpty(templateClass)) { |
| 3415 | final Class<? extends Style> styleClass |
| 3416 | = getNotificationStyleClass(templateClass); |
| 3417 | if (styleClass == null) { |
| 3418 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 3419 | } else { |
| 3420 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3421 | final Constructor<? extends Style> ctor = |
| 3422 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3423 | ctor.setAccessible(true); |
| 3424 | final Style style = ctor.newInstance(); |
| 3425 | style.restoreFromExtras(mN.extras); |
| 3426 | |
| 3427 | if (style != null) { |
| 3428 | setStyle(style); |
| 3429 | } |
| 3430 | } catch (Throwable t) { |
| 3431 | Log.e(TAG, "Could not create Style", t); |
| 3432 | } |
| 3433 | } |
| 3434 | } |
| 3435 | |
| 3436 | } |
| 3437 | } |
| 3438 | |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3439 | private ContrastColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3440 | if (mColorUtil == null) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3441 | mColorUtil = ContrastColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3442 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3443 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3447 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 3448 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 3449 | * the shortcut. |
| 3450 | * |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3451 | * This field will be ignored by Launchers that don't support badging, don't show |
| 3452 | * notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3453 | * |
| 3454 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 3455 | * supersedes |
| 3456 | */ |
| 3457 | public Builder setShortcutId(String shortcutId) { |
| 3458 | mN.mShortcutId = shortcutId; |
| 3459 | return this; |
| 3460 | } |
| 3461 | |
| 3462 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3463 | * Sets which icon to display as a badge for this notification. |
| 3464 | * |
| 3465 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 3466 | * {@link #BADGE_ICON_LARGE}. |
| 3467 | * |
| 3468 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 3469 | */ |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 3470 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3471 | mN.mBadgeIcon = icon; |
| 3472 | return this; |
| 3473 | } |
| 3474 | |
| 3475 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3476 | * Sets the group alert behavior for this notification. Use this method to mute this |
| 3477 | * notification if alerts for this notification's group should be handled by a different |
| 3478 | * notification. This is only applicable for notifications that belong to a |
Julia Reynolds | 399d9bf | 2017-08-11 12:52:14 -0400 | [diff] [blame] | 3479 | * {@link #setGroup(String) group}. This must be called on all notifications you want to |
| 3480 | * mute. For example, if you want only the summary of your group to make noise, all |
| 3481 | * 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] | 3482 | * |
| 3483 | * <p> The default value is {@link #GROUP_ALERT_ALL}.</p> |
| 3484 | */ |
| 3485 | public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 3486 | mN.mGroupAlertBehavior = groupAlertBehavior; |
| 3487 | return this; |
| 3488 | } |
| 3489 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3490 | /** |
| 3491 | * Sets the intent that will be used to display app content in a floating window |
| 3492 | * over the existing foreground activity. |
| 3493 | * |
| 3494 | * <p>This intent will be ignored unless this notification is posted to a channel that |
| 3495 | * allows {@link NotificationChannel#canOverlayApps() app overlays}.</p> |
| 3496 | * |
| 3497 | * <p>Notifications with a valid and allowed app overlay intent will be displayed as |
| 3498 | * floating windows outside of the notification shade on unlocked devices. When a user |
| 3499 | * interacts with one of these windows, this app overlay intent will be invoked and |
| 3500 | * displayed.</p> |
| 3501 | */ |
| 3502 | public Builder setAppOverlayIntent(PendingIntent intent) { |
| 3503 | mN.mAppOverlayIntent = intent; |
| 3504 | return this; |
| 3505 | } |
| 3506 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3507 | /** @removed */ |
| 3508 | @Deprecated |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3509 | public Builder setChannel(String channelId) { |
| 3510 | mN.mChannelId = channelId; |
| 3511 | return this; |
| 3512 | } |
| 3513 | |
| 3514 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3515 | * Specifies the channel the notification should be delivered on. |
| 3516 | */ |
| 3517 | public Builder setChannelId(String channelId) { |
| 3518 | mN.mChannelId = channelId; |
| 3519 | return this; |
| 3520 | } |
| 3521 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3522 | /** @removed */ |
| 3523 | @Deprecated |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 3524 | public Builder setTimeout(long durationMs) { |
| 3525 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3526 | return this; |
| 3527 | } |
| 3528 | |
| 3529 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3530 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 3531 | * if it is not already canceled. |
| 3532 | */ |
| 3533 | public Builder setTimeoutAfter(long durationMs) { |
| 3534 | mN.mTimeout = durationMs; |
| 3535 | return this; |
| 3536 | } |
| 3537 | |
| 3538 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3539 | * 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] | 3540 | * |
| 3541 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 3542 | * shown anymore by default and must be opted into by using |
| 3543 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3544 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3545 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3546 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3547 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3548 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3549 | return this; |
| 3550 | } |
| 3551 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3552 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 3553 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3554 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3555 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 3556 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3557 | */ |
| 3558 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3559 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3560 | return this; |
| 3561 | } |
| 3562 | |
| 3563 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3564 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3565 | * |
| 3566 | * 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] | 3567 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3568 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3569 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 3570 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3571 | * 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] | 3572 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3573 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3574 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3575 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3576 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3577 | */ |
| 3578 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3579 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3580 | return this; |
| 3581 | } |
| 3582 | |
| 3583 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3584 | * Sets the Chronometer to count down instead of counting up. |
| 3585 | * |
| 3586 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 3587 | * If it isn't set the chronometer will count up. |
| 3588 | * |
| 3589 | * @see #setUsesChronometer(boolean) |
| 3590 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3591 | public Builder setChronometerCountDown(boolean countDown) { |
| 3592 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3593 | return this; |
| 3594 | } |
| 3595 | |
| 3596 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3597 | * Set the small icon resource, which will be used to represent the notification in the |
| 3598 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3599 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3600 | |
| 3601 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 3602 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 3603 | * icon will be moved to the right-hand side. |
| 3604 | * |
| 3605 | |
| 3606 | * @param icon |
| 3607 | * A resource ID in the application's package of the drawable to use. |
| 3608 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3609 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3610 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3611 | return setSmallIcon(icon != 0 |
| 3612 | ? Icon.createWithResource(mContext, icon) |
| 3613 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3614 | } |
| 3615 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3616 | /** |
| 3617 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 3618 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 3619 | * LevelListDrawable}. |
| 3620 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3621 | * @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] | 3622 | * @param level The level to use for the icon. |
| 3623 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3624 | * @see Notification#icon |
| 3625 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3626 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3627 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3628 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3629 | return setSmallIcon(icon); |
| 3630 | } |
| 3631 | |
| 3632 | /** |
| 3633 | * 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] | 3634 | * status bar and content view (unless overridden there by a |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3635 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 3636 | * |
| 3637 | * @param icon An Icon object to use. |
| 3638 | * @see Notification#icon |
| 3639 | */ |
| 3640 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3641 | mN.setSmallIcon(icon); |
| 3642 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 3643 | mN.icon = icon.getResId(); |
| 3644 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3645 | return this; |
| 3646 | } |
| 3647 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3648 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3649 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3650 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3651 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3652 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3653 | return this; |
| 3654 | } |
| 3655 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3656 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3657 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3658 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3659 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3660 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3661 | return this; |
| 3662 | } |
| 3663 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3664 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3665 | * This provides some additional information that is displayed in the notification. No |
| 3666 | * guarantees are given where exactly it is displayed. |
| 3667 | * |
| 3668 | * <p>This information should only be provided if it provides an essential |
| 3669 | * benefit to the understanding of the notification. The more text you provide the |
| 3670 | * less readable it becomes. For example, an email client should only provide the account |
| 3671 | * name here if more than one email account has been added.</p> |
| 3672 | * |
| 3673 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 3674 | * notification header area. |
| 3675 | * |
| 3676 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 3677 | * this will be shown in the third line of text in the platform notification template. |
| 3678 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 3679 | * same time on those versions; they occupy the same place. |
| 3680 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3681 | */ |
| 3682 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3683 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3684 | return this; |
| 3685 | } |
| 3686 | |
| 3687 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3688 | * Provides text that will appear as a link to your application's settings. |
| 3689 | * |
| 3690 | * <p>This text does not appear within notification {@link Style templates} but may |
| 3691 | * appear when the user uses an affordance to learn more about the notification. |
| 3692 | * Additionally, this text will not appear unless you provide a valid link target by |
| 3693 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 3694 | * |
| 3695 | * <p>This text is meant to be concise description about what the user can customize |
| 3696 | * when they click on this link. The recommended maximum length is 40 characters. |
| 3697 | * @param text |
| 3698 | * @return |
| 3699 | */ |
| 3700 | public Builder setSettingsText(CharSequence text) { |
| 3701 | mN.mSettingsText = safeCharSequence(text); |
| 3702 | return this; |
| 3703 | } |
| 3704 | |
| 3705 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3706 | * Set the remote input history. |
| 3707 | * |
| 3708 | * This should be set to the most recent inputs that have been sent |
| 3709 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 3710 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 3711 | * |
| 3712 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 3713 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 3714 | * and how much of each individual input is shown. |
| 3715 | * |
| 3716 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 3717 | * with a {@code RemoteInput}.</p> |
| 3718 | */ |
| 3719 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 3720 | if (text == null) { |
| 3721 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 3722 | } else { |
| 3723 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 3724 | CharSequence[] safe = new CharSequence[N]; |
| 3725 | for (int i = 0; i < N; i++) { |
| 3726 | safe[i] = safeCharSequence(text[i]); |
| 3727 | } |
| 3728 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 3729 | } |
| 3730 | return this; |
| 3731 | } |
| 3732 | |
| 3733 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 3734 | * Sets whether remote history entries view should have a spinner. |
| 3735 | * @hide |
| 3736 | */ |
| 3737 | public Builder setShowRemoteInputSpinner(boolean showSpinner) { |
| 3738 | mN.extras.putBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER, showSpinner); |
| 3739 | return this; |
| 3740 | } |
| 3741 | |
| 3742 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 3743 | * Sets whether smart reply buttons should be hidden. |
| 3744 | * @hide |
| 3745 | */ |
| 3746 | public Builder setHideSmartReplies(boolean hideSmartReplies) { |
| 3747 | mN.extras.putBoolean(EXTRA_HIDE_SMART_REPLIES, hideSmartReplies); |
| 3748 | return this; |
| 3749 | } |
| 3750 | |
| 3751 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3752 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 3753 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3754 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3755 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3756 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3757 | return this; |
| 3758 | } |
| 3759 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3760 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3761 | * A small piece of additional information pertaining to this notification. |
| 3762 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3763 | * The platform template will draw this on the last line of the notification, at the far |
| 3764 | * 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] | 3765 | * |
| 3766 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 3767 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 3768 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3769 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3770 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3771 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3772 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3773 | return this; |
| 3774 | } |
| 3775 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3776 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3777 | * Set the progress this notification represents. |
| 3778 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3779 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3780 | */ |
| 3781 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3782 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3783 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3784 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3785 | return this; |
| 3786 | } |
| 3787 | |
| 3788 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3789 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3790 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3791 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3792 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3793 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3794 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3795 | return setCustomContentView(views); |
| 3796 | } |
| 3797 | |
| 3798 | /** |
| 3799 | * Supply custom RemoteViews to use instead of the platform template. |
| 3800 | * |
| 3801 | * This will override the layout that would otherwise be constructed by this Builder |
| 3802 | * object. |
| 3803 | */ |
| 3804 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3805 | mN.contentView = contentView; |
| 3806 | return this; |
| 3807 | } |
| 3808 | |
| 3809 | /** |
| 3810 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3811 | * |
| 3812 | * This will override the expanded layout that would otherwise be constructed by this |
| 3813 | * Builder object. |
| 3814 | */ |
| 3815 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3816 | mN.bigContentView = contentView; |
| 3817 | return this; |
| 3818 | } |
| 3819 | |
| 3820 | /** |
| 3821 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3822 | * |
| 3823 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3824 | * Builder object. |
| 3825 | */ |
| 3826 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3827 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3828 | return this; |
| 3829 | } |
| 3830 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3831 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3832 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3833 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3834 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3835 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3836 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3837 | * 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] | 3838 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3839 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3840 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3841 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3842 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3843 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -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 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3849 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3850 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3851 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3852 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3853 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3854 | return this; |
| 3855 | } |
| 3856 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3857 | /** |
| 3858 | * An intent to launch instead of posting the notification to the status bar. |
| 3859 | * Only for use with extremely high-priority notifications demanding the user's |
| 3860 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3861 | * alarm clock that the user has explicitly set to a particular time. |
| 3862 | * If this facility is used for something else, please give the user an option |
| 3863 | * to turn it off and use a normal notification, as this can be extremely |
| 3864 | * disruptive. |
| 3865 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3866 | * <p> |
| 3867 | * The system UI may choose to display a heads-up notification, instead of |
| 3868 | * launching this intent, while the user is using the device. |
| 3869 | * </p> |
Julia Reynolds | 47fd15f | 2018-11-28 10:16:00 -0500 | [diff] [blame] | 3870 | * <p>Apps targeting {@link Build.VERSION_CODES#Q} and above will have to request |
| 3871 | * a permission ({@link android.Manifest.permission#USE_FULL_SCREEN_INTENT}) in order to |
| 3872 | * use full screen intents.</p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3873 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3874 | * @param intent The pending intent to launch. |
| 3875 | * @param highPriority Passing true will cause this notification to be sent |
| 3876 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3877 | * |
| 3878 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3879 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3880 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3881 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3882 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3883 | return this; |
| 3884 | } |
| 3885 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3886 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3887 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3888 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3889 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3890 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3891 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3892 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3893 | return this; |
| 3894 | } |
| 3895 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3896 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3897 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3898 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3899 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3900 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3901 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3902 | setTicker(tickerText); |
| 3903 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3904 | return this; |
| 3905 | } |
| 3906 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3907 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3908 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3909 | * |
| 3910 | * 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] | 3911 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3912 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3913 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3914 | public Builder setLargeIcon(Bitmap b) { |
| 3915 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3916 | } |
| 3917 | |
| 3918 | /** |
| 3919 | * Add a large icon to the notification content view. |
| 3920 | * |
| 3921 | * In the platform template, this image will be shown on the left of the notification view |
| 3922 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3923 | * badge atop the large icon). |
| 3924 | */ |
| 3925 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3926 | mN.mLargeIcon = icon; |
| 3927 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3928 | return this; |
| 3929 | } |
| 3930 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3931 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3932 | * Set the sound to play. |
| 3933 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3934 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 3935 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3936 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3937 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3938 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3939 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3940 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3941 | mN.sound = sound; |
| 3942 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3943 | return this; |
| 3944 | } |
| 3945 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3946 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3947 | * 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] | 3948 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3949 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 3950 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3951 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3952 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 3953 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3954 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 3955 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3956 | mN.sound = sound; |
| 3957 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3958 | return this; |
| 3959 | } |
| 3960 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3961 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3962 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 3963 | * use during playback. |
| 3964 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3965 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3966 | * @see Notification#sound |
| 3967 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3968 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3969 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3970 | mN.sound = sound; |
| 3971 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3972 | return this; |
| 3973 | } |
| 3974 | |
| 3975 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3976 | * Set the vibration pattern to use. |
| 3977 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3978 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 3979 | * <code>pattern</code> parameter. |
| 3980 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3981 | * <p> |
| 3982 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 3983 | * </p> |
| 3984 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3985 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3986 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3987 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3988 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3989 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3990 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3991 | return this; |
| 3992 | } |
| 3993 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3994 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3995 | * Set the desired color for the indicator LED on the device, as well as the |
| 3996 | * blink duty cycle (specified in milliseconds). |
| 3997 | * |
| 3998 | |
| 3999 | * Not all devices will honor all (or even any) of these values. |
| 4000 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 4001 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4002 | * @see Notification#ledARGB |
| 4003 | * @see Notification#ledOnMS |
| 4004 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4005 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4006 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4007 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4008 | mN.ledARGB = argb; |
| 4009 | mN.ledOnMS = onMs; |
| 4010 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4011 | if (onMs != 0 || offMs != 0) { |
| 4012 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 4013 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4014 | return this; |
| 4015 | } |
| 4016 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4017 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4018 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4019 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4020 | |
| 4021 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 4022 | * must take care of canceling them. |
| 4023 | * |
| 4024 | |
| 4025 | * They are typically used to indicate a background task that the user is actively engaged |
| 4026 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 4027 | * (e.g., a file download, sync operation, active network connection). |
| 4028 | * |
| 4029 | |
| 4030 | * @see Notification#FLAG_ONGOING_EVENT |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4031 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4032 | public Builder setOngoing(boolean ongoing) { |
| 4033 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 4034 | return this; |
| 4035 | } |
| 4036 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4037 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4038 | * Set whether this notification should be colorized. When set, the color set with |
| 4039 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 4040 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4041 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 4042 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4043 | * <p> |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 4044 | * For most styles, the coloring will only be applied if the notification is for a |
| 4045 | * foreground service notification. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4046 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 4047 | * that have a media session attached there is no such requirement. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4048 | * |
Aurimas Liutikas | 7f69533 | 2018-05-31 21:07:32 -0700 | [diff] [blame] | 4049 | * @see #setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4050 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4051 | */ |
| 4052 | public Builder setColorized(boolean colorize) { |
| 4053 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 4054 | return this; |
| 4055 | } |
| 4056 | |
| 4057 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4058 | * Set this flag if you would only like the sound, vibrate |
| 4059 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4060 | * |
| 4061 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4062 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4063 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 4064 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 4065 | return this; |
| 4066 | } |
| 4067 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4068 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4069 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4070 | * |
| 4071 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4072 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4073 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 4074 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4075 | return this; |
| 4076 | } |
| 4077 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4078 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 4079 | * Set whether or not this notification should not bridge to other devices. |
| 4080 | * |
| 4081 | * <p>Some notifications can be bridged to other devices for remote display. |
| 4082 | * This hint can be set to recommend this notification not be bridged. |
| 4083 | */ |
| 4084 | public Builder setLocalOnly(boolean localOnly) { |
| 4085 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 4086 | return this; |
| 4087 | } |
| 4088 | |
| 4089 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4090 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4091 | * <p> |
| 4092 | * The value should be one or more of the following fields combined with |
| 4093 | * bitwise-or: |
| 4094 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 4095 | * <p> |
| 4096 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4097 | * |
| 4098 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 4099 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4100 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4101 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4102 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4103 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4104 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4105 | return this; |
| 4106 | } |
| 4107 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4108 | /** |
| 4109 | * Set the priority of this notification. |
| 4110 | * |
| 4111 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4112 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4113 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4114 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4115 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4116 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4117 | return this; |
| 4118 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4119 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4120 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4121 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4122 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4123 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4124 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4125 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4126 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4127 | return this; |
| 4128 | } |
| 4129 | |
| 4130 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4131 | * Add a person that is relevant to this notification. |
| 4132 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4133 | * <P> |
| 4134 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 4135 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4136 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4137 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4138 | * </P> |
| 4139 | * |
| 4140 | * <P> |
| 4141 | * The person should be specified by the {@code String} representation of a |
| 4142 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 4143 | * </P> |
| 4144 | * |
| 4145 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 4146 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 4147 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 4148 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4149 | * It is also possible to provide a URI with the schema {@code name:} in order to uniquely |
| 4150 | * identify a person without an entry in the contacts database. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4151 | * </P> |
| 4152 | * |
| 4153 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4154 | * @see Notification#EXTRA_PEOPLE |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4155 | * @deprecated use {@link #addPerson(Person)} |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4156 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4157 | public Builder addPerson(String uri) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 4158 | addPerson(new Person.Builder().setUri(uri).build()); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4159 | return this; |
| 4160 | } |
| 4161 | |
| 4162 | /** |
| 4163 | * Add a person that is relevant to this notification. |
| 4164 | * |
| 4165 | * <P> |
| 4166 | * Depending on user preferences, this annotation may allow the notification to pass |
| 4167 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4168 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4169 | * appear more prominently in the user interface. |
| 4170 | * </P> |
| 4171 | * |
| 4172 | * <P> |
| 4173 | * A person should usually contain a uri in order to benefit from the ranking boost. |
| 4174 | * However, even if no uri is provided, it's beneficial to provide other people in the |
| 4175 | * notification, such that listeners and voice only devices can announce and handle them |
| 4176 | * properly. |
| 4177 | * </P> |
| 4178 | * |
| 4179 | * @param person the person to add. |
| 4180 | * @see Notification#EXTRA_PEOPLE_LIST |
| 4181 | */ |
| 4182 | public Builder addPerson(Person person) { |
| 4183 | mPersonList.add(person); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4184 | return this; |
| 4185 | } |
| 4186 | |
| 4187 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4188 | * Set this notification to be part of a group of notifications sharing the same key. |
| 4189 | * Grouped notifications may display in a cluster or stack on devices which |
| 4190 | * support such rendering. |
| 4191 | * |
| 4192 | * <p>To make this notification the summary for its group, also call |
| 4193 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 4194 | * {@link #setSortKey}. |
| 4195 | * @param groupKey The group key of the group. |
| 4196 | * @return this object for method chaining |
| 4197 | */ |
| 4198 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4199 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4200 | return this; |
| 4201 | } |
| 4202 | |
| 4203 | /** |
| 4204 | * Set this notification to be the group summary for a group of notifications. |
| 4205 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4206 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 4207 | * 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] | 4208 | * @param isGroupSummary Whether this notification should be a group summary. |
| 4209 | * @return this object for method chaining |
| 4210 | */ |
| 4211 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 4212 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 4213 | return this; |
| 4214 | } |
| 4215 | |
| 4216 | /** |
| 4217 | * Set a sort key that orders this notification among other notifications from the |
| 4218 | * same package. This can be useful if an external sort was already applied and an app |
| 4219 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 4220 | * value, although providing different priorities in addition to providing sort key may |
| 4221 | * cause this value to be ignored. |
| 4222 | * |
| 4223 | * <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] | 4224 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4225 | * |
| 4226 | * @see String#compareTo(String) |
| 4227 | */ |
| 4228 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4229 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4230 | return this; |
| 4231 | } |
| 4232 | |
| 4233 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4234 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4235 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4236 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 4237 | * |
| 4238 | * @see Notification#extras |
| 4239 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4240 | public Builder addExtras(Bundle extras) { |
| 4241 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4242 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4243 | } |
| 4244 | return this; |
| 4245 | } |
| 4246 | |
| 4247 | /** |
| 4248 | * Set metadata for this notification. |
| 4249 | * |
| 4250 | * <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] | 4251 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4252 | * called. |
| 4253 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4254 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 4255 | * Use {@link #addExtras} to merge in metadata instead. |
| 4256 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4257 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4258 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4259 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4260 | if (extras != null) { |
| 4261 | mUserExtras = extras; |
| 4262 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4263 | return this; |
| 4264 | } |
| 4265 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4266 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4267 | * Get the current metadata Bundle used by this notification Builder. |
| 4268 | * |
| 4269 | * <p>The returned Bundle is shared with this Builder. |
| 4270 | * |
| 4271 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 4272 | * {@link #build()} is called. |
| 4273 | * |
| 4274 | * @see Notification#extras |
| 4275 | */ |
| 4276 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4277 | return mUserExtras; |
| 4278 | } |
| 4279 | |
| 4280 | private Bundle getAllExtras() { |
| 4281 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 4282 | saveExtras.putAll(mN.extras); |
| 4283 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4287 | * Add an action to this notification. Actions are typically displayed by |
| 4288 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4289 | * <p> |
| 4290 | * Every action must have an icon (32dp square and matching the |
| 4291 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4292 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4293 | * <p> |
| 4294 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4295 | * the order they were added. Actions will not be displayed when the notification is |
| 4296 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4297 | * 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] | 4298 | * |
| 4299 | * @param icon Resource ID of a drawable that represents the action. |
| 4300 | * @param title Text describing the action. |
| 4301 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4302 | * |
| 4303 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4304 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4305 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4306 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4307 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4308 | return this; |
| 4309 | } |
| 4310 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4311 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4312 | * Add an action to this notification. Actions are typically displayed by |
| 4313 | * the system as a button adjacent to the notification content. |
| 4314 | * <p> |
| 4315 | * Every action must have an icon (32dp square and matching the |
| 4316 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4317 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4318 | * <p> |
| 4319 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4320 | * the order they were added. Actions will not be displayed when the notification is |
| 4321 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4322 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 4323 | * |
| 4324 | * @param action The action to add. |
| 4325 | */ |
| 4326 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4327 | if (action != null) { |
| 4328 | mActions.add(action); |
| 4329 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4330 | return this; |
| 4331 | } |
| 4332 | |
| 4333 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4334 | * Alter the complete list of actions attached to this notification. |
| 4335 | * @see #addAction(Action). |
| 4336 | * |
| 4337 | * @param actions |
| 4338 | * @return |
| 4339 | */ |
| 4340 | public Builder setActions(Action... actions) { |
| 4341 | mActions.clear(); |
| 4342 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4343 | if (actions[i] != null) { |
| 4344 | mActions.add(actions[i]); |
| 4345 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4346 | } |
| 4347 | return this; |
| 4348 | } |
| 4349 | |
| 4350 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4351 | * Add a rich notification style to be applied at build time. |
| 4352 | * |
| 4353 | * @param style Object responsible for modifying the notification style. |
| 4354 | */ |
| 4355 | public Builder setStyle(Style style) { |
| 4356 | if (mStyle != style) { |
| 4357 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4358 | if (mStyle != null) { |
| 4359 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4360 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 4361 | } else { |
| 4362 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4363 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4364 | } |
| 4365 | return this; |
| 4366 | } |
| 4367 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4368 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 4369 | * Returns the style set by {@link #setStyle(Style)}. |
| 4370 | */ |
| 4371 | public Style getStyle() { |
| 4372 | return mStyle; |
| 4373 | } |
| 4374 | |
| 4375 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4376 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4377 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4378 | * @return The same Builder. |
| 4379 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 4380 | public Builder setVisibility(@Visibility int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4381 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4382 | return this; |
| 4383 | } |
| 4384 | |
| 4385 | /** |
| 4386 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 4387 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 4388 | * @param n A replacement notification, presumably with some or all info redacted. |
| 4389 | * @return The same Builder. |
| 4390 | */ |
| 4391 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4392 | if (n != null) { |
| 4393 | mN.publicVersion = new Notification(); |
| 4394 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 4395 | } else { |
| 4396 | mN.publicVersion = null; |
| 4397 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4398 | return this; |
| 4399 | } |
| 4400 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4401 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4402 | * Apply an extender to this notification builder. Extenders may be used to add |
| 4403 | * metadata or change options on this builder. |
| 4404 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4405 | public Builder extend(Extender extender) { |
| 4406 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4407 | return this; |
| 4408 | } |
| 4409 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 4410 | /** |
| 4411 | * @hide |
| 4412 | */ |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4413 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4414 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4415 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4416 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4417 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4418 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4419 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4420 | } |
| 4421 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4422 | /** |
| 4423 | * Sets {@link Notification#color}. |
| 4424 | * |
| 4425 | * @param argb The accent color to use |
| 4426 | * |
| 4427 | * @return The same Builder. |
| 4428 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4429 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4430 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4431 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4432 | return this; |
| 4433 | } |
| 4434 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4435 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 4436 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 4437 | // This user can never be a badged profile, |
| 4438 | // and also includes USER_ALL system notifications. |
| 4439 | return null; |
| 4440 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 4441 | // Note: This assumes that the current user can read the profile badge of the |
| 4442 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 4443 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4444 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | private Bitmap getProfileBadge() { |
| 4448 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4449 | if (badge == null) { |
| 4450 | return null; |
| 4451 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4452 | final int size = mContext.getResources().getDimensionPixelSize( |
| 4453 | R.dimen.notification_badge_size); |
| 4454 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4455 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4456 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4457 | badge.draw(canvas); |
| 4458 | return bitmap; |
| 4459 | } |
| 4460 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4461 | private void bindProfileBadge(RemoteViews contentView, StandardTemplateParams p) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4462 | Bitmap profileBadge = getProfileBadge(); |
| 4463 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4464 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4465 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 4466 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4467 | if (isColorized(p)) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4468 | contentView.setDrawableTint(R.id.profile_badge, false, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4469 | getPrimaryTextColor(p), PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4470 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4471 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4472 | } |
| 4473 | |
Gus Prevas | bae5ba3 | 2018-11-28 15:45:13 -0500 | [diff] [blame] | 4474 | private void bindAlertedIcon(RemoteViews contentView, StandardTemplateParams p) { |
| 4475 | contentView.setDrawableTint( |
| 4476 | R.id.alerted_icon, |
| 4477 | false /* targetBackground */, |
| 4478 | getNeutralColor(p), |
| 4479 | PorterDuff.Mode.SRC_ATOP); |
| 4480 | } |
| 4481 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4482 | /** |
| 4483 | * @hide |
| 4484 | */ |
| 4485 | public boolean usesStandardHeader() { |
| 4486 | if (mN.mUsesStandardHeader) { |
| 4487 | return true; |
| 4488 | } |
| 4489 | if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.N) { |
| 4490 | if (mN.contentView == null && mN.bigContentView == null) { |
| 4491 | return true; |
| 4492 | } |
| 4493 | } |
| 4494 | boolean contentViewUsesHeader = mN.contentView == null |
| 4495 | || STANDARD_LAYOUTS.contains(mN.contentView.getLayoutId()); |
| 4496 | boolean bigContentViewUsesHeader = mN.bigContentView == null |
| 4497 | || STANDARD_LAYOUTS.contains(mN.bigContentView.getLayoutId()); |
| 4498 | return contentViewUsesHeader && bigContentViewUsesHeader; |
| 4499 | } |
| 4500 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4501 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4502 | resetNotificationHeader(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4503 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4504 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4505 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4506 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4507 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4508 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4509 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4510 | } |
| 4511 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4512 | /** |
| 4513 | * Resets the notification header to its original state |
| 4514 | */ |
| 4515 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 4516 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 4517 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 4518 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4519 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 4520 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4521 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 4522 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4523 | contentView.setViewVisibility(R.id.header_text_secondary, View.GONE); |
| 4524 | contentView.setTextViewText(R.id.header_text_secondary, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4525 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4526 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4527 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4528 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4529 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 4530 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 4531 | contentView.setViewVisibility(R.id.alerted_icon, View.GONE); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4532 | mN.mUsesStandardHeader = false; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4533 | } |
| 4534 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4535 | private RemoteViews applyStandardTemplate(int resId, TemplateBindResult result) { |
| 4536 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this), |
| 4537 | result); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4538 | } |
| 4539 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4540 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p, |
| 4541 | TemplateBindResult result) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 4542 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 4543 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4544 | resetStandardTemplate(contentView); |
| 4545 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4546 | final Bundle ex = mN.extras; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4547 | updateBackgroundColor(contentView, p); |
| 4548 | bindNotificationHeader(contentView, p); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4549 | bindLargeIconAndReply(contentView, p, result); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4550 | boolean showProgress = handleProgressBar(contentView, ex, p); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4551 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4552 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4553 | contentView.setTextViewText(R.id.title, processTextSpans(p.title)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4554 | if (!p.ambient) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4555 | setTextViewColorPrimary(contentView, R.id.title, p); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4556 | } |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 4557 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 4558 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 4559 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4560 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4561 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4562 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 4563 | : com.android.internal.R.id.text; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4564 | contentView.setTextViewText(textId, processTextSpans(p.text)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4565 | if (!p.ambient) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4566 | setTextViewColorSecondary(contentView, textId, p); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4567 | } |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4568 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4569 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4570 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4571 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4572 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4573 | return contentView; |
| 4574 | } |
| 4575 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4576 | private CharSequence processTextSpans(CharSequence text) { |
Lucas Dupin | d3c9932 | 2018-09-27 10:22:29 -0700 | [diff] [blame] | 4577 | if (hasForegroundColor() || mInNightMode) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4578 | return ContrastColorUtil.clearColorSpans(text); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4579 | } |
| 4580 | return text; |
| 4581 | } |
| 4582 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4583 | private void setTextViewColorPrimary(RemoteViews contentView, int id, |
| 4584 | StandardTemplateParams p) { |
| 4585 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4586 | contentView.setTextColor(id, mPrimaryTextColor); |
| 4587 | } |
| 4588 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4589 | private boolean hasForegroundColor() { |
| 4590 | return mForegroundColor != COLOR_INVALID; |
| 4591 | } |
| 4592 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4593 | /** |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4594 | * Return the primary text color using the existing template params |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4595 | * @hide |
| 4596 | */ |
| 4597 | @VisibleForTesting |
| 4598 | public int getPrimaryTextColor() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4599 | return getPrimaryTextColor(mParams); |
| 4600 | } |
| 4601 | |
| 4602 | /** |
| 4603 | * @param p the template params to inflate this with |
| 4604 | * @return the primary text color |
| 4605 | * @hide |
| 4606 | */ |
| 4607 | @VisibleForTesting |
| 4608 | public int getPrimaryTextColor(StandardTemplateParams p) { |
| 4609 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4610 | return mPrimaryTextColor; |
| 4611 | } |
| 4612 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4613 | /** |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4614 | * Return the secondary text color using the existing template params |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4615 | * @hide |
| 4616 | */ |
| 4617 | @VisibleForTesting |
| 4618 | public int getSecondaryTextColor() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4619 | return getSecondaryTextColor(mParams); |
| 4620 | } |
| 4621 | |
| 4622 | /** |
| 4623 | * @param p the template params to inflate this with |
| 4624 | * @return the secondary text color |
| 4625 | * @hide |
| 4626 | */ |
| 4627 | @VisibleForTesting |
| 4628 | public int getSecondaryTextColor(StandardTemplateParams p) { |
| 4629 | ensureColors(p); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4630 | return mSecondaryTextColor; |
| 4631 | } |
| 4632 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4633 | private void setTextViewColorSecondary(RemoteViews contentView, int id, |
| 4634 | StandardTemplateParams p) { |
| 4635 | ensureColors(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4636 | contentView.setTextColor(id, mSecondaryTextColor); |
| 4637 | } |
| 4638 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4639 | private void ensureColors(StandardTemplateParams p) { |
| 4640 | int backgroundColor = getBackgroundColor(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4641 | if (mPrimaryTextColor == COLOR_INVALID |
| 4642 | || mSecondaryTextColor == COLOR_INVALID |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4643 | || mTextColorsAreForBackground != backgroundColor) { |
| 4644 | mTextColorsAreForBackground = backgroundColor; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4645 | if (!hasForegroundColor() || !isColorized(p)) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4646 | mPrimaryTextColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 4647 | backgroundColor, mInNightMode); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4648 | mSecondaryTextColor = ContrastColorUtil.resolveSecondaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 4649 | backgroundColor, mInNightMode); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4650 | if (backgroundColor != COLOR_DEFAULT && isColorized(p)) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4651 | mPrimaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4652 | mPrimaryTextColor, backgroundColor, 4.5); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4653 | mSecondaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4654 | mSecondaryTextColor, backgroundColor, 4.5); |
| 4655 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4656 | } else { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4657 | double backLum = ContrastColorUtil.calculateLuminance(backgroundColor); |
| 4658 | double textLum = ContrastColorUtil.calculateLuminance(mForegroundColor); |
| 4659 | double contrast = ContrastColorUtil.calculateContrast(mForegroundColor, |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4660 | backgroundColor); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4661 | // We only respect the given colors if worst case Black or White still has |
| 4662 | // contrast |
| 4663 | boolean backgroundLight = backLum > textLum |
| 4664 | && satisfiesTextContrast(backgroundColor, Color.BLACK) |
| 4665 | || backLum <= textLum |
| 4666 | && !satisfiesTextContrast(backgroundColor, Color.WHITE); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4667 | if (contrast < 4.5f) { |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4668 | if (backgroundLight) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4669 | mSecondaryTextColor = ContrastColorUtil.findContrastColor( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4670 | mForegroundColor, |
| 4671 | backgroundColor, |
| 4672 | true /* findFG */, |
| 4673 | 4.5f); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4674 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4675 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_LIGHT); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4676 | } else { |
| 4677 | mSecondaryTextColor = |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4678 | ContrastColorUtil.findContrastColorAgainstDark( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4679 | mForegroundColor, |
| 4680 | backgroundColor, |
| 4681 | true /* findFG */, |
| 4682 | 4.5f); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4683 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4684 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4685 | } |
| 4686 | } else { |
| 4687 | mPrimaryTextColor = mForegroundColor; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4688 | mSecondaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4689 | mPrimaryTextColor, backgroundLight ? LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4690 | : LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4691 | if (ContrastColorUtil.calculateContrast(mSecondaryTextColor, |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4692 | backgroundColor) < 4.5f) { |
| 4693 | // oh well the secondary is not good enough |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4694 | if (backgroundLight) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4695 | mSecondaryTextColor = ContrastColorUtil.findContrastColor( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4696 | mSecondaryTextColor, |
| 4697 | backgroundColor, |
| 4698 | true /* findFG */, |
| 4699 | 4.5f); |
| 4700 | } else { |
| 4701 | mSecondaryTextColor |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4702 | = ContrastColorUtil.findContrastColorAgainstDark( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4703 | mSecondaryTextColor, |
| 4704 | backgroundColor, |
| 4705 | true /* findFG */, |
| 4706 | 4.5f); |
| 4707 | } |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4708 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4709 | mSecondaryTextColor, backgroundLight |
| 4710 | ? -LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4711 | : -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4712 | } |
| 4713 | } |
| 4714 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4715 | } |
| 4716 | } |
| 4717 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4718 | private void updateBackgroundColor(RemoteViews contentView, |
| 4719 | StandardTemplateParams p) { |
| 4720 | if (isColorized(p)) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4721 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4722 | getBackgroundColor(p)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4723 | } else { |
| 4724 | // Clear it! |
| 4725 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 4726 | 0); |
| 4727 | } |
| 4728 | } |
| 4729 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4730 | /** |
| 4731 | * @param remoteView the remote view to update the minheight in |
| 4732 | * @param hasMinHeight does it have a mimHeight |
| 4733 | * @hide |
| 4734 | */ |
| 4735 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 4736 | int minHeight = 0; |
| 4737 | if (hasMinHeight) { |
| 4738 | // we need to set the minHeight of the notification |
| 4739 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 4740 | com.android.internal.R.dimen.notification_min_content_height); |
| 4741 | } |
| 4742 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 4743 | } |
| 4744 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4745 | private boolean handleProgressBar(RemoteViews contentView, Bundle ex, |
| 4746 | StandardTemplateParams p) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4747 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4748 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 4749 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4750 | if (p.hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4751 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4752 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4753 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4754 | contentView.setProgressBackgroundTintList( |
| 4755 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 4756 | R.color.notification_progress_background_color))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4757 | if (getRawColor(p) != COLOR_DEFAULT) { |
| 4758 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor(p)); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4759 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 4760 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4761 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4762 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4763 | } else { |
| 4764 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4765 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 4766 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4767 | } |
| 4768 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4769 | private void bindLargeIconAndReply(RemoteViews contentView, StandardTemplateParams p, |
| 4770 | TemplateBindResult result) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4771 | boolean largeIconShown = bindLargeIcon(contentView, p); |
| 4772 | boolean replyIconShown = bindReplyIcon(contentView, p); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame^] | 4773 | boolean iconContainerVisible = largeIconShown || replyIconShown; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4774 | contentView.setViewVisibility(R.id.right_icon_container, |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame^] | 4775 | iconContainerVisible ? View.VISIBLE : View.GONE); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4776 | int marginEnd = calculateMarginEnd(largeIconShown, replyIconShown); |
| 4777 | contentView.setViewLayoutMarginEnd(R.id.line1, marginEnd); |
| 4778 | contentView.setViewLayoutMarginEnd(R.id.text, marginEnd); |
| 4779 | contentView.setViewLayoutMarginEnd(R.id.progress, marginEnd); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4780 | if (result != null) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4781 | result.setIconMarginEnd(marginEnd); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame^] | 4782 | result.setRightIconContainerVisible(iconContainerVisible); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4783 | } |
| 4784 | } |
| 4785 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4786 | private int calculateMarginEnd(boolean largeIconShown, boolean replyIconShown) { |
| 4787 | int marginEnd = 0; |
| 4788 | int contentMargin = mContext.getResources().getDimensionPixelSize( |
| 4789 | R.dimen.notification_content_margin_end); |
| 4790 | int iconSize = mContext.getResources().getDimensionPixelSize( |
| 4791 | R.dimen.notification_right_icon_size); |
| 4792 | if (replyIconShown) { |
| 4793 | // The size of the reply icon |
| 4794 | marginEnd += iconSize; |
| 4795 | |
| 4796 | int replyInset = mContext.getResources().getDimensionPixelSize( |
| 4797 | R.dimen.notification_reply_inset); |
| 4798 | // We're subtracting the inset of the reply icon to make sure it's |
| 4799 | // aligned nicely on the right, and remove it from the following padding |
| 4800 | marginEnd -= replyInset * 2; |
| 4801 | } |
| 4802 | if (largeIconShown) { |
| 4803 | // adding size of the right icon |
| 4804 | marginEnd += iconSize; |
| 4805 | |
| 4806 | if (replyIconShown) { |
| 4807 | // We also add some padding to the reply icon if it's around |
| 4808 | marginEnd += contentMargin; |
| 4809 | } |
| 4810 | } |
| 4811 | if (replyIconShown || largeIconShown) { |
| 4812 | // The padding to the content |
| 4813 | marginEnd += contentMargin; |
| 4814 | } |
| 4815 | return marginEnd; |
| 4816 | } |
| 4817 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4818 | /** |
| 4819 | * Bind the large icon. |
| 4820 | * @return if the largeIcon is visible |
| 4821 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4822 | private boolean bindLargeIcon(RemoteViews contentView, StandardTemplateParams p) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4823 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 4824 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 4825 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4826 | boolean showLargeIcon = mN.mLargeIcon != null && !p.hideLargeIcon && !p.ambient; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4827 | if (showLargeIcon) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4828 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 4829 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4830 | processLargeLegacyIcon(mN.mLargeIcon, contentView, p); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4831 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4832 | return showLargeIcon; |
| 4833 | } |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4834 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4835 | /** |
| 4836 | * Bind the reply icon. |
| 4837 | * @return if the reply icon is visible |
| 4838 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4839 | private boolean bindReplyIcon(RemoteViews contentView, StandardTemplateParams p) { |
| 4840 | boolean actionVisible = !p.hideReplyIcon && !p.ambient; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4841 | Action action = null; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4842 | if (actionVisible) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4843 | action = findReplyAction(); |
| 4844 | actionVisible = action != null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4845 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4846 | if (actionVisible) { |
| 4847 | contentView.setViewVisibility(R.id.reply_icon_action, View.VISIBLE); |
| 4848 | contentView.setDrawableTint(R.id.reply_icon_action, |
| 4849 | false /* targetBackground */, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4850 | getNeutralColor(p), |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4851 | PorterDuff.Mode.SRC_ATOP); |
| 4852 | contentView.setOnClickPendingIntent(R.id.reply_icon_action, action.actionIntent); |
| 4853 | contentView.setRemoteInputs(R.id.reply_icon_action, action.mRemoteInputs); |
| 4854 | } else { |
| 4855 | contentView.setRemoteInputs(R.id.reply_icon_action, null); |
| 4856 | } |
| 4857 | contentView.setViewVisibility(R.id.reply_icon_action, |
| 4858 | actionVisible ? View.VISIBLE : View.GONE); |
| 4859 | return actionVisible; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4860 | } |
| 4861 | |
| 4862 | private Action findReplyAction() { |
| 4863 | ArrayList<Action> actions = mActions; |
| 4864 | if (mOriginalActions != null) { |
| 4865 | actions = mOriginalActions; |
| 4866 | } |
| 4867 | int numActions = actions.size(); |
| 4868 | for (int i = 0; i < numActions; i++) { |
| 4869 | Action action = actions.get(i); |
| 4870 | if (hasValidRemoteInput(action)) { |
| 4871 | return action; |
| 4872 | } |
| 4873 | } |
| 4874 | return null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4875 | } |
| 4876 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4877 | private void bindNotificationHeader(RemoteViews contentView, StandardTemplateParams p) { |
| 4878 | bindSmallIcon(contentView, p); |
| 4879 | bindHeaderAppName(contentView, p); |
| 4880 | if (!p.ambient) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4881 | // Ambient view does not have these |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4882 | bindHeaderText(contentView, p); |
| 4883 | bindHeaderTextSecondary(contentView, p); |
| 4884 | bindHeaderChronometerAndTime(contentView, p); |
| 4885 | bindProfileBadge(contentView, p); |
Gus Prevas | bae5ba3 | 2018-11-28 15:45:13 -0500 | [diff] [blame] | 4886 | bindAlertedIcon(contentView, p); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4887 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4888 | bindActivePermissions(contentView, p); |
| 4889 | bindExpandButton(contentView, p); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4890 | mN.mUsesStandardHeader = true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4891 | } |
| 4892 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4893 | private void bindActivePermissions(RemoteViews contentView, StandardTemplateParams p) { |
| 4894 | int color = p.ambient ? resolveAmbientColor(p) : getNeutralColor(p); |
Julia Reynolds | b887b23 | 2018-04-10 16:38:08 -0400 | [diff] [blame] | 4895 | contentView.setDrawableTint(R.id.camera, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4896 | contentView.setDrawableTint(R.id.mic, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4897 | contentView.setDrawableTint(R.id.overlay, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4898 | } |
| 4899 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4900 | private void bindExpandButton(RemoteViews contentView, StandardTemplateParams p) { |
| 4901 | int color = isColorized(p) ? getPrimaryTextColor(p) : getSecondaryTextColor(p); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4902 | contentView.setDrawableTint(R.id.expand_button, false, color, |
| 4903 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4904 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4905 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4906 | } |
| 4907 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4908 | private void bindHeaderChronometerAndTime(RemoteViews contentView, |
| 4909 | StandardTemplateParams p) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4910 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4911 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4912 | setTextViewColorSecondary(contentView, R.id.time_divider, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4913 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 4914 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 4915 | contentView.setLong(R.id.chronometer, "setBase", |
| 4916 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 4917 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4918 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 4919 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4920 | setTextViewColorSecondary(contentView, R.id.chronometer, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4921 | } else { |
| 4922 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 4923 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4924 | setTextViewColorSecondary(contentView, R.id.time, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4925 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4926 | } else { |
| 4927 | // We still want a time to be set but gone, such that we can show and hide it |
| 4928 | // on demand in case it's a child notification without anything in the header |
| 4929 | 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] | 4930 | } |
| 4931 | } |
| 4932 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4933 | private void bindHeaderText(RemoteViews contentView, StandardTemplateParams p) { |
| 4934 | CharSequence summaryText = p.summaryText; |
| 4935 | if (summaryText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4936 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4937 | summaryText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4938 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4939 | if (summaryText == null |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4940 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 4941 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4942 | summaryText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4943 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4944 | if (summaryText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4945 | // 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] | 4946 | contentView.setTextViewText(R.id.header_text, processTextSpans( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4947 | processLegacyText(summaryText))); |
| 4948 | setTextViewColorSecondary(contentView, R.id.header_text, p); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4949 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 4950 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4951 | setTextViewColorSecondary(contentView, R.id.header_text_divider, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4952 | } |
| 4953 | } |
| 4954 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4955 | private void bindHeaderTextSecondary(RemoteViews contentView, StandardTemplateParams p) { |
| 4956 | if (!TextUtils.isEmpty(p.headerTextSecondary)) { |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4957 | contentView.setTextViewText(R.id.header_text_secondary, processTextSpans( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4958 | processLegacyText(p.headerTextSecondary))); |
| 4959 | setTextViewColorSecondary(contentView, R.id.header_text_secondary, p); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4960 | contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE); |
| 4961 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 4962 | setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider, p); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4963 | } |
| 4964 | } |
| 4965 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4966 | /** |
| 4967 | * @hide |
| 4968 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 4969 | @UnsupportedAppUsage |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4970 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4971 | CharSequence name = null; |
| 4972 | final PackageManager pm = mContext.getPackageManager(); |
| 4973 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 4974 | // only system packages which lump together a bunch of unrelated stuff |
| 4975 | // may substitute a different name to make the purpose of the |
| 4976 | // notification more clear. the correct package label should always |
| 4977 | // be accessible via SystemUI. |
| 4978 | final String pkg = mContext.getPackageName(); |
| 4979 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 4980 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 4981 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 4982 | name = subName; |
| 4983 | } else { |
| 4984 | Log.w(TAG, "warning: pkg " |
| 4985 | + pkg + " attempting to substitute app name '" + subName |
| 4986 | + "' without holding perm " |
| 4987 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 4988 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4989 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4990 | if (TextUtils.isEmpty(name)) { |
| 4991 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 4992 | } |
| 4993 | if (TextUtils.isEmpty(name)) { |
| 4994 | // still nothing? |
| 4995 | return null; |
| 4996 | } |
| 4997 | |
| 4998 | return String.valueOf(name); |
| 4999 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5000 | private void bindHeaderAppName(RemoteViews contentView, StandardTemplateParams p) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 5001 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5002 | if (isColorized(p)) { |
| 5003 | setTextViewColorPrimary(contentView, R.id.app_name_text, p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5004 | } else { |
| 5005 | contentView.setTextColor(R.id.app_name_text, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5006 | p.ambient ? resolveAmbientColor(p) : getSecondaryTextColor(p)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5007 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5008 | } |
| 5009 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5010 | private boolean isColorized(StandardTemplateParams p) { |
| 5011 | return p.allowColorization && !p.ambient && mN.isColorized(); |
| 5012 | } |
| 5013 | |
| 5014 | private void bindSmallIcon(RemoteViews contentView, StandardTemplateParams p) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5015 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 5016 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 5017 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5018 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5019 | contentView.setInt(R.id.icon, "setImageLevel", mN.iconLevel); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5020 | processSmallIconColor(mN.mSmallIcon, contentView, p); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5021 | } |
| 5022 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5023 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5024 | * @return true if the built notification will show the time or the chronometer; false |
| 5025 | * otherwise |
| 5026 | */ |
| 5027 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5028 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5029 | } |
| 5030 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5031 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 5032 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 5033 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5034 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5035 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5036 | |
| 5037 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 5038 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5039 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, View.GONE); |
| 5040 | big.setViewVisibility(R.id.notification_material_reply_progress, View.GONE); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5041 | |
| 5042 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 5043 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 5044 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 5045 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 5046 | |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 5047 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 5048 | R.dimen.notification_content_margin); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5049 | } |
| 5050 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5051 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 5052 | TemplateBindResult result) { |
| 5053 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this), |
| 5054 | result); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 5055 | } |
| 5056 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5057 | private static List<Notification.Action> filterOutContextualActions( |
| 5058 | List<Notification.Action> actions) { |
| 5059 | List<Notification.Action> nonContextualActions = new ArrayList<>(); |
| 5060 | for (Notification.Action action : actions) { |
| 5061 | if (action.getSemanticAction() |
| 5062 | != Action.SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION) { |
| 5063 | nonContextualActions.add(action); |
| 5064 | } |
| 5065 | } |
| 5066 | return nonContextualActions; |
| 5067 | } |
| 5068 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 5069 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5070 | StandardTemplateParams p, TemplateBindResult result) { |
| 5071 | RemoteViews big = applyStandardTemplate(layoutId, p, result); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5072 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 5073 | resetStandardTemplateWithActions(big); |
| 5074 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5075 | boolean validRemoteInput = false; |
| 5076 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5077 | // In the UI contextual actions appear separately from the standard actions, so we |
| 5078 | // filter them out here. |
| 5079 | List<Notification.Action> nonContextualActions = filterOutContextualActions(mActions); |
| 5080 | |
| 5081 | int N = nonContextualActions.size(); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5082 | boolean emphazisedMode = mN.fullScreenIntent != null && !p.ambient; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5083 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5084 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 5085 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5086 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 5087 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5088 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5089 | for (int i=0; i<N; i++) { |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 5090 | Action action = nonContextualActions.get(i); |
| 5091 | |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 5092 | boolean actionHasValidInput = hasValidRemoteInput(action); |
| 5093 | validRemoteInput |= actionHasValidInput; |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5094 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5095 | final RemoteViews button = generateActionButton(action, emphazisedMode, p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5096 | if (actionHasValidInput && !emphazisedMode) { |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 5097 | // Clear the drawable |
| 5098 | button.setInt(R.id.action0, "setBackgroundResource", 0); |
| 5099 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5100 | big.addView(R.id.actions, button); |
| 5101 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 5102 | } else { |
| 5103 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5104 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5105 | |
| 5106 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5107 | if (!p.ambient && validRemoteInput && replyText != null |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5108 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0]) |
| 5109 | && p.maxRemoteInputHistory > 0) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5110 | boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5111 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5112 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, |
| 5113 | View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5114 | big.setTextViewText(R.id.notification_material_reply_text_1, |
| 5115 | processTextSpans(replyText[0])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5116 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1, p); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5117 | big.setViewVisibility(R.id.notification_material_reply_progress, |
| 5118 | showSpinner ? View.VISIBLE : View.GONE); |
| 5119 | big.setProgressIndeterminateTintList( |
| 5120 | R.id.notification_material_reply_progress, |
| 5121 | ColorStateList.valueOf( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5122 | isColorized(p) ? getPrimaryTextColor(p) : resolveContrastColor(p))); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5123 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5124 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1]) |
| 5125 | && p.maxRemoteInputHistory > 1) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5126 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5127 | big.setTextViewText(R.id.notification_material_reply_text_2, |
| 5128 | processTextSpans(replyText[1])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5129 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2, p); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5130 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5131 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2]) |
| 5132 | && p.maxRemoteInputHistory > 2) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5133 | big.setViewVisibility( |
| 5134 | R.id.notification_material_reply_text_3, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5135 | big.setTextViewText(R.id.notification_material_reply_text_3, |
| 5136 | processTextSpans(replyText[2])); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5137 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3, p); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5138 | } |
| 5139 | } |
| 5140 | } |
| 5141 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5142 | return big; |
| 5143 | } |
| 5144 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5145 | private boolean hasValidRemoteInput(Action action) { |
| 5146 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 5147 | // Weird actions |
| 5148 | return false; |
| 5149 | } |
| 5150 | |
| 5151 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 5152 | if (remoteInputs == null) { |
| 5153 | return false; |
| 5154 | } |
| 5155 | |
| 5156 | for (RemoteInput r : remoteInputs) { |
| 5157 | CharSequence[] choices = r.getChoices(); |
| 5158 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 5159 | return true; |
| 5160 | } |
| 5161 | } |
| 5162 | return false; |
| 5163 | } |
| 5164 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5165 | /** |
| 5166 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 5167 | * 1. Custom contentView from the caller |
| 5168 | * 2. Style's proposed content view |
| 5169 | * 3. Standard template view |
| 5170 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5171 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5172 | return createContentView(false /* increasedheight */ ); |
| 5173 | } |
| 5174 | |
| 5175 | /** |
| 5176 | * Construct a RemoteViews for the smaller content view. |
| 5177 | * |
| 5178 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5179 | * styles may support showing more then just that basic 1U size |
| 5180 | * and the system may decide to render important notifications |
| 5181 | * slightly bigger even when collapsed. |
| 5182 | * |
| 5183 | * @hide |
| 5184 | */ |
| 5185 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5186 | if (mN.contentView != null && useExistingRemoteView()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5187 | return mN.contentView; |
| 5188 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5189 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5190 | if (styleView != null) { |
| 5191 | return styleView; |
| 5192 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5193 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5194 | return applyStandardTemplate(getBaseLayoutResource(), null /* result */); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5195 | } |
| 5196 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5197 | private boolean useExistingRemoteView() { |
| 5198 | return mStyle == null || (!mStyle.displayCustomViewInline() |
| 5199 | && !mRebuildStyledRemoteViews); |
| 5200 | } |
| 5201 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5202 | /** |
| 5203 | * Construct a RemoteViews for the final big notification layout. |
| 5204 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5205 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5206 | RemoteViews result = null; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5207 | if (mN.bigContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5208 | return mN.bigContentView; |
| 5209 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5210 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 5211 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5212 | } else if (mActions.size() != 0) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5213 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5214 | null /* result */); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5215 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5216 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5217 | return result; |
| 5218 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5219 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5220 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 5221 | * Construct a RemoteViews for the final notification header only. This will not be |
| 5222 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5223 | * |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5224 | * @param ambient if true, generate the header for the ambient display layout. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5225 | * @hide |
| 5226 | */ |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5227 | public RemoteViews makeNotificationHeader(boolean ambient) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5228 | return makeNotificationHeader(mParams.reset().ambient(ambient).fillTextsFrom(this)); |
| 5229 | } |
| 5230 | |
| 5231 | /** |
| 5232 | * Construct a RemoteViews for the final notification header only. This will not be |
| 5233 | * colorized. |
| 5234 | * |
| 5235 | * @param p the template params to inflate this with |
| 5236 | */ |
| 5237 | private RemoteViews makeNotificationHeader(StandardTemplateParams p) { |
| 5238 | // Headers on their own are never colorized |
| 5239 | p.disallowColorization(); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5240 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5241 | p.ambient ? R.layout.notification_template_ambient_header |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5242 | : R.layout.notification_template_header); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5243 | resetNotificationHeader(header); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5244 | bindNotificationHeader(header, p); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5245 | return header; |
| 5246 | } |
| 5247 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5248 | /** |
| 5249 | * Construct a RemoteViews for the ambient version of the notification. |
| 5250 | * |
| 5251 | * @hide |
| 5252 | */ |
| 5253 | public RemoteViews makeAmbientNotification() { |
| 5254 | RemoteViews ambient = applyStandardTemplateWithActions( |
| 5255 | R.layout.notification_template_material_ambient, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5256 | mParams.reset().ambient(true).fillTextsFrom(this).hasProgress(false), |
| 5257 | null /* result */); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5258 | return ambient; |
| 5259 | } |
| 5260 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5261 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5262 | if (result != null) { |
| 5263 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 5264 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5265 | } |
| 5266 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5267 | /** |
| 5268 | * Adapt the Notification header if this view is used as an expanded view. |
| 5269 | * |
| 5270 | * @hide |
| 5271 | */ |
| 5272 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5273 | if (result != null) { |
| 5274 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 5275 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5276 | } |
| 5277 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5278 | /** |
| 5279 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5280 | * |
| 5281 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5282 | * styles may support showing more then just that basic 1U size |
| 5283 | * and the system may decide to render important notifications |
| 5284 | * slightly bigger even when collapsed. |
| 5285 | * |
| 5286 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5287 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5288 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5289 | if (mN.headsUpContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5290 | return mN.headsUpContentView; |
| 5291 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5292 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 5293 | if (styleView != null) { |
| 5294 | return styleView; |
| 5295 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5296 | } else if (mActions.size() == 0) { |
| 5297 | return null; |
| 5298 | } |
| 5299 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5300 | // We only want at most a single remote input history to be shown here, otherwise |
| 5301 | // the content would become squished. |
| 5302 | StandardTemplateParams p = mParams.reset().fillTextsFrom(this) |
| 5303 | .setMaxRemoteInputHistory(1); |
| 5304 | return applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5305 | p, |
| 5306 | null /* result */); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5307 | } |
| 5308 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5309 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5310 | * Construct a RemoteViews for the final heads-up notification layout. |
| 5311 | */ |
| 5312 | public RemoteViews createHeadsUpContentView() { |
| 5313 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 5314 | } |
| 5315 | |
| 5316 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5317 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5318 | * |
| 5319 | * @hide |
| 5320 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5321 | @UnsupportedAppUsage |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5322 | public RemoteViews makePublicContentView() { |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5323 | return makePublicView(false /* ambient */); |
| 5324 | } |
| 5325 | |
| 5326 | /** |
| 5327 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5328 | * |
| 5329 | * @hide |
| 5330 | */ |
| 5331 | public RemoteViews makePublicAmbientNotification() { |
| 5332 | return makePublicView(true /* ambient */); |
| 5333 | } |
| 5334 | |
| 5335 | private RemoteViews makePublicView(boolean ambient) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5336 | if (mN.publicVersion != null) { |
| 5337 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5338 | return ambient ? builder.makeAmbientNotification() : builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5339 | } |
| 5340 | Bundle savedBundle = mN.extras; |
| 5341 | Style style = mStyle; |
| 5342 | mStyle = null; |
| 5343 | Icon largeIcon = mN.mLargeIcon; |
| 5344 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5345 | Bitmap largeIconLegacy = mN.largeIcon; |
| 5346 | mN.largeIcon = null; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5347 | ArrayList<Action> actions = mActions; |
| 5348 | mActions = new ArrayList<>(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5349 | Bundle publicExtras = new Bundle(); |
| 5350 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 5351 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 5352 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 5353 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5354 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 5355 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | ed07b96 | 2018-04-30 14:39:35 -0700 | [diff] [blame] | 5356 | String appName = savedBundle.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 5357 | if (appName != null) { |
| 5358 | publicExtras.putString(EXTRA_SUBSTITUTE_APP_NAME, appName); |
| 5359 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5360 | mN.extras = publicExtras; |
Selim Cinek | 499c20f | 2017-07-20 14:06:09 -0700 | [diff] [blame] | 5361 | RemoteViews view; |
| 5362 | if (ambient) { |
| 5363 | publicExtras.putCharSequence(EXTRA_TITLE, |
| 5364 | mContext.getString(com.android.internal.R.string.notification_hidden_text)); |
| 5365 | view = makeAmbientNotification(); |
| 5366 | } else{ |
| 5367 | view = makeNotificationHeader(false /* ambient */); |
| 5368 | view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true); |
| 5369 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5370 | mN.extras = savedBundle; |
| 5371 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5372 | mN.largeIcon = largeIconLegacy; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5373 | mActions = actions; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5374 | mStyle = style; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5375 | return view; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5376 | } |
| 5377 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5378 | /** |
| 5379 | * Construct a content view for the display when low - priority |
| 5380 | * |
| 5381 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 5382 | * a new subtext is created consisting of the content of the |
| 5383 | * notification. |
| 5384 | * @hide |
| 5385 | */ |
| 5386 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5387 | StandardTemplateParams p = mParams.reset() |
| 5388 | .forceDefaultColor() |
| 5389 | .ambient(false) |
| 5390 | .fillTextsFrom(this); |
| 5391 | if (!useRegularSubtext || TextUtils.isEmpty(mParams.summaryText)) { |
| 5392 | p.summaryText(createSummaryText()); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5393 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5394 | RemoteViews header = makeNotificationHeader(p); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 5395 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5396 | return header; |
| 5397 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5398 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5399 | private CharSequence createSummaryText() { |
| 5400 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 5401 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 5402 | return titleText; |
| 5403 | } |
| 5404 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 5405 | if (titleText == null) { |
| 5406 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 5407 | } |
| 5408 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5409 | if (titleText != null) { |
| 5410 | summary.append(bidi.unicodeWrap(titleText)); |
| 5411 | } |
| 5412 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 5413 | if (titleText != null && contentText != null) { |
| 5414 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 5415 | R.string.notification_header_divider_symbol_with_spaces))); |
| 5416 | } |
| 5417 | if (contentText != null) { |
| 5418 | summary.append(bidi.unicodeWrap(contentText)); |
| 5419 | } |
| 5420 | return summary; |
| 5421 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5422 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5423 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5424 | StandardTemplateParams p) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5425 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 5426 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5427 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 5428 | : tombstone ? getActionTombstoneLayoutResource() |
| 5429 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5430 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5431 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5432 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5433 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5434 | if (action.mRemoteInputs != null) { |
| 5435 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 5436 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5437 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5438 | // change the background bgColor |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5439 | CharSequence title = action.title; |
| 5440 | ColorStateList[] outResultColor = null; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5441 | int background = resolveBackgroundColor(p); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5442 | if (isLegacy()) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5443 | title = ContrastColorUtil.clearColorSpans(title); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5444 | } else { |
| 5445 | outResultColor = new ColorStateList[1]; |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5446 | title = ensureColorSpanContrast(title, background, outResultColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5447 | } |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5448 | button.setTextViewText(R.id.action0, processTextSpans(title)); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5449 | setTextViewColorPrimary(button, R.id.action0, p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5450 | int rippleColor; |
| 5451 | boolean hasColorOverride = outResultColor != null && outResultColor[0] != null; |
| 5452 | if (hasColorOverride) { |
| 5453 | // There's a span spanning the full text, let's take it and use it as the |
| 5454 | // background color |
| 5455 | background = outResultColor[0].getDefaultColor(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5456 | int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5457 | background, mInNightMode); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5458 | button.setTextColor(R.id.action0, textColor); |
| 5459 | rippleColor = textColor; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5460 | } else if (getRawColor(p) != COLOR_DEFAULT && !isColorized(p) |
| 5461 | && mTintActionButtons) { |
| 5462 | rippleColor = resolveContrastColor(p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5463 | button.setTextColor(R.id.action0, rippleColor); |
| 5464 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5465 | rippleColor = getPrimaryTextColor(p); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5466 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5467 | // We only want about 20% alpha for the ripple |
| 5468 | rippleColor = (rippleColor & 0x00ffffff) | 0x33000000; |
| 5469 | button.setColorStateList(R.id.action0, "setRippleColor", |
| 5470 | ColorStateList.valueOf(rippleColor)); |
| 5471 | button.setColorStateList(R.id.action0, "setButtonBackground", |
| 5472 | ColorStateList.valueOf(background)); |
| 5473 | button.setBoolean(R.id.action0, "setHasStroke", !hasColorOverride); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5474 | } else { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5475 | button.setTextViewText(R.id.action0, processTextSpans( |
| 5476 | processLegacyText(action.title))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5477 | if (isColorized(p)) { |
| 5478 | setTextViewColorPrimary(button, R.id.action0, p); |
| 5479 | } else if (getRawColor(p) != COLOR_DEFAULT && mTintActionButtons) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5480 | button.setTextColor(R.id.action0, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5481 | p.ambient ? resolveAmbientColor(p) : resolveContrastColor(p)); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5482 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5483 | } |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 5484 | button.setIntTag(R.id.action0, R.id.notification_action_index_tag, |
| 5485 | mActions.indexOf(action)); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5486 | return button; |
| 5487 | } |
| 5488 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5489 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5490 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 5491 | * text if a span was found that spans over the whole text. |
| 5492 | * |
| 5493 | * @param charSequence the charSequence on which the spans are |
| 5494 | * @param background the background color to ensure the contrast against |
| 5495 | * @param outResultColor an array in which a color will be returned as the first element if |
| 5496 | * there exists a full length color span. |
| 5497 | * @return the contrasted charSequence |
| 5498 | */ |
| 5499 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 5500 | ColorStateList[] outResultColor) { |
| 5501 | if (charSequence instanceof Spanned) { |
| 5502 | Spanned ss = (Spanned) charSequence; |
| 5503 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 5504 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 5505 | for (Object span : spans) { |
| 5506 | Object resultSpan = span; |
| 5507 | int spanStart = ss.getSpanStart(span); |
| 5508 | int spanEnd = ss.getSpanEnd(span); |
| 5509 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 5510 | if (resultSpan instanceof CharacterStyle) { |
| 5511 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 5512 | } |
| 5513 | if (resultSpan instanceof TextAppearanceSpan) { |
| 5514 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 5515 | ColorStateList textColor = originalSpan.getTextColor(); |
| 5516 | if (textColor != null) { |
| 5517 | int[] colors = textColor.getColors(); |
| 5518 | int[] newColors = new int[colors.length]; |
| 5519 | for (int i = 0; i < newColors.length; i++) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5520 | newColors[i] = ContrastColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5521 | colors[i], background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5522 | } |
| 5523 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 5524 | newColors); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5525 | if (fullLength) { |
| 5526 | outResultColor[0] = textColor; |
| 5527 | // Let's drop the color from the span |
| 5528 | textColor = null; |
| 5529 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5530 | resultSpan = new TextAppearanceSpan( |
| 5531 | originalSpan.getFamily(), |
| 5532 | originalSpan.getTextStyle(), |
| 5533 | originalSpan.getTextSize(), |
| 5534 | textColor, |
| 5535 | originalSpan.getLinkTextColor()); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5536 | } |
| 5537 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 5538 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 5539 | int foregroundColor = originalSpan.getForegroundColor(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5540 | foregroundColor = ContrastColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5541 | foregroundColor, background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5542 | if (fullLength) { |
| 5543 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5544 | resultSpan = null; |
| 5545 | } else { |
| 5546 | resultSpan = new ForegroundColorSpan(foregroundColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5547 | } |
| 5548 | } else { |
| 5549 | resultSpan = span; |
| 5550 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5551 | if (resultSpan != null) { |
| 5552 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 5553 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5554 | } |
| 5555 | return builder; |
| 5556 | } |
| 5557 | return charSequence; |
| 5558 | } |
| 5559 | |
| 5560 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5561 | * @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] | 5562 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5563 | */ |
| 5564 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5565 | if (!mIsLegacyInitialized) { |
| 5566 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 5567 | < Build.VERSION_CODES.LOLLIPOP; |
| 5568 | mIsLegacyInitialized = true; |
| 5569 | } |
| 5570 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5571 | } |
| 5572 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5573 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 5574 | return processLegacyText(charSequence, false /* ambient */); |
| 5575 | } |
| 5576 | |
| 5577 | private CharSequence processLegacyText(CharSequence charSequence, boolean ambient) { |
| 5578 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
| 5579 | boolean wantLightText = ambient; |
| 5580 | if (isAlreadyLightText != wantLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5581 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5582 | } else { |
| 5583 | return charSequence; |
| 5584 | } |
| 5585 | } |
| 5586 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5587 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5588 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5589 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5590 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5591 | StandardTemplateParams p) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5592 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5593 | int color; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5594 | if (p.ambient) { |
| 5595 | color = resolveAmbientColor(p); |
| 5596 | } else if (isColorized(p)) { |
| 5597 | color = getPrimaryTextColor(p); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5598 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5599 | color = resolveContrastColor(p); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5600 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5601 | if (colorable) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5602 | contentView.setDrawableTint(R.id.icon, false, color, |
| 5603 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5604 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5605 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5606 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5607 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5608 | } |
| 5609 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5610 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5611 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5612 | * if it's grayscale). |
| 5613 | */ |
| 5614 | // TODO: also check bounds, transparency, that sort of thing. |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5615 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView, |
| 5616 | StandardTemplateParams p) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5617 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5618 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5619 | // resolve color will fall back to the default when legacy |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5620 | contentView.setDrawableTint(R.id.icon, false, resolveContrastColor(p), |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5621 | PorterDuff.Mode.SRC_ATOP); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 5622 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5623 | } |
| 5624 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 5625 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5626 | if (mN.color != COLOR_DEFAULT) { |
| 5627 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5628 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5629 | } |
| 5630 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5631 | int resolveContrastColor(StandardTemplateParams p) { |
| 5632 | int rawColor = getRawColor(p); |
| 5633 | if (mCachedContrastColorIsFor == rawColor && mCachedContrastColor != COLOR_INVALID) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5634 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5635 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5636 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5637 | int color; |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5638 | int background = mContext.getColor( |
| 5639 | com.android.internal.R.color.notification_material_background_color); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5640 | if (rawColor == COLOR_DEFAULT) { |
| 5641 | ensureColors(p); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5642 | color = ContrastColorUtil.resolveDefaultColor(mContext, background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5643 | } else { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5644 | color = ContrastColorUtil.resolveContrastColor(mContext, rawColor, |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5645 | background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5646 | } |
| 5647 | if (Color.alpha(color) < 255) { |
| 5648 | // 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] | 5649 | color = ContrastColorUtil.compositeColors(color, background); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5650 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5651 | mCachedContrastColorIsFor = rawColor; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5652 | return mCachedContrastColor = color; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5653 | } |
| 5654 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5655 | /** |
| 5656 | * Return the raw color of this Notification, which doesn't necessarily satisfy contrast. |
| 5657 | * |
| 5658 | * @see #resolveContrastColor(StandardTemplateParams) for the contrasted color |
| 5659 | * @param p the template params to inflate this with |
| 5660 | */ |
| 5661 | private int getRawColor(StandardTemplateParams p) { |
| 5662 | if (p.forceDefaultColor) { |
| 5663 | return COLOR_DEFAULT; |
| 5664 | } |
| 5665 | return mN.color; |
| 5666 | } |
| 5667 | |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5668 | int resolveNeutralColor() { |
| 5669 | if (mNeutralColor != COLOR_INVALID) { |
| 5670 | return mNeutralColor; |
| 5671 | } |
| 5672 | int background = mContext.getColor( |
| 5673 | com.android.internal.R.color.notification_material_background_color); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5674 | mNeutralColor = ContrastColorUtil.resolveDefaultColor(mContext, background, |
| 5675 | mInNightMode); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5676 | if (Color.alpha(mNeutralColor) < 255) { |
| 5677 | // 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] | 5678 | mNeutralColor = ContrastColorUtil.compositeColors(mNeutralColor, background); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5679 | } |
| 5680 | return mNeutralColor; |
| 5681 | } |
| 5682 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5683 | int resolveAmbientColor(StandardTemplateParams p) { |
| 5684 | int rawColor = getRawColor(p); |
| 5685 | if (mCachedAmbientColorIsFor == rawColor && mCachedAmbientColorIsFor != COLOR_INVALID) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5686 | return mCachedAmbientColor; |
| 5687 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5688 | final int contrasted = ContrastColorUtil.resolveAmbientColor(mContext, rawColor); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5689 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5690 | mCachedAmbientColorIsFor = rawColor; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5691 | return mCachedAmbientColor = contrasted; |
| 5692 | } |
| 5693 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5694 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5695 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5696 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5697 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5698 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5699 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5700 | mN.actions = new Action[mActions.size()]; |
| 5701 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5702 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5703 | if (!mPersonList.isEmpty()) { |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 5704 | mN.extras.putParcelableArrayList(EXTRA_PEOPLE_LIST, mPersonList); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 5705 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5706 | if (mN.bigContentView != null || mN.contentView != null |
| 5707 | || mN.headsUpContentView != null) { |
| 5708 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 5709 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5710 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5711 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5712 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5713 | /** |
| 5714 | * Creates a Builder from an existing notification so further changes can be made. |
| 5715 | * @param context The context for your application / activity. |
| 5716 | * @param n The notification to create a Builder from. |
| 5717 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5718 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5719 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5720 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 5721 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5722 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5723 | if (applicationInfo != null) { |
| 5724 | try { |
| 5725 | builderContext = context.createApplicationContext(applicationInfo, |
| 5726 | Context.CONTEXT_RESTRICTED); |
| 5727 | } catch (NameNotFoundException e) { |
| 5728 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 5729 | builderContext = context; // try with our context |
| 5730 | } |
| 5731 | } else { |
| 5732 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5733 | } |
| 5734 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5735 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5736 | } |
| 5737 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5738 | /** |
Gustav Sennton | 761884c | 2018-11-19 17:40:19 +0000 | [diff] [blame] | 5739 | * Determines whether the platform can generate contextual actions for a notification. |
| 5740 | * By default this is true. |
| 5741 | */ |
| 5742 | public Builder setAllowSystemGeneratedContextualActions(boolean allowed) { |
| 5743 | mN.mAllowSystemGeneratedContextualActions = allowed; |
| 5744 | return this; |
| 5745 | } |
| 5746 | |
| 5747 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5748 | * @deprecated Use {@link #build()} instead. |
| 5749 | */ |
| 5750 | @Deprecated |
| 5751 | public Notification getNotification() { |
| 5752 | return build(); |
| 5753 | } |
| 5754 | |
| 5755 | /** |
| 5756 | * Combine all of the options that have been set and return a new {@link Notification} |
| 5757 | * object. |
| 5758 | */ |
| 5759 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5760 | // first, add any extras from the calling code |
| 5761 | if (mUserExtras != null) { |
| 5762 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5763 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5764 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5765 | mN.creationTime = System.currentTimeMillis(); |
| 5766 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5767 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5768 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 5769 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5770 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5771 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5772 | if (mStyle != null) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5773 | mStyle.reduceImageSizes(mContext); |
| 5774 | mStyle.purgeResources(); |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 5775 | mStyle.validate(mContext); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5776 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5777 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5778 | mN.reduceImageSizes(mContext); |
| 5779 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5780 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5781 | && (useExistingRemoteView())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5782 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5783 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5784 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 5785 | mN.contentView.getSequenceNumber()); |
| 5786 | } |
| 5787 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5788 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5789 | if (mN.bigContentView != null) { |
| 5790 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 5791 | mN.bigContentView.getSequenceNumber()); |
| 5792 | } |
| 5793 | } |
| 5794 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5795 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5796 | if (mN.headsUpContentView != null) { |
| 5797 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 5798 | mN.headsUpContentView.getSequenceNumber()); |
| 5799 | } |
| 5800 | } |
| 5801 | } |
| 5802 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 5803 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 5804 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 5805 | } |
| 5806 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 5807 | mN.allPendingIntents = null; |
| 5808 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5809 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5810 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5811 | |
| 5812 | /** |
| 5813 | * Apply this Builder to an existing {@link Notification} object. |
| 5814 | * |
| 5815 | * @hide |
| 5816 | */ |
| 5817 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 5818 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5819 | return n; |
| 5820 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5821 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5822 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5823 | * 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] | 5824 | * change. Also removes extenders on low ram devices, as |
| 5825 | * {@link android.service.notification.NotificationListenerService} services are disabled. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5826 | * |
| 5827 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 5828 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5829 | * @hide |
| 5830 | */ |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5831 | public static Notification maybeCloneStrippedForDelivery(Notification n, boolean isLowRam, |
| 5832 | Context context) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5833 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5834 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5835 | // Only strip views for known Styles because we won't know how to |
| 5836 | // re-create them otherwise. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5837 | if (!isLowRam |
| 5838 | && !TextUtils.isEmpty(templateClass) |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5839 | && getNotificationStyleClass(templateClass) == null) { |
| 5840 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5841 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5842 | |
| 5843 | // Only strip unmodified BuilderRemoteViews. |
| 5844 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5845 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5846 | n.contentView.getSequenceNumber(); |
| 5847 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5848 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5849 | n.bigContentView.getSequenceNumber(); |
| 5850 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5851 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5852 | n.headsUpContentView.getSequenceNumber(); |
| 5853 | |
| 5854 | // Nothing to do here, no need to clone. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5855 | if (!isLowRam |
| 5856 | && !stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5857 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5858 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5859 | |
| 5860 | Notification clone = n.clone(); |
| 5861 | if (stripContentView) { |
| 5862 | clone.contentView = null; |
| 5863 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 5864 | } |
| 5865 | if (stripBigContentView) { |
| 5866 | clone.bigContentView = null; |
| 5867 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 5868 | } |
| 5869 | if (stripHeadsUpContentView) { |
| 5870 | clone.headsUpContentView = null; |
| 5871 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 5872 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5873 | if (isLowRam) { |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5874 | String[] allowedServices = context.getResources().getStringArray( |
| 5875 | R.array.config_allowedManagedServicesOnLowRamDevices); |
| 5876 | if (allowedServices.length == 0) { |
| 5877 | clone.extras.remove(Notification.TvExtender.EXTRA_TV_EXTENDER); |
| 5878 | clone.extras.remove(WearableExtender.EXTRA_WEARABLE_EXTENSIONS); |
| 5879 | clone.extras.remove(CarExtender.EXTRA_CAR_EXTENDER); |
| 5880 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5881 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5882 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5883 | } |
| 5884 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5885 | @UnsupportedAppUsage |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5886 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5887 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5888 | } |
| 5889 | |
| 5890 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5891 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5895 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5899 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5900 | } |
| 5901 | |
| 5902 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5903 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5904 | } |
| 5905 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5906 | private int getMessagingLayoutResource() { |
| 5907 | return R.layout.notification_template_material_messaging; |
| 5908 | } |
| 5909 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5910 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5911 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5912 | } |
| 5913 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5914 | private int getEmphasizedActionLayoutResource() { |
| 5915 | return R.layout.notification_material_action_emphasized; |
| 5916 | } |
| 5917 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5918 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5919 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5920 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5921 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5922 | private int getBackgroundColor(StandardTemplateParams p) { |
| 5923 | if (isColorized(p)) { |
| 5924 | return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : getRawColor(p); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5925 | } else { |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5926 | return COLOR_DEFAULT; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5927 | } |
| 5928 | } |
| 5929 | |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5930 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5931 | * 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] | 5932 | * @param p the template params to inflate this with |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5933 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5934 | private int getNeutralColor(StandardTemplateParams p) { |
| 5935 | if (isColorized(p)) { |
| 5936 | return getSecondaryTextColor(p); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5937 | } else { |
| 5938 | return resolveNeutralColor(); |
| 5939 | } |
| 5940 | } |
| 5941 | |
| 5942 | /** |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5943 | * Same as getBackgroundColor but also resolved the default color to the background. |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5944 | * @param p the template params to inflate this with |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5945 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5946 | private int resolveBackgroundColor(StandardTemplateParams p) { |
| 5947 | int backgroundColor = getBackgroundColor(p); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5948 | if (backgroundColor == COLOR_DEFAULT) { |
| 5949 | backgroundColor = mContext.getColor( |
| 5950 | com.android.internal.R.color.notification_material_background_color); |
| 5951 | } |
| 5952 | return backgroundColor; |
| 5953 | } |
| 5954 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5955 | private boolean shouldTintActionButtons() { |
| 5956 | return mTintActionButtons; |
| 5957 | } |
| 5958 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5959 | private boolean textColorsNeedInversion() { |
| 5960 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 5961 | return false; |
| 5962 | } |
| 5963 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 5964 | return targetSdkVersion > Build.VERSION_CODES.M |
| 5965 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 5966 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5967 | |
| 5968 | /** |
| 5969 | * Set a color palette to be used as the background and textColors |
| 5970 | * |
| 5971 | * @param backgroundColor the color to be used as the background |
| 5972 | * @param foregroundColor the color to be used as the foreground |
| 5973 | * |
| 5974 | * @hide |
| 5975 | */ |
| 5976 | public void setColorPalette(int backgroundColor, int foregroundColor) { |
| 5977 | mBackgroundColor = backgroundColor; |
| 5978 | mForegroundColor = foregroundColor; |
| 5979 | mTextColorsAreForBackground = COLOR_INVALID; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 5980 | ensureColors(mParams.reset().fillTextsFrom(this)); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5981 | } |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5982 | |
| 5983 | /** |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5984 | * Forces all styled remoteViews to be built from scratch and not use any cached |
| 5985 | * RemoteViews. |
| 5986 | * This is needed for legacy apps that are baking in their remoteviews into the |
| 5987 | * notification. |
| 5988 | * |
| 5989 | * @hide |
| 5990 | */ |
| 5991 | public void setRebuildStyledRemoteViews(boolean rebuild) { |
| 5992 | mRebuildStyledRemoteViews = rebuild; |
| 5993 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5994 | |
| 5995 | /** |
| 5996 | * Get the text that should be displayed in the statusBar when heads upped. This is |
| 5997 | * usually just the app name, but may be different depending on the style. |
| 5998 | * |
| 5999 | * @param publicMode If true, return a text that is safe to display in public. |
| 6000 | * |
| 6001 | * @hide |
| 6002 | */ |
| 6003 | public CharSequence getHeadsUpStatusBarText(boolean publicMode) { |
| 6004 | if (mStyle != null && !publicMode) { |
| 6005 | CharSequence text = mStyle.getHeadsUpStatusBarText(); |
| 6006 | if (!TextUtils.isEmpty(text)) { |
| 6007 | return text; |
| 6008 | } |
| 6009 | } |
| 6010 | return loadHeaderAppName(); |
| 6011 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6012 | } |
| 6013 | |
| 6014 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6015 | * Reduces the image sizes to conform to a maximum allowed size. This also processes all custom |
| 6016 | * remote views. |
| 6017 | * |
| 6018 | * @hide |
| 6019 | */ |
| 6020 | void reduceImageSizes(Context context) { |
| 6021 | if (extras.getBoolean(EXTRA_REDUCED_IMAGES)) { |
| 6022 | return; |
| 6023 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6024 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6025 | if (mLargeIcon != null || largeIcon != null) { |
| 6026 | Resources resources = context.getResources(); |
| 6027 | Class<? extends Style> style = getNotificationStyle(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6028 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6029 | ? R.dimen.notification_right_icon_size_low_ram |
| 6030 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6031 | int maxHeight = maxWidth; |
| 6032 | if (MediaStyle.class.equals(style) |
| 6033 | || DecoratedMediaCustomViewStyle.class.equals(style)) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6034 | maxHeight = resources.getDimensionPixelSize(isLowRam |
| 6035 | ? R.dimen.notification_media_image_max_height_low_ram |
| 6036 | : R.dimen.notification_media_image_max_height); |
| 6037 | maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6038 | ? R.dimen.notification_media_image_max_width_low_ram |
| 6039 | : R.dimen.notification_media_image_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6040 | } |
| 6041 | if (mLargeIcon != null) { |
| 6042 | mLargeIcon.scaleDownIfNecessary(maxWidth, maxHeight); |
| 6043 | } |
| 6044 | if (largeIcon != null) { |
| 6045 | largeIcon = Icon.scaleDownIfNecessary(largeIcon, maxWidth, maxHeight); |
| 6046 | } |
| 6047 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6048 | reduceImageSizesForRemoteView(contentView, context, isLowRam); |
| 6049 | reduceImageSizesForRemoteView(headsUpContentView, context, isLowRam); |
| 6050 | reduceImageSizesForRemoteView(bigContentView, context, isLowRam); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6051 | extras.putBoolean(EXTRA_REDUCED_IMAGES, true); |
| 6052 | } |
| 6053 | |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6054 | private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context, |
| 6055 | boolean isLowRam) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6056 | if (remoteView != null) { |
| 6057 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6058 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6059 | ? R.dimen.notification_custom_view_max_image_width_low_ram |
| 6060 | : R.dimen.notification_custom_view_max_image_width); |
| 6061 | int maxHeight = resources.getDimensionPixelSize(isLowRam |
| 6062 | ? R.dimen.notification_custom_view_max_image_height_low_ram |
| 6063 | : R.dimen.notification_custom_view_max_image_height); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6064 | remoteView.reduceImageSizes(maxWidth, maxHeight); |
| 6065 | } |
| 6066 | } |
| 6067 | |
| 6068 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6069 | * @return whether this notification is a foreground service notification |
Gus Prevas | b0c1a46 | 2018-11-05 11:06:15 -0500 | [diff] [blame] | 6070 | * @hide |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6071 | */ |
Gus Prevas | b0c1a46 | 2018-11-05 11:06:15 -0500 | [diff] [blame] | 6072 | public boolean isForegroundService() { |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6073 | return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6074 | } |
| 6075 | |
| 6076 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6077 | * @return whether this notification has a media session attached |
| 6078 | * @hide |
| 6079 | */ |
| 6080 | public boolean hasMediaSession() { |
| 6081 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 6082 | } |
| 6083 | |
| 6084 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6085 | * @return the style class of this notification |
| 6086 | * @hide |
| 6087 | */ |
| 6088 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 6089 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 6090 | |
| 6091 | if (!TextUtils.isEmpty(templateClass)) { |
| 6092 | return Notification.getNotificationStyleClass(templateClass); |
| 6093 | } |
| 6094 | return null; |
| 6095 | } |
| 6096 | |
| 6097 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 6098 | * @return true if this notification is colorized. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6099 | * |
| 6100 | * @hide |
| 6101 | */ |
| 6102 | public boolean isColorized() { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6103 | if (isColorizedMedia()) { |
| 6104 | return true; |
| 6105 | } |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 6106 | return extras.getBoolean(EXTRA_COLORIZED) |
| 6107 | && (hasColorizedPermission() || isForegroundService()); |
| 6108 | } |
| 6109 | |
| 6110 | /** |
| 6111 | * Returns whether an app can colorize due to the android.permission.USE_COLORIZED_NOTIFICATIONS |
| 6112 | * permission. The permission is checked when a notification is enqueued. |
| 6113 | */ |
| 6114 | private boolean hasColorizedPermission() { |
| 6115 | return (flags & Notification.FLAG_CAN_COLORIZE) != 0; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | /** |
| 6119 | * @return true if this notification is colorized and it is a media notification |
| 6120 | * |
| 6121 | * @hide |
| 6122 | */ |
| 6123 | public boolean isColorizedMedia() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6124 | Class<? extends Style> style = getNotificationStyle(); |
| 6125 | if (MediaStyle.class.equals(style)) { |
| 6126 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 6127 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 6128 | return true; |
| 6129 | } |
| 6130 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 6131 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 6132 | return true; |
| 6133 | } |
| 6134 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6135 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6136 | } |
| 6137 | |
Selim Cinek | 0847acd | 2017-04-24 19:48:29 -0700 | [diff] [blame] | 6138 | |
| 6139 | /** |
| 6140 | * @return true if this is a media notification |
| 6141 | * |
| 6142 | * @hide |
| 6143 | */ |
| 6144 | public boolean isMediaNotification() { |
| 6145 | Class<? extends Style> style = getNotificationStyle(); |
| 6146 | if (MediaStyle.class.equals(style)) { |
| 6147 | return true; |
| 6148 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 6149 | return true; |
| 6150 | } |
| 6151 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6152 | } |
| 6153 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6154 | private boolean hasLargeIcon() { |
| 6155 | return mLargeIcon != null || largeIcon != null; |
| 6156 | } |
| 6157 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6158 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6159 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 6160 | * @hide |
| 6161 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6162 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 6163 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 6164 | } |
| 6165 | |
| 6166 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6167 | * @return true if the notification will show a chronometer; false otherwise |
| 6168 | * @hide |
| 6169 | */ |
| 6170 | public boolean showsChronometer() { |
| 6171 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 6172 | } |
| 6173 | |
| 6174 | /** |
Julia Reynolds | 7ca3307 | 2017-06-29 13:58:24 -0400 | [diff] [blame] | 6175 | * @removed |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 6176 | */ |
| 6177 | @SystemApi |
| 6178 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 6179 | Class<? extends Style>[] classes = new Class[] { |
| 6180 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 6181 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 6182 | MessagingStyle.class }; |
| 6183 | for (Class<? extends Style> innerClass : classes) { |
| 6184 | if (templateClass.equals(innerClass.getName())) { |
| 6185 | return innerClass; |
| 6186 | } |
| 6187 | } |
| 6188 | return null; |
| 6189 | } |
| 6190 | |
| 6191 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6192 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 6193 | * object. |
| 6194 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 6195 | public static abstract class Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 6196 | |
| 6197 | /** |
| 6198 | * The number of items allowed simulatanously in the remote input history. |
| 6199 | * @hide |
| 6200 | */ |
| 6201 | static final int MAX_REMOTE_INPUT_HISTORY_LINES = 3; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6202 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6203 | |
| 6204 | /** |
| 6205 | * @hide |
| 6206 | */ |
| 6207 | protected CharSequence mSummaryText = null; |
| 6208 | |
| 6209 | /** |
| 6210 | * @hide |
| 6211 | */ |
| 6212 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6213 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6214 | protected Builder mBuilder; |
| 6215 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6216 | /** |
| 6217 | * Overrides ContentTitle in the big form of the template. |
| 6218 | * This defaults to the value passed to setContentTitle(). |
| 6219 | */ |
| 6220 | protected void internalSetBigContentTitle(CharSequence title) { |
| 6221 | mBigContentTitle = title; |
| 6222 | } |
| 6223 | |
| 6224 | /** |
| 6225 | * Set the first line of text after the detail section in the big form of the template. |
| 6226 | */ |
| 6227 | protected void internalSetSummaryText(CharSequence cs) { |
| 6228 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 6229 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6230 | } |
| 6231 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6232 | public void setBuilder(Builder builder) { |
| 6233 | if (mBuilder != builder) { |
| 6234 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 6235 | if (mBuilder != null) { |
| 6236 | mBuilder.setStyle(this); |
| 6237 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6238 | } |
| 6239 | } |
| 6240 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6241 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6242 | if (mBuilder == null) { |
| 6243 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 6244 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6245 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6246 | |
| 6247 | protected RemoteViews getStandardView(int layoutId) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6248 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder); |
| 6249 | return getStandardView(layoutId, p, null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6250 | } |
| 6251 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6252 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6253 | /** |
| 6254 | * Get the standard view for this style. |
| 6255 | * |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6256 | * @param layoutId The layout id to use. |
| 6257 | * @param p the params for this inflation. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6258 | * @param result The result where template bind information is saved. |
| 6259 | * @return A remoteView for this style. |
| 6260 | * @hide |
| 6261 | */ |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6262 | protected RemoteViews getStandardView(int layoutId, StandardTemplateParams p, |
| 6263 | TemplateBindResult result) { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6264 | checkBuilder(); |
| 6265 | |
| 6266 | if (mBigContentTitle != null) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6267 | p.title = mBigContentTitle; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6268 | } |
| 6269 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6270 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId, p, |
| 6271 | result); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6272 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6273 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 6274 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 6275 | } else { |
| 6276 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6277 | } |
| 6278 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6279 | return contentView; |
| 6280 | } |
| 6281 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6282 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6283 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6284 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6285 | * |
| 6286 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6287 | * @hide |
| 6288 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6289 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6290 | return null; |
| 6291 | } |
| 6292 | |
| 6293 | /** |
| 6294 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 6295 | * @hide |
| 6296 | */ |
| 6297 | public RemoteViews makeBigContentView() { |
| 6298 | return null; |
| 6299 | } |
| 6300 | |
| 6301 | /** |
| 6302 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6303 | * |
| 6304 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6305 | * @hide |
| 6306 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6307 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6308 | return null; |
| 6309 | } |
| 6310 | |
| 6311 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6312 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6313 | * @hide |
| 6314 | */ |
| 6315 | public void addExtras(Bundle extras) { |
| 6316 | if (mSummaryTextSet) { |
| 6317 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 6318 | } |
| 6319 | if (mBigContentTitle != null) { |
| 6320 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 6321 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 6322 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6323 | } |
| 6324 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6325 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6326 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6327 | * @hide |
| 6328 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6329 | protected void restoreFromExtras(Bundle extras) { |
| 6330 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 6331 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 6332 | mSummaryTextSet = true; |
| 6333 | } |
| 6334 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 6335 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 6336 | } |
| 6337 | } |
| 6338 | |
| 6339 | |
| 6340 | /** |
| 6341 | * @hide |
| 6342 | */ |
| 6343 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6344 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6345 | return wip; |
| 6346 | } |
| 6347 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6348 | /** |
| 6349 | * @hide |
| 6350 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6351 | public void purgeResources() {} |
| 6352 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6353 | /** |
| 6354 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 6355 | * attached to. |
| 6356 | * |
| 6357 | * @return the fully constructed Notification. |
| 6358 | */ |
| 6359 | public Notification build() { |
| 6360 | checkBuilder(); |
| 6361 | return mBuilder.build(); |
| 6362 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6363 | |
| 6364 | /** |
| 6365 | * @hide |
| 6366 | * @return true if the style positions the progress bar on the second line; false if the |
| 6367 | * style hides the progress bar |
| 6368 | */ |
| 6369 | protected boolean hasProgress() { |
| 6370 | return true; |
| 6371 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6372 | |
| 6373 | /** |
| 6374 | * @hide |
| 6375 | * @return Whether we should put the summary be put into the notification header |
| 6376 | */ |
| 6377 | public boolean hasSummaryInHeader() { |
| 6378 | return true; |
| 6379 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6380 | |
| 6381 | /** |
| 6382 | * @hide |
| 6383 | * @return Whether custom content views are displayed inline in the style |
| 6384 | */ |
| 6385 | public boolean displayCustomViewInline() { |
| 6386 | return false; |
| 6387 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6388 | |
| 6389 | /** |
| 6390 | * Reduces the image sizes contained in this style. |
| 6391 | * |
| 6392 | * @hide |
| 6393 | */ |
| 6394 | public void reduceImageSizes(Context context) { |
| 6395 | } |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6396 | |
| 6397 | /** |
| 6398 | * Validate that this style was properly composed. This is called at build time. |
| 6399 | * @hide |
| 6400 | */ |
| 6401 | public void validate(Context context) { |
| 6402 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6403 | |
| 6404 | /** |
| 6405 | * @hide |
| 6406 | */ |
| 6407 | public abstract boolean areNotificationsVisiblyDifferent(Style other); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 6408 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6409 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6410 | * @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] | 6411 | * If {@code null} is returned, the default implementation will be used. |
| 6412 | * |
| 6413 | * @hide |
| 6414 | */ |
| 6415 | public CharSequence getHeadsUpStatusBarText() { |
| 6416 | return null; |
| 6417 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 6418 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6419 | |
| 6420 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6421 | * 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] | 6422 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6423 | * 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] | 6424 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6425 | * Notification notif = new Notification.Builder(mContext) |
| 6426 | * .setContentTitle("New photo from " + sender.toString()) |
| 6427 | * .setContentText(subject) |
| 6428 | * .setSmallIcon(R.drawable.new_post) |
| 6429 | * .setLargeIcon(aBitmap) |
| 6430 | * .setStyle(new Notification.BigPictureStyle() |
| 6431 | * .bigPicture(aBigBitmap)) |
| 6432 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6433 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6434 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6435 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6436 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6437 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6438 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6439 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6440 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6441 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6442 | public BigPictureStyle() { |
| 6443 | } |
| 6444 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6445 | /** |
| 6446 | * @deprecated use {@code BigPictureStyle()}. |
| 6447 | */ |
| 6448 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6449 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6450 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6451 | } |
| 6452 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6453 | /** |
| 6454 | * Overrides ContentTitle in the big form of the template. |
| 6455 | * This defaults to the value passed to setContentTitle(). |
| 6456 | */ |
| 6457 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6458 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6459 | return this; |
| 6460 | } |
| 6461 | |
| 6462 | /** |
| 6463 | * Set the first line of text after the detail section in the big form of the template. |
| 6464 | */ |
| 6465 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6466 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6467 | return this; |
| 6468 | } |
| 6469 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6470 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6471 | * @hide |
| 6472 | */ |
| 6473 | public Bitmap getBigPicture() { |
| 6474 | return mPicture; |
| 6475 | } |
| 6476 | |
| 6477 | /** |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6478 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 6479 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6480 | public BigPictureStyle bigPicture(Bitmap b) { |
| 6481 | mPicture = b; |
| 6482 | return this; |
| 6483 | } |
| 6484 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6485 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6486 | * Override the large icon when the big notification is shown. |
| 6487 | */ |
| 6488 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6489 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 6490 | } |
| 6491 | |
| 6492 | /** |
| 6493 | * Override the large icon when the big notification is shown. |
| 6494 | */ |
| 6495 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6496 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6497 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6498 | return this; |
| 6499 | } |
| 6500 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6501 | /** @hide */ |
| 6502 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 6503 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6504 | /** |
| 6505 | * @hide |
| 6506 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6507 | @Override |
| 6508 | public void purgeResources() { |
| 6509 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 6510 | if (mPicture != null && |
| 6511 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6512 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6513 | mPicture = mPicture.createAshmemBitmap(); |
| 6514 | } |
| 6515 | if (mBigLargeIcon != null) { |
| 6516 | mBigLargeIcon.convertToAshmem(); |
| 6517 | } |
| 6518 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6519 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6520 | /** |
| 6521 | * @hide |
| 6522 | */ |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6523 | @Override |
| 6524 | public void reduceImageSizes(Context context) { |
| 6525 | super.reduceImageSizes(context); |
| 6526 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6527 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6528 | if (mPicture != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6529 | int maxPictureWidth = resources.getDimensionPixelSize(isLowRam |
| 6530 | ? R.dimen.notification_big_picture_max_height_low_ram |
| 6531 | : R.dimen.notification_big_picture_max_height); |
| 6532 | int maxPictureHeight = resources.getDimensionPixelSize(isLowRam |
| 6533 | ? R.dimen.notification_big_picture_max_width_low_ram |
| 6534 | : R.dimen.notification_big_picture_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6535 | mPicture = Icon.scaleDownIfNecessary(mPicture, maxPictureWidth, maxPictureHeight); |
| 6536 | } |
| 6537 | if (mBigLargeIcon != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6538 | int rightIconSize = resources.getDimensionPixelSize(isLowRam |
| 6539 | ? R.dimen.notification_right_icon_size_low_ram |
| 6540 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6541 | mBigLargeIcon.scaleDownIfNecessary(rightIconSize, rightIconSize); |
| 6542 | } |
| 6543 | } |
| 6544 | |
| 6545 | /** |
| 6546 | * @hide |
| 6547 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6548 | public RemoteViews makeBigContentView() { |
| 6549 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6550 | // This covers the following cases: |
| 6551 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6552 | // mN.mLargeIcon |
| 6553 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6554 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6555 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6556 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6557 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 6558 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6559 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 6560 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 6561 | // for old listeners, this is in general non-null. |
| 6562 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 6563 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6564 | } |
| 6565 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6566 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6567 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource(), |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6568 | p, null /* result */); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6569 | if (mSummaryTextSet) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6570 | contentView.setTextViewText(R.id.text, mBuilder.processTextSpans( |
| 6571 | mBuilder.processLegacyText(mSummaryText))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6572 | mBuilder.setTextViewColorSecondary(contentView, R.id.text, p); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 6573 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6574 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6575 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 6576 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6577 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6578 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6579 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6580 | } |
| 6581 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6582 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6583 | return contentView; |
| 6584 | } |
| 6585 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6586 | /** |
| 6587 | * @hide |
| 6588 | */ |
| 6589 | public void addExtras(Bundle extras) { |
| 6590 | super.addExtras(extras); |
| 6591 | |
| 6592 | if (mBigLargeIconSet) { |
| 6593 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 6594 | } |
| 6595 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 6596 | } |
| 6597 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6598 | /** |
| 6599 | * @hide |
| 6600 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6601 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6602 | protected void restoreFromExtras(Bundle extras) { |
| 6603 | super.restoreFromExtras(extras); |
| 6604 | |
| 6605 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6606 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6607 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6608 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6609 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 6610 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6611 | |
| 6612 | /** |
| 6613 | * @hide |
| 6614 | */ |
| 6615 | @Override |
| 6616 | public boolean hasSummaryInHeader() { |
| 6617 | return false; |
| 6618 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6619 | |
| 6620 | /** |
| 6621 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6622 | * Note that we aren't actually comparing the contents of the bitmaps here, so this |
| 6623 | * 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] | 6624 | */ |
| 6625 | @Override |
| 6626 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6627 | if (other == null || getClass() != other.getClass()) { |
| 6628 | return true; |
| 6629 | } |
| 6630 | BigPictureStyle otherS = (BigPictureStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6631 | return areBitmapsObviouslyDifferent(getBigPicture(), otherS.getBigPicture()); |
| 6632 | } |
| 6633 | |
| 6634 | private static boolean areBitmapsObviouslyDifferent(Bitmap a, Bitmap b) { |
| 6635 | if (a == b) { |
| 6636 | return false; |
| 6637 | } |
| 6638 | if (a == null || b == null) { |
| 6639 | return true; |
| 6640 | } |
| 6641 | return a.getWidth() != b.getWidth() |
| 6642 | || a.getHeight() != b.getHeight() |
| 6643 | || a.getConfig() != b.getConfig() |
| 6644 | || a.getGenerationId() != b.getGenerationId(); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6645 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6646 | } |
| 6647 | |
| 6648 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6649 | * 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] | 6650 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6651 | * 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] | 6652 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6653 | * Notification notif = new Notification.Builder(mContext) |
| 6654 | * .setContentTitle("New mail from " + sender.toString()) |
| 6655 | * .setContentText(subject) |
| 6656 | * .setSmallIcon(R.drawable.new_mail) |
| 6657 | * .setLargeIcon(aBitmap) |
| 6658 | * .setStyle(new Notification.BigTextStyle() |
| 6659 | * .bigText(aVeryLongString)) |
| 6660 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6661 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6662 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6663 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6664 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6665 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6666 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6667 | private CharSequence mBigText; |
| 6668 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6669 | public BigTextStyle() { |
| 6670 | } |
| 6671 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6672 | /** |
| 6673 | * @deprecated use {@code BigTextStyle()}. |
| 6674 | */ |
| 6675 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6676 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6677 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6678 | } |
| 6679 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6680 | /** |
| 6681 | * Overrides ContentTitle in the big form of the template. |
| 6682 | * This defaults to the value passed to setContentTitle(). |
| 6683 | */ |
| 6684 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6685 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6686 | return this; |
| 6687 | } |
| 6688 | |
| 6689 | /** |
| 6690 | * Set the first line of text after the detail section in the big form of the template. |
| 6691 | */ |
| 6692 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6693 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6694 | return this; |
| 6695 | } |
| 6696 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6697 | /** |
| 6698 | * Provide the longer text to be displayed in the big form of the |
| 6699 | * template in place of the content text. |
| 6700 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6701 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6702 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6703 | return this; |
| 6704 | } |
| 6705 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6706 | /** |
| 6707 | * @hide |
| 6708 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6709 | public CharSequence getBigText() { |
| 6710 | return mBigText; |
| 6711 | } |
| 6712 | |
| 6713 | /** |
| 6714 | * @hide |
| 6715 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6716 | public void addExtras(Bundle extras) { |
| 6717 | super.addExtras(extras); |
| 6718 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6719 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 6720 | } |
| 6721 | |
| 6722 | /** |
| 6723 | * @hide |
| 6724 | */ |
| 6725 | @Override |
| 6726 | protected void restoreFromExtras(Bundle extras) { |
| 6727 | super.restoreFromExtras(extras); |
| 6728 | |
| 6729 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6730 | } |
| 6731 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6732 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6733 | * @param increasedHeight true if this layout be created with an increased height. |
| 6734 | * |
| 6735 | * @hide |
| 6736 | */ |
| 6737 | @Override |
| 6738 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6739 | if (increasedHeight) { |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6740 | mBuilder.mOriginalActions = mBuilder.mActions; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6741 | mBuilder.mActions = new ArrayList<>(); |
| 6742 | RemoteViews remoteViews = makeBigContentView(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6743 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6744 | mBuilder.mOriginalActions = null; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6745 | return remoteViews; |
| 6746 | } |
| 6747 | return super.makeContentView(increasedHeight); |
| 6748 | } |
| 6749 | |
| 6750 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6751 | * @hide |
| 6752 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6753 | @Override |
| 6754 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 6755 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 6756 | return makeBigContentView(); |
| 6757 | } |
| 6758 | return super.makeHeadsUpContentView(increasedHeight); |
| 6759 | } |
| 6760 | |
| 6761 | /** |
| 6762 | * @hide |
| 6763 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6764 | public RemoteViews makeBigContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6765 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder).text(null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6766 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6767 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource(), p, |
| 6768 | result); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 6769 | contentView.setInt(R.id.big_text, "setImageEndMargin", result.getIconMarginEnd()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6770 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 6771 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6772 | if (TextUtils.isEmpty(bigTextText)) { |
| 6773 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 6774 | // experience |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6775 | bigTextText = mBuilder.processLegacyText( |
| 6776 | mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT)); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6777 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 6778 | contentView.setTextViewText(R.id.big_text, mBuilder.processTextSpans(bigTextText)); |
| 6779 | mBuilder.setTextViewColorSecondary(contentView, R.id.big_text, p); |
| 6780 | contentView.setViewVisibility(R.id.big_text, |
| 6781 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame^] | 6782 | contentView.setBoolean(R.id.big_text, "setHasImage", |
| 6783 | result.isRightIconContainerVisible()); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 6784 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6785 | return contentView; |
| 6786 | } |
| 6787 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6788 | /** |
| 6789 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6790 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6791 | */ |
| 6792 | @Override |
| 6793 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6794 | if (other == null || getClass() != other.getClass()) { |
| 6795 | return true; |
| 6796 | } |
| 6797 | BigTextStyle newS = (BigTextStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6798 | return !Objects.equals(String.valueOf(getBigText()), String.valueOf(newS.getBigText())); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6799 | } |
| 6800 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6801 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6802 | |
| 6803 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6804 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 6805 | * messages of varying types between any number of people. |
| 6806 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6807 | * <p> |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6808 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 6809 | * user will always see the normal notification view. |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6810 | * |
| 6811 | * <p> |
| 6812 | * If the app is targeting Android P and above, it is required to use the {@link Person} |
| 6813 | * class in order to get an optimal rendering of the notification and its avatars. For |
| 6814 | * conversations involving multiple people, the app should also make sure that it marks the |
| 6815 | * conversation as a group with {@link #setGroupConversation(boolean)}. |
| 6816 | * |
| 6817 | * <p> |
| 6818 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior. |
| 6819 | * Here's an example of how this may be used: |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6820 | * <pre class="prettyprint"> |
| 6821 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6822 | * Person user = new Person.Builder().setIcon(userIcon).setName(userName).build(); |
| 6823 | * MessagingStyle style = new MessagingStyle(user) |
| 6824 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getPerson()) |
| 6825 | * .addMessage(messages[2].getText(), messages[2].getTime(), messages[2].getPerson()) |
| 6826 | * .setGroupConversation(hasMultiplePeople()); |
| 6827 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6828 | * Notification noti = new Notification.Builder() |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6829 | * .setContentTitle("2 new messages with " + sender.toString()) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6830 | * .setContentText(subject) |
| 6831 | * .setSmallIcon(R.drawable.new_message) |
| 6832 | * .setLargeIcon(aBitmap) |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6833 | * .setStyle(style) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6834 | * .build(); |
| 6835 | * </pre> |
| 6836 | */ |
| 6837 | public static class MessagingStyle extends Style { |
| 6838 | |
| 6839 | /** |
| 6840 | * The maximum number of messages that will be retained in the Notification itself (the |
| 6841 | * number displayed is up to the platform). |
| 6842 | */ |
| 6843 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 6844 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6845 | @NonNull Person mUser; |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6846 | @Nullable CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6847 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6848 | List<Message> mHistoricMessages = new ArrayList<>(); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6849 | boolean mIsGroupConversation; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6850 | |
| 6851 | MessagingStyle() { |
| 6852 | } |
| 6853 | |
| 6854 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6855 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 6856 | * user before the posting app reposts the notification with those messages after they've |
| 6857 | * 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] | 6858 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6859 | * |
| 6860 | * @deprecated use {@code MessagingStyle(Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6861 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6862 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6863 | this(new Person.Builder().setName(userDisplayName).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6864 | } |
| 6865 | |
| 6866 | /** |
| 6867 | * @param user Required - The person displayed for any messages that are sent by the |
| 6868 | * user. Any messages added with {@link #addMessage(Notification.MessagingStyle.Message)} |
| 6869 | * 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] | 6870 | * by this user. The user also needs to have a valid name associated with it, which will |
| 6871 | * be enforced starting in Android P. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6872 | */ |
| 6873 | public MessagingStyle(@NonNull Person user) { |
| 6874 | mUser = user; |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6875 | } |
| 6876 | |
| 6877 | /** |
| 6878 | * Validate that this style was properly composed. This is called at build time. |
| 6879 | * @hide |
| 6880 | */ |
| 6881 | @Override |
| 6882 | public void validate(Context context) { |
| 6883 | super.validate(context); |
| 6884 | if (context.getApplicationInfo().targetSdkVersion |
| 6885 | >= Build.VERSION_CODES.P && (mUser == null || mUser.getName() == null)) { |
| 6886 | throw new RuntimeException("User must be valid and have a name."); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6887 | } |
| 6888 | } |
| 6889 | |
| 6890 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6891 | * @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] | 6892 | * If {@code null} is returned, the default implementation will be used. |
| 6893 | * |
| 6894 | * @hide |
| 6895 | */ |
| 6896 | @Override |
| 6897 | public CharSequence getHeadsUpStatusBarText() { |
| 6898 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
| 6899 | ? super.mBigContentTitle |
| 6900 | : mConversationTitle; |
| 6901 | if (!TextUtils.isEmpty(conversationTitle) && !hasOnlyWhiteSpaceSenders()) { |
| 6902 | return conversationTitle; |
| 6903 | } |
| 6904 | return null; |
| 6905 | } |
| 6906 | |
| 6907 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6908 | * @return the user to be displayed for any replies sent by the user |
| 6909 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6910 | @NonNull |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6911 | public Person getUser() { |
| 6912 | return mUser; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6913 | } |
| 6914 | |
| 6915 | /** |
| 6916 | * 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] | 6917 | * |
| 6918 | * @deprecated use {@link #getUser()} instead |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6919 | */ |
| 6920 | public CharSequence getUserDisplayName() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6921 | return mUser.getName(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6922 | } |
| 6923 | |
| 6924 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6925 | * Sets the title to be displayed on this conversation. May be set to {@code null}. |
| 6926 | * |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6927 | * <p>This API's behavior was changed in SDK version {@link Build.VERSION_CODES#P}. If your |
| 6928 | * application's target version is less than {@link Build.VERSION_CODES#P}, setting a |
| 6929 | * conversation title to a non-null value will make {@link #isGroupConversation()} return |
| 6930 | * {@code true} and passing {@code null} will make it return {@code false}. In |
| 6931 | * {@link Build.VERSION_CODES#P} and beyond, use {@link #setGroupConversation(boolean)} |
| 6932 | * to set group conversation status. |
| 6933 | * |
| 6934 | * @param conversationTitle Title displayed for this conversation |
| 6935 | * @return this object for method chaining |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6936 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6937 | public MessagingStyle setConversationTitle(@Nullable CharSequence conversationTitle) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6938 | mConversationTitle = conversationTitle; |
| 6939 | return this; |
| 6940 | } |
| 6941 | |
| 6942 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6943 | * 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] | 6944 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6945 | @Nullable |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6946 | public CharSequence getConversationTitle() { |
| 6947 | return mConversationTitle; |
| 6948 | } |
| 6949 | |
| 6950 | /** |
| 6951 | * Adds a message for display by this notification. Convenience call for a simple |
| 6952 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6953 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6954 | * @param timestamp Time at which the message arrived |
| 6955 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 6956 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 6957 | * the platform will insert {@link #getUserDisplayName()}. |
| 6958 | * Should be unique amongst all individuals in the conversation, and should be |
| 6959 | * consistent during re-posts of the notification. |
| 6960 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 6961 | * @see Message#Notification.MessagingStyle.Message(CharSequence, long, CharSequence) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6962 | * |
| 6963 | * @return this object for method chaining |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6964 | * |
| 6965 | * @deprecated use {@link #addMessage(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6966 | */ |
| 6967 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6968 | return addMessage(text, timestamp, |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6969 | sender == null ? null : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6970 | } |
| 6971 | |
| 6972 | /** |
| 6973 | * Adds a message for display by this notification. Convenience call for a simple |
| 6974 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6975 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6976 | * @param timestamp Time at which the message arrived |
| 6977 | * @param sender The {@link Person} who sent the message. |
| 6978 | * Should be <code>null</code> for messages by the current user, in which case |
| 6979 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 6980 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 6981 | * @see Message#Notification.MessagingStyle.Message(CharSequence, long, CharSequence) |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6982 | * |
| 6983 | * @return this object for method chaining |
| 6984 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6985 | public MessagingStyle addMessage(@NonNull CharSequence text, long timestamp, |
| 6986 | @Nullable Person sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6987 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6988 | } |
| 6989 | |
| 6990 | /** |
| 6991 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6992 | * |
| 6993 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6994 | * the newest last. |
| 6995 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6996 | * @param message The {@link Message} to be displayed |
| 6997 | * @return this object for method chaining |
| 6998 | */ |
| 6999 | public MessagingStyle addMessage(Message message) { |
| 7000 | mMessages.add(message); |
| 7001 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 7002 | mMessages.remove(0); |
| 7003 | } |
| 7004 | return this; |
| 7005 | } |
| 7006 | |
| 7007 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7008 | * Adds a {@link Message} for historic context in this notification. |
| 7009 | * |
| 7010 | * <p>Messages should be added as historic if they are not the main subject of the |
| 7011 | * notification but may give context to a conversation. The system may choose to present |
| 7012 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 7013 | * |
| 7014 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 7015 | * the newest last. |
| 7016 | * |
| 7017 | * @param message The historic {@link Message} to be added |
| 7018 | * @return this object for method chaining |
| 7019 | */ |
| 7020 | public MessagingStyle addHistoricMessage(Message message) { |
| 7021 | mHistoricMessages.add(message); |
| 7022 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 7023 | mHistoricMessages.remove(0); |
| 7024 | } |
| 7025 | return this; |
| 7026 | } |
| 7027 | |
| 7028 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7029 | * Gets the list of {@code Message} objects that represent the notification |
| 7030 | */ |
| 7031 | public List<Message> getMessages() { |
| 7032 | return mMessages; |
| 7033 | } |
| 7034 | |
| 7035 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7036 | * Gets the list of historic {@code Message}s in the notification. |
| 7037 | */ |
| 7038 | public List<Message> getHistoricMessages() { |
| 7039 | return mHistoricMessages; |
| 7040 | } |
| 7041 | |
| 7042 | /** |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7043 | * Sets whether this conversation notification represents a group. If the app is targeting |
| 7044 | * Android P, this is required if the app wants to display the largeIcon set with |
| 7045 | * {@link Notification.Builder#setLargeIcon(Bitmap)}, otherwise it will be hidden. |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7046 | * |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7047 | * @param isGroupConversation {@code true} if the conversation represents a group, |
| 7048 | * {@code false} otherwise. |
| 7049 | * @return this object for method chaining |
| 7050 | */ |
| 7051 | public MessagingStyle setGroupConversation(boolean isGroupConversation) { |
| 7052 | mIsGroupConversation = isGroupConversation; |
| 7053 | return this; |
| 7054 | } |
| 7055 | |
| 7056 | /** |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7057 | * Returns {@code true} if this notification represents a group conversation, otherwise |
| 7058 | * {@code false}. |
| 7059 | * |
| 7060 | * <p> If the application that generated this {@link MessagingStyle} targets an SDK version |
| 7061 | * less than {@link Build.VERSION_CODES#P}, this method becomes dependent on whether or |
| 7062 | * not the conversation title is set; returning {@code true} if the conversation title is |
| 7063 | * a non-null value, or {@code false} otherwise. From {@link Build.VERSION_CODES#P} forward, |
| 7064 | * this method returns what's set by {@link #setGroupConversation(boolean)} allowing for |
| 7065 | * named, non-group conversations. |
| 7066 | * |
| 7067 | * @see #setConversationTitle(CharSequence) |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7068 | */ |
| 7069 | public boolean isGroupConversation() { |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 7070 | // When target SDK version is < P, a non-null conversation title dictates if this is |
| 7071 | // as group conversation. |
| 7072 | if (mBuilder != null |
| 7073 | && mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 7074 | < Build.VERSION_CODES.P) { |
| 7075 | return mConversationTitle != null; |
| 7076 | } |
| 7077 | |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7078 | return mIsGroupConversation; |
| 7079 | } |
| 7080 | |
| 7081 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7082 | * @hide |
| 7083 | */ |
| 7084 | @Override |
| 7085 | public void addExtras(Bundle extras) { |
| 7086 | super.addExtras(extras); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7087 | if (mUser != null) { |
| 7088 | // For legacy usages |
| 7089 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUser.getName()); |
| 7090 | extras.putParcelable(EXTRA_MESSAGING_PERSON, mUser); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7091 | } |
| 7092 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7093 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7094 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7095 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 7096 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7097 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7098 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 7099 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 7100 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7101 | |
| 7102 | fixTitleAndTextExtras(extras); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7103 | extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | private void fixTitleAndTextExtras(Bundle extras) { |
| 7107 | Message m = findLatestIncomingMessage(); |
| 7108 | CharSequence text = (m == null) ? null : m.mText; |
| 7109 | CharSequence sender = m == null ? null |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7110 | : m.mSender == null || TextUtils.isEmpty(m.mSender.getName()) |
| 7111 | ? mUser.getName() : m.mSender.getName(); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7112 | CharSequence title; |
| 7113 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 7114 | if (!TextUtils.isEmpty(sender)) { |
| 7115 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 7116 | title = mBuilder.mContext.getString( |
| 7117 | com.android.internal.R.string.notification_messaging_title_template, |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7118 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(sender)); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7119 | } else { |
| 7120 | title = mConversationTitle; |
| 7121 | } |
| 7122 | } else { |
| 7123 | title = sender; |
| 7124 | } |
| 7125 | |
| 7126 | if (title != null) { |
| 7127 | extras.putCharSequence(EXTRA_TITLE, title); |
| 7128 | } |
| 7129 | if (text != null) { |
| 7130 | extras.putCharSequence(EXTRA_TEXT, text); |
| 7131 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7132 | } |
| 7133 | |
| 7134 | /** |
| 7135 | * @hide |
| 7136 | */ |
| 7137 | @Override |
| 7138 | protected void restoreFromExtras(Bundle extras) { |
| 7139 | super.restoreFromExtras(extras); |
| 7140 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7141 | mUser = extras.getParcelable(EXTRA_MESSAGING_PERSON); |
| 7142 | if (mUser == null) { |
| 7143 | CharSequence displayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7144 | mUser = new Person.Builder().setName(displayName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7145 | } |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 7146 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7147 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7148 | mMessages = Message.getMessagesFromBundleArray(messages); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7149 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7150 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7151 | mIsGroupConversation = extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7152 | } |
| 7153 | |
| 7154 | /** |
| 7155 | * @hide |
| 7156 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7157 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7158 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7159 | mBuilder.mOriginalActions = mBuilder.mActions; |
| 7160 | mBuilder.mActions = new ArrayList<>(); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7161 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7162 | false /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7163 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 7164 | mBuilder.mOriginalActions = null; |
| 7165 | return remoteViews; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7166 | } |
| 7167 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7168 | /** |
| 7169 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7170 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7171 | */ |
| 7172 | @Override |
| 7173 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7174 | if (other == null || getClass() != other.getClass()) { |
| 7175 | return true; |
| 7176 | } |
| 7177 | MessagingStyle newS = (MessagingStyle) other; |
| 7178 | List<MessagingStyle.Message> oldMs = getMessages(); |
| 7179 | List<MessagingStyle.Message> newMs = newS.getMessages(); |
| 7180 | |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7181 | if (oldMs == null || newMs == null) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7182 | newMs = new ArrayList<>(); |
| 7183 | } |
| 7184 | |
| 7185 | int n = oldMs.size(); |
| 7186 | if (n != newMs.size()) { |
| 7187 | return true; |
| 7188 | } |
| 7189 | for (int i = 0; i < n; i++) { |
| 7190 | MessagingStyle.Message oldM = oldMs.get(i); |
| 7191 | MessagingStyle.Message newM = newMs.get(i); |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7192 | if (!Objects.equals( |
| 7193 | String.valueOf(oldM.getText()), |
| 7194 | String.valueOf(newM.getText()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7195 | return true; |
| 7196 | } |
| 7197 | if (!Objects.equals(oldM.getDataUri(), newM.getDataUri())) { |
| 7198 | return true; |
| 7199 | } |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7200 | String oldSender = String.valueOf(oldM.getSenderPerson() == null |
| 7201 | ? oldM.getSender() |
| 7202 | : oldM.getSenderPerson().getName()); |
| 7203 | String newSender = String.valueOf(newM.getSenderPerson() == null |
| 7204 | ? newM.getSender() |
| 7205 | : newM.getSenderPerson().getName()); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7206 | if (!Objects.equals(oldSender, newSender)) { |
| 7207 | return true; |
| 7208 | } |
| 7209 | |
| 7210 | String oldKey = oldM.getSenderPerson() == null |
| 7211 | ? null : oldM.getSenderPerson().getKey(); |
| 7212 | String newKey = newM.getSenderPerson() == null |
| 7213 | ? null : newM.getSenderPerson().getKey(); |
| 7214 | if (!Objects.equals(oldKey, newKey)) { |
| 7215 | return true; |
| 7216 | } |
| 7217 | // Other fields (like timestamp) intentionally excluded |
| 7218 | } |
| 7219 | return false; |
| 7220 | } |
| 7221 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7222 | private Message findLatestIncomingMessage() { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7223 | return findLatestIncomingMessage(mMessages); |
| 7224 | } |
| 7225 | |
| 7226 | /** |
| 7227 | * @hide |
| 7228 | */ |
| 7229 | @Nullable |
| 7230 | public static Message findLatestIncomingMessage( |
| 7231 | List<Message> messages) { |
| 7232 | for (int i = messages.size() - 1; i >= 0; i--) { |
| 7233 | Message m = messages.get(i); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7234 | // Incoming messages have a non-empty sender. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7235 | if (m.mSender != null && !TextUtils.isEmpty(m.mSender.getName())) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7236 | return m; |
| 7237 | } |
| 7238 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7239 | if (!messages.isEmpty()) { |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7240 | // No incoming messages, fall back to outgoing message |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7241 | return messages.get(messages.size() - 1); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7242 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7243 | return null; |
| 7244 | } |
| 7245 | |
| 7246 | /** |
| 7247 | * @hide |
| 7248 | */ |
| 7249 | @Override |
| 7250 | public RemoteViews makeBigContentView() { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7251 | return makeMessagingView(false /* displayImagesAtEnd */, true /* hideLargeIcon */); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7252 | } |
| 7253 | |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7254 | /** |
| 7255 | * Create a messaging layout. |
| 7256 | * |
| 7257 | * @param displayImagesAtEnd should images be displayed at the end of the content instead |
| 7258 | * of inline. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7259 | * @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] | 7260 | * @return the created remoteView. |
| 7261 | */ |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7262 | @NonNull |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7263 | private RemoteViews makeMessagingView(boolean displayImagesAtEnd, boolean hideRightIcons) { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7264 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7265 | ? super.mBigContentTitle |
| 7266 | : mConversationTitle; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7267 | boolean atLeastP = mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 7268 | >= Build.VERSION_CODES.P; |
| 7269 | boolean isOneToOne; |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7270 | CharSequence nameReplacement = null; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7271 | Icon avatarReplacement = null; |
| 7272 | if (!atLeastP) { |
| 7273 | isOneToOne = TextUtils.isEmpty(conversationTitle); |
| 7274 | avatarReplacement = mBuilder.mN.mLargeIcon; |
| 7275 | if (hasOnlyWhiteSpaceSenders()) { |
| 7276 | isOneToOne = true; |
| 7277 | nameReplacement = conversationTitle; |
| 7278 | conversationTitle = null; |
| 7279 | } |
| 7280 | } else { |
| 7281 | isOneToOne = !isGroupConversation(); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 7282 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7283 | TemplateBindResult bindResult = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7284 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).title( |
| 7285 | conversationTitle).text(null) |
| 7286 | .hideLargeIcon(hideRightIcons || isOneToOne) |
| 7287 | .hideReplyIcon(hideRightIcons) |
| 7288 | .headerTextSecondary(conversationTitle); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 7289 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7290 | mBuilder.getMessagingLayoutResource(), |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7291 | p, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7292 | bindResult); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7293 | addExtras(mBuilder.mN.extras); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7294 | // also update the end margin if there is an image |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7295 | contentView.setViewLayoutMarginEnd(R.id.notification_messaging, |
| 7296 | bindResult.getIconMarginEnd()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7297 | contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7298 | mBuilder.isColorized(p) ? mBuilder.getPrimaryTextColor(p) |
| 7299 | : mBuilder.resolveContrastColor(p)); |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 7300 | contentView.setInt(R.id.status_bar_latest_event_content, "setSenderTextColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7301 | mBuilder.getPrimaryTextColor(p)); |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 7302 | contentView.setInt(R.id.status_bar_latest_event_content, "setMessageTextColor", |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7303 | mBuilder.getSecondaryTextColor(p)); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7304 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd", |
| 7305 | displayImagesAtEnd); |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7306 | contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement", |
| 7307 | avatarReplacement); |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7308 | contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement", |
| 7309 | nameReplacement); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7310 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne", |
| 7311 | isOneToOne); |
| 7312 | contentView.setBundle(R.id.status_bar_latest_event_content, "setData", |
| 7313 | mBuilder.mN.extras); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7314 | return contentView; |
| 7315 | } |
| 7316 | |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7317 | private boolean hasOnlyWhiteSpaceSenders() { |
| 7318 | for (int i = 0; i < mMessages.size(); i++) { |
| 7319 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7320 | Person sender = m.getSenderPerson(); |
| 7321 | if (sender != null && !isWhiteSpace(sender.getName())) { |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7322 | return false; |
| 7323 | } |
| 7324 | } |
| 7325 | return true; |
| 7326 | } |
| 7327 | |
| 7328 | private boolean isWhiteSpace(CharSequence sender) { |
| 7329 | if (TextUtils.isEmpty(sender)) { |
| 7330 | return true; |
| 7331 | } |
| 7332 | if (sender.toString().matches("^\\s*$")) { |
| 7333 | return true; |
| 7334 | } |
| 7335 | // Let's check if we only have 0 whitespace chars. Some apps did this as a workaround |
| 7336 | // For the presentation that we had. |
| 7337 | for (int i = 0; i < sender.length(); i++) { |
| 7338 | char c = sender.charAt(i); |
| 7339 | if (c != '\u200B') { |
| 7340 | return false; |
| 7341 | } |
| 7342 | } |
| 7343 | return true; |
| 7344 | } |
| 7345 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7346 | private CharSequence createConversationTitleFromMessages() { |
| 7347 | ArraySet<CharSequence> names = new ArraySet<>(); |
| 7348 | for (int i = 0; i < mMessages.size(); i++) { |
| 7349 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7350 | Person sender = m.getSenderPerson(); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7351 | if (sender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7352 | names.add(sender.getName()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7353 | } |
| 7354 | } |
| 7355 | SpannableStringBuilder title = new SpannableStringBuilder(); |
| 7356 | int size = names.size(); |
| 7357 | for (int i = 0; i < size; i++) { |
| 7358 | CharSequence name = names.valueAt(i); |
| 7359 | if (!TextUtils.isEmpty(title)) { |
| 7360 | title.append(", "); |
| 7361 | } |
| 7362 | title.append(BidiFormatter.getInstance().unicodeWrap(name)); |
| 7363 | } |
| 7364 | return title; |
| 7365 | } |
| 7366 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7367 | /** |
| 7368 | * @hide |
| 7369 | */ |
| 7370 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7371 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7372 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7373 | true /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7374 | remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1); |
| 7375 | return remoteViews; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7376 | } |
| 7377 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7378 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 7379 | return new TextAppearanceSpan(null, 0, 0, |
| 7380 | ColorStateList.valueOf(color), null); |
| 7381 | } |
| 7382 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7383 | public static final class Message { |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 7384 | /** @hide */ |
| 7385 | public static final String KEY_TEXT = "text"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7386 | static final String KEY_TIMESTAMP = "time"; |
| 7387 | static final String KEY_SENDER = "sender"; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7388 | static final String KEY_SENDER_PERSON = "sender_person"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7389 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 7390 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7391 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7392 | static final String KEY_REMOTE_INPUT_HISTORY = "remote_input_history"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7393 | |
| 7394 | private final CharSequence mText; |
| 7395 | private final long mTimestamp; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7396 | @Nullable |
| 7397 | private final Person mSender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7398 | /** True if this message was generated from the extra |
| 7399 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY} |
| 7400 | */ |
| 7401 | private final boolean mRemoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7402 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7403 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7404 | private String mDataMimeType; |
| 7405 | private Uri mDataUri; |
| 7406 | |
| 7407 | /** |
| 7408 | * Constructor |
| 7409 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7410 | * @param timestamp Time at which the message arrived |
| 7411 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 7412 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 7413 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 7414 | * Should be unique amongst all individuals in the conversation, and should be |
| 7415 | * consistent during re-posts of the notification. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7416 | * |
| 7417 | * @deprecated use {@code Message(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7418 | */ |
| 7419 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7420 | this(text, timestamp, sender == null ? null |
| 7421 | : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7422 | } |
| 7423 | |
| 7424 | /** |
| 7425 | * Constructor |
| 7426 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7427 | * @param timestamp Time at which the message arrived |
| 7428 | * @param sender The {@link Person} who sent the message. |
| 7429 | * Should be <code>null</code> for messages by the current user, in which case |
| 7430 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7431 | * <p> |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7432 | * The person provided should contain an Icon, set with |
| 7433 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7434 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7435 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7436 | * to differentiate between the different users. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7437 | * </p> |
| 7438 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 7439 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7440 | this(text, timestamp, sender, false /* remoteHistory */); |
| 7441 | } |
| 7442 | |
| 7443 | /** |
| 7444 | * Constructor |
| 7445 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7446 | * @param timestamp Time at which the message arrived |
| 7447 | * @param sender The {@link Person} who sent the message. |
| 7448 | * Should be <code>null</code> for messages by the current user, in which case |
| 7449 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7450 | * @param remoteInputHistory True if the messages was generated from the extra |
| 7451 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7452 | * <p> |
| 7453 | * The person provided should contain an Icon, set with |
| 7454 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7455 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7456 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7457 | * to differentiate between the different users. |
| 7458 | * </p> |
| 7459 | * @hide |
| 7460 | */ |
| 7461 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender, |
| 7462 | boolean remoteInputHistory) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7463 | mText = text; |
| 7464 | mTimestamp = timestamp; |
| 7465 | mSender = sender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7466 | mRemoteInputHistory = remoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7467 | } |
| 7468 | |
| 7469 | /** |
| 7470 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 7471 | * where the platform doesn't support the MIME type, the original text provided in the |
| 7472 | * constructor will be used. |
| 7473 | * @param dataMimeType The MIME type of the content. See |
| 7474 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 7475 | * types on Android and Android Wear. |
| 7476 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 7477 | * <p class="note"> |
| 7478 | * <ol> |
| 7479 | * <li>Notification Listeners including the System UI need permission to access the |
| 7480 | * data the Uri points to. The recommended ways to do this are:</li> |
| 7481 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 7482 | * the correct permission to access your provider. The preferred mechanism for |
| 7483 | * providing access is to use per-URI permissions which are temporary and only |
| 7484 | * grant access to the receiving application. An easy way to create a |
| 7485 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 7486 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 7487 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 7488 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 7489 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 7490 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 7491 | * Note that once added to the system MediaStore the content is accessible to any |
| 7492 | * app on the device.</li> |
| 7493 | * </ol> |
| 7494 | * @return this object for method chaining |
| 7495 | */ |
| 7496 | public Message setData(String dataMimeType, Uri dataUri) { |
| 7497 | mDataMimeType = dataMimeType; |
| 7498 | mDataUri = dataUri; |
| 7499 | return this; |
| 7500 | } |
| 7501 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7502 | /** |
| 7503 | * Get the text to be used for this message, or the fallback text if a type and content |
| 7504 | * Uri have been set |
| 7505 | */ |
| 7506 | public CharSequence getText() { |
| 7507 | return mText; |
| 7508 | } |
| 7509 | |
| 7510 | /** |
| 7511 | * Get the time at which this message arrived |
| 7512 | */ |
| 7513 | public long getTimestamp() { |
| 7514 | return mTimestamp; |
| 7515 | } |
| 7516 | |
| 7517 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7518 | * Get the extras Bundle for this message. |
| 7519 | */ |
| 7520 | public Bundle getExtras() { |
| 7521 | return mExtras; |
| 7522 | } |
| 7523 | |
| 7524 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7525 | * 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] | 7526 | * |
| 7527 | * @deprecated use {@link #getSenderPerson()} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7528 | */ |
| 7529 | public CharSequence getSender() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7530 | return mSender == null ? null : mSender.getName(); |
| 7531 | } |
| 7532 | |
| 7533 | /** |
| 7534 | * Get the sender associated with this message. |
| 7535 | */ |
| 7536 | @Nullable |
| 7537 | public Person getSenderPerson() { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7538 | return mSender; |
| 7539 | } |
| 7540 | |
| 7541 | /** |
| 7542 | * Get the MIME type of the data pointed to by the Uri |
| 7543 | */ |
| 7544 | public String getDataMimeType() { |
| 7545 | return mDataMimeType; |
| 7546 | } |
| 7547 | |
| 7548 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 7549 | * 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] | 7550 | * {@see #getText()} is used. |
| 7551 | */ |
| 7552 | public Uri getDataUri() { |
| 7553 | return mDataUri; |
| 7554 | } |
| 7555 | |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7556 | /** |
| 7557 | * @return True if the message was generated from |
| 7558 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7559 | * @hide |
| 7560 | */ |
| 7561 | public boolean isRemoteInputHistory() { |
| 7562 | return mRemoteInputHistory; |
| 7563 | } |
| 7564 | |
Beverly | e98937a | 2018-11-15 10:18:57 -0500 | [diff] [blame] | 7565 | /** |
| 7566 | * @hide |
| 7567 | */ |
| 7568 | @VisibleForTesting |
| 7569 | public Bundle toBundle() { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7570 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7571 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7572 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7573 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7574 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7575 | if (mSender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7576 | // Legacy listeners need this |
| 7577 | bundle.putCharSequence(KEY_SENDER, mSender.getName()); |
| 7578 | bundle.putParcelable(KEY_SENDER_PERSON, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7579 | } |
| 7580 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7581 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7582 | } |
| 7583 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7584 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7585 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7586 | if (mExtras != null) { |
| 7587 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 7588 | } |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7589 | if (mRemoteInputHistory) { |
| 7590 | bundle.putBoolean(KEY_REMOTE_INPUT_HISTORY, mRemoteInputHistory); |
| 7591 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7592 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7593 | } |
| 7594 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7595 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 7596 | Bundle[] bundles = new Bundle[messages.size()]; |
| 7597 | final int N = messages.size(); |
| 7598 | for (int i = 0; i < N; i++) { |
| 7599 | bundles[i] = messages.get(i).toBundle(); |
| 7600 | } |
| 7601 | return bundles; |
| 7602 | } |
| 7603 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7604 | /** |
| 7605 | * @return A list of messages read from the bundles. |
| 7606 | * |
| 7607 | * @hide |
| 7608 | */ |
| 7609 | public static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
| 7610 | if (bundles == null) { |
| 7611 | return new ArrayList<>(); |
| 7612 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7613 | List<Message> messages = new ArrayList<>(bundles.length); |
| 7614 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7615 | if (bundles[i] instanceof Bundle) { |
| 7616 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 7617 | if (message != null) { |
| 7618 | messages.add(message); |
| 7619 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7620 | } |
| 7621 | } |
| 7622 | return messages; |
| 7623 | } |
| 7624 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 7625 | /** |
| 7626 | * @return The message that is stored in the bundle or null if the message couldn't be |
| 7627 | * resolved. |
| 7628 | * |
| 7629 | * @hide |
| 7630 | */ |
| 7631 | @Nullable |
| 7632 | public static Message getMessageFromBundle(Bundle bundle) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7633 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 7634 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7635 | return null; |
| 7636 | } else { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7637 | |
| 7638 | Person senderPerson = bundle.getParcelable(KEY_SENDER_PERSON); |
| 7639 | if (senderPerson == null) { |
| 7640 | // Legacy apps that use compat don't actually provide the sender objects |
| 7641 | // We need to fix the compat version to provide people / use |
| 7642 | // the native api instead |
| 7643 | CharSequence senderName = bundle.getCharSequence(KEY_SENDER); |
| 7644 | if (senderName != null) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7645 | senderPerson = new Person.Builder().setName(senderName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7646 | } |
| 7647 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7648 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7649 | bundle.getLong(KEY_TIMESTAMP), |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7650 | senderPerson, |
| 7651 | bundle.getBoolean(KEY_REMOTE_INPUT_HISTORY, false)); |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7652 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 7653 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7654 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 7655 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7656 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7657 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 7658 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 7659 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7660 | return message; |
| 7661 | } |
| 7662 | } catch (ClassCastException e) { |
| 7663 | return null; |
| 7664 | } |
| 7665 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7666 | } |
| 7667 | } |
| 7668 | |
| 7669 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7670 | * 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] | 7671 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7672 | * 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] | 7673 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7674 | * Notification notif = new Notification.Builder(mContext) |
| 7675 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 7676 | * .setContentText(subject) |
| 7677 | * .setSmallIcon(R.drawable.new_mail) |
| 7678 | * .setLargeIcon(aBitmap) |
| 7679 | * .setStyle(new Notification.InboxStyle() |
| 7680 | * .addLine(str1) |
| 7681 | * .addLine(str2) |
| 7682 | * .setContentTitle("") |
| 7683 | * .setSummaryText("+3 more")) |
| 7684 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7685 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 7686 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7687 | * @see Notification#bigContentView |
| 7688 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7689 | public static class InboxStyle extends Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7690 | |
| 7691 | /** |
| 7692 | * The number of lines of remote input history allowed until we start reducing lines. |
| 7693 | */ |
| 7694 | private static final int NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION = 1; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7695 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 7696 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7697 | public InboxStyle() { |
| 7698 | } |
| 7699 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7700 | /** |
| 7701 | * @deprecated use {@code InboxStyle()}. |
| 7702 | */ |
| 7703 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7704 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7705 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7706 | } |
| 7707 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7708 | /** |
| 7709 | * Overrides ContentTitle in the big form of the template. |
| 7710 | * This defaults to the value passed to setContentTitle(). |
| 7711 | */ |
| 7712 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7713 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7714 | return this; |
| 7715 | } |
| 7716 | |
| 7717 | /** |
| 7718 | * Set the first line of text after the detail section in the big form of the template. |
| 7719 | */ |
| 7720 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7721 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7722 | return this; |
| 7723 | } |
| 7724 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 7725 | /** |
| 7726 | * Append a line to the digest section of the Inbox notification. |
| 7727 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7728 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7729 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7730 | return this; |
| 7731 | } |
| 7732 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7733 | /** |
| 7734 | * @hide |
| 7735 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7736 | public ArrayList<CharSequence> getLines() { |
| 7737 | return mTexts; |
| 7738 | } |
| 7739 | |
| 7740 | /** |
| 7741 | * @hide |
| 7742 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7743 | public void addExtras(Bundle extras) { |
| 7744 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7745 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7746 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 7747 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 7748 | } |
| 7749 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7750 | /** |
| 7751 | * @hide |
| 7752 | */ |
| 7753 | @Override |
| 7754 | protected void restoreFromExtras(Bundle extras) { |
| 7755 | super.restoreFromExtras(extras); |
| 7756 | |
| 7757 | mTexts.clear(); |
| 7758 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 7759 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 7760 | } |
| 7761 | } |
| 7762 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7763 | /** |
| 7764 | * @hide |
| 7765 | */ |
| 7766 | public RemoteViews makeBigContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7767 | StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder).text(null); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7768 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7769 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource(), p, result); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7770 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7771 | 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] | 7772 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7773 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 7774 | // Make sure all rows are gone in case we reuse a view. |
| 7775 | for (int rowId : rowIds) { |
| 7776 | contentView.setViewVisibility(rowId, View.GONE); |
| 7777 | } |
| 7778 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7779 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7780 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7781 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7782 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7783 | int onlyViewId = 0; |
| 7784 | int maxRows = rowIds.length; |
| 7785 | if (mBuilder.mActions.size() > 0) { |
| 7786 | maxRows--; |
| 7787 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7788 | CharSequence[] remoteInputHistory = mBuilder.mN.extras.getCharSequenceArray( |
| 7789 | EXTRA_REMOTE_INPUT_HISTORY); |
| 7790 | if (remoteInputHistory != null |
| 7791 | && remoteInputHistory.length > NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION) { |
| 7792 | // Let's remove some messages to make room for the remote input history. |
| 7793 | // 1 is always able to fit, but let's remove them if they are 2 or 3 |
| 7794 | int numRemoteInputs = Math.min(remoteInputHistory.length, |
| 7795 | MAX_REMOTE_INPUT_HISTORY_LINES); |
| 7796 | int totalNumRows = mTexts.size() + numRemoteInputs |
| 7797 | - NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION; |
| 7798 | if (totalNumRows > maxRows) { |
| 7799 | int overflow = totalNumRows - maxRows; |
| 7800 | if (mTexts.size() > maxRows) { |
| 7801 | // Heuristic: if the Texts don't fit anyway, we'll rather drop the last |
| 7802 | // few messages, even with the remote input |
| 7803 | maxRows -= overflow; |
| 7804 | } else { |
| 7805 | // otherwise we drop the first messages |
| 7806 | i = overflow; |
| 7807 | } |
| 7808 | } |
| 7809 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7810 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7811 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7812 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7813 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 7814 | contentView.setTextViewText(rowIds[i], |
| 7815 | mBuilder.processTextSpans(mBuilder.processLegacyText(str))); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 7816 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i], p); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7817 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7818 | handleInboxImageMargin(contentView, rowIds[i], first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7819 | result.getIconMarginEnd()); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7820 | if (first) { |
| 7821 | onlyViewId = rowIds[i]; |
| 7822 | } else { |
| 7823 | onlyViewId = 0; |
| 7824 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7825 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7826 | } |
| 7827 | i++; |
| 7828 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7829 | if (onlyViewId != 0) { |
| 7830 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 7831 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7832 | R.dimen.notification_text_margin_top); |
| 7833 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 7834 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7835 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7836 | return contentView; |
| 7837 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7838 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7839 | /** |
| 7840 | * @hide |
| 7841 | */ |
| 7842 | @Override |
| 7843 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7844 | if (other == null || getClass() != other.getClass()) { |
| 7845 | return true; |
| 7846 | } |
| 7847 | InboxStyle newS = (InboxStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7848 | |
| 7849 | final ArrayList<CharSequence> myLines = getLines(); |
| 7850 | final ArrayList<CharSequence> newLines = newS.getLines(); |
| 7851 | final int n = myLines.size(); |
| 7852 | if (n != newLines.size()) { |
| 7853 | return true; |
| 7854 | } |
| 7855 | |
| 7856 | for (int i = 0; i < n; i++) { |
| 7857 | if (!Objects.equals( |
| 7858 | String.valueOf(myLines.get(i)), |
| 7859 | String.valueOf(newLines.get(i)))) { |
| 7860 | return true; |
| 7861 | } |
| 7862 | } |
| 7863 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7864 | } |
| 7865 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7866 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7867 | int marginEndValue) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7868 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7869 | if (first) { |
| 7870 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 7871 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 7872 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7873 | if (!hasProgress) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7874 | endMargin = marginEndValue; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7875 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7876 | } |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7877 | contentView.setViewLayoutMarginEnd(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7878 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7879 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7880 | |
| 7881 | /** |
| 7882 | * Notification style for media playback notifications. |
| 7883 | * |
| 7884 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 7885 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 7886 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7887 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 7888 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 7889 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7890 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7891 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 7892 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 7893 | * {@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] | 7894 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7895 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7896 | * Notifications created with MediaStyle will have their category set to |
| 7897 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 7898 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7899 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7900 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 7901 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7902 | * the System UI can identify this as a notification representing an active media session |
| 7903 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 7904 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7905 | * <p> |
| 7906 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 7907 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 7908 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 7909 | * <p> |
| 7910 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7911 | * To use this style with your Notification, feed it to |
| 7912 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7913 | * <pre class="prettyprint"> |
| 7914 | * Notification noti = new Notification.Builder() |
| 7915 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 7916 | * .setContentTitle("Track title") |
| 7917 | * .setContentText("Artist - Album") |
| 7918 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7919 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 7920 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7921 | * .build(); |
| 7922 | * </pre> |
| 7923 | * |
| 7924 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7925 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7926 | */ |
| 7927 | public static class MediaStyle extends Style { |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7928 | // Changing max media buttons requires also changing templates |
| 7929 | // (notification_template_material_media and notification_template_material_big_media). |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7930 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7931 | static final int MAX_MEDIA_BUTTONS = 5; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7932 | @IdRes private static final int[] MEDIA_BUTTON_IDS = { |
| 7933 | R.id.action0, |
| 7934 | R.id.action1, |
| 7935 | R.id.action2, |
| 7936 | R.id.action3, |
| 7937 | R.id.action4, |
| 7938 | }; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7939 | |
| 7940 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7941 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7942 | |
| 7943 | public MediaStyle() { |
| 7944 | } |
| 7945 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7946 | /** |
| 7947 | * @deprecated use {@code MediaStyle()}. |
| 7948 | */ |
| 7949 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7950 | public MediaStyle(Builder builder) { |
| 7951 | setBuilder(builder); |
| 7952 | } |
| 7953 | |
| 7954 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7955 | * 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] | 7956 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7957 | * |
| 7958 | * @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] | 7959 | */ |
| 7960 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 7961 | mActionsToShowInCompact = actions; |
| 7962 | return this; |
| 7963 | } |
| 7964 | |
| 7965 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7966 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 7967 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7968 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7969 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7970 | mToken = token; |
| 7971 | return this; |
| 7972 | } |
| 7973 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7974 | /** |
| 7975 | * @hide |
| 7976 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7977 | @Override |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7978 | @UnsupportedAppUsage |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7979 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7980 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7981 | if (wip.category == null) { |
| 7982 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 7983 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7984 | return wip; |
| 7985 | } |
| 7986 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7987 | /** |
| 7988 | * @hide |
| 7989 | */ |
| 7990 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7991 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7992 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7993 | } |
| 7994 | |
| 7995 | /** |
| 7996 | * @hide |
| 7997 | */ |
| 7998 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7999 | public RemoteViews makeBigContentView() { |
| 8000 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8001 | } |
| 8002 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8003 | /** |
| 8004 | * @hide |
| 8005 | */ |
| 8006 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8007 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8008 | RemoteViews expanded = makeMediaBigContentView(); |
| 8009 | return expanded != null ? expanded : makeMediaContentView(); |
| 8010 | } |
| 8011 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8012 | /** @hide */ |
| 8013 | @Override |
| 8014 | public void addExtras(Bundle extras) { |
| 8015 | super.addExtras(extras); |
| 8016 | |
| 8017 | if (mToken != null) { |
| 8018 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 8019 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 8020 | if (mActionsToShowInCompact != null) { |
| 8021 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 8022 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8023 | } |
| 8024 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8025 | /** |
| 8026 | * @hide |
| 8027 | */ |
| 8028 | @Override |
| 8029 | protected void restoreFromExtras(Bundle extras) { |
| 8030 | super.restoreFromExtras(extras); |
| 8031 | |
| 8032 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 8033 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 8034 | } |
| 8035 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 8036 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 8037 | } |
| 8038 | } |
| 8039 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8040 | /** |
| 8041 | * @hide |
| 8042 | */ |
| 8043 | @Override |
| 8044 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8045 | if (other == null || getClass() != other.getClass()) { |
| 8046 | return true; |
| 8047 | } |
| 8048 | // All fields to compare are on the Notification object |
| 8049 | return false; |
| 8050 | } |
| 8051 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8052 | private void bindMediaActionButton(RemoteViews container, @IdRes int buttonId, |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8053 | Action action, StandardTemplateParams p) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8054 | final boolean tombstone = (action.actionIntent == null); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8055 | container.setViewVisibility(buttonId, View.VISIBLE); |
| 8056 | container.setImageViewIcon(buttonId, action.getIcon()); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 8057 | |
| 8058 | // If the action buttons should not be tinted, then just use the default |
| 8059 | // notification color. Otherwise, just use the passed-in color. |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8060 | Resources resources = mBuilder.mContext.getResources(); |
| 8061 | Configuration currentConfig = resources.getConfiguration(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 8062 | boolean inNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 8063 | == Configuration.UI_MODE_NIGHT_YES; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8064 | int tintColor = mBuilder.shouldTintActionButtons() || mBuilder.isColorized(p) |
| 8065 | ? getActionColor(p) |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 8066 | : ContrastColorUtil.resolveColor(mBuilder.mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 8067 | Notification.COLOR_DEFAULT, inNightMode); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 8068 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8069 | container.setDrawableTint(buttonId, false, tintColor, |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 8070 | PorterDuff.Mode.SRC_ATOP); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8071 | |
| 8072 | final TypedArray typedArray = mBuilder.mContext.obtainStyledAttributes( |
| 8073 | new int[]{ android.R.attr.colorControlHighlight }); |
| 8074 | int rippleAlpha = Color.alpha(typedArray.getColor(0, 0)); |
| 8075 | typedArray.recycle(); |
| 8076 | int rippleColor = Color.argb(rippleAlpha, Color.red(tintColor), Color.green(tintColor), |
| 8077 | Color.blue(tintColor)); |
| 8078 | container.setRippleDrawableColor(buttonId, ColorStateList.valueOf(rippleColor)); |
| 8079 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8080 | if (!tombstone) { |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8081 | container.setOnClickPendingIntent(buttonId, action.actionIntent); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8082 | } |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8083 | container.setContentDescription(buttonId, action.title); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8084 | } |
| 8085 | |
| 8086 | private RemoteViews makeMediaContentView() { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8087 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).fillTextsFrom( |
| 8088 | mBuilder); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8089 | RemoteViews view = mBuilder.applyStandardTemplate( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8090 | R.layout.notification_template_material_media, p, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8091 | null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8092 | |
| 8093 | final int numActions = mBuilder.mActions.size(); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8094 | final int numActionsToShow = mActionsToShowInCompact == null |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8095 | ? 0 |
| 8096 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8097 | if (numActionsToShow > numActions) { |
| 8098 | throw new IllegalArgumentException(String.format( |
| 8099 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 8100 | numActions, numActions - 1)); |
| 8101 | } |
| 8102 | for (int i = 0; i < MAX_MEDIA_BUTTONS_IN_COMPACT; i++) { |
| 8103 | if (i < numActionsToShow) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8104 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8105 | bindMediaActionButton(view, MEDIA_BUTTON_IDS[i], action, p); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8106 | } else { |
| 8107 | view.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8108 | } |
| 8109 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 8110 | handleImage(view); |
| 8111 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8112 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8113 | if (mBuilder.mN.hasLargeIcon()) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8114 | endMargin = R.dimen.notification_media_image_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 8115 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8116 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8117 | return view; |
| 8118 | } |
| 8119 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8120 | private int getActionColor(StandardTemplateParams p) { |
| 8121 | return mBuilder.isColorized(p) ? mBuilder.getPrimaryTextColor(p) |
| 8122 | : mBuilder.resolveContrastColor(p); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8123 | } |
| 8124 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8125 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8126 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8127 | // Dont add an expanded view if there is no more content to be revealed |
| 8128 | int actionsInCompact = mActionsToShowInCompact == null |
| 8129 | ? 0 |
| 8130 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8131 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8132 | return null; |
| 8133 | } |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8134 | StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).fillTextsFrom( |
| 8135 | mBuilder); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8136 | RemoteViews big = mBuilder.applyStandardTemplate( |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8137 | R.layout.notification_template_material_big_media, p , null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8138 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8139 | for (int i = 0; i < MAX_MEDIA_BUTTONS; i++) { |
| 8140 | if (i < actionCount) { |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8141 | bindMediaActionButton(big, MEDIA_BUTTON_IDS[i], mBuilder.mActions.get(i), p); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8142 | } else { |
| 8143 | big.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8144 | } |
| 8145 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8146 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8147 | return big; |
| 8148 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8149 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8150 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8151 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8152 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 8153 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8154 | } |
| 8155 | } |
| 8156 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8157 | /** |
| 8158 | * @hide |
| 8159 | */ |
| 8160 | @Override |
| 8161 | protected boolean hasProgress() { |
| 8162 | return false; |
| 8163 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8164 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8165 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8166 | /** |
| 8167 | * Notification style for custom views that are decorated by the system |
| 8168 | * |
| 8169 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 8170 | * style and still obtain system decorations like the notification header with the expand |
| 8171 | * affordance and actions. |
| 8172 | * |
| 8173 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8174 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8175 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8176 | * corresponding custom views to display. |
| 8177 | * |
| 8178 | * To use this style with your Notification, feed it to |
| 8179 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8180 | * <pre class="prettyprint"> |
| 8181 | * Notification noti = new Notification.Builder() |
| 8182 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8183 | * .setLargeIcon(albumArtBitmap)) |
| 8184 | * .setCustomContentView(contentView); |
| 8185 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 8186 | * .build(); |
| 8187 | * </pre> |
| 8188 | */ |
| 8189 | public static class DecoratedCustomViewStyle extends Style { |
| 8190 | |
| 8191 | public DecoratedCustomViewStyle() { |
| 8192 | } |
| 8193 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8194 | /** |
| 8195 | * @hide |
| 8196 | */ |
| 8197 | public boolean displayCustomViewInline() { |
| 8198 | return true; |
| 8199 | } |
| 8200 | |
| 8201 | /** |
| 8202 | * @hide |
| 8203 | */ |
| 8204 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8205 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8206 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 8207 | } |
| 8208 | |
| 8209 | /** |
| 8210 | * @hide |
| 8211 | */ |
| 8212 | @Override |
| 8213 | public RemoteViews makeBigContentView() { |
| 8214 | return makeDecoratedBigContentView(); |
| 8215 | } |
| 8216 | |
| 8217 | /** |
| 8218 | * @hide |
| 8219 | */ |
| 8220 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8221 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8222 | return makeDecoratedHeadsUpContentView(); |
| 8223 | } |
| 8224 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8225 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 8226 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 8227 | ? mBuilder.mN.contentView |
| 8228 | : mBuilder.mN.headsUpContentView; |
| 8229 | if (mBuilder.mActions.size() == 0) { |
| 8230 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 8231 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8232 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8233 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8234 | mBuilder.getBigBaseLayoutResource(), result); |
| 8235 | buildIntoRemoteViewContent(remoteViews, headsUpContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8236 | return remoteViews; |
| 8237 | } |
| 8238 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8239 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8240 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8241 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8242 | mBuilder.getBaseLayoutResource(), result); |
| 8243 | buildIntoRemoteViewContent(remoteViews, customContent, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8244 | return remoteViews; |
| 8245 | } |
| 8246 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8247 | private RemoteViews makeDecoratedBigContentView() { |
| 8248 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 8249 | ? mBuilder.mN.contentView |
| 8250 | : mBuilder.mN.bigContentView; |
| 8251 | if (mBuilder.mActions.size() == 0) { |
| 8252 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 8253 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8254 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8255 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8256 | mBuilder.getBigBaseLayoutResource(), result); |
| 8257 | buildIntoRemoteViewContent(remoteViews, bigContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8258 | return remoteViews; |
| 8259 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8260 | |
| 8261 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8262 | RemoteViews customContent, TemplateBindResult result) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8263 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8264 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8265 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8266 | customContent = customContent.clone(); |
Anthony Chen | 8f5f358 | 2017-04-11 11:18:37 -0700 | [diff] [blame] | 8267 | remoteViews.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress); |
| 8268 | remoteViews.addView(R.id.notification_main_column, customContent, 0 /* index */); |
Selim Cinek | fc8073c | 2017-08-16 17:50:20 -0700 | [diff] [blame] | 8269 | remoteViews.setReapplyDisallowed(); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8270 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8271 | // also update the end margin if there is an image |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8272 | Resources resources = mBuilder.mContext.getResources(); |
| 8273 | int endMargin = resources.getDimensionPixelSize( |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 8274 | R.dimen.notification_content_margin_end) + result.getIconMarginEnd(); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8275 | remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8276 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8277 | |
| 8278 | /** |
| 8279 | * @hide |
| 8280 | */ |
| 8281 | @Override |
| 8282 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8283 | if (other == null || getClass() != other.getClass()) { |
| 8284 | return true; |
| 8285 | } |
| 8286 | // Comparison done for all custom RemoteViews, independent of style |
| 8287 | return false; |
| 8288 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8289 | } |
| 8290 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8291 | /** |
| 8292 | * Notification style for media custom views that are decorated by the system |
| 8293 | * |
| 8294 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 8295 | * this style and still obtain system decorations like the notification header with the expand |
| 8296 | * affordance and actions. |
| 8297 | * |
| 8298 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8299 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8300 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8301 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8302 | * <p> |
| 8303 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 8304 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 8305 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8306 | * To use this style with your Notification, feed it to |
| 8307 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8308 | * <pre class="prettyprint"> |
| 8309 | * Notification noti = new Notification.Builder() |
| 8310 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8311 | * .setLargeIcon(albumArtBitmap)) |
| 8312 | * .setCustomContentView(contentView); |
| 8313 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 8314 | * .setMediaSession(mySession)) |
| 8315 | * .build(); |
| 8316 | * </pre> |
| 8317 | * |
| 8318 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 8319 | * @see android.app.Notification.MediaStyle |
| 8320 | */ |
| 8321 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 8322 | |
| 8323 | public DecoratedMediaCustomViewStyle() { |
| 8324 | } |
| 8325 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8326 | /** |
| 8327 | * @hide |
| 8328 | */ |
| 8329 | public boolean displayCustomViewInline() { |
| 8330 | return true; |
| 8331 | } |
| 8332 | |
| 8333 | /** |
| 8334 | * @hide |
| 8335 | */ |
| 8336 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8337 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 8338 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8339 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8340 | mBuilder.mN.contentView); |
| 8341 | } |
| 8342 | |
| 8343 | /** |
| 8344 | * @hide |
| 8345 | */ |
| 8346 | @Override |
| 8347 | public RemoteViews makeBigContentView() { |
| 8348 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 8349 | ? mBuilder.mN.bigContentView |
| 8350 | : mBuilder.mN.contentView; |
| 8351 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8352 | } |
| 8353 | |
| 8354 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 8355 | RemoteViews remoteViews = super.makeBigContentView(); |
| 8356 | if (remoteViews != null) { |
| 8357 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 8358 | customRemoteView); |
| 8359 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8360 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8361 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8362 | customRemoteView); |
| 8363 | } else { |
| 8364 | return null; |
| 8365 | } |
| 8366 | } |
| 8367 | |
| 8368 | /** |
| 8369 | * @hide |
| 8370 | */ |
| 8371 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8372 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8373 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 8374 | ? mBuilder.mN.headsUpContentView |
| 8375 | : mBuilder.mN.contentView; |
| 8376 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8377 | } |
| 8378 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8379 | /** |
| 8380 | * @hide |
| 8381 | */ |
| 8382 | @Override |
| 8383 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8384 | if (other == null || getClass() != other.getClass()) { |
| 8385 | return true; |
| 8386 | } |
| 8387 | // Comparison done for all custom RemoteViews, independent of style |
| 8388 | return false; |
| 8389 | } |
| 8390 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8391 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 8392 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8393 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8394 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8395 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8396 | customContent = customContent.clone(); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 8397 | customContent.overrideTextColors(mBuilder.getPrimaryTextColor(mBuilder.mParams)); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8398 | remoteViews.removeAllViews(id); |
| 8399 | remoteViews.addView(id, customContent); |
Selim Cinek | fc8073c | 2017-08-16 17:50:20 -0700 | [diff] [blame] | 8400 | remoteViews.setReapplyDisallowed(); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8401 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8402 | return remoteViews; |
| 8403 | } |
| 8404 | } |
| 8405 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8406 | // When adding a new Style subclass here, don't forget to update |
| 8407 | // Builder.getNotificationStyleClass. |
| 8408 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8409 | /** |
| 8410 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 8411 | * metadata or change options on a notification builder. |
| 8412 | */ |
| 8413 | public interface Extender { |
| 8414 | /** |
| 8415 | * Apply this extender to a notification builder. |
| 8416 | * @param builder the builder to be modified. |
| 8417 | * @return the build object for chaining. |
| 8418 | */ |
| 8419 | public Builder extend(Builder builder); |
| 8420 | } |
| 8421 | |
| 8422 | /** |
| 8423 | * Helper class to add wearable extensions to notifications. |
| 8424 | * <p class="note"> See |
| 8425 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 8426 | * for Android Wear</a> for more information on how to use this class. |
| 8427 | * <p> |
| 8428 | * To create a notification with wearable extensions: |
| 8429 | * <ol> |
| 8430 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 8431 | * properties. |
| 8432 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 8433 | * <li>Set wearable-specific properties using the |
| 8434 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 8435 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 8436 | * notification. |
| 8437 | * <li>Post the notification to the notification system with the |
| 8438 | * {@code NotificationManager.notify(...)} methods. |
| 8439 | * </ol> |
| 8440 | * |
| 8441 | * <pre class="prettyprint"> |
| 8442 | * Notification notif = new Notification.Builder(mContext) |
| 8443 | * .setContentTitle("New mail from " + sender.toString()) |
| 8444 | * .setContentText(subject) |
| 8445 | * .setSmallIcon(R.drawable.new_mail) |
| 8446 | * .extend(new Notification.WearableExtender() |
| 8447 | * .setContentIcon(R.drawable.new_mail)) |
| 8448 | * .build(); |
| 8449 | * NotificationManager notificationManger = |
| 8450 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 8451 | * notificationManger.notify(0, notif);</pre> |
| 8452 | * |
| 8453 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 8454 | * {@code WearableExtender(Notification)} constructor, |
| 8455 | * and then using the {@code get} methods to access values. |
| 8456 | * |
| 8457 | * <pre class="prettyprint"> |
| 8458 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 8459 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8460 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8461 | */ |
| 8462 | public static final class WearableExtender implements Extender { |
| 8463 | /** |
| 8464 | * Sentinel value for an action index that is unset. |
| 8465 | */ |
| 8466 | public static final int UNSET_ACTION_INDEX = -1; |
| 8467 | |
| 8468 | /** |
| 8469 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 8470 | * default sizing. |
| 8471 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 8472 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8473 | * on their content. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8474 | * |
| 8475 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8476 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8477 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8478 | public static final int SIZE_DEFAULT = 0; |
| 8479 | |
| 8480 | /** |
| 8481 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8482 | * with an extra small size. |
| 8483 | * <p>This value is only applicable for custom display notifications created using |
| 8484 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8485 | * |
| 8486 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8487 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8488 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8489 | public static final int SIZE_XSMALL = 1; |
| 8490 | |
| 8491 | /** |
| 8492 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8493 | * with a small size. |
| 8494 | * <p>This value is only applicable for custom display notifications created using |
| 8495 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8496 | * |
| 8497 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8498 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8499 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8500 | public static final int SIZE_SMALL = 2; |
| 8501 | |
| 8502 | /** |
| 8503 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8504 | * with a medium size. |
| 8505 | * <p>This value is only applicable for custom display notifications created using |
| 8506 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8507 | * |
| 8508 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8509 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8510 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8511 | public static final int SIZE_MEDIUM = 3; |
| 8512 | |
| 8513 | /** |
| 8514 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8515 | * with a large size. |
| 8516 | * <p>This value is only applicable for custom display notifications created using |
| 8517 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8518 | * |
| 8519 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8520 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8521 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8522 | public static final int SIZE_LARGE = 4; |
| 8523 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8524 | /** |
| 8525 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8526 | * full screen. |
| 8527 | * <p>This value is only applicable for custom display notifications created using |
| 8528 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8529 | * |
| 8530 | * @deprecated Display intents are no longer supported. |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8531 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8532 | @Deprecated |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8533 | public static final int SIZE_FULL_SCREEN = 5; |
| 8534 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8535 | /** |
| 8536 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 8537 | * short amount of time when this notification is displayed on the screen. This |
| 8538 | * is the default value. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8539 | * |
| 8540 | * @deprecated This feature is no longer supported. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8541 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8542 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8543 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 8544 | |
| 8545 | /** |
| 8546 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 8547 | * 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] | 8548 | * |
| 8549 | * @deprecated This feature is no longer supported. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8550 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8551 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8552 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 8553 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8554 | /** Notification extra which contains wearable extensions */ |
| 8555 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 8556 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 8557 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8558 | private static final String KEY_ACTIONS = "actions"; |
| 8559 | private static final String KEY_FLAGS = "flags"; |
| 8560 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 8561 | private static final String KEY_PAGES = "pages"; |
| 8562 | private static final String KEY_BACKGROUND = "background"; |
| 8563 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 8564 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 8565 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 8566 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 8567 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 8568 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8569 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8570 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8571 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8572 | |
| 8573 | // Flags bitwise-ored to mFlags |
| 8574 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 8575 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 8576 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 8577 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8578 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 8579 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8580 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8581 | |
| 8582 | // Default value for flags integer |
| 8583 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 8584 | |
| 8585 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 8586 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 8587 | |
| 8588 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 8589 | private int mFlags = DEFAULT_FLAGS; |
| 8590 | private PendingIntent mDisplayIntent; |
| 8591 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 8592 | private Bitmap mBackground; |
| 8593 | private int mContentIcon; |
| 8594 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 8595 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 8596 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 8597 | private int mCustomContentHeight; |
| 8598 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8599 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8600 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8601 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8602 | |
| 8603 | /** |
| 8604 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 8605 | * options. |
| 8606 | */ |
| 8607 | public WearableExtender() { |
| 8608 | } |
| 8609 | |
| 8610 | public WearableExtender(Notification notif) { |
| 8611 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 8612 | if (wearableBundle != null) { |
| 8613 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 8614 | if (actions != null) { |
| 8615 | mActions.addAll(actions); |
| 8616 | } |
| 8617 | |
| 8618 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 8619 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 8620 | |
| 8621 | Notification[] pages = getNotificationArrayFromBundle( |
| 8622 | wearableBundle, KEY_PAGES); |
| 8623 | if (pages != null) { |
| 8624 | Collections.addAll(mPages, pages); |
| 8625 | } |
| 8626 | |
| 8627 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 8628 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 8629 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 8630 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 8631 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 8632 | UNSET_ACTION_INDEX); |
| 8633 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 8634 | SIZE_DEFAULT); |
| 8635 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 8636 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8637 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8638 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8639 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8640 | } |
| 8641 | } |
| 8642 | |
| 8643 | /** |
| 8644 | * Apply wearable extensions to a notification that is being built. This is typically |
| 8645 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 8646 | * {@link android.app.Notification.Builder}. |
| 8647 | */ |
| 8648 | @Override |
| 8649 | public Notification.Builder extend(Notification.Builder builder) { |
| 8650 | Bundle wearableBundle = new Bundle(); |
| 8651 | |
| 8652 | if (!mActions.isEmpty()) { |
| 8653 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 8654 | } |
| 8655 | if (mFlags != DEFAULT_FLAGS) { |
| 8656 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 8657 | } |
| 8658 | if (mDisplayIntent != null) { |
| 8659 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 8660 | } |
| 8661 | if (!mPages.isEmpty()) { |
| 8662 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 8663 | new Notification[mPages.size()])); |
| 8664 | } |
| 8665 | if (mBackground != null) { |
| 8666 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 8667 | } |
| 8668 | if (mContentIcon != 0) { |
| 8669 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 8670 | } |
| 8671 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 8672 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 8673 | } |
| 8674 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 8675 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 8676 | mContentActionIndex); |
| 8677 | } |
| 8678 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 8679 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 8680 | } |
| 8681 | if (mCustomContentHeight != 0) { |
| 8682 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 8683 | } |
| 8684 | if (mGravity != DEFAULT_GRAVITY) { |
| 8685 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 8686 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8687 | if (mHintScreenTimeout != 0) { |
| 8688 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 8689 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8690 | if (mDismissalId != null) { |
| 8691 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 8692 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8693 | if (mBridgeTag != null) { |
| 8694 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 8695 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8696 | |
| 8697 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 8698 | return builder; |
| 8699 | } |
| 8700 | |
| 8701 | @Override |
| 8702 | public WearableExtender clone() { |
| 8703 | WearableExtender that = new WearableExtender(); |
| 8704 | that.mActions = new ArrayList<Action>(this.mActions); |
| 8705 | that.mFlags = this.mFlags; |
| 8706 | that.mDisplayIntent = this.mDisplayIntent; |
| 8707 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 8708 | that.mBackground = this.mBackground; |
| 8709 | that.mContentIcon = this.mContentIcon; |
| 8710 | that.mContentIconGravity = this.mContentIconGravity; |
| 8711 | that.mContentActionIndex = this.mContentActionIndex; |
| 8712 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 8713 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 8714 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8715 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8716 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8717 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8718 | return that; |
| 8719 | } |
| 8720 | |
| 8721 | /** |
| 8722 | * Add a wearable action to this notification. |
| 8723 | * |
| 8724 | * <p>When wearable actions are added using this method, the set of actions that |
| 8725 | * show on a wearable device splits from devices that only show actions added |
| 8726 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 8727 | * of which actions display on different devices. |
| 8728 | * |
| 8729 | * @param action the action to add to this notification |
| 8730 | * @return this object for method chaining |
| 8731 | * @see android.app.Notification.Action |
| 8732 | */ |
| 8733 | public WearableExtender addAction(Action action) { |
| 8734 | mActions.add(action); |
| 8735 | return this; |
| 8736 | } |
| 8737 | |
| 8738 | /** |
| 8739 | * Adds wearable actions to this notification. |
| 8740 | * |
| 8741 | * <p>When wearable actions are added using this method, the set of actions that |
| 8742 | * show on a wearable device splits from devices that only show actions added |
| 8743 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 8744 | * of which actions display on different devices. |
| 8745 | * |
| 8746 | * @param actions the actions to add to this notification |
| 8747 | * @return this object for method chaining |
| 8748 | * @see android.app.Notification.Action |
| 8749 | */ |
| 8750 | public WearableExtender addActions(List<Action> actions) { |
| 8751 | mActions.addAll(actions); |
| 8752 | return this; |
| 8753 | } |
| 8754 | |
| 8755 | /** |
| 8756 | * Clear all wearable actions present on this builder. |
| 8757 | * @return this object for method chaining. |
| 8758 | * @see #addAction |
| 8759 | */ |
| 8760 | public WearableExtender clearActions() { |
| 8761 | mActions.clear(); |
| 8762 | return this; |
| 8763 | } |
| 8764 | |
| 8765 | /** |
| 8766 | * Get the wearable actions present on this notification. |
| 8767 | */ |
| 8768 | public List<Action> getActions() { |
| 8769 | return mActions; |
| 8770 | } |
| 8771 | |
| 8772 | /** |
| 8773 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8774 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 8775 | * |
| 8776 | * <pre class="prettyprint"> |
| 8777 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 8778 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 8779 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 8780 | * Notification notif = new Notification.Builder(context) |
| 8781 | * .extend(new Notification.WearableExtender() |
| 8782 | * .setDisplayIntent(displayPendingIntent) |
| 8783 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 8784 | * .build();</pre> |
| 8785 | * |
| 8786 | * <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] | 8787 | * should have an empty task affinity. It is also recommended to use the device |
| 8788 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8789 | * |
| 8790 | * <p>Example AndroidManifest.xml entry: |
| 8791 | * <pre class="prettyprint"> |
| 8792 | * <activity android:name="com.example.MyDisplayActivity" |
| 8793 | * android:exported="true" |
| 8794 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 8795 | * android:taskAffinity="" |
| 8796 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8797 | * |
| 8798 | * @param intent the {@link PendingIntent} for an activity |
| 8799 | * @return this object for method chaining |
| 8800 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8801 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8802 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8803 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8804 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 8805 | mDisplayIntent = intent; |
| 8806 | return this; |
| 8807 | } |
| 8808 | |
| 8809 | /** |
| 8810 | * Get the intent to launch inside of an activity view when displaying this |
| 8811 | * notification. This {@code PendingIntent} should be for an activity. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8812 | * |
| 8813 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8814 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8815 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8816 | public PendingIntent getDisplayIntent() { |
| 8817 | return mDisplayIntent; |
| 8818 | } |
| 8819 | |
| 8820 | /** |
| 8821 | * Add an additional page of content to display with this notification. The current |
| 8822 | * notification forms the first page, and pages added using this function form |
| 8823 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8824 | * sections. |
| 8825 | * |
| 8826 | * @param page the notification to add as another page |
| 8827 | * @return this object for method chaining |
| 8828 | * @see android.app.Notification.WearableExtender#getPages |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8829 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8830 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8831 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8832 | public WearableExtender addPage(Notification page) { |
| 8833 | mPages.add(page); |
| 8834 | return this; |
| 8835 | } |
| 8836 | |
| 8837 | /** |
| 8838 | * Add additional pages of content to display with this notification. The current |
| 8839 | * notification forms the first page, and pages added using this function form |
| 8840 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8841 | * sections. |
| 8842 | * |
| 8843 | * @param pages a list of notifications |
| 8844 | * @return this object for method chaining |
| 8845 | * @see android.app.Notification.WearableExtender#getPages |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8846 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8847 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8848 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8849 | public WearableExtender addPages(List<Notification> pages) { |
| 8850 | mPages.addAll(pages); |
| 8851 | return this; |
| 8852 | } |
| 8853 | |
| 8854 | /** |
| 8855 | * Clear all additional pages present on this builder. |
| 8856 | * @return this object for method chaining. |
| 8857 | * @see #addPage |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8858 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8859 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8860 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8861 | public WearableExtender clearPages() { |
| 8862 | mPages.clear(); |
| 8863 | return this; |
| 8864 | } |
| 8865 | |
| 8866 | /** |
| 8867 | * Get the array of additional pages of content for displaying this notification. The |
| 8868 | * current notification forms the first page, and elements within this array form |
| 8869 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8870 | * sections. |
| 8871 | * @return the pages for this notification |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8872 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8873 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8874 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8875 | public List<Notification> getPages() { |
| 8876 | return mPages; |
| 8877 | } |
| 8878 | |
| 8879 | /** |
| 8880 | * Set a background image to be displayed behind the notification content. |
| 8881 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 8882 | * will work with any notification style. |
| 8883 | * |
| 8884 | * @param background the background bitmap |
| 8885 | * @return this object for method chaining |
| 8886 | * @see android.app.Notification.WearableExtender#getBackground |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8887 | * @deprecated Background images 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 WearableExtender setBackground(Bitmap background) { |
| 8891 | mBackground = background; |
| 8892 | return this; |
| 8893 | } |
| 8894 | |
| 8895 | /** |
| 8896 | * Get a background image to be displayed behind the notification content. |
| 8897 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 8898 | * will work with any notification style. |
| 8899 | * |
| 8900 | * @return the background image |
| 8901 | * @see android.app.Notification.WearableExtender#setBackground |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8902 | * @deprecated Background images are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8903 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8904 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8905 | public Bitmap getBackground() { |
| 8906 | return mBackground; |
| 8907 | } |
| 8908 | |
| 8909 | /** |
| 8910 | * Set an icon that goes with the content of this notification. |
| 8911 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8912 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8913 | public WearableExtender setContentIcon(int icon) { |
| 8914 | mContentIcon = icon; |
| 8915 | return this; |
| 8916 | } |
| 8917 | |
| 8918 | /** |
| 8919 | * Get an icon that goes with the content of this notification. |
| 8920 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8921 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8922 | public int getContentIcon() { |
| 8923 | return mContentIcon; |
| 8924 | } |
| 8925 | |
| 8926 | /** |
| 8927 | * Set the gravity that the content icon should have within the notification display. |
| 8928 | * Supported values include {@link android.view.Gravity#START} and |
| 8929 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 8930 | * @see #setContentIcon |
| 8931 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8932 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8933 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 8934 | mContentIconGravity = contentIconGravity; |
| 8935 | return this; |
| 8936 | } |
| 8937 | |
| 8938 | /** |
| 8939 | * Get the gravity that the content icon should have within the notification display. |
| 8940 | * Supported values include {@link android.view.Gravity#START} and |
| 8941 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 8942 | * @see #getContentIcon |
| 8943 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8944 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8945 | public int getContentIconGravity() { |
| 8946 | return mContentIconGravity; |
| 8947 | } |
| 8948 | |
| 8949 | /** |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8950 | * Set an action from this notification's actions as the primary action. If the action has a |
| 8951 | * {@link RemoteInput} associated with it, shortcuts to the options for that input are shown |
| 8952 | * directly on the notification. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8953 | * |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8954 | * @param actionIndex The index of the primary action. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8955 | * If wearable actions were added to the main notification, this index |
| 8956 | * will apply to that list, otherwise it will apply to the regular |
| 8957 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8958 | */ |
| 8959 | public WearableExtender setContentAction(int actionIndex) { |
| 8960 | mContentActionIndex = actionIndex; |
| 8961 | return this; |
| 8962 | } |
| 8963 | |
| 8964 | /** |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8965 | * Get the index of the notification action, if any, that was specified as the primary |
| 8966 | * action. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8967 | * |
| 8968 | * <p>If wearable specific actions were added to the main notification, this index will |
| 8969 | * 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] | 8970 | * |
| 8971 | * @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] | 8972 | */ |
| 8973 | public int getContentAction() { |
| 8974 | return mContentActionIndex; |
| 8975 | } |
| 8976 | |
| 8977 | /** |
| 8978 | * Set the gravity that this notification should have within the available viewport space. |
| 8979 | * Supported values include {@link android.view.Gravity#TOP}, |
| 8980 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 8981 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 8982 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8983 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8984 | public WearableExtender setGravity(int gravity) { |
| 8985 | mGravity = gravity; |
| 8986 | return this; |
| 8987 | } |
| 8988 | |
| 8989 | /** |
| 8990 | * Get the gravity that this notification should have within the available viewport space. |
| 8991 | * Supported values include {@link android.view.Gravity#TOP}, |
| 8992 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 8993 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 8994 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8995 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8996 | public int getGravity() { |
| 8997 | return mGravity; |
| 8998 | } |
| 8999 | |
| 9000 | /** |
| 9001 | * Set the custom size preset for the display of this notification out of the available |
| 9002 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 9003 | * {@link #SIZE_LARGE}. |
| 9004 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 9005 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 9006 | * documentation for the preset in question. See also |
| 9007 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 9008 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9009 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9010 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 9011 | mCustomSizePreset = sizePreset; |
| 9012 | return this; |
| 9013 | } |
| 9014 | |
| 9015 | /** |
| 9016 | * Get the custom size preset for the display of this notification out of the available |
| 9017 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 9018 | * {@link #SIZE_LARGE}. |
| 9019 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 9020 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 9021 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 9022 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9023 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9024 | public int getCustomSizePreset() { |
| 9025 | return mCustomSizePreset; |
| 9026 | } |
| 9027 | |
| 9028 | /** |
| 9029 | * Set the custom height in pixels for the display of this notification's content. |
| 9030 | * <p>This option is only available for custom display notifications created |
| 9031 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 9032 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 9033 | * {@link #getCustomContentHeight}. |
| 9034 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9035 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9036 | public WearableExtender setCustomContentHeight(int height) { |
| 9037 | mCustomContentHeight = height; |
| 9038 | return this; |
| 9039 | } |
| 9040 | |
| 9041 | /** |
| 9042 | * Get the custom height in pixels for the display of this notification's content. |
| 9043 | * <p>This option is only available for custom display notifications created |
| 9044 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 9045 | * {@link #setCustomContentHeight}. |
| 9046 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9047 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9048 | public int getCustomContentHeight() { |
| 9049 | return mCustomContentHeight; |
| 9050 | } |
| 9051 | |
| 9052 | /** |
| 9053 | * Set whether the scrolling position for the contents of this notification should start |
| 9054 | * at the bottom of the contents instead of the top when the contents are too long to |
| 9055 | * display within the screen. Default is false (start scroll at the top). |
| 9056 | */ |
| 9057 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 9058 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 9059 | return this; |
| 9060 | } |
| 9061 | |
| 9062 | /** |
| 9063 | * Get whether the scrolling position for the contents of this notification should start |
| 9064 | * at the bottom of the contents instead of the top when the contents are too long to |
| 9065 | * display within the screen. Default is false (start scroll at the top). |
| 9066 | */ |
| 9067 | public boolean getStartScrollBottom() { |
| 9068 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 9069 | } |
| 9070 | |
| 9071 | /** |
| 9072 | * Set whether the content intent is available when the wearable device is not connected |
| 9073 | * to a companion device. The user can still trigger this intent when the wearable device |
| 9074 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 9075 | * Defaults to true. |
| 9076 | */ |
| 9077 | public WearableExtender setContentIntentAvailableOffline( |
| 9078 | boolean contentIntentAvailableOffline) { |
| 9079 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 9080 | return this; |
| 9081 | } |
| 9082 | |
| 9083 | /** |
| 9084 | * Get whether the content intent is available when the wearable device is not connected |
| 9085 | * to a companion device. The user can still trigger this intent when the wearable device |
| 9086 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 9087 | * Defaults to true. |
| 9088 | */ |
| 9089 | public boolean getContentIntentAvailableOffline() { |
| 9090 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 9091 | } |
| 9092 | |
| 9093 | /** |
| 9094 | * Set a hint that this notification's icon should not be displayed. |
| 9095 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 9096 | * @return this object for method chaining |
| 9097 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9098 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9099 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 9100 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 9101 | return this; |
| 9102 | } |
| 9103 | |
| 9104 | /** |
| 9105 | * Get a hint that this notification's icon should not be displayed. |
| 9106 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 9107 | * The default value is {@code false} if this was never set. |
| 9108 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9109 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9110 | public boolean getHintHideIcon() { |
| 9111 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 9112 | } |
| 9113 | |
| 9114 | /** |
| 9115 | * Set a visual hint that only the background image of this notification should be |
| 9116 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 9117 | * to sub-pages added using {@link #addPage}. |
| 9118 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9119 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9120 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 9121 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 9122 | return this; |
| 9123 | } |
| 9124 | |
| 9125 | /** |
| 9126 | * Get a visual hint that only the background image of this notification should be |
| 9127 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 9128 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 9129 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9130 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9131 | public boolean getHintShowBackgroundOnly() { |
| 9132 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 9133 | } |
| 9134 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9135 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 9136 | * Set a hint that this notification's background should not be clipped if possible, |
| 9137 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 9138 | * 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] | 9139 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 9140 | * @return this object for method chaining |
| 9141 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9142 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9143 | public WearableExtender setHintAvoidBackgroundClipping( |
| 9144 | boolean hintAvoidBackgroundClipping) { |
| 9145 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 9146 | return this; |
| 9147 | } |
| 9148 | |
| 9149 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 9150 | * Get a hint that this notification's background should not be clipped if possible, |
| 9151 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 9152 | * 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] | 9153 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 9154 | * otherwise. The default value is {@code false} if this was never set. |
| 9155 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9156 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9157 | public boolean getHintAvoidBackgroundClipping() { |
| 9158 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 9159 | } |
| 9160 | |
| 9161 | /** |
| 9162 | * Set a hint that the screen should remain on for at least this duration when |
| 9163 | * this notification is displayed on the screen. |
| 9164 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 9165 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 9166 | * @return this object for method chaining |
| 9167 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9168 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9169 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 9170 | mHintScreenTimeout = timeout; |
| 9171 | return this; |
| 9172 | } |
| 9173 | |
| 9174 | /** |
| 9175 | * Get the duration, in milliseconds, that the screen should remain on for |
| 9176 | * when this notification is displayed. |
| 9177 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 9178 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 9179 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9180 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9181 | public int getHintScreenTimeout() { |
| 9182 | return mHintScreenTimeout; |
| 9183 | } |
| 9184 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9185 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9186 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 9187 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 9188 | * qr codes, as well as other simple black-and-white tickets. |
| 9189 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 9190 | * @return this object for method chaining |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9191 | * @deprecated This feature is no longer supported. |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9192 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9193 | @Deprecated |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9194 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 9195 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 9196 | return this; |
| 9197 | } |
| 9198 | |
| 9199 | /** |
| 9200 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 9201 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 9202 | * qr codes, as well as other simple black-and-white tickets. |
| 9203 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 9204 | * otherwise. The default value is {@code false} if this was never set. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9205 | * @deprecated This feature is no longer supported. |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9206 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9207 | @Deprecated |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9208 | public boolean getHintAmbientBigPicture() { |
| 9209 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 9210 | } |
| 9211 | |
| 9212 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9213 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 9214 | * directly, telling the platform that it can generate the appropriate transitions. |
| 9215 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 9216 | * an activity and transitions should be generated, false otherwise. |
| 9217 | * @return this object for method chaining |
| 9218 | */ |
| 9219 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 9220 | boolean hintContentIntentLaunchesActivity) { |
| 9221 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 9222 | return this; |
| 9223 | } |
| 9224 | |
| 9225 | /** |
| 9226 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 9227 | * directly, telling the platform that it can generate the appropriate transitions |
| 9228 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 9229 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 9230 | */ |
| 9231 | public boolean getHintContentIntentLaunchesActivity() { |
| 9232 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 9233 | } |
| 9234 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9235 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9236 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 9237 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 9238 | * 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] | 9239 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9240 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9241 | * @param dismissalId the dismissal id of the notification. |
| 9242 | * @return this object for method chaining |
| 9243 | */ |
| 9244 | public WearableExtender setDismissalId(String dismissalId) { |
| 9245 | mDismissalId = dismissalId; |
| 9246 | return this; |
| 9247 | } |
| 9248 | |
| 9249 | /** |
| 9250 | * Returns the dismissal id of the notification. |
| 9251 | * @return the dismissal id of the notification or null if it has not been set. |
| 9252 | */ |
| 9253 | public String getDismissalId() { |
| 9254 | return mDismissalId; |
| 9255 | } |
| 9256 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9257 | /** |
| 9258 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 9259 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 9260 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 9261 | * Features to Notifications</a> for more information. |
| 9262 | * @param bridgeTag the bridge tag of the notification. |
| 9263 | * @return this object for method chaining |
| 9264 | */ |
| 9265 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 9266 | mBridgeTag = bridgeTag; |
| 9267 | return this; |
| 9268 | } |
| 9269 | |
| 9270 | /** |
| 9271 | * Returns the bridge tag of the notification. |
| 9272 | * @return the bridge tag or null if not present. |
| 9273 | */ |
| 9274 | public String getBridgeTag() { |
| 9275 | return mBridgeTag; |
| 9276 | } |
| 9277 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9278 | private void setFlag(int mask, boolean value) { |
| 9279 | if (value) { |
| 9280 | mFlags |= mask; |
| 9281 | } else { |
| 9282 | mFlags &= ~mask; |
| 9283 | } |
| 9284 | } |
| 9285 | } |
| 9286 | |
| 9287 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9288 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 9289 | * with car extensions: |
| 9290 | * |
| 9291 | * <ol> |
| 9292 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 9293 | * properties. |
| 9294 | * <li>Create a {@link CarExtender}. |
| 9295 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 9296 | * {@link CarExtender}. |
| 9297 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9298 | * to apply the extensions to a notification. |
| 9299 | * </ol> |
| 9300 | * |
| 9301 | * <pre class="prettyprint"> |
| 9302 | * Notification notification = new Notification.Builder(context) |
| 9303 | * ... |
| 9304 | * .extend(new CarExtender() |
| 9305 | * .set*(...)) |
| 9306 | * .build(); |
| 9307 | * </pre> |
| 9308 | * |
| 9309 | * <p>Car extensions can be accessed on an existing notification by using the |
| 9310 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 9311 | * to access values. |
| 9312 | */ |
| 9313 | public static final class CarExtender implements Extender { |
| 9314 | private static final String TAG = "CarExtender"; |
| 9315 | |
| 9316 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 9317 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 9318 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 9319 | private static final String EXTRA_COLOR = "app_color"; |
| 9320 | |
| 9321 | private Bitmap mLargeIcon; |
| 9322 | private UnreadConversation mUnreadConversation; |
| 9323 | private int mColor = Notification.COLOR_DEFAULT; |
| 9324 | |
| 9325 | /** |
| 9326 | * Create a {@link CarExtender} with default options. |
| 9327 | */ |
| 9328 | public CarExtender() { |
| 9329 | } |
| 9330 | |
| 9331 | /** |
| 9332 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 9333 | * |
| 9334 | * @param notif The notification from which to copy options. |
| 9335 | */ |
| 9336 | public CarExtender(Notification notif) { |
| 9337 | Bundle carBundle = notif.extras == null ? |
| 9338 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 9339 | if (carBundle != null) { |
| 9340 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 9341 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 9342 | |
| 9343 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 9344 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 9345 | } |
| 9346 | } |
| 9347 | |
| 9348 | /** |
| 9349 | * Apply car extensions to a notification that is being built. This is typically called by |
| 9350 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9351 | * method of {@link Notification.Builder}. |
| 9352 | */ |
| 9353 | @Override |
| 9354 | public Notification.Builder extend(Notification.Builder builder) { |
| 9355 | Bundle carExtensions = new Bundle(); |
| 9356 | |
| 9357 | if (mLargeIcon != null) { |
| 9358 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 9359 | } |
| 9360 | if (mColor != Notification.COLOR_DEFAULT) { |
| 9361 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 9362 | } |
| 9363 | |
| 9364 | if (mUnreadConversation != null) { |
| 9365 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 9366 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 9367 | } |
| 9368 | |
| 9369 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 9370 | return builder; |
| 9371 | } |
| 9372 | |
| 9373 | /** |
| 9374 | * Sets the accent color to use when Android Auto presents the notification. |
| 9375 | * |
| 9376 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 9377 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 9378 | * automotive setting. This method can be used to override the color provided in the |
| 9379 | * notification in such a situation. |
| 9380 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9381 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9382 | mColor = color; |
| 9383 | return this; |
| 9384 | } |
| 9385 | |
| 9386 | /** |
| 9387 | * Gets the accent color. |
| 9388 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 9389 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9390 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9391 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9392 | public int getColor() { |
| 9393 | return mColor; |
| 9394 | } |
| 9395 | |
| 9396 | /** |
| 9397 | * Sets the large icon of the car notification. |
| 9398 | * |
| 9399 | * If no large icon is set in the extender, Android Auto will display the icon |
| 9400 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 9401 | * |
| 9402 | * @param largeIcon The large icon to use in the car notification. |
| 9403 | * @return This object for method chaining. |
| 9404 | */ |
| 9405 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 9406 | mLargeIcon = largeIcon; |
| 9407 | return this; |
| 9408 | } |
| 9409 | |
| 9410 | /** |
| 9411 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 9412 | * |
| 9413 | * @return The large icon for the car notification. |
| 9414 | * @see CarExtender#setLargeIcon |
| 9415 | */ |
| 9416 | public Bitmap getLargeIcon() { |
| 9417 | return mLargeIcon; |
| 9418 | } |
| 9419 | |
| 9420 | /** |
| 9421 | * Sets the unread conversation in a message notification. |
| 9422 | * |
| 9423 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 9424 | * @return This object for method chaining. |
| 9425 | */ |
| 9426 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 9427 | mUnreadConversation = unreadConversation; |
| 9428 | return this; |
| 9429 | } |
| 9430 | |
| 9431 | /** |
| 9432 | * Returns the unread conversation conveyed by this notification. |
| 9433 | * @see #setUnreadConversation(UnreadConversation) |
| 9434 | */ |
| 9435 | public UnreadConversation getUnreadConversation() { |
| 9436 | return mUnreadConversation; |
| 9437 | } |
| 9438 | |
| 9439 | /** |
| 9440 | * A class which holds the unread messages from a conversation. |
| 9441 | */ |
| 9442 | public static class UnreadConversation { |
| 9443 | private static final String KEY_AUTHOR = "author"; |
| 9444 | private static final String KEY_TEXT = "text"; |
| 9445 | private static final String KEY_MESSAGES = "messages"; |
| 9446 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 9447 | private static final String KEY_ON_REPLY = "on_reply"; |
| 9448 | private static final String KEY_ON_READ = "on_read"; |
| 9449 | private static final String KEY_PARTICIPANTS = "participants"; |
| 9450 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 9451 | |
| 9452 | private final String[] mMessages; |
| 9453 | private final RemoteInput mRemoteInput; |
| 9454 | private final PendingIntent mReplyPendingIntent; |
| 9455 | private final PendingIntent mReadPendingIntent; |
| 9456 | private final String[] mParticipants; |
| 9457 | private final long mLatestTimestamp; |
| 9458 | |
| 9459 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 9460 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 9461 | String[] participants, long latestTimestamp) { |
| 9462 | mMessages = messages; |
| 9463 | mRemoteInput = remoteInput; |
| 9464 | mReadPendingIntent = readPendingIntent; |
| 9465 | mReplyPendingIntent = replyPendingIntent; |
| 9466 | mParticipants = participants; |
| 9467 | mLatestTimestamp = latestTimestamp; |
| 9468 | } |
| 9469 | |
| 9470 | /** |
| 9471 | * Gets the list of messages conveyed by this notification. |
| 9472 | */ |
| 9473 | public String[] getMessages() { |
| 9474 | return mMessages; |
| 9475 | } |
| 9476 | |
| 9477 | /** |
| 9478 | * Gets the remote input that will be used to convey the response to a message list, or |
| 9479 | * null if no such remote input exists. |
| 9480 | */ |
| 9481 | public RemoteInput getRemoteInput() { |
| 9482 | return mRemoteInput; |
| 9483 | } |
| 9484 | |
| 9485 | /** |
| 9486 | * Gets the pending intent that will be triggered when the user replies to this |
| 9487 | * notification. |
| 9488 | */ |
| 9489 | public PendingIntent getReplyPendingIntent() { |
| 9490 | return mReplyPendingIntent; |
| 9491 | } |
| 9492 | |
| 9493 | /** |
| 9494 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 9495 | * in this object's message list. |
| 9496 | */ |
| 9497 | public PendingIntent getReadPendingIntent() { |
| 9498 | return mReadPendingIntent; |
| 9499 | } |
| 9500 | |
| 9501 | /** |
| 9502 | * Gets the participants in the conversation. |
| 9503 | */ |
| 9504 | public String[] getParticipants() { |
| 9505 | return mParticipants; |
| 9506 | } |
| 9507 | |
| 9508 | /** |
| 9509 | * Gets the firs participant in the conversation. |
| 9510 | */ |
| 9511 | public String getParticipant() { |
| 9512 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 9513 | } |
| 9514 | |
| 9515 | /** |
| 9516 | * Gets the timestamp of the conversation. |
| 9517 | */ |
| 9518 | public long getLatestTimestamp() { |
| 9519 | return mLatestTimestamp; |
| 9520 | } |
| 9521 | |
| 9522 | Bundle getBundleForUnreadConversation() { |
| 9523 | Bundle b = new Bundle(); |
| 9524 | String author = null; |
| 9525 | if (mParticipants != null && mParticipants.length > 1) { |
| 9526 | author = mParticipants[0]; |
| 9527 | } |
| 9528 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 9529 | for (int i = 0; i < messages.length; i++) { |
| 9530 | Bundle m = new Bundle(); |
| 9531 | m.putString(KEY_TEXT, mMessages[i]); |
| 9532 | m.putString(KEY_AUTHOR, author); |
| 9533 | messages[i] = m; |
| 9534 | } |
| 9535 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 9536 | if (mRemoteInput != null) { |
| 9537 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 9538 | } |
| 9539 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 9540 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 9541 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 9542 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 9543 | return b; |
| 9544 | } |
| 9545 | |
| 9546 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 9547 | if (b == null) { |
| 9548 | return null; |
| 9549 | } |
| 9550 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 9551 | String[] messages = null; |
| 9552 | if (parcelableMessages != null) { |
| 9553 | String[] tmp = new String[parcelableMessages.length]; |
| 9554 | boolean success = true; |
| 9555 | for (int i = 0; i < tmp.length; i++) { |
| 9556 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 9557 | success = false; |
| 9558 | break; |
| 9559 | } |
| 9560 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 9561 | if (tmp[i] == null) { |
| 9562 | success = false; |
| 9563 | break; |
| 9564 | } |
| 9565 | } |
| 9566 | if (success) { |
| 9567 | messages = tmp; |
| 9568 | } else { |
| 9569 | return null; |
| 9570 | } |
| 9571 | } |
| 9572 | |
| 9573 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 9574 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 9575 | |
| 9576 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 9577 | |
| 9578 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 9579 | if (participants == null || participants.length != 1) { |
| 9580 | return null; |
| 9581 | } |
| 9582 | |
| 9583 | return new UnreadConversation(messages, |
| 9584 | remoteInput, |
| 9585 | onReply, |
| 9586 | onRead, |
| 9587 | participants, b.getLong(KEY_TIMESTAMP)); |
| 9588 | } |
| 9589 | }; |
| 9590 | |
| 9591 | /** |
| 9592 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 9593 | */ |
| 9594 | public static class Builder { |
| 9595 | private final List<String> mMessages = new ArrayList<String>(); |
| 9596 | private final String mParticipant; |
| 9597 | private RemoteInput mRemoteInput; |
| 9598 | private PendingIntent mReadPendingIntent; |
| 9599 | private PendingIntent mReplyPendingIntent; |
| 9600 | private long mLatestTimestamp; |
| 9601 | |
| 9602 | /** |
| 9603 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 9604 | * |
| 9605 | * @param name The name of the other participant in the conversation. |
| 9606 | */ |
| 9607 | public Builder(String name) { |
| 9608 | mParticipant = name; |
| 9609 | } |
| 9610 | |
| 9611 | /** |
| 9612 | * Appends a new unread message to the list of messages for this conversation. |
| 9613 | * |
| 9614 | * The messages should be added from oldest to newest. |
| 9615 | * |
| 9616 | * @param message The text of the new unread message. |
| 9617 | * @return This object for method chaining. |
| 9618 | */ |
| 9619 | public Builder addMessage(String message) { |
| 9620 | mMessages.add(message); |
| 9621 | return this; |
| 9622 | } |
| 9623 | |
| 9624 | /** |
| 9625 | * Sets the pending intent and remote input which will convey the reply to this |
| 9626 | * notification. |
| 9627 | * |
| 9628 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 9629 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 9630 | * @return This object for method chaining. |
| 9631 | * |
| 9632 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 9633 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 9634 | */ |
| 9635 | public Builder setReplyAction( |
| 9636 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 9637 | mRemoteInput = remoteInput; |
| 9638 | mReplyPendingIntent = pendingIntent; |
| 9639 | |
| 9640 | return this; |
| 9641 | } |
| 9642 | |
| 9643 | /** |
| 9644 | * Sets the pending intent that will be sent once the messages in this notification |
| 9645 | * are read. |
| 9646 | * |
| 9647 | * @param pendingIntent The pending intent to use. |
| 9648 | * @return This object for method chaining. |
| 9649 | */ |
| 9650 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 9651 | mReadPendingIntent = pendingIntent; |
| 9652 | return this; |
| 9653 | } |
| 9654 | |
| 9655 | /** |
| 9656 | * Sets the timestamp of the most recent message in an unread conversation. |
| 9657 | * |
| 9658 | * If a messaging notification has been posted by your application and has not |
| 9659 | * yet been cancelled, posting a later notification with the same id and tag |
| 9660 | * but without a newer timestamp may result in Android Auto not displaying a |
| 9661 | * heads up notification for the later notification. |
| 9662 | * |
| 9663 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 9664 | * @return This object for method chaining. |
| 9665 | */ |
| 9666 | public Builder setLatestTimestamp(long timestamp) { |
| 9667 | mLatestTimestamp = timestamp; |
| 9668 | return this; |
| 9669 | } |
| 9670 | |
| 9671 | /** |
| 9672 | * Builds a new unread conversation object. |
| 9673 | * |
| 9674 | * @return The new unread conversation object. |
| 9675 | */ |
| 9676 | public UnreadConversation build() { |
| 9677 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 9678 | String[] participants = { mParticipant }; |
| 9679 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 9680 | mReadPendingIntent, participants, mLatestTimestamp); |
| 9681 | } |
| 9682 | } |
| 9683 | } |
| 9684 | |
| 9685 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9686 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 9687 | * with a TV extension: |
| 9688 | * |
| 9689 | * <ol> |
| 9690 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 9691 | * <li>Create a {@link TvExtender}. |
| 9692 | * <li>Set TV-specific properties using the {@code set} methods of |
| 9693 | * {@link TvExtender}. |
| 9694 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9695 | * to apply the extension to a notification. |
| 9696 | * </ol> |
| 9697 | * |
| 9698 | * <pre class="prettyprint"> |
| 9699 | * Notification notification = new Notification.Builder(context) |
| 9700 | * ... |
| 9701 | * .extend(new TvExtender() |
| 9702 | * .set*(...)) |
| 9703 | * .build(); |
| 9704 | * </pre> |
| 9705 | * |
| 9706 | * <p>TV extensions can be accessed on an existing notification by using the |
| 9707 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 9708 | * to access values. |
| 9709 | * |
| 9710 | * @hide |
| 9711 | */ |
| 9712 | @SystemApi |
| 9713 | public static final class TvExtender implements Extender { |
| 9714 | private static final String TAG = "TvExtender"; |
| 9715 | |
| 9716 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 9717 | private static final String EXTRA_FLAGS = "flags"; |
| 9718 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 9719 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9720 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9721 | private static final String EXTRA_SUPPRESS_SHOW_OVER_APPS = "suppressShowOverApps"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9722 | |
| 9723 | // Flags bitwise-ored to mFlags |
| 9724 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 9725 | |
| 9726 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9727 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9728 | private PendingIntent mContentIntent; |
| 9729 | private PendingIntent mDeleteIntent; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9730 | private boolean mSuppressShowOverApps; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9731 | |
| 9732 | /** |
| 9733 | * Create a {@link TvExtender} with default options. |
| 9734 | */ |
| 9735 | public TvExtender() { |
| 9736 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 9737 | } |
| 9738 | |
| 9739 | /** |
| 9740 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 9741 | * |
| 9742 | * @param notif The notification from which to copy options. |
| 9743 | */ |
| 9744 | public TvExtender(Notification notif) { |
| 9745 | Bundle bundle = notif.extras == null ? |
| 9746 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 9747 | if (bundle != null) { |
| 9748 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9749 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9750 | mSuppressShowOverApps = bundle.getBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9751 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 9752 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 9753 | } |
| 9754 | } |
| 9755 | |
| 9756 | /** |
| 9757 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 9758 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9759 | * method of {@link Notification.Builder}. |
| 9760 | */ |
| 9761 | @Override |
| 9762 | public Notification.Builder extend(Notification.Builder builder) { |
| 9763 | Bundle bundle = new Bundle(); |
| 9764 | |
| 9765 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9766 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9767 | bundle.putBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS, mSuppressShowOverApps); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9768 | if (mContentIntent != null) { |
| 9769 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 9770 | } |
| 9771 | |
| 9772 | if (mDeleteIntent != null) { |
| 9773 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 9774 | } |
| 9775 | |
| 9776 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 9777 | return builder; |
| 9778 | } |
| 9779 | |
| 9780 | /** |
| 9781 | * Returns true if this notification should be shown on TV. This method return true |
| 9782 | * if the notification was extended with a TvExtender. |
| 9783 | */ |
| 9784 | public boolean isAvailableOnTv() { |
| 9785 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 9786 | } |
| 9787 | |
| 9788 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9789 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 9790 | * It can be different from the channel that the notification is delivered to when |
| 9791 | * posting on a non-TV device. |
| 9792 | */ |
| 9793 | public TvExtender setChannel(String channelId) { |
| 9794 | mChannelId = channelId; |
| 9795 | return this; |
| 9796 | } |
| 9797 | |
| 9798 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 9799 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 9800 | * It can be different from the channel that the notification is delivered to when |
| 9801 | * posting on a non-TV device. |
| 9802 | */ |
| 9803 | public TvExtender setChannelId(String channelId) { |
| 9804 | mChannelId = channelId; |
| 9805 | return this; |
| 9806 | } |
| 9807 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 9808 | /** @removed */ |
| 9809 | @Deprecated |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9810 | public String getChannel() { |
| 9811 | return mChannelId; |
| 9812 | } |
| 9813 | |
| 9814 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 9815 | * Returns the id of the channel this notification posts to on TV. |
| 9816 | */ |
| 9817 | public String getChannelId() { |
| 9818 | return mChannelId; |
| 9819 | } |
| 9820 | |
| 9821 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9822 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 9823 | * If provided, it is used instead of the content intent specified |
| 9824 | * at the level of Notification. |
| 9825 | */ |
| 9826 | public TvExtender setContentIntent(PendingIntent intent) { |
| 9827 | mContentIntent = intent; |
| 9828 | return this; |
| 9829 | } |
| 9830 | |
| 9831 | /** |
| 9832 | * Returns the TV-specific content intent. If this method returns null, the |
| 9833 | * main content intent on the notification should be used. |
| 9834 | * |
| 9835 | * @see {@link Notification#contentIntent} |
| 9836 | */ |
| 9837 | public PendingIntent getContentIntent() { |
| 9838 | return mContentIntent; |
| 9839 | } |
| 9840 | |
| 9841 | /** |
| 9842 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 9843 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 9844 | * at the level of Notification. |
| 9845 | */ |
| 9846 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 9847 | mDeleteIntent = intent; |
| 9848 | return this; |
| 9849 | } |
| 9850 | |
| 9851 | /** |
| 9852 | * Returns the TV-specific delete intent. If this method returns null, the |
| 9853 | * main delete intent on the notification should be used. |
| 9854 | * |
| 9855 | * @see {@link Notification#deleteIntent} |
| 9856 | */ |
| 9857 | public PendingIntent getDeleteIntent() { |
| 9858 | return mDeleteIntent; |
| 9859 | } |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9860 | |
| 9861 | /** |
| 9862 | * Specifies whether this notification should suppress showing a message over top of apps |
| 9863 | * outside of the launcher. |
| 9864 | */ |
| 9865 | public TvExtender setSuppressShowOverApps(boolean suppress) { |
| 9866 | mSuppressShowOverApps = suppress; |
| 9867 | return this; |
| 9868 | } |
| 9869 | |
| 9870 | /** |
| 9871 | * Returns true if this notification should not show messages over top of apps |
| 9872 | * outside of the launcher. |
| 9873 | */ |
| 9874 | public boolean getSuppressShowOverApps() { |
| 9875 | return mSuppressShowOverApps; |
| 9876 | } |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9877 | } |
| 9878 | |
| 9879 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9880 | * Get an array of Notification objects from a parcelable array bundle field. |
| 9881 | * Update the bundle to have a typed array so fetches in the future don't need |
| 9882 | * to do an array copy. |
| 9883 | */ |
| 9884 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 9885 | Parcelable[] array = bundle.getParcelableArray(key); |
| 9886 | if (array instanceof Notification[] || array == null) { |
| 9887 | return (Notification[]) array; |
| 9888 | } |
| 9889 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 9890 | Notification[].class); |
| 9891 | bundle.putParcelableArray(key, typedArray); |
| 9892 | return typedArray; |
| 9893 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 9894 | |
| 9895 | private static class BuilderRemoteViews extends RemoteViews { |
| 9896 | public BuilderRemoteViews(Parcel parcel) { |
| 9897 | super(parcel); |
| 9898 | } |
| 9899 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 9900 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 9901 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 9902 | } |
| 9903 | |
| 9904 | @Override |
| 9905 | public BuilderRemoteViews clone() { |
| 9906 | Parcel p = Parcel.obtain(); |
| 9907 | writeToParcel(p, 0); |
| 9908 | p.setDataPosition(0); |
| 9909 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 9910 | p.recycle(); |
| 9911 | return brv; |
| 9912 | } |
| 9913 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9914 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9915 | /** |
| 9916 | * A result object where information about the template that was created is saved. |
| 9917 | */ |
| 9918 | private static class TemplateBindResult { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9919 | int mIconMarginEnd; |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame^] | 9920 | boolean mRightIconContainerVisible; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9921 | |
| 9922 | /** |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9923 | * 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] | 9924 | * with the right actions. |
| 9925 | */ |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9926 | public int getIconMarginEnd() { |
| 9927 | return mIconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9928 | } |
| 9929 | |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame^] | 9930 | /** |
| 9931 | * Is the icon container visible on the right size because of the reply button or the |
| 9932 | * right icon. |
| 9933 | */ |
| 9934 | public boolean isRightIconContainerVisible() { |
| 9935 | return mRightIconContainerVisible; |
| 9936 | } |
| 9937 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9938 | public void setIconMarginEnd(int iconMarginEnd) { |
| 9939 | this.mIconMarginEnd = iconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9940 | } |
Selim Cinek | 6e41b0e | 2018-12-06 18:10:20 -0800 | [diff] [blame^] | 9941 | |
| 9942 | public void setRightIconContainerVisible(boolean iconContainerVisible) { |
| 9943 | mRightIconContainerVisible = iconContainerVisible; |
| 9944 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9945 | } |
| 9946 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9947 | private static class StandardTemplateParams { |
| 9948 | boolean hasProgress = true; |
| 9949 | boolean ambient = false; |
| 9950 | CharSequence title; |
| 9951 | CharSequence text; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9952 | CharSequence headerTextSecondary; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 9953 | CharSequence summaryText; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 9954 | int maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9955 | boolean hideLargeIcon; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9956 | boolean hideReplyIcon; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 9957 | boolean allowColorization = true; |
| 9958 | boolean forceDefaultColor = false; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9959 | |
| 9960 | final StandardTemplateParams reset() { |
| 9961 | hasProgress = true; |
| 9962 | ambient = false; |
| 9963 | title = null; |
| 9964 | text = null; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 9965 | summaryText = null; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9966 | headerTextSecondary = null; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 9967 | maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 9968 | allowColorization = true; |
| 9969 | forceDefaultColor = false; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9970 | return this; |
| 9971 | } |
| 9972 | |
| 9973 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 9974 | this.hasProgress = hasProgress; |
| 9975 | return this; |
| 9976 | } |
| 9977 | |
| 9978 | final StandardTemplateParams title(CharSequence title) { |
| 9979 | this.title = title; |
| 9980 | return this; |
| 9981 | } |
| 9982 | |
| 9983 | final StandardTemplateParams text(CharSequence text) { |
| 9984 | this.text = text; |
| 9985 | return this; |
| 9986 | } |
| 9987 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 9988 | final StandardTemplateParams summaryText(CharSequence text) { |
| 9989 | this.summaryText = text; |
| 9990 | return this; |
| 9991 | } |
| 9992 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9993 | final StandardTemplateParams headerTextSecondary(CharSequence text) { |
| 9994 | this.headerTextSecondary = text; |
| 9995 | return this; |
| 9996 | } |
| 9997 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9998 | final StandardTemplateParams hideLargeIcon(boolean hideLargeIcon) { |
| 9999 | this.hideLargeIcon = hideLargeIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10000 | return this; |
| 10001 | } |
| 10002 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 10003 | final StandardTemplateParams hideReplyIcon(boolean hideReplyIcon) { |
| 10004 | this.hideReplyIcon = hideReplyIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 10005 | return this; |
| 10006 | } |
| 10007 | |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10008 | final StandardTemplateParams disallowColorization() { |
| 10009 | this.allowColorization = false; |
| 10010 | return this; |
| 10011 | } |
| 10012 | |
| 10013 | final StandardTemplateParams forceDefaultColor() { |
| 10014 | this.forceDefaultColor = true; |
| 10015 | return this; |
| 10016 | } |
| 10017 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10018 | final StandardTemplateParams ambient(boolean ambient) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 10019 | Preconditions.checkState(title == null && text == null, "must set ambient before text"); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10020 | this.ambient = ambient; |
| 10021 | return this; |
| 10022 | } |
| 10023 | |
| 10024 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 10025 | Bundle extras = b.mN.extras; |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 10026 | this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE), ambient); |
| 10027 | |
| 10028 | // Big text notifications should contain their content when viewed in ambient mode. |
| 10029 | CharSequence text = extras.getCharSequence(EXTRA_BIG_TEXT); |
| 10030 | if (!ambient || TextUtils.isEmpty(text)) { |
| 10031 | text = extras.getCharSequence(EXTRA_TEXT); |
| 10032 | } |
| 10033 | this.text = b.processLegacyText(text, ambient); |
Selim Cinek | 10bbc0e | 2018-11-21 15:14:10 -0800 | [diff] [blame] | 10034 | this.summaryText = extras.getCharSequence(EXTRA_SUB_TEXT); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10035 | return this; |
| 10036 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 10037 | |
| 10038 | /** |
| 10039 | * Set the maximum lines of remote input history lines allowed. |
| 10040 | * @param maxRemoteInputHistory The number of lines. |
| 10041 | * @return The builder for method chaining. |
| 10042 | */ |
| 10043 | public StandardTemplateParams setMaxRemoteInputHistory(int maxRemoteInputHistory) { |
| 10044 | this.maxRemoteInputHistory = maxRemoteInputHistory; |
| 10045 | return this; |
| 10046 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 10047 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10048 | } |