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 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1341 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 1342 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 1343 | * selected by the user. |
| 1344 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1345 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 1346 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 1347 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1348 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1349 | public static class Action implements Parcelable { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1350 | /** |
| 1351 | * {@link #extras} key: Keys to a {@link Parcelable} {@link ArrayList} of |
| 1352 | * {@link RemoteInput}s. |
| 1353 | * |
| 1354 | * This is intended for {@link RemoteInput}s that only accept data, meaning |
| 1355 | * {@link RemoteInput#getAllowFreeFormInput} is false, {@link RemoteInput#getChoices} |
| 1356 | * is null or empty, and {@link RemoteInput#getAllowedDataTypes is non-null and not |
| 1357 | * empty. These {@link RemoteInput}s will be ignored by devices that do not |
| 1358 | * support non-text-based {@link RemoteInput}s. See {@link Builder#build}. |
| 1359 | * |
| 1360 | * You can test if a RemoteInput matches these constraints using |
| 1361 | * {@link RemoteInput#isDataOnly}. |
| 1362 | */ |
| 1363 | private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1364 | |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1365 | /** |
| 1366 | * {@link }: No semantic action defined. |
| 1367 | */ |
| 1368 | public static final int SEMANTIC_ACTION_NONE = 0; |
| 1369 | |
| 1370 | /** |
| 1371 | * {@code SemanticAction}: Reply to a conversation, chat, group, or wherever replies |
| 1372 | * may be appropriate. |
| 1373 | */ |
| 1374 | public static final int SEMANTIC_ACTION_REPLY = 1; |
| 1375 | |
| 1376 | /** |
| 1377 | * {@code SemanticAction}: Mark content as read. |
| 1378 | */ |
| 1379 | public static final int SEMANTIC_ACTION_MARK_AS_READ = 2; |
| 1380 | |
| 1381 | /** |
| 1382 | * {@code SemanticAction}: Mark content as unread. |
| 1383 | */ |
| 1384 | public static final int SEMANTIC_ACTION_MARK_AS_UNREAD = 3; |
| 1385 | |
| 1386 | /** |
| 1387 | * {@code SemanticAction}: Delete the content associated with the notification. This |
| 1388 | * could mean deleting an email, message, etc. |
| 1389 | */ |
| 1390 | public static final int SEMANTIC_ACTION_DELETE = 4; |
| 1391 | |
| 1392 | /** |
| 1393 | * {@code SemanticAction}: Archive the content associated with the notification. This |
| 1394 | * could mean archiving an email, message, etc. |
| 1395 | */ |
| 1396 | public static final int SEMANTIC_ACTION_ARCHIVE = 5; |
| 1397 | |
| 1398 | /** |
| 1399 | * {@code SemanticAction}: Mute the content associated with the notification. This could |
| 1400 | * mean silencing a conversation or currently playing media. |
| 1401 | */ |
| 1402 | public static final int SEMANTIC_ACTION_MUTE = 6; |
| 1403 | |
| 1404 | /** |
| 1405 | * {@code SemanticAction}: Unmute the content associated with the notification. This could |
| 1406 | * mean un-silencing a conversation or currently playing media. |
| 1407 | */ |
| 1408 | public static final int SEMANTIC_ACTION_UNMUTE = 7; |
| 1409 | |
| 1410 | /** |
| 1411 | * {@code SemanticAction}: Mark content with a thumbs up. |
| 1412 | */ |
| 1413 | public static final int SEMANTIC_ACTION_THUMBS_UP = 8; |
| 1414 | |
| 1415 | /** |
| 1416 | * {@code SemanticAction}: Mark content with a thumbs down. |
| 1417 | */ |
| 1418 | public static final int SEMANTIC_ACTION_THUMBS_DOWN = 9; |
| 1419 | |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 1420 | /** |
| 1421 | * {@code SemanticAction}: Call a contact, group, etc. |
| 1422 | */ |
| 1423 | public static final int SEMANTIC_ACTION_CALL = 10; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1424 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame^] | 1425 | /** |
| 1426 | * {@code SemanticAction}: Contextual action - dependent on the current notification. E.g. |
| 1427 | * open a Map application with an address shown in the notification. |
| 1428 | */ |
| 1429 | public static final int SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION = 11; |
| 1430 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1431 | private final Bundle mExtras; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1432 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1433 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1434 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1435 | private boolean mAllowGeneratedReplies = true; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1436 | private final @SemanticAction int mSemanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1437 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1438 | /** |
| 1439 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1440 | * |
| 1441 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1442 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1443 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1444 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1445 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1446 | /** |
| 1447 | * Title of the action. |
| 1448 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1449 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1450 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1451 | /** |
| 1452 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1453 | * may be rendered in a disabled presentation by the system UI. |
| 1454 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1455 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1456 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1457 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1458 | if (in.readInt() != 0) { |
| 1459 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1460 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1461 | icon = mIcon.getResId(); |
| 1462 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1463 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1464 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1465 | if (in.readInt() == 1) { |
| 1466 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1467 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1468 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1469 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1470 | mAllowGeneratedReplies = in.readInt() == 1; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1471 | mSemanticAction = in.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1472 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1473 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1474 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1475 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1476 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1477 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1478 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1479 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true, |
| 1480 | SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1483 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1484 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1485 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1486 | @SemanticAction int semanticAction) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1487 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1488 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1489 | this.icon = icon.getResId(); |
| 1490 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1491 | this.title = title; |
| 1492 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1493 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1494 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1495 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1496 | this.mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1500 | * Return an icon representing the action. |
| 1501 | */ |
| 1502 | public Icon getIcon() { |
| 1503 | if (mIcon == null && icon != 0) { |
| 1504 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1505 | mIcon = Icon.createWithResource("", icon); |
| 1506 | } |
| 1507 | return mIcon; |
| 1508 | } |
| 1509 | |
| 1510 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1511 | * Get additional metadata carried around with this Action. |
| 1512 | */ |
| 1513 | public Bundle getExtras() { |
| 1514 | return mExtras; |
| 1515 | } |
| 1516 | |
| 1517 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1518 | * Return whether the platform should automatically generate possible replies for this |
| 1519 | * {@link Action} |
| 1520 | */ |
| 1521 | public boolean getAllowGeneratedReplies() { |
| 1522 | return mAllowGeneratedReplies; |
| 1523 | } |
| 1524 | |
| 1525 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1526 | * Get the list of inputs to be collected from the user when this action is sent. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1527 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1528 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1529 | */ |
| 1530 | public RemoteInput[] getRemoteInputs() { |
| 1531 | return mRemoteInputs; |
| 1532 | } |
| 1533 | |
| 1534 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1535 | * Returns the {@code SemanticAction} associated with this {@link Action}. A |
| 1536 | * {@code SemanticAction} denotes what an {@link Action}'s {@link PendingIntent} will do |
| 1537 | * (eg. reply, mark as read, delete, etc). |
| 1538 | */ |
| 1539 | public @SemanticAction int getSemanticAction() { |
| 1540 | return mSemanticAction; |
| 1541 | } |
| 1542 | |
| 1543 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1544 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1545 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1546 | * {@link RemoteInput#isDataOnly}. |
| 1547 | * |
Shane Brennan | f670d6c | 2017-04-25 13:05:45 -0700 | [diff] [blame] | 1548 | * Returns null if there are no data-only remote inputs. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1549 | * |
| 1550 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1551 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1552 | */ |
| 1553 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1554 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1555 | } |
| 1556 | |
| 1557 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1558 | * Builder class for {@link Action} objects. |
| 1559 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1560 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1561 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1562 | private final CharSequence mTitle; |
| 1563 | private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1564 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1565 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1566 | private ArrayList<RemoteInput> mRemoteInputs; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1567 | private @SemanticAction int mSemanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1568 | |
| 1569 | /** |
| 1570 | * Construct a new builder for {@link Action} object. |
| 1571 | * @param icon icon to show for this action |
| 1572 | * @param title the title of the action |
| 1573 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1574 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1575 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1576 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1577 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | /** |
| 1581 | * Construct a new builder for {@link Action} object. |
| 1582 | * @param icon icon to show for this action |
| 1583 | * @param title the title of the action |
| 1584 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1585 | */ |
| 1586 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1587 | this(icon, title, intent, new Bundle(), null, true, SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | /** |
| 1591 | * Construct a new builder for {@link Action} object using the fields from an |
| 1592 | * {@link Action}. |
| 1593 | * @param action the action to read fields from. |
| 1594 | */ |
| 1595 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1596 | this(action.getIcon(), action.title, action.actionIntent, |
| 1597 | new Bundle(action.mExtras), action.getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1598 | action.getAllowGeneratedReplies(), action.getSemanticAction()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1601 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1602 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1603 | @SemanticAction int semanticAction) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1604 | mIcon = icon; |
| 1605 | mTitle = title; |
| 1606 | mIntent = intent; |
| 1607 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1608 | if (remoteInputs != null) { |
| 1609 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1610 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1611 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1612 | mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1613 | mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | /** |
| 1617 | * Merge additional metadata into this builder. |
| 1618 | * |
| 1619 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1620 | * |
| 1621 | * @see Notification.Action#extras |
| 1622 | */ |
| 1623 | public Builder addExtras(Bundle extras) { |
| 1624 | if (extras != null) { |
| 1625 | mExtras.putAll(extras); |
| 1626 | } |
| 1627 | return this; |
| 1628 | } |
| 1629 | |
| 1630 | /** |
| 1631 | * Get the metadata Bundle used by this Builder. |
| 1632 | * |
| 1633 | * <p>The returned Bundle is shared with this Builder. |
| 1634 | */ |
| 1635 | public Bundle getExtras() { |
| 1636 | return mExtras; |
| 1637 | } |
| 1638 | |
| 1639 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1640 | * Add an input to be collected from the user when this action is sent. |
| 1641 | * Response values can be retrieved from the fired intent by using the |
| 1642 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1643 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1644 | * @return this object for method chaining |
| 1645 | */ |
| 1646 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1647 | if (mRemoteInputs == null) { |
| 1648 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1649 | } |
| 1650 | mRemoteInputs.add(remoteInput); |
| 1651 | return this; |
| 1652 | } |
| 1653 | |
| 1654 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1655 | * Set whether the platform should automatically generate possible replies to add to |
| 1656 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1657 | * {@link RemoteInput}, this has no effect. |
| 1658 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1659 | * otherwise |
| 1660 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1661 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1662 | */ |
| 1663 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1664 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1665 | return this; |
| 1666 | } |
| 1667 | |
| 1668 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1669 | * Sets the {@code SemanticAction} for this {@link Action}. A |
| 1670 | * {@code SemanticAction} denotes what an {@link Action}'s |
| 1671 | * {@link PendingIntent} will do (eg. reply, mark as read, delete, etc). |
| 1672 | * @param semanticAction a SemanticAction defined within {@link Action} with |
| 1673 | * {@code SEMANTIC_ACTION_} prefixes |
| 1674 | * @return this object for method chaining |
| 1675 | */ |
| 1676 | public Builder setSemanticAction(@SemanticAction int semanticAction) { |
| 1677 | mSemanticAction = semanticAction; |
| 1678 | return this; |
| 1679 | } |
| 1680 | |
| 1681 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1682 | * Apply an extender to this action builder. Extenders may be used to add |
| 1683 | * metadata or change options on this builder. |
| 1684 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1685 | public Builder extend(Extender extender) { |
| 1686 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1687 | return this; |
| 1688 | } |
| 1689 | |
| 1690 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1691 | * Combine all of the options that have been set and return a new {@link Action} |
| 1692 | * object. |
| 1693 | * @return the built action |
| 1694 | */ |
| 1695 | public Action build() { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1696 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1697 | RemoteInput[] previousDataInputs = |
| 1698 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1699 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1700 | for (RemoteInput input : previousDataInputs) { |
| 1701 | dataOnlyInputs.add(input); |
| 1702 | } |
| 1703 | } |
| 1704 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1705 | if (mRemoteInputs != null) { |
| 1706 | for (RemoteInput input : mRemoteInputs) { |
| 1707 | if (input.isDataOnly()) { |
| 1708 | dataOnlyInputs.add(input); |
| 1709 | } else { |
| 1710 | textInputs.add(input); |
| 1711 | } |
| 1712 | } |
| 1713 | } |
| 1714 | if (!dataOnlyInputs.isEmpty()) { |
| 1715 | RemoteInput[] dataInputsArr = |
| 1716 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1717 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1718 | } |
| 1719 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1720 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1721 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1722 | mAllowGeneratedReplies, mSemanticAction); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1723 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1724 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1725 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1726 | @Override |
| 1727 | public Action clone() { |
| 1728 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1729 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1730 | title, |
| 1731 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1732 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1733 | getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1734 | getAllowGeneratedReplies(), |
| 1735 | getSemanticAction()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1736 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1737 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1738 | @Override |
| 1739 | public int describeContents() { |
| 1740 | return 0; |
| 1741 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1742 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1743 | @Override |
| 1744 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1745 | final Icon ic = getIcon(); |
| 1746 | if (ic != null) { |
| 1747 | out.writeInt(1); |
| 1748 | ic.writeToParcel(out, 0); |
| 1749 | } else { |
| 1750 | out.writeInt(0); |
| 1751 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1752 | TextUtils.writeToParcel(title, out, flags); |
| 1753 | if (actionIntent != null) { |
| 1754 | out.writeInt(1); |
| 1755 | actionIntent.writeToParcel(out, flags); |
| 1756 | } else { |
| 1757 | out.writeInt(0); |
| 1758 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1759 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1760 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1761 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1762 | out.writeInt(mSemanticAction); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1763 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1764 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1765 | public static final Parcelable.Creator<Action> CREATOR = |
| 1766 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1767 | public Action createFromParcel(Parcel in) { |
| 1768 | return new Action(in); |
| 1769 | } |
| 1770 | public Action[] newArray(int size) { |
| 1771 | return new Action[size]; |
| 1772 | } |
| 1773 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1774 | |
| 1775 | /** |
| 1776 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1777 | * metadata or change options on an action builder. |
| 1778 | */ |
| 1779 | public interface Extender { |
| 1780 | /** |
| 1781 | * Apply this extender to a notification action builder. |
| 1782 | * @param builder the builder to be modified. |
| 1783 | * @return the build object for chaining. |
| 1784 | */ |
| 1785 | public Builder extend(Builder builder); |
| 1786 | } |
| 1787 | |
| 1788 | /** |
| 1789 | * Wearable extender for notification actions. To add extensions to an action, |
| 1790 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1791 | * the {@code WearableExtender()} constructor and apply it to a |
| 1792 | * {@link android.app.Notification.Action.Builder} using |
| 1793 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1794 | * |
| 1795 | * <pre class="prettyprint"> |
| 1796 | * Notification.Action action = new Notification.Action.Builder( |
| 1797 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1798 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1799 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1800 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1801 | */ |
| 1802 | public static final class WearableExtender implements Extender { |
| 1803 | /** Notification action extra which contains wearable extensions */ |
| 1804 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1805 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1806 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1807 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1808 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1809 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1810 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1811 | |
| 1812 | // Flags bitwise-ored to mFlags |
| 1813 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1814 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1815 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1816 | |
| 1817 | // Default value for flags integer |
| 1818 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1819 | |
| 1820 | private int mFlags = DEFAULT_FLAGS; |
| 1821 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1822 | private CharSequence mInProgressLabel; |
| 1823 | private CharSequence mConfirmLabel; |
| 1824 | private CharSequence mCancelLabel; |
| 1825 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1826 | /** |
| 1827 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1828 | * options. |
| 1829 | */ |
| 1830 | public WearableExtender() { |
| 1831 | } |
| 1832 | |
| 1833 | /** |
| 1834 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1835 | * wearable options present in an existing notification action. |
| 1836 | * @param action the notification action to inspect. |
| 1837 | */ |
| 1838 | public WearableExtender(Action action) { |
| 1839 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1840 | if (wearableBundle != null) { |
| 1841 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1842 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1843 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1844 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1845 | } |
| 1846 | } |
| 1847 | |
| 1848 | /** |
| 1849 | * Apply wearable extensions to a notification action that is being built. This is |
| 1850 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1851 | * method of {@link android.app.Notification.Action.Builder}. |
| 1852 | */ |
| 1853 | @Override |
| 1854 | public Action.Builder extend(Action.Builder builder) { |
| 1855 | Bundle wearableBundle = new Bundle(); |
| 1856 | |
| 1857 | if (mFlags != DEFAULT_FLAGS) { |
| 1858 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1859 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1860 | if (mInProgressLabel != null) { |
| 1861 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1862 | } |
| 1863 | if (mConfirmLabel != null) { |
| 1864 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1865 | } |
| 1866 | if (mCancelLabel != null) { |
| 1867 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1868 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1869 | |
| 1870 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1871 | return builder; |
| 1872 | } |
| 1873 | |
| 1874 | @Override |
| 1875 | public WearableExtender clone() { |
| 1876 | WearableExtender that = new WearableExtender(); |
| 1877 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1878 | that.mInProgressLabel = this.mInProgressLabel; |
| 1879 | that.mConfirmLabel = this.mConfirmLabel; |
| 1880 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1881 | return that; |
| 1882 | } |
| 1883 | |
| 1884 | /** |
| 1885 | * Set whether this action is available when the wearable device is not connected to |
| 1886 | * a companion device. The user can still trigger this action when the wearable device is |
| 1887 | * offline, but a visual hint will indicate that the action may not be available. |
| 1888 | * Defaults to true. |
| 1889 | */ |
| 1890 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1891 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1892 | return this; |
| 1893 | } |
| 1894 | |
| 1895 | /** |
| 1896 | * Get whether this action is available when the wearable device is not connected to |
| 1897 | * a companion device. The user can still trigger this action when the wearable device is |
| 1898 | * offline, but a visual hint will indicate that the action may not be available. |
| 1899 | * Defaults to true. |
| 1900 | */ |
| 1901 | public boolean isAvailableOffline() { |
| 1902 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1903 | } |
| 1904 | |
| 1905 | private void setFlag(int mask, boolean value) { |
| 1906 | if (value) { |
| 1907 | mFlags |= mask; |
| 1908 | } else { |
| 1909 | mFlags &= ~mask; |
| 1910 | } |
| 1911 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1912 | |
| 1913 | /** |
| 1914 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1915 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1916 | * |
| 1917 | * @param label the label to display while the action is being prepared to execute |
| 1918 | * @return this object for method chaining |
| 1919 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1920 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1921 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1922 | mInProgressLabel = label; |
| 1923 | return this; |
| 1924 | } |
| 1925 | |
| 1926 | /** |
| 1927 | * Get the label to display while the wearable is preparing to automatically execute |
| 1928 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1929 | * |
| 1930 | * @return the label to display while the action is being prepared to execute |
| 1931 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1932 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1933 | public CharSequence getInProgressLabel() { |
| 1934 | return mInProgressLabel; |
| 1935 | } |
| 1936 | |
| 1937 | /** |
| 1938 | * Set a label to display to confirm that the action should be executed. |
| 1939 | * This is usually an imperative verb like "Send". |
| 1940 | * |
| 1941 | * @param label the label to confirm the action should be executed |
| 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 setConfirmLabel(CharSequence label) { |
| 1946 | mConfirmLabel = label; |
| 1947 | return this; |
| 1948 | } |
| 1949 | |
| 1950 | /** |
| 1951 | * Get the label to display to confirm that the action should be executed. |
| 1952 | * This is usually an imperative verb like "Send". |
| 1953 | * |
| 1954 | * @return the label to confirm the action should be executed |
| 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 getConfirmLabel() { |
| 1958 | return mConfirmLabel; |
| 1959 | } |
| 1960 | |
| 1961 | /** |
| 1962 | * Set a label to display to cancel the action. |
| 1963 | * This is usually an imperative verb, like "Cancel". |
| 1964 | * |
| 1965 | * @param label the label to display to cancel the action |
| 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 setCancelLabel(CharSequence label) { |
| 1970 | mCancelLabel = label; |
| 1971 | return this; |
| 1972 | } |
| 1973 | |
| 1974 | /** |
| 1975 | * Get the label to display to cancel the action. |
| 1976 | * This is usually an imperative verb like "Cancel". |
| 1977 | * |
| 1978 | * @return the label to display to cancel the action |
| 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 getCancelLabel() { |
| 1982 | return mCancelLabel; |
| 1983 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1984 | |
| 1985 | /** |
| 1986 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 1987 | * platform that it can generate the appropriate transitions. |
| 1988 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 1989 | * an activity and transitions should be generated, false otherwise. |
| 1990 | * @return this object for method chaining |
| 1991 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1992 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1993 | boolean hintLaunchesActivity) { |
| 1994 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 1995 | return this; |
| 1996 | } |
| 1997 | |
| 1998 | /** |
| 1999 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 2000 | * platform that it can generate the appropriate transitions |
| 2001 | * @return {@code true} if the content intent will launch an activity and transitions |
| 2002 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 2003 | * never set. |
| 2004 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 2005 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 2006 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 2007 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2008 | |
| 2009 | /** |
| 2010 | * Set a hint that this Action should be displayed inline. |
| 2011 | * |
| 2012 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 2013 | * otherwise |
| 2014 | * @return this object for method chaining |
| 2015 | */ |
| 2016 | public WearableExtender setHintDisplayActionInline( |
| 2017 | boolean hintDisplayInline) { |
| 2018 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 2019 | return this; |
| 2020 | } |
| 2021 | |
| 2022 | /** |
| 2023 | * Get a hint that this Action should be displayed inline. |
| 2024 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 2025 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2026 | * otherwise. The default value is {@code false} if this was never set. |
| 2027 | */ |
| 2028 | public boolean getHintDisplayActionInline() { |
| 2029 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 2030 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2031 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2032 | |
| 2033 | /** |
| 2034 | * Provides meaning to an {@link Action} that hints at what the associated |
| 2035 | * {@link PendingIntent} will do. For example, an {@link Action} with a |
| 2036 | * {@link PendingIntent} that replies to a text message notification may have the |
| 2037 | * {@link #SEMANTIC_ACTION_REPLY} {@code SemanticAction} set within it. |
| 2038 | * |
| 2039 | * @hide |
| 2040 | */ |
| 2041 | @IntDef(prefix = { "SEMANTIC_ACTION_" }, value = { |
| 2042 | SEMANTIC_ACTION_NONE, |
| 2043 | SEMANTIC_ACTION_REPLY, |
| 2044 | SEMANTIC_ACTION_MARK_AS_READ, |
| 2045 | SEMANTIC_ACTION_MARK_AS_UNREAD, |
| 2046 | SEMANTIC_ACTION_DELETE, |
| 2047 | SEMANTIC_ACTION_ARCHIVE, |
| 2048 | SEMANTIC_ACTION_MUTE, |
| 2049 | SEMANTIC_ACTION_UNMUTE, |
| 2050 | SEMANTIC_ACTION_THUMBS_UP, |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 2051 | SEMANTIC_ACTION_THUMBS_DOWN, |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame^] | 2052 | SEMANTIC_ACTION_CALL, |
| 2053 | SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2054 | }) |
| 2055 | @Retention(RetentionPolicy.SOURCE) |
| 2056 | public @interface SemanticAction {} |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2057 | } |
| 2058 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2059 | /** |
| 2060 | * Array of all {@link Action} structures attached to this notification by |
| 2061 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 2062 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 2063 | * interface for invoking actions. |
| 2064 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 2065 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2066 | |
| 2067 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2068 | * Replacement version of this notification whose content will be shown |
| 2069 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 2070 | * and {@link #VISIBILITY_PUBLIC}. |
| 2071 | */ |
| 2072 | public Notification publicVersion; |
| 2073 | |
| 2074 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2075 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2076 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | */ |
| 2078 | public Notification() |
| 2079 | { |
| 2080 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2081 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2082 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | * @hide |
| 2087 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2088 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 2090 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 2091 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2092 | new Builder(context) |
| 2093 | .setWhen(when) |
| 2094 | .setSmallIcon(icon) |
| 2095 | .setTicker(tickerText) |
| 2096 | .setContentTitle(contentTitle) |
| 2097 | .setContentText(contentText) |
| 2098 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 2099 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | /** |
| 2103 | * Constructs a Notification object with the information needed to |
| 2104 | * have a status bar icon without the standard expanded view. |
| 2105 | * |
| 2106 | * @param icon The resource id of the icon to put in the status bar. |
| 2107 | * @param tickerText The text that flows by in the status bar when the notification first |
| 2108 | * activates. |
| 2109 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 2110 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2111 | * |
| 2112 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2113 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2114 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2115 | public Notification(int icon, CharSequence tickerText, long when) |
| 2116 | { |
| 2117 | this.icon = icon; |
| 2118 | this.tickerText = tickerText; |
| 2119 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2120 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | /** |
| 2124 | * Unflatten the notification from a parcel. |
| 2125 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2126 | @SuppressWarnings("unchecked") |
| 2127 | public Notification(Parcel parcel) { |
| 2128 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 2129 | // intents in extras are always written as the last entry. |
| 2130 | readFromParcelImpl(parcel); |
| 2131 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2132 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | { |
| 2137 | int version = parcel.readInt(); |
| 2138 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2139 | mWhitelistToken = parcel.readStrongBinder(); |
| 2140 | if (mWhitelistToken == null) { |
| 2141 | mWhitelistToken = processWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2142 | } |
| 2143 | // 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] | 2144 | parcel.setClassCookie(PendingIntent.class, mWhitelistToken); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2147 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2148 | if (parcel.readInt() != 0) { |
| 2149 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2150 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 2151 | icon = mSmallIcon.getResId(); |
| 2152 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2153 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | number = parcel.readInt(); |
| 2155 | if (parcel.readInt() != 0) { |
| 2156 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2157 | } |
| 2158 | if (parcel.readInt() != 0) { |
| 2159 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2160 | } |
| 2161 | if (parcel.readInt() != 0) { |
| 2162 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2163 | } |
| 2164 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2165 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2166 | } |
| 2167 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2168 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2169 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2170 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2171 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2172 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2173 | defaults = parcel.readInt(); |
| 2174 | flags = parcel.readInt(); |
| 2175 | if (parcel.readInt() != 0) { |
| 2176 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 2177 | } |
| 2178 | |
| 2179 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2180 | if (parcel.readInt() != 0) { |
| 2181 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 2182 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | vibrate = parcel.createLongArray(); |
| 2184 | ledARGB = parcel.readInt(); |
| 2185 | ledOnMS = parcel.readInt(); |
| 2186 | ledOffMS = parcel.readInt(); |
| 2187 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2188 | |
| 2189 | if (parcel.readInt() != 0) { |
| 2190 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2191 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2192 | |
| 2193 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2194 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2195 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2196 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2197 | mGroupKey = parcel.readString(); |
| 2198 | |
| 2199 | mSortKey = parcel.readString(); |
| 2200 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 2201 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2202 | fixDuplicateExtras(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2203 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2204 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 2205 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2206 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2207 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2208 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2209 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2210 | if (parcel.readInt() != 0) { |
| 2211 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2212 | } |
| 2213 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2214 | visibility = parcel.readInt(); |
| 2215 | |
| 2216 | if (parcel.readInt() != 0) { |
| 2217 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 2218 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2219 | |
| 2220 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2221 | |
| 2222 | if (parcel.readInt() != 0) { |
| 2223 | mChannelId = parcel.readString(); |
| 2224 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2225 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2226 | |
| 2227 | if (parcel.readInt() != 0) { |
| 2228 | mShortcutId = parcel.readString(); |
| 2229 | } |
| 2230 | |
| 2231 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2232 | |
| 2233 | if (parcel.readInt() != 0) { |
| 2234 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2235 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2236 | |
| 2237 | mGroupAlertBehavior = parcel.readInt(); |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2238 | if (parcel.readInt() != 0) { |
| 2239 | mAppOverlayIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2240 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2241 | } |
| 2242 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2243 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2244 | public Notification clone() { |
| 2245 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2246 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2247 | return that; |
| 2248 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2249 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2250 | /** |
| 2251 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 2252 | * of this into that. |
| 2253 | * @hide |
| 2254 | */ |
| 2255 | public void cloneInto(Notification that, boolean heavy) { |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2256 | that.mWhitelistToken = this.mWhitelistToken; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2257 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2258 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2259 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2260 | that.number = this.number; |
| 2261 | |
| 2262 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 2263 | that.contentIntent = this.contentIntent; |
| 2264 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2265 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2266 | |
| 2267 | if (this.tickerText != null) { |
| 2268 | that.tickerText = this.tickerText.toString(); |
| 2269 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2270 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2271 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2272 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2273 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2274 | that.contentView = this.contentView.clone(); |
| 2275 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2276 | if (heavy && this.mLargeIcon != null) { |
| 2277 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2278 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 2279 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2280 | that.sound = this.sound; // android.net.Uri is immutable |
| 2281 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2282 | if (this.audioAttributes != null) { |
| 2283 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 2284 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2285 | |
| 2286 | final long[] vibrate = this.vibrate; |
| 2287 | if (vibrate != null) { |
| 2288 | final int N = vibrate.length; |
| 2289 | final long[] vib = that.vibrate = new long[N]; |
| 2290 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 2291 | } |
| 2292 | |
| 2293 | that.ledARGB = this.ledARGB; |
| 2294 | that.ledOnMS = this.ledOnMS; |
| 2295 | that.ledOffMS = this.ledOffMS; |
| 2296 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2297 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2298 | that.flags = this.flags; |
| 2299 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2300 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2301 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2302 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2303 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2304 | that.mGroupKey = this.mGroupKey; |
| 2305 | |
| 2306 | that.mSortKey = this.mSortKey; |
| 2307 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2308 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2309 | try { |
| 2310 | that.extras = new Bundle(this.extras); |
| 2311 | // will unparcel |
| 2312 | that.extras.size(); |
| 2313 | } catch (BadParcelableException e) { |
| 2314 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2315 | that.extras = null; |
| 2316 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2317 | } |
| 2318 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2319 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2320 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2323 | if (this.actions != null) { |
| 2324 | that.actions = new Action[this.actions.length]; |
| 2325 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 2326 | if ( this.actions[i] != null) { |
| 2327 | that.actions[i] = this.actions[i].clone(); |
| 2328 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2329 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2330 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2331 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2332 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2333 | that.bigContentView = this.bigContentView.clone(); |
| 2334 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2335 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2336 | if (heavy && this.headsUpContentView != null) { |
| 2337 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 2338 | } |
| 2339 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2340 | that.visibility = this.visibility; |
| 2341 | |
| 2342 | if (this.publicVersion != null) { |
| 2343 | that.publicVersion = new Notification(); |
| 2344 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2345 | } |
| 2346 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2347 | that.color = this.color; |
| 2348 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2349 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2350 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2351 | that.mShortcutId = this.mShortcutId; |
| 2352 | that.mBadgeIcon = this.mBadgeIcon; |
| 2353 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2354 | that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2355 | that.mAppOverlayIntent = this.mAppOverlayIntent; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2356 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2357 | if (!heavy) { |
| 2358 | that.lightenPayload(); // will clean out extras |
| 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | /** |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2363 | * Note all {@link Uri} that are referenced internally, with the expectation |
| 2364 | * that Uri permission grants will need to be issued to ensure the recipient |
| 2365 | * of this object is able to render its contents. |
| 2366 | * |
| 2367 | * @hide |
| 2368 | */ |
| 2369 | public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 2370 | visitor.accept(sound); |
| 2371 | |
| 2372 | if (tickerView != null) tickerView.visitUris(visitor); |
| 2373 | if (contentView != null) contentView.visitUris(visitor); |
| 2374 | if (bigContentView != null) bigContentView.visitUris(visitor); |
| 2375 | if (headsUpContentView != null) headsUpContentView.visitUris(visitor); |
| 2376 | |
| 2377 | if (extras != null) { |
| 2378 | visitor.accept(extras.getParcelable(EXTRA_AUDIO_CONTENTS_URI)); |
Robin Lee | d107af6 | 2018-04-27 13:55:56 +0200 | [diff] [blame] | 2379 | if (extras.containsKey(EXTRA_BACKGROUND_IMAGE_URI)) { |
| 2380 | visitor.accept(Uri.parse(extras.getString(EXTRA_BACKGROUND_IMAGE_URI))); |
| 2381 | } |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | if (MessagingStyle.class.equals(getNotificationStyle()) && extras != null) { |
| 2385 | final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 2386 | if (!ArrayUtils.isEmpty(messages)) { |
| 2387 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2388 | .getMessagesFromBundleArray(messages)) { |
| 2389 | visitor.accept(message.getDataUri()); |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 2394 | if (!ArrayUtils.isEmpty(historic)) { |
| 2395 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2396 | .getMessagesFromBundleArray(historic)) { |
| 2397 | visitor.accept(message.getDataUri()); |
| 2398 | } |
| 2399 | } |
| 2400 | } |
| 2401 | } |
| 2402 | |
| 2403 | /** |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2404 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 2405 | * listeners when the full contents are not necessary. |
| 2406 | * @hide |
| 2407 | */ |
| 2408 | public final void lightenPayload() { |
| 2409 | tickerView = null; |
| 2410 | contentView = null; |
| 2411 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2412 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2413 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2414 | if (extras != null && !extras.isEmpty()) { |
| 2415 | final Set<String> keyset = extras.keySet(); |
| 2416 | final int N = keyset.size(); |
| 2417 | final String[] keys = keyset.toArray(new String[N]); |
| 2418 | for (int i=0; i<N; i++) { |
| 2419 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2420 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2421 | continue; |
| 2422 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2423 | final Object obj = extras.get(key); |
| 2424 | if (obj != null && |
| 2425 | ( obj instanceof Parcelable |
| 2426 | || obj instanceof Parcelable[] |
| 2427 | || obj instanceof SparseArray |
| 2428 | || obj instanceof ArrayList)) { |
| 2429 | extras.remove(key); |
| 2430 | } |
| 2431 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2432 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2435 | /** |
| 2436 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2437 | * means it had better not be some custom Parcelable implementation. |
| 2438 | * @hide |
| 2439 | */ |
| 2440 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2441 | if (cs == null) return cs; |
| 2442 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2443 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2444 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2445 | if (cs instanceof Parcelable) { |
| 2446 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2447 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2448 | return cs.toString(); |
| 2449 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2450 | return removeTextSizeSpans(cs); |
| 2451 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2452 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2453 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2454 | if (charSequence instanceof Spanned) { |
| 2455 | Spanned ss = (Spanned) charSequence; |
| 2456 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2457 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2458 | for (Object span : spans) { |
| 2459 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2460 | if (resultSpan instanceof CharacterStyle) { |
| 2461 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2462 | } |
| 2463 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2464 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2465 | resultSpan = new TextAppearanceSpan( |
| 2466 | originalSpan.getFamily(), |
| 2467 | originalSpan.getTextStyle(), |
| 2468 | -1, |
| 2469 | originalSpan.getTextColor(), |
| 2470 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2471 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2472 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2473 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2474 | } else { |
| 2475 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2476 | } |
| 2477 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2478 | ss.getSpanFlags(span)); |
| 2479 | } |
| 2480 | return builder; |
| 2481 | } |
| 2482 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2483 | } |
| 2484 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2485 | public int describeContents() { |
| 2486 | return 0; |
| 2487 | } |
| 2488 | |
| 2489 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2490 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2491 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2492 | public void writeToParcel(Parcel parcel, int flags) { |
| 2493 | // We need to mark all pending intents getting into the notification |
| 2494 | // system as being put there to later allow the notification ranker |
| 2495 | // to launch them and by doing so add the app to the battery saver white |
| 2496 | // list for a short period of time. The problem is that the system |
| 2497 | // cannot look into the extras as there may be parcelables there that |
| 2498 | // the platform does not know how to handle. To go around that we have |
| 2499 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2500 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2501 | if (collectPendingIntents) { |
| 2502 | PendingIntent.setOnMarshaledListener( |
| 2503 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2504 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2505 | if (allPendingIntents == null) { |
| 2506 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2507 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2508 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2509 | } |
| 2510 | }); |
| 2511 | } |
| 2512 | try { |
| 2513 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2514 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2515 | writeToParcelImpl(parcel, flags); |
| 2516 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2517 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2518 | } finally { |
| 2519 | if (collectPendingIntents) { |
| 2520 | PendingIntent.setOnMarshaledListener(null); |
| 2521 | } |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | parcel.writeInt(1); |
| 2527 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2528 | parcel.writeStrongBinder(mWhitelistToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2529 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2530 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2531 | if (mSmallIcon == null && icon != 0) { |
| 2532 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2533 | mSmallIcon = Icon.createWithResource("", icon); |
| 2534 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2535 | if (mSmallIcon != null) { |
| 2536 | parcel.writeInt(1); |
| 2537 | mSmallIcon.writeToParcel(parcel, 0); |
| 2538 | } else { |
| 2539 | parcel.writeInt(0); |
| 2540 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | parcel.writeInt(number); |
| 2542 | if (contentIntent != null) { |
| 2543 | parcel.writeInt(1); |
| 2544 | contentIntent.writeToParcel(parcel, 0); |
| 2545 | } else { |
| 2546 | parcel.writeInt(0); |
| 2547 | } |
| 2548 | if (deleteIntent != null) { |
| 2549 | parcel.writeInt(1); |
| 2550 | deleteIntent.writeToParcel(parcel, 0); |
| 2551 | } else { |
| 2552 | parcel.writeInt(0); |
| 2553 | } |
| 2554 | if (tickerText != null) { |
| 2555 | parcel.writeInt(1); |
| 2556 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2557 | } else { |
| 2558 | parcel.writeInt(0); |
| 2559 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2560 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2561 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2562 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2563 | } else { |
| 2564 | parcel.writeInt(0); |
| 2565 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2566 | if (contentView != null) { |
| 2567 | parcel.writeInt(1); |
| 2568 | contentView.writeToParcel(parcel, 0); |
| 2569 | } else { |
| 2570 | parcel.writeInt(0); |
| 2571 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2572 | if (mLargeIcon == null && largeIcon != null) { |
| 2573 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2574 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2575 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2576 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2577 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2578 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2579 | } else { |
| 2580 | parcel.writeInt(0); |
| 2581 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2582 | |
| 2583 | parcel.writeInt(defaults); |
| 2584 | parcel.writeInt(this.flags); |
| 2585 | |
| 2586 | if (sound != null) { |
| 2587 | parcel.writeInt(1); |
| 2588 | sound.writeToParcel(parcel, 0); |
| 2589 | } else { |
| 2590 | parcel.writeInt(0); |
| 2591 | } |
| 2592 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2593 | |
| 2594 | if (audioAttributes != null) { |
| 2595 | parcel.writeInt(1); |
| 2596 | audioAttributes.writeToParcel(parcel, 0); |
| 2597 | } else { |
| 2598 | parcel.writeInt(0); |
| 2599 | } |
| 2600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | parcel.writeLongArray(vibrate); |
| 2602 | parcel.writeInt(ledARGB); |
| 2603 | parcel.writeInt(ledOnMS); |
| 2604 | parcel.writeInt(ledOffMS); |
| 2605 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2606 | |
| 2607 | if (fullScreenIntent != null) { |
| 2608 | parcel.writeInt(1); |
| 2609 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2610 | } else { |
| 2611 | parcel.writeInt(0); |
| 2612 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2613 | |
| 2614 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2615 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2616 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2617 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2618 | parcel.writeString(mGroupKey); |
| 2619 | |
| 2620 | parcel.writeString(mSortKey); |
| 2621 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2622 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2623 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2624 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2625 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2626 | if (bigContentView != null) { |
| 2627 | parcel.writeInt(1); |
| 2628 | bigContentView.writeToParcel(parcel, 0); |
| 2629 | } else { |
| 2630 | parcel.writeInt(0); |
| 2631 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2632 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2633 | if (headsUpContentView != null) { |
| 2634 | parcel.writeInt(1); |
| 2635 | headsUpContentView.writeToParcel(parcel, 0); |
| 2636 | } else { |
| 2637 | parcel.writeInt(0); |
| 2638 | } |
| 2639 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2640 | parcel.writeInt(visibility); |
| 2641 | |
| 2642 | if (publicVersion != null) { |
| 2643 | parcel.writeInt(1); |
| 2644 | publicVersion.writeToParcel(parcel, 0); |
| 2645 | } else { |
| 2646 | parcel.writeInt(0); |
| 2647 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2648 | |
| 2649 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2650 | |
| 2651 | if (mChannelId != null) { |
| 2652 | parcel.writeInt(1); |
| 2653 | parcel.writeString(mChannelId); |
| 2654 | } else { |
| 2655 | parcel.writeInt(0); |
| 2656 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2657 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2658 | |
| 2659 | if (mShortcutId != null) { |
| 2660 | parcel.writeInt(1); |
| 2661 | parcel.writeString(mShortcutId); |
| 2662 | } else { |
| 2663 | parcel.writeInt(0); |
| 2664 | } |
| 2665 | |
| 2666 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2667 | |
| 2668 | if (mSettingsText != null) { |
| 2669 | parcel.writeInt(1); |
| 2670 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2671 | } else { |
| 2672 | parcel.writeInt(0); |
| 2673 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2674 | |
| 2675 | parcel.writeInt(mGroupAlertBehavior); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2676 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 2677 | if (mAppOverlayIntent != null) { |
| 2678 | parcel.writeInt(1); |
| 2679 | mAppOverlayIntent.writeToParcel(parcel, 0); |
| 2680 | } else { |
| 2681 | parcel.writeInt(0); |
| 2682 | } |
| 2683 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2684 | // 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] | 2685 | } |
| 2686 | |
| 2687 | /** |
| 2688 | * Parcelable.Creator that instantiates Notification objects |
| 2689 | */ |
| 2690 | public static final Parcelable.Creator<Notification> CREATOR |
| 2691 | = new Parcelable.Creator<Notification>() |
| 2692 | { |
| 2693 | public Notification createFromParcel(Parcel parcel) |
| 2694 | { |
| 2695 | return new Notification(parcel); |
| 2696 | } |
| 2697 | |
| 2698 | public Notification[] newArray(int size) |
| 2699 | { |
| 2700 | return new Notification[size]; |
| 2701 | } |
| 2702 | }; |
| 2703 | |
| 2704 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2705 | * @hide |
| 2706 | */ |
| 2707 | public static boolean areActionsVisiblyDifferent(Notification first, Notification second) { |
| 2708 | Notification.Action[] firstAs = first.actions; |
| 2709 | Notification.Action[] secondAs = second.actions; |
| 2710 | if (firstAs == null && secondAs != null || firstAs != null && secondAs == null) { |
| 2711 | return true; |
| 2712 | } |
| 2713 | if (firstAs != null && secondAs != null) { |
| 2714 | if (firstAs.length != secondAs.length) { |
| 2715 | return true; |
| 2716 | } |
| 2717 | for (int i = 0; i < firstAs.length; i++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2718 | if (!Objects.equals(String.valueOf(firstAs[i].title), |
| 2719 | String.valueOf(secondAs[i].title))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2720 | return true; |
| 2721 | } |
| 2722 | RemoteInput[] firstRs = firstAs[i].getRemoteInputs(); |
| 2723 | RemoteInput[] secondRs = secondAs[i].getRemoteInputs(); |
| 2724 | if (firstRs == null) { |
| 2725 | firstRs = new RemoteInput[0]; |
| 2726 | } |
| 2727 | if (secondRs == null) { |
| 2728 | secondRs = new RemoteInput[0]; |
| 2729 | } |
| 2730 | if (firstRs.length != secondRs.length) { |
| 2731 | return true; |
| 2732 | } |
| 2733 | for (int j = 0; j < firstRs.length; j++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2734 | if (!Objects.equals(String.valueOf(firstRs[j].getLabel()), |
| 2735 | String.valueOf(secondRs[j].getLabel()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2736 | return true; |
| 2737 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2738 | } |
| 2739 | } |
| 2740 | } |
| 2741 | return false; |
| 2742 | } |
| 2743 | |
| 2744 | /** |
| 2745 | * @hide |
| 2746 | */ |
| 2747 | public static boolean areStyledNotificationsVisiblyDifferent(Builder first, Builder second) { |
| 2748 | if (first.getStyle() == null) { |
| 2749 | return second.getStyle() != null; |
| 2750 | } |
| 2751 | if (second.getStyle() == null) { |
| 2752 | return true; |
| 2753 | } |
| 2754 | return first.getStyle().areNotificationsVisiblyDifferent(second.getStyle()); |
| 2755 | } |
| 2756 | |
| 2757 | /** |
| 2758 | * @hide |
| 2759 | */ |
| 2760 | public static boolean areRemoteViewsChanged(Builder first, Builder second) { |
Julia Reynolds | e5c6045 | 2018-04-30 14:41:36 -0400 | [diff] [blame] | 2761 | if (!Objects.equals(first.usesStandardHeader(), second.usesStandardHeader())) { |
| 2762 | return true; |
| 2763 | } |
| 2764 | |
| 2765 | if (areRemoteViewsChanged(first.mN.contentView, second.mN.contentView)) { |
| 2766 | return true; |
| 2767 | } |
| 2768 | if (areRemoteViewsChanged(first.mN.bigContentView, second.mN.bigContentView)) { |
| 2769 | return true; |
| 2770 | } |
| 2771 | if (areRemoteViewsChanged(first.mN.headsUpContentView, second.mN.headsUpContentView)) { |
| 2772 | return true; |
| 2773 | } |
| 2774 | |
| 2775 | return false; |
| 2776 | } |
| 2777 | |
| 2778 | private static boolean areRemoteViewsChanged(RemoteViews first, RemoteViews second) { |
| 2779 | if (first == null && second == null) { |
| 2780 | return false; |
| 2781 | } |
| 2782 | if (first == null && second != null || first != null && second == null) { |
| 2783 | return true; |
| 2784 | } |
| 2785 | |
| 2786 | if (!Objects.equals(first.getLayoutId(), second.getLayoutId())) { |
| 2787 | return true; |
| 2788 | } |
| 2789 | |
| 2790 | if (!Objects.equals(first.getSequenceNumber(), second.getSequenceNumber())) { |
| 2791 | return true; |
| 2792 | } |
| 2793 | |
| 2794 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | /** |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2798 | * Parcelling creates multiple copies of objects in {@code extras}. Fix them. |
| 2799 | * <p> |
| 2800 | * For backwards compatibility {@code extras} holds some references to "real" member data such |
| 2801 | * as {@link getLargeIcon()} which is mirrored by {@link #EXTRA_LARGE_ICON}. This is mostly |
| 2802 | * fine as long as the object stays in one process. |
| 2803 | * <p> |
| 2804 | * However, once the notification goes into a parcel each reference gets marshalled separately, |
| 2805 | * wasting memory. Especially with large images on Auto and TV, this is worth fixing. |
| 2806 | */ |
| 2807 | private void fixDuplicateExtras() { |
| 2808 | if (extras != null) { |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2809 | fixDuplicateExtra(mLargeIcon, EXTRA_LARGE_ICON); |
| 2810 | } |
| 2811 | } |
| 2812 | |
| 2813 | /** |
| 2814 | * If we find an extra that's exactly the same as one of the "real" fields but refers to a |
| 2815 | * separate object, replace it with the field's version to avoid holding duplicate copies. |
| 2816 | */ |
| 2817 | private void fixDuplicateExtra(@Nullable Parcelable original, @NonNull String extraName) { |
| 2818 | if (original != null && extras.getParcelable(extraName) != null) { |
| 2819 | extras.putParcelable(extraName, original); |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2824 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2825 | * layout. |
| 2826 | * |
| 2827 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2828 | * in the view.</p> |
| 2829 | * @param context The context for your application / activity. |
| 2830 | * @param contentTitle The title that goes in the expanded entry. |
| 2831 | * @param contentText The text that goes in the expanded entry. |
| 2832 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2833 | * If this is an activity, it must include the |
| 2834 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2835 | * that you take care of task management as described in the |
| 2836 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2837 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2838 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2839 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2840 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2841 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2842 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | public void setLatestEventInfo(Context context, |
| 2844 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2845 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2846 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2847 | new Throwable()); |
| 2848 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2849 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2850 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2851 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2852 | } |
| 2853 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2854 | // ensure that any information already set directly is preserved |
| 2855 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2856 | |
| 2857 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2858 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2859 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | } |
| 2861 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2862 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2863 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2864 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2865 | |
| 2866 | 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] | 2867 | } |
| 2868 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2869 | /** |
| 2870 | * @hide |
| 2871 | */ |
| 2872 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2873 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | /** |
| 2877 | * @hide |
| 2878 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2879 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2880 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2881 | } |
| 2882 | |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 2883 | /** |
| 2884 | * @hide |
| 2885 | */ |
| 2886 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 2887 | long token = proto.start(fieldId); |
| 2888 | proto.write(NotificationProto.CHANNEL_ID, getChannelId()); |
| 2889 | proto.write(NotificationProto.HAS_TICKER_TEXT, this.tickerText != null); |
| 2890 | proto.write(NotificationProto.FLAGS, this.flags); |
| 2891 | proto.write(NotificationProto.COLOR, this.color); |
| 2892 | proto.write(NotificationProto.CATEGORY, this.category); |
| 2893 | proto.write(NotificationProto.GROUP_KEY, this.mGroupKey); |
| 2894 | proto.write(NotificationProto.SORT_KEY, this.mSortKey); |
| 2895 | if (this.actions != null) { |
| 2896 | proto.write(NotificationProto.ACTION_LENGTH, this.actions.length); |
| 2897 | } |
| 2898 | if (this.visibility >= VISIBILITY_SECRET && this.visibility <= VISIBILITY_PUBLIC) { |
| 2899 | proto.write(NotificationProto.VISIBILITY, this.visibility); |
| 2900 | } |
| 2901 | if (publicVersion != null) { |
| 2902 | publicVersion.writeToProto(proto, NotificationProto.PUBLIC_VERSION); |
| 2903 | } |
| 2904 | proto.end(token); |
| 2905 | } |
| 2906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | @Override |
| 2908 | public String toString() { |
| 2909 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2910 | sb.append("Notification(channel="); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2911 | sb.append(getChannelId()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2912 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2913 | sb.append(priority); |
| 2914 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2915 | if (contentView != null) { |
| 2916 | sb.append(contentView.getPackage()); |
| 2917 | sb.append("/0x"); |
| 2918 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2919 | } else { |
| 2920 | sb.append("null"); |
| 2921 | } |
| 2922 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2923 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2924 | sb.append("default"); |
| 2925 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2926 | int N = this.vibrate.length-1; |
| 2927 | sb.append("["); |
| 2928 | for (int i=0; i<N; i++) { |
| 2929 | sb.append(this.vibrate[i]); |
| 2930 | sb.append(','); |
| 2931 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 2932 | if (N != -1) { |
| 2933 | sb.append(this.vibrate[N]); |
| 2934 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2936 | } else { |
| 2937 | sb.append("null"); |
| 2938 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2939 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2940 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2941 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2942 | } else if (this.sound != null) { |
| 2943 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2944 | } else { |
| 2945 | sb.append("null"); |
| 2946 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 2947 | if (this.tickerText != null) { |
| 2948 | sb.append(" tick"); |
| 2949 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2950 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2951 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2952 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2953 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2954 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2955 | if (this.category != null) { |
| 2956 | sb.append(" category="); |
| 2957 | sb.append(this.category); |
| 2958 | } |
| 2959 | if (this.mGroupKey != null) { |
| 2960 | sb.append(" groupKey="); |
| 2961 | sb.append(this.mGroupKey); |
| 2962 | } |
| 2963 | if (this.mSortKey != null) { |
| 2964 | sb.append(" sortKey="); |
| 2965 | sb.append(this.mSortKey); |
| 2966 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2967 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2968 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2969 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2970 | } |
| 2971 | sb.append(" vis="); |
| 2972 | sb.append(visibilityToString(this.visibility)); |
| 2973 | if (this.publicVersion != null) { |
| 2974 | sb.append(" publicVersion="); |
| 2975 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2976 | } |
| 2977 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2978 | return sb.toString(); |
| 2979 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2980 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2981 | /** |
| 2982 | * {@hide} |
| 2983 | */ |
| 2984 | public static String visibilityToString(int vis) { |
| 2985 | switch (vis) { |
| 2986 | case VISIBILITY_PRIVATE: |
| 2987 | return "PRIVATE"; |
| 2988 | case VISIBILITY_PUBLIC: |
| 2989 | return "PUBLIC"; |
| 2990 | case VISIBILITY_SECRET: |
| 2991 | return "SECRET"; |
| 2992 | default: |
| 2993 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 2994 | } |
| 2995 | } |
| 2996 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2997 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 2998 | * {@hide} |
| 2999 | */ |
| 3000 | public static String priorityToString(@Priority int pri) { |
| 3001 | switch (pri) { |
| 3002 | case PRIORITY_MIN: |
| 3003 | return "MIN"; |
| 3004 | case PRIORITY_LOW: |
| 3005 | return "LOW"; |
| 3006 | case PRIORITY_DEFAULT: |
| 3007 | return "DEFAULT"; |
| 3008 | case PRIORITY_HIGH: |
| 3009 | return "HIGH"; |
| 3010 | case PRIORITY_MAX: |
| 3011 | return "MAX"; |
| 3012 | default: |
| 3013 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 3014 | } |
| 3015 | } |
| 3016 | |
Julia Reynolds | 6ad0aec | 2017-07-05 08:47:03 -0400 | [diff] [blame] | 3017 | /** |
| 3018 | * @hide |
| 3019 | */ |
| 3020 | public boolean hasCompletedProgress() { |
| 3021 | // not a progress notification; can't be complete |
| 3022 | if (!extras.containsKey(EXTRA_PROGRESS) |
| 3023 | || !extras.containsKey(EXTRA_PROGRESS_MAX)) { |
| 3024 | return false; |
| 3025 | } |
| 3026 | // many apps use max 0 for 'indeterminate'; not complete |
| 3027 | if (extras.getInt(EXTRA_PROGRESS_MAX) == 0) { |
| 3028 | return false; |
| 3029 | } |
| 3030 | return extras.getInt(EXTRA_PROGRESS) == extras.getInt(EXTRA_PROGRESS_MAX); |
| 3031 | } |
| 3032 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3033 | /** @removed */ |
| 3034 | @Deprecated |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 3035 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3036 | return mChannelId; |
| 3037 | } |
| 3038 | |
| 3039 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3040 | * Returns the id of the channel this notification posts to. |
| 3041 | */ |
| 3042 | public String getChannelId() { |
| 3043 | return mChannelId; |
| 3044 | } |
| 3045 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3046 | /** @removed */ |
| 3047 | @Deprecated |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3048 | public long getTimeout() { |
| 3049 | return mTimeout; |
| 3050 | } |
| 3051 | |
| 3052 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3053 | * Returns the duration from posting after which this notification should be canceled by the |
| 3054 | * system, if it's not canceled already. |
| 3055 | */ |
| 3056 | public long getTimeoutAfter() { |
| 3057 | return mTimeout; |
| 3058 | } |
| 3059 | |
| 3060 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3061 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 3062 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 3063 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 3064 | */ |
| 3065 | public int getBadgeIconType() { |
| 3066 | return mBadgeIcon; |
| 3067 | } |
| 3068 | |
| 3069 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3070 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3071 | * |
| 3072 | * <p>Used by some Launchers that display notification content to hide shortcuts that duplicate |
| 3073 | * notifications. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3074 | */ |
| 3075 | public String getShortcutId() { |
| 3076 | return mShortcutId; |
| 3077 | } |
| 3078 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3079 | |
| 3080 | /** |
| 3081 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 3082 | */ |
| 3083 | public CharSequence getSettingsText() { |
| 3084 | return mSettingsText; |
| 3085 | } |
| 3086 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3087 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3088 | * Returns which type of notifications in a group are responsible for audibly alerting the |
| 3089 | * user. See {@link #GROUP_ALERT_ALL}, {@link #GROUP_ALERT_CHILDREN}, |
| 3090 | * {@link #GROUP_ALERT_SUMMARY}. |
| 3091 | */ |
| 3092 | public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 3093 | return mGroupAlertBehavior; |
| 3094 | } |
| 3095 | |
| 3096 | /** |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3097 | * Returns the intent that will be used to display app content in a floating window over the |
| 3098 | * existing foreground activity. |
| 3099 | */ |
| 3100 | public PendingIntent getAppOverlayIntent() { |
| 3101 | return mAppOverlayIntent; |
| 3102 | } |
| 3103 | |
| 3104 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3105 | * The small icon representing this notification in the status bar and content view. |
| 3106 | * |
| 3107 | * @return the small icon representing this notification. |
| 3108 | * |
| 3109 | * @see Builder#getSmallIcon() |
| 3110 | * @see Builder#setSmallIcon(Icon) |
| 3111 | */ |
| 3112 | public Icon getSmallIcon() { |
| 3113 | return mSmallIcon; |
| 3114 | } |
| 3115 | |
| 3116 | /** |
| 3117 | * Used when notifying to clean up legacy small icons. |
| 3118 | * @hide |
| 3119 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3120 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3121 | public void setSmallIcon(Icon icon) { |
| 3122 | mSmallIcon = icon; |
| 3123 | } |
| 3124 | |
| 3125 | /** |
| 3126 | * The large icon shown in this notification's content view. |
| 3127 | * @see Builder#getLargeIcon() |
| 3128 | * @see Builder#setLargeIcon(Icon) |
| 3129 | */ |
| 3130 | public Icon getLargeIcon() { |
| 3131 | return mLargeIcon; |
| 3132 | } |
| 3133 | |
| 3134 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3135 | * @hide |
| 3136 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3137 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3138 | public boolean isGroupSummary() { |
| 3139 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 3140 | } |
| 3141 | |
| 3142 | /** |
| 3143 | * @hide |
| 3144 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3145 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3146 | public boolean isGroupChild() { |
| 3147 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 3148 | } |
| 3149 | |
| 3150 | /** |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3151 | * @hide |
| 3152 | */ |
| 3153 | public boolean suppressAlertingDueToGrouping() { |
| 3154 | if (isGroupSummary() |
| 3155 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { |
| 3156 | return true; |
| 3157 | } else if (isGroupChild() |
| 3158 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { |
| 3159 | return true; |
| 3160 | } |
| 3161 | return false; |
| 3162 | } |
| 3163 | |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 3164 | |
| 3165 | /** |
| 3166 | * Finds and returns a remote input and its corresponding action. |
| 3167 | * |
| 3168 | * @param requiresFreeform requires the remoteinput to allow freeform or not. |
| 3169 | * @return the result pair, {@code null} if no result is found. |
| 3170 | * |
| 3171 | * @hide |
| 3172 | */ |
| 3173 | @Nullable |
| 3174 | public Pair<RemoteInput, Action> findRemoteInputActionPair(boolean requiresFreeform) { |
| 3175 | if (actions == null) { |
| 3176 | return null; |
| 3177 | } |
| 3178 | for (Notification.Action action : actions) { |
| 3179 | if (action.getRemoteInputs() == null) { |
| 3180 | continue; |
| 3181 | } |
| 3182 | RemoteInput resultRemoteInput = null; |
| 3183 | for (RemoteInput remoteInput : action.getRemoteInputs()) { |
| 3184 | if (remoteInput.getAllowFreeFormInput() || !requiresFreeform) { |
| 3185 | resultRemoteInput = remoteInput; |
| 3186 | } |
| 3187 | } |
| 3188 | if (resultRemoteInput != null) { |
| 3189 | return Pair.create(resultRemoteInput, action); |
| 3190 | } |
| 3191 | } |
| 3192 | return null; |
| 3193 | } |
| 3194 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3195 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3196 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3197 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3198 | * 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] | 3199 | * content views using the platform's notification layout template. If your app supports |
| 3200 | * versions of Android as old as API level 4, you can instead use |
| 3201 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 3202 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 3203 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3204 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3205 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3206 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3207 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3208 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3209 | * .setContentTitle("New mail from " + sender.toString()) |
| 3210 | * .setContentText(subject) |
| 3211 | * .setSmallIcon(R.drawable.new_mail) |
| 3212 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3213 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3214 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3215 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3216 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3217 | /** |
| 3218 | * @hide |
| 3219 | */ |
| 3220 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 3221 | "android.rebuild.contentViewActionCount"; |
| 3222 | /** |
| 3223 | * @hide |
| 3224 | */ |
| 3225 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 3226 | = "android.rebuild.bigViewActionCount"; |
| 3227 | /** |
| 3228 | * @hide |
| 3229 | */ |
| 3230 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 3231 | = "android.rebuild.hudViewActionCount"; |
| 3232 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 3233 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 3234 | SystemProperties.getBoolean("notifications.only_title", true); |
| 3235 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3236 | /** |
| 3237 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3238 | * secondary text color when the background is light. |
| 3239 | */ |
| 3240 | private static final int LIGHTNESS_TEXT_DIFFERENCE_LIGHT = 20; |
| 3241 | |
| 3242 | /** |
| 3243 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3244 | * secondary text color when the background is dark. |
| 3245 | * A bit less then the above value, since it looks better on dark backgrounds. |
| 3246 | */ |
| 3247 | private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10; |
| 3248 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3249 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3250 | private Notification mN; |
| 3251 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3252 | private Style mStyle; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3253 | @UnsupportedAppUsage |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3254 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3255 | private ArrayList<Person> mPersonList = new ArrayList<>(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3256 | private ContrastColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3257 | private boolean mIsLegacy; |
| 3258 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3259 | |
| 3260 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3261 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 3262 | */ |
| 3263 | private int mCachedContrastColor = COLOR_INVALID; |
| 3264 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3265 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3266 | * Caches a ambient version of {@link #mCachedAmbientColorIsFor}. |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3267 | */ |
| 3268 | private int mCachedAmbientColor = COLOR_INVALID; |
| 3269 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3270 | /** |
| 3271 | * A neutral color color that can be used for icons. |
| 3272 | */ |
| 3273 | private int mNeutralColor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3274 | |
| 3275 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3276 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 3277 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 3278 | */ |
| 3279 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3280 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 3281 | private int mPrimaryTextColor = COLOR_INVALID; |
| 3282 | private int mSecondaryTextColor = COLOR_INVALID; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3283 | private int mBackgroundColor = COLOR_INVALID; |
| 3284 | private int mForegroundColor = COLOR_INVALID; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 3285 | /** |
| 3286 | * A temporary location where actions are stored. If != null the view originally has action |
| 3287 | * but doesn't have any for this inflation. |
| 3288 | */ |
| 3289 | private ArrayList<Action> mOriginalActions; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 3290 | private boolean mRebuildStyledRemoteViews; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3291 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3292 | private boolean mTintActionButtons; |
| 3293 | private boolean mInNightMode; |
| 3294 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3295 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3296 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3297 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3298 | * @param context |
| 3299 | * A {@link Context} that will be used by the Builder to construct the |
| 3300 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 3301 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3302 | * @param channelId |
| 3303 | * The constructed Notification will be posted on this |
| 3304 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 3305 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3306 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3307 | public Builder(Context context, String channelId) { |
| 3308 | this(context, (Notification) null); |
| 3309 | mN.mChannelId = channelId; |
| 3310 | } |
| 3311 | |
| 3312 | /** |
| 3313 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 3314 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 3315 | */ |
| 3316 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3317 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3318 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3319 | } |
| 3320 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3321 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3322 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3323 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3324 | public Builder(Context context, Notification toAdopt) { |
| 3325 | mContext = context; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3326 | Resources res = mContext.getResources(); |
| 3327 | mTintActionButtons = res.getBoolean(R.bool.config_tintNotificationActionButtons); |
| 3328 | |
| 3329 | if (res.getBoolean(R.bool.config_enableNightMode)) { |
| 3330 | Configuration currentConfig = res.getConfiguration(); |
| 3331 | mInNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 3332 | == Configuration.UI_MODE_NIGHT_YES; |
| 3333 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3334 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3335 | if (toAdopt == null) { |
| 3336 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3337 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 3338 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 3339 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3340 | mN.priority = PRIORITY_DEFAULT; |
| 3341 | mN.visibility = VISIBILITY_PRIVATE; |
| 3342 | } else { |
| 3343 | mN = toAdopt; |
| 3344 | if (mN.actions != null) { |
| 3345 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3346 | } |
| 3347 | |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3348 | if (mN.extras.containsKey(EXTRA_PEOPLE_LIST)) { |
| 3349 | ArrayList<Person> people = mN.extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 3350 | mPersonList.addAll(people); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3351 | } |
| 3352 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 3353 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 3354 | setSmallIcon(mN.icon); |
| 3355 | } |
| 3356 | |
| 3357 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 3358 | setLargeIcon(mN.largeIcon); |
| 3359 | } |
| 3360 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3361 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 3362 | if (!TextUtils.isEmpty(templateClass)) { |
| 3363 | final Class<? extends Style> styleClass |
| 3364 | = getNotificationStyleClass(templateClass); |
| 3365 | if (styleClass == null) { |
| 3366 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 3367 | } else { |
| 3368 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3369 | final Constructor<? extends Style> ctor = |
| 3370 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3371 | ctor.setAccessible(true); |
| 3372 | final Style style = ctor.newInstance(); |
| 3373 | style.restoreFromExtras(mN.extras); |
| 3374 | |
| 3375 | if (style != null) { |
| 3376 | setStyle(style); |
| 3377 | } |
| 3378 | } catch (Throwable t) { |
| 3379 | Log.e(TAG, "Could not create Style", t); |
| 3380 | } |
| 3381 | } |
| 3382 | } |
| 3383 | |
| 3384 | } |
| 3385 | } |
| 3386 | |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3387 | private ContrastColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3388 | if (mColorUtil == null) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 3389 | mColorUtil = ContrastColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3390 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3391 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3395 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 3396 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 3397 | * the shortcut. |
| 3398 | * |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3399 | * This field will be ignored by Launchers that don't support badging, don't show |
| 3400 | * notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3401 | * |
| 3402 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 3403 | * supersedes |
| 3404 | */ |
| 3405 | public Builder setShortcutId(String shortcutId) { |
| 3406 | mN.mShortcutId = shortcutId; |
| 3407 | return this; |
| 3408 | } |
| 3409 | |
| 3410 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3411 | * Sets which icon to display as a badge for this notification. |
| 3412 | * |
| 3413 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 3414 | * {@link #BADGE_ICON_LARGE}. |
| 3415 | * |
| 3416 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 3417 | */ |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 3418 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3419 | mN.mBadgeIcon = icon; |
| 3420 | return this; |
| 3421 | } |
| 3422 | |
| 3423 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3424 | * Sets the group alert behavior for this notification. Use this method to mute this |
| 3425 | * notification if alerts for this notification's group should be handled by a different |
| 3426 | * notification. This is only applicable for notifications that belong to a |
Julia Reynolds | 399d9bf | 2017-08-11 12:52:14 -0400 | [diff] [blame] | 3427 | * {@link #setGroup(String) group}. This must be called on all notifications you want to |
| 3428 | * mute. For example, if you want only the summary of your group to make noise, all |
| 3429 | * 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] | 3430 | * |
| 3431 | * <p> The default value is {@link #GROUP_ALERT_ALL}.</p> |
| 3432 | */ |
| 3433 | public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 3434 | mN.mGroupAlertBehavior = groupAlertBehavior; |
| 3435 | return this; |
| 3436 | } |
| 3437 | |
Julia Reynolds | b6bd93d | 2018-10-24 09:22:38 -0400 | [diff] [blame] | 3438 | /** |
| 3439 | * Sets the intent that will be used to display app content in a floating window |
| 3440 | * over the existing foreground activity. |
| 3441 | * |
| 3442 | * <p>This intent will be ignored unless this notification is posted to a channel that |
| 3443 | * allows {@link NotificationChannel#canOverlayApps() app overlays}.</p> |
| 3444 | * |
| 3445 | * <p>Notifications with a valid and allowed app overlay intent will be displayed as |
| 3446 | * floating windows outside of the notification shade on unlocked devices. When a user |
| 3447 | * interacts with one of these windows, this app overlay intent will be invoked and |
| 3448 | * displayed.</p> |
| 3449 | */ |
| 3450 | public Builder setAppOverlayIntent(PendingIntent intent) { |
| 3451 | mN.mAppOverlayIntent = intent; |
| 3452 | return this; |
| 3453 | } |
| 3454 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3455 | /** @removed */ |
| 3456 | @Deprecated |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3457 | public Builder setChannel(String channelId) { |
| 3458 | mN.mChannelId = channelId; |
| 3459 | return this; |
| 3460 | } |
| 3461 | |
| 3462 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3463 | * Specifies the channel the notification should be delivered on. |
| 3464 | */ |
| 3465 | public Builder setChannelId(String channelId) { |
| 3466 | mN.mChannelId = channelId; |
| 3467 | return this; |
| 3468 | } |
| 3469 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3470 | /** @removed */ |
| 3471 | @Deprecated |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 3472 | public Builder setTimeout(long durationMs) { |
| 3473 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3474 | return this; |
| 3475 | } |
| 3476 | |
| 3477 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3478 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 3479 | * if it is not already canceled. |
| 3480 | */ |
| 3481 | public Builder setTimeoutAfter(long durationMs) { |
| 3482 | mN.mTimeout = durationMs; |
| 3483 | return this; |
| 3484 | } |
| 3485 | |
| 3486 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3487 | * 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] | 3488 | * |
| 3489 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 3490 | * shown anymore by default and must be opted into by using |
| 3491 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3492 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3493 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3494 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3495 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3496 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3497 | return this; |
| 3498 | } |
| 3499 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3500 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 3501 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3502 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3503 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 3504 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3505 | */ |
| 3506 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3507 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3508 | return this; |
| 3509 | } |
| 3510 | |
| 3511 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3512 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3513 | * |
| 3514 | * 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] | 3515 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3516 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3517 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 3518 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3519 | * 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] | 3520 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3521 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3522 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3523 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3524 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3525 | */ |
| 3526 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3527 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3528 | return this; |
| 3529 | } |
| 3530 | |
| 3531 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3532 | * Sets the Chronometer to count down instead of counting up. |
| 3533 | * |
| 3534 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 3535 | * If it isn't set the chronometer will count up. |
| 3536 | * |
| 3537 | * @see #setUsesChronometer(boolean) |
| 3538 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3539 | public Builder setChronometerCountDown(boolean countDown) { |
| 3540 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3541 | return this; |
| 3542 | } |
| 3543 | |
| 3544 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3545 | * Set the small icon resource, which will be used to represent the notification in the |
| 3546 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3547 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3548 | |
| 3549 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 3550 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 3551 | * icon will be moved to the right-hand side. |
| 3552 | * |
| 3553 | |
| 3554 | * @param icon |
| 3555 | * A resource ID in the application's package of the drawable to use. |
| 3556 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3557 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3558 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3559 | return setSmallIcon(icon != 0 |
| 3560 | ? Icon.createWithResource(mContext, icon) |
| 3561 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3562 | } |
| 3563 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3564 | /** |
| 3565 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 3566 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 3567 | * LevelListDrawable}. |
| 3568 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3569 | * @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] | 3570 | * @param level The level to use for the icon. |
| 3571 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3572 | * @see Notification#icon |
| 3573 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3574 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3575 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3576 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3577 | return setSmallIcon(icon); |
| 3578 | } |
| 3579 | |
| 3580 | /** |
| 3581 | * 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] | 3582 | * status bar and content view (unless overridden there by a |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3583 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 3584 | * |
| 3585 | * @param icon An Icon object to use. |
| 3586 | * @see Notification#icon |
| 3587 | */ |
| 3588 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3589 | mN.setSmallIcon(icon); |
| 3590 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 3591 | mN.icon = icon.getResId(); |
| 3592 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3593 | return this; |
| 3594 | } |
| 3595 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3596 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3597 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3598 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3599 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3600 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3601 | return this; |
| 3602 | } |
| 3603 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3604 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3605 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3606 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3607 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3608 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3609 | return this; |
| 3610 | } |
| 3611 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3612 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3613 | * This provides some additional information that is displayed in the notification. No |
| 3614 | * guarantees are given where exactly it is displayed. |
| 3615 | * |
| 3616 | * <p>This information should only be provided if it provides an essential |
| 3617 | * benefit to the understanding of the notification. The more text you provide the |
| 3618 | * less readable it becomes. For example, an email client should only provide the account |
| 3619 | * name here if more than one email account has been added.</p> |
| 3620 | * |
| 3621 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 3622 | * notification header area. |
| 3623 | * |
| 3624 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 3625 | * this will be shown in the third line of text in the platform notification template. |
| 3626 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 3627 | * same time on those versions; they occupy the same place. |
| 3628 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3629 | */ |
| 3630 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3631 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3632 | return this; |
| 3633 | } |
| 3634 | |
| 3635 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3636 | * Provides text that will appear as a link to your application's settings. |
| 3637 | * |
| 3638 | * <p>This text does not appear within notification {@link Style templates} but may |
| 3639 | * appear when the user uses an affordance to learn more about the notification. |
| 3640 | * Additionally, this text will not appear unless you provide a valid link target by |
| 3641 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 3642 | * |
| 3643 | * <p>This text is meant to be concise description about what the user can customize |
| 3644 | * when they click on this link. The recommended maximum length is 40 characters. |
| 3645 | * @param text |
| 3646 | * @return |
| 3647 | */ |
| 3648 | public Builder setSettingsText(CharSequence text) { |
| 3649 | mN.mSettingsText = safeCharSequence(text); |
| 3650 | return this; |
| 3651 | } |
| 3652 | |
| 3653 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3654 | * Set the remote input history. |
| 3655 | * |
| 3656 | * This should be set to the most recent inputs that have been sent |
| 3657 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 3658 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 3659 | * |
| 3660 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 3661 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 3662 | * and how much of each individual input is shown. |
| 3663 | * |
| 3664 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 3665 | * with a {@code RemoteInput}.</p> |
| 3666 | */ |
| 3667 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 3668 | if (text == null) { |
| 3669 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 3670 | } else { |
| 3671 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 3672 | CharSequence[] safe = new CharSequence[N]; |
| 3673 | for (int i = 0; i < N; i++) { |
| 3674 | safe[i] = safeCharSequence(text[i]); |
| 3675 | } |
| 3676 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 3677 | } |
| 3678 | return this; |
| 3679 | } |
| 3680 | |
| 3681 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 3682 | * Sets whether remote history entries view should have a spinner. |
| 3683 | * @hide |
| 3684 | */ |
| 3685 | public Builder setShowRemoteInputSpinner(boolean showSpinner) { |
| 3686 | mN.extras.putBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER, showSpinner); |
| 3687 | return this; |
| 3688 | } |
| 3689 | |
| 3690 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 3691 | * Sets whether smart reply buttons should be hidden. |
| 3692 | * @hide |
| 3693 | */ |
| 3694 | public Builder setHideSmartReplies(boolean hideSmartReplies) { |
| 3695 | mN.extras.putBoolean(EXTRA_HIDE_SMART_REPLIES, hideSmartReplies); |
| 3696 | return this; |
| 3697 | } |
| 3698 | |
| 3699 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3700 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 3701 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3702 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3703 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3704 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3705 | return this; |
| 3706 | } |
| 3707 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3708 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3709 | * A small piece of additional information pertaining to this notification. |
| 3710 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3711 | * The platform template will draw this on the last line of the notification, at the far |
| 3712 | * 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] | 3713 | * |
| 3714 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 3715 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 3716 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3717 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3718 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3719 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3720 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3721 | return this; |
| 3722 | } |
| 3723 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3724 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3725 | * Set the progress this notification represents. |
| 3726 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3727 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3728 | */ |
| 3729 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3730 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3731 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3732 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3733 | return this; |
| 3734 | } |
| 3735 | |
| 3736 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3737 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3738 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3739 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3740 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3741 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3742 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3743 | return setCustomContentView(views); |
| 3744 | } |
| 3745 | |
| 3746 | /** |
| 3747 | * Supply custom RemoteViews to use instead of the platform template. |
| 3748 | * |
| 3749 | * This will override the layout that would otherwise be constructed by this Builder |
| 3750 | * object. |
| 3751 | */ |
| 3752 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3753 | mN.contentView = contentView; |
| 3754 | return this; |
| 3755 | } |
| 3756 | |
| 3757 | /** |
| 3758 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3759 | * |
| 3760 | * This will override the expanded layout that would otherwise be constructed by this |
| 3761 | * Builder object. |
| 3762 | */ |
| 3763 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3764 | mN.bigContentView = contentView; |
| 3765 | return this; |
| 3766 | } |
| 3767 | |
| 3768 | /** |
| 3769 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3770 | * |
| 3771 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3772 | * Builder object. |
| 3773 | */ |
| 3774 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3775 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3776 | return this; |
| 3777 | } |
| 3778 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3779 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3780 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3781 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3782 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3783 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3784 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3785 | * 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] | 3786 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3787 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3788 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3789 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3790 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3791 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3792 | return this; |
| 3793 | } |
| 3794 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3795 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3796 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3797 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3798 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3799 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3800 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3801 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3802 | return this; |
| 3803 | } |
| 3804 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3805 | /** |
| 3806 | * An intent to launch instead of posting the notification to the status bar. |
| 3807 | * Only for use with extremely high-priority notifications demanding the user's |
| 3808 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3809 | * alarm clock that the user has explicitly set to a particular time. |
| 3810 | * If this facility is used for something else, please give the user an option |
| 3811 | * to turn it off and use a normal notification, as this can be extremely |
| 3812 | * disruptive. |
| 3813 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3814 | * <p> |
| 3815 | * The system UI may choose to display a heads-up notification, instead of |
| 3816 | * launching this intent, while the user is using the device. |
| 3817 | * </p> |
| 3818 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3819 | * @param intent The pending intent to launch. |
| 3820 | * @param highPriority Passing true will cause this notification to be sent |
| 3821 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3822 | * |
| 3823 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3824 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3825 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3826 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3827 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3828 | return this; |
| 3829 | } |
| 3830 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3831 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3832 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3833 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3834 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3835 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3836 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3837 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3838 | return this; |
| 3839 | } |
| 3840 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3841 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3842 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3843 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3844 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3845 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3846 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3847 | setTicker(tickerText); |
| 3848 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3849 | return this; |
| 3850 | } |
| 3851 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3852 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3853 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3854 | * |
| 3855 | * 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] | 3856 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3857 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3858 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3859 | public Builder setLargeIcon(Bitmap b) { |
| 3860 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3861 | } |
| 3862 | |
| 3863 | /** |
| 3864 | * Add a large icon to the notification content view. |
| 3865 | * |
| 3866 | * In the platform template, this image will be shown on the left of the notification view |
| 3867 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3868 | * badge atop the large icon). |
| 3869 | */ |
| 3870 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3871 | mN.mLargeIcon = icon; |
| 3872 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3873 | return this; |
| 3874 | } |
| 3875 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3876 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3877 | * Set the sound to play. |
| 3878 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3879 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 3880 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3881 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3882 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3883 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3884 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3885 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3886 | mN.sound = sound; |
| 3887 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3888 | return this; |
| 3889 | } |
| 3890 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3891 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3892 | * 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] | 3893 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3894 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 3895 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3896 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3897 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 3898 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3899 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 3900 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3901 | mN.sound = sound; |
| 3902 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3903 | return this; |
| 3904 | } |
| 3905 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3906 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3907 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 3908 | * use during playback. |
| 3909 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3910 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3911 | * @see Notification#sound |
| 3912 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3913 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3914 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3915 | mN.sound = sound; |
| 3916 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3917 | return this; |
| 3918 | } |
| 3919 | |
| 3920 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3921 | * Set the vibration pattern to use. |
| 3922 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3923 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 3924 | * <code>pattern</code> parameter. |
| 3925 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3926 | * <p> |
| 3927 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 3928 | * </p> |
| 3929 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3930 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3931 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3932 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3933 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3934 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3935 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3936 | return this; |
| 3937 | } |
| 3938 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3939 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3940 | * Set the desired color for the indicator LED on the device, as well as the |
| 3941 | * blink duty cycle (specified in milliseconds). |
| 3942 | * |
| 3943 | |
| 3944 | * Not all devices will honor all (or even any) of these values. |
| 3945 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3946 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3947 | * @see Notification#ledARGB |
| 3948 | * @see Notification#ledOnMS |
| 3949 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3950 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3951 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3952 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3953 | mN.ledARGB = argb; |
| 3954 | mN.ledOnMS = onMs; |
| 3955 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3956 | if (onMs != 0 || offMs != 0) { |
| 3957 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 3958 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3959 | return this; |
| 3960 | } |
| 3961 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3962 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3963 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3964 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3965 | |
| 3966 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 3967 | * must take care of canceling them. |
| 3968 | * |
| 3969 | |
| 3970 | * They are typically used to indicate a background task that the user is actively engaged |
| 3971 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 3972 | * (e.g., a file download, sync operation, active network connection). |
| 3973 | * |
| 3974 | |
| 3975 | * @see Notification#FLAG_ONGOING_EVENT |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3976 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3977 | public Builder setOngoing(boolean ongoing) { |
| 3978 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 3979 | return this; |
| 3980 | } |
| 3981 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3982 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3983 | * Set whether this notification should be colorized. When set, the color set with |
| 3984 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 3985 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3986 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 3987 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3988 | * <p> |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3989 | * For most styles, the coloring will only be applied if the notification is for a |
| 3990 | * foreground service notification. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3991 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3992 | * that have a media session attached there is no such requirement. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3993 | * |
Aurimas Liutikas | 7f69533 | 2018-05-31 21:07:32 -0700 | [diff] [blame] | 3994 | * @see #setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3995 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3996 | */ |
| 3997 | public Builder setColorized(boolean colorize) { |
| 3998 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 3999 | return this; |
| 4000 | } |
| 4001 | |
| 4002 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4003 | * Set this flag if you would only like the sound, vibrate |
| 4004 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4005 | * |
| 4006 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4007 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4008 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 4009 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 4010 | return this; |
| 4011 | } |
| 4012 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4013 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4014 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4015 | * |
| 4016 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4017 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4018 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 4019 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4020 | return this; |
| 4021 | } |
| 4022 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4023 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 4024 | * Set whether or not this notification should not bridge to other devices. |
| 4025 | * |
| 4026 | * <p>Some notifications can be bridged to other devices for remote display. |
| 4027 | * This hint can be set to recommend this notification not be bridged. |
| 4028 | */ |
| 4029 | public Builder setLocalOnly(boolean localOnly) { |
| 4030 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 4031 | return this; |
| 4032 | } |
| 4033 | |
| 4034 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4035 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4036 | * <p> |
| 4037 | * The value should be one or more of the following fields combined with |
| 4038 | * bitwise-or: |
| 4039 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 4040 | * <p> |
| 4041 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4042 | * |
| 4043 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 4044 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4045 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4046 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4047 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4048 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4049 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4050 | return this; |
| 4051 | } |
| 4052 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4053 | /** |
| 4054 | * Set the priority of this notification. |
| 4055 | * |
| 4056 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4057 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4058 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 4059 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 4060 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4061 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4062 | return this; |
| 4063 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4064 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4065 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4066 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 4067 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4068 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4069 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 4070 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4071 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4072 | return this; |
| 4073 | } |
| 4074 | |
| 4075 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4076 | * Add a person that is relevant to this notification. |
| 4077 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4078 | * <P> |
| 4079 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 4080 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4081 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4082 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4083 | * </P> |
| 4084 | * |
| 4085 | * <P> |
| 4086 | * The person should be specified by the {@code String} representation of a |
| 4087 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 4088 | * </P> |
| 4089 | * |
| 4090 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 4091 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 4092 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 4093 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4094 | * It is also possible to provide a URI with the schema {@code name:} in order to uniquely |
| 4095 | * identify a person without an entry in the contacts database. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4096 | * </P> |
| 4097 | * |
| 4098 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4099 | * @see Notification#EXTRA_PEOPLE |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4100 | * @deprecated use {@link #addPerson(Person)} |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4101 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4102 | public Builder addPerson(String uri) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 4103 | addPerson(new Person.Builder().setUri(uri).build()); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4104 | return this; |
| 4105 | } |
| 4106 | |
| 4107 | /** |
| 4108 | * Add a person that is relevant to this notification. |
| 4109 | * |
| 4110 | * <P> |
| 4111 | * Depending on user preferences, this annotation may allow the notification to pass |
| 4112 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4113 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4114 | * appear more prominently in the user interface. |
| 4115 | * </P> |
| 4116 | * |
| 4117 | * <P> |
| 4118 | * A person should usually contain a uri in order to benefit from the ranking boost. |
| 4119 | * However, even if no uri is provided, it's beneficial to provide other people in the |
| 4120 | * notification, such that listeners and voice only devices can announce and handle them |
| 4121 | * properly. |
| 4122 | * </P> |
| 4123 | * |
| 4124 | * @param person the person to add. |
| 4125 | * @see Notification#EXTRA_PEOPLE_LIST |
| 4126 | */ |
| 4127 | public Builder addPerson(Person person) { |
| 4128 | mPersonList.add(person); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4129 | return this; |
| 4130 | } |
| 4131 | |
| 4132 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4133 | * Set this notification to be part of a group of notifications sharing the same key. |
| 4134 | * Grouped notifications may display in a cluster or stack on devices which |
| 4135 | * support such rendering. |
| 4136 | * |
| 4137 | * <p>To make this notification the summary for its group, also call |
| 4138 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 4139 | * {@link #setSortKey}. |
| 4140 | * @param groupKey The group key of the group. |
| 4141 | * @return this object for method chaining |
| 4142 | */ |
| 4143 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4144 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4145 | return this; |
| 4146 | } |
| 4147 | |
| 4148 | /** |
| 4149 | * Set this notification to be the group summary for a group of notifications. |
| 4150 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4151 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 4152 | * 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] | 4153 | * @param isGroupSummary Whether this notification should be a group summary. |
| 4154 | * @return this object for method chaining |
| 4155 | */ |
| 4156 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 4157 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 4158 | return this; |
| 4159 | } |
| 4160 | |
| 4161 | /** |
| 4162 | * Set a sort key that orders this notification among other notifications from the |
| 4163 | * same package. This can be useful if an external sort was already applied and an app |
| 4164 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 4165 | * value, although providing different priorities in addition to providing sort key may |
| 4166 | * cause this value to be ignored. |
| 4167 | * |
| 4168 | * <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] | 4169 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4170 | * |
| 4171 | * @see String#compareTo(String) |
| 4172 | */ |
| 4173 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4174 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4175 | return this; |
| 4176 | } |
| 4177 | |
| 4178 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4179 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4180 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4181 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 4182 | * |
| 4183 | * @see Notification#extras |
| 4184 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4185 | public Builder addExtras(Bundle extras) { |
| 4186 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4187 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4188 | } |
| 4189 | return this; |
| 4190 | } |
| 4191 | |
| 4192 | /** |
| 4193 | * Set metadata for this notification. |
| 4194 | * |
| 4195 | * <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] | 4196 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4197 | * called. |
| 4198 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4199 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 4200 | * Use {@link #addExtras} to merge in metadata instead. |
| 4201 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4202 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4203 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4204 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4205 | if (extras != null) { |
| 4206 | mUserExtras = extras; |
| 4207 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4208 | return this; |
| 4209 | } |
| 4210 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4211 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4212 | * Get the current metadata Bundle used by this notification Builder. |
| 4213 | * |
| 4214 | * <p>The returned Bundle is shared with this Builder. |
| 4215 | * |
| 4216 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 4217 | * {@link #build()} is called. |
| 4218 | * |
| 4219 | * @see Notification#extras |
| 4220 | */ |
| 4221 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4222 | return mUserExtras; |
| 4223 | } |
| 4224 | |
| 4225 | private Bundle getAllExtras() { |
| 4226 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 4227 | saveExtras.putAll(mN.extras); |
| 4228 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4232 | * Add an action to this notification. Actions are typically displayed by |
| 4233 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4234 | * <p> |
| 4235 | * Every action must have an icon (32dp square and matching the |
| 4236 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4237 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4238 | * <p> |
| 4239 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4240 | * the order they were added. Actions will not be displayed when the notification is |
| 4241 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4242 | * 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] | 4243 | * |
| 4244 | * @param icon Resource ID of a drawable that represents the action. |
| 4245 | * @param title Text describing the action. |
| 4246 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4247 | * |
| 4248 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4249 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4250 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4251 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4252 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4253 | return this; |
| 4254 | } |
| 4255 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4256 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4257 | * Add an action to this notification. Actions are typically displayed by |
| 4258 | * the system as a button adjacent to the notification content. |
| 4259 | * <p> |
| 4260 | * Every action must have an icon (32dp square and matching the |
| 4261 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4262 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4263 | * <p> |
| 4264 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4265 | * the order they were added. Actions will not be displayed when the notification is |
| 4266 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4267 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 4268 | * |
| 4269 | * @param action The action to add. |
| 4270 | */ |
| 4271 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4272 | if (action != null) { |
| 4273 | mActions.add(action); |
| 4274 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4275 | return this; |
| 4276 | } |
| 4277 | |
| 4278 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4279 | * Alter the complete list of actions attached to this notification. |
| 4280 | * @see #addAction(Action). |
| 4281 | * |
| 4282 | * @param actions |
| 4283 | * @return |
| 4284 | */ |
| 4285 | public Builder setActions(Action... actions) { |
| 4286 | mActions.clear(); |
| 4287 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4288 | if (actions[i] != null) { |
| 4289 | mActions.add(actions[i]); |
| 4290 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4291 | } |
| 4292 | return this; |
| 4293 | } |
| 4294 | |
| 4295 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4296 | * Add a rich notification style to be applied at build time. |
| 4297 | * |
| 4298 | * @param style Object responsible for modifying the notification style. |
| 4299 | */ |
| 4300 | public Builder setStyle(Style style) { |
| 4301 | if (mStyle != style) { |
| 4302 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4303 | if (mStyle != null) { |
| 4304 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4305 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 4306 | } else { |
| 4307 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4308 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4309 | } |
| 4310 | return this; |
| 4311 | } |
| 4312 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4313 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 4314 | * Returns the style set by {@link #setStyle(Style)}. |
| 4315 | */ |
| 4316 | public Style getStyle() { |
| 4317 | return mStyle; |
| 4318 | } |
| 4319 | |
| 4320 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4321 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4322 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4323 | * @return The same Builder. |
| 4324 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 4325 | public Builder setVisibility(@Visibility int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4326 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4327 | return this; |
| 4328 | } |
| 4329 | |
| 4330 | /** |
| 4331 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 4332 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 4333 | * @param n A replacement notification, presumably with some or all info redacted. |
| 4334 | * @return The same Builder. |
| 4335 | */ |
| 4336 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4337 | if (n != null) { |
| 4338 | mN.publicVersion = new Notification(); |
| 4339 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 4340 | } else { |
| 4341 | mN.publicVersion = null; |
| 4342 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4343 | return this; |
| 4344 | } |
| 4345 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4346 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4347 | * Apply an extender to this notification builder. Extenders may be used to add |
| 4348 | * metadata or change options on this builder. |
| 4349 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4350 | public Builder extend(Extender extender) { |
| 4351 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4352 | return this; |
| 4353 | } |
| 4354 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 4355 | /** |
| 4356 | * @hide |
| 4357 | */ |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4358 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4359 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4360 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4361 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4362 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4363 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4364 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4365 | } |
| 4366 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4367 | /** |
| 4368 | * Sets {@link Notification#color}. |
| 4369 | * |
| 4370 | * @param argb The accent color to use |
| 4371 | * |
| 4372 | * @return The same Builder. |
| 4373 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4374 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4375 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4376 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4377 | return this; |
| 4378 | } |
| 4379 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4380 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 4381 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 4382 | // This user can never be a badged profile, |
| 4383 | // and also includes USER_ALL system notifications. |
| 4384 | return null; |
| 4385 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 4386 | // Note: This assumes that the current user can read the profile badge of the |
| 4387 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 4388 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4389 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | private Bitmap getProfileBadge() { |
| 4393 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4394 | if (badge == null) { |
| 4395 | return null; |
| 4396 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4397 | final int size = mContext.getResources().getDimensionPixelSize( |
| 4398 | R.dimen.notification_badge_size); |
| 4399 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4400 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4401 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4402 | badge.draw(canvas); |
| 4403 | return bitmap; |
| 4404 | } |
| 4405 | |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4406 | private void bindProfileBadge(RemoteViews contentView) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4407 | Bitmap profileBadge = getProfileBadge(); |
| 4408 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4409 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4410 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 4411 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4412 | if (isColorized()) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4413 | contentView.setDrawableTint(R.id.profile_badge, false, |
| 4414 | getPrimaryTextColor(), PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4415 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4416 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4417 | } |
| 4418 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4419 | /** |
| 4420 | * @hide |
| 4421 | */ |
| 4422 | public boolean usesStandardHeader() { |
| 4423 | if (mN.mUsesStandardHeader) { |
| 4424 | return true; |
| 4425 | } |
| 4426 | if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.N) { |
| 4427 | if (mN.contentView == null && mN.bigContentView == null) { |
| 4428 | return true; |
| 4429 | } |
| 4430 | } |
| 4431 | boolean contentViewUsesHeader = mN.contentView == null |
| 4432 | || STANDARD_LAYOUTS.contains(mN.contentView.getLayoutId()); |
| 4433 | boolean bigContentViewUsesHeader = mN.bigContentView == null |
| 4434 | || STANDARD_LAYOUTS.contains(mN.bigContentView.getLayoutId()); |
| 4435 | return contentViewUsesHeader && bigContentViewUsesHeader; |
| 4436 | } |
| 4437 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4438 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4439 | resetNotificationHeader(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4440 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4441 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4442 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4443 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4444 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4445 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4446 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4449 | /** |
| 4450 | * Resets the notification header to its original state |
| 4451 | */ |
| 4452 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 4453 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 4454 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 4455 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4456 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 4457 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4458 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 4459 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4460 | contentView.setViewVisibility(R.id.header_text_secondary, View.GONE); |
| 4461 | contentView.setTextViewText(R.id.header_text_secondary, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4462 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4463 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4464 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4465 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4466 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 4467 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 4468 | contentView.setViewVisibility(R.id.alerted_icon, View.GONE); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4469 | mN.mUsesStandardHeader = false; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4470 | } |
| 4471 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4472 | private RemoteViews applyStandardTemplate(int resId, TemplateBindResult result) { |
| 4473 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this), |
| 4474 | result); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | /** |
| 4478 | * @param hasProgress whether the progress bar should be shown and set |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4479 | * @param result |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4480 | */ |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4481 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress, |
| 4482 | TemplateBindResult result) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4483 | return applyStandardTemplate(resId, mParams.reset().hasProgress(hasProgress) |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4484 | .fillTextsFrom(this), result); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 4485 | } |
| 4486 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4487 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p, |
| 4488 | TemplateBindResult result) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 4489 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 4490 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4491 | resetStandardTemplate(contentView); |
| 4492 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4493 | final Bundle ex = mN.extras; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4494 | updateBackgroundColor(contentView); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4495 | bindNotificationHeader(contentView, p.ambient, p.headerTextSecondary); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4496 | bindLargeIconAndReply(contentView, p, result); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4497 | boolean showProgress = handleProgressBar(p.hasProgress, contentView, ex); |
| 4498 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4499 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4500 | contentView.setTextViewText(R.id.title, processTextSpans(p.title)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4501 | if (!p.ambient) { |
| 4502 | setTextViewColorPrimary(contentView, R.id.title); |
| 4503 | } |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 4504 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 4505 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 4506 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4507 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4508 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4509 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 4510 | : com.android.internal.R.id.text; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4511 | contentView.setTextViewText(textId, processTextSpans(p.text)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4512 | if (!p.ambient) { |
| 4513 | setTextViewColorSecondary(contentView, textId); |
| 4514 | } |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4515 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4516 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4517 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4518 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4519 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4520 | return contentView; |
| 4521 | } |
| 4522 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4523 | private CharSequence processTextSpans(CharSequence text) { |
Lucas Dupin | d3c9932 | 2018-09-27 10:22:29 -0700 | [diff] [blame] | 4524 | if (hasForegroundColor() || mInNightMode) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4525 | return ContrastColorUtil.clearColorSpans(text); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4526 | } |
| 4527 | return text; |
| 4528 | } |
| 4529 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4530 | private void setTextViewColorPrimary(RemoteViews contentView, int id) { |
| 4531 | ensureColors(); |
| 4532 | contentView.setTextColor(id, mPrimaryTextColor); |
| 4533 | } |
| 4534 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4535 | private boolean hasForegroundColor() { |
| 4536 | return mForegroundColor != COLOR_INVALID; |
| 4537 | } |
| 4538 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4539 | /** |
| 4540 | * @return the primary text color |
| 4541 | * @hide |
| 4542 | */ |
| 4543 | @VisibleForTesting |
| 4544 | public int getPrimaryTextColor() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4545 | ensureColors(); |
| 4546 | return mPrimaryTextColor; |
| 4547 | } |
| 4548 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4549 | /** |
| 4550 | * @return the secondary text color |
| 4551 | * @hide |
| 4552 | */ |
| 4553 | @VisibleForTesting |
| 4554 | public int getSecondaryTextColor() { |
| 4555 | ensureColors(); |
| 4556 | return mSecondaryTextColor; |
| 4557 | } |
| 4558 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4559 | private void setTextViewColorSecondary(RemoteViews contentView, int id) { |
| 4560 | ensureColors(); |
| 4561 | contentView.setTextColor(id, mSecondaryTextColor); |
| 4562 | } |
| 4563 | |
| 4564 | private void ensureColors() { |
| 4565 | int backgroundColor = getBackgroundColor(); |
| 4566 | if (mPrimaryTextColor == COLOR_INVALID |
| 4567 | || mSecondaryTextColor == COLOR_INVALID |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4568 | || mTextColorsAreForBackground != backgroundColor) { |
| 4569 | mTextColorsAreForBackground = backgroundColor; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4570 | if (!hasForegroundColor() || !isColorized()) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4571 | mPrimaryTextColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 4572 | backgroundColor, mInNightMode); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4573 | mSecondaryTextColor = ContrastColorUtil.resolveSecondaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 4574 | backgroundColor, mInNightMode); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 4575 | if (backgroundColor != COLOR_DEFAULT && isColorized()) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4576 | mPrimaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4577 | mPrimaryTextColor, backgroundColor, 4.5); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4578 | mSecondaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4579 | mSecondaryTextColor, backgroundColor, 4.5); |
| 4580 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4581 | } else { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4582 | double backLum = ContrastColorUtil.calculateLuminance(backgroundColor); |
| 4583 | double textLum = ContrastColorUtil.calculateLuminance(mForegroundColor); |
| 4584 | double contrast = ContrastColorUtil.calculateContrast(mForegroundColor, |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4585 | backgroundColor); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4586 | // We only respect the given colors if worst case Black or White still has |
| 4587 | // contrast |
| 4588 | boolean backgroundLight = backLum > textLum |
| 4589 | && satisfiesTextContrast(backgroundColor, Color.BLACK) |
| 4590 | || backLum <= textLum |
| 4591 | && !satisfiesTextContrast(backgroundColor, Color.WHITE); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4592 | if (contrast < 4.5f) { |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4593 | if (backgroundLight) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4594 | mSecondaryTextColor = ContrastColorUtil.findContrastColor( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4595 | mForegroundColor, |
| 4596 | backgroundColor, |
| 4597 | true /* findFG */, |
| 4598 | 4.5f); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4599 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4600 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_LIGHT); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4601 | } else { |
| 4602 | mSecondaryTextColor = |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4603 | ContrastColorUtil.findContrastColorAgainstDark( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4604 | mForegroundColor, |
| 4605 | backgroundColor, |
| 4606 | true /* findFG */, |
| 4607 | 4.5f); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4608 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4609 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4610 | } |
| 4611 | } else { |
| 4612 | mPrimaryTextColor = mForegroundColor; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4613 | mSecondaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4614 | mPrimaryTextColor, backgroundLight ? LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4615 | : LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4616 | if (ContrastColorUtil.calculateContrast(mSecondaryTextColor, |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4617 | backgroundColor) < 4.5f) { |
| 4618 | // oh well the secondary is not good enough |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4619 | if (backgroundLight) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4620 | mSecondaryTextColor = ContrastColorUtil.findContrastColor( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4621 | mSecondaryTextColor, |
| 4622 | backgroundColor, |
| 4623 | true /* findFG */, |
| 4624 | 4.5f); |
| 4625 | } else { |
| 4626 | mSecondaryTextColor |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4627 | = ContrastColorUtil.findContrastColorAgainstDark( |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4628 | mSecondaryTextColor, |
| 4629 | backgroundColor, |
| 4630 | true /* findFG */, |
| 4631 | 4.5f); |
| 4632 | } |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 4633 | mPrimaryTextColor = ContrastColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4634 | mSecondaryTextColor, backgroundLight |
| 4635 | ? -LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4636 | : -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4640 | } |
| 4641 | } |
| 4642 | |
| 4643 | private void updateBackgroundColor(RemoteViews contentView) { |
| 4644 | if (isColorized()) { |
| 4645 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
| 4646 | getBackgroundColor()); |
| 4647 | } else { |
| 4648 | // Clear it! |
| 4649 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 4650 | 0); |
| 4651 | } |
| 4652 | } |
| 4653 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4654 | /** |
| 4655 | * @param remoteView the remote view to update the minheight in |
| 4656 | * @param hasMinHeight does it have a mimHeight |
| 4657 | * @hide |
| 4658 | */ |
| 4659 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 4660 | int minHeight = 0; |
| 4661 | if (hasMinHeight) { |
| 4662 | // we need to set the minHeight of the notification |
| 4663 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 4664 | com.android.internal.R.dimen.notification_min_content_height); |
| 4665 | } |
| 4666 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 4667 | } |
| 4668 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4669 | private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4670 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4671 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 4672 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 4673 | if (hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4674 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4675 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4676 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4677 | contentView.setProgressBackgroundTintList( |
| 4678 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 4679 | R.color.notification_progress_background_color))); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4680 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4681 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4682 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 4683 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4684 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4685 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4686 | } else { |
| 4687 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4688 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 4689 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4690 | } |
| 4691 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4692 | private void bindLargeIconAndReply(RemoteViews contentView, StandardTemplateParams p, |
| 4693 | TemplateBindResult result) { |
| 4694 | boolean largeIconShown = bindLargeIcon(contentView, p.hideLargeIcon || p.ambient); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4695 | boolean replyIconShown = bindReplyIcon(contentView, p.hideReplyIcon || p.ambient); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4696 | contentView.setViewVisibility(R.id.right_icon_container, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4697 | largeIconShown || replyIconShown ? View.VISIBLE : View.GONE); |
| 4698 | int marginEnd = calculateMarginEnd(largeIconShown, replyIconShown); |
| 4699 | contentView.setViewLayoutMarginEnd(R.id.line1, marginEnd); |
| 4700 | contentView.setViewLayoutMarginEnd(R.id.text, marginEnd); |
| 4701 | contentView.setViewLayoutMarginEnd(R.id.progress, marginEnd); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4702 | if (result != null) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4703 | result.setIconMarginEnd(marginEnd); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4704 | } |
| 4705 | } |
| 4706 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4707 | private int calculateMarginEnd(boolean largeIconShown, boolean replyIconShown) { |
| 4708 | int marginEnd = 0; |
| 4709 | int contentMargin = mContext.getResources().getDimensionPixelSize( |
| 4710 | R.dimen.notification_content_margin_end); |
| 4711 | int iconSize = mContext.getResources().getDimensionPixelSize( |
| 4712 | R.dimen.notification_right_icon_size); |
| 4713 | if (replyIconShown) { |
| 4714 | // The size of the reply icon |
| 4715 | marginEnd += iconSize; |
| 4716 | |
| 4717 | int replyInset = mContext.getResources().getDimensionPixelSize( |
| 4718 | R.dimen.notification_reply_inset); |
| 4719 | // We're subtracting the inset of the reply icon to make sure it's |
| 4720 | // aligned nicely on the right, and remove it from the following padding |
| 4721 | marginEnd -= replyInset * 2; |
| 4722 | } |
| 4723 | if (largeIconShown) { |
| 4724 | // adding size of the right icon |
| 4725 | marginEnd += iconSize; |
| 4726 | |
| 4727 | if (replyIconShown) { |
| 4728 | // We also add some padding to the reply icon if it's around |
| 4729 | marginEnd += contentMargin; |
| 4730 | } |
| 4731 | } |
| 4732 | if (replyIconShown || largeIconShown) { |
| 4733 | // The padding to the content |
| 4734 | marginEnd += contentMargin; |
| 4735 | } |
| 4736 | return marginEnd; |
| 4737 | } |
| 4738 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4739 | /** |
| 4740 | * Bind the large icon. |
| 4741 | * @return if the largeIcon is visible |
| 4742 | */ |
| 4743 | private boolean bindLargeIcon(RemoteViews contentView, boolean hideLargeIcon) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4744 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 4745 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 4746 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4747 | boolean showLargeIcon = mN.mLargeIcon != null && !hideLargeIcon; |
| 4748 | if (showLargeIcon) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4749 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 4750 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
| 4751 | processLargeLegacyIcon(mN.mLargeIcon, contentView); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4752 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4753 | return showLargeIcon; |
| 4754 | } |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4755 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4756 | /** |
| 4757 | * Bind the reply icon. |
| 4758 | * @return if the reply icon is visible |
| 4759 | */ |
| 4760 | private boolean bindReplyIcon(RemoteViews contentView, boolean hideReplyIcon) { |
| 4761 | boolean actionVisible = !hideReplyIcon; |
| 4762 | Action action = null; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4763 | if (actionVisible) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4764 | action = findReplyAction(); |
| 4765 | actionVisible = action != null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4766 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4767 | if (actionVisible) { |
| 4768 | contentView.setViewVisibility(R.id.reply_icon_action, View.VISIBLE); |
| 4769 | contentView.setDrawableTint(R.id.reply_icon_action, |
| 4770 | false /* targetBackground */, |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 4771 | getNeutralColor(), |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4772 | PorterDuff.Mode.SRC_ATOP); |
| 4773 | contentView.setOnClickPendingIntent(R.id.reply_icon_action, action.actionIntent); |
| 4774 | contentView.setRemoteInputs(R.id.reply_icon_action, action.mRemoteInputs); |
| 4775 | } else { |
| 4776 | contentView.setRemoteInputs(R.id.reply_icon_action, null); |
| 4777 | } |
| 4778 | contentView.setViewVisibility(R.id.reply_icon_action, |
| 4779 | actionVisible ? View.VISIBLE : View.GONE); |
| 4780 | return actionVisible; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | private Action findReplyAction() { |
| 4784 | ArrayList<Action> actions = mActions; |
| 4785 | if (mOriginalActions != null) { |
| 4786 | actions = mOriginalActions; |
| 4787 | } |
| 4788 | int numActions = actions.size(); |
| 4789 | for (int i = 0; i < numActions; i++) { |
| 4790 | Action action = actions.get(i); |
| 4791 | if (hasValidRemoteInput(action)) { |
| 4792 | return action; |
| 4793 | } |
| 4794 | } |
| 4795 | return null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4796 | } |
| 4797 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4798 | private void bindNotificationHeader(RemoteViews contentView, boolean ambient, |
| 4799 | CharSequence secondaryHeaderText) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4800 | bindSmallIcon(contentView, ambient); |
| 4801 | bindHeaderAppName(contentView, ambient); |
| 4802 | if (!ambient) { |
| 4803 | // Ambient view does not have these |
| 4804 | bindHeaderText(contentView); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4805 | bindHeaderTextSecondary(contentView, secondaryHeaderText); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4806 | bindHeaderChronometerAndTime(contentView); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4807 | bindProfileBadge(contentView); |
| 4808 | } |
Julia Reynolds | 6013e5c | 2018-04-18 08:43:34 -0400 | [diff] [blame] | 4809 | bindActivePermissions(contentView, ambient); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 4810 | bindExpandButton(contentView); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4811 | mN.mUsesStandardHeader = true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4812 | } |
| 4813 | |
Julia Reynolds | 6013e5c | 2018-04-18 08:43:34 -0400 | [diff] [blame] | 4814 | private void bindActivePermissions(RemoteViews contentView, boolean ambient) { |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 4815 | int color = ambient ? resolveAmbientColor() : getNeutralColor(); |
Julia Reynolds | b887b23 | 2018-04-10 16:38:08 -0400 | [diff] [blame] | 4816 | contentView.setDrawableTint(R.id.camera, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4817 | contentView.setDrawableTint(R.id.mic, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4818 | contentView.setDrawableTint(R.id.overlay, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4819 | } |
| 4820 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4821 | private void bindExpandButton(RemoteViews contentView) { |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 4822 | int color = isColorized() ? getPrimaryTextColor() : getSecondaryTextColor(); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4823 | contentView.setDrawableTint(R.id.expand_button, false, color, |
| 4824 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4825 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4826 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | private void bindHeaderChronometerAndTime(RemoteViews contentView) { |
| 4830 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4831 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4832 | setTextViewColorSecondary(contentView, R.id.time_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4833 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 4834 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 4835 | contentView.setLong(R.id.chronometer, "setBase", |
| 4836 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 4837 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4838 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 4839 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4840 | setTextViewColorSecondary(contentView, R.id.chronometer); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4841 | } else { |
| 4842 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 4843 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4844 | setTextViewColorSecondary(contentView, R.id.time); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4845 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4846 | } else { |
| 4847 | // We still want a time to be set but gone, such that we can show and hide it |
| 4848 | // on demand in case it's a child notification without anything in the header |
| 4849 | 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] | 4850 | } |
| 4851 | } |
| 4852 | |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4853 | private void bindHeaderText(RemoteViews contentView) { |
| 4854 | CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 4855 | if (headerText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4856 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4857 | headerText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4858 | } |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4859 | if (headerText == null |
| 4860 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 4861 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 4862 | headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 4863 | } |
| 4864 | if (headerText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4865 | // 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] | 4866 | contentView.setTextViewText(R.id.header_text, processTextSpans( |
| 4867 | processLegacyText(headerText))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4868 | setTextViewColorSecondary(contentView, R.id.header_text); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4869 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 4870 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4871 | setTextViewColorSecondary(contentView, R.id.header_text_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4872 | } |
| 4873 | } |
| 4874 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4875 | private void bindHeaderTextSecondary(RemoteViews contentView, CharSequence secondaryText) { |
| 4876 | if (!TextUtils.isEmpty(secondaryText)) { |
| 4877 | contentView.setTextViewText(R.id.header_text_secondary, processTextSpans( |
| 4878 | processLegacyText(secondaryText))); |
| 4879 | setTextViewColorSecondary(contentView, R.id.header_text_secondary); |
| 4880 | contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE); |
| 4881 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE); |
| 4882 | setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider); |
| 4883 | } |
| 4884 | } |
| 4885 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4886 | /** |
| 4887 | * @hide |
| 4888 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 4889 | @UnsupportedAppUsage |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4890 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4891 | CharSequence name = null; |
| 4892 | final PackageManager pm = mContext.getPackageManager(); |
| 4893 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 4894 | // only system packages which lump together a bunch of unrelated stuff |
| 4895 | // may substitute a different name to make the purpose of the |
| 4896 | // notification more clear. the correct package label should always |
| 4897 | // be accessible via SystemUI. |
| 4898 | final String pkg = mContext.getPackageName(); |
| 4899 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 4900 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 4901 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 4902 | name = subName; |
| 4903 | } else { |
| 4904 | Log.w(TAG, "warning: pkg " |
| 4905 | + pkg + " attempting to substitute app name '" + subName |
| 4906 | + "' without holding perm " |
| 4907 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 4908 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4909 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4910 | if (TextUtils.isEmpty(name)) { |
| 4911 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 4912 | } |
| 4913 | if (TextUtils.isEmpty(name)) { |
| 4914 | // still nothing? |
| 4915 | return null; |
| 4916 | } |
| 4917 | |
| 4918 | return String.valueOf(name); |
| 4919 | } |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4920 | private void bindHeaderAppName(RemoteViews contentView, boolean ambient) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4921 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4922 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4923 | setTextViewColorPrimary(contentView, R.id.app_name_text); |
| 4924 | } else { |
| 4925 | contentView.setTextColor(R.id.app_name_text, |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 4926 | ambient ? resolveAmbientColor() : getSecondaryTextColor()); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4927 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4928 | } |
| 4929 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4930 | private void bindSmallIcon(RemoteViews contentView, boolean ambient) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4931 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 4932 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 4933 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4934 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4935 | contentView.setInt(R.id.icon, "setImageLevel", mN.iconLevel); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4936 | processSmallIconColor(mN.mSmallIcon, contentView, ambient); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4937 | } |
| 4938 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4939 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4940 | * @return true if the built notification will show the time or the chronometer; false |
| 4941 | * otherwise |
| 4942 | */ |
| 4943 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 4944 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4945 | } |
| 4946 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4947 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4948 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 4949 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4950 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4951 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4952 | |
| 4953 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 4954 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 4955 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, View.GONE); |
| 4956 | big.setViewVisibility(R.id.notification_material_reply_progress, View.GONE); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4957 | |
| 4958 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 4959 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 4960 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 4961 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 4962 | |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 4963 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 4964 | R.dimen.notification_content_margin); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4965 | } |
| 4966 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4967 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 4968 | TemplateBindResult result) { |
| 4969 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this), |
| 4970 | result); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 4971 | } |
| 4972 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame^] | 4973 | private static List<Notification.Action> filterOutContextualActions( |
| 4974 | List<Notification.Action> actions) { |
| 4975 | List<Notification.Action> nonContextualActions = new ArrayList<>(); |
| 4976 | for (Notification.Action action : actions) { |
| 4977 | if (action.getSemanticAction() |
| 4978 | != Action.SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION) { |
| 4979 | nonContextualActions.add(action); |
| 4980 | } |
| 4981 | } |
| 4982 | return nonContextualActions; |
| 4983 | } |
| 4984 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4985 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4986 | StandardTemplateParams p, TemplateBindResult result) { |
| 4987 | RemoteViews big = applyStandardTemplate(layoutId, p, result); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4988 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4989 | resetStandardTemplateWithActions(big); |
| 4990 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4991 | boolean validRemoteInput = false; |
| 4992 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame^] | 4993 | // In the UI contextual actions appear separately from the standard actions, so we |
| 4994 | // filter them out here. |
| 4995 | List<Notification.Action> nonContextualActions = filterOutContextualActions(mActions); |
| 4996 | |
| 4997 | int N = nonContextualActions.size(); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4998 | boolean emphazisedMode = mN.fullScreenIntent != null && !p.ambient; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4999 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5000 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 5001 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5002 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 5003 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5004 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5005 | for (int i=0; i<N; i++) { |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame^] | 5006 | Action action = nonContextualActions.get(i); |
| 5007 | |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 5008 | boolean actionHasValidInput = hasValidRemoteInput(action); |
| 5009 | validRemoteInput |= actionHasValidInput; |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5010 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5011 | final RemoteViews button = generateActionButton(action, emphazisedMode, |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5012 | p.ambient); |
| 5013 | if (actionHasValidInput && !emphazisedMode) { |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 5014 | // Clear the drawable |
| 5015 | button.setInt(R.id.action0, "setBackgroundResource", 0); |
| 5016 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5017 | big.addView(R.id.actions, button); |
| 5018 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 5019 | } else { |
| 5020 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5021 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5022 | |
| 5023 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5024 | if (!p.ambient && validRemoteInput && replyText != null |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5025 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0]) |
| 5026 | && p.maxRemoteInputHistory > 0) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5027 | boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5028 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5029 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, |
| 5030 | View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5031 | big.setTextViewText(R.id.notification_material_reply_text_1, |
| 5032 | processTextSpans(replyText[0])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5033 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 5034 | big.setViewVisibility(R.id.notification_material_reply_progress, |
| 5035 | showSpinner ? View.VISIBLE : View.GONE); |
| 5036 | big.setProgressIndeterminateTintList( |
| 5037 | R.id.notification_material_reply_progress, |
| 5038 | ColorStateList.valueOf( |
| 5039 | isColorized() ? getPrimaryTextColor() : resolveContrastColor())); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5040 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5041 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1]) |
| 5042 | && p.maxRemoteInputHistory > 1) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5043 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5044 | big.setTextViewText(R.id.notification_material_reply_text_2, |
| 5045 | processTextSpans(replyText[1])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5046 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5047 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5048 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2]) |
| 5049 | && p.maxRemoteInputHistory > 2) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5050 | big.setViewVisibility( |
| 5051 | R.id.notification_material_reply_text_3, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5052 | big.setTextViewText(R.id.notification_material_reply_text_3, |
| 5053 | processTextSpans(replyText[2])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5054 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5055 | } |
| 5056 | } |
| 5057 | } |
| 5058 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5059 | return big; |
| 5060 | } |
| 5061 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 5062 | private boolean hasValidRemoteInput(Action action) { |
| 5063 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 5064 | // Weird actions |
| 5065 | return false; |
| 5066 | } |
| 5067 | |
| 5068 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 5069 | if (remoteInputs == null) { |
| 5070 | return false; |
| 5071 | } |
| 5072 | |
| 5073 | for (RemoteInput r : remoteInputs) { |
| 5074 | CharSequence[] choices = r.getChoices(); |
| 5075 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 5076 | return true; |
| 5077 | } |
| 5078 | } |
| 5079 | return false; |
| 5080 | } |
| 5081 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5082 | /** |
| 5083 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 5084 | * 1. Custom contentView from the caller |
| 5085 | * 2. Style's proposed content view |
| 5086 | * 3. Standard template view |
| 5087 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5088 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5089 | return createContentView(false /* increasedheight */ ); |
| 5090 | } |
| 5091 | |
| 5092 | /** |
| 5093 | * Construct a RemoteViews for the smaller content view. |
| 5094 | * |
| 5095 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5096 | * styles may support showing more then just that basic 1U size |
| 5097 | * and the system may decide to render important notifications |
| 5098 | * slightly bigger even when collapsed. |
| 5099 | * |
| 5100 | * @hide |
| 5101 | */ |
| 5102 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5103 | if (mN.contentView != null && useExistingRemoteView()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5104 | return mN.contentView; |
| 5105 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5106 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5107 | if (styleView != null) { |
| 5108 | return styleView; |
| 5109 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5110 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5111 | return applyStandardTemplate(getBaseLayoutResource(), null /* result */); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5112 | } |
| 5113 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5114 | private boolean useExistingRemoteView() { |
| 5115 | return mStyle == null || (!mStyle.displayCustomViewInline() |
| 5116 | && !mRebuildStyledRemoteViews); |
| 5117 | } |
| 5118 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5119 | /** |
| 5120 | * Construct a RemoteViews for the final big notification layout. |
| 5121 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5122 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5123 | RemoteViews result = null; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5124 | if (mN.bigContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5125 | return mN.bigContentView; |
| 5126 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5127 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 5128 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5129 | } else if (mActions.size() != 0) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5130 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5131 | null /* result */); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5132 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5133 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5134 | return result; |
| 5135 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5136 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5137 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 5138 | * Construct a RemoteViews for the final notification header only. This will not be |
| 5139 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5140 | * |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5141 | * @param ambient if true, generate the header for the ambient display layout. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5142 | * @hide |
| 5143 | */ |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5144 | public RemoteViews makeNotificationHeader(boolean ambient) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 5145 | Boolean colorized = (Boolean) mN.extras.get(EXTRA_COLORIZED); |
| 5146 | mN.extras.putBoolean(EXTRA_COLORIZED, false); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5147 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5148 | ambient ? R.layout.notification_template_ambient_header |
| 5149 | : R.layout.notification_template_header); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5150 | resetNotificationHeader(header); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 5151 | bindNotificationHeader(header, ambient, null); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 5152 | if (colorized != null) { |
| 5153 | mN.extras.putBoolean(EXTRA_COLORIZED, colorized); |
| 5154 | } else { |
| 5155 | mN.extras.remove(EXTRA_COLORIZED); |
| 5156 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5157 | return header; |
| 5158 | } |
| 5159 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5160 | /** |
| 5161 | * Construct a RemoteViews for the ambient version of the notification. |
| 5162 | * |
| 5163 | * @hide |
| 5164 | */ |
| 5165 | public RemoteViews makeAmbientNotification() { |
| 5166 | RemoteViews ambient = applyStandardTemplateWithActions( |
| 5167 | R.layout.notification_template_material_ambient, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5168 | mParams.reset().ambient(true).fillTextsFrom(this).hasProgress(false), |
| 5169 | null /* result */); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5170 | return ambient; |
| 5171 | } |
| 5172 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5173 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5174 | if (result != null) { |
| 5175 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 5176 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5177 | } |
| 5178 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5179 | /** |
| 5180 | * Adapt the Notification header if this view is used as an expanded view. |
| 5181 | * |
| 5182 | * @hide |
| 5183 | */ |
| 5184 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5185 | if (result != null) { |
| 5186 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 5187 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5188 | } |
| 5189 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5190 | /** |
| 5191 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5192 | * |
| 5193 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5194 | * styles may support showing more then just that basic 1U size |
| 5195 | * and the system may decide to render important notifications |
| 5196 | * slightly bigger even when collapsed. |
| 5197 | * |
| 5198 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5199 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5200 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5201 | if (mN.headsUpContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5202 | return mN.headsUpContentView; |
| 5203 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5204 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 5205 | if (styleView != null) { |
| 5206 | return styleView; |
| 5207 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5208 | } else if (mActions.size() == 0) { |
| 5209 | return null; |
| 5210 | } |
| 5211 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5212 | // We only want at most a single remote input history to be shown here, otherwise |
| 5213 | // the content would become squished. |
| 5214 | StandardTemplateParams p = mParams.reset().fillTextsFrom(this) |
| 5215 | .setMaxRemoteInputHistory(1); |
| 5216 | return applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5217 | p, |
| 5218 | null /* result */); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5219 | } |
| 5220 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5221 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5222 | * Construct a RemoteViews for the final heads-up notification layout. |
| 5223 | */ |
| 5224 | public RemoteViews createHeadsUpContentView() { |
| 5225 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 5226 | } |
| 5227 | |
| 5228 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5229 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5230 | * |
| 5231 | * @hide |
| 5232 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5233 | @UnsupportedAppUsage |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5234 | public RemoteViews makePublicContentView() { |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5235 | return makePublicView(false /* ambient */); |
| 5236 | } |
| 5237 | |
| 5238 | /** |
| 5239 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5240 | * |
| 5241 | * @hide |
| 5242 | */ |
| 5243 | public RemoteViews makePublicAmbientNotification() { |
| 5244 | return makePublicView(true /* ambient */); |
| 5245 | } |
| 5246 | |
| 5247 | private RemoteViews makePublicView(boolean ambient) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5248 | if (mN.publicVersion != null) { |
| 5249 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5250 | return ambient ? builder.makeAmbientNotification() : builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5251 | } |
| 5252 | Bundle savedBundle = mN.extras; |
| 5253 | Style style = mStyle; |
| 5254 | mStyle = null; |
| 5255 | Icon largeIcon = mN.mLargeIcon; |
| 5256 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5257 | Bitmap largeIconLegacy = mN.largeIcon; |
| 5258 | mN.largeIcon = null; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5259 | ArrayList<Action> actions = mActions; |
| 5260 | mActions = new ArrayList<>(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5261 | Bundle publicExtras = new Bundle(); |
| 5262 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 5263 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 5264 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 5265 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5266 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 5267 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | ed07b96 | 2018-04-30 14:39:35 -0700 | [diff] [blame] | 5268 | String appName = savedBundle.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 5269 | if (appName != null) { |
| 5270 | publicExtras.putString(EXTRA_SUBSTITUTE_APP_NAME, appName); |
| 5271 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5272 | mN.extras = publicExtras; |
Selim Cinek | 499c20f | 2017-07-20 14:06:09 -0700 | [diff] [blame] | 5273 | RemoteViews view; |
| 5274 | if (ambient) { |
| 5275 | publicExtras.putCharSequence(EXTRA_TITLE, |
| 5276 | mContext.getString(com.android.internal.R.string.notification_hidden_text)); |
| 5277 | view = makeAmbientNotification(); |
| 5278 | } else{ |
| 5279 | view = makeNotificationHeader(false /* ambient */); |
| 5280 | view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true); |
| 5281 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5282 | mN.extras = savedBundle; |
| 5283 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5284 | mN.largeIcon = largeIconLegacy; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5285 | mActions = actions; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5286 | mStyle = style; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5287 | return view; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5288 | } |
| 5289 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5290 | /** |
| 5291 | * Construct a content view for the display when low - priority |
| 5292 | * |
| 5293 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 5294 | * a new subtext is created consisting of the content of the |
| 5295 | * notification. |
| 5296 | * @hide |
| 5297 | */ |
| 5298 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
| 5299 | int color = mN.color; |
| 5300 | mN.color = COLOR_DEFAULT; |
| 5301 | CharSequence summary = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 5302 | if (!useRegularSubtext || TextUtils.isEmpty(summary)) { |
| 5303 | CharSequence newSummary = createSummaryText(); |
| 5304 | if (!TextUtils.isEmpty(newSummary)) { |
| 5305 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, newSummary); |
| 5306 | } |
| 5307 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 5308 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5309 | RemoteViews header = makeNotificationHeader(false /* ambient */); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 5310 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5311 | if (summary != null) { |
| 5312 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, summary); |
| 5313 | } else { |
| 5314 | mN.extras.remove(EXTRA_SUB_TEXT); |
| 5315 | } |
| 5316 | mN.color = color; |
| 5317 | return header; |
| 5318 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5319 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5320 | private CharSequence createSummaryText() { |
| 5321 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 5322 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 5323 | return titleText; |
| 5324 | } |
| 5325 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 5326 | if (titleText == null) { |
| 5327 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 5328 | } |
| 5329 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5330 | if (titleText != null) { |
| 5331 | summary.append(bidi.unicodeWrap(titleText)); |
| 5332 | } |
| 5333 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 5334 | if (titleText != null && contentText != null) { |
| 5335 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 5336 | R.string.notification_header_divider_symbol_with_spaces))); |
| 5337 | } |
| 5338 | if (contentText != null) { |
| 5339 | summary.append(bidi.unicodeWrap(contentText)); |
| 5340 | } |
| 5341 | return summary; |
| 5342 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5343 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5344 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5345 | boolean ambient) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5346 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 5347 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5348 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 5349 | : tombstone ? getActionTombstoneLayoutResource() |
| 5350 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5351 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5352 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5353 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5354 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5355 | if (action.mRemoteInputs != null) { |
| 5356 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 5357 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5358 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5359 | // change the background bgColor |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5360 | CharSequence title = action.title; |
| 5361 | ColorStateList[] outResultColor = null; |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5362 | int background = resolveBackgroundColor(); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5363 | if (isLegacy()) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5364 | title = ContrastColorUtil.clearColorSpans(title); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5365 | } else { |
| 5366 | outResultColor = new ColorStateList[1]; |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5367 | title = ensureColorSpanContrast(title, background, outResultColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5368 | } |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5369 | button.setTextViewText(R.id.action0, processTextSpans(title)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5370 | setTextViewColorPrimary(button, R.id.action0); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5371 | int rippleColor; |
| 5372 | boolean hasColorOverride = outResultColor != null && outResultColor[0] != null; |
| 5373 | if (hasColorOverride) { |
| 5374 | // There's a span spanning the full text, let's take it and use it as the |
| 5375 | // background color |
| 5376 | background = outResultColor[0].getDefaultColor(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5377 | int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5378 | background, mInNightMode); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5379 | button.setTextColor(R.id.action0, textColor); |
| 5380 | rippleColor = textColor; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5381 | } else if (mN.color != COLOR_DEFAULT && !isColorized() && mTintActionButtons) { |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5382 | rippleColor = resolveContrastColor(); |
| 5383 | button.setTextColor(R.id.action0, rippleColor); |
| 5384 | } else { |
| 5385 | rippleColor = getPrimaryTextColor(); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5386 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5387 | // We only want about 20% alpha for the ripple |
| 5388 | rippleColor = (rippleColor & 0x00ffffff) | 0x33000000; |
| 5389 | button.setColorStateList(R.id.action0, "setRippleColor", |
| 5390 | ColorStateList.valueOf(rippleColor)); |
| 5391 | button.setColorStateList(R.id.action0, "setButtonBackground", |
| 5392 | ColorStateList.valueOf(background)); |
| 5393 | button.setBoolean(R.id.action0, "setHasStroke", !hasColorOverride); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5394 | } else { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5395 | button.setTextViewText(R.id.action0, processTextSpans( |
| 5396 | processLegacyText(action.title))); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 5397 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5398 | setTextViewColorPrimary(button, R.id.action0); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5399 | } else if (mN.color != COLOR_DEFAULT && mTintActionButtons) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5400 | button.setTextColor(R.id.action0, |
| 5401 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5402 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5403 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5404 | return button; |
| 5405 | } |
| 5406 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5407 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5408 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 5409 | * text if a span was found that spans over the whole text. |
| 5410 | * |
| 5411 | * @param charSequence the charSequence on which the spans are |
| 5412 | * @param background the background color to ensure the contrast against |
| 5413 | * @param outResultColor an array in which a color will be returned as the first element if |
| 5414 | * there exists a full length color span. |
| 5415 | * @return the contrasted charSequence |
| 5416 | */ |
| 5417 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 5418 | ColorStateList[] outResultColor) { |
| 5419 | if (charSequence instanceof Spanned) { |
| 5420 | Spanned ss = (Spanned) charSequence; |
| 5421 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 5422 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 5423 | for (Object span : spans) { |
| 5424 | Object resultSpan = span; |
| 5425 | int spanStart = ss.getSpanStart(span); |
| 5426 | int spanEnd = ss.getSpanEnd(span); |
| 5427 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 5428 | if (resultSpan instanceof CharacterStyle) { |
| 5429 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 5430 | } |
| 5431 | if (resultSpan instanceof TextAppearanceSpan) { |
| 5432 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 5433 | ColorStateList textColor = originalSpan.getTextColor(); |
| 5434 | if (textColor != null) { |
| 5435 | int[] colors = textColor.getColors(); |
| 5436 | int[] newColors = new int[colors.length]; |
| 5437 | for (int i = 0; i < newColors.length; i++) { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5438 | newColors[i] = ContrastColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5439 | colors[i], background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5440 | } |
| 5441 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 5442 | newColors); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5443 | if (fullLength) { |
| 5444 | outResultColor[0] = textColor; |
| 5445 | // Let's drop the color from the span |
| 5446 | textColor = null; |
| 5447 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5448 | resultSpan = new TextAppearanceSpan( |
| 5449 | originalSpan.getFamily(), |
| 5450 | originalSpan.getTextStyle(), |
| 5451 | originalSpan.getTextSize(), |
| 5452 | textColor, |
| 5453 | originalSpan.getLinkTextColor()); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5454 | } |
| 5455 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 5456 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 5457 | int foregroundColor = originalSpan.getForegroundColor(); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5458 | foregroundColor = ContrastColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5459 | foregroundColor, background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5460 | if (fullLength) { |
| 5461 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5462 | resultSpan = null; |
| 5463 | } else { |
| 5464 | resultSpan = new ForegroundColorSpan(foregroundColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5465 | } |
| 5466 | } else { |
| 5467 | resultSpan = span; |
| 5468 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5469 | if (resultSpan != null) { |
| 5470 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 5471 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5472 | } |
| 5473 | return builder; |
| 5474 | } |
| 5475 | return charSequence; |
| 5476 | } |
| 5477 | |
| 5478 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5479 | * @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] | 5480 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5481 | */ |
| 5482 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5483 | if (!mIsLegacyInitialized) { |
| 5484 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 5485 | < Build.VERSION_CODES.LOLLIPOP; |
| 5486 | mIsLegacyInitialized = true; |
| 5487 | } |
| 5488 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5489 | } |
| 5490 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5491 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 5492 | return processLegacyText(charSequence, false /* ambient */); |
| 5493 | } |
| 5494 | |
| 5495 | private CharSequence processLegacyText(CharSequence charSequence, boolean ambient) { |
| 5496 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
| 5497 | boolean wantLightText = ambient; |
| 5498 | if (isAlreadyLightText != wantLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5499 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5500 | } else { |
| 5501 | return charSequence; |
| 5502 | } |
| 5503 | } |
| 5504 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5505 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5506 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5507 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5508 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
| 5509 | boolean ambient) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5510 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5511 | int color; |
| 5512 | if (ambient) { |
| 5513 | color = resolveAmbientColor(); |
| 5514 | } else if (isColorized()) { |
| 5515 | color = getPrimaryTextColor(); |
| 5516 | } else { |
| 5517 | color = resolveContrastColor(); |
| 5518 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5519 | if (colorable) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5520 | contentView.setDrawableTint(R.id.icon, false, color, |
| 5521 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5522 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5523 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5524 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5525 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5526 | } |
| 5527 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5528 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5529 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5530 | * if it's grayscale). |
| 5531 | */ |
| 5532 | // TODO: also check bounds, transparency, that sort of thing. |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5533 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) { |
| 5534 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5535 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5536 | // resolve color will fall back to the default when legacy |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5537 | contentView.setDrawableTint(R.id.icon, false, resolveContrastColor(), |
| 5538 | PorterDuff.Mode.SRC_ATOP); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 5539 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5540 | } |
| 5541 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 5542 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5543 | if (mN.color != COLOR_DEFAULT) { |
| 5544 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5545 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5546 | } |
| 5547 | |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5548 | int resolveContrastColor() { |
| 5549 | if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) { |
| 5550 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5551 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5552 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5553 | int color; |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5554 | int background = mContext.getColor( |
| 5555 | com.android.internal.R.color.notification_material_background_color); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5556 | if (mN.color == COLOR_DEFAULT) { |
| 5557 | ensureColors(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5558 | color = ContrastColorUtil.resolveDefaultColor(mContext, background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5559 | } else { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5560 | color = ContrastColorUtil.resolveContrastColor(mContext, mN.color, |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5561 | background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5562 | } |
| 5563 | if (Color.alpha(color) < 255) { |
| 5564 | // 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] | 5565 | color = ContrastColorUtil.compositeColors(color, background); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5566 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5567 | mCachedContrastColorIsFor = mN.color; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5568 | return mCachedContrastColor = color; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5569 | } |
| 5570 | |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5571 | int resolveNeutralColor() { |
| 5572 | if (mNeutralColor != COLOR_INVALID) { |
| 5573 | return mNeutralColor; |
| 5574 | } |
| 5575 | int background = mContext.getColor( |
| 5576 | com.android.internal.R.color.notification_material_background_color); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 5577 | mNeutralColor = ContrastColorUtil.resolveDefaultColor(mContext, background, |
| 5578 | mInNightMode); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5579 | if (Color.alpha(mNeutralColor) < 255) { |
| 5580 | // 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] | 5581 | mNeutralColor = ContrastColorUtil.compositeColors(mNeutralColor, background); |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5582 | } |
| 5583 | return mNeutralColor; |
| 5584 | } |
| 5585 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5586 | int resolveAmbientColor() { |
| 5587 | if (mCachedAmbientColorIsFor == mN.color && mCachedAmbientColorIsFor != COLOR_INVALID) { |
| 5588 | return mCachedAmbientColor; |
| 5589 | } |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 5590 | final int contrasted = ContrastColorUtil.resolveAmbientColor(mContext, mN.color); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5591 | |
| 5592 | mCachedAmbientColorIsFor = mN.color; |
| 5593 | return mCachedAmbientColor = contrasted; |
| 5594 | } |
| 5595 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5596 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5597 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5598 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5599 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5600 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5601 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5602 | mN.actions = new Action[mActions.size()]; |
| 5603 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5604 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5605 | if (!mPersonList.isEmpty()) { |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 5606 | mN.extras.putParcelableArrayList(EXTRA_PEOPLE_LIST, mPersonList); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 5607 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5608 | if (mN.bigContentView != null || mN.contentView != null |
| 5609 | || mN.headsUpContentView != null) { |
| 5610 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 5611 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5612 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5613 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5614 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5615 | /** |
| 5616 | * Creates a Builder from an existing notification so further changes can be made. |
| 5617 | * @param context The context for your application / activity. |
| 5618 | * @param n The notification to create a Builder from. |
| 5619 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5620 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5621 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5622 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 5623 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5624 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5625 | if (applicationInfo != null) { |
| 5626 | try { |
| 5627 | builderContext = context.createApplicationContext(applicationInfo, |
| 5628 | Context.CONTEXT_RESTRICTED); |
| 5629 | } catch (NameNotFoundException e) { |
| 5630 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 5631 | builderContext = context; // try with our context |
| 5632 | } |
| 5633 | } else { |
| 5634 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5635 | } |
| 5636 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5637 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5638 | } |
| 5639 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5640 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5641 | * @deprecated Use {@link #build()} instead. |
| 5642 | */ |
| 5643 | @Deprecated |
| 5644 | public Notification getNotification() { |
| 5645 | return build(); |
| 5646 | } |
| 5647 | |
| 5648 | /** |
| 5649 | * Combine all of the options that have been set and return a new {@link Notification} |
| 5650 | * object. |
| 5651 | */ |
| 5652 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5653 | // first, add any extras from the calling code |
| 5654 | if (mUserExtras != null) { |
| 5655 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5656 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5657 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5658 | mN.creationTime = System.currentTimeMillis(); |
| 5659 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5660 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5661 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 5662 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5663 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5664 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5665 | if (mStyle != null) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5666 | mStyle.reduceImageSizes(mContext); |
| 5667 | mStyle.purgeResources(); |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 5668 | mStyle.validate(mContext); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5669 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5670 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5671 | mN.reduceImageSizes(mContext); |
| 5672 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5673 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5674 | && (useExistingRemoteView())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5675 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5676 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5677 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 5678 | mN.contentView.getSequenceNumber()); |
| 5679 | } |
| 5680 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5681 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5682 | if (mN.bigContentView != null) { |
| 5683 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 5684 | mN.bigContentView.getSequenceNumber()); |
| 5685 | } |
| 5686 | } |
| 5687 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5688 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5689 | if (mN.headsUpContentView != null) { |
| 5690 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 5691 | mN.headsUpContentView.getSequenceNumber()); |
| 5692 | } |
| 5693 | } |
| 5694 | } |
| 5695 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 5696 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 5697 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 5698 | } |
| 5699 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 5700 | mN.allPendingIntents = null; |
| 5701 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5702 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5703 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5704 | |
| 5705 | /** |
| 5706 | * Apply this Builder to an existing {@link Notification} object. |
| 5707 | * |
| 5708 | * @hide |
| 5709 | */ |
| 5710 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 5711 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5712 | return n; |
| 5713 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5714 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5715 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5716 | * 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] | 5717 | * change. Also removes extenders on low ram devices, as |
| 5718 | * {@link android.service.notification.NotificationListenerService} services are disabled. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5719 | * |
| 5720 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 5721 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5722 | * @hide |
| 5723 | */ |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5724 | public static Notification maybeCloneStrippedForDelivery(Notification n, boolean isLowRam, |
| 5725 | Context context) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5726 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5727 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5728 | // Only strip views for known Styles because we won't know how to |
| 5729 | // re-create them otherwise. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5730 | if (!isLowRam |
| 5731 | && !TextUtils.isEmpty(templateClass) |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5732 | && getNotificationStyleClass(templateClass) == null) { |
| 5733 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5734 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5735 | |
| 5736 | // Only strip unmodified BuilderRemoteViews. |
| 5737 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5738 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5739 | n.contentView.getSequenceNumber(); |
| 5740 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5741 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5742 | n.bigContentView.getSequenceNumber(); |
| 5743 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5744 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5745 | n.headsUpContentView.getSequenceNumber(); |
| 5746 | |
| 5747 | // Nothing to do here, no need to clone. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5748 | if (!isLowRam |
| 5749 | && !stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5750 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5751 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5752 | |
| 5753 | Notification clone = n.clone(); |
| 5754 | if (stripContentView) { |
| 5755 | clone.contentView = null; |
| 5756 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 5757 | } |
| 5758 | if (stripBigContentView) { |
| 5759 | clone.bigContentView = null; |
| 5760 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 5761 | } |
| 5762 | if (stripHeadsUpContentView) { |
| 5763 | clone.headsUpContentView = null; |
| 5764 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 5765 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5766 | if (isLowRam) { |
Kristian Monsen | 05f3479 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5767 | String[] allowedServices = context.getResources().getStringArray( |
| 5768 | R.array.config_allowedManagedServicesOnLowRamDevices); |
| 5769 | if (allowedServices.length == 0) { |
| 5770 | clone.extras.remove(Notification.TvExtender.EXTRA_TV_EXTENDER); |
| 5771 | clone.extras.remove(WearableExtender.EXTRA_WEARABLE_EXTENSIONS); |
| 5772 | clone.extras.remove(CarExtender.EXTRA_CAR_EXTENDER); |
| 5773 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5774 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5775 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5776 | } |
| 5777 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5778 | @UnsupportedAppUsage |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5779 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5780 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5781 | } |
| 5782 | |
| 5783 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5784 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5785 | } |
| 5786 | |
| 5787 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5788 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5792 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5796 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5797 | } |
| 5798 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5799 | private int getMessagingLayoutResource() { |
| 5800 | return R.layout.notification_template_material_messaging; |
| 5801 | } |
| 5802 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5803 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5804 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5805 | } |
| 5806 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5807 | private int getEmphasizedActionLayoutResource() { |
| 5808 | return R.layout.notification_material_action_emphasized; |
| 5809 | } |
| 5810 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5811 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5812 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5813 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5814 | |
| 5815 | private int getBackgroundColor() { |
| 5816 | if (isColorized()) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5817 | return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : mN.color; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5818 | } else { |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5819 | return COLOR_DEFAULT; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5820 | } |
| 5821 | } |
| 5822 | |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5823 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5824 | * Gets a neutral color that can be used for icons or similar that should not stand out. |
| 5825 | */ |
| 5826 | private int getNeutralColor() { |
| 5827 | if (isColorized()) { |
| 5828 | return getSecondaryTextColor(); |
| 5829 | } else { |
| 5830 | return resolveNeutralColor(); |
| 5831 | } |
| 5832 | } |
| 5833 | |
| 5834 | /** |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5835 | * Same as getBackgroundColor but also resolved the default color to the background. |
| 5836 | */ |
| 5837 | private int resolveBackgroundColor() { |
| 5838 | int backgroundColor = getBackgroundColor(); |
| 5839 | if (backgroundColor == COLOR_DEFAULT) { |
| 5840 | backgroundColor = mContext.getColor( |
| 5841 | com.android.internal.R.color.notification_material_background_color); |
| 5842 | } |
| 5843 | return backgroundColor; |
| 5844 | } |
| 5845 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5846 | private boolean isColorized() { |
| 5847 | return mN.isColorized(); |
| 5848 | } |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5849 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5850 | private boolean shouldTintActionButtons() { |
| 5851 | return mTintActionButtons; |
| 5852 | } |
| 5853 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5854 | private boolean textColorsNeedInversion() { |
| 5855 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 5856 | return false; |
| 5857 | } |
| 5858 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 5859 | return targetSdkVersion > Build.VERSION_CODES.M |
| 5860 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 5861 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5862 | |
| 5863 | /** |
| 5864 | * Set a color palette to be used as the background and textColors |
| 5865 | * |
| 5866 | * @param backgroundColor the color to be used as the background |
| 5867 | * @param foregroundColor the color to be used as the foreground |
| 5868 | * |
| 5869 | * @hide |
| 5870 | */ |
| 5871 | public void setColorPalette(int backgroundColor, int foregroundColor) { |
| 5872 | mBackgroundColor = backgroundColor; |
| 5873 | mForegroundColor = foregroundColor; |
| 5874 | mTextColorsAreForBackground = COLOR_INVALID; |
| 5875 | ensureColors(); |
| 5876 | } |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5877 | |
| 5878 | /** |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5879 | * Forces all styled remoteViews to be built from scratch and not use any cached |
| 5880 | * RemoteViews. |
| 5881 | * This is needed for legacy apps that are baking in their remoteviews into the |
| 5882 | * notification. |
| 5883 | * |
| 5884 | * @hide |
| 5885 | */ |
| 5886 | public void setRebuildStyledRemoteViews(boolean rebuild) { |
| 5887 | mRebuildStyledRemoteViews = rebuild; |
| 5888 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5889 | |
| 5890 | /** |
| 5891 | * Get the text that should be displayed in the statusBar when heads upped. This is |
| 5892 | * usually just the app name, but may be different depending on the style. |
| 5893 | * |
| 5894 | * @param publicMode If true, return a text that is safe to display in public. |
| 5895 | * |
| 5896 | * @hide |
| 5897 | */ |
| 5898 | public CharSequence getHeadsUpStatusBarText(boolean publicMode) { |
| 5899 | if (mStyle != null && !publicMode) { |
| 5900 | CharSequence text = mStyle.getHeadsUpStatusBarText(); |
| 5901 | if (!TextUtils.isEmpty(text)) { |
| 5902 | return text; |
| 5903 | } |
| 5904 | } |
| 5905 | return loadHeaderAppName(); |
| 5906 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5907 | } |
| 5908 | |
| 5909 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5910 | * Reduces the image sizes to conform to a maximum allowed size. This also processes all custom |
| 5911 | * remote views. |
| 5912 | * |
| 5913 | * @hide |
| 5914 | */ |
| 5915 | void reduceImageSizes(Context context) { |
| 5916 | if (extras.getBoolean(EXTRA_REDUCED_IMAGES)) { |
| 5917 | return; |
| 5918 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5919 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5920 | if (mLargeIcon != null || largeIcon != null) { |
| 5921 | Resources resources = context.getResources(); |
| 5922 | Class<? extends Style> style = getNotificationStyle(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5923 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5924 | ? R.dimen.notification_right_icon_size_low_ram |
| 5925 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5926 | int maxHeight = maxWidth; |
| 5927 | if (MediaStyle.class.equals(style) |
| 5928 | || DecoratedMediaCustomViewStyle.class.equals(style)) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5929 | maxHeight = resources.getDimensionPixelSize(isLowRam |
| 5930 | ? R.dimen.notification_media_image_max_height_low_ram |
| 5931 | : R.dimen.notification_media_image_max_height); |
| 5932 | maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5933 | ? R.dimen.notification_media_image_max_width_low_ram |
| 5934 | : R.dimen.notification_media_image_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5935 | } |
| 5936 | if (mLargeIcon != null) { |
| 5937 | mLargeIcon.scaleDownIfNecessary(maxWidth, maxHeight); |
| 5938 | } |
| 5939 | if (largeIcon != null) { |
| 5940 | largeIcon = Icon.scaleDownIfNecessary(largeIcon, maxWidth, maxHeight); |
| 5941 | } |
| 5942 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5943 | reduceImageSizesForRemoteView(contentView, context, isLowRam); |
| 5944 | reduceImageSizesForRemoteView(headsUpContentView, context, isLowRam); |
| 5945 | reduceImageSizesForRemoteView(bigContentView, context, isLowRam); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5946 | extras.putBoolean(EXTRA_REDUCED_IMAGES, true); |
| 5947 | } |
| 5948 | |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5949 | private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context, |
| 5950 | boolean isLowRam) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5951 | if (remoteView != null) { |
| 5952 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5953 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5954 | ? R.dimen.notification_custom_view_max_image_width_low_ram |
| 5955 | : R.dimen.notification_custom_view_max_image_width); |
| 5956 | int maxHeight = resources.getDimensionPixelSize(isLowRam |
| 5957 | ? R.dimen.notification_custom_view_max_image_height_low_ram |
| 5958 | : R.dimen.notification_custom_view_max_image_height); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5959 | remoteView.reduceImageSizes(maxWidth, maxHeight); |
| 5960 | } |
| 5961 | } |
| 5962 | |
| 5963 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5964 | * @return whether this notification is a foreground service notification |
Gus Prevas | b0c1a46 | 2018-11-05 11:06:15 -0500 | [diff] [blame] | 5965 | * @hide |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5966 | */ |
Gus Prevas | b0c1a46 | 2018-11-05 11:06:15 -0500 | [diff] [blame] | 5967 | public boolean isForegroundService() { |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5968 | return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5972 | * @return whether this notification has a media session attached |
| 5973 | * @hide |
| 5974 | */ |
| 5975 | public boolean hasMediaSession() { |
| 5976 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 5977 | } |
| 5978 | |
| 5979 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5980 | * @return the style class of this notification |
| 5981 | * @hide |
| 5982 | */ |
| 5983 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 5984 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 5985 | |
| 5986 | if (!TextUtils.isEmpty(templateClass)) { |
| 5987 | return Notification.getNotificationStyleClass(templateClass); |
| 5988 | } |
| 5989 | return null; |
| 5990 | } |
| 5991 | |
| 5992 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5993 | * @return true if this notification is colorized. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5994 | * |
| 5995 | * @hide |
| 5996 | */ |
| 5997 | public boolean isColorized() { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5998 | if (isColorizedMedia()) { |
| 5999 | return true; |
| 6000 | } |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 6001 | return extras.getBoolean(EXTRA_COLORIZED) |
| 6002 | && (hasColorizedPermission() || isForegroundService()); |
| 6003 | } |
| 6004 | |
| 6005 | /** |
| 6006 | * Returns whether an app can colorize due to the android.permission.USE_COLORIZED_NOTIFICATIONS |
| 6007 | * permission. The permission is checked when a notification is enqueued. |
| 6008 | */ |
| 6009 | private boolean hasColorizedPermission() { |
| 6010 | return (flags & Notification.FLAG_CAN_COLORIZE) != 0; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6011 | } |
| 6012 | |
| 6013 | /** |
| 6014 | * @return true if this notification is colorized and it is a media notification |
| 6015 | * |
| 6016 | * @hide |
| 6017 | */ |
| 6018 | public boolean isColorizedMedia() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6019 | Class<? extends Style> style = getNotificationStyle(); |
| 6020 | if (MediaStyle.class.equals(style)) { |
| 6021 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 6022 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 6023 | return true; |
| 6024 | } |
| 6025 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 6026 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 6027 | return true; |
| 6028 | } |
| 6029 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 6030 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6031 | } |
| 6032 | |
Selim Cinek | 0847acd | 2017-04-24 19:48:29 -0700 | [diff] [blame] | 6033 | |
| 6034 | /** |
| 6035 | * @return true if this is a media notification |
| 6036 | * |
| 6037 | * @hide |
| 6038 | */ |
| 6039 | public boolean isMediaNotification() { |
| 6040 | Class<? extends Style> style = getNotificationStyle(); |
| 6041 | if (MediaStyle.class.equals(style)) { |
| 6042 | return true; |
| 6043 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 6044 | return true; |
| 6045 | } |
| 6046 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6047 | } |
| 6048 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6049 | private boolean hasLargeIcon() { |
| 6050 | return mLargeIcon != null || largeIcon != null; |
| 6051 | } |
| 6052 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6053 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6054 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 6055 | * @hide |
| 6056 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6057 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 6058 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 6059 | } |
| 6060 | |
| 6061 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 6062 | * @return true if the notification will show a chronometer; false otherwise |
| 6063 | * @hide |
| 6064 | */ |
| 6065 | public boolean showsChronometer() { |
| 6066 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 6067 | } |
| 6068 | |
| 6069 | /** |
Julia Reynolds | 7ca3307 | 2017-06-29 13:58:24 -0400 | [diff] [blame] | 6070 | * @removed |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 6071 | */ |
| 6072 | @SystemApi |
| 6073 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 6074 | Class<? extends Style>[] classes = new Class[] { |
| 6075 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 6076 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 6077 | MessagingStyle.class }; |
| 6078 | for (Class<? extends Style> innerClass : classes) { |
| 6079 | if (templateClass.equals(innerClass.getName())) { |
| 6080 | return innerClass; |
| 6081 | } |
| 6082 | } |
| 6083 | return null; |
| 6084 | } |
| 6085 | |
| 6086 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6087 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 6088 | * object. |
| 6089 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 6090 | public static abstract class Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 6091 | |
| 6092 | /** |
| 6093 | * The number of items allowed simulatanously in the remote input history. |
| 6094 | * @hide |
| 6095 | */ |
| 6096 | static final int MAX_REMOTE_INPUT_HISTORY_LINES = 3; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6097 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6098 | |
| 6099 | /** |
| 6100 | * @hide |
| 6101 | */ |
| 6102 | protected CharSequence mSummaryText = null; |
| 6103 | |
| 6104 | /** |
| 6105 | * @hide |
| 6106 | */ |
| 6107 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6108 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6109 | protected Builder mBuilder; |
| 6110 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6111 | /** |
| 6112 | * Overrides ContentTitle in the big form of the template. |
| 6113 | * This defaults to the value passed to setContentTitle(). |
| 6114 | */ |
| 6115 | protected void internalSetBigContentTitle(CharSequence title) { |
| 6116 | mBigContentTitle = title; |
| 6117 | } |
| 6118 | |
| 6119 | /** |
| 6120 | * Set the first line of text after the detail section in the big form of the template. |
| 6121 | */ |
| 6122 | protected void internalSetSummaryText(CharSequence cs) { |
| 6123 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 6124 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6125 | } |
| 6126 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6127 | public void setBuilder(Builder builder) { |
| 6128 | if (mBuilder != builder) { |
| 6129 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 6130 | if (mBuilder != null) { |
| 6131 | mBuilder.setStyle(this); |
| 6132 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6133 | } |
| 6134 | } |
| 6135 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6136 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6137 | if (mBuilder == null) { |
| 6138 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 6139 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6140 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6141 | |
| 6142 | protected RemoteViews getStandardView(int layoutId) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6143 | return getStandardView(layoutId, null); |
| 6144 | } |
| 6145 | |
| 6146 | /** |
| 6147 | * Get the standard view for this style. |
| 6148 | * |
| 6149 | * @param layoutId The layout id to use |
| 6150 | * @param result The result where template bind information is saved. |
| 6151 | * @return A remoteView for this style. |
| 6152 | * @hide |
| 6153 | */ |
| 6154 | protected RemoteViews getStandardView(int layoutId, TemplateBindResult result) { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6155 | checkBuilder(); |
| 6156 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6157 | // Nasty. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6158 | CharSequence oldBuilderContentTitle = |
| 6159 | mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6160 | if (mBigContentTitle != null) { |
| 6161 | mBuilder.setContentTitle(mBigContentTitle); |
| 6162 | } |
| 6163 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6164 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId, result); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6165 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6166 | mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6167 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6168 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 6169 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 6170 | } else { |
| 6171 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6172 | } |
| 6173 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6174 | return contentView; |
| 6175 | } |
| 6176 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6177 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6178 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6179 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6180 | * |
| 6181 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6182 | * @hide |
| 6183 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6184 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6185 | return null; |
| 6186 | } |
| 6187 | |
| 6188 | /** |
| 6189 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 6190 | * @hide |
| 6191 | */ |
| 6192 | public RemoteViews makeBigContentView() { |
| 6193 | return null; |
| 6194 | } |
| 6195 | |
| 6196 | /** |
| 6197 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6198 | * |
| 6199 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6200 | * @hide |
| 6201 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6202 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6203 | return null; |
| 6204 | } |
| 6205 | |
| 6206 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6207 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6208 | * @hide |
| 6209 | */ |
| 6210 | public void addExtras(Bundle extras) { |
| 6211 | if (mSummaryTextSet) { |
| 6212 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 6213 | } |
| 6214 | if (mBigContentTitle != null) { |
| 6215 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 6216 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 6217 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6218 | } |
| 6219 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6220 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6221 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6222 | * @hide |
| 6223 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6224 | protected void restoreFromExtras(Bundle extras) { |
| 6225 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 6226 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 6227 | mSummaryTextSet = true; |
| 6228 | } |
| 6229 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 6230 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 6231 | } |
| 6232 | } |
| 6233 | |
| 6234 | |
| 6235 | /** |
| 6236 | * @hide |
| 6237 | */ |
| 6238 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6239 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6240 | return wip; |
| 6241 | } |
| 6242 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6243 | /** |
| 6244 | * @hide |
| 6245 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6246 | public void purgeResources() {} |
| 6247 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6248 | /** |
| 6249 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 6250 | * attached to. |
| 6251 | * |
| 6252 | * @return the fully constructed Notification. |
| 6253 | */ |
| 6254 | public Notification build() { |
| 6255 | checkBuilder(); |
| 6256 | return mBuilder.build(); |
| 6257 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6258 | |
| 6259 | /** |
| 6260 | * @hide |
| 6261 | * @return true if the style positions the progress bar on the second line; false if the |
| 6262 | * style hides the progress bar |
| 6263 | */ |
| 6264 | protected boolean hasProgress() { |
| 6265 | return true; |
| 6266 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6267 | |
| 6268 | /** |
| 6269 | * @hide |
| 6270 | * @return Whether we should put the summary be put into the notification header |
| 6271 | */ |
| 6272 | public boolean hasSummaryInHeader() { |
| 6273 | return true; |
| 6274 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6275 | |
| 6276 | /** |
| 6277 | * @hide |
| 6278 | * @return Whether custom content views are displayed inline in the style |
| 6279 | */ |
| 6280 | public boolean displayCustomViewInline() { |
| 6281 | return false; |
| 6282 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6283 | |
| 6284 | /** |
| 6285 | * Reduces the image sizes contained in this style. |
| 6286 | * |
| 6287 | * @hide |
| 6288 | */ |
| 6289 | public void reduceImageSizes(Context context) { |
| 6290 | } |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6291 | |
| 6292 | /** |
| 6293 | * Validate that this style was properly composed. This is called at build time. |
| 6294 | * @hide |
| 6295 | */ |
| 6296 | public void validate(Context context) { |
| 6297 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6298 | |
| 6299 | /** |
| 6300 | * @hide |
| 6301 | */ |
| 6302 | public abstract boolean areNotificationsVisiblyDifferent(Style other); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 6303 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6304 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6305 | * @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] | 6306 | * If {@code null} is returned, the default implementation will be used. |
| 6307 | * |
| 6308 | * @hide |
| 6309 | */ |
| 6310 | public CharSequence getHeadsUpStatusBarText() { |
| 6311 | return null; |
| 6312 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 6313 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6314 | |
| 6315 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6316 | * 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] | 6317 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6318 | * 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] | 6319 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6320 | * Notification notif = new Notification.Builder(mContext) |
| 6321 | * .setContentTitle("New photo from " + sender.toString()) |
| 6322 | * .setContentText(subject) |
| 6323 | * .setSmallIcon(R.drawable.new_post) |
| 6324 | * .setLargeIcon(aBitmap) |
| 6325 | * .setStyle(new Notification.BigPictureStyle() |
| 6326 | * .bigPicture(aBigBitmap)) |
| 6327 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6328 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6329 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6330 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6331 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6332 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6333 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6334 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6335 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6336 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6337 | public BigPictureStyle() { |
| 6338 | } |
| 6339 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6340 | /** |
| 6341 | * @deprecated use {@code BigPictureStyle()}. |
| 6342 | */ |
| 6343 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6344 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6345 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6346 | } |
| 6347 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6348 | /** |
| 6349 | * Overrides ContentTitle in the big form of the template. |
| 6350 | * This defaults to the value passed to setContentTitle(). |
| 6351 | */ |
| 6352 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6353 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6354 | return this; |
| 6355 | } |
| 6356 | |
| 6357 | /** |
| 6358 | * Set the first line of text after the detail section in the big form of the template. |
| 6359 | */ |
| 6360 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6361 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6362 | return this; |
| 6363 | } |
| 6364 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6365 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6366 | * @hide |
| 6367 | */ |
| 6368 | public Bitmap getBigPicture() { |
| 6369 | return mPicture; |
| 6370 | } |
| 6371 | |
| 6372 | /** |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6373 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 6374 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6375 | public BigPictureStyle bigPicture(Bitmap b) { |
| 6376 | mPicture = b; |
| 6377 | return this; |
| 6378 | } |
| 6379 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6380 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6381 | * Override the large icon when the big notification is shown. |
| 6382 | */ |
| 6383 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6384 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 6385 | } |
| 6386 | |
| 6387 | /** |
| 6388 | * Override the large icon when the big notification is shown. |
| 6389 | */ |
| 6390 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6391 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6392 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6393 | return this; |
| 6394 | } |
| 6395 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6396 | /** @hide */ |
| 6397 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 6398 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6399 | /** |
| 6400 | * @hide |
| 6401 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6402 | @Override |
| 6403 | public void purgeResources() { |
| 6404 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 6405 | if (mPicture != null && |
| 6406 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6407 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6408 | mPicture = mPicture.createAshmemBitmap(); |
| 6409 | } |
| 6410 | if (mBigLargeIcon != null) { |
| 6411 | mBigLargeIcon.convertToAshmem(); |
| 6412 | } |
| 6413 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6414 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6415 | /** |
| 6416 | * @hide |
| 6417 | */ |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6418 | @Override |
| 6419 | public void reduceImageSizes(Context context) { |
| 6420 | super.reduceImageSizes(context); |
| 6421 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6422 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6423 | if (mPicture != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6424 | int maxPictureWidth = resources.getDimensionPixelSize(isLowRam |
| 6425 | ? R.dimen.notification_big_picture_max_height_low_ram |
| 6426 | : R.dimen.notification_big_picture_max_height); |
| 6427 | int maxPictureHeight = resources.getDimensionPixelSize(isLowRam |
| 6428 | ? R.dimen.notification_big_picture_max_width_low_ram |
| 6429 | : R.dimen.notification_big_picture_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6430 | mPicture = Icon.scaleDownIfNecessary(mPicture, maxPictureWidth, maxPictureHeight); |
| 6431 | } |
| 6432 | if (mBigLargeIcon != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6433 | int rightIconSize = resources.getDimensionPixelSize(isLowRam |
| 6434 | ? R.dimen.notification_right_icon_size_low_ram |
| 6435 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6436 | mBigLargeIcon.scaleDownIfNecessary(rightIconSize, rightIconSize); |
| 6437 | } |
| 6438 | } |
| 6439 | |
| 6440 | /** |
| 6441 | * @hide |
| 6442 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6443 | public RemoteViews makeBigContentView() { |
| 6444 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6445 | // This covers the following cases: |
| 6446 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6447 | // mN.mLargeIcon |
| 6448 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6449 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6450 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6451 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6452 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 6453 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6454 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 6455 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 6456 | // for old listeners, this is in general non-null. |
| 6457 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 6458 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6459 | } |
| 6460 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6461 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource(), |
| 6462 | null /* result */); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6463 | if (mSummaryTextSet) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6464 | contentView.setTextViewText(R.id.text, mBuilder.processTextSpans( |
| 6465 | mBuilder.processLegacyText(mSummaryText))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6466 | mBuilder.setTextViewColorSecondary(contentView, R.id.text); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 6467 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6468 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6469 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 6470 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6471 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6472 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6473 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6474 | } |
| 6475 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6476 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6477 | return contentView; |
| 6478 | } |
| 6479 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6480 | /** |
| 6481 | * @hide |
| 6482 | */ |
| 6483 | public void addExtras(Bundle extras) { |
| 6484 | super.addExtras(extras); |
| 6485 | |
| 6486 | if (mBigLargeIconSet) { |
| 6487 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 6488 | } |
| 6489 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 6490 | } |
| 6491 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6492 | /** |
| 6493 | * @hide |
| 6494 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6495 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6496 | protected void restoreFromExtras(Bundle extras) { |
| 6497 | super.restoreFromExtras(extras); |
| 6498 | |
| 6499 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6500 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6501 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6502 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6503 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 6504 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6505 | |
| 6506 | /** |
| 6507 | * @hide |
| 6508 | */ |
| 6509 | @Override |
| 6510 | public boolean hasSummaryInHeader() { |
| 6511 | return false; |
| 6512 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6513 | |
| 6514 | /** |
| 6515 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6516 | * Note that we aren't actually comparing the contents of the bitmaps here, so this |
| 6517 | * 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] | 6518 | */ |
| 6519 | @Override |
| 6520 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6521 | if (other == null || getClass() != other.getClass()) { |
| 6522 | return true; |
| 6523 | } |
| 6524 | BigPictureStyle otherS = (BigPictureStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6525 | return areBitmapsObviouslyDifferent(getBigPicture(), otherS.getBigPicture()); |
| 6526 | } |
| 6527 | |
| 6528 | private static boolean areBitmapsObviouslyDifferent(Bitmap a, Bitmap b) { |
| 6529 | if (a == b) { |
| 6530 | return false; |
| 6531 | } |
| 6532 | if (a == null || b == null) { |
| 6533 | return true; |
| 6534 | } |
| 6535 | return a.getWidth() != b.getWidth() |
| 6536 | || a.getHeight() != b.getHeight() |
| 6537 | || a.getConfig() != b.getConfig() |
| 6538 | || a.getGenerationId() != b.getGenerationId(); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6539 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6540 | } |
| 6541 | |
| 6542 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6543 | * 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] | 6544 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6545 | * 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] | 6546 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6547 | * Notification notif = new Notification.Builder(mContext) |
| 6548 | * .setContentTitle("New mail from " + sender.toString()) |
| 6549 | * .setContentText(subject) |
| 6550 | * .setSmallIcon(R.drawable.new_mail) |
| 6551 | * .setLargeIcon(aBitmap) |
| 6552 | * .setStyle(new Notification.BigTextStyle() |
| 6553 | * .bigText(aVeryLongString)) |
| 6554 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6555 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6556 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6557 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6558 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6559 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6560 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6561 | private CharSequence mBigText; |
| 6562 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6563 | public BigTextStyle() { |
| 6564 | } |
| 6565 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6566 | /** |
| 6567 | * @deprecated use {@code BigTextStyle()}. |
| 6568 | */ |
| 6569 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6570 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6571 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6572 | } |
| 6573 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6574 | /** |
| 6575 | * Overrides ContentTitle in the big form of the template. |
| 6576 | * This defaults to the value passed to setContentTitle(). |
| 6577 | */ |
| 6578 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6579 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6580 | return this; |
| 6581 | } |
| 6582 | |
| 6583 | /** |
| 6584 | * Set the first line of text after the detail section in the big form of the template. |
| 6585 | */ |
| 6586 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6587 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6588 | return this; |
| 6589 | } |
| 6590 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6591 | /** |
| 6592 | * Provide the longer text to be displayed in the big form of the |
| 6593 | * template in place of the content text. |
| 6594 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6595 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6596 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6597 | return this; |
| 6598 | } |
| 6599 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6600 | /** |
| 6601 | * @hide |
| 6602 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6603 | public CharSequence getBigText() { |
| 6604 | return mBigText; |
| 6605 | } |
| 6606 | |
| 6607 | /** |
| 6608 | * @hide |
| 6609 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6610 | public void addExtras(Bundle extras) { |
| 6611 | super.addExtras(extras); |
| 6612 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6613 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 6614 | } |
| 6615 | |
| 6616 | /** |
| 6617 | * @hide |
| 6618 | */ |
| 6619 | @Override |
| 6620 | protected void restoreFromExtras(Bundle extras) { |
| 6621 | super.restoreFromExtras(extras); |
| 6622 | |
| 6623 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6624 | } |
| 6625 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6626 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6627 | * @param increasedHeight true if this layout be created with an increased height. |
| 6628 | * |
| 6629 | * @hide |
| 6630 | */ |
| 6631 | @Override |
| 6632 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6633 | if (increasedHeight) { |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6634 | mBuilder.mOriginalActions = mBuilder.mActions; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6635 | mBuilder.mActions = new ArrayList<>(); |
| 6636 | RemoteViews remoteViews = makeBigContentView(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6637 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6638 | mBuilder.mOriginalActions = null; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6639 | return remoteViews; |
| 6640 | } |
| 6641 | return super.makeContentView(increasedHeight); |
| 6642 | } |
| 6643 | |
| 6644 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6645 | * @hide |
| 6646 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6647 | @Override |
| 6648 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 6649 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 6650 | return makeBigContentView(); |
| 6651 | } |
| 6652 | return super.makeHeadsUpContentView(increasedHeight); |
| 6653 | } |
| 6654 | |
| 6655 | /** |
| 6656 | * @hide |
| 6657 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6658 | public RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6659 | |
| 6660 | // Nasty |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6661 | CharSequence text = mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6662 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 6663 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6664 | TemplateBindResult result = new TemplateBindResult(); |
| 6665 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource(), result); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 6666 | contentView.setInt(R.id.big_text, "setImageEndMargin", result.getIconMarginEnd()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6667 | |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6668 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, text); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6669 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 6670 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6671 | if (TextUtils.isEmpty(bigTextText)) { |
| 6672 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 6673 | // experience |
| 6674 | bigTextText = mBuilder.processLegacyText(text); |
| 6675 | } |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6676 | applyBigTextContentView(mBuilder, contentView, bigTextText); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 6677 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6678 | return contentView; |
| 6679 | } |
| 6680 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6681 | /** |
| 6682 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6683 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6684 | */ |
| 6685 | @Override |
| 6686 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6687 | if (other == null || getClass() != other.getClass()) { |
| 6688 | return true; |
| 6689 | } |
| 6690 | BigTextStyle newS = (BigTextStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6691 | return !Objects.equals(String.valueOf(getBigText()), String.valueOf(newS.getBigText())); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6692 | } |
| 6693 | |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6694 | static void applyBigTextContentView(Builder builder, |
| 6695 | RemoteViews contentView, CharSequence bigTextText) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6696 | contentView.setTextViewText(R.id.big_text, builder.processTextSpans(bigTextText)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6697 | builder.setTextViewColorSecondary(contentView, R.id.big_text); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6698 | contentView.setViewVisibility(R.id.big_text, |
| 6699 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6700 | contentView.setBoolean(R.id.big_text, "setHasImage", builder.mN.hasLargeIcon()); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6701 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6702 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6703 | |
| 6704 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6705 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 6706 | * messages of varying types between any number of people. |
| 6707 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6708 | * <p> |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6709 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 6710 | * user will always see the normal notification view. |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6711 | * |
| 6712 | * <p> |
| 6713 | * If the app is targeting Android P and above, it is required to use the {@link Person} |
| 6714 | * class in order to get an optimal rendering of the notification and its avatars. For |
| 6715 | * conversations involving multiple people, the app should also make sure that it marks the |
| 6716 | * conversation as a group with {@link #setGroupConversation(boolean)}. |
| 6717 | * |
| 6718 | * <p> |
| 6719 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior. |
| 6720 | * Here's an example of how this may be used: |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6721 | * <pre class="prettyprint"> |
| 6722 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6723 | * Person user = new Person.Builder().setIcon(userIcon).setName(userName).build(); |
| 6724 | * MessagingStyle style = new MessagingStyle(user) |
| 6725 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getPerson()) |
| 6726 | * .addMessage(messages[2].getText(), messages[2].getTime(), messages[2].getPerson()) |
| 6727 | * .setGroupConversation(hasMultiplePeople()); |
| 6728 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6729 | * Notification noti = new Notification.Builder() |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6730 | * .setContentTitle("2 new messages with " + sender.toString()) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6731 | * .setContentText(subject) |
| 6732 | * .setSmallIcon(R.drawable.new_message) |
| 6733 | * .setLargeIcon(aBitmap) |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6734 | * .setStyle(style) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6735 | * .build(); |
| 6736 | * </pre> |
| 6737 | */ |
| 6738 | public static class MessagingStyle extends Style { |
| 6739 | |
| 6740 | /** |
| 6741 | * The maximum number of messages that will be retained in the Notification itself (the |
| 6742 | * number displayed is up to the platform). |
| 6743 | */ |
| 6744 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 6745 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6746 | @NonNull Person mUser; |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6747 | @Nullable CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6748 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6749 | List<Message> mHistoricMessages = new ArrayList<>(); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6750 | boolean mIsGroupConversation; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6751 | |
| 6752 | MessagingStyle() { |
| 6753 | } |
| 6754 | |
| 6755 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6756 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 6757 | * user before the posting app reposts the notification with those messages after they've |
| 6758 | * 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] | 6759 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6760 | * |
| 6761 | * @deprecated use {@code MessagingStyle(Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6762 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6763 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6764 | this(new Person.Builder().setName(userDisplayName).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6765 | } |
| 6766 | |
| 6767 | /** |
| 6768 | * @param user Required - The person displayed for any messages that are sent by the |
| 6769 | * user. Any messages added with {@link #addMessage(Notification.MessagingStyle.Message)} |
| 6770 | * 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] | 6771 | * by this user. The user also needs to have a valid name associated with it, which will |
| 6772 | * be enforced starting in Android P. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6773 | */ |
| 6774 | public MessagingStyle(@NonNull Person user) { |
| 6775 | mUser = user; |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6776 | } |
| 6777 | |
| 6778 | /** |
| 6779 | * Validate that this style was properly composed. This is called at build time. |
| 6780 | * @hide |
| 6781 | */ |
| 6782 | @Override |
| 6783 | public void validate(Context context) { |
| 6784 | super.validate(context); |
| 6785 | if (context.getApplicationInfo().targetSdkVersion |
| 6786 | >= Build.VERSION_CODES.P && (mUser == null || mUser.getName() == null)) { |
| 6787 | throw new RuntimeException("User must be valid and have a name."); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6788 | } |
| 6789 | } |
| 6790 | |
| 6791 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6792 | * @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] | 6793 | * If {@code null} is returned, the default implementation will be used. |
| 6794 | * |
| 6795 | * @hide |
| 6796 | */ |
| 6797 | @Override |
| 6798 | public CharSequence getHeadsUpStatusBarText() { |
| 6799 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
| 6800 | ? super.mBigContentTitle |
| 6801 | : mConversationTitle; |
| 6802 | if (!TextUtils.isEmpty(conversationTitle) && !hasOnlyWhiteSpaceSenders()) { |
| 6803 | return conversationTitle; |
| 6804 | } |
| 6805 | return null; |
| 6806 | } |
| 6807 | |
| 6808 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6809 | * @return the user to be displayed for any replies sent by the user |
| 6810 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6811 | @NonNull |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6812 | public Person getUser() { |
| 6813 | return mUser; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6814 | } |
| 6815 | |
| 6816 | /** |
| 6817 | * 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] | 6818 | * |
| 6819 | * @deprecated use {@link #getUser()} instead |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6820 | */ |
| 6821 | public CharSequence getUserDisplayName() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6822 | return mUser.getName(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6823 | } |
| 6824 | |
| 6825 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6826 | * Sets the title to be displayed on this conversation. May be set to {@code null}. |
| 6827 | * |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6828 | * <p>This API's behavior was changed in SDK version {@link Build.VERSION_CODES#P}. If your |
| 6829 | * application's target version is less than {@link Build.VERSION_CODES#P}, setting a |
| 6830 | * conversation title to a non-null value will make {@link #isGroupConversation()} return |
| 6831 | * {@code true} and passing {@code null} will make it return {@code false}. In |
| 6832 | * {@link Build.VERSION_CODES#P} and beyond, use {@link #setGroupConversation(boolean)} |
| 6833 | * to set group conversation status. |
| 6834 | * |
| 6835 | * @param conversationTitle Title displayed for this conversation |
| 6836 | * @return this object for method chaining |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6837 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6838 | public MessagingStyle setConversationTitle(@Nullable CharSequence conversationTitle) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6839 | mConversationTitle = conversationTitle; |
| 6840 | return this; |
| 6841 | } |
| 6842 | |
| 6843 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6844 | * 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] | 6845 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6846 | @Nullable |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6847 | public CharSequence getConversationTitle() { |
| 6848 | return mConversationTitle; |
| 6849 | } |
| 6850 | |
| 6851 | /** |
| 6852 | * Adds a message for display by this notification. Convenience call for a simple |
| 6853 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6854 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6855 | * @param timestamp Time at which the message arrived |
| 6856 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 6857 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 6858 | * the platform will insert {@link #getUserDisplayName()}. |
| 6859 | * Should be unique amongst all individuals in the conversation, and should be |
| 6860 | * consistent during re-posts of the notification. |
| 6861 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 6862 | * @see Message#Notification.MessagingStyle.Message(CharSequence, long, CharSequence) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6863 | * |
| 6864 | * @return this object for method chaining |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6865 | * |
| 6866 | * @deprecated use {@link #addMessage(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6867 | */ |
| 6868 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6869 | return addMessage(text, timestamp, |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6870 | sender == null ? null : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6871 | } |
| 6872 | |
| 6873 | /** |
| 6874 | * Adds a message for display by this notification. Convenience call for a simple |
| 6875 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6876 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6877 | * @param timestamp Time at which the message arrived |
| 6878 | * @param sender The {@link Person} who sent the message. |
| 6879 | * Should be <code>null</code> for messages by the current user, in which case |
| 6880 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 6881 | * |
Aurimas Liutikas | e701dc1 | 2018-06-01 16:04:37 -0700 | [diff] [blame] | 6882 | * @see Message#Notification.MessagingStyle.Message(CharSequence, long, CharSequence) |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6883 | * |
| 6884 | * @return this object for method chaining |
| 6885 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6886 | public MessagingStyle addMessage(@NonNull CharSequence text, long timestamp, |
| 6887 | @Nullable Person sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6888 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | /** |
| 6892 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6893 | * |
| 6894 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6895 | * the newest last. |
| 6896 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6897 | * @param message The {@link Message} to be displayed |
| 6898 | * @return this object for method chaining |
| 6899 | */ |
| 6900 | public MessagingStyle addMessage(Message message) { |
| 6901 | mMessages.add(message); |
| 6902 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 6903 | mMessages.remove(0); |
| 6904 | } |
| 6905 | return this; |
| 6906 | } |
| 6907 | |
| 6908 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6909 | * Adds a {@link Message} for historic context in this notification. |
| 6910 | * |
| 6911 | * <p>Messages should be added as historic if they are not the main subject of the |
| 6912 | * notification but may give context to a conversation. The system may choose to present |
| 6913 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 6914 | * |
| 6915 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6916 | * the newest last. |
| 6917 | * |
| 6918 | * @param message The historic {@link Message} to be added |
| 6919 | * @return this object for method chaining |
| 6920 | */ |
| 6921 | public MessagingStyle addHistoricMessage(Message message) { |
| 6922 | mHistoricMessages.add(message); |
| 6923 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 6924 | mHistoricMessages.remove(0); |
| 6925 | } |
| 6926 | return this; |
| 6927 | } |
| 6928 | |
| 6929 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6930 | * Gets the list of {@code Message} objects that represent the notification |
| 6931 | */ |
| 6932 | public List<Message> getMessages() { |
| 6933 | return mMessages; |
| 6934 | } |
| 6935 | |
| 6936 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6937 | * Gets the list of historic {@code Message}s in the notification. |
| 6938 | */ |
| 6939 | public List<Message> getHistoricMessages() { |
| 6940 | return mHistoricMessages; |
| 6941 | } |
| 6942 | |
| 6943 | /** |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6944 | * Sets whether this conversation notification represents a group. If the app is targeting |
| 6945 | * Android P, this is required if the app wants to display the largeIcon set with |
| 6946 | * {@link Notification.Builder#setLargeIcon(Bitmap)}, otherwise it will be hidden. |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6947 | * |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6948 | * @param isGroupConversation {@code true} if the conversation represents a group, |
| 6949 | * {@code false} otherwise. |
| 6950 | * @return this object for method chaining |
| 6951 | */ |
| 6952 | public MessagingStyle setGroupConversation(boolean isGroupConversation) { |
| 6953 | mIsGroupConversation = isGroupConversation; |
| 6954 | return this; |
| 6955 | } |
| 6956 | |
| 6957 | /** |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6958 | * Returns {@code true} if this notification represents a group conversation, otherwise |
| 6959 | * {@code false}. |
| 6960 | * |
| 6961 | * <p> If the application that generated this {@link MessagingStyle} targets an SDK version |
| 6962 | * less than {@link Build.VERSION_CODES#P}, this method becomes dependent on whether or |
| 6963 | * not the conversation title is set; returning {@code true} if the conversation title is |
| 6964 | * a non-null value, or {@code false} otherwise. From {@link Build.VERSION_CODES#P} forward, |
| 6965 | * this method returns what's set by {@link #setGroupConversation(boolean)} allowing for |
| 6966 | * named, non-group conversations. |
| 6967 | * |
| 6968 | * @see #setConversationTitle(CharSequence) |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6969 | */ |
| 6970 | public boolean isGroupConversation() { |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6971 | // When target SDK version is < P, a non-null conversation title dictates if this is |
| 6972 | // as group conversation. |
| 6973 | if (mBuilder != null |
| 6974 | && mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 6975 | < Build.VERSION_CODES.P) { |
| 6976 | return mConversationTitle != null; |
| 6977 | } |
| 6978 | |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6979 | return mIsGroupConversation; |
| 6980 | } |
| 6981 | |
| 6982 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6983 | * @hide |
| 6984 | */ |
| 6985 | @Override |
| 6986 | public void addExtras(Bundle extras) { |
| 6987 | super.addExtras(extras); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6988 | if (mUser != null) { |
| 6989 | // For legacy usages |
| 6990 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUser.getName()); |
| 6991 | extras.putParcelable(EXTRA_MESSAGING_PERSON, mUser); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6992 | } |
| 6993 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6994 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6995 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6996 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 6997 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6998 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6999 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 7000 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 7001 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7002 | |
| 7003 | fixTitleAndTextExtras(extras); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7004 | extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7005 | } |
| 7006 | |
| 7007 | private void fixTitleAndTextExtras(Bundle extras) { |
| 7008 | Message m = findLatestIncomingMessage(); |
| 7009 | CharSequence text = (m == null) ? null : m.mText; |
| 7010 | CharSequence sender = m == null ? null |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7011 | : m.mSender == null || TextUtils.isEmpty(m.mSender.getName()) |
| 7012 | ? mUser.getName() : m.mSender.getName(); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7013 | CharSequence title; |
| 7014 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 7015 | if (!TextUtils.isEmpty(sender)) { |
| 7016 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 7017 | title = mBuilder.mContext.getString( |
| 7018 | com.android.internal.R.string.notification_messaging_title_template, |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7019 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(sender)); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7020 | } else { |
| 7021 | title = mConversationTitle; |
| 7022 | } |
| 7023 | } else { |
| 7024 | title = sender; |
| 7025 | } |
| 7026 | |
| 7027 | if (title != null) { |
| 7028 | extras.putCharSequence(EXTRA_TITLE, title); |
| 7029 | } |
| 7030 | if (text != null) { |
| 7031 | extras.putCharSequence(EXTRA_TEXT, text); |
| 7032 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7033 | } |
| 7034 | |
| 7035 | /** |
| 7036 | * @hide |
| 7037 | */ |
| 7038 | @Override |
| 7039 | protected void restoreFromExtras(Bundle extras) { |
| 7040 | super.restoreFromExtras(extras); |
| 7041 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7042 | mUser = extras.getParcelable(EXTRA_MESSAGING_PERSON); |
| 7043 | if (mUser == null) { |
| 7044 | CharSequence displayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7045 | mUser = new Person.Builder().setName(displayName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7046 | } |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 7047 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7048 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7049 | mMessages = Message.getMessagesFromBundleArray(messages); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 7050 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7051 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 7052 | mIsGroupConversation = extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7053 | } |
| 7054 | |
| 7055 | /** |
| 7056 | * @hide |
| 7057 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7058 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7059 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7060 | mBuilder.mOriginalActions = mBuilder.mActions; |
| 7061 | mBuilder.mActions = new ArrayList<>(); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7062 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7063 | false /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7064 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 7065 | mBuilder.mOriginalActions = null; |
| 7066 | return remoteViews; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7067 | } |
| 7068 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7069 | /** |
| 7070 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7071 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7072 | */ |
| 7073 | @Override |
| 7074 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7075 | if (other == null || getClass() != other.getClass()) { |
| 7076 | return true; |
| 7077 | } |
| 7078 | MessagingStyle newS = (MessagingStyle) other; |
| 7079 | List<MessagingStyle.Message> oldMs = getMessages(); |
| 7080 | List<MessagingStyle.Message> newMs = newS.getMessages(); |
| 7081 | |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7082 | if (oldMs == null || newMs == null) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7083 | newMs = new ArrayList<>(); |
| 7084 | } |
| 7085 | |
| 7086 | int n = oldMs.size(); |
| 7087 | if (n != newMs.size()) { |
| 7088 | return true; |
| 7089 | } |
| 7090 | for (int i = 0; i < n; i++) { |
| 7091 | MessagingStyle.Message oldM = oldMs.get(i); |
| 7092 | MessagingStyle.Message newM = newMs.get(i); |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7093 | if (!Objects.equals( |
| 7094 | String.valueOf(oldM.getText()), |
| 7095 | String.valueOf(newM.getText()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7096 | return true; |
| 7097 | } |
| 7098 | if (!Objects.equals(oldM.getDataUri(), newM.getDataUri())) { |
| 7099 | return true; |
| 7100 | } |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7101 | String oldSender = String.valueOf(oldM.getSenderPerson() == null |
| 7102 | ? oldM.getSender() |
| 7103 | : oldM.getSenderPerson().getName()); |
| 7104 | String newSender = String.valueOf(newM.getSenderPerson() == null |
| 7105 | ? newM.getSender() |
| 7106 | : newM.getSenderPerson().getName()); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7107 | if (!Objects.equals(oldSender, newSender)) { |
| 7108 | return true; |
| 7109 | } |
| 7110 | |
| 7111 | String oldKey = oldM.getSenderPerson() == null |
| 7112 | ? null : oldM.getSenderPerson().getKey(); |
| 7113 | String newKey = newM.getSenderPerson() == null |
| 7114 | ? null : newM.getSenderPerson().getKey(); |
| 7115 | if (!Objects.equals(oldKey, newKey)) { |
| 7116 | return true; |
| 7117 | } |
| 7118 | // Other fields (like timestamp) intentionally excluded |
| 7119 | } |
| 7120 | return false; |
| 7121 | } |
| 7122 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7123 | private Message findLatestIncomingMessage() { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7124 | return findLatestIncomingMessage(mMessages); |
| 7125 | } |
| 7126 | |
| 7127 | /** |
| 7128 | * @hide |
| 7129 | */ |
| 7130 | @Nullable |
| 7131 | public static Message findLatestIncomingMessage( |
| 7132 | List<Message> messages) { |
| 7133 | for (int i = messages.size() - 1; i >= 0; i--) { |
| 7134 | Message m = messages.get(i); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7135 | // Incoming messages have a non-empty sender. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7136 | if (m.mSender != null && !TextUtils.isEmpty(m.mSender.getName())) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7137 | return m; |
| 7138 | } |
| 7139 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7140 | if (!messages.isEmpty()) { |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7141 | // No incoming messages, fall back to outgoing message |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7142 | return messages.get(messages.size() - 1); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7143 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7144 | return null; |
| 7145 | } |
| 7146 | |
| 7147 | /** |
| 7148 | * @hide |
| 7149 | */ |
| 7150 | @Override |
| 7151 | public RemoteViews makeBigContentView() { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7152 | return makeMessagingView(false /* displayImagesAtEnd */, true /* hideLargeIcon */); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7153 | } |
| 7154 | |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7155 | /** |
| 7156 | * Create a messaging layout. |
| 7157 | * |
| 7158 | * @param displayImagesAtEnd should images be displayed at the end of the content instead |
| 7159 | * of inline. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7160 | * @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] | 7161 | * @return the created remoteView. |
| 7162 | */ |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7163 | @NonNull |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7164 | private RemoteViews makeMessagingView(boolean displayImagesAtEnd, boolean hideRightIcons) { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7165 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7166 | ? super.mBigContentTitle |
| 7167 | : mConversationTitle; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7168 | boolean atLeastP = mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 7169 | >= Build.VERSION_CODES.P; |
| 7170 | boolean isOneToOne; |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7171 | CharSequence nameReplacement = null; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7172 | Icon avatarReplacement = null; |
| 7173 | if (!atLeastP) { |
| 7174 | isOneToOne = TextUtils.isEmpty(conversationTitle); |
| 7175 | avatarReplacement = mBuilder.mN.mLargeIcon; |
| 7176 | if (hasOnlyWhiteSpaceSenders()) { |
| 7177 | isOneToOne = true; |
| 7178 | nameReplacement = conversationTitle; |
| 7179 | conversationTitle = null; |
| 7180 | } |
| 7181 | } else { |
| 7182 | isOneToOne = !isGroupConversation(); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 7183 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7184 | TemplateBindResult bindResult = new TemplateBindResult(); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 7185 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7186 | mBuilder.getMessagingLayoutResource(), |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7187 | mBuilder.mParams.reset().hasProgress(false).title(conversationTitle).text(null) |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7188 | .hideLargeIcon(hideRightIcons || isOneToOne) |
| 7189 | .hideReplyIcon(hideRightIcons) |
| 7190 | .headerTextSecondary(conversationTitle), |
| 7191 | bindResult); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7192 | addExtras(mBuilder.mN.extras); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7193 | // also update the end margin if there is an image |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7194 | contentView.setViewLayoutMarginEnd(R.id.notification_messaging, |
| 7195 | bindResult.getIconMarginEnd()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7196 | contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 7197 | mBuilder.isColorized() ? mBuilder.getPrimaryTextColor() |
| 7198 | : mBuilder.resolveContrastColor()); |
| 7199 | contentView.setInt(R.id.status_bar_latest_event_content, "setSenderTextColor", |
| 7200 | mBuilder.getPrimaryTextColor()); |
| 7201 | contentView.setInt(R.id.status_bar_latest_event_content, "setMessageTextColor", |
| 7202 | mBuilder.getSecondaryTextColor()); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7203 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd", |
| 7204 | displayImagesAtEnd); |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7205 | contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement", |
| 7206 | avatarReplacement); |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7207 | contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement", |
| 7208 | nameReplacement); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7209 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne", |
| 7210 | isOneToOne); |
| 7211 | contentView.setBundle(R.id.status_bar_latest_event_content, "setData", |
| 7212 | mBuilder.mN.extras); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7213 | return contentView; |
| 7214 | } |
| 7215 | |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7216 | private boolean hasOnlyWhiteSpaceSenders() { |
| 7217 | for (int i = 0; i < mMessages.size(); i++) { |
| 7218 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7219 | Person sender = m.getSenderPerson(); |
| 7220 | if (sender != null && !isWhiteSpace(sender.getName())) { |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7221 | return false; |
| 7222 | } |
| 7223 | } |
| 7224 | return true; |
| 7225 | } |
| 7226 | |
| 7227 | private boolean isWhiteSpace(CharSequence sender) { |
| 7228 | if (TextUtils.isEmpty(sender)) { |
| 7229 | return true; |
| 7230 | } |
| 7231 | if (sender.toString().matches("^\\s*$")) { |
| 7232 | return true; |
| 7233 | } |
| 7234 | // Let's check if we only have 0 whitespace chars. Some apps did this as a workaround |
| 7235 | // For the presentation that we had. |
| 7236 | for (int i = 0; i < sender.length(); i++) { |
| 7237 | char c = sender.charAt(i); |
| 7238 | if (c != '\u200B') { |
| 7239 | return false; |
| 7240 | } |
| 7241 | } |
| 7242 | return true; |
| 7243 | } |
| 7244 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7245 | private CharSequence createConversationTitleFromMessages() { |
| 7246 | ArraySet<CharSequence> names = new ArraySet<>(); |
| 7247 | for (int i = 0; i < mMessages.size(); i++) { |
| 7248 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7249 | Person sender = m.getSenderPerson(); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7250 | if (sender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7251 | names.add(sender.getName()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7252 | } |
| 7253 | } |
| 7254 | SpannableStringBuilder title = new SpannableStringBuilder(); |
| 7255 | int size = names.size(); |
| 7256 | for (int i = 0; i < size; i++) { |
| 7257 | CharSequence name = names.valueAt(i); |
| 7258 | if (!TextUtils.isEmpty(title)) { |
| 7259 | title.append(", "); |
| 7260 | } |
| 7261 | title.append(BidiFormatter.getInstance().unicodeWrap(name)); |
| 7262 | } |
| 7263 | return title; |
| 7264 | } |
| 7265 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7266 | /** |
| 7267 | * @hide |
| 7268 | */ |
| 7269 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7270 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7271 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7272 | true /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7273 | remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1); |
| 7274 | return remoteViews; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7275 | } |
| 7276 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7277 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 7278 | return new TextAppearanceSpan(null, 0, 0, |
| 7279 | ColorStateList.valueOf(color), null); |
| 7280 | } |
| 7281 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7282 | public static final class Message { |
Tony Mak | 09db2ea | 2018-06-27 18:12:48 +0100 | [diff] [blame] | 7283 | /** @hide */ |
| 7284 | public static final String KEY_TEXT = "text"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7285 | static final String KEY_TIMESTAMP = "time"; |
| 7286 | static final String KEY_SENDER = "sender"; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7287 | static final String KEY_SENDER_PERSON = "sender_person"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7288 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 7289 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7290 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7291 | static final String KEY_REMOTE_INPUT_HISTORY = "remote_input_history"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7292 | |
| 7293 | private final CharSequence mText; |
| 7294 | private final long mTimestamp; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7295 | @Nullable |
| 7296 | private final Person mSender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7297 | /** True if this message was generated from the extra |
| 7298 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY} |
| 7299 | */ |
| 7300 | private final boolean mRemoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7301 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7302 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7303 | private String mDataMimeType; |
| 7304 | private Uri mDataUri; |
| 7305 | |
| 7306 | /** |
| 7307 | * Constructor |
| 7308 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7309 | * @param timestamp Time at which the message arrived |
| 7310 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 7311 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 7312 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 7313 | * Should be unique amongst all individuals in the conversation, and should be |
| 7314 | * consistent during re-posts of the notification. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7315 | * |
| 7316 | * @deprecated use {@code Message(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7317 | */ |
| 7318 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7319 | this(text, timestamp, sender == null ? null |
| 7320 | : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7321 | } |
| 7322 | |
| 7323 | /** |
| 7324 | * Constructor |
| 7325 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7326 | * @param timestamp Time at which the message arrived |
| 7327 | * @param sender The {@link Person} who sent the message. |
| 7328 | * Should be <code>null</code> for messages by the current user, in which case |
| 7329 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7330 | * <p> |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7331 | * The person provided should contain an Icon, set with |
| 7332 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7333 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7334 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7335 | * to differentiate between the different users. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7336 | * </p> |
| 7337 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 7338 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7339 | this(text, timestamp, sender, false /* remoteHistory */); |
| 7340 | } |
| 7341 | |
| 7342 | /** |
| 7343 | * Constructor |
| 7344 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7345 | * @param timestamp Time at which the message arrived |
| 7346 | * @param sender The {@link Person} who sent the message. |
| 7347 | * Should be <code>null</code> for messages by the current user, in which case |
| 7348 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7349 | * @param remoteInputHistory True if the messages was generated from the extra |
| 7350 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7351 | * <p> |
| 7352 | * The person provided should contain an Icon, set with |
| 7353 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7354 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7355 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7356 | * to differentiate between the different users. |
| 7357 | * </p> |
| 7358 | * @hide |
| 7359 | */ |
| 7360 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender, |
| 7361 | boolean remoteInputHistory) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7362 | mText = text; |
| 7363 | mTimestamp = timestamp; |
| 7364 | mSender = sender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7365 | mRemoteInputHistory = remoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7366 | } |
| 7367 | |
| 7368 | /** |
| 7369 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 7370 | * where the platform doesn't support the MIME type, the original text provided in the |
| 7371 | * constructor will be used. |
| 7372 | * @param dataMimeType The MIME type of the content. See |
| 7373 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 7374 | * types on Android and Android Wear. |
| 7375 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 7376 | * <p class="note"> |
| 7377 | * <ol> |
| 7378 | * <li>Notification Listeners including the System UI need permission to access the |
| 7379 | * data the Uri points to. The recommended ways to do this are:</li> |
| 7380 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 7381 | * the correct permission to access your provider. The preferred mechanism for |
| 7382 | * providing access is to use per-URI permissions which are temporary and only |
| 7383 | * grant access to the receiving application. An easy way to create a |
| 7384 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 7385 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 7386 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 7387 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 7388 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 7389 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 7390 | * Note that once added to the system MediaStore the content is accessible to any |
| 7391 | * app on the device.</li> |
| 7392 | * </ol> |
| 7393 | * @return this object for method chaining |
| 7394 | */ |
| 7395 | public Message setData(String dataMimeType, Uri dataUri) { |
| 7396 | mDataMimeType = dataMimeType; |
| 7397 | mDataUri = dataUri; |
| 7398 | return this; |
| 7399 | } |
| 7400 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7401 | /** |
| 7402 | * Get the text to be used for this message, or the fallback text if a type and content |
| 7403 | * Uri have been set |
| 7404 | */ |
| 7405 | public CharSequence getText() { |
| 7406 | return mText; |
| 7407 | } |
| 7408 | |
| 7409 | /** |
| 7410 | * Get the time at which this message arrived |
| 7411 | */ |
| 7412 | public long getTimestamp() { |
| 7413 | return mTimestamp; |
| 7414 | } |
| 7415 | |
| 7416 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7417 | * Get the extras Bundle for this message. |
| 7418 | */ |
| 7419 | public Bundle getExtras() { |
| 7420 | return mExtras; |
| 7421 | } |
| 7422 | |
| 7423 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7424 | * 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] | 7425 | * |
| 7426 | * @deprecated use {@link #getSenderPerson()} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7427 | */ |
| 7428 | public CharSequence getSender() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7429 | return mSender == null ? null : mSender.getName(); |
| 7430 | } |
| 7431 | |
| 7432 | /** |
| 7433 | * Get the sender associated with this message. |
| 7434 | */ |
| 7435 | @Nullable |
| 7436 | public Person getSenderPerson() { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7437 | return mSender; |
| 7438 | } |
| 7439 | |
| 7440 | /** |
| 7441 | * Get the MIME type of the data pointed to by the Uri |
| 7442 | */ |
| 7443 | public String getDataMimeType() { |
| 7444 | return mDataMimeType; |
| 7445 | } |
| 7446 | |
| 7447 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 7448 | * 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] | 7449 | * {@see #getText()} is used. |
| 7450 | */ |
| 7451 | public Uri getDataUri() { |
| 7452 | return mDataUri; |
| 7453 | } |
| 7454 | |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7455 | /** |
| 7456 | * @return True if the message was generated from |
| 7457 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7458 | * @hide |
| 7459 | */ |
| 7460 | public boolean isRemoteInputHistory() { |
| 7461 | return mRemoteInputHistory; |
| 7462 | } |
| 7463 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7464 | private Bundle toBundle() { |
| 7465 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7466 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7467 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7468 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7469 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7470 | if (mSender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7471 | // Legacy listeners need this |
| 7472 | bundle.putCharSequence(KEY_SENDER, mSender.getName()); |
| 7473 | bundle.putParcelable(KEY_SENDER_PERSON, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7474 | } |
| 7475 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7476 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7477 | } |
| 7478 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7479 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7480 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7481 | if (mExtras != null) { |
| 7482 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 7483 | } |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7484 | if (mRemoteInputHistory) { |
| 7485 | bundle.putBoolean(KEY_REMOTE_INPUT_HISTORY, mRemoteInputHistory); |
| 7486 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7487 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7488 | } |
| 7489 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7490 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 7491 | Bundle[] bundles = new Bundle[messages.size()]; |
| 7492 | final int N = messages.size(); |
| 7493 | for (int i = 0; i < N; i++) { |
| 7494 | bundles[i] = messages.get(i).toBundle(); |
| 7495 | } |
| 7496 | return bundles; |
| 7497 | } |
| 7498 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7499 | /** |
| 7500 | * @return A list of messages read from the bundles. |
| 7501 | * |
| 7502 | * @hide |
| 7503 | */ |
| 7504 | public static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
| 7505 | if (bundles == null) { |
| 7506 | return new ArrayList<>(); |
| 7507 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7508 | List<Message> messages = new ArrayList<>(bundles.length); |
| 7509 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7510 | if (bundles[i] instanceof Bundle) { |
| 7511 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 7512 | if (message != null) { |
| 7513 | messages.add(message); |
| 7514 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7515 | } |
| 7516 | } |
| 7517 | return messages; |
| 7518 | } |
| 7519 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 7520 | /** |
| 7521 | * @return The message that is stored in the bundle or null if the message couldn't be |
| 7522 | * resolved. |
| 7523 | * |
| 7524 | * @hide |
| 7525 | */ |
| 7526 | @Nullable |
| 7527 | public static Message getMessageFromBundle(Bundle bundle) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7528 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 7529 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7530 | return null; |
| 7531 | } else { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7532 | |
| 7533 | Person senderPerson = bundle.getParcelable(KEY_SENDER_PERSON); |
| 7534 | if (senderPerson == null) { |
| 7535 | // Legacy apps that use compat don't actually provide the sender objects |
| 7536 | // We need to fix the compat version to provide people / use |
| 7537 | // the native api instead |
| 7538 | CharSequence senderName = bundle.getCharSequence(KEY_SENDER); |
| 7539 | if (senderName != null) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7540 | senderPerson = new Person.Builder().setName(senderName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7541 | } |
| 7542 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7543 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7544 | bundle.getLong(KEY_TIMESTAMP), |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7545 | senderPerson, |
| 7546 | bundle.getBoolean(KEY_REMOTE_INPUT_HISTORY, false)); |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7547 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 7548 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7549 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 7550 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7551 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7552 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 7553 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 7554 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7555 | return message; |
| 7556 | } |
| 7557 | } catch (ClassCastException e) { |
| 7558 | return null; |
| 7559 | } |
| 7560 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7561 | } |
| 7562 | } |
| 7563 | |
| 7564 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7565 | * 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] | 7566 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7567 | * 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] | 7568 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7569 | * Notification notif = new Notification.Builder(mContext) |
| 7570 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 7571 | * .setContentText(subject) |
| 7572 | * .setSmallIcon(R.drawable.new_mail) |
| 7573 | * .setLargeIcon(aBitmap) |
| 7574 | * .setStyle(new Notification.InboxStyle() |
| 7575 | * .addLine(str1) |
| 7576 | * .addLine(str2) |
| 7577 | * .setContentTitle("") |
| 7578 | * .setSummaryText("+3 more")) |
| 7579 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7580 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 7581 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7582 | * @see Notification#bigContentView |
| 7583 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7584 | public static class InboxStyle extends Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7585 | |
| 7586 | /** |
| 7587 | * The number of lines of remote input history allowed until we start reducing lines. |
| 7588 | */ |
| 7589 | private static final int NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION = 1; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7590 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 7591 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7592 | public InboxStyle() { |
| 7593 | } |
| 7594 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7595 | /** |
| 7596 | * @deprecated use {@code InboxStyle()}. |
| 7597 | */ |
| 7598 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7599 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7600 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7601 | } |
| 7602 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7603 | /** |
| 7604 | * Overrides ContentTitle in the big form of the template. |
| 7605 | * This defaults to the value passed to setContentTitle(). |
| 7606 | */ |
| 7607 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7608 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7609 | return this; |
| 7610 | } |
| 7611 | |
| 7612 | /** |
| 7613 | * Set the first line of text after the detail section in the big form of the template. |
| 7614 | */ |
| 7615 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7616 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7617 | return this; |
| 7618 | } |
| 7619 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 7620 | /** |
| 7621 | * Append a line to the digest section of the Inbox notification. |
| 7622 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7623 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7624 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7625 | return this; |
| 7626 | } |
| 7627 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7628 | /** |
| 7629 | * @hide |
| 7630 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7631 | public ArrayList<CharSequence> getLines() { |
| 7632 | return mTexts; |
| 7633 | } |
| 7634 | |
| 7635 | /** |
| 7636 | * @hide |
| 7637 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7638 | public void addExtras(Bundle extras) { |
| 7639 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7640 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7641 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 7642 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 7643 | } |
| 7644 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7645 | /** |
| 7646 | * @hide |
| 7647 | */ |
| 7648 | @Override |
| 7649 | protected void restoreFromExtras(Bundle extras) { |
| 7650 | super.restoreFromExtras(extras); |
| 7651 | |
| 7652 | mTexts.clear(); |
| 7653 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 7654 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 7655 | } |
| 7656 | } |
| 7657 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7658 | /** |
| 7659 | * @hide |
| 7660 | */ |
| 7661 | public RemoteViews makeBigContentView() { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 7662 | // Remove the content text so it disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7663 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7664 | CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT); |
| 7665 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7666 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7667 | TemplateBindResult result = new TemplateBindResult(); |
| 7668 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource(), result); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 7669 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7670 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7671 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7672 | 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] | 7673 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7674 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 7675 | // Make sure all rows are gone in case we reuse a view. |
| 7676 | for (int rowId : rowIds) { |
| 7677 | contentView.setViewVisibility(rowId, View.GONE); |
| 7678 | } |
| 7679 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7680 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7681 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7682 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7683 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7684 | int onlyViewId = 0; |
| 7685 | int maxRows = rowIds.length; |
| 7686 | if (mBuilder.mActions.size() > 0) { |
| 7687 | maxRows--; |
| 7688 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7689 | CharSequence[] remoteInputHistory = mBuilder.mN.extras.getCharSequenceArray( |
| 7690 | EXTRA_REMOTE_INPUT_HISTORY); |
| 7691 | if (remoteInputHistory != null |
| 7692 | && remoteInputHistory.length > NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION) { |
| 7693 | // Let's remove some messages to make room for the remote input history. |
| 7694 | // 1 is always able to fit, but let's remove them if they are 2 or 3 |
| 7695 | int numRemoteInputs = Math.min(remoteInputHistory.length, |
| 7696 | MAX_REMOTE_INPUT_HISTORY_LINES); |
| 7697 | int totalNumRows = mTexts.size() + numRemoteInputs |
| 7698 | - NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION; |
| 7699 | if (totalNumRows > maxRows) { |
| 7700 | int overflow = totalNumRows - maxRows; |
| 7701 | if (mTexts.size() > maxRows) { |
| 7702 | // Heuristic: if the Texts don't fit anyway, we'll rather drop the last |
| 7703 | // few messages, even with the remote input |
| 7704 | maxRows -= overflow; |
| 7705 | } else { |
| 7706 | // otherwise we drop the first messages |
| 7707 | i = overflow; |
| 7708 | } |
| 7709 | } |
| 7710 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7711 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7712 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7713 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7714 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 7715 | contentView.setTextViewText(rowIds[i], |
| 7716 | mBuilder.processTextSpans(mBuilder.processLegacyText(str))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 7717 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i]); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7718 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7719 | handleInboxImageMargin(contentView, rowIds[i], first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7720 | result.getIconMarginEnd()); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7721 | if (first) { |
| 7722 | onlyViewId = rowIds[i]; |
| 7723 | } else { |
| 7724 | onlyViewId = 0; |
| 7725 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7726 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7727 | } |
| 7728 | i++; |
| 7729 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7730 | if (onlyViewId != 0) { |
| 7731 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 7732 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7733 | R.dimen.notification_text_margin_top); |
| 7734 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 7735 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7736 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7737 | return contentView; |
| 7738 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7739 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7740 | /** |
| 7741 | * @hide |
| 7742 | */ |
| 7743 | @Override |
| 7744 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7745 | if (other == null || getClass() != other.getClass()) { |
| 7746 | return true; |
| 7747 | } |
| 7748 | InboxStyle newS = (InboxStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7749 | |
| 7750 | final ArrayList<CharSequence> myLines = getLines(); |
| 7751 | final ArrayList<CharSequence> newLines = newS.getLines(); |
| 7752 | final int n = myLines.size(); |
| 7753 | if (n != newLines.size()) { |
| 7754 | return true; |
| 7755 | } |
| 7756 | |
| 7757 | for (int i = 0; i < n; i++) { |
| 7758 | if (!Objects.equals( |
| 7759 | String.valueOf(myLines.get(i)), |
| 7760 | String.valueOf(newLines.get(i)))) { |
| 7761 | return true; |
| 7762 | } |
| 7763 | } |
| 7764 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7765 | } |
| 7766 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7767 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7768 | int marginEndValue) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7769 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7770 | if (first) { |
| 7771 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 7772 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 7773 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7774 | if (!hasProgress) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7775 | endMargin = marginEndValue; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7776 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7777 | } |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7778 | contentView.setViewLayoutMarginEnd(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7779 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7780 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7781 | |
| 7782 | /** |
| 7783 | * Notification style for media playback notifications. |
| 7784 | * |
| 7785 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 7786 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 7787 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7788 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 7789 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 7790 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7791 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7792 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 7793 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 7794 | * {@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] | 7795 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7796 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7797 | * Notifications created with MediaStyle will have their category set to |
| 7798 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 7799 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7800 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7801 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 7802 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7803 | * the System UI can identify this as a notification representing an active media session |
| 7804 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 7805 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7806 | * <p> |
| 7807 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 7808 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 7809 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 7810 | * <p> |
| 7811 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7812 | * To use this style with your Notification, feed it to |
| 7813 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7814 | * <pre class="prettyprint"> |
| 7815 | * Notification noti = new Notification.Builder() |
| 7816 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 7817 | * .setContentTitle("Track title") |
| 7818 | * .setContentText("Artist - Album") |
| 7819 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7820 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 7821 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7822 | * .build(); |
| 7823 | * </pre> |
| 7824 | * |
| 7825 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7826 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7827 | */ |
| 7828 | public static class MediaStyle extends Style { |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7829 | // Changing max media buttons requires also changing templates |
| 7830 | // (notification_template_material_media and notification_template_material_big_media). |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7831 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7832 | static final int MAX_MEDIA_BUTTONS = 5; |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7833 | @IdRes private static final int[] MEDIA_BUTTON_IDS = { |
| 7834 | R.id.action0, |
| 7835 | R.id.action1, |
| 7836 | R.id.action2, |
| 7837 | R.id.action3, |
| 7838 | R.id.action4, |
| 7839 | }; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7840 | |
| 7841 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7842 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7843 | |
| 7844 | public MediaStyle() { |
| 7845 | } |
| 7846 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7847 | /** |
| 7848 | * @deprecated use {@code MediaStyle()}. |
| 7849 | */ |
| 7850 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7851 | public MediaStyle(Builder builder) { |
| 7852 | setBuilder(builder); |
| 7853 | } |
| 7854 | |
| 7855 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7856 | * 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] | 7857 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7858 | * |
| 7859 | * @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] | 7860 | */ |
| 7861 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 7862 | mActionsToShowInCompact = actions; |
| 7863 | return this; |
| 7864 | } |
| 7865 | |
| 7866 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7867 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 7868 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7869 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7870 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7871 | mToken = token; |
| 7872 | return this; |
| 7873 | } |
| 7874 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7875 | /** |
| 7876 | * @hide |
| 7877 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7878 | @Override |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7879 | @UnsupportedAppUsage |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7880 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7881 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7882 | if (wip.category == null) { |
| 7883 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 7884 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7885 | return wip; |
| 7886 | } |
| 7887 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7888 | /** |
| 7889 | * @hide |
| 7890 | */ |
| 7891 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7892 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7893 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7894 | } |
| 7895 | |
| 7896 | /** |
| 7897 | * @hide |
| 7898 | */ |
| 7899 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7900 | public RemoteViews makeBigContentView() { |
| 7901 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7902 | } |
| 7903 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7904 | /** |
| 7905 | * @hide |
| 7906 | */ |
| 7907 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7908 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7909 | RemoteViews expanded = makeMediaBigContentView(); |
| 7910 | return expanded != null ? expanded : makeMediaContentView(); |
| 7911 | } |
| 7912 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7913 | /** @hide */ |
| 7914 | @Override |
| 7915 | public void addExtras(Bundle extras) { |
| 7916 | super.addExtras(extras); |
| 7917 | |
| 7918 | if (mToken != null) { |
| 7919 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 7920 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 7921 | if (mActionsToShowInCompact != null) { |
| 7922 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 7923 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7924 | } |
| 7925 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7926 | /** |
| 7927 | * @hide |
| 7928 | */ |
| 7929 | @Override |
| 7930 | protected void restoreFromExtras(Bundle extras) { |
| 7931 | super.restoreFromExtras(extras); |
| 7932 | |
| 7933 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 7934 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 7935 | } |
| 7936 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 7937 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 7938 | } |
| 7939 | } |
| 7940 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7941 | /** |
| 7942 | * @hide |
| 7943 | */ |
| 7944 | @Override |
| 7945 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7946 | if (other == null || getClass() != other.getClass()) { |
| 7947 | return true; |
| 7948 | } |
| 7949 | // All fields to compare are on the Notification object |
| 7950 | return false; |
| 7951 | } |
| 7952 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7953 | private void bindMediaActionButton(RemoteViews container, @IdRes int buttonId, |
| 7954 | Action action, int color) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7955 | final boolean tombstone = (action.actionIntent == null); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7956 | container.setViewVisibility(buttonId, View.VISIBLE); |
| 7957 | container.setImageViewIcon(buttonId, action.getIcon()); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 7958 | |
| 7959 | // If the action buttons should not be tinted, then just use the default |
| 7960 | // notification color. Otherwise, just use the passed-in color. |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7961 | Resources resources = mBuilder.mContext.getResources(); |
| 7962 | Configuration currentConfig = resources.getConfiguration(); |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 7963 | boolean inNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 7964 | == Configuration.UI_MODE_NIGHT_YES; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 7965 | int tintColor = mBuilder.shouldTintActionButtons() || mBuilder.isColorized() |
| 7966 | ? color |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 7967 | : ContrastColorUtil.resolveColor(mBuilder.mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 7968 | Notification.COLOR_DEFAULT, inNightMode); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 7969 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7970 | container.setDrawableTint(buttonId, false, tintColor, |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 7971 | PorterDuff.Mode.SRC_ATOP); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7972 | |
| 7973 | final TypedArray typedArray = mBuilder.mContext.obtainStyledAttributes( |
| 7974 | new int[]{ android.R.attr.colorControlHighlight }); |
| 7975 | int rippleAlpha = Color.alpha(typedArray.getColor(0, 0)); |
| 7976 | typedArray.recycle(); |
| 7977 | int rippleColor = Color.argb(rippleAlpha, Color.red(tintColor), Color.green(tintColor), |
| 7978 | Color.blue(tintColor)); |
| 7979 | container.setRippleDrawableColor(buttonId, ColorStateList.valueOf(rippleColor)); |
| 7980 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7981 | if (!tombstone) { |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7982 | container.setOnClickPendingIntent(buttonId, action.actionIntent); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7983 | } |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7984 | container.setContentDescription(buttonId, action.title); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7985 | } |
| 7986 | |
| 7987 | private RemoteViews makeMediaContentView() { |
| 7988 | RemoteViews view = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7989 | R.layout.notification_template_material_media, false, /* hasProgress */ |
| 7990 | null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7991 | |
| 7992 | final int numActions = mBuilder.mActions.size(); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7993 | final int numActionsToShow = mActionsToShowInCompact == null |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7994 | ? 0 |
| 7995 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 7996 | if (numActionsToShow > numActions) { |
| 7997 | throw new IllegalArgumentException(String.format( |
| 7998 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 7999 | numActions, numActions - 1)); |
| 8000 | } |
| 8001 | for (int i = 0; i < MAX_MEDIA_BUTTONS_IN_COMPACT; i++) { |
| 8002 | if (i < numActionsToShow) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8003 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8004 | bindMediaActionButton(view, MEDIA_BUTTON_IDS[i], action, getActionColor()); |
| 8005 | } else { |
| 8006 | view.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8007 | } |
| 8008 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 8009 | handleImage(view); |
| 8010 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8011 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8012 | if (mBuilder.mN.hasLargeIcon()) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8013 | endMargin = R.dimen.notification_media_image_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 8014 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8015 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8016 | return view; |
| 8017 | } |
| 8018 | |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 8019 | private int getActionColor() { |
| 8020 | return mBuilder.isColorized() ? mBuilder.getPrimaryTextColor() |
| 8021 | : mBuilder.resolveContrastColor(); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8022 | } |
| 8023 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8024 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8025 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8026 | // Dont add an expanded view if there is no more content to be revealed |
| 8027 | int actionsInCompact = mActionsToShowInCompact == null |
| 8028 | ? 0 |
| 8029 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8030 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 8031 | return null; |
| 8032 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8033 | RemoteViews big = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8034 | R.layout.notification_template_material_big_media, false, null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8035 | |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8036 | for (int i = 0; i < MAX_MEDIA_BUTTONS; i++) { |
| 8037 | if (i < actionCount) { |
| 8038 | bindMediaActionButton(big, MEDIA_BUTTON_IDS[i], mBuilder.mActions.get(i), |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 8039 | getActionColor()); |
Gus Prevas | 9cc9660 | 2018-10-11 11:24:23 -0400 | [diff] [blame] | 8040 | } else { |
| 8041 | big.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8042 | } |
| 8043 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8044 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8045 | return big; |
| 8046 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8047 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 8048 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 8049 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 8050 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 8051 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8052 | } |
| 8053 | } |
| 8054 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 8055 | /** |
| 8056 | * @hide |
| 8057 | */ |
| 8058 | @Override |
| 8059 | protected boolean hasProgress() { |
| 8060 | return false; |
| 8061 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 8062 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8063 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8064 | /** |
| 8065 | * Notification style for custom views that are decorated by the system |
| 8066 | * |
| 8067 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 8068 | * style and still obtain system decorations like the notification header with the expand |
| 8069 | * affordance and actions. |
| 8070 | * |
| 8071 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8072 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8073 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8074 | * corresponding custom views to display. |
| 8075 | * |
| 8076 | * To use this style with your Notification, feed it to |
| 8077 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8078 | * <pre class="prettyprint"> |
| 8079 | * Notification noti = new Notification.Builder() |
| 8080 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8081 | * .setLargeIcon(albumArtBitmap)) |
| 8082 | * .setCustomContentView(contentView); |
| 8083 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 8084 | * .build(); |
| 8085 | * </pre> |
| 8086 | */ |
| 8087 | public static class DecoratedCustomViewStyle extends Style { |
| 8088 | |
| 8089 | public DecoratedCustomViewStyle() { |
| 8090 | } |
| 8091 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8092 | /** |
| 8093 | * @hide |
| 8094 | */ |
| 8095 | public boolean displayCustomViewInline() { |
| 8096 | return true; |
| 8097 | } |
| 8098 | |
| 8099 | /** |
| 8100 | * @hide |
| 8101 | */ |
| 8102 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8103 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8104 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 8105 | } |
| 8106 | |
| 8107 | /** |
| 8108 | * @hide |
| 8109 | */ |
| 8110 | @Override |
| 8111 | public RemoteViews makeBigContentView() { |
| 8112 | return makeDecoratedBigContentView(); |
| 8113 | } |
| 8114 | |
| 8115 | /** |
| 8116 | * @hide |
| 8117 | */ |
| 8118 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8119 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8120 | return makeDecoratedHeadsUpContentView(); |
| 8121 | } |
| 8122 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8123 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 8124 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 8125 | ? mBuilder.mN.contentView |
| 8126 | : mBuilder.mN.headsUpContentView; |
| 8127 | if (mBuilder.mActions.size() == 0) { |
| 8128 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 8129 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8130 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8131 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8132 | mBuilder.getBigBaseLayoutResource(), result); |
| 8133 | buildIntoRemoteViewContent(remoteViews, headsUpContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8134 | return remoteViews; |
| 8135 | } |
| 8136 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8137 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8138 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8139 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8140 | mBuilder.getBaseLayoutResource(), result); |
| 8141 | buildIntoRemoteViewContent(remoteViews, customContent, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8142 | return remoteViews; |
| 8143 | } |
| 8144 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8145 | private RemoteViews makeDecoratedBigContentView() { |
| 8146 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 8147 | ? mBuilder.mN.contentView |
| 8148 | : mBuilder.mN.bigContentView; |
| 8149 | if (mBuilder.mActions.size() == 0) { |
| 8150 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 8151 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8152 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8153 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8154 | mBuilder.getBigBaseLayoutResource(), result); |
| 8155 | buildIntoRemoteViewContent(remoteViews, bigContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8156 | return remoteViews; |
| 8157 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8158 | |
| 8159 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8160 | RemoteViews customContent, TemplateBindResult result) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8161 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8162 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8163 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8164 | customContent = customContent.clone(); |
Anthony Chen | 8f5f358 | 2017-04-11 11:18:37 -0700 | [diff] [blame] | 8165 | remoteViews.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress); |
| 8166 | remoteViews.addView(R.id.notification_main_column, customContent, 0 /* index */); |
Selim Cinek | fc8073c | 2017-08-16 17:50:20 -0700 | [diff] [blame] | 8167 | remoteViews.setReapplyDisallowed(); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8168 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8169 | // also update the end margin if there is an image |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8170 | Resources resources = mBuilder.mContext.getResources(); |
| 8171 | int endMargin = resources.getDimensionPixelSize( |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 8172 | R.dimen.notification_content_margin_end) + result.getIconMarginEnd(); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8173 | remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8174 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8175 | |
| 8176 | /** |
| 8177 | * @hide |
| 8178 | */ |
| 8179 | @Override |
| 8180 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8181 | if (other == null || getClass() != other.getClass()) { |
| 8182 | return true; |
| 8183 | } |
| 8184 | // Comparison done for all custom RemoteViews, independent of style |
| 8185 | return false; |
| 8186 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8187 | } |
| 8188 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8189 | /** |
| 8190 | * Notification style for media custom views that are decorated by the system |
| 8191 | * |
| 8192 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 8193 | * this style and still obtain system decorations like the notification header with the expand |
| 8194 | * affordance and actions. |
| 8195 | * |
| 8196 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8197 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8198 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8199 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8200 | * <p> |
| 8201 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 8202 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 8203 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8204 | * To use this style with your Notification, feed it to |
| 8205 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8206 | * <pre class="prettyprint"> |
| 8207 | * Notification noti = new Notification.Builder() |
| 8208 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8209 | * .setLargeIcon(albumArtBitmap)) |
| 8210 | * .setCustomContentView(contentView); |
| 8211 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 8212 | * .setMediaSession(mySession)) |
| 8213 | * .build(); |
| 8214 | * </pre> |
| 8215 | * |
| 8216 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 8217 | * @see android.app.Notification.MediaStyle |
| 8218 | */ |
| 8219 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 8220 | |
| 8221 | public DecoratedMediaCustomViewStyle() { |
| 8222 | } |
| 8223 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8224 | /** |
| 8225 | * @hide |
| 8226 | */ |
| 8227 | public boolean displayCustomViewInline() { |
| 8228 | return true; |
| 8229 | } |
| 8230 | |
| 8231 | /** |
| 8232 | * @hide |
| 8233 | */ |
| 8234 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8235 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 8236 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8237 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8238 | mBuilder.mN.contentView); |
| 8239 | } |
| 8240 | |
| 8241 | /** |
| 8242 | * @hide |
| 8243 | */ |
| 8244 | @Override |
| 8245 | public RemoteViews makeBigContentView() { |
| 8246 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 8247 | ? mBuilder.mN.bigContentView |
| 8248 | : mBuilder.mN.contentView; |
| 8249 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8250 | } |
| 8251 | |
| 8252 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 8253 | RemoteViews remoteViews = super.makeBigContentView(); |
| 8254 | if (remoteViews != null) { |
| 8255 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 8256 | customRemoteView); |
| 8257 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8258 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8259 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8260 | customRemoteView); |
| 8261 | } else { |
| 8262 | return null; |
| 8263 | } |
| 8264 | } |
| 8265 | |
| 8266 | /** |
| 8267 | * @hide |
| 8268 | */ |
| 8269 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8270 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8271 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 8272 | ? mBuilder.mN.headsUpContentView |
| 8273 | : mBuilder.mN.contentView; |
| 8274 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8275 | } |
| 8276 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8277 | /** |
| 8278 | * @hide |
| 8279 | */ |
| 8280 | @Override |
| 8281 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8282 | if (other == null || getClass() != other.getClass()) { |
| 8283 | return true; |
| 8284 | } |
| 8285 | // Comparison done for all custom RemoteViews, independent of style |
| 8286 | return false; |
| 8287 | } |
| 8288 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8289 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 8290 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8291 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8292 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8293 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8294 | customContent = customContent.clone(); |
Selim Cinek | 87c3153 | 2017-08-18 18:53:44 -0700 | [diff] [blame] | 8295 | customContent.overrideTextColors(mBuilder.getPrimaryTextColor()); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8296 | remoteViews.removeAllViews(id); |
| 8297 | remoteViews.addView(id, customContent); |
Selim Cinek | fc8073c | 2017-08-16 17:50:20 -0700 | [diff] [blame] | 8298 | remoteViews.setReapplyDisallowed(); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8299 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8300 | return remoteViews; |
| 8301 | } |
| 8302 | } |
| 8303 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8304 | // When adding a new Style subclass here, don't forget to update |
| 8305 | // Builder.getNotificationStyleClass. |
| 8306 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8307 | /** |
| 8308 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 8309 | * metadata or change options on a notification builder. |
| 8310 | */ |
| 8311 | public interface Extender { |
| 8312 | /** |
| 8313 | * Apply this extender to a notification builder. |
| 8314 | * @param builder the builder to be modified. |
| 8315 | * @return the build object for chaining. |
| 8316 | */ |
| 8317 | public Builder extend(Builder builder); |
| 8318 | } |
| 8319 | |
| 8320 | /** |
| 8321 | * Helper class to add wearable extensions to notifications. |
| 8322 | * <p class="note"> See |
| 8323 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 8324 | * for Android Wear</a> for more information on how to use this class. |
| 8325 | * <p> |
| 8326 | * To create a notification with wearable extensions: |
| 8327 | * <ol> |
| 8328 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 8329 | * properties. |
| 8330 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 8331 | * <li>Set wearable-specific properties using the |
| 8332 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 8333 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 8334 | * notification. |
| 8335 | * <li>Post the notification to the notification system with the |
| 8336 | * {@code NotificationManager.notify(...)} methods. |
| 8337 | * </ol> |
| 8338 | * |
| 8339 | * <pre class="prettyprint"> |
| 8340 | * Notification notif = new Notification.Builder(mContext) |
| 8341 | * .setContentTitle("New mail from " + sender.toString()) |
| 8342 | * .setContentText(subject) |
| 8343 | * .setSmallIcon(R.drawable.new_mail) |
| 8344 | * .extend(new Notification.WearableExtender() |
| 8345 | * .setContentIcon(R.drawable.new_mail)) |
| 8346 | * .build(); |
| 8347 | * NotificationManager notificationManger = |
| 8348 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 8349 | * notificationManger.notify(0, notif);</pre> |
| 8350 | * |
| 8351 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 8352 | * {@code WearableExtender(Notification)} constructor, |
| 8353 | * and then using the {@code get} methods to access values. |
| 8354 | * |
| 8355 | * <pre class="prettyprint"> |
| 8356 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 8357 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8358 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8359 | */ |
| 8360 | public static final class WearableExtender implements Extender { |
| 8361 | /** |
| 8362 | * Sentinel value for an action index that is unset. |
| 8363 | */ |
| 8364 | public static final int UNSET_ACTION_INDEX = -1; |
| 8365 | |
| 8366 | /** |
| 8367 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 8368 | * default sizing. |
| 8369 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 8370 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8371 | * on their content. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8372 | * |
| 8373 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8374 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8375 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8376 | public static final int SIZE_DEFAULT = 0; |
| 8377 | |
| 8378 | /** |
| 8379 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8380 | * with an extra small size. |
| 8381 | * <p>This value is only applicable for custom display notifications created using |
| 8382 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8383 | * |
| 8384 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8385 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8386 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8387 | public static final int SIZE_XSMALL = 1; |
| 8388 | |
| 8389 | /** |
| 8390 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8391 | * with a small size. |
| 8392 | * <p>This value is only applicable for custom display notifications created using |
| 8393 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8394 | * |
| 8395 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8396 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8397 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8398 | public static final int SIZE_SMALL = 2; |
| 8399 | |
| 8400 | /** |
| 8401 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8402 | * with a medium size. |
| 8403 | * <p>This value is only applicable for custom display notifications created using |
| 8404 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8405 | * |
| 8406 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8407 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8408 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8409 | public static final int SIZE_MEDIUM = 3; |
| 8410 | |
| 8411 | /** |
| 8412 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8413 | * with a large size. |
| 8414 | * <p>This value is only applicable for custom display notifications created using |
| 8415 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8416 | * |
| 8417 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8418 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8419 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8420 | public static final int SIZE_LARGE = 4; |
| 8421 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8422 | /** |
| 8423 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8424 | * full screen. |
| 8425 | * <p>This value is only applicable for custom display notifications created using |
| 8426 | * {@link #setDisplayIntent}. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8427 | * |
| 8428 | * @deprecated Display intents are no longer supported. |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8429 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8430 | @Deprecated |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8431 | public static final int SIZE_FULL_SCREEN = 5; |
| 8432 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8433 | /** |
| 8434 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 8435 | * short amount of time when this notification is displayed on the screen. This |
| 8436 | * is the default value. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8437 | * |
| 8438 | * @deprecated This feature is no longer supported. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8439 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8440 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8441 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 8442 | |
| 8443 | /** |
| 8444 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 8445 | * 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] | 8446 | * |
| 8447 | * @deprecated This feature is no longer supported. |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8448 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8449 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8450 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 8451 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8452 | /** Notification extra which contains wearable extensions */ |
| 8453 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 8454 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 8455 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8456 | private static final String KEY_ACTIONS = "actions"; |
| 8457 | private static final String KEY_FLAGS = "flags"; |
| 8458 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 8459 | private static final String KEY_PAGES = "pages"; |
| 8460 | private static final String KEY_BACKGROUND = "background"; |
| 8461 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 8462 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 8463 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 8464 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 8465 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 8466 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8467 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8468 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8469 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8470 | |
| 8471 | // Flags bitwise-ored to mFlags |
| 8472 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 8473 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 8474 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 8475 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8476 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 8477 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8478 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8479 | |
| 8480 | // Default value for flags integer |
| 8481 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 8482 | |
| 8483 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 8484 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 8485 | |
| 8486 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 8487 | private int mFlags = DEFAULT_FLAGS; |
| 8488 | private PendingIntent mDisplayIntent; |
| 8489 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 8490 | private Bitmap mBackground; |
| 8491 | private int mContentIcon; |
| 8492 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 8493 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 8494 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 8495 | private int mCustomContentHeight; |
| 8496 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8497 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8498 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8499 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8500 | |
| 8501 | /** |
| 8502 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 8503 | * options. |
| 8504 | */ |
| 8505 | public WearableExtender() { |
| 8506 | } |
| 8507 | |
| 8508 | public WearableExtender(Notification notif) { |
| 8509 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 8510 | if (wearableBundle != null) { |
| 8511 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 8512 | if (actions != null) { |
| 8513 | mActions.addAll(actions); |
| 8514 | } |
| 8515 | |
| 8516 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 8517 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 8518 | |
| 8519 | Notification[] pages = getNotificationArrayFromBundle( |
| 8520 | wearableBundle, KEY_PAGES); |
| 8521 | if (pages != null) { |
| 8522 | Collections.addAll(mPages, pages); |
| 8523 | } |
| 8524 | |
| 8525 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 8526 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 8527 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 8528 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 8529 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 8530 | UNSET_ACTION_INDEX); |
| 8531 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 8532 | SIZE_DEFAULT); |
| 8533 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 8534 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8535 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8536 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8537 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8538 | } |
| 8539 | } |
| 8540 | |
| 8541 | /** |
| 8542 | * Apply wearable extensions to a notification that is being built. This is typically |
| 8543 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 8544 | * {@link android.app.Notification.Builder}. |
| 8545 | */ |
| 8546 | @Override |
| 8547 | public Notification.Builder extend(Notification.Builder builder) { |
| 8548 | Bundle wearableBundle = new Bundle(); |
| 8549 | |
| 8550 | if (!mActions.isEmpty()) { |
| 8551 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 8552 | } |
| 8553 | if (mFlags != DEFAULT_FLAGS) { |
| 8554 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 8555 | } |
| 8556 | if (mDisplayIntent != null) { |
| 8557 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 8558 | } |
| 8559 | if (!mPages.isEmpty()) { |
| 8560 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 8561 | new Notification[mPages.size()])); |
| 8562 | } |
| 8563 | if (mBackground != null) { |
| 8564 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 8565 | } |
| 8566 | if (mContentIcon != 0) { |
| 8567 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 8568 | } |
| 8569 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 8570 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 8571 | } |
| 8572 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 8573 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 8574 | mContentActionIndex); |
| 8575 | } |
| 8576 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 8577 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 8578 | } |
| 8579 | if (mCustomContentHeight != 0) { |
| 8580 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 8581 | } |
| 8582 | if (mGravity != DEFAULT_GRAVITY) { |
| 8583 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 8584 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8585 | if (mHintScreenTimeout != 0) { |
| 8586 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 8587 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8588 | if (mDismissalId != null) { |
| 8589 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 8590 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8591 | if (mBridgeTag != null) { |
| 8592 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 8593 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8594 | |
| 8595 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 8596 | return builder; |
| 8597 | } |
| 8598 | |
| 8599 | @Override |
| 8600 | public WearableExtender clone() { |
| 8601 | WearableExtender that = new WearableExtender(); |
| 8602 | that.mActions = new ArrayList<Action>(this.mActions); |
| 8603 | that.mFlags = this.mFlags; |
| 8604 | that.mDisplayIntent = this.mDisplayIntent; |
| 8605 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 8606 | that.mBackground = this.mBackground; |
| 8607 | that.mContentIcon = this.mContentIcon; |
| 8608 | that.mContentIconGravity = this.mContentIconGravity; |
| 8609 | that.mContentActionIndex = this.mContentActionIndex; |
| 8610 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 8611 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 8612 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8613 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8614 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8615 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8616 | return that; |
| 8617 | } |
| 8618 | |
| 8619 | /** |
| 8620 | * Add a wearable action to this notification. |
| 8621 | * |
| 8622 | * <p>When wearable actions are added using this method, the set of actions that |
| 8623 | * show on a wearable device splits from devices that only show actions added |
| 8624 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 8625 | * of which actions display on different devices. |
| 8626 | * |
| 8627 | * @param action the action to add to this notification |
| 8628 | * @return this object for method chaining |
| 8629 | * @see android.app.Notification.Action |
| 8630 | */ |
| 8631 | public WearableExtender addAction(Action action) { |
| 8632 | mActions.add(action); |
| 8633 | return this; |
| 8634 | } |
| 8635 | |
| 8636 | /** |
| 8637 | * Adds wearable actions to this notification. |
| 8638 | * |
| 8639 | * <p>When wearable actions are added using this method, the set of actions that |
| 8640 | * show on a wearable device splits from devices that only show actions added |
| 8641 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 8642 | * of which actions display on different devices. |
| 8643 | * |
| 8644 | * @param actions the actions to add to this notification |
| 8645 | * @return this object for method chaining |
| 8646 | * @see android.app.Notification.Action |
| 8647 | */ |
| 8648 | public WearableExtender addActions(List<Action> actions) { |
| 8649 | mActions.addAll(actions); |
| 8650 | return this; |
| 8651 | } |
| 8652 | |
| 8653 | /** |
| 8654 | * Clear all wearable actions present on this builder. |
| 8655 | * @return this object for method chaining. |
| 8656 | * @see #addAction |
| 8657 | */ |
| 8658 | public WearableExtender clearActions() { |
| 8659 | mActions.clear(); |
| 8660 | return this; |
| 8661 | } |
| 8662 | |
| 8663 | /** |
| 8664 | * Get the wearable actions present on this notification. |
| 8665 | */ |
| 8666 | public List<Action> getActions() { |
| 8667 | return mActions; |
| 8668 | } |
| 8669 | |
| 8670 | /** |
| 8671 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8672 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 8673 | * |
| 8674 | * <pre class="prettyprint"> |
| 8675 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 8676 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 8677 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 8678 | * Notification notif = new Notification.Builder(context) |
| 8679 | * .extend(new Notification.WearableExtender() |
| 8680 | * .setDisplayIntent(displayPendingIntent) |
| 8681 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 8682 | * .build();</pre> |
| 8683 | * |
| 8684 | * <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] | 8685 | * should have an empty task affinity. It is also recommended to use the device |
| 8686 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8687 | * |
| 8688 | * <p>Example AndroidManifest.xml entry: |
| 8689 | * <pre class="prettyprint"> |
| 8690 | * <activity android:name="com.example.MyDisplayActivity" |
| 8691 | * android:exported="true" |
| 8692 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 8693 | * android:taskAffinity="" |
| 8694 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8695 | * |
| 8696 | * @param intent the {@link PendingIntent} for an activity |
| 8697 | * @return this object for method chaining |
| 8698 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8699 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8700 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8701 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8702 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 8703 | mDisplayIntent = intent; |
| 8704 | return this; |
| 8705 | } |
| 8706 | |
| 8707 | /** |
| 8708 | * Get the intent to launch inside of an activity view when displaying this |
| 8709 | * notification. This {@code PendingIntent} should be for an activity. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8710 | * |
| 8711 | * @deprecated Display intents are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8712 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8713 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8714 | public PendingIntent getDisplayIntent() { |
| 8715 | return mDisplayIntent; |
| 8716 | } |
| 8717 | |
| 8718 | /** |
| 8719 | * Add an additional page of content to display with this notification. The current |
| 8720 | * notification forms the first page, and pages added using this function form |
| 8721 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8722 | * sections. |
| 8723 | * |
| 8724 | * @param page the notification to add as another page |
| 8725 | * @return this object for method chaining |
| 8726 | * @see android.app.Notification.WearableExtender#getPages |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8727 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8728 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8729 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8730 | public WearableExtender addPage(Notification page) { |
| 8731 | mPages.add(page); |
| 8732 | return this; |
| 8733 | } |
| 8734 | |
| 8735 | /** |
| 8736 | * Add additional pages of content to display with this notification. The current |
| 8737 | * notification forms the first page, and pages added using this function form |
| 8738 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8739 | * sections. |
| 8740 | * |
| 8741 | * @param pages a list of notifications |
| 8742 | * @return this object for method chaining |
| 8743 | * @see android.app.Notification.WearableExtender#getPages |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8744 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8745 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8746 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8747 | public WearableExtender addPages(List<Notification> pages) { |
| 8748 | mPages.addAll(pages); |
| 8749 | return this; |
| 8750 | } |
| 8751 | |
| 8752 | /** |
| 8753 | * Clear all additional pages present on this builder. |
| 8754 | * @return this object for method chaining. |
| 8755 | * @see #addPage |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8756 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8757 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8758 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8759 | public WearableExtender clearPages() { |
| 8760 | mPages.clear(); |
| 8761 | return this; |
| 8762 | } |
| 8763 | |
| 8764 | /** |
| 8765 | * Get the array of additional pages of content for displaying this notification. The |
| 8766 | * current notification forms the first page, and elements within this array form |
| 8767 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8768 | * sections. |
| 8769 | * @return the pages for this notification |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8770 | * @deprecated Multiple content pages are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8771 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8772 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8773 | public List<Notification> getPages() { |
| 8774 | return mPages; |
| 8775 | } |
| 8776 | |
| 8777 | /** |
| 8778 | * Set a background image to be displayed behind the notification content. |
| 8779 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 8780 | * will work with any notification style. |
| 8781 | * |
| 8782 | * @param background the background bitmap |
| 8783 | * @return this object for method chaining |
| 8784 | * @see android.app.Notification.WearableExtender#getBackground |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8785 | * @deprecated Background images are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8786 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8787 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8788 | public WearableExtender setBackground(Bitmap background) { |
| 8789 | mBackground = background; |
| 8790 | return this; |
| 8791 | } |
| 8792 | |
| 8793 | /** |
| 8794 | * Get a background image to be displayed behind the notification content. |
| 8795 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 8796 | * will work with any notification style. |
| 8797 | * |
| 8798 | * @return the background image |
| 8799 | * @see android.app.Notification.WearableExtender#setBackground |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8800 | * @deprecated Background images are no longer supported. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8801 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8802 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8803 | public Bitmap getBackground() { |
| 8804 | return mBackground; |
| 8805 | } |
| 8806 | |
| 8807 | /** |
| 8808 | * Set an icon that goes with the content of this notification. |
| 8809 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8810 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8811 | public WearableExtender setContentIcon(int icon) { |
| 8812 | mContentIcon = icon; |
| 8813 | return this; |
| 8814 | } |
| 8815 | |
| 8816 | /** |
| 8817 | * Get an icon that goes with the content of this notification. |
| 8818 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8819 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8820 | public int getContentIcon() { |
| 8821 | return mContentIcon; |
| 8822 | } |
| 8823 | |
| 8824 | /** |
| 8825 | * Set the gravity that the content icon should have within the notification display. |
| 8826 | * Supported values include {@link android.view.Gravity#START} and |
| 8827 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 8828 | * @see #setContentIcon |
| 8829 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8830 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8831 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 8832 | mContentIconGravity = contentIconGravity; |
| 8833 | return this; |
| 8834 | } |
| 8835 | |
| 8836 | /** |
| 8837 | * Get the gravity that the content icon should have within the notification display. |
| 8838 | * Supported values include {@link android.view.Gravity#START} and |
| 8839 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 8840 | * @see #getContentIcon |
| 8841 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8842 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8843 | public int getContentIconGravity() { |
| 8844 | return mContentIconGravity; |
| 8845 | } |
| 8846 | |
| 8847 | /** |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8848 | * Set an action from this notification's actions as the primary action. If the action has a |
| 8849 | * {@link RemoteInput} associated with it, shortcuts to the options for that input are shown |
| 8850 | * directly on the notification. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8851 | * |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8852 | * @param actionIndex The index of the primary action. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8853 | * If wearable actions were added to the main notification, this index |
| 8854 | * will apply to that list, otherwise it will apply to the regular |
| 8855 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8856 | */ |
| 8857 | public WearableExtender setContentAction(int actionIndex) { |
| 8858 | mContentActionIndex = actionIndex; |
| 8859 | return this; |
| 8860 | } |
| 8861 | |
| 8862 | /** |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 8863 | * Get the index of the notification action, if any, that was specified as the primary |
| 8864 | * action. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8865 | * |
| 8866 | * <p>If wearable specific actions were added to the main notification, this index will |
| 8867 | * 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] | 8868 | * |
| 8869 | * @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] | 8870 | */ |
| 8871 | public int getContentAction() { |
| 8872 | return mContentActionIndex; |
| 8873 | } |
| 8874 | |
| 8875 | /** |
| 8876 | * Set the gravity that this notification should have within the available viewport space. |
| 8877 | * Supported values include {@link android.view.Gravity#TOP}, |
| 8878 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 8879 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 8880 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8881 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8882 | public WearableExtender setGravity(int gravity) { |
| 8883 | mGravity = gravity; |
| 8884 | return this; |
| 8885 | } |
| 8886 | |
| 8887 | /** |
| 8888 | * Get the gravity that this notification should have within the available viewport space. |
| 8889 | * Supported values include {@link android.view.Gravity#TOP}, |
| 8890 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 8891 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 8892 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8893 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8894 | public int getGravity() { |
| 8895 | return mGravity; |
| 8896 | } |
| 8897 | |
| 8898 | /** |
| 8899 | * Set the custom size preset for the display of this notification out of the available |
| 8900 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 8901 | * {@link #SIZE_LARGE}. |
| 8902 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 8903 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 8904 | * documentation for the preset in question. See also |
| 8905 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 8906 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8907 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8908 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 8909 | mCustomSizePreset = sizePreset; |
| 8910 | return this; |
| 8911 | } |
| 8912 | |
| 8913 | /** |
| 8914 | * Get the custom size preset for the display of this notification out of the available |
| 8915 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 8916 | * {@link #SIZE_LARGE}. |
| 8917 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 8918 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 8919 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 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 getCustomSizePreset() { |
| 8923 | return mCustomSizePreset; |
| 8924 | } |
| 8925 | |
| 8926 | /** |
| 8927 | * Set the custom height in pixels for the display of this notification's content. |
| 8928 | * <p>This option is only available for custom display notifications created |
| 8929 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 8930 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 8931 | * {@link #getCustomContentHeight}. |
| 8932 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8933 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8934 | public WearableExtender setCustomContentHeight(int height) { |
| 8935 | mCustomContentHeight = height; |
| 8936 | return this; |
| 8937 | } |
| 8938 | |
| 8939 | /** |
| 8940 | * Get the custom height in pixels for the display of this notification's content. |
| 8941 | * <p>This option is only available for custom display notifications created |
| 8942 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 8943 | * {@link #setCustomContentHeight}. |
| 8944 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8945 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8946 | public int getCustomContentHeight() { |
| 8947 | return mCustomContentHeight; |
| 8948 | } |
| 8949 | |
| 8950 | /** |
| 8951 | * Set whether the scrolling position for the contents of this notification should start |
| 8952 | * at the bottom of the contents instead of the top when the contents are too long to |
| 8953 | * display within the screen. Default is false (start scroll at the top). |
| 8954 | */ |
| 8955 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 8956 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 8957 | return this; |
| 8958 | } |
| 8959 | |
| 8960 | /** |
| 8961 | * Get whether the scrolling position for the contents of this notification should start |
| 8962 | * at the bottom of the contents instead of the top when the contents are too long to |
| 8963 | * display within the screen. Default is false (start scroll at the top). |
| 8964 | */ |
| 8965 | public boolean getStartScrollBottom() { |
| 8966 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 8967 | } |
| 8968 | |
| 8969 | /** |
| 8970 | * Set whether the content intent is available when the wearable device is not connected |
| 8971 | * to a companion device. The user can still trigger this intent when the wearable device |
| 8972 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 8973 | * Defaults to true. |
| 8974 | */ |
| 8975 | public WearableExtender setContentIntentAvailableOffline( |
| 8976 | boolean contentIntentAvailableOffline) { |
| 8977 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 8978 | return this; |
| 8979 | } |
| 8980 | |
| 8981 | /** |
| 8982 | * Get whether the content intent is available when the wearable device is not connected |
| 8983 | * to a companion device. The user can still trigger this intent when the wearable device |
| 8984 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 8985 | * Defaults to true. |
| 8986 | */ |
| 8987 | public boolean getContentIntentAvailableOffline() { |
| 8988 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 8989 | } |
| 8990 | |
| 8991 | /** |
| 8992 | * Set a hint that this notification's icon should not be displayed. |
| 8993 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 8994 | * @return this object for method chaining |
| 8995 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8996 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8997 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 8998 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 8999 | return this; |
| 9000 | } |
| 9001 | |
| 9002 | /** |
| 9003 | * Get a hint that this notification's icon should not be displayed. |
| 9004 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 9005 | * The default value is {@code false} if this was never set. |
| 9006 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9007 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9008 | public boolean getHintHideIcon() { |
| 9009 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 9010 | } |
| 9011 | |
| 9012 | /** |
| 9013 | * Set a visual hint that only the background image of this notification should be |
| 9014 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 9015 | * to sub-pages added using {@link #addPage}. |
| 9016 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9017 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9018 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 9019 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 9020 | return this; |
| 9021 | } |
| 9022 | |
| 9023 | /** |
| 9024 | * Get a visual hint that only the background image of this notification should be |
| 9025 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 9026 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 9027 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9028 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9029 | public boolean getHintShowBackgroundOnly() { |
| 9030 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 9031 | } |
| 9032 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9033 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 9034 | * Set a hint that this notification's background should not be clipped if possible, |
| 9035 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 9036 | * 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] | 9037 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 9038 | * @return this object for method chaining |
| 9039 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9040 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9041 | public WearableExtender setHintAvoidBackgroundClipping( |
| 9042 | boolean hintAvoidBackgroundClipping) { |
| 9043 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 9044 | return this; |
| 9045 | } |
| 9046 | |
| 9047 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 9048 | * Get a hint that this notification's background should not be clipped if possible, |
| 9049 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 9050 | * 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] | 9051 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 9052 | * otherwise. The default value is {@code false} if this was never set. |
| 9053 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9054 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9055 | public boolean getHintAvoidBackgroundClipping() { |
| 9056 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 9057 | } |
| 9058 | |
| 9059 | /** |
| 9060 | * Set a hint that the screen should remain on for at least this duration when |
| 9061 | * this notification is displayed on the screen. |
| 9062 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 9063 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 9064 | * @return this object for method chaining |
| 9065 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9066 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9067 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 9068 | mHintScreenTimeout = timeout; |
| 9069 | return this; |
| 9070 | } |
| 9071 | |
| 9072 | /** |
| 9073 | * Get the duration, in milliseconds, that the screen should remain on for |
| 9074 | * when this notification is displayed. |
| 9075 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 9076 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 9077 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 9078 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 9079 | public int getHintScreenTimeout() { |
| 9080 | return mHintScreenTimeout; |
| 9081 | } |
| 9082 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9083 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9084 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 9085 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 9086 | * qr codes, as well as other simple black-and-white tickets. |
| 9087 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 9088 | * @return this object for method chaining |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9089 | * @deprecated This feature is no longer supported. |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9090 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9091 | @Deprecated |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9092 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 9093 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 9094 | return this; |
| 9095 | } |
| 9096 | |
| 9097 | /** |
| 9098 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 9099 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 9100 | * qr codes, as well as other simple black-and-white tickets. |
| 9101 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 9102 | * otherwise. The default value is {@code false} if this was never set. |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9103 | * @deprecated This feature is no longer supported. |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9104 | */ |
Gus Prevas | d736375 | 2018-09-18 14:35:15 -0400 | [diff] [blame] | 9105 | @Deprecated |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 9106 | public boolean getHintAmbientBigPicture() { |
| 9107 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 9108 | } |
| 9109 | |
| 9110 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 9111 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 9112 | * directly, telling the platform that it can generate the appropriate transitions. |
| 9113 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 9114 | * an activity and transitions should be generated, false otherwise. |
| 9115 | * @return this object for method chaining |
| 9116 | */ |
| 9117 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 9118 | boolean hintContentIntentLaunchesActivity) { |
| 9119 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 9120 | return this; |
| 9121 | } |
| 9122 | |
| 9123 | /** |
| 9124 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 9125 | * directly, telling the platform that it can generate the appropriate transitions |
| 9126 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 9127 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 9128 | */ |
| 9129 | public boolean getHintContentIntentLaunchesActivity() { |
| 9130 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 9131 | } |
| 9132 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9133 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9134 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 9135 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 9136 | * 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] | 9137 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9138 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 9139 | * @param dismissalId the dismissal id of the notification. |
| 9140 | * @return this object for method chaining |
| 9141 | */ |
| 9142 | public WearableExtender setDismissalId(String dismissalId) { |
| 9143 | mDismissalId = dismissalId; |
| 9144 | return this; |
| 9145 | } |
| 9146 | |
| 9147 | /** |
| 9148 | * Returns the dismissal id of the notification. |
| 9149 | * @return the dismissal id of the notification or null if it has not been set. |
| 9150 | */ |
| 9151 | public String getDismissalId() { |
| 9152 | return mDismissalId; |
| 9153 | } |
| 9154 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 9155 | /** |
| 9156 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 9157 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 9158 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 9159 | * Features to Notifications</a> for more information. |
| 9160 | * @param bridgeTag the bridge tag of the notification. |
| 9161 | * @return this object for method chaining |
| 9162 | */ |
| 9163 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 9164 | mBridgeTag = bridgeTag; |
| 9165 | return this; |
| 9166 | } |
| 9167 | |
| 9168 | /** |
| 9169 | * Returns the bridge tag of the notification. |
| 9170 | * @return the bridge tag or null if not present. |
| 9171 | */ |
| 9172 | public String getBridgeTag() { |
| 9173 | return mBridgeTag; |
| 9174 | } |
| 9175 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9176 | private void setFlag(int mask, boolean value) { |
| 9177 | if (value) { |
| 9178 | mFlags |= mask; |
| 9179 | } else { |
| 9180 | mFlags &= ~mask; |
| 9181 | } |
| 9182 | } |
| 9183 | } |
| 9184 | |
| 9185 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9186 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 9187 | * with car extensions: |
| 9188 | * |
| 9189 | * <ol> |
| 9190 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 9191 | * properties. |
| 9192 | * <li>Create a {@link CarExtender}. |
| 9193 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 9194 | * {@link CarExtender}. |
| 9195 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9196 | * to apply the extensions to a notification. |
| 9197 | * </ol> |
| 9198 | * |
| 9199 | * <pre class="prettyprint"> |
| 9200 | * Notification notification = new Notification.Builder(context) |
| 9201 | * ... |
| 9202 | * .extend(new CarExtender() |
| 9203 | * .set*(...)) |
| 9204 | * .build(); |
| 9205 | * </pre> |
| 9206 | * |
| 9207 | * <p>Car extensions can be accessed on an existing notification by using the |
| 9208 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 9209 | * to access values. |
| 9210 | */ |
| 9211 | public static final class CarExtender implements Extender { |
| 9212 | private static final String TAG = "CarExtender"; |
| 9213 | |
| 9214 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 9215 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 9216 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 9217 | private static final String EXTRA_COLOR = "app_color"; |
| 9218 | |
| 9219 | private Bitmap mLargeIcon; |
| 9220 | private UnreadConversation mUnreadConversation; |
| 9221 | private int mColor = Notification.COLOR_DEFAULT; |
| 9222 | |
| 9223 | /** |
| 9224 | * Create a {@link CarExtender} with default options. |
| 9225 | */ |
| 9226 | public CarExtender() { |
| 9227 | } |
| 9228 | |
| 9229 | /** |
| 9230 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 9231 | * |
| 9232 | * @param notif The notification from which to copy options. |
| 9233 | */ |
| 9234 | public CarExtender(Notification notif) { |
| 9235 | Bundle carBundle = notif.extras == null ? |
| 9236 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 9237 | if (carBundle != null) { |
| 9238 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 9239 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 9240 | |
| 9241 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 9242 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 9243 | } |
| 9244 | } |
| 9245 | |
| 9246 | /** |
| 9247 | * Apply car extensions to a notification that is being built. This is typically called by |
| 9248 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9249 | * method of {@link Notification.Builder}. |
| 9250 | */ |
| 9251 | @Override |
| 9252 | public Notification.Builder extend(Notification.Builder builder) { |
| 9253 | Bundle carExtensions = new Bundle(); |
| 9254 | |
| 9255 | if (mLargeIcon != null) { |
| 9256 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 9257 | } |
| 9258 | if (mColor != Notification.COLOR_DEFAULT) { |
| 9259 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 9260 | } |
| 9261 | |
| 9262 | if (mUnreadConversation != null) { |
| 9263 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 9264 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 9265 | } |
| 9266 | |
| 9267 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 9268 | return builder; |
| 9269 | } |
| 9270 | |
| 9271 | /** |
| 9272 | * Sets the accent color to use when Android Auto presents the notification. |
| 9273 | * |
| 9274 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 9275 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 9276 | * automotive setting. This method can be used to override the color provided in the |
| 9277 | * notification in such a situation. |
| 9278 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9279 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9280 | mColor = color; |
| 9281 | return this; |
| 9282 | } |
| 9283 | |
| 9284 | /** |
| 9285 | * Gets the accent color. |
| 9286 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 9287 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9288 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9289 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9290 | public int getColor() { |
| 9291 | return mColor; |
| 9292 | } |
| 9293 | |
| 9294 | /** |
| 9295 | * Sets the large icon of the car notification. |
| 9296 | * |
| 9297 | * If no large icon is set in the extender, Android Auto will display the icon |
| 9298 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 9299 | * |
| 9300 | * @param largeIcon The large icon to use in the car notification. |
| 9301 | * @return This object for method chaining. |
| 9302 | */ |
| 9303 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 9304 | mLargeIcon = largeIcon; |
| 9305 | return this; |
| 9306 | } |
| 9307 | |
| 9308 | /** |
| 9309 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 9310 | * |
| 9311 | * @return The large icon for the car notification. |
| 9312 | * @see CarExtender#setLargeIcon |
| 9313 | */ |
| 9314 | public Bitmap getLargeIcon() { |
| 9315 | return mLargeIcon; |
| 9316 | } |
| 9317 | |
| 9318 | /** |
| 9319 | * Sets the unread conversation in a message notification. |
| 9320 | * |
| 9321 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 9322 | * @return This object for method chaining. |
| 9323 | */ |
| 9324 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 9325 | mUnreadConversation = unreadConversation; |
| 9326 | return this; |
| 9327 | } |
| 9328 | |
| 9329 | /** |
| 9330 | * Returns the unread conversation conveyed by this notification. |
| 9331 | * @see #setUnreadConversation(UnreadConversation) |
| 9332 | */ |
| 9333 | public UnreadConversation getUnreadConversation() { |
| 9334 | return mUnreadConversation; |
| 9335 | } |
| 9336 | |
| 9337 | /** |
| 9338 | * A class which holds the unread messages from a conversation. |
| 9339 | */ |
| 9340 | public static class UnreadConversation { |
| 9341 | private static final String KEY_AUTHOR = "author"; |
| 9342 | private static final String KEY_TEXT = "text"; |
| 9343 | private static final String KEY_MESSAGES = "messages"; |
| 9344 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 9345 | private static final String KEY_ON_REPLY = "on_reply"; |
| 9346 | private static final String KEY_ON_READ = "on_read"; |
| 9347 | private static final String KEY_PARTICIPANTS = "participants"; |
| 9348 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 9349 | |
| 9350 | private final String[] mMessages; |
| 9351 | private final RemoteInput mRemoteInput; |
| 9352 | private final PendingIntent mReplyPendingIntent; |
| 9353 | private final PendingIntent mReadPendingIntent; |
| 9354 | private final String[] mParticipants; |
| 9355 | private final long mLatestTimestamp; |
| 9356 | |
| 9357 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 9358 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 9359 | String[] participants, long latestTimestamp) { |
| 9360 | mMessages = messages; |
| 9361 | mRemoteInput = remoteInput; |
| 9362 | mReadPendingIntent = readPendingIntent; |
| 9363 | mReplyPendingIntent = replyPendingIntent; |
| 9364 | mParticipants = participants; |
| 9365 | mLatestTimestamp = latestTimestamp; |
| 9366 | } |
| 9367 | |
| 9368 | /** |
| 9369 | * Gets the list of messages conveyed by this notification. |
| 9370 | */ |
| 9371 | public String[] getMessages() { |
| 9372 | return mMessages; |
| 9373 | } |
| 9374 | |
| 9375 | /** |
| 9376 | * Gets the remote input that will be used to convey the response to a message list, or |
| 9377 | * null if no such remote input exists. |
| 9378 | */ |
| 9379 | public RemoteInput getRemoteInput() { |
| 9380 | return mRemoteInput; |
| 9381 | } |
| 9382 | |
| 9383 | /** |
| 9384 | * Gets the pending intent that will be triggered when the user replies to this |
| 9385 | * notification. |
| 9386 | */ |
| 9387 | public PendingIntent getReplyPendingIntent() { |
| 9388 | return mReplyPendingIntent; |
| 9389 | } |
| 9390 | |
| 9391 | /** |
| 9392 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 9393 | * in this object's message list. |
| 9394 | */ |
| 9395 | public PendingIntent getReadPendingIntent() { |
| 9396 | return mReadPendingIntent; |
| 9397 | } |
| 9398 | |
| 9399 | /** |
| 9400 | * Gets the participants in the conversation. |
| 9401 | */ |
| 9402 | public String[] getParticipants() { |
| 9403 | return mParticipants; |
| 9404 | } |
| 9405 | |
| 9406 | /** |
| 9407 | * Gets the firs participant in the conversation. |
| 9408 | */ |
| 9409 | public String getParticipant() { |
| 9410 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 9411 | } |
| 9412 | |
| 9413 | /** |
| 9414 | * Gets the timestamp of the conversation. |
| 9415 | */ |
| 9416 | public long getLatestTimestamp() { |
| 9417 | return mLatestTimestamp; |
| 9418 | } |
| 9419 | |
| 9420 | Bundle getBundleForUnreadConversation() { |
| 9421 | Bundle b = new Bundle(); |
| 9422 | String author = null; |
| 9423 | if (mParticipants != null && mParticipants.length > 1) { |
| 9424 | author = mParticipants[0]; |
| 9425 | } |
| 9426 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 9427 | for (int i = 0; i < messages.length; i++) { |
| 9428 | Bundle m = new Bundle(); |
| 9429 | m.putString(KEY_TEXT, mMessages[i]); |
| 9430 | m.putString(KEY_AUTHOR, author); |
| 9431 | messages[i] = m; |
| 9432 | } |
| 9433 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 9434 | if (mRemoteInput != null) { |
| 9435 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 9436 | } |
| 9437 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 9438 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 9439 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 9440 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 9441 | return b; |
| 9442 | } |
| 9443 | |
| 9444 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 9445 | if (b == null) { |
| 9446 | return null; |
| 9447 | } |
| 9448 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 9449 | String[] messages = null; |
| 9450 | if (parcelableMessages != null) { |
| 9451 | String[] tmp = new String[parcelableMessages.length]; |
| 9452 | boolean success = true; |
| 9453 | for (int i = 0; i < tmp.length; i++) { |
| 9454 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 9455 | success = false; |
| 9456 | break; |
| 9457 | } |
| 9458 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 9459 | if (tmp[i] == null) { |
| 9460 | success = false; |
| 9461 | break; |
| 9462 | } |
| 9463 | } |
| 9464 | if (success) { |
| 9465 | messages = tmp; |
| 9466 | } else { |
| 9467 | return null; |
| 9468 | } |
| 9469 | } |
| 9470 | |
| 9471 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 9472 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 9473 | |
| 9474 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 9475 | |
| 9476 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 9477 | if (participants == null || participants.length != 1) { |
| 9478 | return null; |
| 9479 | } |
| 9480 | |
| 9481 | return new UnreadConversation(messages, |
| 9482 | remoteInput, |
| 9483 | onReply, |
| 9484 | onRead, |
| 9485 | participants, b.getLong(KEY_TIMESTAMP)); |
| 9486 | } |
| 9487 | }; |
| 9488 | |
| 9489 | /** |
| 9490 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 9491 | */ |
| 9492 | public static class Builder { |
| 9493 | private final List<String> mMessages = new ArrayList<String>(); |
| 9494 | private final String mParticipant; |
| 9495 | private RemoteInput mRemoteInput; |
| 9496 | private PendingIntent mReadPendingIntent; |
| 9497 | private PendingIntent mReplyPendingIntent; |
| 9498 | private long mLatestTimestamp; |
| 9499 | |
| 9500 | /** |
| 9501 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 9502 | * |
| 9503 | * @param name The name of the other participant in the conversation. |
| 9504 | */ |
| 9505 | public Builder(String name) { |
| 9506 | mParticipant = name; |
| 9507 | } |
| 9508 | |
| 9509 | /** |
| 9510 | * Appends a new unread message to the list of messages for this conversation. |
| 9511 | * |
| 9512 | * The messages should be added from oldest to newest. |
| 9513 | * |
| 9514 | * @param message The text of the new unread message. |
| 9515 | * @return This object for method chaining. |
| 9516 | */ |
| 9517 | public Builder addMessage(String message) { |
| 9518 | mMessages.add(message); |
| 9519 | return this; |
| 9520 | } |
| 9521 | |
| 9522 | /** |
| 9523 | * Sets the pending intent and remote input which will convey the reply to this |
| 9524 | * notification. |
| 9525 | * |
| 9526 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 9527 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 9528 | * @return This object for method chaining. |
| 9529 | * |
| 9530 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 9531 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 9532 | */ |
| 9533 | public Builder setReplyAction( |
| 9534 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 9535 | mRemoteInput = remoteInput; |
| 9536 | mReplyPendingIntent = pendingIntent; |
| 9537 | |
| 9538 | return this; |
| 9539 | } |
| 9540 | |
| 9541 | /** |
| 9542 | * Sets the pending intent that will be sent once the messages in this notification |
| 9543 | * are read. |
| 9544 | * |
| 9545 | * @param pendingIntent The pending intent to use. |
| 9546 | * @return This object for method chaining. |
| 9547 | */ |
| 9548 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 9549 | mReadPendingIntent = pendingIntent; |
| 9550 | return this; |
| 9551 | } |
| 9552 | |
| 9553 | /** |
| 9554 | * Sets the timestamp of the most recent message in an unread conversation. |
| 9555 | * |
| 9556 | * If a messaging notification has been posted by your application and has not |
| 9557 | * yet been cancelled, posting a later notification with the same id and tag |
| 9558 | * but without a newer timestamp may result in Android Auto not displaying a |
| 9559 | * heads up notification for the later notification. |
| 9560 | * |
| 9561 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 9562 | * @return This object for method chaining. |
| 9563 | */ |
| 9564 | public Builder setLatestTimestamp(long timestamp) { |
| 9565 | mLatestTimestamp = timestamp; |
| 9566 | return this; |
| 9567 | } |
| 9568 | |
| 9569 | /** |
| 9570 | * Builds a new unread conversation object. |
| 9571 | * |
| 9572 | * @return The new unread conversation object. |
| 9573 | */ |
| 9574 | public UnreadConversation build() { |
| 9575 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 9576 | String[] participants = { mParticipant }; |
| 9577 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 9578 | mReadPendingIntent, participants, mLatestTimestamp); |
| 9579 | } |
| 9580 | } |
| 9581 | } |
| 9582 | |
| 9583 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9584 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 9585 | * with a TV extension: |
| 9586 | * |
| 9587 | * <ol> |
| 9588 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 9589 | * <li>Create a {@link TvExtender}. |
| 9590 | * <li>Set TV-specific properties using the {@code set} methods of |
| 9591 | * {@link TvExtender}. |
| 9592 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9593 | * to apply the extension to a notification. |
| 9594 | * </ol> |
| 9595 | * |
| 9596 | * <pre class="prettyprint"> |
| 9597 | * Notification notification = new Notification.Builder(context) |
| 9598 | * ... |
| 9599 | * .extend(new TvExtender() |
| 9600 | * .set*(...)) |
| 9601 | * .build(); |
| 9602 | * </pre> |
| 9603 | * |
| 9604 | * <p>TV extensions can be accessed on an existing notification by using the |
| 9605 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 9606 | * to access values. |
| 9607 | * |
| 9608 | * @hide |
| 9609 | */ |
| 9610 | @SystemApi |
| 9611 | public static final class TvExtender implements Extender { |
| 9612 | private static final String TAG = "TvExtender"; |
| 9613 | |
| 9614 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 9615 | private static final String EXTRA_FLAGS = "flags"; |
| 9616 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 9617 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9618 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9619 | private static final String EXTRA_SUPPRESS_SHOW_OVER_APPS = "suppressShowOverApps"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9620 | |
| 9621 | // Flags bitwise-ored to mFlags |
| 9622 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 9623 | |
| 9624 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9625 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9626 | private PendingIntent mContentIntent; |
| 9627 | private PendingIntent mDeleteIntent; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9628 | private boolean mSuppressShowOverApps; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9629 | |
| 9630 | /** |
| 9631 | * Create a {@link TvExtender} with default options. |
| 9632 | */ |
| 9633 | public TvExtender() { |
| 9634 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 9635 | } |
| 9636 | |
| 9637 | /** |
| 9638 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 9639 | * |
| 9640 | * @param notif The notification from which to copy options. |
| 9641 | */ |
| 9642 | public TvExtender(Notification notif) { |
| 9643 | Bundle bundle = notif.extras == null ? |
| 9644 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 9645 | if (bundle != null) { |
| 9646 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9647 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9648 | mSuppressShowOverApps = bundle.getBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9649 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 9650 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 9651 | } |
| 9652 | } |
| 9653 | |
| 9654 | /** |
| 9655 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 9656 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9657 | * method of {@link Notification.Builder}. |
| 9658 | */ |
| 9659 | @Override |
| 9660 | public Notification.Builder extend(Notification.Builder builder) { |
| 9661 | Bundle bundle = new Bundle(); |
| 9662 | |
| 9663 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9664 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9665 | bundle.putBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS, mSuppressShowOverApps); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9666 | if (mContentIntent != null) { |
| 9667 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 9668 | } |
| 9669 | |
| 9670 | if (mDeleteIntent != null) { |
| 9671 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 9672 | } |
| 9673 | |
| 9674 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 9675 | return builder; |
| 9676 | } |
| 9677 | |
| 9678 | /** |
| 9679 | * Returns true if this notification should be shown on TV. This method return true |
| 9680 | * if the notification was extended with a TvExtender. |
| 9681 | */ |
| 9682 | public boolean isAvailableOnTv() { |
| 9683 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 9684 | } |
| 9685 | |
| 9686 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9687 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 9688 | * It can be different from the channel that the notification is delivered to when |
| 9689 | * posting on a non-TV device. |
| 9690 | */ |
| 9691 | public TvExtender setChannel(String channelId) { |
| 9692 | mChannelId = channelId; |
| 9693 | return this; |
| 9694 | } |
| 9695 | |
| 9696 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 9697 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 9698 | * It can be different from the channel that the notification is delivered to when |
| 9699 | * posting on a non-TV device. |
| 9700 | */ |
| 9701 | public TvExtender setChannelId(String channelId) { |
| 9702 | mChannelId = channelId; |
| 9703 | return this; |
| 9704 | } |
| 9705 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 9706 | /** @removed */ |
| 9707 | @Deprecated |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9708 | public String getChannel() { |
| 9709 | return mChannelId; |
| 9710 | } |
| 9711 | |
| 9712 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 9713 | * Returns the id of the channel this notification posts to on TV. |
| 9714 | */ |
| 9715 | public String getChannelId() { |
| 9716 | return mChannelId; |
| 9717 | } |
| 9718 | |
| 9719 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9720 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 9721 | * If provided, it is used instead of the content intent specified |
| 9722 | * at the level of Notification. |
| 9723 | */ |
| 9724 | public TvExtender setContentIntent(PendingIntent intent) { |
| 9725 | mContentIntent = intent; |
| 9726 | return this; |
| 9727 | } |
| 9728 | |
| 9729 | /** |
| 9730 | * Returns the TV-specific content intent. If this method returns null, the |
| 9731 | * main content intent on the notification should be used. |
| 9732 | * |
| 9733 | * @see {@link Notification#contentIntent} |
| 9734 | */ |
| 9735 | public PendingIntent getContentIntent() { |
| 9736 | return mContentIntent; |
| 9737 | } |
| 9738 | |
| 9739 | /** |
| 9740 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 9741 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 9742 | * at the level of Notification. |
| 9743 | */ |
| 9744 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 9745 | mDeleteIntent = intent; |
| 9746 | return this; |
| 9747 | } |
| 9748 | |
| 9749 | /** |
| 9750 | * Returns the TV-specific delete intent. If this method returns null, the |
| 9751 | * main delete intent on the notification should be used. |
| 9752 | * |
| 9753 | * @see {@link Notification#deleteIntent} |
| 9754 | */ |
| 9755 | public PendingIntent getDeleteIntent() { |
| 9756 | return mDeleteIntent; |
| 9757 | } |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9758 | |
| 9759 | /** |
| 9760 | * Specifies whether this notification should suppress showing a message over top of apps |
| 9761 | * outside of the launcher. |
| 9762 | */ |
| 9763 | public TvExtender setSuppressShowOverApps(boolean suppress) { |
| 9764 | mSuppressShowOverApps = suppress; |
| 9765 | return this; |
| 9766 | } |
| 9767 | |
| 9768 | /** |
| 9769 | * Returns true if this notification should not show messages over top of apps |
| 9770 | * outside of the launcher. |
| 9771 | */ |
| 9772 | public boolean getSuppressShowOverApps() { |
| 9773 | return mSuppressShowOverApps; |
| 9774 | } |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9775 | } |
| 9776 | |
| 9777 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9778 | * Get an array of Notification objects from a parcelable array bundle field. |
| 9779 | * Update the bundle to have a typed array so fetches in the future don't need |
| 9780 | * to do an array copy. |
| 9781 | */ |
| 9782 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 9783 | Parcelable[] array = bundle.getParcelableArray(key); |
| 9784 | if (array instanceof Notification[] || array == null) { |
| 9785 | return (Notification[]) array; |
| 9786 | } |
| 9787 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 9788 | Notification[].class); |
| 9789 | bundle.putParcelableArray(key, typedArray); |
| 9790 | return typedArray; |
| 9791 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 9792 | |
| 9793 | private static class BuilderRemoteViews extends RemoteViews { |
| 9794 | public BuilderRemoteViews(Parcel parcel) { |
| 9795 | super(parcel); |
| 9796 | } |
| 9797 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 9798 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 9799 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 9800 | } |
| 9801 | |
| 9802 | @Override |
| 9803 | public BuilderRemoteViews clone() { |
| 9804 | Parcel p = Parcel.obtain(); |
| 9805 | writeToParcel(p, 0); |
| 9806 | p.setDataPosition(0); |
| 9807 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 9808 | p.recycle(); |
| 9809 | return brv; |
| 9810 | } |
| 9811 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9812 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9813 | /** |
| 9814 | * A result object where information about the template that was created is saved. |
| 9815 | */ |
| 9816 | private static class TemplateBindResult { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9817 | int mIconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9818 | |
| 9819 | /** |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9820 | * 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] | 9821 | * with the right actions. |
| 9822 | */ |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9823 | public int getIconMarginEnd() { |
| 9824 | return mIconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9825 | } |
| 9826 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9827 | public void setIconMarginEnd(int iconMarginEnd) { |
| 9828 | this.mIconMarginEnd = iconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9829 | } |
| 9830 | } |
| 9831 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9832 | private static class StandardTemplateParams { |
| 9833 | boolean hasProgress = true; |
| 9834 | boolean ambient = false; |
| 9835 | CharSequence title; |
| 9836 | CharSequence text; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9837 | CharSequence headerTextSecondary; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 9838 | int maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9839 | boolean hideLargeIcon; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9840 | boolean hideReplyIcon; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9841 | |
| 9842 | final StandardTemplateParams reset() { |
| 9843 | hasProgress = true; |
| 9844 | ambient = false; |
| 9845 | title = null; |
| 9846 | text = null; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9847 | headerTextSecondary = null; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 9848 | maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9849 | return this; |
| 9850 | } |
| 9851 | |
| 9852 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 9853 | this.hasProgress = hasProgress; |
| 9854 | return this; |
| 9855 | } |
| 9856 | |
| 9857 | final StandardTemplateParams title(CharSequence title) { |
| 9858 | this.title = title; |
| 9859 | return this; |
| 9860 | } |
| 9861 | |
| 9862 | final StandardTemplateParams text(CharSequence text) { |
| 9863 | this.text = text; |
| 9864 | return this; |
| 9865 | } |
| 9866 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9867 | final StandardTemplateParams headerTextSecondary(CharSequence text) { |
| 9868 | this.headerTextSecondary = text; |
| 9869 | return this; |
| 9870 | } |
| 9871 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9872 | final StandardTemplateParams hideLargeIcon(boolean hideLargeIcon) { |
| 9873 | this.hideLargeIcon = hideLargeIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9874 | return this; |
| 9875 | } |
| 9876 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9877 | final StandardTemplateParams hideReplyIcon(boolean hideReplyIcon) { |
| 9878 | this.hideReplyIcon = hideReplyIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9879 | return this; |
| 9880 | } |
| 9881 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9882 | final StandardTemplateParams ambient(boolean ambient) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 9883 | Preconditions.checkState(title == null && text == null, "must set ambient before text"); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9884 | this.ambient = ambient; |
| 9885 | return this; |
| 9886 | } |
| 9887 | |
| 9888 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 9889 | Bundle extras = b.mN.extras; |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 9890 | this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE), ambient); |
| 9891 | |
| 9892 | // Big text notifications should contain their content when viewed in ambient mode. |
| 9893 | CharSequence text = extras.getCharSequence(EXTRA_BIG_TEXT); |
| 9894 | if (!ambient || TextUtils.isEmpty(text)) { |
| 9895 | text = extras.getCharSequence(EXTRA_TEXT); |
| 9896 | } |
| 9897 | this.text = b.processLegacyText(text, ambient); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9898 | return this; |
| 9899 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 9900 | |
| 9901 | /** |
| 9902 | * Set the maximum lines of remote input history lines allowed. |
| 9903 | * @param maxRemoteInputHistory The number of lines. |
| 9904 | * @return The builder for method chaining. |
| 9905 | */ |
| 9906 | public StandardTemplateParams setMaxRemoteInputHistory(int maxRemoteInputHistory) { |
| 9907 | this.maxRemoteInputHistory = maxRemoteInputHistory; |
| 9908 | return this; |
| 9909 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9910 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9911 | } |