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 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 19 | import static com.android.internal.util.NotificationColorUtil.satisfiesTextContrast; |
| 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; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 23 | import android.annotation.IntDef; |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 24 | import android.annotation.NonNull; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 25 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 26 | import android.annotation.RequiresPermission; |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 27 | import android.annotation.SdkConstant; |
| 28 | import android.annotation.SdkConstant.SdkConstantType; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 29 | import android.annotation.SystemApi; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 30 | import android.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 33 | import android.content.pm.ApplicationInfo; |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 34 | import android.content.pm.PackageManager; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 35 | import android.content.pm.PackageManager.NameNotFoundException; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 36 | import android.content.pm.ShortcutInfo; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 37 | import android.content.res.ColorStateList; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 38 | import android.content.res.Configuration; |
| 39 | import android.content.res.Resources; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 40 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 41 | import android.graphics.Canvas; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 42 | import android.graphics.Color; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 43 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 44 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 45 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 46 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 47 | import android.media.AudioManager; |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 48 | import android.media.PlayerBase; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 49 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 51 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 52 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 53 | import android.os.Bundle; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 54 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.os.Parcel; |
| 56 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 57 | import android.os.SystemClock; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 58 | import android.os.SystemProperties; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 59 | import android.os.UserHandle; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 60 | import android.text.BidiFormatter; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 61 | import android.text.SpannableStringBuilder; |
| 62 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 64 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 65 | import android.text.style.CharacterStyle; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 66 | import android.text.style.ForegroundColorSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 67 | import android.text.style.RelativeSizeSpan; |
| 68 | import android.text.style.TextAppearanceSpan; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 69 | import android.util.ArraySet; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 70 | import android.util.Log; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 71 | import android.util.SparseArray; |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 72 | import android.util.proto.ProtoOutputStream; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 73 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 74 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 75 | import android.view.View; |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 76 | import android.view.ViewGroup; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 77 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import android.widget.RemoteViews; |
| 79 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 80 | import com.android.internal.R; |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 81 | import com.android.internal.annotations.VisibleForTesting; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 82 | import com.android.internal.util.ArrayUtils; |
Griff Hazen | c091ba8 | 2014-05-16 10:13:26 -0700 | [diff] [blame] | 83 | import com.android.internal.util.NotificationColorUtil; |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 84 | import com.android.internal.util.Preconditions; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 85 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 86 | import java.lang.annotation.Retention; |
| 87 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 88 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 89 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 90 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 91 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 92 | import java.util.List; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 93 | import java.util.Objects; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 94 | import java.util.Set; |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 95 | import java.util.function.Consumer; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 96 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | /** |
| 98 | * A class that represents how a persistent notification is to be presented to |
| 99 | * the user using the {@link android.app.NotificationManager}. |
| 100 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 101 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 102 | * easier to construct Notifications.</p> |
| 103 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 104 | * <div class="special reference"> |
| 105 | * <h3>Developer Guides</h3> |
| 106 | * <p>For a guide to creating notifications, read the |
| 107 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 108 | * developer guide.</p> |
| 109 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | */ |
| 111 | public class Notification implements Parcelable |
| 112 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 113 | private static final String TAG = "Notification"; |
| 114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 116 | * 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] | 117 | * containing application. |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 118 | */ |
| 119 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 120 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 121 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 122 | |
| 123 | /** |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 124 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 125 | * 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] | 126 | * what settings should be shown in the target app. |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 127 | */ |
| 128 | public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 129 | |
| 130 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 131 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 005c8b9 | 2017-08-24 10:35:53 -0400 | [diff] [blame] | 132 | * contain a {@link NotificationChannelGroup#getId() group id} that can be used to narrow down |
| 133 | * what settings should be shown in the target app. |
| 134 | */ |
| 135 | public static final String EXTRA_CHANNEL_GROUP_ID = "android.intent.extra.CHANNEL_GROUP_ID"; |
| 136 | |
| 137 | /** |
| 138 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 139 | * contain the tag provided to {@link NotificationManager#notify(String, int, Notification)} |
| 140 | * that can be used to narrow down what settings should be shown in the target app. |
| 141 | */ |
| 142 | public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 143 | |
| 144 | /** |
| 145 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 146 | * contain the id provided to {@link NotificationManager#notify(String, int, Notification)} |
| 147 | * that can be used to narrow down what settings should be shown in the target app. |
| 148 | */ |
| 149 | public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 150 | |
| 151 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | * Use all default values (where applicable). |
| 153 | */ |
| 154 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | /** |
| 157 | * Use the default notification sound. This will ignore any given |
| 158 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 159 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 160 | * <p> |
| 161 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 162 | * </p> |
| 163 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 165 | */ |
| 166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | public static final int DEFAULT_SOUND = 1; |
| 168 | |
| 169 | /** |
| 170 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 171 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 172 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 173 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 174 | * <p> |
| 175 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 176 | * </p> |
| 177 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 179 | */ |
| 180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | /** |
| 184 | * Use the default notification lights. This will ignore the |
| 185 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 186 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 187 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 189 | */ |
| 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 194 | * Maximum length of CharSequences accepted by Builder and friends. |
| 195 | * |
| 196 | * <p> |
| 197 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 198 | */ |
| 199 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 200 | |
| 201 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 202 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 203 | */ |
| 204 | private static final int MAX_REPLY_HISTORY = 5; |
| 205 | |
Selim Cinek | de4de0e | 2018-01-24 16:21:07 -0800 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * If the notification contained an unsent draft for a RemoteInput when the user clicked on it, |
| 209 | * we're adding the draft as a String extra to the {@link #contentIntent} using this key. |
| 210 | * |
| 211 | * <p>Apps may use this extra to prepopulate text fields in the app, where the user usually |
| 212 | * sends messages.</p> |
| 213 | */ |
| 214 | public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; |
| 215 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 216 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 217 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 218 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 219 | * Default value: {@link System#currentTimeMillis() Now}. |
| 220 | * |
| 221 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 222 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 223 | * 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] | 224 | * timestamped according to when the activity began. |
| 225 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 226 | * Some examples: |
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 | * <ul> |
| 229 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 230 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 231 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 232 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 233 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 234 | * <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] | 235 | * </ul> |
| 236 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 237 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 238 | * anymore by default and must be opted into by using |
| 239 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | */ |
| 241 | public long when; |
| 242 | |
| 243 | /** |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 244 | * The creation time of the notification |
| 245 | */ |
| 246 | private long creationTime; |
| 247 | |
| 248 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | * 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] | 250 | * |
| 251 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 253 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 254 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | public int icon; |
| 256 | |
| 257 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 258 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 259 | * leave it at its default value of 0. |
| 260 | * |
| 261 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 262 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 263 | */ |
| 264 | public int iconLevel; |
| 265 | |
| 266 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 267 | * The number of events that this notification represents. For example, in a new mail |
| 268 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 269 | * |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 270 | * 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] | 271 | * Starting with {@link android.os.Build.VERSION_CODES#O}, the number may be displayed as a |
| 272 | * badge icon in Launchers that support badging. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | */ |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 274 | public int number = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | |
| 276 | /** |
| 277 | * The intent to execute when the expanded status entry is clicked. If |
| 278 | * this is an activity, it must include the |
| 279 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 280 | * that you take care of task management as described in the |
| 281 | * <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] | 282 | * Stack</a> document. In particular, make sure to read the notification section |
| 283 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 284 | * Notifications</a> for the correct ways to launch an application from a |
| 285 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | */ |
| 287 | public PendingIntent contentIntent; |
| 288 | |
| 289 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 290 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 291 | * the "Clear All" button or by swiping it away individually. |
| 292 | * |
| 293 | * This probably shouldn't be launching an activity since several of those will be sent |
| 294 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | */ |
| 296 | public PendingIntent deleteIntent; |
| 297 | |
| 298 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 299 | * 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] | 300 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 301 | * <p> |
| 302 | * The system UI may choose to display a heads-up notification, instead of |
| 303 | * launching this intent, while the user is using the device. |
| 304 | * </p> |
| 305 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 306 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 307 | */ |
| 308 | public PendingIntent fullScreenIntent; |
| 309 | |
| 310 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 311 | * Text that summarizes this notification for accessibility services. |
| 312 | * |
| 313 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 314 | * accessibility services (where it serves as an audible announcement of the notification's |
| 315 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 316 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 317 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | */ |
| 319 | public CharSequence tickerText; |
| 320 | |
| 321 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 322 | * Formerly, a view showing the {@link #tickerText}. |
| 323 | * |
| 324 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 325 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 326 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 327 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 328 | |
| 329 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 330 | * The view that will represent this notification in the notification list (which is pulled |
| 331 | * down from the status bar). |
| 332 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 333 | * As of N, this field may be null. The notification view is determined by the inputs |
| 334 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 335 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 337 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | public RemoteViews contentView; |
| 339 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 340 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 341 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 342 | * opportunity to show more detail. The system UI may choose to show this |
| 343 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 344 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 345 | * 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] | 346 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 347 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 348 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 349 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 350 | public RemoteViews bigContentView; |
| 351 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 352 | |
| 353 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 354 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 355 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 356 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 357 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 358 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 359 | * 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] | 360 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 361 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 362 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 363 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 364 | public RemoteViews headsUpContentView; |
| 365 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 366 | private boolean mUsesStandardHeader; |
| 367 | |
| 368 | private static final ArraySet<Integer> STANDARD_LAYOUTS = new ArraySet<>(); |
| 369 | static { |
| 370 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_base); |
| 371 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_base); |
| 372 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_picture); |
| 373 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text); |
| 374 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_inbox); |
| 375 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging); |
| 376 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_media); |
| 377 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media); |
| 378 | STANDARD_LAYOUTS.add(R.layout.notification_template_ambient_header); |
| 379 | STANDARD_LAYOUTS.add(R.layout.notification_template_header); |
| 380 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_ambient); |
| 381 | } |
| 382 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 383 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 384 | * A large bitmap to be shown in the notification content area. |
| 385 | * |
| 386 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 388 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 389 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | |
| 391 | /** |
| 392 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 393 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 395 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 396 | * </p> |
| 397 | * |
| 398 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 399 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 401 | * @deprecated use {@link NotificationChannel#getSound()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 403 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | public Uri sound; |
| 405 | |
| 406 | /** |
| 407 | * Use this constant as the value for audioStreamType to request that |
| 408 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 409 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 410 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 411 | * @deprecated Use {@link NotificationChannel#getAudioAttributes()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 413 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | public static final int STREAM_DEFAULT = -1; |
| 415 | |
| 416 | /** |
| 417 | * The audio stream type to use when playing the sound. |
| 418 | * Should be one of the STREAM_ constants from |
| 419 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 420 | * |
| 421 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 423 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | public int audioStreamType = STREAM_DEFAULT; |
| 425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 427 | * The default value of {@link #audioAttributes}. |
| 428 | */ |
| 429 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 430 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 431 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 432 | .build(); |
| 433 | |
| 434 | /** |
| 435 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 436 | * |
| 437 | * @deprecated use {@link NotificationChannel#getAudioAttributes()} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 438 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 439 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 440 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 441 | |
| 442 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 443 | * The pattern with which to vibrate. |
| 444 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | * <p> |
| 446 | * To vibrate the default pattern, see {@link #defaults}. |
| 447 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 448 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | * @see android.os.Vibrator#vibrate(long[],int) |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 450 | * @deprecated use {@link NotificationChannel#getVibrationPattern()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 452 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | public long[] vibrate; |
| 454 | |
| 455 | /** |
| 456 | * The color of the led. The hardware will do its best approximation. |
| 457 | * |
| 458 | * @see #FLAG_SHOW_LIGHTS |
| 459 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 460 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 462 | @ColorInt |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 463 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | public int ledARGB; |
| 465 | |
| 466 | /** |
| 467 | * The number of milliseconds for the LED to be on while it's flashing. |
| 468 | * The hardware will do its best approximation. |
| 469 | * |
| 470 | * @see #FLAG_SHOW_LIGHTS |
| 471 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 472 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 474 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | public int ledOnMS; |
| 476 | |
| 477 | /** |
| 478 | * The number of milliseconds for the LED to be off while it's flashing. |
| 479 | * The hardware will do its best approximation. |
| 480 | * |
| 481 | * @see #FLAG_SHOW_LIGHTS |
| 482 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 483 | * |
| 484 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 486 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | public int ledOffMS; |
| 488 | |
| 489 | /** |
| 490 | * Specifies which values should be taken from the defaults. |
| 491 | * <p> |
| 492 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 493 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 494 | * values, use {@link #DEFAULT_ALL}. |
| 495 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 496 | * |
| 497 | * @deprecated use {@link NotificationChannel#getSound()} and |
| 498 | * {@link NotificationChannel#shouldShowLights()} and |
| 499 | * {@link NotificationChannel#shouldVibrate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 501 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | public int defaults; |
| 503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | /** |
| 505 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 506 | * set if you want the LED on for this notification. |
| 507 | * <ul> |
| 508 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 509 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 510 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 511 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 512 | * be on and off to ledOnMS and ledOffMS.</li> |
| 513 | * </ul> |
| 514 | * <p> |
| 515 | * 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] | 516 | * 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] | 517 | * because they will be set to values that work on any given hardware. |
| 518 | * <p> |
| 519 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 520 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 521 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 523 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 525 | |
| 526 | /** |
| 527 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 528 | * set if this notification is in reference to something that is ongoing, |
| 529 | * like a phone call. It should not be set if this notification is in |
| 530 | * reference to something that happened at a particular point in time, |
| 531 | * like a missed phone call. |
| 532 | */ |
| 533 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 534 | |
| 535 | /** |
| 536 | * 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] | 537 | * the audio will be repeated until the notification is |
| 538 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | */ |
| 540 | public static final int FLAG_INSISTENT = 0x00000004; |
| 541 | |
| 542 | /** |
| 543 | * 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] | 544 | * set if you would only like the sound, vibrate and ticker to be played |
| 545 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | */ |
| 547 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 548 | |
| 549 | /** |
| 550 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 551 | * 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] | 552 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | */ |
| 554 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 555 | |
| 556 | /** |
| 557 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 558 | * set if the notification should not be canceled when the user clicks |
| 559 | * the Clear all button. |
| 560 | */ |
| 561 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 562 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 563 | /** |
| 564 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 565 | * set if this notification represents a currently running service. This |
| 566 | * will normally be set for you by {@link Service#startForeground}. |
| 567 | */ |
| 568 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 569 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 570 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 571 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 572 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 573 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 574 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 575 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 576 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 577 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 578 | /** |
| 579 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 580 | * set if this notification is relevant to the current device only |
| 581 | * and it is not recommended that it bridge to other devices. |
| 582 | */ |
| 583 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 584 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 585 | /** |
| 586 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 587 | * set if this notification is the group summary for a group of notifications. |
| 588 | * Grouped notifications may display in a cluster or stack on devices which |
| 589 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 590 | */ |
| 591 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 592 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 593 | /** |
| 594 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 595 | * set if this notification is the group summary for an auto-group of notifications. |
| 596 | * |
| 597 | * @hide |
| 598 | */ |
| 599 | @SystemApi |
| 600 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 601 | |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 602 | /** |
| 603 | * @hide |
| 604 | */ |
| 605 | public static final int FLAG_CAN_COLORIZE = 0x00000800; |
| 606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | public int flags; |
| 608 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 609 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 610 | @IntDef(prefix = { "PRIORITY_" }, value = { |
| 611 | PRIORITY_DEFAULT, |
| 612 | PRIORITY_LOW, |
| 613 | PRIORITY_MIN, |
| 614 | PRIORITY_HIGH, |
| 615 | PRIORITY_MAX |
| 616 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 617 | @Retention(RetentionPolicy.SOURCE) |
| 618 | public @interface Priority {} |
| 619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 621 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 622 | * notifications, use this value for all notifications. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 623 | * |
| 624 | * @deprecated use {@link NotificationManager#IMPORTANCE_DEFAULT} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 625 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 626 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 627 | public static final int PRIORITY_DEFAULT = 0; |
| 628 | |
| 629 | /** |
| 630 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 631 | * items smaller, or at a different position in the list, compared with your app's |
| 632 | * {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 633 | * |
| 634 | * @deprecated use {@link NotificationManager#IMPORTANCE_LOW} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 635 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 636 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 637 | public static final int PRIORITY_LOW = -1; |
| 638 | |
| 639 | /** |
| 640 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 641 | * circumstances, such as detailed notification logs. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 642 | * |
| 643 | * @deprecated use {@link NotificationManager#IMPORTANCE_MIN} 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_MIN = -2; |
| 647 | |
| 648 | /** |
| 649 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 650 | * show these items larger, or at a different position in notification lists, compared with |
| 651 | * your app's {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 652 | * |
| 653 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 654 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 655 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 656 | public static final int PRIORITY_HIGH = 1; |
| 657 | |
| 658 | /** |
| 659 | * Highest {@link #priority}, for your application's most important items that require the |
| 660 | * user's prompt attention or input. |
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_MAX = 2; |
| 666 | |
| 667 | /** |
| 668 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 669 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 670 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 671 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 672 | * 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] | 673 | * system will make a determination about how to interpret this priority when presenting |
| 674 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 675 | * |
| 676 | * <p> |
| 677 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 678 | * as a heads-up notification. |
| 679 | * </p> |
| 680 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 681 | * @deprecated use {@link NotificationChannel#getImportance()} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 682 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 683 | @Priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 684 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 685 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 686 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 687 | /** |
| 688 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 689 | * to be applied by the standard Style templates when presenting this notification. |
| 690 | * |
| 691 | * The current template design constructs a colorful header image by overlaying the |
| 692 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 693 | * ignored. |
| 694 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 695 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 696 | public int color = COLOR_DEFAULT; |
| 697 | |
| 698 | /** |
| 699 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 700 | * any special color but instead use default colors when presenting this notification. |
| 701 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 702 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 703 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 704 | |
| 705 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 706 | * 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] | 707 | * @hide |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 708 | */ |
| 709 | @ColorInt |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 710 | public static final int COLOR_INVALID = 1; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 711 | |
| 712 | /** |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 713 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 714 | * 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] | 715 | * lockscreen). |
| 716 | * |
| 717 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 718 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 719 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 720 | * the appropriate user. |
| 721 | * |
| 722 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 723 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 724 | * To modify the public version of this notification—for example, to redact some portions—see |
| 725 | * {@link Builder#setPublicVersion(Notification)}. |
| 726 | * |
| 727 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 728 | * and ticker until the user has bypassed the lockscreen. |
| 729 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 730 | public @Visibility int visibility; |
| 731 | |
| 732 | /** @hide */ |
| 733 | @IntDef(prefix = { "VISIBILITY_" }, value = { |
| 734 | VISIBILITY_PUBLIC, |
| 735 | VISIBILITY_PRIVATE, |
| 736 | VISIBILITY_SECRET, |
| 737 | }) |
| 738 | @Retention(RetentionPolicy.SOURCE) |
| 739 | public @interface Visibility {} |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 740 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 741 | /** |
| 742 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 743 | * |
| 744 | * {@see #visibility} |
| 745 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 746 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 747 | |
| 748 | /** |
| 749 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 750 | * private information on secure lockscreens. |
| 751 | * |
| 752 | * {@see #visibility} |
| 753 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 754 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 755 | |
| 756 | /** |
| 757 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 758 | * |
| 759 | * {@see #visibility} |
| 760 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 761 | public static final int VISIBILITY_SECRET = -1; |
| 762 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 763 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 764 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 765 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 766 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 767 | |
| 768 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 769 | * Notification category: map turn-by-turn navigation. |
| 770 | */ |
| 771 | public static final String CATEGORY_NAVIGATION = "navigation"; |
| 772 | |
| 773 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 774 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 775 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 776 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 777 | |
| 778 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 779 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 780 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 781 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 782 | |
| 783 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 784 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 785 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 786 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 787 | |
| 788 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 789 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 790 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 791 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 792 | |
| 793 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 794 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 795 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 796 | public static final String CATEGORY_ALARM = "alarm"; |
| 797 | |
| 798 | /** |
| 799 | * Notification category: progress of a long-running background operation. |
| 800 | */ |
| 801 | public static final String CATEGORY_PROGRESS = "progress"; |
| 802 | |
| 803 | /** |
| 804 | * Notification category: social network or sharing update. |
| 805 | */ |
| 806 | public static final String CATEGORY_SOCIAL = "social"; |
| 807 | |
| 808 | /** |
| 809 | * Notification category: error in background operation or authentication status. |
| 810 | */ |
| 811 | public static final String CATEGORY_ERROR = "err"; |
| 812 | |
| 813 | /** |
| 814 | * Notification category: media transport control for playback. |
| 815 | */ |
| 816 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 817 | |
| 818 | /** |
| 819 | * Notification category: system or device status update. Reserved for system use. |
| 820 | */ |
| 821 | public static final String CATEGORY_SYSTEM = "sys"; |
| 822 | |
| 823 | /** |
| 824 | * Notification category: indication of running background service. |
| 825 | */ |
| 826 | public static final String CATEGORY_SERVICE = "service"; |
| 827 | |
| 828 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 829 | * Notification category: a specific, timely recommendation for a single thing. |
| 830 | * For example, a news app might want to recommend a news story it believes the user will |
| 831 | * want to read next. |
| 832 | */ |
| 833 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 834 | |
| 835 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 836 | * Notification category: ongoing information about device or contextual status. |
| 837 | */ |
| 838 | public static final String CATEGORY_STATUS = "status"; |
| 839 | |
| 840 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 841 | * Notification category: user-scheduled reminder. |
| 842 | */ |
| 843 | public static final String CATEGORY_REMINDER = "reminder"; |
| 844 | |
| 845 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 846 | * Notification category: extreme car emergencies. |
| 847 | * @hide |
| 848 | */ |
| 849 | @SystemApi |
| 850 | public static final String CATEGORY_CAR_EMERGENCY = "car_emergency"; |
| 851 | |
| 852 | /** |
| 853 | * Notification category: car warnings. |
| 854 | * @hide |
| 855 | */ |
| 856 | @SystemApi |
| 857 | public static final String CATEGORY_CAR_WARNING = "car_warning"; |
| 858 | |
| 859 | /** |
| 860 | * Notification category: general car system information. |
| 861 | * @hide |
| 862 | */ |
| 863 | @SystemApi |
| 864 | public static final String CATEGORY_CAR_INFORMATION = "car_information"; |
| 865 | |
| 866 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 867 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 868 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 869 | */ |
| 870 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 871 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 872 | @UnsupportedAppUsage |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 873 | private String mGroupKey; |
| 874 | |
| 875 | /** |
| 876 | * Get the key used to group this notification into a cluster or stack |
| 877 | * with other notifications on devices which support such rendering. |
| 878 | */ |
| 879 | public String getGroup() { |
| 880 | return mGroupKey; |
| 881 | } |
| 882 | |
| 883 | private String mSortKey; |
| 884 | |
| 885 | /** |
| 886 | * Get a sort key that orders this notification among other notifications from the |
| 887 | * same package. This can be useful if an external sort was already applied and an app |
| 888 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 889 | * value, although providing different priorities in addition to providing sort key may |
| 890 | * cause this value to be ignored. |
| 891 | * |
| 892 | * <p>This sort key can also be used to order members of a notification group. See |
| 893 | * {@link Builder#setGroup}. |
| 894 | * |
| 895 | * @see String#compareTo(String) |
| 896 | */ |
| 897 | public String getSortKey() { |
| 898 | return mSortKey; |
| 899 | } |
| 900 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 901 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 902 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 903 | * <p> |
| 904 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 905 | * APIs, and are intended to be used by |
| 906 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 907 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 908 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 909 | public Bundle extras = new Bundle(); |
| 910 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 911 | /** |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 912 | * All pending intents in the notification as the system needs to be able to access them but |
| 913 | * 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] | 914 | * custom parcelable objects. |
| 915 | * |
| 916 | * @hide |
| 917 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 918 | @UnsupportedAppUsage |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 919 | public ArraySet<PendingIntent> allPendingIntents; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 920 | |
| 921 | /** |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 922 | * Token identifying the notification that is applying doze/bgcheck whitelisting to the |
| 923 | * pending intents inside of it, so only those will get the behavior. |
| 924 | * |
| 925 | * @hide |
| 926 | */ |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 927 | private IBinder mWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 928 | |
| 929 | /** |
| 930 | * Must be set by a process to start associating tokens with Notification objects |
| 931 | * coming in to it. This is set by NotificationManagerService. |
| 932 | * |
| 933 | * @hide |
| 934 | */ |
| 935 | static public IBinder processWhitelistToken; |
| 936 | |
| 937 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 938 | * {@link #extras} key: this is the title of the notification, |
| 939 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 940 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 941 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 942 | |
| 943 | /** |
| 944 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 945 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 946 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 947 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 948 | |
| 949 | /** |
| 950 | * {@link #extras} key: this is the main text payload, as supplied to |
| 951 | * {@link Builder#setContentText(CharSequence)}. |
| 952 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 953 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 954 | |
| 955 | /** |
| 956 | * {@link #extras} key: this is a third line of text, as supplied to |
| 957 | * {@link Builder#setSubText(CharSequence)}. |
| 958 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 959 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 960 | |
| 961 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 962 | * {@link #extras} key: this is the remote input history, as supplied to |
| 963 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
Adrian Roos | 005e774 | 2016-04-13 15:02:20 -0700 | [diff] [blame] | 964 | * |
| 965 | * Apps can fill this through {@link Builder#setRemoteInputHistory(CharSequence[])} |
| 966 | * with the most recent inputs that have been sent through a {@link RemoteInput} of this |
| 967 | * Notification and are expected to clear it once the it is no longer relevant (e.g. for chat |
| 968 | * notifications once the other party has responded). |
| 969 | * |
| 970 | * The extra with this key is of type CharSequence[] and contains the most recent entry at |
| 971 | * the 0 index, the second most recent at the 1 index, etc. |
| 972 | * |
| 973 | * @see Builder#setRemoteInputHistory(CharSequence[]) |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 974 | */ |
| 975 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 976 | |
| 977 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 978 | * {@link #extras} key: boolean as supplied to |
| 979 | * {@link Builder#setShowRemoteInputSpinner(boolean)}. |
| 980 | * |
| 981 | * If set to true, then the view displaying the remote input history from |
| 982 | * {@link Builder#setRemoteInputHistory(CharSequence[])} will have a progress spinner. |
| 983 | * |
| 984 | * @see Builder#setShowRemoteInputSpinner(boolean) |
| 985 | * @hide |
| 986 | */ |
| 987 | public static final String EXTRA_SHOW_REMOTE_INPUT_SPINNER = "android.remoteInputSpinner"; |
| 988 | |
| 989 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 990 | * {@link #extras} key: boolean as supplied to |
| 991 | * {@link Builder#setHideSmartReplies(boolean)}. |
| 992 | * |
| 993 | * If set to true, then any smart reply buttons will be hidden. |
| 994 | * |
| 995 | * @see Builder#setHideSmartReplies(boolean) |
| 996 | * @hide |
| 997 | */ |
| 998 | public static final String EXTRA_HIDE_SMART_REPLIES = "android.hideSmartReplies"; |
| 999 | |
| 1000 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1001 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 1002 | * {@link Builder#setContentInfo(CharSequence)}. |
| 1003 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1004 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1005 | |
| 1006 | /** |
| 1007 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 1008 | * alongside expanded notifications, as supplied to (e.g.) |
| 1009 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 1010 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1011 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1012 | |
| 1013 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1014 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 1015 | * {@link BigTextStyle} notification, as supplied to |
| 1016 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 1017 | */ |
| 1018 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 1019 | |
| 1020 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1021 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 1022 | * supplied to {@link Builder#setSmallIcon(int)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1023 | * |
| 1024 | * @deprecated Use {@link #getSmallIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1025 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1026 | @Deprecated |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1027 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1028 | |
| 1029 | /** |
| 1030 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 1031 | * notification payload, as |
| 1032 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1033 | * |
| 1034 | * @deprecated Use {@link #getLargeIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1035 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1036 | @Deprecated |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1037 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1038 | |
| 1039 | /** |
| 1040 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 1041 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 1042 | * shown in its expanded form, as supplied to |
| 1043 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 1044 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1045 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1046 | |
| 1047 | /** |
| 1048 | * {@link #extras} key: this is the progress value supplied to |
| 1049 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1050 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1051 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1052 | |
| 1053 | /** |
| 1054 | * {@link #extras} key: this is the maximum value supplied to |
| 1055 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1056 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1057 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1058 | |
| 1059 | /** |
| 1060 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 1061 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1062 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1063 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1064 | |
| 1065 | /** |
| 1066 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 1067 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 1068 | * {@link Builder#setUsesChronometer(boolean)}. |
| 1069 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1070 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1071 | |
| 1072 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1073 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 1074 | * 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] | 1075 | * This extra is a boolean. The default is false. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1076 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1077 | public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1078 | |
| 1079 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1080 | * {@link #extras} key: whether {@link #when} should be shown, |
| 1081 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 1082 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1083 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1084 | |
| 1085 | /** |
| 1086 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 1087 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 1088 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1089 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1090 | |
| 1091 | /** |
| 1092 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 1093 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 1094 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1095 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1096 | |
| 1097 | /** |
| 1098 | * {@link #extras} key: A string representing the name of the specific |
| 1099 | * {@link android.app.Notification.Style} used to create this notification. |
| 1100 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 1101 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1102 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1103 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 1104 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 1105 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1106 | * |
| 1107 | * @deprecated the actual objects are now in {@link #EXTRA_PEOPLE_LIST} |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1108 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1109 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1110 | |
| 1111 | /** |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1112 | * {@link #extras} key: An arrayList of {@link Person} objects containing the people that |
| 1113 | * this notification relates to. |
| 1114 | */ |
| 1115 | public static final String EXTRA_PEOPLE_LIST = "android.people.list"; |
| 1116 | |
| 1117 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1118 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 1119 | * Only available to notifications coming from the android package. |
| 1120 | * @hide |
| 1121 | */ |
Maurice Lam | 96c1003 | 2017-03-29 15:42:38 -0700 | [diff] [blame] | 1122 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1123 | @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1124 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 1125 | |
| 1126 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1127 | * {@link #extras} key: A |
| 1128 | * {@link android.content.ContentUris content URI} pointing to an image that can be displayed |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1129 | * in the background when the notification is selected. Used on television platforms. |
| 1130 | * The URI must point to an image stream suitable for passing into |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1131 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1132 | * BitmapFactory.decodeStream}; all other content types will be ignored. |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1133 | */ |
| 1134 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1135 | |
| 1136 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1137 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 1138 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1139 | * {@link android.app.Notification.MediaStyle} notification. |
| 1140 | */ |
| 1141 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1142 | |
| 1143 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 1144 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 1145 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 1146 | */ |
| 1147 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1148 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 1149 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1150 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 1151 | * direct replies |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1152 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1153 | * {@link CharSequence} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1154 | * |
| 1155 | * @deprecated use {@link #EXTRA_MESSAGING_PERSON} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1156 | */ |
| 1157 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1158 | |
| 1159 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1160 | * {@link #extras} key: the person to be displayed for all messages sent by the user including |
| 1161 | * direct replies |
| 1162 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1163 | * {@link Person} |
| 1164 | */ |
| 1165 | public static final String EXTRA_MESSAGING_PERSON = "android.messagingUser"; |
| 1166 | |
| 1167 | /** |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1168 | * {@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] | 1169 | * represented by a {@link android.app.Notification.MessagingStyle} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1170 | */ |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1171 | public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1172 | |
| 1173 | /** |
| 1174 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 1175 | * bundles provided by a |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1176 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1177 | * array of bundles. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1178 | */ |
| 1179 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 1180 | |
| 1181 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 1182 | * {@link #extras} key: an array of |
| 1183 | * {@link android.app.Notification.MessagingStyle#addHistoricMessage historic} |
| 1184 | * {@link android.app.Notification.MessagingStyle.Message} bundles provided by a |
| 1185 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1186 | * array of bundles. |
| 1187 | */ |
| 1188 | public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1189 | |
| 1190 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 1191 | * {@link #extras} key: whether the {@link android.app.Notification.MessagingStyle} notification |
| 1192 | * represents a group conversation. |
| 1193 | */ |
| 1194 | public static final String EXTRA_IS_GROUP_CONVERSATION = "android.isGroupConversation"; |
| 1195 | |
| 1196 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1197 | * {@link #extras} key: whether the notification should be colorized as |
| 1198 | * supplied to {@link Builder#setColorized(boolean)}}. |
| 1199 | */ |
| 1200 | public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1201 | |
| 1202 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1203 | * @hide |
| 1204 | */ |
| 1205 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1206 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 1207 | /** |
| 1208 | * @hide |
| 1209 | */ |
| 1210 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1211 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1212 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 1213 | * @hide |
| 1214 | */ |
| 1215 | public static final String EXTRA_REDUCED_IMAGES = "android.reduced.images"; |
| 1216 | |
| 1217 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1218 | * {@link #extras} key: the audio contents of this notification. |
| 1219 | * |
| 1220 | * This is for use when rendering the notification on an audio-focused interface; |
| 1221 | * the audio contents are a complete sound sample that contains the contents/body of the |
| 1222 | * notification. This may be used in substitute of a Text-to-Speech reading of the |
| 1223 | * notification. For example if the notification represents a voice message this should point |
| 1224 | * to the audio of that message. |
| 1225 | * |
| 1226 | * The data stored under this key should be a String representation of a Uri that contains the |
| 1227 | * audio contents in one of the following formats: WAV, PCM 16-bit, AMR-WB. |
| 1228 | * |
| 1229 | * This extra is unnecessary if you are using {@code MessagingStyle} since each {@code Message} |
| 1230 | * has a field for holding data URI. That field can be used for audio. |
| 1231 | * See {@code Message#setData}. |
| 1232 | * |
| 1233 | * Example usage: |
| 1234 | * <pre> |
| 1235 | * {@code |
| 1236 | * Notification.Builder myBuilder = (build your Notification as normal); |
| 1237 | * myBuilder.getExtras().putString(EXTRA_AUDIO_CONTENTS_URI, myAudioUri.toString()); |
| 1238 | * } |
| 1239 | * </pre> |
| 1240 | */ |
| 1241 | public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1242 | |
Dan Sandler | 80eaa59 | 2016-04-14 23:34:54 -0400 | [diff] [blame] | 1243 | /** @hide */ |
| 1244 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1245 | @RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME) |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1246 | public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1247 | |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1248 | /** |
Julia Reynolds | 3c7de11 | 2018-03-28 09:33:13 -0400 | [diff] [blame] | 1249 | * This is set on the notifications shown by system_server about apps running foreground |
| 1250 | * services. It indicates that the notification should be shown |
| 1251 | * only if any of the given apps do not already have a properly tagged |
| 1252 | * {@link #FLAG_FOREGROUND_SERVICE} notification currently visible to the user. |
| 1253 | * This is a string array of all package names of the apps. |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1254 | * @hide |
| 1255 | */ |
| 1256 | public static final String EXTRA_FOREGROUND_APPS = "android.foregroundApps"; |
| 1257 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1258 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1259 | private Icon mSmallIcon; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1260 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1261 | private Icon mLargeIcon; |
| 1262 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1263 | @UnsupportedAppUsage |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1264 | private String mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1265 | private long mTimeout; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1266 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1267 | private String mShortcutId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1268 | private CharSequence mSettingsText; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1269 | |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1270 | /** @hide */ |
| 1271 | @IntDef(prefix = { "GROUP_ALERT_" }, value = { |
| 1272 | GROUP_ALERT_ALL, GROUP_ALERT_CHILDREN, GROUP_ALERT_SUMMARY |
| 1273 | }) |
| 1274 | @Retention(RetentionPolicy.SOURCE) |
| 1275 | public @interface GroupAlertBehavior {} |
| 1276 | |
| 1277 | /** |
| 1278 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all notifications in a |
| 1279 | * group with sound or vibration ought to make sound or vibrate (respectively), so this |
| 1280 | * notification will not be muted when it is in a group. |
| 1281 | */ |
| 1282 | public static final int GROUP_ALERT_ALL = 0; |
| 1283 | |
| 1284 | /** |
| 1285 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all children |
| 1286 | * notification in a group should be silenced (no sound or vibration) even if they are posted |
| 1287 | * 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] | 1288 | * mute this notification if this notification is a group child. This must be applied to all |
| 1289 | * children notifications you want to mute. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1290 | * |
| 1291 | * <p> For example, you might want to use this constant if you post a number of children |
| 1292 | * notifications at once (say, after a periodic sync), and only need to notify the user |
| 1293 | * audibly once. |
| 1294 | */ |
| 1295 | public static final int GROUP_ALERT_SUMMARY = 1; |
| 1296 | |
| 1297 | /** |
| 1298 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that the summary |
| 1299 | * notification in a group should be silenced (no sound or vibration) even if they are |
| 1300 | * posted to a {@link NotificationChannel} that has sound and/or vibration. Use this constant |
| 1301 | * to mute this notification if this notification is a group summary. |
| 1302 | * |
| 1303 | * <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] | 1304 | * in your group have content and the summary is only used to visually group notifications |
| 1305 | * rather than to alert the user that new information is available. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1306 | */ |
| 1307 | public static final int GROUP_ALERT_CHILDREN = 2; |
| 1308 | |
Julia Reynolds | 2f431e2 | 2017-06-07 14:12:09 +0000 | [diff] [blame] | 1309 | private int mGroupAlertBehavior = GROUP_ALERT_ALL; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1310 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1311 | /** |
| 1312 | * If this notification is being shown as a badge, always show as a number. |
| 1313 | */ |
| 1314 | public static final int BADGE_ICON_NONE = 0; |
| 1315 | |
| 1316 | /** |
| 1317 | * If this notification is being shown as a badge, use the {@link #getSmallIcon()} to |
| 1318 | * represent this notification. |
| 1319 | */ |
| 1320 | public static final int BADGE_ICON_SMALL = 1; |
| 1321 | |
| 1322 | /** |
| 1323 | * If this notification is being shown as a badge, use the {@link #getLargeIcon()} to |
| 1324 | * represent this notification. |
| 1325 | */ |
| 1326 | public static final int BADGE_ICON_LARGE = 2; |
Julia Reynolds | 7d5b4da | 2017-03-20 10:18:49 -0400 | [diff] [blame] | 1327 | private int mBadgeIcon = BADGE_ICON_NONE; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1328 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1329 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1330 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 1331 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 1332 | * selected by the user. |
| 1333 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1334 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 1335 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 1336 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1337 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1338 | public static class Action implements Parcelable { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1339 | /** |
| 1340 | * {@link #extras} key: Keys to a {@link Parcelable} {@link ArrayList} of |
| 1341 | * {@link RemoteInput}s. |
| 1342 | * |
| 1343 | * This is intended for {@link RemoteInput}s that only accept data, meaning |
| 1344 | * {@link RemoteInput#getAllowFreeFormInput} is false, {@link RemoteInput#getChoices} |
| 1345 | * is null or empty, and {@link RemoteInput#getAllowedDataTypes is non-null and not |
| 1346 | * empty. These {@link RemoteInput}s will be ignored by devices that do not |
| 1347 | * support non-text-based {@link RemoteInput}s. See {@link Builder#build}. |
| 1348 | * |
| 1349 | * You can test if a RemoteInput matches these constraints using |
| 1350 | * {@link RemoteInput#isDataOnly}. |
| 1351 | */ |
| 1352 | private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1353 | |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1354 | /** |
| 1355 | * {@link }: No semantic action defined. |
| 1356 | */ |
| 1357 | public static final int SEMANTIC_ACTION_NONE = 0; |
| 1358 | |
| 1359 | /** |
| 1360 | * {@code SemanticAction}: Reply to a conversation, chat, group, or wherever replies |
| 1361 | * may be appropriate. |
| 1362 | */ |
| 1363 | public static final int SEMANTIC_ACTION_REPLY = 1; |
| 1364 | |
| 1365 | /** |
| 1366 | * {@code SemanticAction}: Mark content as read. |
| 1367 | */ |
| 1368 | public static final int SEMANTIC_ACTION_MARK_AS_READ = 2; |
| 1369 | |
| 1370 | /** |
| 1371 | * {@code SemanticAction}: Mark content as unread. |
| 1372 | */ |
| 1373 | public static final int SEMANTIC_ACTION_MARK_AS_UNREAD = 3; |
| 1374 | |
| 1375 | /** |
| 1376 | * {@code SemanticAction}: Delete the content associated with the notification. This |
| 1377 | * could mean deleting an email, message, etc. |
| 1378 | */ |
| 1379 | public static final int SEMANTIC_ACTION_DELETE = 4; |
| 1380 | |
| 1381 | /** |
| 1382 | * {@code SemanticAction}: Archive the content associated with the notification. This |
| 1383 | * could mean archiving an email, message, etc. |
| 1384 | */ |
| 1385 | public static final int SEMANTIC_ACTION_ARCHIVE = 5; |
| 1386 | |
| 1387 | /** |
| 1388 | * {@code SemanticAction}: Mute the content associated with the notification. This could |
| 1389 | * mean silencing a conversation or currently playing media. |
| 1390 | */ |
| 1391 | public static final int SEMANTIC_ACTION_MUTE = 6; |
| 1392 | |
| 1393 | /** |
| 1394 | * {@code SemanticAction}: Unmute the content associated with the notification. This could |
| 1395 | * mean un-silencing a conversation or currently playing media. |
| 1396 | */ |
| 1397 | public static final int SEMANTIC_ACTION_UNMUTE = 7; |
| 1398 | |
| 1399 | /** |
| 1400 | * {@code SemanticAction}: Mark content with a thumbs up. |
| 1401 | */ |
| 1402 | public static final int SEMANTIC_ACTION_THUMBS_UP = 8; |
| 1403 | |
| 1404 | /** |
| 1405 | * {@code SemanticAction}: Mark content with a thumbs down. |
| 1406 | */ |
| 1407 | public static final int SEMANTIC_ACTION_THUMBS_DOWN = 9; |
| 1408 | |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 1409 | /** |
| 1410 | * {@code SemanticAction}: Call a contact, group, etc. |
| 1411 | */ |
| 1412 | public static final int SEMANTIC_ACTION_CALL = 10; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1413 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1414 | private final Bundle mExtras; |
Mathew Inwood | 45d2c25 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1415 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1416 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1417 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1418 | private boolean mAllowGeneratedReplies = true; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1419 | private final @SemanticAction int mSemanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1420 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1421 | /** |
| 1422 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1423 | * |
| 1424 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1425 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1426 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1427 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1428 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1429 | /** |
| 1430 | * Title of the action. |
| 1431 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1432 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1433 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1434 | /** |
| 1435 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1436 | * may be rendered in a disabled presentation by the system UI. |
| 1437 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1438 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1439 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1440 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1441 | if (in.readInt() != 0) { |
| 1442 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1443 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1444 | icon = mIcon.getResId(); |
| 1445 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1446 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1447 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1448 | if (in.readInt() == 1) { |
| 1449 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1450 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1451 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1452 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1453 | mAllowGeneratedReplies = in.readInt() == 1; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1454 | mSemanticAction = in.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1455 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1456 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1457 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1458 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1459 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1460 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1461 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1462 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true, |
| 1463 | SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1466 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1467 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1468 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1469 | @SemanticAction int semanticAction) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1470 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1471 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1472 | this.icon = icon.getResId(); |
| 1473 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1474 | this.title = title; |
| 1475 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1476 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1477 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1478 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1479 | this.mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1483 | * Return an icon representing the action. |
| 1484 | */ |
| 1485 | public Icon getIcon() { |
| 1486 | if (mIcon == null && icon != 0) { |
| 1487 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1488 | mIcon = Icon.createWithResource("", icon); |
| 1489 | } |
| 1490 | return mIcon; |
| 1491 | } |
| 1492 | |
| 1493 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1494 | * Get additional metadata carried around with this Action. |
| 1495 | */ |
| 1496 | public Bundle getExtras() { |
| 1497 | return mExtras; |
| 1498 | } |
| 1499 | |
| 1500 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1501 | * Return whether the platform should automatically generate possible replies for this |
| 1502 | * {@link Action} |
| 1503 | */ |
| 1504 | public boolean getAllowGeneratedReplies() { |
| 1505 | return mAllowGeneratedReplies; |
| 1506 | } |
| 1507 | |
| 1508 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1509 | * 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] | 1510 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1511 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1512 | */ |
| 1513 | public RemoteInput[] getRemoteInputs() { |
| 1514 | return mRemoteInputs; |
| 1515 | } |
| 1516 | |
| 1517 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1518 | * Returns the {@code SemanticAction} associated with this {@link Action}. A |
| 1519 | * {@code SemanticAction} denotes what an {@link Action}'s {@link PendingIntent} will do |
| 1520 | * (eg. reply, mark as read, delete, etc). |
| 1521 | */ |
| 1522 | public @SemanticAction int getSemanticAction() { |
| 1523 | return mSemanticAction; |
| 1524 | } |
| 1525 | |
| 1526 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1527 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1528 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1529 | * {@link RemoteInput#isDataOnly}. |
| 1530 | * |
Shane Brennan | f670d6c | 2017-04-25 13:05:45 -0700 | [diff] [blame] | 1531 | * Returns null if there are no data-only remote inputs. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1532 | * |
| 1533 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1534 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1535 | */ |
| 1536 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1537 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1538 | } |
| 1539 | |
| 1540 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1541 | * Builder class for {@link Action} objects. |
| 1542 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1543 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1544 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1545 | private final CharSequence mTitle; |
| 1546 | private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1547 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1548 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1549 | private ArrayList<RemoteInput> mRemoteInputs; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1550 | private @SemanticAction int mSemanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1551 | |
| 1552 | /** |
| 1553 | * Construct a new builder for {@link Action} object. |
| 1554 | * @param icon icon to show for this action |
| 1555 | * @param title the title of the action |
| 1556 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1557 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1558 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1559 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1560 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | /** |
| 1564 | * Construct a new builder for {@link Action} object. |
| 1565 | * @param icon icon to show for this action |
| 1566 | * @param title the title of the action |
| 1567 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1568 | */ |
| 1569 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1570 | this(icon, title, intent, new Bundle(), null, true, SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | /** |
| 1574 | * Construct a new builder for {@link Action} object using the fields from an |
| 1575 | * {@link Action}. |
| 1576 | * @param action the action to read fields from. |
| 1577 | */ |
| 1578 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1579 | this(action.getIcon(), action.title, action.actionIntent, |
| 1580 | new Bundle(action.mExtras), action.getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1581 | action.getAllowGeneratedReplies(), action.getSemanticAction()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1584 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1585 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1586 | @SemanticAction int semanticAction) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1587 | mIcon = icon; |
| 1588 | mTitle = title; |
| 1589 | mIntent = intent; |
| 1590 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1591 | if (remoteInputs != null) { |
| 1592 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1593 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1594 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1595 | mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1596 | mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | /** |
| 1600 | * Merge additional metadata into this builder. |
| 1601 | * |
| 1602 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1603 | * |
| 1604 | * @see Notification.Action#extras |
| 1605 | */ |
| 1606 | public Builder addExtras(Bundle extras) { |
| 1607 | if (extras != null) { |
| 1608 | mExtras.putAll(extras); |
| 1609 | } |
| 1610 | return this; |
| 1611 | } |
| 1612 | |
| 1613 | /** |
| 1614 | * Get the metadata Bundle used by this Builder. |
| 1615 | * |
| 1616 | * <p>The returned Bundle is shared with this Builder. |
| 1617 | */ |
| 1618 | public Bundle getExtras() { |
| 1619 | return mExtras; |
| 1620 | } |
| 1621 | |
| 1622 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1623 | * Add an input to be collected from the user when this action is sent. |
| 1624 | * Response values can be retrieved from the fired intent by using the |
| 1625 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1626 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1627 | * @return this object for method chaining |
| 1628 | */ |
| 1629 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1630 | if (mRemoteInputs == null) { |
| 1631 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1632 | } |
| 1633 | mRemoteInputs.add(remoteInput); |
| 1634 | return this; |
| 1635 | } |
| 1636 | |
| 1637 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1638 | * Set whether the platform should automatically generate possible replies to add to |
| 1639 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1640 | * {@link RemoteInput}, this has no effect. |
| 1641 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1642 | * otherwise |
| 1643 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1644 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1645 | */ |
| 1646 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1647 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1648 | return this; |
| 1649 | } |
| 1650 | |
| 1651 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1652 | * Sets the {@code SemanticAction} for this {@link Action}. A |
| 1653 | * {@code SemanticAction} denotes what an {@link Action}'s |
| 1654 | * {@link PendingIntent} will do (eg. reply, mark as read, delete, etc). |
| 1655 | * @param semanticAction a SemanticAction defined within {@link Action} with |
| 1656 | * {@code SEMANTIC_ACTION_} prefixes |
| 1657 | * @return this object for method chaining |
| 1658 | */ |
| 1659 | public Builder setSemanticAction(@SemanticAction int semanticAction) { |
| 1660 | mSemanticAction = semanticAction; |
| 1661 | return this; |
| 1662 | } |
| 1663 | |
| 1664 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1665 | * Apply an extender to this action builder. Extenders may be used to add |
| 1666 | * metadata or change options on this builder. |
| 1667 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1668 | public Builder extend(Extender extender) { |
| 1669 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1670 | return this; |
| 1671 | } |
| 1672 | |
| 1673 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1674 | * Combine all of the options that have been set and return a new {@link Action} |
| 1675 | * object. |
| 1676 | * @return the built action |
| 1677 | */ |
| 1678 | public Action build() { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1679 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1680 | RemoteInput[] previousDataInputs = |
| 1681 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1682 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1683 | for (RemoteInput input : previousDataInputs) { |
| 1684 | dataOnlyInputs.add(input); |
| 1685 | } |
| 1686 | } |
| 1687 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1688 | if (mRemoteInputs != null) { |
| 1689 | for (RemoteInput input : mRemoteInputs) { |
| 1690 | if (input.isDataOnly()) { |
| 1691 | dataOnlyInputs.add(input); |
| 1692 | } else { |
| 1693 | textInputs.add(input); |
| 1694 | } |
| 1695 | } |
| 1696 | } |
| 1697 | if (!dataOnlyInputs.isEmpty()) { |
| 1698 | RemoteInput[] dataInputsArr = |
| 1699 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1700 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1701 | } |
| 1702 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1703 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1704 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1705 | mAllowGeneratedReplies, mSemanticAction); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1706 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1707 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1708 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1709 | @Override |
| 1710 | public Action clone() { |
| 1711 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1712 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1713 | title, |
| 1714 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1715 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1716 | getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1717 | getAllowGeneratedReplies(), |
| 1718 | getSemanticAction()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1719 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1720 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1721 | @Override |
| 1722 | public int describeContents() { |
| 1723 | return 0; |
| 1724 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1725 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1726 | @Override |
| 1727 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1728 | final Icon ic = getIcon(); |
| 1729 | if (ic != null) { |
| 1730 | out.writeInt(1); |
| 1731 | ic.writeToParcel(out, 0); |
| 1732 | } else { |
| 1733 | out.writeInt(0); |
| 1734 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1735 | TextUtils.writeToParcel(title, out, flags); |
| 1736 | if (actionIntent != null) { |
| 1737 | out.writeInt(1); |
| 1738 | actionIntent.writeToParcel(out, flags); |
| 1739 | } else { |
| 1740 | out.writeInt(0); |
| 1741 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1742 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1743 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1744 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1745 | out.writeInt(mSemanticAction); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1746 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1747 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1748 | public static final Parcelable.Creator<Action> CREATOR = |
| 1749 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1750 | public Action createFromParcel(Parcel in) { |
| 1751 | return new Action(in); |
| 1752 | } |
| 1753 | public Action[] newArray(int size) { |
| 1754 | return new Action[size]; |
| 1755 | } |
| 1756 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1757 | |
| 1758 | /** |
| 1759 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1760 | * metadata or change options on an action builder. |
| 1761 | */ |
| 1762 | public interface Extender { |
| 1763 | /** |
| 1764 | * Apply this extender to a notification action builder. |
| 1765 | * @param builder the builder to be modified. |
| 1766 | * @return the build object for chaining. |
| 1767 | */ |
| 1768 | public Builder extend(Builder builder); |
| 1769 | } |
| 1770 | |
| 1771 | /** |
| 1772 | * Wearable extender for notification actions. To add extensions to an action, |
| 1773 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1774 | * the {@code WearableExtender()} constructor and apply it to a |
| 1775 | * {@link android.app.Notification.Action.Builder} using |
| 1776 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1777 | * |
| 1778 | * <pre class="prettyprint"> |
| 1779 | * Notification.Action action = new Notification.Action.Builder( |
| 1780 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1781 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1782 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1783 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1784 | */ |
| 1785 | public static final class WearableExtender implements Extender { |
| 1786 | /** Notification action extra which contains wearable extensions */ |
| 1787 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1788 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1789 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1790 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1791 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1792 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1793 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1794 | |
| 1795 | // Flags bitwise-ored to mFlags |
| 1796 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1797 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1798 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1799 | |
| 1800 | // Default value for flags integer |
| 1801 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1802 | |
| 1803 | private int mFlags = DEFAULT_FLAGS; |
| 1804 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1805 | private CharSequence mInProgressLabel; |
| 1806 | private CharSequence mConfirmLabel; |
| 1807 | private CharSequence mCancelLabel; |
| 1808 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1809 | /** |
| 1810 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1811 | * options. |
| 1812 | */ |
| 1813 | public WearableExtender() { |
| 1814 | } |
| 1815 | |
| 1816 | /** |
| 1817 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1818 | * wearable options present in an existing notification action. |
| 1819 | * @param action the notification action to inspect. |
| 1820 | */ |
| 1821 | public WearableExtender(Action action) { |
| 1822 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1823 | if (wearableBundle != null) { |
| 1824 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1825 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1826 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1827 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | /** |
| 1832 | * Apply wearable extensions to a notification action that is being built. This is |
| 1833 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1834 | * method of {@link android.app.Notification.Action.Builder}. |
| 1835 | */ |
| 1836 | @Override |
| 1837 | public Action.Builder extend(Action.Builder builder) { |
| 1838 | Bundle wearableBundle = new Bundle(); |
| 1839 | |
| 1840 | if (mFlags != DEFAULT_FLAGS) { |
| 1841 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1842 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1843 | if (mInProgressLabel != null) { |
| 1844 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1845 | } |
| 1846 | if (mConfirmLabel != null) { |
| 1847 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1848 | } |
| 1849 | if (mCancelLabel != null) { |
| 1850 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1851 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1852 | |
| 1853 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1854 | return builder; |
| 1855 | } |
| 1856 | |
| 1857 | @Override |
| 1858 | public WearableExtender clone() { |
| 1859 | WearableExtender that = new WearableExtender(); |
| 1860 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1861 | that.mInProgressLabel = this.mInProgressLabel; |
| 1862 | that.mConfirmLabel = this.mConfirmLabel; |
| 1863 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1864 | return that; |
| 1865 | } |
| 1866 | |
| 1867 | /** |
| 1868 | * Set whether this action is available when the wearable device is not connected to |
| 1869 | * a companion device. The user can still trigger this action when the wearable device is |
| 1870 | * offline, but a visual hint will indicate that the action may not be available. |
| 1871 | * Defaults to true. |
| 1872 | */ |
| 1873 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1874 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1875 | return this; |
| 1876 | } |
| 1877 | |
| 1878 | /** |
| 1879 | * Get whether this action is available when the wearable device is not connected to |
| 1880 | * a companion device. The user can still trigger this action when the wearable device is |
| 1881 | * offline, but a visual hint will indicate that the action may not be available. |
| 1882 | * Defaults to true. |
| 1883 | */ |
| 1884 | public boolean isAvailableOffline() { |
| 1885 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1886 | } |
| 1887 | |
| 1888 | private void setFlag(int mask, boolean value) { |
| 1889 | if (value) { |
| 1890 | mFlags |= mask; |
| 1891 | } else { |
| 1892 | mFlags &= ~mask; |
| 1893 | } |
| 1894 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1895 | |
| 1896 | /** |
| 1897 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1898 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1899 | * |
| 1900 | * @param label the label to display while the action is being prepared to execute |
| 1901 | * @return this object for method chaining |
| 1902 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1903 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1904 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1905 | mInProgressLabel = label; |
| 1906 | return this; |
| 1907 | } |
| 1908 | |
| 1909 | /** |
| 1910 | * Get the label to display while the wearable is preparing to automatically execute |
| 1911 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1912 | * |
| 1913 | * @return the label to display while the action is being prepared to execute |
| 1914 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1915 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1916 | public CharSequence getInProgressLabel() { |
| 1917 | return mInProgressLabel; |
| 1918 | } |
| 1919 | |
| 1920 | /** |
| 1921 | * Set a label to display to confirm that the action should be executed. |
| 1922 | * This is usually an imperative verb like "Send". |
| 1923 | * |
| 1924 | * @param label the label to confirm the action should be executed |
| 1925 | * @return this object for method chaining |
| 1926 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1927 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1928 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1929 | mConfirmLabel = label; |
| 1930 | return this; |
| 1931 | } |
| 1932 | |
| 1933 | /** |
| 1934 | * Get the label to display to confirm that the action should be executed. |
| 1935 | * This is usually an imperative verb like "Send". |
| 1936 | * |
| 1937 | * @return the label to confirm the action should be executed |
| 1938 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1939 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1940 | public CharSequence getConfirmLabel() { |
| 1941 | return mConfirmLabel; |
| 1942 | } |
| 1943 | |
| 1944 | /** |
| 1945 | * Set a label to display to cancel the action. |
| 1946 | * This is usually an imperative verb, like "Cancel". |
| 1947 | * |
| 1948 | * @param label the label to display to cancel the action |
| 1949 | * @return this object for method chaining |
| 1950 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1951 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1952 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1953 | mCancelLabel = label; |
| 1954 | return this; |
| 1955 | } |
| 1956 | |
| 1957 | /** |
| 1958 | * Get the label to display to cancel the action. |
| 1959 | * This is usually an imperative verb like "Cancel". |
| 1960 | * |
| 1961 | * @return the label to display to cancel the action |
| 1962 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1963 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1964 | public CharSequence getCancelLabel() { |
| 1965 | return mCancelLabel; |
| 1966 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1967 | |
| 1968 | /** |
| 1969 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 1970 | * platform that it can generate the appropriate transitions. |
| 1971 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 1972 | * an activity and transitions should be generated, false otherwise. |
| 1973 | * @return this object for method chaining |
| 1974 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1975 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1976 | boolean hintLaunchesActivity) { |
| 1977 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 1978 | return this; |
| 1979 | } |
| 1980 | |
| 1981 | /** |
| 1982 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 1983 | * platform that it can generate the appropriate transitions |
| 1984 | * @return {@code true} if the content intent will launch an activity and transitions |
| 1985 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 1986 | * never set. |
| 1987 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1988 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1989 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 1990 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1991 | |
| 1992 | /** |
| 1993 | * Set a hint that this Action should be displayed inline. |
| 1994 | * |
| 1995 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 1996 | * otherwise |
| 1997 | * @return this object for method chaining |
| 1998 | */ |
| 1999 | public WearableExtender setHintDisplayActionInline( |
| 2000 | boolean hintDisplayInline) { |
| 2001 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 2002 | return this; |
| 2003 | } |
| 2004 | |
| 2005 | /** |
| 2006 | * Get a hint that this Action should be displayed inline. |
| 2007 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 2008 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 2009 | * otherwise. The default value is {@code false} if this was never set. |
| 2010 | */ |
| 2011 | public boolean getHintDisplayActionInline() { |
| 2012 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 2013 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2014 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2015 | |
| 2016 | /** |
| 2017 | * Provides meaning to an {@link Action} that hints at what the associated |
| 2018 | * {@link PendingIntent} will do. For example, an {@link Action} with a |
| 2019 | * {@link PendingIntent} that replies to a text message notification may have the |
| 2020 | * {@link #SEMANTIC_ACTION_REPLY} {@code SemanticAction} set within it. |
| 2021 | * |
| 2022 | * @hide |
| 2023 | */ |
| 2024 | @IntDef(prefix = { "SEMANTIC_ACTION_" }, value = { |
| 2025 | SEMANTIC_ACTION_NONE, |
| 2026 | SEMANTIC_ACTION_REPLY, |
| 2027 | SEMANTIC_ACTION_MARK_AS_READ, |
| 2028 | SEMANTIC_ACTION_MARK_AS_UNREAD, |
| 2029 | SEMANTIC_ACTION_DELETE, |
| 2030 | SEMANTIC_ACTION_ARCHIVE, |
| 2031 | SEMANTIC_ACTION_MUTE, |
| 2032 | SEMANTIC_ACTION_UNMUTE, |
| 2033 | SEMANTIC_ACTION_THUMBS_UP, |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 2034 | SEMANTIC_ACTION_THUMBS_DOWN, |
| 2035 | SEMANTIC_ACTION_CALL |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2036 | }) |
| 2037 | @Retention(RetentionPolicy.SOURCE) |
| 2038 | public @interface SemanticAction {} |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2039 | } |
| 2040 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2041 | /** |
| 2042 | * Array of all {@link Action} structures attached to this notification by |
| 2043 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 2044 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 2045 | * interface for invoking actions. |
| 2046 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 2047 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2048 | |
| 2049 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2050 | * Replacement version of this notification whose content will be shown |
| 2051 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 2052 | * and {@link #VISIBILITY_PUBLIC}. |
| 2053 | */ |
| 2054 | public Notification publicVersion; |
| 2055 | |
| 2056 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2057 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2058 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2059 | */ |
| 2060 | public Notification() |
| 2061 | { |
| 2062 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2063 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2064 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | * @hide |
| 2069 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 2070 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2071 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 2072 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 2073 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2074 | new Builder(context) |
| 2075 | .setWhen(when) |
| 2076 | .setSmallIcon(icon) |
| 2077 | .setTicker(tickerText) |
| 2078 | .setContentTitle(contentTitle) |
| 2079 | .setContentText(contentText) |
| 2080 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 2081 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | /** |
| 2085 | * Constructs a Notification object with the information needed to |
| 2086 | * have a status bar icon without the standard expanded view. |
| 2087 | * |
| 2088 | * @param icon The resource id of the icon to put in the status bar. |
| 2089 | * @param tickerText The text that flows by in the status bar when the notification first |
| 2090 | * activates. |
| 2091 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 2092 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2093 | * |
| 2094 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2096 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2097 | public Notification(int icon, CharSequence tickerText, long when) |
| 2098 | { |
| 2099 | this.icon = icon; |
| 2100 | this.tickerText = tickerText; |
| 2101 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2102 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | /** |
| 2106 | * Unflatten the notification from a parcel. |
| 2107 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2108 | @SuppressWarnings("unchecked") |
| 2109 | public Notification(Parcel parcel) { |
| 2110 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 2111 | // intents in extras are always written as the last entry. |
| 2112 | readFromParcelImpl(parcel); |
| 2113 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2114 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2118 | { |
| 2119 | int version = parcel.readInt(); |
| 2120 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2121 | mWhitelistToken = parcel.readStrongBinder(); |
| 2122 | if (mWhitelistToken == null) { |
| 2123 | mWhitelistToken = processWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2124 | } |
| 2125 | // 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] | 2126 | parcel.setClassCookie(PendingIntent.class, mWhitelistToken); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2129 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2130 | if (parcel.readInt() != 0) { |
| 2131 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2132 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 2133 | icon = mSmallIcon.getResId(); |
| 2134 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | number = parcel.readInt(); |
| 2137 | if (parcel.readInt() != 0) { |
| 2138 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2139 | } |
| 2140 | if (parcel.readInt() != 0) { |
| 2141 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2142 | } |
| 2143 | if (parcel.readInt() != 0) { |
| 2144 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2145 | } |
| 2146 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2147 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2148 | } |
| 2149 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2151 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2152 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2153 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2154 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2155 | defaults = parcel.readInt(); |
| 2156 | flags = parcel.readInt(); |
| 2157 | if (parcel.readInt() != 0) { |
| 2158 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 2159 | } |
| 2160 | |
| 2161 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2162 | if (parcel.readInt() != 0) { |
| 2163 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 2164 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2165 | vibrate = parcel.createLongArray(); |
| 2166 | ledARGB = parcel.readInt(); |
| 2167 | ledOnMS = parcel.readInt(); |
| 2168 | ledOffMS = parcel.readInt(); |
| 2169 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2170 | |
| 2171 | if (parcel.readInt() != 0) { |
| 2172 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2173 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2174 | |
| 2175 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2176 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2177 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2178 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2179 | mGroupKey = parcel.readString(); |
| 2180 | |
| 2181 | mSortKey = parcel.readString(); |
| 2182 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 2183 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2184 | fixDuplicateExtras(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2185 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2186 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 2187 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2188 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2189 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2190 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2191 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2192 | if (parcel.readInt() != 0) { |
| 2193 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2194 | } |
| 2195 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2196 | visibility = parcel.readInt(); |
| 2197 | |
| 2198 | if (parcel.readInt() != 0) { |
| 2199 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 2200 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2201 | |
| 2202 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2203 | |
| 2204 | if (parcel.readInt() != 0) { |
| 2205 | mChannelId = parcel.readString(); |
| 2206 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2207 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2208 | |
| 2209 | if (parcel.readInt() != 0) { |
| 2210 | mShortcutId = parcel.readString(); |
| 2211 | } |
| 2212 | |
| 2213 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2214 | |
| 2215 | if (parcel.readInt() != 0) { |
| 2216 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2217 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2218 | |
| 2219 | mGroupAlertBehavior = parcel.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | } |
| 2221 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2222 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2223 | public Notification clone() { |
| 2224 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2225 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2226 | return that; |
| 2227 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2228 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2229 | /** |
| 2230 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 2231 | * of this into that. |
| 2232 | * @hide |
| 2233 | */ |
| 2234 | public void cloneInto(Notification that, boolean heavy) { |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2235 | that.mWhitelistToken = this.mWhitelistToken; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2236 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2237 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2238 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2239 | that.number = this.number; |
| 2240 | |
| 2241 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 2242 | that.contentIntent = this.contentIntent; |
| 2243 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2244 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2245 | |
| 2246 | if (this.tickerText != null) { |
| 2247 | that.tickerText = this.tickerText.toString(); |
| 2248 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2249 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2250 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2251 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2252 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2253 | that.contentView = this.contentView.clone(); |
| 2254 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2255 | if (heavy && this.mLargeIcon != null) { |
| 2256 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2257 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 2258 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2259 | that.sound = this.sound; // android.net.Uri is immutable |
| 2260 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2261 | if (this.audioAttributes != null) { |
| 2262 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 2263 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2264 | |
| 2265 | final long[] vibrate = this.vibrate; |
| 2266 | if (vibrate != null) { |
| 2267 | final int N = vibrate.length; |
| 2268 | final long[] vib = that.vibrate = new long[N]; |
| 2269 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 2270 | } |
| 2271 | |
| 2272 | that.ledARGB = this.ledARGB; |
| 2273 | that.ledOnMS = this.ledOnMS; |
| 2274 | that.ledOffMS = this.ledOffMS; |
| 2275 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2276 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2277 | that.flags = this.flags; |
| 2278 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2279 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2280 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2281 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2282 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2283 | that.mGroupKey = this.mGroupKey; |
| 2284 | |
| 2285 | that.mSortKey = this.mSortKey; |
| 2286 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2287 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2288 | try { |
| 2289 | that.extras = new Bundle(this.extras); |
| 2290 | // will unparcel |
| 2291 | that.extras.size(); |
| 2292 | } catch (BadParcelableException e) { |
| 2293 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2294 | that.extras = null; |
| 2295 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2296 | } |
| 2297 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2298 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2299 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2302 | if (this.actions != null) { |
| 2303 | that.actions = new Action[this.actions.length]; |
| 2304 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 2305 | if ( this.actions[i] != null) { |
| 2306 | that.actions[i] = this.actions[i].clone(); |
| 2307 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2308 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2309 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2310 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2311 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2312 | that.bigContentView = this.bigContentView.clone(); |
| 2313 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2314 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2315 | if (heavy && this.headsUpContentView != null) { |
| 2316 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 2317 | } |
| 2318 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2319 | that.visibility = this.visibility; |
| 2320 | |
| 2321 | if (this.publicVersion != null) { |
| 2322 | that.publicVersion = new Notification(); |
| 2323 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2324 | } |
| 2325 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2326 | that.color = this.color; |
| 2327 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2328 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2329 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2330 | that.mShortcutId = this.mShortcutId; |
| 2331 | that.mBadgeIcon = this.mBadgeIcon; |
| 2332 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2333 | that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2334 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2335 | if (!heavy) { |
| 2336 | that.lightenPayload(); // will clean out extras |
| 2337 | } |
| 2338 | } |
| 2339 | |
| 2340 | /** |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2341 | * Note all {@link Uri} that are referenced internally, with the expectation |
| 2342 | * that Uri permission grants will need to be issued to ensure the recipient |
| 2343 | * of this object is able to render its contents. |
| 2344 | * |
| 2345 | * @hide |
| 2346 | */ |
| 2347 | public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 2348 | visitor.accept(sound); |
| 2349 | |
| 2350 | if (tickerView != null) tickerView.visitUris(visitor); |
| 2351 | if (contentView != null) contentView.visitUris(visitor); |
| 2352 | if (bigContentView != null) bigContentView.visitUris(visitor); |
| 2353 | if (headsUpContentView != null) headsUpContentView.visitUris(visitor); |
| 2354 | |
| 2355 | if (extras != null) { |
| 2356 | visitor.accept(extras.getParcelable(EXTRA_AUDIO_CONTENTS_URI)); |
| 2357 | visitor.accept(extras.getParcelable(EXTRA_BACKGROUND_IMAGE_URI)); |
| 2358 | } |
| 2359 | |
| 2360 | if (MessagingStyle.class.equals(getNotificationStyle()) && extras != null) { |
| 2361 | final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 2362 | if (!ArrayUtils.isEmpty(messages)) { |
| 2363 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2364 | .getMessagesFromBundleArray(messages)) { |
| 2365 | visitor.accept(message.getDataUri()); |
| 2366 | } |
| 2367 | } |
| 2368 | |
| 2369 | final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 2370 | if (!ArrayUtils.isEmpty(historic)) { |
| 2371 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2372 | .getMessagesFromBundleArray(historic)) { |
| 2373 | visitor.accept(message.getDataUri()); |
| 2374 | } |
| 2375 | } |
| 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | /** |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2380 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 2381 | * listeners when the full contents are not necessary. |
| 2382 | * @hide |
| 2383 | */ |
| 2384 | public final void lightenPayload() { |
| 2385 | tickerView = null; |
| 2386 | contentView = null; |
| 2387 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2388 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2389 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2390 | if (extras != null && !extras.isEmpty()) { |
| 2391 | final Set<String> keyset = extras.keySet(); |
| 2392 | final int N = keyset.size(); |
| 2393 | final String[] keys = keyset.toArray(new String[N]); |
| 2394 | for (int i=0; i<N; i++) { |
| 2395 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2396 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2397 | continue; |
| 2398 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2399 | final Object obj = extras.get(key); |
| 2400 | if (obj != null && |
| 2401 | ( obj instanceof Parcelable |
| 2402 | || obj instanceof Parcelable[] |
| 2403 | || obj instanceof SparseArray |
| 2404 | || obj instanceof ArrayList)) { |
| 2405 | extras.remove(key); |
| 2406 | } |
| 2407 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2408 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2409 | } |
| 2410 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2411 | /** |
| 2412 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2413 | * means it had better not be some custom Parcelable implementation. |
| 2414 | * @hide |
| 2415 | */ |
| 2416 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2417 | if (cs == null) return cs; |
| 2418 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2419 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2420 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2421 | if (cs instanceof Parcelable) { |
| 2422 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2423 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2424 | return cs.toString(); |
| 2425 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2426 | return removeTextSizeSpans(cs); |
| 2427 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2428 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2429 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2430 | if (charSequence instanceof Spanned) { |
| 2431 | Spanned ss = (Spanned) charSequence; |
| 2432 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2433 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2434 | for (Object span : spans) { |
| 2435 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2436 | if (resultSpan instanceof CharacterStyle) { |
| 2437 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2438 | } |
| 2439 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2440 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2441 | resultSpan = new TextAppearanceSpan( |
| 2442 | originalSpan.getFamily(), |
| 2443 | originalSpan.getTextStyle(), |
| 2444 | -1, |
| 2445 | originalSpan.getTextColor(), |
| 2446 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2447 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2448 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2449 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2450 | } else { |
| 2451 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2452 | } |
| 2453 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2454 | ss.getSpanFlags(span)); |
| 2455 | } |
| 2456 | return builder; |
| 2457 | } |
| 2458 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2459 | } |
| 2460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | public int describeContents() { |
| 2462 | return 0; |
| 2463 | } |
| 2464 | |
| 2465 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2466 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2468 | public void writeToParcel(Parcel parcel, int flags) { |
| 2469 | // We need to mark all pending intents getting into the notification |
| 2470 | // system as being put there to later allow the notification ranker |
| 2471 | // to launch them and by doing so add the app to the battery saver white |
| 2472 | // list for a short period of time. The problem is that the system |
| 2473 | // cannot look into the extras as there may be parcelables there that |
| 2474 | // the platform does not know how to handle. To go around that we have |
| 2475 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2476 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2477 | if (collectPendingIntents) { |
| 2478 | PendingIntent.setOnMarshaledListener( |
| 2479 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2480 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2481 | if (allPendingIntents == null) { |
| 2482 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2483 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2484 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2485 | } |
| 2486 | }); |
| 2487 | } |
| 2488 | try { |
| 2489 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2490 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2491 | writeToParcelImpl(parcel, flags); |
| 2492 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2493 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2494 | } finally { |
| 2495 | if (collectPendingIntents) { |
| 2496 | PendingIntent.setOnMarshaledListener(null); |
| 2497 | } |
| 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | parcel.writeInt(1); |
| 2503 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2504 | parcel.writeStrongBinder(mWhitelistToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2505 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2506 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2507 | if (mSmallIcon == null && icon != 0) { |
| 2508 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2509 | mSmallIcon = Icon.createWithResource("", icon); |
| 2510 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2511 | if (mSmallIcon != null) { |
| 2512 | parcel.writeInt(1); |
| 2513 | mSmallIcon.writeToParcel(parcel, 0); |
| 2514 | } else { |
| 2515 | parcel.writeInt(0); |
| 2516 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2517 | parcel.writeInt(number); |
| 2518 | if (contentIntent != null) { |
| 2519 | parcel.writeInt(1); |
| 2520 | contentIntent.writeToParcel(parcel, 0); |
| 2521 | } else { |
| 2522 | parcel.writeInt(0); |
| 2523 | } |
| 2524 | if (deleteIntent != null) { |
| 2525 | parcel.writeInt(1); |
| 2526 | deleteIntent.writeToParcel(parcel, 0); |
| 2527 | } else { |
| 2528 | parcel.writeInt(0); |
| 2529 | } |
| 2530 | if (tickerText != null) { |
| 2531 | parcel.writeInt(1); |
| 2532 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2533 | } else { |
| 2534 | parcel.writeInt(0); |
| 2535 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2536 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2537 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2538 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2539 | } else { |
| 2540 | parcel.writeInt(0); |
| 2541 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | if (contentView != null) { |
| 2543 | parcel.writeInt(1); |
| 2544 | contentView.writeToParcel(parcel, 0); |
| 2545 | } else { |
| 2546 | parcel.writeInt(0); |
| 2547 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2548 | if (mLargeIcon == null && largeIcon != null) { |
| 2549 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2550 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2551 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2552 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2553 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2554 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2555 | } else { |
| 2556 | parcel.writeInt(0); |
| 2557 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2558 | |
| 2559 | parcel.writeInt(defaults); |
| 2560 | parcel.writeInt(this.flags); |
| 2561 | |
| 2562 | if (sound != null) { |
| 2563 | parcel.writeInt(1); |
| 2564 | sound.writeToParcel(parcel, 0); |
| 2565 | } else { |
| 2566 | parcel.writeInt(0); |
| 2567 | } |
| 2568 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2569 | |
| 2570 | if (audioAttributes != null) { |
| 2571 | parcel.writeInt(1); |
| 2572 | audioAttributes.writeToParcel(parcel, 0); |
| 2573 | } else { |
| 2574 | parcel.writeInt(0); |
| 2575 | } |
| 2576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2577 | parcel.writeLongArray(vibrate); |
| 2578 | parcel.writeInt(ledARGB); |
| 2579 | parcel.writeInt(ledOnMS); |
| 2580 | parcel.writeInt(ledOffMS); |
| 2581 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2582 | |
| 2583 | if (fullScreenIntent != null) { |
| 2584 | parcel.writeInt(1); |
| 2585 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2586 | } else { |
| 2587 | parcel.writeInt(0); |
| 2588 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2589 | |
| 2590 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2591 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2592 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2593 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2594 | parcel.writeString(mGroupKey); |
| 2595 | |
| 2596 | parcel.writeString(mSortKey); |
| 2597 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2598 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2599 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2600 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2601 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2602 | if (bigContentView != null) { |
| 2603 | parcel.writeInt(1); |
| 2604 | bigContentView.writeToParcel(parcel, 0); |
| 2605 | } else { |
| 2606 | parcel.writeInt(0); |
| 2607 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2608 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2609 | if (headsUpContentView != null) { |
| 2610 | parcel.writeInt(1); |
| 2611 | headsUpContentView.writeToParcel(parcel, 0); |
| 2612 | } else { |
| 2613 | parcel.writeInt(0); |
| 2614 | } |
| 2615 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2616 | parcel.writeInt(visibility); |
| 2617 | |
| 2618 | if (publicVersion != null) { |
| 2619 | parcel.writeInt(1); |
| 2620 | publicVersion.writeToParcel(parcel, 0); |
| 2621 | } else { |
| 2622 | parcel.writeInt(0); |
| 2623 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2624 | |
| 2625 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2626 | |
| 2627 | if (mChannelId != null) { |
| 2628 | parcel.writeInt(1); |
| 2629 | parcel.writeString(mChannelId); |
| 2630 | } else { |
| 2631 | parcel.writeInt(0); |
| 2632 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2633 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2634 | |
| 2635 | if (mShortcutId != null) { |
| 2636 | parcel.writeInt(1); |
| 2637 | parcel.writeString(mShortcutId); |
| 2638 | } else { |
| 2639 | parcel.writeInt(0); |
| 2640 | } |
| 2641 | |
| 2642 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2643 | |
| 2644 | if (mSettingsText != null) { |
| 2645 | parcel.writeInt(1); |
| 2646 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2647 | } else { |
| 2648 | parcel.writeInt(0); |
| 2649 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2650 | |
| 2651 | parcel.writeInt(mGroupAlertBehavior); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2652 | |
| 2653 | // 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] | 2654 | } |
| 2655 | |
| 2656 | /** |
| 2657 | * Parcelable.Creator that instantiates Notification objects |
| 2658 | */ |
| 2659 | public static final Parcelable.Creator<Notification> CREATOR |
| 2660 | = new Parcelable.Creator<Notification>() |
| 2661 | { |
| 2662 | public Notification createFromParcel(Parcel parcel) |
| 2663 | { |
| 2664 | return new Notification(parcel); |
| 2665 | } |
| 2666 | |
| 2667 | public Notification[] newArray(int size) |
| 2668 | { |
| 2669 | return new Notification[size]; |
| 2670 | } |
| 2671 | }; |
| 2672 | |
| 2673 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2674 | * @hide |
| 2675 | */ |
| 2676 | public static boolean areActionsVisiblyDifferent(Notification first, Notification second) { |
| 2677 | Notification.Action[] firstAs = first.actions; |
| 2678 | Notification.Action[] secondAs = second.actions; |
| 2679 | if (firstAs == null && secondAs != null || firstAs != null && secondAs == null) { |
| 2680 | return true; |
| 2681 | } |
| 2682 | if (firstAs != null && secondAs != null) { |
| 2683 | if (firstAs.length != secondAs.length) { |
| 2684 | return true; |
| 2685 | } |
| 2686 | for (int i = 0; i < firstAs.length; i++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2687 | if (!Objects.equals(String.valueOf(firstAs[i].title), |
| 2688 | String.valueOf(secondAs[i].title))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2689 | return true; |
| 2690 | } |
| 2691 | RemoteInput[] firstRs = firstAs[i].getRemoteInputs(); |
| 2692 | RemoteInput[] secondRs = secondAs[i].getRemoteInputs(); |
| 2693 | if (firstRs == null) { |
| 2694 | firstRs = new RemoteInput[0]; |
| 2695 | } |
| 2696 | if (secondRs == null) { |
| 2697 | secondRs = new RemoteInput[0]; |
| 2698 | } |
| 2699 | if (firstRs.length != secondRs.length) { |
| 2700 | return true; |
| 2701 | } |
| 2702 | for (int j = 0; j < firstRs.length; j++) { |
Julia Reynolds | a4fb9da | 2018-06-04 12:27:58 -0400 | [diff] [blame] | 2703 | if (!Objects.equals(String.valueOf(firstRs[j].getLabel()), |
| 2704 | String.valueOf(secondRs[j].getLabel()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2705 | return true; |
| 2706 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2707 | } |
| 2708 | } |
| 2709 | } |
| 2710 | return false; |
| 2711 | } |
| 2712 | |
| 2713 | /** |
| 2714 | * @hide |
| 2715 | */ |
| 2716 | public static boolean areStyledNotificationsVisiblyDifferent(Builder first, Builder second) { |
| 2717 | if (first.getStyle() == null) { |
| 2718 | return second.getStyle() != null; |
| 2719 | } |
| 2720 | if (second.getStyle() == null) { |
| 2721 | return true; |
| 2722 | } |
| 2723 | return first.getStyle().areNotificationsVisiblyDifferent(second.getStyle()); |
| 2724 | } |
| 2725 | |
| 2726 | /** |
| 2727 | * @hide |
| 2728 | */ |
| 2729 | public static boolean areRemoteViewsChanged(Builder first, Builder second) { |
Julia Reynolds | e5c6045 | 2018-04-30 14:41:36 -0400 | [diff] [blame] | 2730 | if (!Objects.equals(first.usesStandardHeader(), second.usesStandardHeader())) { |
| 2731 | return true; |
| 2732 | } |
| 2733 | |
| 2734 | if (areRemoteViewsChanged(first.mN.contentView, second.mN.contentView)) { |
| 2735 | return true; |
| 2736 | } |
| 2737 | if (areRemoteViewsChanged(first.mN.bigContentView, second.mN.bigContentView)) { |
| 2738 | return true; |
| 2739 | } |
| 2740 | if (areRemoteViewsChanged(first.mN.headsUpContentView, second.mN.headsUpContentView)) { |
| 2741 | return true; |
| 2742 | } |
| 2743 | |
| 2744 | return false; |
| 2745 | } |
| 2746 | |
| 2747 | private static boolean areRemoteViewsChanged(RemoteViews first, RemoteViews second) { |
| 2748 | if (first == null && second == null) { |
| 2749 | return false; |
| 2750 | } |
| 2751 | if (first == null && second != null || first != null && second == null) { |
| 2752 | return true; |
| 2753 | } |
| 2754 | |
| 2755 | if (!Objects.equals(first.getLayoutId(), second.getLayoutId())) { |
| 2756 | return true; |
| 2757 | } |
| 2758 | |
| 2759 | if (!Objects.equals(first.getSequenceNumber(), second.getSequenceNumber())) { |
| 2760 | return true; |
| 2761 | } |
| 2762 | |
| 2763 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | /** |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2767 | * Parcelling creates multiple copies of objects in {@code extras}. Fix them. |
| 2768 | * <p> |
| 2769 | * For backwards compatibility {@code extras} holds some references to "real" member data such |
| 2770 | * as {@link getLargeIcon()} which is mirrored by {@link #EXTRA_LARGE_ICON}. This is mostly |
| 2771 | * fine as long as the object stays in one process. |
| 2772 | * <p> |
| 2773 | * However, once the notification goes into a parcel each reference gets marshalled separately, |
| 2774 | * wasting memory. Especially with large images on Auto and TV, this is worth fixing. |
| 2775 | */ |
| 2776 | private void fixDuplicateExtras() { |
| 2777 | if (extras != null) { |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2778 | fixDuplicateExtra(mLargeIcon, EXTRA_LARGE_ICON); |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | /** |
| 2783 | * If we find an extra that's exactly the same as one of the "real" fields but refers to a |
| 2784 | * separate object, replace it with the field's version to avoid holding duplicate copies. |
| 2785 | */ |
| 2786 | private void fixDuplicateExtra(@Nullable Parcelable original, @NonNull String extraName) { |
| 2787 | if (original != null && extras.getParcelable(extraName) != null) { |
| 2788 | extras.putParcelable(extraName, original); |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2793 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2794 | * layout. |
| 2795 | * |
| 2796 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2797 | * in the view.</p> |
| 2798 | * @param context The context for your application / activity. |
| 2799 | * @param contentTitle The title that goes in the expanded entry. |
| 2800 | * @param contentText The text that goes in the expanded entry. |
| 2801 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2802 | * If this is an activity, it must include the |
| 2803 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2804 | * that you take care of task management as described in the |
| 2805 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2806 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2807 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2808 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2809 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2811 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2812 | public void setLatestEventInfo(Context context, |
| 2813 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2814 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2815 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2816 | new Throwable()); |
| 2817 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2818 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2819 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2820 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2821 | } |
| 2822 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2823 | // ensure that any information already set directly is preserved |
| 2824 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2825 | |
| 2826 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2827 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2828 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2829 | } |
| 2830 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2831 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2832 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2833 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2834 | |
| 2835 | 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] | 2836 | } |
| 2837 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2838 | /** |
| 2839 | * @hide |
| 2840 | */ |
| 2841 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2842 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | /** |
| 2846 | * @hide |
| 2847 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2848 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2849 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2850 | } |
| 2851 | |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 2852 | /** |
| 2853 | * @hide |
| 2854 | */ |
| 2855 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 2856 | long token = proto.start(fieldId); |
| 2857 | proto.write(NotificationProto.CHANNEL_ID, getChannelId()); |
| 2858 | proto.write(NotificationProto.HAS_TICKER_TEXT, this.tickerText != null); |
| 2859 | proto.write(NotificationProto.FLAGS, this.flags); |
| 2860 | proto.write(NotificationProto.COLOR, this.color); |
| 2861 | proto.write(NotificationProto.CATEGORY, this.category); |
| 2862 | proto.write(NotificationProto.GROUP_KEY, this.mGroupKey); |
| 2863 | proto.write(NotificationProto.SORT_KEY, this.mSortKey); |
| 2864 | if (this.actions != null) { |
| 2865 | proto.write(NotificationProto.ACTION_LENGTH, this.actions.length); |
| 2866 | } |
| 2867 | if (this.visibility >= VISIBILITY_SECRET && this.visibility <= VISIBILITY_PUBLIC) { |
| 2868 | proto.write(NotificationProto.VISIBILITY, this.visibility); |
| 2869 | } |
| 2870 | if (publicVersion != null) { |
| 2871 | publicVersion.writeToProto(proto, NotificationProto.PUBLIC_VERSION); |
| 2872 | } |
| 2873 | proto.end(token); |
| 2874 | } |
| 2875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | @Override |
| 2877 | public String toString() { |
| 2878 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2879 | sb.append("Notification(channel="); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2880 | sb.append(getChannelId()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2881 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2882 | sb.append(priority); |
| 2883 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2884 | if (contentView != null) { |
| 2885 | sb.append(contentView.getPackage()); |
| 2886 | sb.append("/0x"); |
| 2887 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2888 | } else { |
| 2889 | sb.append("null"); |
| 2890 | } |
| 2891 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2892 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2893 | sb.append("default"); |
| 2894 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2895 | int N = this.vibrate.length-1; |
| 2896 | sb.append("["); |
| 2897 | for (int i=0; i<N; i++) { |
| 2898 | sb.append(this.vibrate[i]); |
| 2899 | sb.append(','); |
| 2900 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 2901 | if (N != -1) { |
| 2902 | sb.append(this.vibrate[N]); |
| 2903 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2904 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | } else { |
| 2906 | sb.append("null"); |
| 2907 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2908 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2909 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2911 | } else if (this.sound != null) { |
| 2912 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | } else { |
| 2914 | sb.append("null"); |
| 2915 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 2916 | if (this.tickerText != null) { |
| 2917 | sb.append(" tick"); |
| 2918 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2919 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2920 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2921 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2922 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2923 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2924 | if (this.category != null) { |
| 2925 | sb.append(" category="); |
| 2926 | sb.append(this.category); |
| 2927 | } |
| 2928 | if (this.mGroupKey != null) { |
| 2929 | sb.append(" groupKey="); |
| 2930 | sb.append(this.mGroupKey); |
| 2931 | } |
| 2932 | if (this.mSortKey != null) { |
| 2933 | sb.append(" sortKey="); |
| 2934 | sb.append(this.mSortKey); |
| 2935 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2936 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2937 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2938 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2939 | } |
| 2940 | sb.append(" vis="); |
| 2941 | sb.append(visibilityToString(this.visibility)); |
| 2942 | if (this.publicVersion != null) { |
| 2943 | sb.append(" publicVersion="); |
| 2944 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2945 | } |
| 2946 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2947 | return sb.toString(); |
| 2948 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2949 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2950 | /** |
| 2951 | * {@hide} |
| 2952 | */ |
| 2953 | public static String visibilityToString(int vis) { |
| 2954 | switch (vis) { |
| 2955 | case VISIBILITY_PRIVATE: |
| 2956 | return "PRIVATE"; |
| 2957 | case VISIBILITY_PUBLIC: |
| 2958 | return "PUBLIC"; |
| 2959 | case VISIBILITY_SECRET: |
| 2960 | return "SECRET"; |
| 2961 | default: |
| 2962 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 2963 | } |
| 2964 | } |
| 2965 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2966 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 2967 | * {@hide} |
| 2968 | */ |
| 2969 | public static String priorityToString(@Priority int pri) { |
| 2970 | switch (pri) { |
| 2971 | case PRIORITY_MIN: |
| 2972 | return "MIN"; |
| 2973 | case PRIORITY_LOW: |
| 2974 | return "LOW"; |
| 2975 | case PRIORITY_DEFAULT: |
| 2976 | return "DEFAULT"; |
| 2977 | case PRIORITY_HIGH: |
| 2978 | return "HIGH"; |
| 2979 | case PRIORITY_MAX: |
| 2980 | return "MAX"; |
| 2981 | default: |
| 2982 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 2983 | } |
| 2984 | } |
| 2985 | |
Julia Reynolds | 6ad0aec | 2017-07-05 08:47:03 -0400 | [diff] [blame] | 2986 | /** |
| 2987 | * @hide |
| 2988 | */ |
| 2989 | public boolean hasCompletedProgress() { |
| 2990 | // not a progress notification; can't be complete |
| 2991 | if (!extras.containsKey(EXTRA_PROGRESS) |
| 2992 | || !extras.containsKey(EXTRA_PROGRESS_MAX)) { |
| 2993 | return false; |
| 2994 | } |
| 2995 | // many apps use max 0 for 'indeterminate'; not complete |
| 2996 | if (extras.getInt(EXTRA_PROGRESS_MAX) == 0) { |
| 2997 | return false; |
| 2998 | } |
| 2999 | return extras.getInt(EXTRA_PROGRESS) == extras.getInt(EXTRA_PROGRESS_MAX); |
| 3000 | } |
| 3001 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3002 | /** @removed */ |
| 3003 | @Deprecated |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 3004 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3005 | return mChannelId; |
| 3006 | } |
| 3007 | |
| 3008 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3009 | * Returns the id of the channel this notification posts to. |
| 3010 | */ |
| 3011 | public String getChannelId() { |
| 3012 | return mChannelId; |
| 3013 | } |
| 3014 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3015 | /** @removed */ |
| 3016 | @Deprecated |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3017 | public long getTimeout() { |
| 3018 | return mTimeout; |
| 3019 | } |
| 3020 | |
| 3021 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3022 | * Returns the duration from posting after which this notification should be canceled by the |
| 3023 | * system, if it's not canceled already. |
| 3024 | */ |
| 3025 | public long getTimeoutAfter() { |
| 3026 | return mTimeout; |
| 3027 | } |
| 3028 | |
| 3029 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3030 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 3031 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 3032 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 3033 | */ |
| 3034 | public int getBadgeIconType() { |
| 3035 | return mBadgeIcon; |
| 3036 | } |
| 3037 | |
| 3038 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3039 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3040 | * |
| 3041 | * <p>Used by some Launchers that display notification content to hide shortcuts that duplicate |
| 3042 | * notifications. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3043 | */ |
| 3044 | public String getShortcutId() { |
| 3045 | return mShortcutId; |
| 3046 | } |
| 3047 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3048 | |
| 3049 | /** |
| 3050 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 3051 | */ |
| 3052 | public CharSequence getSettingsText() { |
| 3053 | return mSettingsText; |
| 3054 | } |
| 3055 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3056 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3057 | * Returns which type of notifications in a group are responsible for audibly alerting the |
| 3058 | * user. See {@link #GROUP_ALERT_ALL}, {@link #GROUP_ALERT_CHILDREN}, |
| 3059 | * {@link #GROUP_ALERT_SUMMARY}. |
| 3060 | */ |
| 3061 | public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 3062 | return mGroupAlertBehavior; |
| 3063 | } |
| 3064 | |
| 3065 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3066 | * The small icon representing this notification in the status bar and content view. |
| 3067 | * |
| 3068 | * @return the small icon representing this notification. |
| 3069 | * |
| 3070 | * @see Builder#getSmallIcon() |
| 3071 | * @see Builder#setSmallIcon(Icon) |
| 3072 | */ |
| 3073 | public Icon getSmallIcon() { |
| 3074 | return mSmallIcon; |
| 3075 | } |
| 3076 | |
| 3077 | /** |
| 3078 | * Used when notifying to clean up legacy small icons. |
| 3079 | * @hide |
| 3080 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 3081 | @UnsupportedAppUsage |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3082 | public void setSmallIcon(Icon icon) { |
| 3083 | mSmallIcon = icon; |
| 3084 | } |
| 3085 | |
| 3086 | /** |
| 3087 | * The large icon shown in this notification's content view. |
| 3088 | * @see Builder#getLargeIcon() |
| 3089 | * @see Builder#setLargeIcon(Icon) |
| 3090 | */ |
| 3091 | public Icon getLargeIcon() { |
| 3092 | return mLargeIcon; |
| 3093 | } |
| 3094 | |
| 3095 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3096 | * @hide |
| 3097 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 3098 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3099 | public boolean isGroupSummary() { |
| 3100 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 3101 | } |
| 3102 | |
| 3103 | /** |
| 3104 | * @hide |
| 3105 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 3106 | @UnsupportedAppUsage |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3107 | public boolean isGroupChild() { |
| 3108 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 3109 | } |
| 3110 | |
| 3111 | /** |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3112 | * @hide |
| 3113 | */ |
| 3114 | public boolean suppressAlertingDueToGrouping() { |
| 3115 | if (isGroupSummary() |
| 3116 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { |
| 3117 | return true; |
| 3118 | } else if (isGroupChild() |
| 3119 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { |
| 3120 | return true; |
| 3121 | } |
| 3122 | return false; |
| 3123 | } |
| 3124 | |
| 3125 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3126 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3127 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3128 | * 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] | 3129 | * content views using the platform's notification layout template. If your app supports |
| 3130 | * versions of Android as old as API level 4, you can instead use |
| 3131 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 3132 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 3133 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3134 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3135 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3136 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3137 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3138 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3139 | * .setContentTitle("New mail from " + sender.toString()) |
| 3140 | * .setContentText(subject) |
| 3141 | * .setSmallIcon(R.drawable.new_mail) |
| 3142 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3143 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3144 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3145 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3146 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3147 | /** |
| 3148 | * @hide |
| 3149 | */ |
| 3150 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 3151 | "android.rebuild.contentViewActionCount"; |
| 3152 | /** |
| 3153 | * @hide |
| 3154 | */ |
| 3155 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 3156 | = "android.rebuild.bigViewActionCount"; |
| 3157 | /** |
| 3158 | * @hide |
| 3159 | */ |
| 3160 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 3161 | = "android.rebuild.hudViewActionCount"; |
| 3162 | |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 3163 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3164 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 3165 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 3166 | SystemProperties.getBoolean("notifications.only_title", true); |
| 3167 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3168 | /** |
| 3169 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3170 | * secondary text color when the background is light. |
| 3171 | */ |
| 3172 | private static final int LIGHTNESS_TEXT_DIFFERENCE_LIGHT = 20; |
| 3173 | |
| 3174 | /** |
| 3175 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3176 | * secondary text color when the background is dark. |
| 3177 | * A bit less then the above value, since it looks better on dark backgrounds. |
| 3178 | */ |
| 3179 | private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10; |
| 3180 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3181 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3182 | private Notification mN; |
| 3183 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3184 | private Style mStyle; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 3185 | @UnsupportedAppUsage |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3186 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3187 | private ArrayList<Person> mPersonList = new ArrayList<>(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3188 | private NotificationColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3189 | private boolean mIsLegacy; |
| 3190 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3191 | |
| 3192 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3193 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 3194 | */ |
| 3195 | private int mCachedContrastColor = COLOR_INVALID; |
| 3196 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3197 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3198 | * Caches a ambient version of {@link #mCachedAmbientColorIsFor}. |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3199 | */ |
| 3200 | private int mCachedAmbientColor = COLOR_INVALID; |
| 3201 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3202 | /** |
| 3203 | * A neutral color color that can be used for icons. |
| 3204 | */ |
| 3205 | private int mNeutralColor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3206 | |
| 3207 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3208 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 3209 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 3210 | */ |
| 3211 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3212 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 3213 | private int mPrimaryTextColor = COLOR_INVALID; |
| 3214 | private int mSecondaryTextColor = COLOR_INVALID; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3215 | private int mBackgroundColor = COLOR_INVALID; |
| 3216 | private int mForegroundColor = COLOR_INVALID; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 3217 | /** |
| 3218 | * A temporary location where actions are stored. If != null the view originally has action |
| 3219 | * but doesn't have any for this inflation. |
| 3220 | */ |
| 3221 | private ArrayList<Action> mOriginalActions; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 3222 | private boolean mRebuildStyledRemoteViews; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3223 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3224 | private boolean mTintActionButtons; |
| 3225 | private boolean mInNightMode; |
| 3226 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3227 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3228 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3229 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3230 | * @param context |
| 3231 | * A {@link Context} that will be used by the Builder to construct the |
| 3232 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 3233 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3234 | * @param channelId |
| 3235 | * The constructed Notification will be posted on this |
| 3236 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 3237 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3238 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3239 | public Builder(Context context, String channelId) { |
| 3240 | this(context, (Notification) null); |
| 3241 | mN.mChannelId = channelId; |
| 3242 | } |
| 3243 | |
| 3244 | /** |
| 3245 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 3246 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 3247 | */ |
| 3248 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3249 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3250 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3251 | } |
| 3252 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3253 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3254 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3255 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3256 | public Builder(Context context, Notification toAdopt) { |
| 3257 | mContext = context; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3258 | Resources res = mContext.getResources(); |
| 3259 | mTintActionButtons = res.getBoolean(R.bool.config_tintNotificationActionButtons); |
| 3260 | |
| 3261 | if (res.getBoolean(R.bool.config_enableNightMode)) { |
| 3262 | Configuration currentConfig = res.getConfiguration(); |
| 3263 | mInNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 3264 | == Configuration.UI_MODE_NIGHT_YES; |
| 3265 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3266 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3267 | if (toAdopt == null) { |
| 3268 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3269 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 3270 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 3271 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3272 | mN.priority = PRIORITY_DEFAULT; |
| 3273 | mN.visibility = VISIBILITY_PRIVATE; |
| 3274 | } else { |
| 3275 | mN = toAdopt; |
| 3276 | if (mN.actions != null) { |
| 3277 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3278 | } |
| 3279 | |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3280 | if (mN.extras.containsKey(EXTRA_PEOPLE_LIST)) { |
| 3281 | ArrayList<Person> people = mN.extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 3282 | mPersonList.addAll(people); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3283 | } |
| 3284 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 3285 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 3286 | setSmallIcon(mN.icon); |
| 3287 | } |
| 3288 | |
| 3289 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 3290 | setLargeIcon(mN.largeIcon); |
| 3291 | } |
| 3292 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3293 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 3294 | if (!TextUtils.isEmpty(templateClass)) { |
| 3295 | final Class<? extends Style> styleClass |
| 3296 | = getNotificationStyleClass(templateClass); |
| 3297 | if (styleClass == null) { |
| 3298 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 3299 | } else { |
| 3300 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3301 | final Constructor<? extends Style> ctor = |
| 3302 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3303 | ctor.setAccessible(true); |
| 3304 | final Style style = ctor.newInstance(); |
| 3305 | style.restoreFromExtras(mN.extras); |
| 3306 | |
| 3307 | if (style != null) { |
| 3308 | setStyle(style); |
| 3309 | } |
| 3310 | } catch (Throwable t) { |
| 3311 | Log.e(TAG, "Could not create Style", t); |
| 3312 | } |
| 3313 | } |
| 3314 | } |
| 3315 | |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | private NotificationColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3320 | if (mColorUtil == null) { |
| 3321 | mColorUtil = NotificationColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3322 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3323 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3327 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 3328 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 3329 | * the shortcut. |
| 3330 | * |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3331 | * This field will be ignored by Launchers that don't support badging, don't show |
| 3332 | * notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3333 | * |
| 3334 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 3335 | * supersedes |
| 3336 | */ |
| 3337 | public Builder setShortcutId(String shortcutId) { |
| 3338 | mN.mShortcutId = shortcutId; |
| 3339 | return this; |
| 3340 | } |
| 3341 | |
| 3342 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3343 | * Sets which icon to display as a badge for this notification. |
| 3344 | * |
| 3345 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 3346 | * {@link #BADGE_ICON_LARGE}. |
| 3347 | * |
| 3348 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 3349 | */ |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 3350 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3351 | mN.mBadgeIcon = icon; |
| 3352 | return this; |
| 3353 | } |
| 3354 | |
| 3355 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3356 | * Sets the group alert behavior for this notification. Use this method to mute this |
| 3357 | * notification if alerts for this notification's group should be handled by a different |
| 3358 | * notification. This is only applicable for notifications that belong to a |
Julia Reynolds | 399d9bf | 2017-08-11 12:52:14 -0400 | [diff] [blame] | 3359 | * {@link #setGroup(String) group}. This must be called on all notifications you want to |
| 3360 | * mute. For example, if you want only the summary of your group to make noise, all |
| 3361 | * 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] | 3362 | * |
| 3363 | * <p> The default value is {@link #GROUP_ALERT_ALL}.</p> |
| 3364 | */ |
| 3365 | public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 3366 | mN.mGroupAlertBehavior = groupAlertBehavior; |
| 3367 | return this; |
| 3368 | } |
| 3369 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3370 | /** @removed */ |
| 3371 | @Deprecated |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3372 | public Builder setChannel(String channelId) { |
| 3373 | mN.mChannelId = channelId; |
| 3374 | return this; |
| 3375 | } |
| 3376 | |
| 3377 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3378 | * Specifies the channel the notification should be delivered on. |
| 3379 | */ |
| 3380 | public Builder setChannelId(String channelId) { |
| 3381 | mN.mChannelId = channelId; |
| 3382 | return this; |
| 3383 | } |
| 3384 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3385 | /** @removed */ |
| 3386 | @Deprecated |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 3387 | public Builder setTimeout(long durationMs) { |
| 3388 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3389 | return this; |
| 3390 | } |
| 3391 | |
| 3392 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3393 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 3394 | * if it is not already canceled. |
| 3395 | */ |
| 3396 | public Builder setTimeoutAfter(long durationMs) { |
| 3397 | mN.mTimeout = durationMs; |
| 3398 | return this; |
| 3399 | } |
| 3400 | |
| 3401 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3402 | * 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] | 3403 | * |
| 3404 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 3405 | * shown anymore by default and must be opted into by using |
| 3406 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3407 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3408 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3409 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3410 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3411 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3412 | return this; |
| 3413 | } |
| 3414 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3415 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 3416 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3417 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3418 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 3419 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3420 | */ |
| 3421 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3422 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3423 | return this; |
| 3424 | } |
| 3425 | |
| 3426 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3427 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3428 | * |
| 3429 | * 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] | 3430 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3431 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3432 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 3433 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3434 | * 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] | 3435 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3436 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3437 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3438 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3439 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3440 | */ |
| 3441 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3442 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3443 | return this; |
| 3444 | } |
| 3445 | |
| 3446 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3447 | * Sets the Chronometer to count down instead of counting up. |
| 3448 | * |
| 3449 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 3450 | * If it isn't set the chronometer will count up. |
| 3451 | * |
| 3452 | * @see #setUsesChronometer(boolean) |
| 3453 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3454 | public Builder setChronometerCountDown(boolean countDown) { |
| 3455 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3456 | return this; |
| 3457 | } |
| 3458 | |
| 3459 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3460 | * Set the small icon resource, which will be used to represent the notification in the |
| 3461 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3462 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3463 | |
| 3464 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 3465 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 3466 | * icon will be moved to the right-hand side. |
| 3467 | * |
| 3468 | |
| 3469 | * @param icon |
| 3470 | * A resource ID in the application's package of the drawable to use. |
| 3471 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3472 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3473 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3474 | return setSmallIcon(icon != 0 |
| 3475 | ? Icon.createWithResource(mContext, icon) |
| 3476 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3477 | } |
| 3478 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3479 | /** |
| 3480 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 3481 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 3482 | * LevelListDrawable}. |
| 3483 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3484 | * @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] | 3485 | * @param level The level to use for the icon. |
| 3486 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3487 | * @see Notification#icon |
| 3488 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3489 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3490 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3491 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3492 | return setSmallIcon(icon); |
| 3493 | } |
| 3494 | |
| 3495 | /** |
| 3496 | * 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] | 3497 | * status bar and content view (unless overridden there by a |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3498 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 3499 | * |
| 3500 | * @param icon An Icon object to use. |
| 3501 | * @see Notification#icon |
| 3502 | */ |
| 3503 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3504 | mN.setSmallIcon(icon); |
| 3505 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 3506 | mN.icon = icon.getResId(); |
| 3507 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3508 | return this; |
| 3509 | } |
| 3510 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3511 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3512 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3513 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3514 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3515 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3516 | return this; |
| 3517 | } |
| 3518 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3519 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3520 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3521 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3522 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3523 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3524 | return this; |
| 3525 | } |
| 3526 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3527 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3528 | * This provides some additional information that is displayed in the notification. No |
| 3529 | * guarantees are given where exactly it is displayed. |
| 3530 | * |
| 3531 | * <p>This information should only be provided if it provides an essential |
| 3532 | * benefit to the understanding of the notification. The more text you provide the |
| 3533 | * less readable it becomes. For example, an email client should only provide the account |
| 3534 | * name here if more than one email account has been added.</p> |
| 3535 | * |
| 3536 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 3537 | * notification header area. |
| 3538 | * |
| 3539 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 3540 | * this will be shown in the third line of text in the platform notification template. |
| 3541 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 3542 | * same time on those versions; they occupy the same place. |
| 3543 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3544 | */ |
| 3545 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3546 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3547 | return this; |
| 3548 | } |
| 3549 | |
| 3550 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3551 | * Provides text that will appear as a link to your application's settings. |
| 3552 | * |
| 3553 | * <p>This text does not appear within notification {@link Style templates} but may |
| 3554 | * appear when the user uses an affordance to learn more about the notification. |
| 3555 | * Additionally, this text will not appear unless you provide a valid link target by |
| 3556 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 3557 | * |
| 3558 | * <p>This text is meant to be concise description about what the user can customize |
| 3559 | * when they click on this link. The recommended maximum length is 40 characters. |
| 3560 | * @param text |
| 3561 | * @return |
| 3562 | */ |
| 3563 | public Builder setSettingsText(CharSequence text) { |
| 3564 | mN.mSettingsText = safeCharSequence(text); |
| 3565 | return this; |
| 3566 | } |
| 3567 | |
| 3568 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3569 | * Set the remote input history. |
| 3570 | * |
| 3571 | * This should be set to the most recent inputs that have been sent |
| 3572 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 3573 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 3574 | * |
| 3575 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 3576 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 3577 | * and how much of each individual input is shown. |
| 3578 | * |
| 3579 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 3580 | * with a {@code RemoteInput}.</p> |
| 3581 | */ |
| 3582 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 3583 | if (text == null) { |
| 3584 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 3585 | } else { |
| 3586 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 3587 | CharSequence[] safe = new CharSequence[N]; |
| 3588 | for (int i = 0; i < N; i++) { |
| 3589 | safe[i] = safeCharSequence(text[i]); |
| 3590 | } |
| 3591 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 3592 | } |
| 3593 | return this; |
| 3594 | } |
| 3595 | |
| 3596 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 3597 | * Sets whether remote history entries view should have a spinner. |
| 3598 | * @hide |
| 3599 | */ |
| 3600 | public Builder setShowRemoteInputSpinner(boolean showSpinner) { |
| 3601 | mN.extras.putBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER, showSpinner); |
| 3602 | return this; |
| 3603 | } |
| 3604 | |
| 3605 | /** |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 3606 | * Sets whether smart reply buttons should be hidden. |
| 3607 | * @hide |
| 3608 | */ |
| 3609 | public Builder setHideSmartReplies(boolean hideSmartReplies) { |
| 3610 | mN.extras.putBoolean(EXTRA_HIDE_SMART_REPLIES, hideSmartReplies); |
| 3611 | return this; |
| 3612 | } |
| 3613 | |
| 3614 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3615 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 3616 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3617 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3618 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3619 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3620 | return this; |
| 3621 | } |
| 3622 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3623 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3624 | * A small piece of additional information pertaining to this notification. |
| 3625 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3626 | * The platform template will draw this on the last line of the notification, at the far |
| 3627 | * 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] | 3628 | * |
| 3629 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 3630 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 3631 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3632 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3633 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3634 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3635 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3636 | return this; |
| 3637 | } |
| 3638 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3639 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3640 | * Set the progress this notification represents. |
| 3641 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3642 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3643 | */ |
| 3644 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3645 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3646 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3647 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3648 | return this; |
| 3649 | } |
| 3650 | |
| 3651 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3652 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3653 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3654 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3655 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3656 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3657 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3658 | return setCustomContentView(views); |
| 3659 | } |
| 3660 | |
| 3661 | /** |
| 3662 | * Supply custom RemoteViews to use instead of the platform template. |
| 3663 | * |
| 3664 | * This will override the layout that would otherwise be constructed by this Builder |
| 3665 | * object. |
| 3666 | */ |
| 3667 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3668 | mN.contentView = contentView; |
| 3669 | return this; |
| 3670 | } |
| 3671 | |
| 3672 | /** |
| 3673 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3674 | * |
| 3675 | * This will override the expanded layout that would otherwise be constructed by this |
| 3676 | * Builder object. |
| 3677 | */ |
| 3678 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3679 | mN.bigContentView = contentView; |
| 3680 | return this; |
| 3681 | } |
| 3682 | |
| 3683 | /** |
| 3684 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3685 | * |
| 3686 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3687 | * Builder object. |
| 3688 | */ |
| 3689 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3690 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3691 | return this; |
| 3692 | } |
| 3693 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3694 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3695 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3696 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3697 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3698 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3699 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3700 | * 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] | 3701 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3702 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3703 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3704 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3705 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3706 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3707 | return this; |
| 3708 | } |
| 3709 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3710 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3711 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3712 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3713 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3714 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3715 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3716 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3717 | return this; |
| 3718 | } |
| 3719 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3720 | /** |
| 3721 | * An intent to launch instead of posting the notification to the status bar. |
| 3722 | * Only for use with extremely high-priority notifications demanding the user's |
| 3723 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3724 | * alarm clock that the user has explicitly set to a particular time. |
| 3725 | * If this facility is used for something else, please give the user an option |
| 3726 | * to turn it off and use a normal notification, as this can be extremely |
| 3727 | * disruptive. |
| 3728 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3729 | * <p> |
| 3730 | * The system UI may choose to display a heads-up notification, instead of |
| 3731 | * launching this intent, while the user is using the device. |
| 3732 | * </p> |
| 3733 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3734 | * @param intent The pending intent to launch. |
| 3735 | * @param highPriority Passing true will cause this notification to be sent |
| 3736 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3737 | * |
| 3738 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3739 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3740 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3741 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3742 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3743 | return this; |
| 3744 | } |
| 3745 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3746 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3747 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3748 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3749 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3750 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3751 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3752 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3753 | return this; |
| 3754 | } |
| 3755 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3756 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3757 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3758 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3759 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3760 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3761 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3762 | setTicker(tickerText); |
| 3763 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3764 | return this; |
| 3765 | } |
| 3766 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3767 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3768 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3769 | * |
| 3770 | * 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] | 3771 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3772 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3773 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3774 | public Builder setLargeIcon(Bitmap b) { |
| 3775 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3776 | } |
| 3777 | |
| 3778 | /** |
| 3779 | * Add a large icon to the notification content view. |
| 3780 | * |
| 3781 | * In the platform template, this image will be shown on the left of the notification view |
| 3782 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3783 | * badge atop the large icon). |
| 3784 | */ |
| 3785 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3786 | mN.mLargeIcon = icon; |
| 3787 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3788 | return this; |
| 3789 | } |
| 3790 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3791 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3792 | * Set the sound to play. |
| 3793 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3794 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 3795 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3796 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3797 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3798 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3799 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3800 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3801 | mN.sound = sound; |
| 3802 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3803 | return this; |
| 3804 | } |
| 3805 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3806 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3807 | * 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] | 3808 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3809 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 3810 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3811 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3812 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 3813 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3814 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 3815 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3816 | mN.sound = sound; |
| 3817 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3818 | return this; |
| 3819 | } |
| 3820 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3821 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3822 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 3823 | * use during playback. |
| 3824 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3825 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3826 | * @see Notification#sound |
| 3827 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3828 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3829 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3830 | mN.sound = sound; |
| 3831 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3832 | return this; |
| 3833 | } |
| 3834 | |
| 3835 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3836 | * Set the vibration pattern to use. |
| 3837 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3838 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 3839 | * <code>pattern</code> parameter. |
| 3840 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3841 | * <p> |
| 3842 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 3843 | * </p> |
| 3844 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3845 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3846 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3847 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3848 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3849 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3850 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3851 | return this; |
| 3852 | } |
| 3853 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3854 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3855 | * Set the desired color for the indicator LED on the device, as well as the |
| 3856 | * blink duty cycle (specified in milliseconds). |
| 3857 | * |
| 3858 | |
| 3859 | * Not all devices will honor all (or even any) of these values. |
| 3860 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3861 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3862 | * @see Notification#ledARGB |
| 3863 | * @see Notification#ledOnMS |
| 3864 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3865 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3866 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3867 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3868 | mN.ledARGB = argb; |
| 3869 | mN.ledOnMS = onMs; |
| 3870 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3871 | if (onMs != 0 || offMs != 0) { |
| 3872 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 3873 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3874 | return this; |
| 3875 | } |
| 3876 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3877 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3878 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3879 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3880 | |
| 3881 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 3882 | * must take care of canceling them. |
| 3883 | * |
| 3884 | |
| 3885 | * They are typically used to indicate a background task that the user is actively engaged |
| 3886 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 3887 | * (e.g., a file download, sync operation, active network connection). |
| 3888 | * |
| 3889 | |
| 3890 | * @see Notification#FLAG_ONGOING_EVENT |
| 3891 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3892 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3893 | public Builder setOngoing(boolean ongoing) { |
| 3894 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 3895 | return this; |
| 3896 | } |
| 3897 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3898 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3899 | * Set whether this notification should be colorized. When set, the color set with |
| 3900 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 3901 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3902 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 3903 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3904 | * <p> |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3905 | * For most styles, the coloring will only be applied if the notification is for a |
| 3906 | * foreground service notification. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3907 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3908 | * that have a media session attached there is no such requirement. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3909 | * |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3910 | * @see Builder#setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3911 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3912 | */ |
| 3913 | public Builder setColorized(boolean colorize) { |
| 3914 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 3915 | return this; |
| 3916 | } |
| 3917 | |
| 3918 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3919 | * Set this flag if you would only like the sound, vibrate |
| 3920 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3921 | * |
| 3922 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3923 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3924 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 3925 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 3926 | return this; |
| 3927 | } |
| 3928 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3929 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 3930 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3931 | * |
| 3932 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3933 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3934 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 3935 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
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 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3940 | * Set whether or not this notification should not bridge to other devices. |
| 3941 | * |
| 3942 | * <p>Some notifications can be bridged to other devices for remote display. |
| 3943 | * This hint can be set to recommend this notification not be bridged. |
| 3944 | */ |
| 3945 | public Builder setLocalOnly(boolean localOnly) { |
| 3946 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 3947 | return this; |
| 3948 | } |
| 3949 | |
| 3950 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3951 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3952 | * <p> |
| 3953 | * The value should be one or more of the following fields combined with |
| 3954 | * bitwise-or: |
| 3955 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 3956 | * <p> |
| 3957 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3958 | * |
| 3959 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3960 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3961 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3962 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3963 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3964 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3965 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3966 | return this; |
| 3967 | } |
| 3968 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3969 | /** |
| 3970 | * Set the priority of this notification. |
| 3971 | * |
| 3972 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3973 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3974 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3975 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3976 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3977 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3978 | return this; |
| 3979 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3980 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3981 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3982 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3983 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3984 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3985 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3986 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3987 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3988 | return this; |
| 3989 | } |
| 3990 | |
| 3991 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3992 | * Add a person that is relevant to this notification. |
| 3993 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3994 | * <P> |
| 3995 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3996 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 3997 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 3998 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3999 | * </P> |
| 4000 | * |
| 4001 | * <P> |
| 4002 | * The person should be specified by the {@code String} representation of a |
| 4003 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 4004 | * </P> |
| 4005 | * |
| 4006 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 4007 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 4008 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 4009 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4010 | * It is also possible to provide a URI with the schema {@code name:} in order to uniquely |
| 4011 | * identify a person without an entry in the contacts database. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4012 | * </P> |
| 4013 | * |
| 4014 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4015 | * @see Notification#EXTRA_PEOPLE |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4016 | * @deprecated use {@link #addPerson(Person)} |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4017 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 4018 | public Builder addPerson(String uri) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 4019 | addPerson(new Person.Builder().setUri(uri).build()); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 4020 | return this; |
| 4021 | } |
| 4022 | |
| 4023 | /** |
| 4024 | * Add a person that is relevant to this notification. |
| 4025 | * |
| 4026 | * <P> |
| 4027 | * Depending on user preferences, this annotation may allow the notification to pass |
| 4028 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 4029 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 4030 | * appear more prominently in the user interface. |
| 4031 | * </P> |
| 4032 | * |
| 4033 | * <P> |
| 4034 | * A person should usually contain a uri in order to benefit from the ranking boost. |
| 4035 | * However, even if no uri is provided, it's beneficial to provide other people in the |
| 4036 | * notification, such that listeners and voice only devices can announce and handle them |
| 4037 | * properly. |
| 4038 | * </P> |
| 4039 | * |
| 4040 | * @param person the person to add. |
| 4041 | * @see Notification#EXTRA_PEOPLE_LIST |
| 4042 | */ |
| 4043 | public Builder addPerson(Person person) { |
| 4044 | mPersonList.add(person); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 4045 | return this; |
| 4046 | } |
| 4047 | |
| 4048 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4049 | * Set this notification to be part of a group of notifications sharing the same key. |
| 4050 | * Grouped notifications may display in a cluster or stack on devices which |
| 4051 | * support such rendering. |
| 4052 | * |
| 4053 | * <p>To make this notification the summary for its group, also call |
| 4054 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 4055 | * {@link #setSortKey}. |
| 4056 | * @param groupKey The group key of the group. |
| 4057 | * @return this object for method chaining |
| 4058 | */ |
| 4059 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4060 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4061 | return this; |
| 4062 | } |
| 4063 | |
| 4064 | /** |
| 4065 | * Set this notification to be the group summary for a group of notifications. |
| 4066 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4067 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 4068 | * 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] | 4069 | * @param isGroupSummary Whether this notification should be a group summary. |
| 4070 | * @return this object for method chaining |
| 4071 | */ |
| 4072 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 4073 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 4074 | return this; |
| 4075 | } |
| 4076 | |
| 4077 | /** |
| 4078 | * Set a sort key that orders this notification among other notifications from the |
| 4079 | * same package. This can be useful if an external sort was already applied and an app |
| 4080 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 4081 | * value, although providing different priorities in addition to providing sort key may |
| 4082 | * cause this value to be ignored. |
| 4083 | * |
| 4084 | * <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] | 4085 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4086 | * |
| 4087 | * @see String#compareTo(String) |
| 4088 | */ |
| 4089 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4090 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4091 | return this; |
| 4092 | } |
| 4093 | |
| 4094 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4095 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4096 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4097 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 4098 | * |
| 4099 | * @see Notification#extras |
| 4100 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4101 | public Builder addExtras(Bundle extras) { |
| 4102 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4103 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4104 | } |
| 4105 | return this; |
| 4106 | } |
| 4107 | |
| 4108 | /** |
| 4109 | * Set metadata for this notification. |
| 4110 | * |
| 4111 | * <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] | 4112 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4113 | * called. |
| 4114 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4115 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 4116 | * Use {@link #addExtras} to merge in metadata instead. |
| 4117 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4118 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4119 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4120 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4121 | if (extras != null) { |
| 4122 | mUserExtras = extras; |
| 4123 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4124 | return this; |
| 4125 | } |
| 4126 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4127 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4128 | * Get the current metadata Bundle used by this notification Builder. |
| 4129 | * |
| 4130 | * <p>The returned Bundle is shared with this Builder. |
| 4131 | * |
| 4132 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 4133 | * {@link #build()} is called. |
| 4134 | * |
| 4135 | * @see Notification#extras |
| 4136 | */ |
| 4137 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4138 | return mUserExtras; |
| 4139 | } |
| 4140 | |
| 4141 | private Bundle getAllExtras() { |
| 4142 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 4143 | saveExtras.putAll(mN.extras); |
| 4144 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4145 | } |
| 4146 | |
| 4147 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4148 | * Add an action to this notification. Actions are typically displayed by |
| 4149 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4150 | * <p> |
| 4151 | * Every action must have an icon (32dp square and matching the |
| 4152 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4153 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4154 | * <p> |
| 4155 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4156 | * the order they were added. Actions will not be displayed when the notification is |
| 4157 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4158 | * 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] | 4159 | * |
| 4160 | * @param icon Resource ID of a drawable that represents the action. |
| 4161 | * @param title Text describing the action. |
| 4162 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4163 | * |
| 4164 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4165 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4166 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4167 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4168 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4169 | return this; |
| 4170 | } |
| 4171 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4172 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4173 | * Add an action to this notification. Actions are typically displayed by |
| 4174 | * the system as a button adjacent to the notification content. |
| 4175 | * <p> |
| 4176 | * Every action must have an icon (32dp square and matching the |
| 4177 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4178 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4179 | * <p> |
| 4180 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4181 | * the order they were added. Actions will not be displayed when the notification is |
| 4182 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4183 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 4184 | * |
| 4185 | * @param action The action to add. |
| 4186 | */ |
| 4187 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4188 | if (action != null) { |
| 4189 | mActions.add(action); |
| 4190 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4191 | return this; |
| 4192 | } |
| 4193 | |
| 4194 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4195 | * Alter the complete list of actions attached to this notification. |
| 4196 | * @see #addAction(Action). |
| 4197 | * |
| 4198 | * @param actions |
| 4199 | * @return |
| 4200 | */ |
| 4201 | public Builder setActions(Action... actions) { |
| 4202 | mActions.clear(); |
| 4203 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4204 | if (actions[i] != null) { |
| 4205 | mActions.add(actions[i]); |
| 4206 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4207 | } |
| 4208 | return this; |
| 4209 | } |
| 4210 | |
| 4211 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4212 | * Add a rich notification style to be applied at build time. |
| 4213 | * |
| 4214 | * @param style Object responsible for modifying the notification style. |
| 4215 | */ |
| 4216 | public Builder setStyle(Style style) { |
| 4217 | if (mStyle != style) { |
| 4218 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4219 | if (mStyle != null) { |
| 4220 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4221 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 4222 | } else { |
| 4223 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4224 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4225 | } |
| 4226 | return this; |
| 4227 | } |
| 4228 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4229 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 4230 | * Returns the style set by {@link #setStyle(Style)}. |
| 4231 | */ |
| 4232 | public Style getStyle() { |
| 4233 | return mStyle; |
| 4234 | } |
| 4235 | |
| 4236 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4237 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4238 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4239 | * @return The same Builder. |
| 4240 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 4241 | public Builder setVisibility(@Visibility int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4242 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4243 | return this; |
| 4244 | } |
| 4245 | |
| 4246 | /** |
| 4247 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 4248 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 4249 | * @param n A replacement notification, presumably with some or all info redacted. |
| 4250 | * @return The same Builder. |
| 4251 | */ |
| 4252 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4253 | if (n != null) { |
| 4254 | mN.publicVersion = new Notification(); |
| 4255 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 4256 | } else { |
| 4257 | mN.publicVersion = null; |
| 4258 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4259 | return this; |
| 4260 | } |
| 4261 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4262 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4263 | * Apply an extender to this notification builder. Extenders may be used to add |
| 4264 | * metadata or change options on this builder. |
| 4265 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4266 | public Builder extend(Extender extender) { |
| 4267 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4268 | return this; |
| 4269 | } |
| 4270 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 4271 | /** |
| 4272 | * @hide |
| 4273 | */ |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4274 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4275 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4276 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4277 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4278 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4279 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4280 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4281 | } |
| 4282 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4283 | /** |
| 4284 | * Sets {@link Notification#color}. |
| 4285 | * |
| 4286 | * @param argb The accent color to use |
| 4287 | * |
| 4288 | * @return The same Builder. |
| 4289 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4290 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4291 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4292 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4293 | return this; |
| 4294 | } |
| 4295 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4296 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 4297 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 4298 | // This user can never be a badged profile, |
| 4299 | // and also includes USER_ALL system notifications. |
| 4300 | return null; |
| 4301 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 4302 | // Note: This assumes that the current user can read the profile badge of the |
| 4303 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 4304 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4305 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4306 | } |
| 4307 | |
| 4308 | private Bitmap getProfileBadge() { |
| 4309 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4310 | if (badge == null) { |
| 4311 | return null; |
| 4312 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4313 | final int size = mContext.getResources().getDimensionPixelSize( |
| 4314 | R.dimen.notification_badge_size); |
| 4315 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4316 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4317 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4318 | badge.draw(canvas); |
| 4319 | return bitmap; |
| 4320 | } |
| 4321 | |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4322 | private void bindProfileBadge(RemoteViews contentView) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4323 | Bitmap profileBadge = getProfileBadge(); |
| 4324 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4325 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4326 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 4327 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4328 | if (isColorized()) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4329 | contentView.setDrawableTint(R.id.profile_badge, false, |
| 4330 | getPrimaryTextColor(), PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4331 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4332 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4333 | } |
| 4334 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4335 | /** |
| 4336 | * @hide |
| 4337 | */ |
| 4338 | public boolean usesStandardHeader() { |
| 4339 | if (mN.mUsesStandardHeader) { |
| 4340 | return true; |
| 4341 | } |
| 4342 | if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.N) { |
| 4343 | if (mN.contentView == null && mN.bigContentView == null) { |
| 4344 | return true; |
| 4345 | } |
| 4346 | } |
| 4347 | boolean contentViewUsesHeader = mN.contentView == null |
| 4348 | || STANDARD_LAYOUTS.contains(mN.contentView.getLayoutId()); |
| 4349 | boolean bigContentViewUsesHeader = mN.bigContentView == null |
| 4350 | || STANDARD_LAYOUTS.contains(mN.bigContentView.getLayoutId()); |
| 4351 | return contentViewUsesHeader && bigContentViewUsesHeader; |
| 4352 | } |
| 4353 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4354 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4355 | resetNotificationHeader(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4356 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4357 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4358 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4359 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4360 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4361 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4362 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4363 | } |
| 4364 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4365 | /** |
| 4366 | * Resets the notification header to its original state |
| 4367 | */ |
| 4368 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 4369 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 4370 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 4371 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4372 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 4373 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4374 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 4375 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4376 | contentView.setViewVisibility(R.id.header_text_secondary, View.GONE); |
| 4377 | contentView.setTextViewText(R.id.header_text_secondary, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4378 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4379 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4380 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4381 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4382 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 4383 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4384 | mN.mUsesStandardHeader = false; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4385 | } |
| 4386 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4387 | private RemoteViews applyStandardTemplate(int resId, TemplateBindResult result) { |
| 4388 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this), |
| 4389 | result); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | /** |
| 4393 | * @param hasProgress whether the progress bar should be shown and set |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4394 | * @param result |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4395 | */ |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4396 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress, |
| 4397 | TemplateBindResult result) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4398 | return applyStandardTemplate(resId, mParams.reset().hasProgress(hasProgress) |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4399 | .fillTextsFrom(this), result); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 4400 | } |
| 4401 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4402 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p, |
| 4403 | TemplateBindResult result) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 4404 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 4405 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4406 | resetStandardTemplate(contentView); |
| 4407 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4408 | final Bundle ex = mN.extras; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4409 | updateBackgroundColor(contentView); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4410 | bindNotificationHeader(contentView, p.ambient, p.headerTextSecondary); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4411 | bindLargeIconAndReply(contentView, p, result); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4412 | boolean showProgress = handleProgressBar(p.hasProgress, contentView, ex); |
| 4413 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4414 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4415 | contentView.setTextViewText(R.id.title, processTextSpans(p.title)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4416 | if (!p.ambient) { |
| 4417 | setTextViewColorPrimary(contentView, R.id.title); |
| 4418 | } |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 4419 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 4420 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 4421 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4422 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4423 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4424 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 4425 | : com.android.internal.R.id.text; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4426 | contentView.setTextViewText(textId, processTextSpans(p.text)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4427 | if (!p.ambient) { |
| 4428 | setTextViewColorSecondary(contentView, textId); |
| 4429 | } |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4430 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4431 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4432 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4433 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4434 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4435 | return contentView; |
| 4436 | } |
| 4437 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4438 | private CharSequence processTextSpans(CharSequence text) { |
| 4439 | if (hasForegroundColor()) { |
Selim Cinek | 87c3153 | 2017-08-18 18:53:44 -0700 | [diff] [blame] | 4440 | return NotificationColorUtil.clearColorSpans(text); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4441 | } |
| 4442 | return text; |
| 4443 | } |
| 4444 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4445 | private void setTextViewColorPrimary(RemoteViews contentView, int id) { |
| 4446 | ensureColors(); |
| 4447 | contentView.setTextColor(id, mPrimaryTextColor); |
| 4448 | } |
| 4449 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4450 | private boolean hasForegroundColor() { |
| 4451 | return mForegroundColor != COLOR_INVALID; |
| 4452 | } |
| 4453 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4454 | /** |
| 4455 | * @return the primary text color |
| 4456 | * @hide |
| 4457 | */ |
| 4458 | @VisibleForTesting |
| 4459 | public int getPrimaryTextColor() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4460 | ensureColors(); |
| 4461 | return mPrimaryTextColor; |
| 4462 | } |
| 4463 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4464 | /** |
| 4465 | * @return the secondary text color |
| 4466 | * @hide |
| 4467 | */ |
| 4468 | @VisibleForTesting |
| 4469 | public int getSecondaryTextColor() { |
| 4470 | ensureColors(); |
| 4471 | return mSecondaryTextColor; |
| 4472 | } |
| 4473 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4474 | private void setTextViewColorSecondary(RemoteViews contentView, int id) { |
| 4475 | ensureColors(); |
| 4476 | contentView.setTextColor(id, mSecondaryTextColor); |
| 4477 | } |
| 4478 | |
| 4479 | private void ensureColors() { |
| 4480 | int backgroundColor = getBackgroundColor(); |
| 4481 | if (mPrimaryTextColor == COLOR_INVALID |
| 4482 | || mSecondaryTextColor == COLOR_INVALID |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4483 | || mTextColorsAreForBackground != backgroundColor) { |
| 4484 | mTextColorsAreForBackground = backgroundColor; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4485 | if (!hasForegroundColor() || !isColorized()) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4486 | mPrimaryTextColor = NotificationColorUtil.resolvePrimaryColor(mContext, |
| 4487 | backgroundColor); |
| 4488 | mSecondaryTextColor = NotificationColorUtil.resolveSecondaryColor(mContext, |
| 4489 | backgroundColor); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 4490 | if (backgroundColor != COLOR_DEFAULT && isColorized()) { |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4491 | mPrimaryTextColor = NotificationColorUtil.findAlphaToMeetContrast( |
| 4492 | mPrimaryTextColor, backgroundColor, 4.5); |
| 4493 | mSecondaryTextColor = NotificationColorUtil.findAlphaToMeetContrast( |
| 4494 | mSecondaryTextColor, backgroundColor, 4.5); |
| 4495 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4496 | } else { |
| 4497 | double backLum = NotificationColorUtil.calculateLuminance(backgroundColor); |
| 4498 | double textLum = NotificationColorUtil.calculateLuminance(mForegroundColor); |
| 4499 | double contrast = NotificationColorUtil.calculateContrast(mForegroundColor, |
| 4500 | backgroundColor); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4501 | // We only respect the given colors if worst case Black or White still has |
| 4502 | // contrast |
| 4503 | boolean backgroundLight = backLum > textLum |
| 4504 | && satisfiesTextContrast(backgroundColor, Color.BLACK) |
| 4505 | || backLum <= textLum |
| 4506 | && !satisfiesTextContrast(backgroundColor, Color.WHITE); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4507 | if (contrast < 4.5f) { |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4508 | if (backgroundLight) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4509 | mSecondaryTextColor = NotificationColorUtil.findContrastColor( |
| 4510 | mForegroundColor, |
| 4511 | backgroundColor, |
| 4512 | true /* findFG */, |
| 4513 | 4.5f); |
| 4514 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4515 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_LIGHT); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4516 | } else { |
| 4517 | mSecondaryTextColor = |
| 4518 | NotificationColorUtil.findContrastColorAgainstDark( |
| 4519 | mForegroundColor, |
| 4520 | backgroundColor, |
| 4521 | true /* findFG */, |
| 4522 | 4.5f); |
| 4523 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4524 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4525 | } |
| 4526 | } else { |
| 4527 | mPrimaryTextColor = mForegroundColor; |
| 4528 | mSecondaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4529 | mPrimaryTextColor, backgroundLight ? LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4530 | : LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4531 | if (NotificationColorUtil.calculateContrast(mSecondaryTextColor, |
| 4532 | backgroundColor) < 4.5f) { |
| 4533 | // oh well the secondary is not good enough |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4534 | if (backgroundLight) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4535 | mSecondaryTextColor = NotificationColorUtil.findContrastColor( |
| 4536 | mSecondaryTextColor, |
| 4537 | backgroundColor, |
| 4538 | true /* findFG */, |
| 4539 | 4.5f); |
| 4540 | } else { |
| 4541 | mSecondaryTextColor |
| 4542 | = NotificationColorUtil.findContrastColorAgainstDark( |
| 4543 | mSecondaryTextColor, |
| 4544 | backgroundColor, |
| 4545 | true /* findFG */, |
| 4546 | 4.5f); |
| 4547 | } |
| 4548 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4549 | mSecondaryTextColor, backgroundLight |
| 4550 | ? -LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4551 | : -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4552 | } |
| 4553 | } |
| 4554 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4555 | } |
| 4556 | } |
| 4557 | |
| 4558 | private void updateBackgroundColor(RemoteViews contentView) { |
| 4559 | if (isColorized()) { |
| 4560 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
| 4561 | getBackgroundColor()); |
| 4562 | } else { |
| 4563 | // Clear it! |
| 4564 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 4565 | 0); |
| 4566 | } |
| 4567 | } |
| 4568 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4569 | /** |
| 4570 | * @param remoteView the remote view to update the minheight in |
| 4571 | * @param hasMinHeight does it have a mimHeight |
| 4572 | * @hide |
| 4573 | */ |
| 4574 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 4575 | int minHeight = 0; |
| 4576 | if (hasMinHeight) { |
| 4577 | // we need to set the minHeight of the notification |
| 4578 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 4579 | com.android.internal.R.dimen.notification_min_content_height); |
| 4580 | } |
| 4581 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 4582 | } |
| 4583 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4584 | private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4585 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4586 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 4587 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 4588 | if (hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4589 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4590 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4591 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4592 | contentView.setProgressBackgroundTintList( |
| 4593 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 4594 | R.color.notification_progress_background_color))); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4595 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4596 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4597 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 4598 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4599 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4600 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4601 | } else { |
| 4602 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4603 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 4604 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4605 | } |
| 4606 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4607 | private void bindLargeIconAndReply(RemoteViews contentView, StandardTemplateParams p, |
| 4608 | TemplateBindResult result) { |
| 4609 | boolean largeIconShown = bindLargeIcon(contentView, p.hideLargeIcon || p.ambient); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4610 | boolean replyIconShown = bindReplyIcon(contentView, p.hideReplyIcon || p.ambient); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4611 | contentView.setViewVisibility(R.id.right_icon_container, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4612 | largeIconShown || replyIconShown ? View.VISIBLE : View.GONE); |
| 4613 | int marginEnd = calculateMarginEnd(largeIconShown, replyIconShown); |
| 4614 | contentView.setViewLayoutMarginEnd(R.id.line1, marginEnd); |
| 4615 | contentView.setViewLayoutMarginEnd(R.id.text, marginEnd); |
| 4616 | contentView.setViewLayoutMarginEnd(R.id.progress, marginEnd); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4617 | if (result != null) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4618 | result.setIconMarginEnd(marginEnd); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4619 | } |
| 4620 | } |
| 4621 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4622 | private int calculateMarginEnd(boolean largeIconShown, boolean replyIconShown) { |
| 4623 | int marginEnd = 0; |
| 4624 | int contentMargin = mContext.getResources().getDimensionPixelSize( |
| 4625 | R.dimen.notification_content_margin_end); |
| 4626 | int iconSize = mContext.getResources().getDimensionPixelSize( |
| 4627 | R.dimen.notification_right_icon_size); |
| 4628 | if (replyIconShown) { |
| 4629 | // The size of the reply icon |
| 4630 | marginEnd += iconSize; |
| 4631 | |
| 4632 | int replyInset = mContext.getResources().getDimensionPixelSize( |
| 4633 | R.dimen.notification_reply_inset); |
| 4634 | // We're subtracting the inset of the reply icon to make sure it's |
| 4635 | // aligned nicely on the right, and remove it from the following padding |
| 4636 | marginEnd -= replyInset * 2; |
| 4637 | } |
| 4638 | if (largeIconShown) { |
| 4639 | // adding size of the right icon |
| 4640 | marginEnd += iconSize; |
| 4641 | |
| 4642 | if (replyIconShown) { |
| 4643 | // We also add some padding to the reply icon if it's around |
| 4644 | marginEnd += contentMargin; |
| 4645 | } |
| 4646 | } |
| 4647 | if (replyIconShown || largeIconShown) { |
| 4648 | // The padding to the content |
| 4649 | marginEnd += contentMargin; |
| 4650 | } |
| 4651 | return marginEnd; |
| 4652 | } |
| 4653 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4654 | /** |
| 4655 | * Bind the large icon. |
| 4656 | * @return if the largeIcon is visible |
| 4657 | */ |
| 4658 | private boolean bindLargeIcon(RemoteViews contentView, boolean hideLargeIcon) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4659 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 4660 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 4661 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4662 | boolean showLargeIcon = mN.mLargeIcon != null && !hideLargeIcon; |
| 4663 | if (showLargeIcon) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4664 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 4665 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
| 4666 | processLargeLegacyIcon(mN.mLargeIcon, contentView); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4667 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4668 | return showLargeIcon; |
| 4669 | } |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4670 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4671 | /** |
| 4672 | * Bind the reply icon. |
| 4673 | * @return if the reply icon is visible |
| 4674 | */ |
| 4675 | private boolean bindReplyIcon(RemoteViews contentView, boolean hideReplyIcon) { |
| 4676 | boolean actionVisible = !hideReplyIcon; |
| 4677 | Action action = null; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4678 | if (actionVisible) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4679 | action = findReplyAction(); |
| 4680 | actionVisible = action != null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4681 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4682 | if (actionVisible) { |
| 4683 | contentView.setViewVisibility(R.id.reply_icon_action, View.VISIBLE); |
| 4684 | contentView.setDrawableTint(R.id.reply_icon_action, |
| 4685 | false /* targetBackground */, |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 4686 | getNeutralColor(), |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4687 | PorterDuff.Mode.SRC_ATOP); |
| 4688 | contentView.setOnClickPendingIntent(R.id.reply_icon_action, action.actionIntent); |
| 4689 | contentView.setRemoteInputs(R.id.reply_icon_action, action.mRemoteInputs); |
| 4690 | } else { |
| 4691 | contentView.setRemoteInputs(R.id.reply_icon_action, null); |
| 4692 | } |
| 4693 | contentView.setViewVisibility(R.id.reply_icon_action, |
| 4694 | actionVisible ? View.VISIBLE : View.GONE); |
| 4695 | return actionVisible; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | private Action findReplyAction() { |
| 4699 | ArrayList<Action> actions = mActions; |
| 4700 | if (mOriginalActions != null) { |
| 4701 | actions = mOriginalActions; |
| 4702 | } |
| 4703 | int numActions = actions.size(); |
| 4704 | for (int i = 0; i < numActions; i++) { |
| 4705 | Action action = actions.get(i); |
| 4706 | if (hasValidRemoteInput(action)) { |
| 4707 | return action; |
| 4708 | } |
| 4709 | } |
| 4710 | return null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4711 | } |
| 4712 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4713 | private void bindNotificationHeader(RemoteViews contentView, boolean ambient, |
| 4714 | CharSequence secondaryHeaderText) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4715 | bindSmallIcon(contentView, ambient); |
| 4716 | bindHeaderAppName(contentView, ambient); |
| 4717 | if (!ambient) { |
| 4718 | // Ambient view does not have these |
| 4719 | bindHeaderText(contentView); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4720 | bindHeaderTextSecondary(contentView, secondaryHeaderText); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4721 | bindHeaderChronometerAndTime(contentView); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4722 | bindProfileBadge(contentView); |
| 4723 | } |
Julia Reynolds | 6013e5c | 2018-04-18 08:43:34 -0400 | [diff] [blame] | 4724 | bindActivePermissions(contentView, ambient); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 4725 | bindExpandButton(contentView); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4726 | mN.mUsesStandardHeader = true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4727 | } |
| 4728 | |
Julia Reynolds | 6013e5c | 2018-04-18 08:43:34 -0400 | [diff] [blame] | 4729 | private void bindActivePermissions(RemoteViews contentView, boolean ambient) { |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 4730 | int color = ambient ? resolveAmbientColor() : getNeutralColor(); |
Julia Reynolds | b887b23 | 2018-04-10 16:38:08 -0400 | [diff] [blame] | 4731 | contentView.setDrawableTint(R.id.camera, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4732 | contentView.setDrawableTint(R.id.mic, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4733 | contentView.setDrawableTint(R.id.overlay, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4734 | } |
| 4735 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4736 | private void bindExpandButton(RemoteViews contentView) { |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 4737 | int color = isColorized() ? getPrimaryTextColor() : getSecondaryTextColor(); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4738 | contentView.setDrawableTint(R.id.expand_button, false, color, |
| 4739 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4740 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4741 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | private void bindHeaderChronometerAndTime(RemoteViews contentView) { |
| 4745 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4746 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4747 | setTextViewColorSecondary(contentView, R.id.time_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4748 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 4749 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 4750 | contentView.setLong(R.id.chronometer, "setBase", |
| 4751 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 4752 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4753 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 4754 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4755 | setTextViewColorSecondary(contentView, R.id.chronometer); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4756 | } else { |
| 4757 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 4758 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4759 | setTextViewColorSecondary(contentView, R.id.time); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4760 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4761 | } else { |
| 4762 | // We still want a time to be set but gone, such that we can show and hide it |
| 4763 | // on demand in case it's a child notification without anything in the header |
| 4764 | 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] | 4765 | } |
| 4766 | } |
| 4767 | |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4768 | private void bindHeaderText(RemoteViews contentView) { |
| 4769 | CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 4770 | if (headerText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4771 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4772 | headerText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4773 | } |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4774 | if (headerText == null |
| 4775 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 4776 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 4777 | headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 4778 | } |
| 4779 | if (headerText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4780 | // 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] | 4781 | contentView.setTextViewText(R.id.header_text, processTextSpans( |
| 4782 | processLegacyText(headerText))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4783 | setTextViewColorSecondary(contentView, R.id.header_text); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4784 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 4785 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4786 | setTextViewColorSecondary(contentView, R.id.header_text_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4787 | } |
| 4788 | } |
| 4789 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4790 | private void bindHeaderTextSecondary(RemoteViews contentView, CharSequence secondaryText) { |
| 4791 | if (!TextUtils.isEmpty(secondaryText)) { |
| 4792 | contentView.setTextViewText(R.id.header_text_secondary, processTextSpans( |
| 4793 | processLegacyText(secondaryText))); |
| 4794 | setTextViewColorSecondary(contentView, R.id.header_text_secondary); |
| 4795 | contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE); |
| 4796 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE); |
| 4797 | setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider); |
| 4798 | } |
| 4799 | } |
| 4800 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4801 | /** |
| 4802 | * @hide |
| 4803 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 4804 | @UnsupportedAppUsage |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4805 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4806 | CharSequence name = null; |
| 4807 | final PackageManager pm = mContext.getPackageManager(); |
| 4808 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 4809 | // only system packages which lump together a bunch of unrelated stuff |
| 4810 | // may substitute a different name to make the purpose of the |
| 4811 | // notification more clear. the correct package label should always |
| 4812 | // be accessible via SystemUI. |
| 4813 | final String pkg = mContext.getPackageName(); |
| 4814 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 4815 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 4816 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 4817 | name = subName; |
| 4818 | } else { |
| 4819 | Log.w(TAG, "warning: pkg " |
| 4820 | + pkg + " attempting to substitute app name '" + subName |
| 4821 | + "' without holding perm " |
| 4822 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 4823 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4824 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4825 | if (TextUtils.isEmpty(name)) { |
| 4826 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 4827 | } |
| 4828 | if (TextUtils.isEmpty(name)) { |
| 4829 | // still nothing? |
| 4830 | return null; |
| 4831 | } |
| 4832 | |
| 4833 | return String.valueOf(name); |
| 4834 | } |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4835 | private void bindHeaderAppName(RemoteViews contentView, boolean ambient) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4836 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4837 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4838 | setTextViewColorPrimary(contentView, R.id.app_name_text); |
| 4839 | } else { |
| 4840 | contentView.setTextColor(R.id.app_name_text, |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 4841 | ambient ? resolveAmbientColor() : getSecondaryTextColor()); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4842 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4843 | } |
| 4844 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4845 | private void bindSmallIcon(RemoteViews contentView, boolean ambient) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4846 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 4847 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 4848 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4849 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4850 | contentView.setInt(R.id.icon, "setImageLevel", mN.iconLevel); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4851 | processSmallIconColor(mN.mSmallIcon, contentView, ambient); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4852 | } |
| 4853 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4854 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4855 | * @return true if the built notification will show the time or the chronometer; false |
| 4856 | * otherwise |
| 4857 | */ |
| 4858 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 4859 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4860 | } |
| 4861 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4862 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4863 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 4864 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4865 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4866 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4867 | |
| 4868 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 4869 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 4870 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, View.GONE); |
| 4871 | big.setViewVisibility(R.id.notification_material_reply_progress, View.GONE); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4872 | |
| 4873 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 4874 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 4875 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 4876 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 4877 | |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 4878 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 4879 | R.dimen.notification_content_margin); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4880 | } |
| 4881 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4882 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 4883 | TemplateBindResult result) { |
| 4884 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this), |
| 4885 | result); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 4886 | } |
| 4887 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4888 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4889 | StandardTemplateParams p, TemplateBindResult result) { |
| 4890 | RemoteViews big = applyStandardTemplate(layoutId, p, result); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4891 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4892 | resetStandardTemplateWithActions(big); |
| 4893 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4894 | boolean validRemoteInput = false; |
| 4895 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4896 | int N = mActions.size(); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4897 | boolean emphazisedMode = mN.fullScreenIntent != null && !p.ambient; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4898 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4899 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 4900 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4901 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 4902 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4903 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4904 | for (int i=0; i<N; i++) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4905 | Action action = mActions.get(i); |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 4906 | boolean actionHasValidInput = hasValidRemoteInput(action); |
| 4907 | validRemoteInput |= actionHasValidInput; |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4908 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4909 | final RemoteViews button = generateActionButton(action, emphazisedMode, |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 4910 | p.ambient); |
| 4911 | if (actionHasValidInput && !emphazisedMode) { |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 4912 | // Clear the drawable |
| 4913 | button.setInt(R.id.action0, "setBackgroundResource", 0); |
| 4914 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4915 | big.addView(R.id.actions, button); |
| 4916 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4917 | } else { |
| 4918 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4919 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4920 | |
| 4921 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4922 | if (!p.ambient && validRemoteInput && replyText != null |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 4923 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0]) |
| 4924 | && p.maxRemoteInputHistory > 0) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 4925 | boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4926 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 4927 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, |
| 4928 | View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4929 | big.setTextViewText(R.id.notification_material_reply_text_1, |
| 4930 | processTextSpans(replyText[0])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4931 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 4932 | big.setViewVisibility(R.id.notification_material_reply_progress, |
| 4933 | showSpinner ? View.VISIBLE : View.GONE); |
| 4934 | big.setProgressIndeterminateTintList( |
| 4935 | R.id.notification_material_reply_progress, |
| 4936 | ColorStateList.valueOf( |
| 4937 | isColorized() ? getPrimaryTextColor() : resolveContrastColor())); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4938 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 4939 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1]) |
| 4940 | && p.maxRemoteInputHistory > 1) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4941 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4942 | big.setTextViewText(R.id.notification_material_reply_text_2, |
| 4943 | processTextSpans(replyText[1])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4944 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4945 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 4946 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2]) |
| 4947 | && p.maxRemoteInputHistory > 2) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4948 | big.setViewVisibility( |
| 4949 | R.id.notification_material_reply_text_3, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4950 | big.setTextViewText(R.id.notification_material_reply_text_3, |
| 4951 | processTextSpans(replyText[2])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4952 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4953 | } |
| 4954 | } |
| 4955 | } |
| 4956 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4957 | return big; |
| 4958 | } |
| 4959 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4960 | private boolean hasValidRemoteInput(Action action) { |
| 4961 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 4962 | // Weird actions |
| 4963 | return false; |
| 4964 | } |
| 4965 | |
| 4966 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 4967 | if (remoteInputs == null) { |
| 4968 | return false; |
| 4969 | } |
| 4970 | |
| 4971 | for (RemoteInput r : remoteInputs) { |
| 4972 | CharSequence[] choices = r.getChoices(); |
| 4973 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 4974 | return true; |
| 4975 | } |
| 4976 | } |
| 4977 | return false; |
| 4978 | } |
| 4979 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4980 | /** |
| 4981 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 4982 | * 1. Custom contentView from the caller |
| 4983 | * 2. Style's proposed content view |
| 4984 | * 3. Standard template view |
| 4985 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4986 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4987 | return createContentView(false /* increasedheight */ ); |
| 4988 | } |
| 4989 | |
| 4990 | /** |
| 4991 | * Construct a RemoteViews for the smaller content view. |
| 4992 | * |
| 4993 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 4994 | * styles may support showing more then just that basic 1U size |
| 4995 | * and the system may decide to render important notifications |
| 4996 | * slightly bigger even when collapsed. |
| 4997 | * |
| 4998 | * @hide |
| 4999 | */ |
| 5000 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5001 | if (mN.contentView != null && useExistingRemoteView()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5002 | return mN.contentView; |
| 5003 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5004 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5005 | if (styleView != null) { |
| 5006 | return styleView; |
| 5007 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5008 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5009 | return applyStandardTemplate(getBaseLayoutResource(), null /* result */); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5010 | } |
| 5011 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5012 | private boolean useExistingRemoteView() { |
| 5013 | return mStyle == null || (!mStyle.displayCustomViewInline() |
| 5014 | && !mRebuildStyledRemoteViews); |
| 5015 | } |
| 5016 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5017 | /** |
| 5018 | * Construct a RemoteViews for the final big notification layout. |
| 5019 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5020 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5021 | RemoteViews result = null; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5022 | if (mN.bigContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5023 | return mN.bigContentView; |
| 5024 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5025 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 5026 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5027 | } else if (mActions.size() != 0) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5028 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5029 | null /* result */); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5030 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5031 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 5032 | return result; |
| 5033 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5034 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5035 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 5036 | * Construct a RemoteViews for the final notification header only. This will not be |
| 5037 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5038 | * |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5039 | * @param ambient if true, generate the header for the ambient display layout. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5040 | * @hide |
| 5041 | */ |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5042 | public RemoteViews makeNotificationHeader(boolean ambient) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 5043 | Boolean colorized = (Boolean) mN.extras.get(EXTRA_COLORIZED); |
| 5044 | mN.extras.putBoolean(EXTRA_COLORIZED, false); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5045 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5046 | ambient ? R.layout.notification_template_ambient_header |
| 5047 | : R.layout.notification_template_header); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5048 | resetNotificationHeader(header); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 5049 | bindNotificationHeader(header, ambient, null); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 5050 | if (colorized != null) { |
| 5051 | mN.extras.putBoolean(EXTRA_COLORIZED, colorized); |
| 5052 | } else { |
| 5053 | mN.extras.remove(EXTRA_COLORIZED); |
| 5054 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5055 | return header; |
| 5056 | } |
| 5057 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5058 | /** |
| 5059 | * Construct a RemoteViews for the ambient version of the notification. |
| 5060 | * |
| 5061 | * @hide |
| 5062 | */ |
| 5063 | public RemoteViews makeAmbientNotification() { |
| 5064 | RemoteViews ambient = applyStandardTemplateWithActions( |
| 5065 | R.layout.notification_template_material_ambient, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5066 | mParams.reset().ambient(true).fillTextsFrom(this).hasProgress(false), |
| 5067 | null /* result */); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5068 | return ambient; |
| 5069 | } |
| 5070 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5071 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5072 | if (result != null) { |
| 5073 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 5074 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5075 | } |
| 5076 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5077 | /** |
| 5078 | * Adapt the Notification header if this view is used as an expanded view. |
| 5079 | * |
| 5080 | * @hide |
| 5081 | */ |
| 5082 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5083 | if (result != null) { |
| 5084 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 5085 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5086 | } |
| 5087 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5088 | /** |
| 5089 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5090 | * |
| 5091 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5092 | * styles may support showing more then just that basic 1U size |
| 5093 | * and the system may decide to render important notifications |
| 5094 | * slightly bigger even when collapsed. |
| 5095 | * |
| 5096 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5097 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5098 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5099 | if (mN.headsUpContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5100 | return mN.headsUpContentView; |
| 5101 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5102 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 5103 | if (styleView != null) { |
| 5104 | return styleView; |
| 5105 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5106 | } else if (mActions.size() == 0) { |
| 5107 | return null; |
| 5108 | } |
| 5109 | |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5110 | // We only want at most a single remote input history to be shown here, otherwise |
| 5111 | // the content would become squished. |
| 5112 | StandardTemplateParams p = mParams.reset().fillTextsFrom(this) |
| 5113 | .setMaxRemoteInputHistory(1); |
| 5114 | return applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5115 | p, |
| 5116 | null /* result */); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5117 | } |
| 5118 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5119 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5120 | * Construct a RemoteViews for the final heads-up notification layout. |
| 5121 | */ |
| 5122 | public RemoteViews createHeadsUpContentView() { |
| 5123 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 5124 | } |
| 5125 | |
| 5126 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5127 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5128 | * |
| 5129 | * @hide |
| 5130 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 5131 | @UnsupportedAppUsage |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5132 | public RemoteViews makePublicContentView() { |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5133 | return makePublicView(false /* ambient */); |
| 5134 | } |
| 5135 | |
| 5136 | /** |
| 5137 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5138 | * |
| 5139 | * @hide |
| 5140 | */ |
| 5141 | public RemoteViews makePublicAmbientNotification() { |
| 5142 | return makePublicView(true /* ambient */); |
| 5143 | } |
| 5144 | |
| 5145 | private RemoteViews makePublicView(boolean ambient) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5146 | if (mN.publicVersion != null) { |
| 5147 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5148 | return ambient ? builder.makeAmbientNotification() : builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5149 | } |
| 5150 | Bundle savedBundle = mN.extras; |
| 5151 | Style style = mStyle; |
| 5152 | mStyle = null; |
| 5153 | Icon largeIcon = mN.mLargeIcon; |
| 5154 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5155 | Bitmap largeIconLegacy = mN.largeIcon; |
| 5156 | mN.largeIcon = null; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5157 | ArrayList<Action> actions = mActions; |
| 5158 | mActions = new ArrayList<>(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5159 | Bundle publicExtras = new Bundle(); |
| 5160 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 5161 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 5162 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 5163 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5164 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 5165 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | ed07b96 | 2018-04-30 14:39:35 -0700 | [diff] [blame] | 5166 | String appName = savedBundle.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 5167 | if (appName != null) { |
| 5168 | publicExtras.putString(EXTRA_SUBSTITUTE_APP_NAME, appName); |
| 5169 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5170 | mN.extras = publicExtras; |
Selim Cinek | 499c20f | 2017-07-20 14:06:09 -0700 | [diff] [blame] | 5171 | RemoteViews view; |
| 5172 | if (ambient) { |
| 5173 | publicExtras.putCharSequence(EXTRA_TITLE, |
| 5174 | mContext.getString(com.android.internal.R.string.notification_hidden_text)); |
| 5175 | view = makeAmbientNotification(); |
| 5176 | } else{ |
| 5177 | view = makeNotificationHeader(false /* ambient */); |
| 5178 | view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true); |
| 5179 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5180 | mN.extras = savedBundle; |
| 5181 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5182 | mN.largeIcon = largeIconLegacy; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5183 | mActions = actions; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5184 | mStyle = style; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5185 | return view; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5186 | } |
| 5187 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5188 | /** |
| 5189 | * Construct a content view for the display when low - priority |
| 5190 | * |
| 5191 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 5192 | * a new subtext is created consisting of the content of the |
| 5193 | * notification. |
| 5194 | * @hide |
| 5195 | */ |
| 5196 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
| 5197 | int color = mN.color; |
| 5198 | mN.color = COLOR_DEFAULT; |
| 5199 | CharSequence summary = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 5200 | if (!useRegularSubtext || TextUtils.isEmpty(summary)) { |
| 5201 | CharSequence newSummary = createSummaryText(); |
| 5202 | if (!TextUtils.isEmpty(newSummary)) { |
| 5203 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, newSummary); |
| 5204 | } |
| 5205 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 5206 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5207 | RemoteViews header = makeNotificationHeader(false /* ambient */); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 5208 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5209 | if (summary != null) { |
| 5210 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, summary); |
| 5211 | } else { |
| 5212 | mN.extras.remove(EXTRA_SUB_TEXT); |
| 5213 | } |
| 5214 | mN.color = color; |
| 5215 | return header; |
| 5216 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5217 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5218 | private CharSequence createSummaryText() { |
| 5219 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 5220 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 5221 | return titleText; |
| 5222 | } |
| 5223 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 5224 | if (titleText == null) { |
| 5225 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 5226 | } |
| 5227 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5228 | if (titleText != null) { |
| 5229 | summary.append(bidi.unicodeWrap(titleText)); |
| 5230 | } |
| 5231 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 5232 | if (titleText != null && contentText != null) { |
| 5233 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 5234 | R.string.notification_header_divider_symbol_with_spaces))); |
| 5235 | } |
| 5236 | if (contentText != null) { |
| 5237 | summary.append(bidi.unicodeWrap(contentText)); |
| 5238 | } |
| 5239 | return summary; |
| 5240 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5241 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5242 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5243 | boolean ambient) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5244 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 5245 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5246 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 5247 | : tombstone ? getActionTombstoneLayoutResource() |
| 5248 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5249 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5250 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5251 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5252 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5253 | if (action.mRemoteInputs != null) { |
| 5254 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 5255 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5256 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5257 | // change the background bgColor |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5258 | CharSequence title = action.title; |
| 5259 | ColorStateList[] outResultColor = null; |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5260 | int background = resolveBackgroundColor(); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5261 | if (isLegacy()) { |
Selim Cinek | 87c3153 | 2017-08-18 18:53:44 -0700 | [diff] [blame] | 5262 | title = NotificationColorUtil.clearColorSpans(title); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5263 | } else { |
| 5264 | outResultColor = new ColorStateList[1]; |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5265 | title = ensureColorSpanContrast(title, background, outResultColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5266 | } |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5267 | button.setTextViewText(R.id.action0, processTextSpans(title)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5268 | setTextViewColorPrimary(button, R.id.action0); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5269 | int rippleColor; |
| 5270 | boolean hasColorOverride = outResultColor != null && outResultColor[0] != null; |
| 5271 | if (hasColorOverride) { |
| 5272 | // There's a span spanning the full text, let's take it and use it as the |
| 5273 | // background color |
| 5274 | background = outResultColor[0].getDefaultColor(); |
| 5275 | int textColor = NotificationColorUtil.resolvePrimaryColor(mContext, |
| 5276 | background); |
| 5277 | button.setTextColor(R.id.action0, textColor); |
| 5278 | rippleColor = textColor; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5279 | } else if (mN.color != COLOR_DEFAULT && !isColorized() && mTintActionButtons) { |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5280 | rippleColor = resolveContrastColor(); |
| 5281 | button.setTextColor(R.id.action0, rippleColor); |
| 5282 | } else { |
| 5283 | rippleColor = getPrimaryTextColor(); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5284 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5285 | // We only want about 20% alpha for the ripple |
| 5286 | rippleColor = (rippleColor & 0x00ffffff) | 0x33000000; |
| 5287 | button.setColorStateList(R.id.action0, "setRippleColor", |
| 5288 | ColorStateList.valueOf(rippleColor)); |
| 5289 | button.setColorStateList(R.id.action0, "setButtonBackground", |
| 5290 | ColorStateList.valueOf(background)); |
| 5291 | button.setBoolean(R.id.action0, "setHasStroke", !hasColorOverride); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5292 | } else { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5293 | button.setTextViewText(R.id.action0, processTextSpans( |
| 5294 | processLegacyText(action.title))); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 5295 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5296 | setTextViewColorPrimary(button, R.id.action0); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5297 | } else if (mN.color != COLOR_DEFAULT && mTintActionButtons) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5298 | button.setTextColor(R.id.action0, |
| 5299 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5300 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5301 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5302 | return button; |
| 5303 | } |
| 5304 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5305 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5306 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 5307 | * text if a span was found that spans over the whole text. |
| 5308 | * |
| 5309 | * @param charSequence the charSequence on which the spans are |
| 5310 | * @param background the background color to ensure the contrast against |
| 5311 | * @param outResultColor an array in which a color will be returned as the first element if |
| 5312 | * there exists a full length color span. |
| 5313 | * @return the contrasted charSequence |
| 5314 | */ |
| 5315 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 5316 | ColorStateList[] outResultColor) { |
| 5317 | if (charSequence instanceof Spanned) { |
| 5318 | Spanned ss = (Spanned) charSequence; |
| 5319 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 5320 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 5321 | for (Object span : spans) { |
| 5322 | Object resultSpan = span; |
| 5323 | int spanStart = ss.getSpanStart(span); |
| 5324 | int spanEnd = ss.getSpanEnd(span); |
| 5325 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 5326 | if (resultSpan instanceof CharacterStyle) { |
| 5327 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 5328 | } |
| 5329 | if (resultSpan instanceof TextAppearanceSpan) { |
| 5330 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 5331 | ColorStateList textColor = originalSpan.getTextColor(); |
| 5332 | if (textColor != null) { |
| 5333 | int[] colors = textColor.getColors(); |
| 5334 | int[] newColors = new int[colors.length]; |
| 5335 | for (int i = 0; i < newColors.length; i++) { |
| 5336 | newColors[i] = NotificationColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5337 | colors[i], background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5338 | } |
| 5339 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 5340 | newColors); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5341 | if (fullLength) { |
| 5342 | outResultColor[0] = textColor; |
| 5343 | // Let's drop the color from the span |
| 5344 | textColor = null; |
| 5345 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5346 | resultSpan = new TextAppearanceSpan( |
| 5347 | originalSpan.getFamily(), |
| 5348 | originalSpan.getTextStyle(), |
| 5349 | originalSpan.getTextSize(), |
| 5350 | textColor, |
| 5351 | originalSpan.getLinkTextColor()); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5352 | } |
| 5353 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 5354 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 5355 | int foregroundColor = originalSpan.getForegroundColor(); |
| 5356 | foregroundColor = NotificationColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5357 | foregroundColor, background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5358 | if (fullLength) { |
| 5359 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5360 | resultSpan = null; |
| 5361 | } else { |
| 5362 | resultSpan = new ForegroundColorSpan(foregroundColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5363 | } |
| 5364 | } else { |
| 5365 | resultSpan = span; |
| 5366 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5367 | if (resultSpan != null) { |
| 5368 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 5369 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5370 | } |
| 5371 | return builder; |
| 5372 | } |
| 5373 | return charSequence; |
| 5374 | } |
| 5375 | |
| 5376 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5377 | * @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] | 5378 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5379 | */ |
| 5380 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5381 | if (!mIsLegacyInitialized) { |
| 5382 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 5383 | < Build.VERSION_CODES.LOLLIPOP; |
| 5384 | mIsLegacyInitialized = true; |
| 5385 | } |
| 5386 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5387 | } |
| 5388 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5389 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 5390 | return processLegacyText(charSequence, false /* ambient */); |
| 5391 | } |
| 5392 | |
| 5393 | private CharSequence processLegacyText(CharSequence charSequence, boolean ambient) { |
| 5394 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
| 5395 | boolean wantLightText = ambient; |
| 5396 | if (isAlreadyLightText != wantLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5397 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5398 | } else { |
| 5399 | return charSequence; |
| 5400 | } |
| 5401 | } |
| 5402 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5403 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5404 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5405 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5406 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
| 5407 | boolean ambient) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5408 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5409 | int color; |
| 5410 | if (ambient) { |
| 5411 | color = resolveAmbientColor(); |
| 5412 | } else if (isColorized()) { |
| 5413 | color = getPrimaryTextColor(); |
| 5414 | } else { |
| 5415 | color = resolveContrastColor(); |
| 5416 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5417 | if (colorable) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5418 | contentView.setDrawableTint(R.id.icon, false, color, |
| 5419 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5420 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5421 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5422 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5423 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5424 | } |
| 5425 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5426 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5427 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5428 | * if it's grayscale). |
| 5429 | */ |
| 5430 | // TODO: also check bounds, transparency, that sort of thing. |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5431 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) { |
| 5432 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5433 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5434 | // resolve color will fall back to the default when legacy |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5435 | contentView.setDrawableTint(R.id.icon, false, resolveContrastColor(), |
| 5436 | PorterDuff.Mode.SRC_ATOP); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 5437 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5438 | } |
| 5439 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 5440 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5441 | if (mN.color != COLOR_DEFAULT) { |
| 5442 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5443 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5444 | } |
| 5445 | |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5446 | int resolveContrastColor() { |
| 5447 | if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) { |
| 5448 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5449 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5450 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5451 | int color; |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5452 | int background = mContext.getColor( |
| 5453 | com.android.internal.R.color.notification_material_background_color); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5454 | if (mN.color == COLOR_DEFAULT) { |
| 5455 | ensureColors(); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5456 | color = NotificationColorUtil.resolveDefaultColor(mContext, background); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5457 | } else { |
| 5458 | color = NotificationColorUtil.resolveContrastColor(mContext, mN.color, |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5459 | background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5460 | } |
| 5461 | if (Color.alpha(color) < 255) { |
| 5462 | // alpha doesn't go well for color filters, so let's blend it manually |
| 5463 | color = NotificationColorUtil.compositeColors(color, background); |
| 5464 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5465 | mCachedContrastColorIsFor = mN.color; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5466 | return mCachedContrastColor = color; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5467 | } |
| 5468 | |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5469 | int resolveNeutralColor() { |
| 5470 | if (mNeutralColor != COLOR_INVALID) { |
| 5471 | return mNeutralColor; |
| 5472 | } |
| 5473 | int background = mContext.getColor( |
| 5474 | com.android.internal.R.color.notification_material_background_color); |
| 5475 | mNeutralColor = NotificationColorUtil.resolveDefaultColor(mContext, background); |
| 5476 | if (Color.alpha(mNeutralColor) < 255) { |
| 5477 | // alpha doesn't go well for color filters, so let's blend it manually |
| 5478 | mNeutralColor = NotificationColorUtil.compositeColors(mNeutralColor, background); |
| 5479 | } |
| 5480 | return mNeutralColor; |
| 5481 | } |
| 5482 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5483 | int resolveAmbientColor() { |
| 5484 | if (mCachedAmbientColorIsFor == mN.color && mCachedAmbientColorIsFor != COLOR_INVALID) { |
| 5485 | return mCachedAmbientColor; |
| 5486 | } |
| 5487 | final int contrasted = NotificationColorUtil.resolveAmbientColor(mContext, mN.color); |
| 5488 | |
| 5489 | mCachedAmbientColorIsFor = mN.color; |
| 5490 | return mCachedAmbientColor = contrasted; |
| 5491 | } |
| 5492 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5493 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5494 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5495 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5496 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5497 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5498 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5499 | mN.actions = new Action[mActions.size()]; |
| 5500 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5501 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5502 | if (!mPersonList.isEmpty()) { |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 5503 | mN.extras.putParcelableArrayList(EXTRA_PEOPLE_LIST, mPersonList); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 5504 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5505 | if (mN.bigContentView != null || mN.contentView != null |
| 5506 | || mN.headsUpContentView != null) { |
| 5507 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 5508 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5509 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5510 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5511 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5512 | /** |
| 5513 | * Creates a Builder from an existing notification so further changes can be made. |
| 5514 | * @param context The context for your application / activity. |
| 5515 | * @param n The notification to create a Builder from. |
| 5516 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5517 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5518 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5519 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 5520 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5521 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5522 | if (applicationInfo != null) { |
| 5523 | try { |
| 5524 | builderContext = context.createApplicationContext(applicationInfo, |
| 5525 | Context.CONTEXT_RESTRICTED); |
| 5526 | } catch (NameNotFoundException e) { |
| 5527 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 5528 | builderContext = context; // try with our context |
| 5529 | } |
| 5530 | } else { |
| 5531 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5532 | } |
| 5533 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5534 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5535 | } |
| 5536 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5537 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5538 | * @deprecated Use {@link #build()} instead. |
| 5539 | */ |
| 5540 | @Deprecated |
| 5541 | public Notification getNotification() { |
| 5542 | return build(); |
| 5543 | } |
| 5544 | |
| 5545 | /** |
| 5546 | * Combine all of the options that have been set and return a new {@link Notification} |
| 5547 | * object. |
| 5548 | */ |
| 5549 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5550 | // first, add any extras from the calling code |
| 5551 | if (mUserExtras != null) { |
| 5552 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5553 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5554 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5555 | mN.creationTime = System.currentTimeMillis(); |
| 5556 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5557 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5558 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 5559 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5560 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5561 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5562 | if (mStyle != null) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5563 | mStyle.reduceImageSizes(mContext); |
| 5564 | mStyle.purgeResources(); |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 5565 | mStyle.validate(mContext); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5566 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5567 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5568 | mN.reduceImageSizes(mContext); |
| 5569 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5570 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5571 | && (useExistingRemoteView())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5572 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5573 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5574 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 5575 | mN.contentView.getSequenceNumber()); |
| 5576 | } |
| 5577 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5578 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5579 | if (mN.bigContentView != null) { |
| 5580 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 5581 | mN.bigContentView.getSequenceNumber()); |
| 5582 | } |
| 5583 | } |
| 5584 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5585 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5586 | if (mN.headsUpContentView != null) { |
| 5587 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 5588 | mN.headsUpContentView.getSequenceNumber()); |
| 5589 | } |
| 5590 | } |
| 5591 | } |
| 5592 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 5593 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 5594 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 5595 | } |
| 5596 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 5597 | mN.allPendingIntents = null; |
| 5598 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5599 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5600 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5601 | |
| 5602 | /** |
| 5603 | * Apply this Builder to an existing {@link Notification} object. |
| 5604 | * |
| 5605 | * @hide |
| 5606 | */ |
| 5607 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 5608 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5609 | return n; |
| 5610 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5611 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5612 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5613 | * 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] | 5614 | * change. Also removes extenders on low ram devices, as |
| 5615 | * {@link android.service.notification.NotificationListenerService} services are disabled. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5616 | * |
| 5617 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 5618 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5619 | * @hide |
| 5620 | */ |
Kristian Monsen | 30f59b2 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5621 | public static Notification maybeCloneStrippedForDelivery(Notification n, boolean isLowRam, |
| 5622 | Context context) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5623 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5624 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5625 | // Only strip views for known Styles because we won't know how to |
| 5626 | // re-create them otherwise. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5627 | if (!isLowRam |
| 5628 | && !TextUtils.isEmpty(templateClass) |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5629 | && getNotificationStyleClass(templateClass) == null) { |
| 5630 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5631 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5632 | |
| 5633 | // Only strip unmodified BuilderRemoteViews. |
| 5634 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5635 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5636 | n.contentView.getSequenceNumber(); |
| 5637 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5638 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5639 | n.bigContentView.getSequenceNumber(); |
| 5640 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5641 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5642 | n.headsUpContentView.getSequenceNumber(); |
| 5643 | |
| 5644 | // Nothing to do here, no need to clone. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5645 | if (!isLowRam |
| 5646 | && !stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5647 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5648 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5649 | |
| 5650 | Notification clone = n.clone(); |
| 5651 | if (stripContentView) { |
| 5652 | clone.contentView = null; |
| 5653 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 5654 | } |
| 5655 | if (stripBigContentView) { |
| 5656 | clone.bigContentView = null; |
| 5657 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 5658 | } |
| 5659 | if (stripHeadsUpContentView) { |
| 5660 | clone.headsUpContentView = null; |
| 5661 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 5662 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5663 | if (isLowRam) { |
Kristian Monsen | 30f59b2 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5664 | String[] allowedServices = context.getResources().getStringArray( |
| 5665 | R.array.config_allowedManagedServicesOnLowRamDevices); |
| 5666 | if (allowedServices.length == 0) { |
| 5667 | clone.extras.remove(Notification.TvExtender.EXTRA_TV_EXTENDER); |
| 5668 | clone.extras.remove(WearableExtender.EXTRA_WEARABLE_EXTENSIONS); |
| 5669 | clone.extras.remove(CarExtender.EXTRA_CAR_EXTENDER); |
| 5670 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5671 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5672 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5673 | } |
| 5674 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 5675 | @UnsupportedAppUsage |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5676 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5677 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5678 | } |
| 5679 | |
| 5680 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5681 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5685 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5689 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5690 | } |
| 5691 | |
| 5692 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5693 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5694 | } |
| 5695 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5696 | private int getMessagingLayoutResource() { |
| 5697 | return R.layout.notification_template_material_messaging; |
| 5698 | } |
| 5699 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5700 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5701 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5702 | } |
| 5703 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5704 | private int getEmphasizedActionLayoutResource() { |
| 5705 | return R.layout.notification_material_action_emphasized; |
| 5706 | } |
| 5707 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5708 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5709 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5710 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5711 | |
| 5712 | private int getBackgroundColor() { |
| 5713 | if (isColorized()) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5714 | return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : mN.color; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5715 | } else { |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5716 | return COLOR_DEFAULT; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5717 | } |
| 5718 | } |
| 5719 | |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5720 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5721 | * Gets a neutral color that can be used for icons or similar that should not stand out. |
| 5722 | */ |
| 5723 | private int getNeutralColor() { |
| 5724 | if (isColorized()) { |
| 5725 | return getSecondaryTextColor(); |
| 5726 | } else { |
| 5727 | return resolveNeutralColor(); |
| 5728 | } |
| 5729 | } |
| 5730 | |
| 5731 | /** |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5732 | * Same as getBackgroundColor but also resolved the default color to the background. |
| 5733 | */ |
| 5734 | private int resolveBackgroundColor() { |
| 5735 | int backgroundColor = getBackgroundColor(); |
| 5736 | if (backgroundColor == COLOR_DEFAULT) { |
| 5737 | backgroundColor = mContext.getColor( |
| 5738 | com.android.internal.R.color.notification_material_background_color); |
| 5739 | } |
| 5740 | return backgroundColor; |
| 5741 | } |
| 5742 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5743 | private boolean isColorized() { |
| 5744 | return mN.isColorized(); |
| 5745 | } |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5746 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5747 | private boolean shouldTintActionButtons() { |
| 5748 | return mTintActionButtons; |
| 5749 | } |
| 5750 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5751 | private boolean textColorsNeedInversion() { |
| 5752 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 5753 | return false; |
| 5754 | } |
| 5755 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 5756 | return targetSdkVersion > Build.VERSION_CODES.M |
| 5757 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 5758 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5759 | |
| 5760 | /** |
| 5761 | * Set a color palette to be used as the background and textColors |
| 5762 | * |
| 5763 | * @param backgroundColor the color to be used as the background |
| 5764 | * @param foregroundColor the color to be used as the foreground |
| 5765 | * |
| 5766 | * @hide |
| 5767 | */ |
| 5768 | public void setColorPalette(int backgroundColor, int foregroundColor) { |
| 5769 | mBackgroundColor = backgroundColor; |
| 5770 | mForegroundColor = foregroundColor; |
| 5771 | mTextColorsAreForBackground = COLOR_INVALID; |
| 5772 | ensureColors(); |
| 5773 | } |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5774 | |
| 5775 | /** |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5776 | * Forces all styled remoteViews to be built from scratch and not use any cached |
| 5777 | * RemoteViews. |
| 5778 | * This is needed for legacy apps that are baking in their remoteviews into the |
| 5779 | * notification. |
| 5780 | * |
| 5781 | * @hide |
| 5782 | */ |
| 5783 | public void setRebuildStyledRemoteViews(boolean rebuild) { |
| 5784 | mRebuildStyledRemoteViews = rebuild; |
| 5785 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5786 | |
| 5787 | /** |
| 5788 | * Get the text that should be displayed in the statusBar when heads upped. This is |
| 5789 | * usually just the app name, but may be different depending on the style. |
| 5790 | * |
| 5791 | * @param publicMode If true, return a text that is safe to display in public. |
| 5792 | * |
| 5793 | * @hide |
| 5794 | */ |
| 5795 | public CharSequence getHeadsUpStatusBarText(boolean publicMode) { |
| 5796 | if (mStyle != null && !publicMode) { |
| 5797 | CharSequence text = mStyle.getHeadsUpStatusBarText(); |
| 5798 | if (!TextUtils.isEmpty(text)) { |
| 5799 | return text; |
| 5800 | } |
| 5801 | } |
| 5802 | return loadHeaderAppName(); |
| 5803 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5807 | * Reduces the image sizes to conform to a maximum allowed size. This also processes all custom |
| 5808 | * remote views. |
| 5809 | * |
| 5810 | * @hide |
| 5811 | */ |
| 5812 | void reduceImageSizes(Context context) { |
| 5813 | if (extras.getBoolean(EXTRA_REDUCED_IMAGES)) { |
| 5814 | return; |
| 5815 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5816 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5817 | if (mLargeIcon != null || largeIcon != null) { |
| 5818 | Resources resources = context.getResources(); |
| 5819 | Class<? extends Style> style = getNotificationStyle(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5820 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5821 | ? R.dimen.notification_right_icon_size_low_ram |
| 5822 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5823 | int maxHeight = maxWidth; |
| 5824 | if (MediaStyle.class.equals(style) |
| 5825 | || DecoratedMediaCustomViewStyle.class.equals(style)) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5826 | maxHeight = resources.getDimensionPixelSize(isLowRam |
| 5827 | ? R.dimen.notification_media_image_max_height_low_ram |
| 5828 | : R.dimen.notification_media_image_max_height); |
| 5829 | maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5830 | ? R.dimen.notification_media_image_max_width_low_ram |
| 5831 | : R.dimen.notification_media_image_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5832 | } |
| 5833 | if (mLargeIcon != null) { |
| 5834 | mLargeIcon.scaleDownIfNecessary(maxWidth, maxHeight); |
| 5835 | } |
| 5836 | if (largeIcon != null) { |
| 5837 | largeIcon = Icon.scaleDownIfNecessary(largeIcon, maxWidth, maxHeight); |
| 5838 | } |
| 5839 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5840 | reduceImageSizesForRemoteView(contentView, context, isLowRam); |
| 5841 | reduceImageSizesForRemoteView(headsUpContentView, context, isLowRam); |
| 5842 | reduceImageSizesForRemoteView(bigContentView, context, isLowRam); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5843 | extras.putBoolean(EXTRA_REDUCED_IMAGES, true); |
| 5844 | } |
| 5845 | |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5846 | private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context, |
| 5847 | boolean isLowRam) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5848 | if (remoteView != null) { |
| 5849 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5850 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5851 | ? R.dimen.notification_custom_view_max_image_width_low_ram |
| 5852 | : R.dimen.notification_custom_view_max_image_width); |
| 5853 | int maxHeight = resources.getDimensionPixelSize(isLowRam |
| 5854 | ? R.dimen.notification_custom_view_max_image_height_low_ram |
| 5855 | : R.dimen.notification_custom_view_max_image_height); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5856 | remoteView.reduceImageSizes(maxWidth, maxHeight); |
| 5857 | } |
| 5858 | } |
| 5859 | |
| 5860 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5861 | * @return whether this notification is a foreground service notification |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5862 | */ |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5863 | private boolean isForegroundService() { |
| 5864 | return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5865 | } |
| 5866 | |
| 5867 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5868 | * @return whether this notification has a media session attached |
| 5869 | * @hide |
| 5870 | */ |
| 5871 | public boolean hasMediaSession() { |
| 5872 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 5873 | } |
| 5874 | |
| 5875 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5876 | * @return the style class of this notification |
| 5877 | * @hide |
| 5878 | */ |
| 5879 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 5880 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 5881 | |
| 5882 | if (!TextUtils.isEmpty(templateClass)) { |
| 5883 | return Notification.getNotificationStyleClass(templateClass); |
| 5884 | } |
| 5885 | return null; |
| 5886 | } |
| 5887 | |
| 5888 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5889 | * @return true if this notification is colorized. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5890 | * |
| 5891 | * @hide |
| 5892 | */ |
| 5893 | public boolean isColorized() { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5894 | if (isColorizedMedia()) { |
| 5895 | return true; |
| 5896 | } |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 5897 | return extras.getBoolean(EXTRA_COLORIZED) |
| 5898 | && (hasColorizedPermission() || isForegroundService()); |
| 5899 | } |
| 5900 | |
| 5901 | /** |
| 5902 | * Returns whether an app can colorize due to the android.permission.USE_COLORIZED_NOTIFICATIONS |
| 5903 | * permission. The permission is checked when a notification is enqueued. |
| 5904 | */ |
| 5905 | private boolean hasColorizedPermission() { |
| 5906 | return (flags & Notification.FLAG_CAN_COLORIZE) != 0; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5907 | } |
| 5908 | |
| 5909 | /** |
| 5910 | * @return true if this notification is colorized and it is a media notification |
| 5911 | * |
| 5912 | * @hide |
| 5913 | */ |
| 5914 | public boolean isColorizedMedia() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5915 | Class<? extends Style> style = getNotificationStyle(); |
| 5916 | if (MediaStyle.class.equals(style)) { |
| 5917 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 5918 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 5919 | return true; |
| 5920 | } |
| 5921 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 5922 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 5923 | return true; |
| 5924 | } |
| 5925 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5926 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5927 | } |
| 5928 | |
Selim Cinek | 0847acd | 2017-04-24 19:48:29 -0700 | [diff] [blame] | 5929 | |
| 5930 | /** |
| 5931 | * @return true if this is a media notification |
| 5932 | * |
| 5933 | * @hide |
| 5934 | */ |
| 5935 | public boolean isMediaNotification() { |
| 5936 | Class<? extends Style> style = getNotificationStyle(); |
| 5937 | if (MediaStyle.class.equals(style)) { |
| 5938 | return true; |
| 5939 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 5940 | return true; |
| 5941 | } |
| 5942 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5943 | } |
| 5944 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5945 | private boolean hasLargeIcon() { |
| 5946 | return mLargeIcon != null || largeIcon != null; |
| 5947 | } |
| 5948 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5949 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5950 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5951 | * @hide |
| 5952 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5953 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5954 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 5955 | } |
| 5956 | |
| 5957 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5958 | * @return true if the notification will show a chronometer; false otherwise |
| 5959 | * @hide |
| 5960 | */ |
| 5961 | public boolean showsChronometer() { |
| 5962 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 5963 | } |
| 5964 | |
| 5965 | /** |
Julia Reynolds | 7ca3307 | 2017-06-29 13:58:24 -0400 | [diff] [blame] | 5966 | * @removed |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 5967 | */ |
| 5968 | @SystemApi |
| 5969 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 5970 | Class<? extends Style>[] classes = new Class[] { |
| 5971 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 5972 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 5973 | MessagingStyle.class }; |
| 5974 | for (Class<? extends Style> innerClass : classes) { |
| 5975 | if (templateClass.equals(innerClass.getName())) { |
| 5976 | return innerClass; |
| 5977 | } |
| 5978 | } |
| 5979 | return null; |
| 5980 | } |
| 5981 | |
| 5982 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5983 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 5984 | * object. |
| 5985 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 5986 | public static abstract class Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 5987 | |
| 5988 | /** |
| 5989 | * The number of items allowed simulatanously in the remote input history. |
| 5990 | * @hide |
| 5991 | */ |
| 5992 | static final int MAX_REMOTE_INPUT_HISTORY_LINES = 3; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5993 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 5994 | |
| 5995 | /** |
| 5996 | * @hide |
| 5997 | */ |
| 5998 | protected CharSequence mSummaryText = null; |
| 5999 | |
| 6000 | /** |
| 6001 | * @hide |
| 6002 | */ |
| 6003 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6004 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6005 | protected Builder mBuilder; |
| 6006 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6007 | /** |
| 6008 | * Overrides ContentTitle in the big form of the template. |
| 6009 | * This defaults to the value passed to setContentTitle(). |
| 6010 | */ |
| 6011 | protected void internalSetBigContentTitle(CharSequence title) { |
| 6012 | mBigContentTitle = title; |
| 6013 | } |
| 6014 | |
| 6015 | /** |
| 6016 | * Set the first line of text after the detail section in the big form of the template. |
| 6017 | */ |
| 6018 | protected void internalSetSummaryText(CharSequence cs) { |
| 6019 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 6020 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6021 | } |
| 6022 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6023 | public void setBuilder(Builder builder) { |
| 6024 | if (mBuilder != builder) { |
| 6025 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 6026 | if (mBuilder != null) { |
| 6027 | mBuilder.setStyle(this); |
| 6028 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6029 | } |
| 6030 | } |
| 6031 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6032 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6033 | if (mBuilder == null) { |
| 6034 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 6035 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6036 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6037 | |
| 6038 | protected RemoteViews getStandardView(int layoutId) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6039 | return getStandardView(layoutId, null); |
| 6040 | } |
| 6041 | |
| 6042 | /** |
| 6043 | * Get the standard view for this style. |
| 6044 | * |
| 6045 | * @param layoutId The layout id to use |
| 6046 | * @param result The result where template bind information is saved. |
| 6047 | * @return A remoteView for this style. |
| 6048 | * @hide |
| 6049 | */ |
| 6050 | protected RemoteViews getStandardView(int layoutId, TemplateBindResult result) { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6051 | checkBuilder(); |
| 6052 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6053 | // Nasty. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6054 | CharSequence oldBuilderContentTitle = |
| 6055 | mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6056 | if (mBigContentTitle != null) { |
| 6057 | mBuilder.setContentTitle(mBigContentTitle); |
| 6058 | } |
| 6059 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6060 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId, result); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6061 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6062 | mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6063 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6064 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 6065 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 6066 | } else { |
| 6067 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6068 | } |
| 6069 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6070 | return contentView; |
| 6071 | } |
| 6072 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6073 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6074 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6075 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6076 | * |
| 6077 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6078 | * @hide |
| 6079 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6080 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6081 | return null; |
| 6082 | } |
| 6083 | |
| 6084 | /** |
| 6085 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 6086 | * @hide |
| 6087 | */ |
| 6088 | public RemoteViews makeBigContentView() { |
| 6089 | return null; |
| 6090 | } |
| 6091 | |
| 6092 | /** |
| 6093 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6094 | * |
| 6095 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6096 | * @hide |
| 6097 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6098 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6099 | return null; |
| 6100 | } |
| 6101 | |
| 6102 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6103 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6104 | * @hide |
| 6105 | */ |
| 6106 | public void addExtras(Bundle extras) { |
| 6107 | if (mSummaryTextSet) { |
| 6108 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 6109 | } |
| 6110 | if (mBigContentTitle != null) { |
| 6111 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 6112 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 6113 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6114 | } |
| 6115 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6116 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6117 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6118 | * @hide |
| 6119 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6120 | protected void restoreFromExtras(Bundle extras) { |
| 6121 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 6122 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 6123 | mSummaryTextSet = true; |
| 6124 | } |
| 6125 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 6126 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 6127 | } |
| 6128 | } |
| 6129 | |
| 6130 | |
| 6131 | /** |
| 6132 | * @hide |
| 6133 | */ |
| 6134 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6135 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6136 | return wip; |
| 6137 | } |
| 6138 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6139 | /** |
| 6140 | * @hide |
| 6141 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6142 | public void purgeResources() {} |
| 6143 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6144 | /** |
| 6145 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 6146 | * attached to. |
| 6147 | * |
| 6148 | * @return the fully constructed Notification. |
| 6149 | */ |
| 6150 | public Notification build() { |
| 6151 | checkBuilder(); |
| 6152 | return mBuilder.build(); |
| 6153 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6154 | |
| 6155 | /** |
| 6156 | * @hide |
| 6157 | * @return true if the style positions the progress bar on the second line; false if the |
| 6158 | * style hides the progress bar |
| 6159 | */ |
| 6160 | protected boolean hasProgress() { |
| 6161 | return true; |
| 6162 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6163 | |
| 6164 | /** |
| 6165 | * @hide |
| 6166 | * @return Whether we should put the summary be put into the notification header |
| 6167 | */ |
| 6168 | public boolean hasSummaryInHeader() { |
| 6169 | return true; |
| 6170 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6171 | |
| 6172 | /** |
| 6173 | * @hide |
| 6174 | * @return Whether custom content views are displayed inline in the style |
| 6175 | */ |
| 6176 | public boolean displayCustomViewInline() { |
| 6177 | return false; |
| 6178 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6179 | |
| 6180 | /** |
| 6181 | * Reduces the image sizes contained in this style. |
| 6182 | * |
| 6183 | * @hide |
| 6184 | */ |
| 6185 | public void reduceImageSizes(Context context) { |
| 6186 | } |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6187 | |
| 6188 | /** |
| 6189 | * Validate that this style was properly composed. This is called at build time. |
| 6190 | * @hide |
| 6191 | */ |
| 6192 | public void validate(Context context) { |
| 6193 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6194 | |
| 6195 | /** |
| 6196 | * @hide |
| 6197 | */ |
| 6198 | public abstract boolean areNotificationsVisiblyDifferent(Style other); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 6199 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6200 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6201 | * @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] | 6202 | * If {@code null} is returned, the default implementation will be used. |
| 6203 | * |
| 6204 | * @hide |
| 6205 | */ |
| 6206 | public CharSequence getHeadsUpStatusBarText() { |
| 6207 | return null; |
| 6208 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 6209 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6210 | |
| 6211 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6212 | * 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] | 6213 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6214 | * 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] | 6215 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6216 | * Notification notif = new Notification.Builder(mContext) |
| 6217 | * .setContentTitle("New photo from " + sender.toString()) |
| 6218 | * .setContentText(subject) |
| 6219 | * .setSmallIcon(R.drawable.new_post) |
| 6220 | * .setLargeIcon(aBitmap) |
| 6221 | * .setStyle(new Notification.BigPictureStyle() |
| 6222 | * .bigPicture(aBigBitmap)) |
| 6223 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6224 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6225 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6226 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6227 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6228 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6229 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6230 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6231 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6232 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6233 | public BigPictureStyle() { |
| 6234 | } |
| 6235 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6236 | /** |
| 6237 | * @deprecated use {@code BigPictureStyle()}. |
| 6238 | */ |
| 6239 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6240 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6241 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6242 | } |
| 6243 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6244 | /** |
| 6245 | * Overrides ContentTitle in the big form of the template. |
| 6246 | * This defaults to the value passed to setContentTitle(). |
| 6247 | */ |
| 6248 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6249 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6250 | return this; |
| 6251 | } |
| 6252 | |
| 6253 | /** |
| 6254 | * Set the first line of text after the detail section in the big form of the template. |
| 6255 | */ |
| 6256 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6257 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6258 | return this; |
| 6259 | } |
| 6260 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6261 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6262 | * @hide |
| 6263 | */ |
| 6264 | public Bitmap getBigPicture() { |
| 6265 | return mPicture; |
| 6266 | } |
| 6267 | |
| 6268 | /** |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6269 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 6270 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6271 | public BigPictureStyle bigPicture(Bitmap b) { |
| 6272 | mPicture = b; |
| 6273 | return this; |
| 6274 | } |
| 6275 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6276 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6277 | * Override the large icon when the big notification is shown. |
| 6278 | */ |
| 6279 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6280 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 6281 | } |
| 6282 | |
| 6283 | /** |
| 6284 | * Override the large icon when the big notification is shown. |
| 6285 | */ |
| 6286 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6287 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6288 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6289 | return this; |
| 6290 | } |
| 6291 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6292 | /** @hide */ |
| 6293 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 6294 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6295 | /** |
| 6296 | * @hide |
| 6297 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6298 | @Override |
| 6299 | public void purgeResources() { |
| 6300 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 6301 | if (mPicture != null && |
| 6302 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6303 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6304 | mPicture = mPicture.createAshmemBitmap(); |
| 6305 | } |
| 6306 | if (mBigLargeIcon != null) { |
| 6307 | mBigLargeIcon.convertToAshmem(); |
| 6308 | } |
| 6309 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6310 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6311 | /** |
| 6312 | * @hide |
| 6313 | */ |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6314 | @Override |
| 6315 | public void reduceImageSizes(Context context) { |
| 6316 | super.reduceImageSizes(context); |
| 6317 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6318 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6319 | if (mPicture != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6320 | int maxPictureWidth = resources.getDimensionPixelSize(isLowRam |
| 6321 | ? R.dimen.notification_big_picture_max_height_low_ram |
| 6322 | : R.dimen.notification_big_picture_max_height); |
| 6323 | int maxPictureHeight = resources.getDimensionPixelSize(isLowRam |
| 6324 | ? R.dimen.notification_big_picture_max_width_low_ram |
| 6325 | : R.dimen.notification_big_picture_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6326 | mPicture = Icon.scaleDownIfNecessary(mPicture, maxPictureWidth, maxPictureHeight); |
| 6327 | } |
| 6328 | if (mBigLargeIcon != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6329 | int rightIconSize = resources.getDimensionPixelSize(isLowRam |
| 6330 | ? R.dimen.notification_right_icon_size_low_ram |
| 6331 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6332 | mBigLargeIcon.scaleDownIfNecessary(rightIconSize, rightIconSize); |
| 6333 | } |
| 6334 | } |
| 6335 | |
| 6336 | /** |
| 6337 | * @hide |
| 6338 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6339 | public RemoteViews makeBigContentView() { |
| 6340 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6341 | // This covers the following cases: |
| 6342 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6343 | // mN.mLargeIcon |
| 6344 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6345 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6346 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6347 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6348 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 6349 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6350 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 6351 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 6352 | // for old listeners, this is in general non-null. |
| 6353 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 6354 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6355 | } |
| 6356 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6357 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource(), |
| 6358 | null /* result */); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6359 | if (mSummaryTextSet) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6360 | contentView.setTextViewText(R.id.text, mBuilder.processTextSpans( |
| 6361 | mBuilder.processLegacyText(mSummaryText))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6362 | mBuilder.setTextViewColorSecondary(contentView, R.id.text); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 6363 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6364 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6365 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 6366 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6367 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6368 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6369 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6370 | } |
| 6371 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6372 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6373 | return contentView; |
| 6374 | } |
| 6375 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6376 | /** |
| 6377 | * @hide |
| 6378 | */ |
| 6379 | public void addExtras(Bundle extras) { |
| 6380 | super.addExtras(extras); |
| 6381 | |
| 6382 | if (mBigLargeIconSet) { |
| 6383 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 6384 | } |
| 6385 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 6386 | } |
| 6387 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6388 | /** |
| 6389 | * @hide |
| 6390 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6391 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6392 | protected void restoreFromExtras(Bundle extras) { |
| 6393 | super.restoreFromExtras(extras); |
| 6394 | |
| 6395 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6396 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6397 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6398 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6399 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 6400 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6401 | |
| 6402 | /** |
| 6403 | * @hide |
| 6404 | */ |
| 6405 | @Override |
| 6406 | public boolean hasSummaryInHeader() { |
| 6407 | return false; |
| 6408 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6409 | |
| 6410 | /** |
| 6411 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6412 | * Note that we aren't actually comparing the contents of the bitmaps here, so this |
| 6413 | * 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] | 6414 | */ |
| 6415 | @Override |
| 6416 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6417 | if (other == null || getClass() != other.getClass()) { |
| 6418 | return true; |
| 6419 | } |
| 6420 | BigPictureStyle otherS = (BigPictureStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6421 | return areBitmapsObviouslyDifferent(getBigPicture(), otherS.getBigPicture()); |
| 6422 | } |
| 6423 | |
| 6424 | private static boolean areBitmapsObviouslyDifferent(Bitmap a, Bitmap b) { |
| 6425 | if (a == b) { |
| 6426 | return false; |
| 6427 | } |
| 6428 | if (a == null || b == null) { |
| 6429 | return true; |
| 6430 | } |
| 6431 | return a.getWidth() != b.getWidth() |
| 6432 | || a.getHeight() != b.getHeight() |
| 6433 | || a.getConfig() != b.getConfig() |
| 6434 | || a.getGenerationId() != b.getGenerationId(); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6435 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6439 | * 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] | 6440 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6441 | * 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] | 6442 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6443 | * Notification notif = new Notification.Builder(mContext) |
| 6444 | * .setContentTitle("New mail from " + sender.toString()) |
| 6445 | * .setContentText(subject) |
| 6446 | * .setSmallIcon(R.drawable.new_mail) |
| 6447 | * .setLargeIcon(aBitmap) |
| 6448 | * .setStyle(new Notification.BigTextStyle() |
| 6449 | * .bigText(aVeryLongString)) |
| 6450 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6451 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6452 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6453 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6454 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6455 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6456 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6457 | private CharSequence mBigText; |
| 6458 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6459 | public BigTextStyle() { |
| 6460 | } |
| 6461 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6462 | /** |
| 6463 | * @deprecated use {@code BigTextStyle()}. |
| 6464 | */ |
| 6465 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6466 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6467 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6468 | } |
| 6469 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6470 | /** |
| 6471 | * Overrides ContentTitle in the big form of the template. |
| 6472 | * This defaults to the value passed to setContentTitle(). |
| 6473 | */ |
| 6474 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6475 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6476 | return this; |
| 6477 | } |
| 6478 | |
| 6479 | /** |
| 6480 | * Set the first line of text after the detail section in the big form of the template. |
| 6481 | */ |
| 6482 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6483 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6484 | return this; |
| 6485 | } |
| 6486 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6487 | /** |
| 6488 | * Provide the longer text to be displayed in the big form of the |
| 6489 | * template in place of the content text. |
| 6490 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6491 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6492 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6493 | return this; |
| 6494 | } |
| 6495 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6496 | /** |
| 6497 | * @hide |
| 6498 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6499 | public CharSequence getBigText() { |
| 6500 | return mBigText; |
| 6501 | } |
| 6502 | |
| 6503 | /** |
| 6504 | * @hide |
| 6505 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6506 | public void addExtras(Bundle extras) { |
| 6507 | super.addExtras(extras); |
| 6508 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6509 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 6510 | } |
| 6511 | |
| 6512 | /** |
| 6513 | * @hide |
| 6514 | */ |
| 6515 | @Override |
| 6516 | protected void restoreFromExtras(Bundle extras) { |
| 6517 | super.restoreFromExtras(extras); |
| 6518 | |
| 6519 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6520 | } |
| 6521 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6522 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6523 | * @param increasedHeight true if this layout be created with an increased height. |
| 6524 | * |
| 6525 | * @hide |
| 6526 | */ |
| 6527 | @Override |
| 6528 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6529 | if (increasedHeight) { |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6530 | mBuilder.mOriginalActions = mBuilder.mActions; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6531 | mBuilder.mActions = new ArrayList<>(); |
| 6532 | RemoteViews remoteViews = makeBigContentView(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6533 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6534 | mBuilder.mOriginalActions = null; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6535 | return remoteViews; |
| 6536 | } |
| 6537 | return super.makeContentView(increasedHeight); |
| 6538 | } |
| 6539 | |
| 6540 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6541 | * @hide |
| 6542 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6543 | @Override |
| 6544 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 6545 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 6546 | return makeBigContentView(); |
| 6547 | } |
| 6548 | return super.makeHeadsUpContentView(increasedHeight); |
| 6549 | } |
| 6550 | |
| 6551 | /** |
| 6552 | * @hide |
| 6553 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6554 | public RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6555 | |
| 6556 | // Nasty |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6557 | CharSequence text = mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6558 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 6559 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6560 | TemplateBindResult result = new TemplateBindResult(); |
| 6561 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource(), result); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 6562 | contentView.setInt(R.id.big_text, "setImageEndMargin", result.getIconMarginEnd()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6563 | |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6564 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, text); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6565 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 6566 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6567 | if (TextUtils.isEmpty(bigTextText)) { |
| 6568 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 6569 | // experience |
| 6570 | bigTextText = mBuilder.processLegacyText(text); |
| 6571 | } |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6572 | applyBigTextContentView(mBuilder, contentView, bigTextText); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 6573 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6574 | return contentView; |
| 6575 | } |
| 6576 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6577 | /** |
| 6578 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6579 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6580 | */ |
| 6581 | @Override |
| 6582 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6583 | if (other == null || getClass() != other.getClass()) { |
| 6584 | return true; |
| 6585 | } |
| 6586 | BigTextStyle newS = (BigTextStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6587 | return !Objects.equals(String.valueOf(getBigText()), String.valueOf(newS.getBigText())); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6588 | } |
| 6589 | |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6590 | static void applyBigTextContentView(Builder builder, |
| 6591 | RemoteViews contentView, CharSequence bigTextText) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6592 | contentView.setTextViewText(R.id.big_text, builder.processTextSpans(bigTextText)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6593 | builder.setTextViewColorSecondary(contentView, R.id.big_text); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6594 | contentView.setViewVisibility(R.id.big_text, |
| 6595 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6596 | contentView.setBoolean(R.id.big_text, "setHasImage", builder.mN.hasLargeIcon()); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6597 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6598 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6599 | |
| 6600 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6601 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 6602 | * messages of varying types between any number of people. |
| 6603 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6604 | * <p> |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6605 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 6606 | * user will always see the normal notification view. |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6607 | * |
| 6608 | * <p> |
| 6609 | * If the app is targeting Android P and above, it is required to use the {@link Person} |
| 6610 | * class in order to get an optimal rendering of the notification and its avatars. For |
| 6611 | * conversations involving multiple people, the app should also make sure that it marks the |
| 6612 | * conversation as a group with {@link #setGroupConversation(boolean)}. |
| 6613 | * |
| 6614 | * <p> |
| 6615 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior. |
| 6616 | * Here's an example of how this may be used: |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6617 | * <pre class="prettyprint"> |
| 6618 | * |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6619 | * Person user = new Person.Builder().setIcon(userIcon).setName(userName).build(); |
| 6620 | * MessagingStyle style = new MessagingStyle(user) |
| 6621 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getPerson()) |
| 6622 | * .addMessage(messages[2].getText(), messages[2].getTime(), messages[2].getPerson()) |
| 6623 | * .setGroupConversation(hasMultiplePeople()); |
| 6624 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6625 | * Notification noti = new Notification.Builder() |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6626 | * .setContentTitle("2 new messages with " + sender.toString()) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6627 | * .setContentText(subject) |
| 6628 | * .setSmallIcon(R.drawable.new_message) |
| 6629 | * .setLargeIcon(aBitmap) |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6630 | * .setStyle(style) |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6631 | * .build(); |
| 6632 | * </pre> |
| 6633 | */ |
| 6634 | public static class MessagingStyle extends Style { |
| 6635 | |
| 6636 | /** |
| 6637 | * The maximum number of messages that will be retained in the Notification itself (the |
| 6638 | * number displayed is up to the platform). |
| 6639 | */ |
| 6640 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 6641 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6642 | @NonNull Person mUser; |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6643 | @Nullable CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6644 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6645 | List<Message> mHistoricMessages = new ArrayList<>(); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6646 | boolean mIsGroupConversation; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6647 | |
| 6648 | MessagingStyle() { |
| 6649 | } |
| 6650 | |
| 6651 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6652 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 6653 | * user before the posting app reposts the notification with those messages after they've |
| 6654 | * 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] | 6655 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6656 | * |
| 6657 | * @deprecated use {@code MessagingStyle(Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6658 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6659 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6660 | this(new Person.Builder().setName(userDisplayName).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6661 | } |
| 6662 | |
| 6663 | /** |
| 6664 | * @param user Required - The person displayed for any messages that are sent by the |
| 6665 | * user. Any messages added with {@link #addMessage(Notification.MessagingStyle.Message)} |
| 6666 | * 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] | 6667 | * by this user. The user also needs to have a valid name associated with it, which will |
| 6668 | * be enforced starting in Android P. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6669 | */ |
| 6670 | public MessagingStyle(@NonNull Person user) { |
| 6671 | mUser = user; |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6672 | } |
| 6673 | |
| 6674 | /** |
| 6675 | * Validate that this style was properly composed. This is called at build time. |
| 6676 | * @hide |
| 6677 | */ |
| 6678 | @Override |
| 6679 | public void validate(Context context) { |
| 6680 | super.validate(context); |
| 6681 | if (context.getApplicationInfo().targetSdkVersion |
| 6682 | >= Build.VERSION_CODES.P && (mUser == null || mUser.getName() == null)) { |
| 6683 | throw new RuntimeException("User must be valid and have a name."); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6684 | } |
| 6685 | } |
| 6686 | |
| 6687 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 6688 | * @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] | 6689 | * If {@code null} is returned, the default implementation will be used. |
| 6690 | * |
| 6691 | * @hide |
| 6692 | */ |
| 6693 | @Override |
| 6694 | public CharSequence getHeadsUpStatusBarText() { |
| 6695 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
| 6696 | ? super.mBigContentTitle |
| 6697 | : mConversationTitle; |
| 6698 | if (!TextUtils.isEmpty(conversationTitle) && !hasOnlyWhiteSpaceSenders()) { |
| 6699 | return conversationTitle; |
| 6700 | } |
| 6701 | return null; |
| 6702 | } |
| 6703 | |
| 6704 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6705 | * @return the user to be displayed for any replies sent by the user |
| 6706 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6707 | @NonNull |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6708 | public Person getUser() { |
| 6709 | return mUser; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6710 | } |
| 6711 | |
| 6712 | /** |
| 6713 | * 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] | 6714 | * |
| 6715 | * @deprecated use {@link #getUser()} instead |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6716 | */ |
| 6717 | public CharSequence getUserDisplayName() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6718 | return mUser.getName(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6722 | * Sets the title to be displayed on this conversation. May be set to {@code null}. |
| 6723 | * |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6724 | * <p>This API's behavior was changed in SDK version {@link Build.VERSION_CODES#P}. If your |
| 6725 | * application's target version is less than {@link Build.VERSION_CODES#P}, setting a |
| 6726 | * conversation title to a non-null value will make {@link #isGroupConversation()} return |
| 6727 | * {@code true} and passing {@code null} will make it return {@code false}. In |
| 6728 | * {@link Build.VERSION_CODES#P} and beyond, use {@link #setGroupConversation(boolean)} |
| 6729 | * to set group conversation status. |
| 6730 | * |
| 6731 | * @param conversationTitle Title displayed for this conversation |
| 6732 | * @return this object for method chaining |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6733 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6734 | public MessagingStyle setConversationTitle(@Nullable CharSequence conversationTitle) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6735 | mConversationTitle = conversationTitle; |
| 6736 | return this; |
| 6737 | } |
| 6738 | |
| 6739 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6740 | * 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] | 6741 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6742 | @Nullable |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6743 | public CharSequence getConversationTitle() { |
| 6744 | return mConversationTitle; |
| 6745 | } |
| 6746 | |
| 6747 | /** |
| 6748 | * Adds a message for display by this notification. Convenience call for a simple |
| 6749 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6750 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6751 | * @param timestamp Time at which the message arrived |
| 6752 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 6753 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 6754 | * the platform will insert {@link #getUserDisplayName()}. |
| 6755 | * Should be unique amongst all individuals in the conversation, and should be |
| 6756 | * consistent during re-posts of the notification. |
| 6757 | * |
| 6758 | * @see Message#Message(CharSequence, long, CharSequence) |
| 6759 | * |
| 6760 | * @return this object for method chaining |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6761 | * |
| 6762 | * @deprecated use {@link #addMessage(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6763 | */ |
| 6764 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6765 | return addMessage(text, timestamp, |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6766 | sender == null ? null : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6767 | } |
| 6768 | |
| 6769 | /** |
| 6770 | * Adds a message for display by this notification. Convenience call for a simple |
| 6771 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6772 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6773 | * @param timestamp Time at which the message arrived |
| 6774 | * @param sender The {@link Person} who sent the message. |
| 6775 | * Should be <code>null</code> for messages by the current user, in which case |
| 6776 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 6777 | * |
| 6778 | * @see Message#Message(CharSequence, long, CharSequence) |
| 6779 | * |
| 6780 | * @return this object for method chaining |
| 6781 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6782 | public MessagingStyle addMessage(@NonNull CharSequence text, long timestamp, |
| 6783 | @Nullable Person sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6784 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | /** |
| 6788 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6789 | * |
| 6790 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6791 | * the newest last. |
| 6792 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6793 | * @param message The {@link Message} to be displayed |
| 6794 | * @return this object for method chaining |
| 6795 | */ |
| 6796 | public MessagingStyle addMessage(Message message) { |
| 6797 | mMessages.add(message); |
| 6798 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 6799 | mMessages.remove(0); |
| 6800 | } |
| 6801 | return this; |
| 6802 | } |
| 6803 | |
| 6804 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6805 | * Adds a {@link Message} for historic context in this notification. |
| 6806 | * |
| 6807 | * <p>Messages should be added as historic if they are not the main subject of the |
| 6808 | * notification but may give context to a conversation. The system may choose to present |
| 6809 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 6810 | * |
| 6811 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6812 | * the newest last. |
| 6813 | * |
| 6814 | * @param message The historic {@link Message} to be added |
| 6815 | * @return this object for method chaining |
| 6816 | */ |
| 6817 | public MessagingStyle addHistoricMessage(Message message) { |
| 6818 | mHistoricMessages.add(message); |
| 6819 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 6820 | mHistoricMessages.remove(0); |
| 6821 | } |
| 6822 | return this; |
| 6823 | } |
| 6824 | |
| 6825 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6826 | * Gets the list of {@code Message} objects that represent the notification |
| 6827 | */ |
| 6828 | public List<Message> getMessages() { |
| 6829 | return mMessages; |
| 6830 | } |
| 6831 | |
| 6832 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6833 | * Gets the list of historic {@code Message}s in the notification. |
| 6834 | */ |
| 6835 | public List<Message> getHistoricMessages() { |
| 6836 | return mHistoricMessages; |
| 6837 | } |
| 6838 | |
| 6839 | /** |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 6840 | * Sets whether this conversation notification represents a group. If the app is targeting |
| 6841 | * Android P, this is required if the app wants to display the largeIcon set with |
| 6842 | * {@link Notification.Builder#setLargeIcon(Bitmap)}, otherwise it will be hidden. |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6843 | * |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6844 | * @param isGroupConversation {@code true} if the conversation represents a group, |
| 6845 | * {@code false} otherwise. |
| 6846 | * @return this object for method chaining |
| 6847 | */ |
| 6848 | public MessagingStyle setGroupConversation(boolean isGroupConversation) { |
| 6849 | mIsGroupConversation = isGroupConversation; |
| 6850 | return this; |
| 6851 | } |
| 6852 | |
| 6853 | /** |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6854 | * Returns {@code true} if this notification represents a group conversation, otherwise |
| 6855 | * {@code false}. |
| 6856 | * |
| 6857 | * <p> If the application that generated this {@link MessagingStyle} targets an SDK version |
| 6858 | * less than {@link Build.VERSION_CODES#P}, this method becomes dependent on whether or |
| 6859 | * not the conversation title is set; returning {@code true} if the conversation title is |
| 6860 | * a non-null value, or {@code false} otherwise. From {@link Build.VERSION_CODES#P} forward, |
| 6861 | * this method returns what's set by {@link #setGroupConversation(boolean)} allowing for |
| 6862 | * named, non-group conversations. |
| 6863 | * |
| 6864 | * @see #setConversationTitle(CharSequence) |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6865 | */ |
| 6866 | public boolean isGroupConversation() { |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6867 | // When target SDK version is < P, a non-null conversation title dictates if this is |
| 6868 | // as group conversation. |
| 6869 | if (mBuilder != null |
| 6870 | && mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 6871 | < Build.VERSION_CODES.P) { |
| 6872 | return mConversationTitle != null; |
| 6873 | } |
| 6874 | |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6875 | return mIsGroupConversation; |
| 6876 | } |
| 6877 | |
| 6878 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6879 | * @hide |
| 6880 | */ |
| 6881 | @Override |
| 6882 | public void addExtras(Bundle extras) { |
| 6883 | super.addExtras(extras); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6884 | if (mUser != null) { |
| 6885 | // For legacy usages |
| 6886 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUser.getName()); |
| 6887 | extras.putParcelable(EXTRA_MESSAGING_PERSON, mUser); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6888 | } |
| 6889 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6890 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6891 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6892 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 6893 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6894 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6895 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 6896 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 6897 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6898 | |
| 6899 | fixTitleAndTextExtras(extras); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6900 | extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6901 | } |
| 6902 | |
| 6903 | private void fixTitleAndTextExtras(Bundle extras) { |
| 6904 | Message m = findLatestIncomingMessage(); |
| 6905 | CharSequence text = (m == null) ? null : m.mText; |
| 6906 | CharSequence sender = m == null ? null |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6907 | : m.mSender == null || TextUtils.isEmpty(m.mSender.getName()) |
| 6908 | ? mUser.getName() : m.mSender.getName(); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6909 | CharSequence title; |
| 6910 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 6911 | if (!TextUtils.isEmpty(sender)) { |
| 6912 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 6913 | title = mBuilder.mContext.getString( |
| 6914 | com.android.internal.R.string.notification_messaging_title_template, |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6915 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(sender)); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6916 | } else { |
| 6917 | title = mConversationTitle; |
| 6918 | } |
| 6919 | } else { |
| 6920 | title = sender; |
| 6921 | } |
| 6922 | |
| 6923 | if (title != null) { |
| 6924 | extras.putCharSequence(EXTRA_TITLE, title); |
| 6925 | } |
| 6926 | if (text != null) { |
| 6927 | extras.putCharSequence(EXTRA_TEXT, text); |
| 6928 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6929 | } |
| 6930 | |
| 6931 | /** |
| 6932 | * @hide |
| 6933 | */ |
| 6934 | @Override |
| 6935 | protected void restoreFromExtras(Bundle extras) { |
| 6936 | super.restoreFromExtras(extras); |
| 6937 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6938 | mUser = extras.getParcelable(EXTRA_MESSAGING_PERSON); |
| 6939 | if (mUser == null) { |
| 6940 | CharSequence displayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6941 | mUser = new Person.Builder().setName(displayName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6942 | } |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 6943 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6944 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6945 | mMessages = Message.getMessagesFromBundleArray(messages); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6946 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6947 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6948 | mIsGroupConversation = extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6949 | } |
| 6950 | |
| 6951 | /** |
| 6952 | * @hide |
| 6953 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6954 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6955 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 6956 | mBuilder.mOriginalActions = mBuilder.mActions; |
| 6957 | mBuilder.mActions = new ArrayList<>(); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 6958 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6959 | false /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 6960 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6961 | mBuilder.mOriginalActions = null; |
| 6962 | return remoteViews; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6963 | } |
| 6964 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6965 | /** |
| 6966 | * @hide |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6967 | * Spans are ignored when comparing text for visual difference. |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6968 | */ |
| 6969 | @Override |
| 6970 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6971 | if (other == null || getClass() != other.getClass()) { |
| 6972 | return true; |
| 6973 | } |
| 6974 | MessagingStyle newS = (MessagingStyle) other; |
| 6975 | List<MessagingStyle.Message> oldMs = getMessages(); |
| 6976 | List<MessagingStyle.Message> newMs = newS.getMessages(); |
| 6977 | |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6978 | if (oldMs == null || newMs == null) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6979 | newMs = new ArrayList<>(); |
| 6980 | } |
| 6981 | |
| 6982 | int n = oldMs.size(); |
| 6983 | if (n != newMs.size()) { |
| 6984 | return true; |
| 6985 | } |
| 6986 | for (int i = 0; i < n; i++) { |
| 6987 | MessagingStyle.Message oldM = oldMs.get(i); |
| 6988 | MessagingStyle.Message newM = newMs.get(i); |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6989 | if (!Objects.equals( |
| 6990 | String.valueOf(oldM.getText()), |
| 6991 | String.valueOf(newM.getText()))) { |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6992 | return true; |
| 6993 | } |
| 6994 | if (!Objects.equals(oldM.getDataUri(), newM.getDataUri())) { |
| 6995 | return true; |
| 6996 | } |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 6997 | String oldSender = String.valueOf(oldM.getSenderPerson() == null |
| 6998 | ? oldM.getSender() |
| 6999 | : oldM.getSenderPerson().getName()); |
| 7000 | String newSender = String.valueOf(newM.getSenderPerson() == null |
| 7001 | ? newM.getSender() |
| 7002 | : newM.getSenderPerson().getName()); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7003 | if (!Objects.equals(oldSender, newSender)) { |
| 7004 | return true; |
| 7005 | } |
| 7006 | |
| 7007 | String oldKey = oldM.getSenderPerson() == null |
| 7008 | ? null : oldM.getSenderPerson().getKey(); |
| 7009 | String newKey = newM.getSenderPerson() == null |
| 7010 | ? null : newM.getSenderPerson().getKey(); |
| 7011 | if (!Objects.equals(oldKey, newKey)) { |
| 7012 | return true; |
| 7013 | } |
| 7014 | // Other fields (like timestamp) intentionally excluded |
| 7015 | } |
| 7016 | return false; |
| 7017 | } |
| 7018 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7019 | private Message findLatestIncomingMessage() { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7020 | return findLatestIncomingMessage(mMessages); |
| 7021 | } |
| 7022 | |
| 7023 | /** |
| 7024 | * @hide |
| 7025 | */ |
| 7026 | @Nullable |
| 7027 | public static Message findLatestIncomingMessage( |
| 7028 | List<Message> messages) { |
| 7029 | for (int i = messages.size() - 1; i >= 0; i--) { |
| 7030 | Message m = messages.get(i); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7031 | // Incoming messages have a non-empty sender. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7032 | if (m.mSender != null && !TextUtils.isEmpty(m.mSender.getName())) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7033 | return m; |
| 7034 | } |
| 7035 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7036 | if (!messages.isEmpty()) { |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7037 | // No incoming messages, fall back to outgoing message |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7038 | return messages.get(messages.size() - 1); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 7039 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7040 | return null; |
| 7041 | } |
| 7042 | |
| 7043 | /** |
| 7044 | * @hide |
| 7045 | */ |
| 7046 | @Override |
| 7047 | public RemoteViews makeBigContentView() { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7048 | return makeMessagingView(false /* displayImagesAtEnd */, true /* hideLargeIcon */); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7049 | } |
| 7050 | |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7051 | /** |
| 7052 | * Create a messaging layout. |
| 7053 | * |
| 7054 | * @param displayImagesAtEnd should images be displayed at the end of the content instead |
| 7055 | * of inline. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7056 | * @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] | 7057 | * @return the created remoteView. |
| 7058 | */ |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7059 | @NonNull |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7060 | private RemoteViews makeMessagingView(boolean displayImagesAtEnd, boolean hideRightIcons) { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7061 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7062 | ? super.mBigContentTitle |
| 7063 | : mConversationTitle; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7064 | boolean atLeastP = mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 7065 | >= Build.VERSION_CODES.P; |
| 7066 | boolean isOneToOne; |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7067 | CharSequence nameReplacement = null; |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7068 | Icon avatarReplacement = null; |
| 7069 | if (!atLeastP) { |
| 7070 | isOneToOne = TextUtils.isEmpty(conversationTitle); |
| 7071 | avatarReplacement = mBuilder.mN.mLargeIcon; |
| 7072 | if (hasOnlyWhiteSpaceSenders()) { |
| 7073 | isOneToOne = true; |
| 7074 | nameReplacement = conversationTitle; |
| 7075 | conversationTitle = null; |
| 7076 | } |
| 7077 | } else { |
| 7078 | isOneToOne = !isGroupConversation(); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 7079 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7080 | TemplateBindResult bindResult = new TemplateBindResult(); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 7081 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7082 | mBuilder.getMessagingLayoutResource(), |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7083 | mBuilder.mParams.reset().hasProgress(false).title(conversationTitle).text(null) |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7084 | .hideLargeIcon(hideRightIcons || isOneToOne) |
| 7085 | .hideReplyIcon(hideRightIcons) |
| 7086 | .headerTextSecondary(conversationTitle), |
| 7087 | bindResult); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7088 | addExtras(mBuilder.mN.extras); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 7089 | // also update the end margin if there is an image |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7090 | contentView.setViewLayoutMarginEnd(R.id.notification_messaging, |
| 7091 | bindResult.getIconMarginEnd()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7092 | contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 7093 | mBuilder.isColorized() ? mBuilder.getPrimaryTextColor() |
| 7094 | : mBuilder.resolveContrastColor()); |
| 7095 | contentView.setInt(R.id.status_bar_latest_event_content, "setSenderTextColor", |
| 7096 | mBuilder.getPrimaryTextColor()); |
| 7097 | contentView.setInt(R.id.status_bar_latest_event_content, "setMessageTextColor", |
| 7098 | mBuilder.getSecondaryTextColor()); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7099 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd", |
| 7100 | displayImagesAtEnd); |
Selim Cinek | ce8794f | 2018-05-23 16:46:05 -0700 | [diff] [blame] | 7101 | contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement", |
| 7102 | avatarReplacement); |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 7103 | contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement", |
| 7104 | nameReplacement); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7105 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne", |
| 7106 | isOneToOne); |
| 7107 | contentView.setBundle(R.id.status_bar_latest_event_content, "setData", |
| 7108 | mBuilder.mN.extras); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7109 | return contentView; |
| 7110 | } |
| 7111 | |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7112 | private boolean hasOnlyWhiteSpaceSenders() { |
| 7113 | for (int i = 0; i < mMessages.size(); i++) { |
| 7114 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7115 | Person sender = m.getSenderPerson(); |
| 7116 | if (sender != null && !isWhiteSpace(sender.getName())) { |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7117 | return false; |
| 7118 | } |
| 7119 | } |
| 7120 | return true; |
| 7121 | } |
| 7122 | |
| 7123 | private boolean isWhiteSpace(CharSequence sender) { |
| 7124 | if (TextUtils.isEmpty(sender)) { |
| 7125 | return true; |
| 7126 | } |
| 7127 | if (sender.toString().matches("^\\s*$")) { |
| 7128 | return true; |
| 7129 | } |
| 7130 | // Let's check if we only have 0 whitespace chars. Some apps did this as a workaround |
| 7131 | // For the presentation that we had. |
| 7132 | for (int i = 0; i < sender.length(); i++) { |
| 7133 | char c = sender.charAt(i); |
| 7134 | if (c != '\u200B') { |
| 7135 | return false; |
| 7136 | } |
| 7137 | } |
| 7138 | return true; |
| 7139 | } |
| 7140 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7141 | private CharSequence createConversationTitleFromMessages() { |
| 7142 | ArraySet<CharSequence> names = new ArraySet<>(); |
| 7143 | for (int i = 0; i < mMessages.size(); i++) { |
| 7144 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7145 | Person sender = m.getSenderPerson(); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7146 | if (sender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7147 | names.add(sender.getName()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7148 | } |
| 7149 | } |
| 7150 | SpannableStringBuilder title = new SpannableStringBuilder(); |
| 7151 | int size = names.size(); |
| 7152 | for (int i = 0; i < size; i++) { |
| 7153 | CharSequence name = names.valueAt(i); |
| 7154 | if (!TextUtils.isEmpty(title)) { |
| 7155 | title.append(", "); |
| 7156 | } |
| 7157 | title.append(BidiFormatter.getInstance().unicodeWrap(name)); |
| 7158 | } |
| 7159 | return title; |
| 7160 | } |
| 7161 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7162 | /** |
| 7163 | * @hide |
| 7164 | */ |
| 7165 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7166 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7167 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7168 | true /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7169 | remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1); |
| 7170 | return remoteViews; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7171 | } |
| 7172 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7173 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 7174 | return new TextAppearanceSpan(null, 0, 0, |
| 7175 | ColorStateList.valueOf(color), null); |
| 7176 | } |
| 7177 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7178 | public static final class Message { |
| 7179 | |
| 7180 | static final String KEY_TEXT = "text"; |
| 7181 | static final String KEY_TIMESTAMP = "time"; |
| 7182 | static final String KEY_SENDER = "sender"; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7183 | static final String KEY_SENDER_PERSON = "sender_person"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7184 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 7185 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7186 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7187 | static final String KEY_REMOTE_INPUT_HISTORY = "remote_input_history"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7188 | |
| 7189 | private final CharSequence mText; |
| 7190 | private final long mTimestamp; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7191 | @Nullable |
| 7192 | private final Person mSender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7193 | /** True if this message was generated from the extra |
| 7194 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY} |
| 7195 | */ |
| 7196 | private final boolean mRemoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7197 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7198 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7199 | private String mDataMimeType; |
| 7200 | private Uri mDataUri; |
| 7201 | |
| 7202 | /** |
| 7203 | * Constructor |
| 7204 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7205 | * @param timestamp Time at which the message arrived |
| 7206 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 7207 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 7208 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 7209 | * Should be unique amongst all individuals in the conversation, and should be |
| 7210 | * consistent during re-posts of the notification. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7211 | * |
| 7212 | * @deprecated use {@code Message(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7213 | */ |
| 7214 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7215 | this(text, timestamp, sender == null ? null |
| 7216 | : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7217 | } |
| 7218 | |
| 7219 | /** |
| 7220 | * Constructor |
| 7221 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7222 | * @param timestamp Time at which the message arrived |
| 7223 | * @param sender The {@link Person} who sent the message. |
| 7224 | * Should be <code>null</code> for messages by the current user, in which case |
| 7225 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7226 | * <p> |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7227 | * The person provided should contain an Icon, set with |
| 7228 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7229 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7230 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7231 | * to differentiate between the different users. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7232 | * </p> |
| 7233 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 7234 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7235 | this(text, timestamp, sender, false /* remoteHistory */); |
| 7236 | } |
| 7237 | |
| 7238 | /** |
| 7239 | * Constructor |
| 7240 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7241 | * @param timestamp Time at which the message arrived |
| 7242 | * @param sender The {@link Person} who sent the message. |
| 7243 | * Should be <code>null</code> for messages by the current user, in which case |
| 7244 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7245 | * @param remoteInputHistory True if the messages was generated from the extra |
| 7246 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7247 | * <p> |
| 7248 | * The person provided should contain an Icon, set with |
| 7249 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7250 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7251 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7252 | * to differentiate between the different users. |
| 7253 | * </p> |
| 7254 | * @hide |
| 7255 | */ |
| 7256 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender, |
| 7257 | boolean remoteInputHistory) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7258 | mText = text; |
| 7259 | mTimestamp = timestamp; |
| 7260 | mSender = sender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7261 | mRemoteInputHistory = remoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7262 | } |
| 7263 | |
| 7264 | /** |
| 7265 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 7266 | * where the platform doesn't support the MIME type, the original text provided in the |
| 7267 | * constructor will be used. |
| 7268 | * @param dataMimeType The MIME type of the content. See |
| 7269 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 7270 | * types on Android and Android Wear. |
| 7271 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 7272 | * <p class="note"> |
| 7273 | * <ol> |
| 7274 | * <li>Notification Listeners including the System UI need permission to access the |
| 7275 | * data the Uri points to. The recommended ways to do this are:</li> |
| 7276 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 7277 | * the correct permission to access your provider. The preferred mechanism for |
| 7278 | * providing access is to use per-URI permissions which are temporary and only |
| 7279 | * grant access to the receiving application. An easy way to create a |
| 7280 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 7281 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 7282 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 7283 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 7284 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 7285 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 7286 | * Note that once added to the system MediaStore the content is accessible to any |
| 7287 | * app on the device.</li> |
| 7288 | * </ol> |
| 7289 | * @return this object for method chaining |
| 7290 | */ |
| 7291 | public Message setData(String dataMimeType, Uri dataUri) { |
| 7292 | mDataMimeType = dataMimeType; |
| 7293 | mDataUri = dataUri; |
| 7294 | return this; |
| 7295 | } |
| 7296 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7297 | /** |
| 7298 | * Get the text to be used for this message, or the fallback text if a type and content |
| 7299 | * Uri have been set |
| 7300 | */ |
| 7301 | public CharSequence getText() { |
| 7302 | return mText; |
| 7303 | } |
| 7304 | |
| 7305 | /** |
| 7306 | * Get the time at which this message arrived |
| 7307 | */ |
| 7308 | public long getTimestamp() { |
| 7309 | return mTimestamp; |
| 7310 | } |
| 7311 | |
| 7312 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7313 | * Get the extras Bundle for this message. |
| 7314 | */ |
| 7315 | public Bundle getExtras() { |
| 7316 | return mExtras; |
| 7317 | } |
| 7318 | |
| 7319 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7320 | * 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] | 7321 | * |
| 7322 | * @deprecated use {@link #getSenderPerson()} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7323 | */ |
| 7324 | public CharSequence getSender() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7325 | return mSender == null ? null : mSender.getName(); |
| 7326 | } |
| 7327 | |
| 7328 | /** |
| 7329 | * Get the sender associated with this message. |
| 7330 | */ |
| 7331 | @Nullable |
| 7332 | public Person getSenderPerson() { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7333 | return mSender; |
| 7334 | } |
| 7335 | |
| 7336 | /** |
| 7337 | * Get the MIME type of the data pointed to by the Uri |
| 7338 | */ |
| 7339 | public String getDataMimeType() { |
| 7340 | return mDataMimeType; |
| 7341 | } |
| 7342 | |
| 7343 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 7344 | * 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] | 7345 | * {@see #getText()} is used. |
| 7346 | */ |
| 7347 | public Uri getDataUri() { |
| 7348 | return mDataUri; |
| 7349 | } |
| 7350 | |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7351 | /** |
| 7352 | * @return True if the message was generated from |
| 7353 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7354 | * @hide |
| 7355 | */ |
| 7356 | public boolean isRemoteInputHistory() { |
| 7357 | return mRemoteInputHistory; |
| 7358 | } |
| 7359 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7360 | private Bundle toBundle() { |
| 7361 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7362 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7363 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7364 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7365 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7366 | if (mSender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7367 | // Legacy listeners need this |
| 7368 | bundle.putCharSequence(KEY_SENDER, mSender.getName()); |
| 7369 | bundle.putParcelable(KEY_SENDER_PERSON, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7370 | } |
| 7371 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7372 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7373 | } |
| 7374 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7375 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7376 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7377 | if (mExtras != null) { |
| 7378 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 7379 | } |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7380 | if (mRemoteInputHistory) { |
| 7381 | bundle.putBoolean(KEY_REMOTE_INPUT_HISTORY, mRemoteInputHistory); |
| 7382 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7383 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7384 | } |
| 7385 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7386 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 7387 | Bundle[] bundles = new Bundle[messages.size()]; |
| 7388 | final int N = messages.size(); |
| 7389 | for (int i = 0; i < N; i++) { |
| 7390 | bundles[i] = messages.get(i).toBundle(); |
| 7391 | } |
| 7392 | return bundles; |
| 7393 | } |
| 7394 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7395 | /** |
| 7396 | * @return A list of messages read from the bundles. |
| 7397 | * |
| 7398 | * @hide |
| 7399 | */ |
| 7400 | public static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
| 7401 | if (bundles == null) { |
| 7402 | return new ArrayList<>(); |
| 7403 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7404 | List<Message> messages = new ArrayList<>(bundles.length); |
| 7405 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7406 | if (bundles[i] instanceof Bundle) { |
| 7407 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 7408 | if (message != null) { |
| 7409 | messages.add(message); |
| 7410 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7411 | } |
| 7412 | } |
| 7413 | return messages; |
| 7414 | } |
| 7415 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 7416 | /** |
| 7417 | * @return The message that is stored in the bundle or null if the message couldn't be |
| 7418 | * resolved. |
| 7419 | * |
| 7420 | * @hide |
| 7421 | */ |
| 7422 | @Nullable |
| 7423 | public static Message getMessageFromBundle(Bundle bundle) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7424 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 7425 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7426 | return null; |
| 7427 | } else { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7428 | |
| 7429 | Person senderPerson = bundle.getParcelable(KEY_SENDER_PERSON); |
| 7430 | if (senderPerson == null) { |
| 7431 | // Legacy apps that use compat don't actually provide the sender objects |
| 7432 | // We need to fix the compat version to provide people / use |
| 7433 | // the native api instead |
| 7434 | CharSequence senderName = bundle.getCharSequence(KEY_SENDER); |
| 7435 | if (senderName != null) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7436 | senderPerson = new Person.Builder().setName(senderName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7437 | } |
| 7438 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7439 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7440 | bundle.getLong(KEY_TIMESTAMP), |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7441 | senderPerson, |
| 7442 | bundle.getBoolean(KEY_REMOTE_INPUT_HISTORY, false)); |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7443 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 7444 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7445 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 7446 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7447 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7448 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 7449 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 7450 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7451 | return message; |
| 7452 | } |
| 7453 | } catch (ClassCastException e) { |
| 7454 | return null; |
| 7455 | } |
| 7456 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7457 | } |
| 7458 | } |
| 7459 | |
| 7460 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7461 | * 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] | 7462 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7463 | * 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] | 7464 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7465 | * Notification notif = new Notification.Builder(mContext) |
| 7466 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 7467 | * .setContentText(subject) |
| 7468 | * .setSmallIcon(R.drawable.new_mail) |
| 7469 | * .setLargeIcon(aBitmap) |
| 7470 | * .setStyle(new Notification.InboxStyle() |
| 7471 | * .addLine(str1) |
| 7472 | * .addLine(str2) |
| 7473 | * .setContentTitle("") |
| 7474 | * .setSummaryText("+3 more")) |
| 7475 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7476 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 7477 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7478 | * @see Notification#bigContentView |
| 7479 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7480 | public static class InboxStyle extends Style { |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7481 | |
| 7482 | /** |
| 7483 | * The number of lines of remote input history allowed until we start reducing lines. |
| 7484 | */ |
| 7485 | private static final int NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION = 1; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7486 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 7487 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7488 | public InboxStyle() { |
| 7489 | } |
| 7490 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7491 | /** |
| 7492 | * @deprecated use {@code InboxStyle()}. |
| 7493 | */ |
| 7494 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7495 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7496 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7497 | } |
| 7498 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7499 | /** |
| 7500 | * Overrides ContentTitle in the big form of the template. |
| 7501 | * This defaults to the value passed to setContentTitle(). |
| 7502 | */ |
| 7503 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7504 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7505 | return this; |
| 7506 | } |
| 7507 | |
| 7508 | /** |
| 7509 | * Set the first line of text after the detail section in the big form of the template. |
| 7510 | */ |
| 7511 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7512 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7513 | return this; |
| 7514 | } |
| 7515 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 7516 | /** |
| 7517 | * Append a line to the digest section of the Inbox notification. |
| 7518 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7519 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7520 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7521 | return this; |
| 7522 | } |
| 7523 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7524 | /** |
| 7525 | * @hide |
| 7526 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7527 | public ArrayList<CharSequence> getLines() { |
| 7528 | return mTexts; |
| 7529 | } |
| 7530 | |
| 7531 | /** |
| 7532 | * @hide |
| 7533 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7534 | public void addExtras(Bundle extras) { |
| 7535 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7536 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7537 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 7538 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 7539 | } |
| 7540 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7541 | /** |
| 7542 | * @hide |
| 7543 | */ |
| 7544 | @Override |
| 7545 | protected void restoreFromExtras(Bundle extras) { |
| 7546 | super.restoreFromExtras(extras); |
| 7547 | |
| 7548 | mTexts.clear(); |
| 7549 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 7550 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 7551 | } |
| 7552 | } |
| 7553 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7554 | /** |
| 7555 | * @hide |
| 7556 | */ |
| 7557 | public RemoteViews makeBigContentView() { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 7558 | // Remove the content text so it disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7559 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7560 | CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT); |
| 7561 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7562 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7563 | TemplateBindResult result = new TemplateBindResult(); |
| 7564 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource(), result); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 7565 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7566 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7567 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7568 | 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] | 7569 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7570 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 7571 | // Make sure all rows are gone in case we reuse a view. |
| 7572 | for (int rowId : rowIds) { |
| 7573 | contentView.setViewVisibility(rowId, View.GONE); |
| 7574 | } |
| 7575 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7576 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7577 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7578 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7579 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7580 | int onlyViewId = 0; |
| 7581 | int maxRows = rowIds.length; |
| 7582 | if (mBuilder.mActions.size() > 0) { |
| 7583 | maxRows--; |
| 7584 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 7585 | CharSequence[] remoteInputHistory = mBuilder.mN.extras.getCharSequenceArray( |
| 7586 | EXTRA_REMOTE_INPUT_HISTORY); |
| 7587 | if (remoteInputHistory != null |
| 7588 | && remoteInputHistory.length > NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION) { |
| 7589 | // Let's remove some messages to make room for the remote input history. |
| 7590 | // 1 is always able to fit, but let's remove them if they are 2 or 3 |
| 7591 | int numRemoteInputs = Math.min(remoteInputHistory.length, |
| 7592 | MAX_REMOTE_INPUT_HISTORY_LINES); |
| 7593 | int totalNumRows = mTexts.size() + numRemoteInputs |
| 7594 | - NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION; |
| 7595 | if (totalNumRows > maxRows) { |
| 7596 | int overflow = totalNumRows - maxRows; |
| 7597 | if (mTexts.size() > maxRows) { |
| 7598 | // Heuristic: if the Texts don't fit anyway, we'll rather drop the last |
| 7599 | // few messages, even with the remote input |
| 7600 | maxRows -= overflow; |
| 7601 | } else { |
| 7602 | // otherwise we drop the first messages |
| 7603 | i = overflow; |
| 7604 | } |
| 7605 | } |
| 7606 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7607 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7608 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7609 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7610 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 7611 | contentView.setTextViewText(rowIds[i], |
| 7612 | mBuilder.processTextSpans(mBuilder.processLegacyText(str))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 7613 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i]); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7614 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7615 | handleInboxImageMargin(contentView, rowIds[i], first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7616 | result.getIconMarginEnd()); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7617 | if (first) { |
| 7618 | onlyViewId = rowIds[i]; |
| 7619 | } else { |
| 7620 | onlyViewId = 0; |
| 7621 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7622 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7623 | } |
| 7624 | i++; |
| 7625 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7626 | if (onlyViewId != 0) { |
| 7627 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 7628 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7629 | R.dimen.notification_text_margin_top); |
| 7630 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 7631 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7632 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7633 | return contentView; |
| 7634 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7635 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7636 | /** |
| 7637 | * @hide |
| 7638 | */ |
| 7639 | @Override |
| 7640 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7641 | if (other == null || getClass() != other.getClass()) { |
| 7642 | return true; |
| 7643 | } |
| 7644 | InboxStyle newS = (InboxStyle) other; |
Dan Sandler | 7d67bd4 | 2018-05-15 14:06:38 -0400 | [diff] [blame] | 7645 | |
| 7646 | final ArrayList<CharSequence> myLines = getLines(); |
| 7647 | final ArrayList<CharSequence> newLines = newS.getLines(); |
| 7648 | final int n = myLines.size(); |
| 7649 | if (n != newLines.size()) { |
| 7650 | return true; |
| 7651 | } |
| 7652 | |
| 7653 | for (int i = 0; i < n; i++) { |
| 7654 | if (!Objects.equals( |
| 7655 | String.valueOf(myLines.get(i)), |
| 7656 | String.valueOf(newLines.get(i)))) { |
| 7657 | return true; |
| 7658 | } |
| 7659 | } |
| 7660 | return false; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7661 | } |
| 7662 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7663 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7664 | int marginEndValue) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7665 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7666 | if (first) { |
| 7667 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 7668 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 7669 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7670 | if (!hasProgress) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7671 | endMargin = marginEndValue; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7672 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7673 | } |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7674 | contentView.setViewLayoutMarginEnd(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7675 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7676 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7677 | |
| 7678 | /** |
| 7679 | * Notification style for media playback notifications. |
| 7680 | * |
| 7681 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 7682 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 7683 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7684 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 7685 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 7686 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7687 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7688 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 7689 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 7690 | * {@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] | 7691 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7692 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7693 | * Notifications created with MediaStyle will have their category set to |
| 7694 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 7695 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7696 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7697 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 7698 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7699 | * the System UI can identify this as a notification representing an active media session |
| 7700 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 7701 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7702 | * <p> |
| 7703 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 7704 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 7705 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 7706 | * <p> |
| 7707 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7708 | * To use this style with your Notification, feed it to |
| 7709 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7710 | * <pre class="prettyprint"> |
| 7711 | * Notification noti = new Notification.Builder() |
| 7712 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 7713 | * .setContentTitle("Track title") |
| 7714 | * .setContentText("Artist - Album") |
| 7715 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7716 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 7717 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7718 | * .build(); |
| 7719 | * </pre> |
| 7720 | * |
| 7721 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7722 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7723 | */ |
| 7724 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7725 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7726 | static final int MAX_MEDIA_BUTTONS = 5; |
| 7727 | |
| 7728 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7729 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7730 | |
| 7731 | public MediaStyle() { |
| 7732 | } |
| 7733 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7734 | /** |
| 7735 | * @deprecated use {@code MediaStyle()}. |
| 7736 | */ |
| 7737 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7738 | public MediaStyle(Builder builder) { |
| 7739 | setBuilder(builder); |
| 7740 | } |
| 7741 | |
| 7742 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7743 | * 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] | 7744 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7745 | * |
| 7746 | * @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] | 7747 | */ |
| 7748 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 7749 | mActionsToShowInCompact = actions; |
| 7750 | return this; |
| 7751 | } |
| 7752 | |
| 7753 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7754 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 7755 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7756 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7757 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7758 | mToken = token; |
| 7759 | return this; |
| 7760 | } |
| 7761 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7762 | /** |
| 7763 | * @hide |
| 7764 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7765 | @Override |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 7766 | @UnsupportedAppUsage |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7767 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7768 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7769 | if (wip.category == null) { |
| 7770 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 7771 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7772 | return wip; |
| 7773 | } |
| 7774 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7775 | /** |
| 7776 | * @hide |
| 7777 | */ |
| 7778 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7779 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7780 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7781 | } |
| 7782 | |
| 7783 | /** |
| 7784 | * @hide |
| 7785 | */ |
| 7786 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7787 | public RemoteViews makeBigContentView() { |
| 7788 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7789 | } |
| 7790 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7791 | /** |
| 7792 | * @hide |
| 7793 | */ |
| 7794 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7795 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7796 | RemoteViews expanded = makeMediaBigContentView(); |
| 7797 | return expanded != null ? expanded : makeMediaContentView(); |
| 7798 | } |
| 7799 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7800 | /** @hide */ |
| 7801 | @Override |
| 7802 | public void addExtras(Bundle extras) { |
| 7803 | super.addExtras(extras); |
| 7804 | |
| 7805 | if (mToken != null) { |
| 7806 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 7807 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 7808 | if (mActionsToShowInCompact != null) { |
| 7809 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 7810 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7811 | } |
| 7812 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7813 | /** |
| 7814 | * @hide |
| 7815 | */ |
| 7816 | @Override |
| 7817 | protected void restoreFromExtras(Bundle extras) { |
| 7818 | super.restoreFromExtras(extras); |
| 7819 | |
| 7820 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 7821 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 7822 | } |
| 7823 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 7824 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 7825 | } |
| 7826 | } |
| 7827 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7828 | /** |
| 7829 | * @hide |
| 7830 | */ |
| 7831 | @Override |
| 7832 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7833 | if (other == null || getClass() != other.getClass()) { |
| 7834 | return true; |
| 7835 | } |
| 7836 | // All fields to compare are on the Notification object |
| 7837 | return false; |
| 7838 | } |
| 7839 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7840 | private RemoteViews generateMediaActionButton(Action action, int color) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7841 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 7842 | RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 7843 | R.layout.notification_material_media_action); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 7844 | button.setImageViewIcon(R.id.action0, action.getIcon()); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 7845 | |
| 7846 | // If the action buttons should not be tinted, then just use the default |
| 7847 | // notification color. Otherwise, just use the passed-in color. |
| 7848 | int tintColor = mBuilder.shouldTintActionButtons() || mBuilder.isColorized() |
| 7849 | ? color |
| 7850 | : NotificationColorUtil.resolveColor(mBuilder.mContext, |
| 7851 | Notification.COLOR_DEFAULT); |
| 7852 | |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 7853 | button.setDrawableTint(R.id.action0, false, tintColor, |
| 7854 | PorterDuff.Mode.SRC_ATOP); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7855 | if (!tombstone) { |
| 7856 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 7857 | } |
| 7858 | button.setContentDescription(R.id.action0, action.title); |
| 7859 | return button; |
| 7860 | } |
| 7861 | |
| 7862 | private RemoteViews makeMediaContentView() { |
| 7863 | RemoteViews view = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7864 | R.layout.notification_template_material_media, false, /* hasProgress */ |
| 7865 | null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7866 | |
| 7867 | final int numActions = mBuilder.mActions.size(); |
| 7868 | final int N = mActionsToShowInCompact == null |
| 7869 | ? 0 |
| 7870 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 7871 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7872 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7873 | for (int i = 0; i < N; i++) { |
| 7874 | if (i >= numActions) { |
| 7875 | throw new IllegalArgumentException(String.format( |
| 7876 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 7877 | i, numActions - 1)); |
| 7878 | } |
| 7879 | |
| 7880 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 7881 | final RemoteViews button = generateMediaActionButton(action, getActionColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7882 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7883 | } |
| 7884 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 7885 | handleImage(view); |
| 7886 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7887 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 7888 | if (mBuilder.mN.hasLargeIcon()) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7889 | endMargin = R.dimen.notification_media_image_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 7890 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7891 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7892 | return view; |
| 7893 | } |
| 7894 | |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 7895 | private int getActionColor() { |
| 7896 | return mBuilder.isColorized() ? mBuilder.getPrimaryTextColor() |
| 7897 | : mBuilder.resolveContrastColor(); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7898 | } |
| 7899 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7900 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7901 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7902 | // Dont add an expanded view if there is no more content to be revealed |
| 7903 | int actionsInCompact = mActionsToShowInCompact == null |
| 7904 | ? 0 |
| 7905 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 7906 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7907 | return null; |
| 7908 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7909 | RemoteViews big = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7910 | R.layout.notification_template_material_big_media, false, null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7911 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7912 | if (actionCount > 0) { |
| 7913 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 7914 | for (int i = 0; i < actionCount; i++) { |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7915 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i), |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 7916 | getActionColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7917 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7918 | } |
| 7919 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7920 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7921 | return big; |
| 7922 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7923 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7924 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 7925 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7926 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 7927 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7928 | } |
| 7929 | } |
| 7930 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7931 | /** |
| 7932 | * @hide |
| 7933 | */ |
| 7934 | @Override |
| 7935 | protected boolean hasProgress() { |
| 7936 | return false; |
| 7937 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7938 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7939 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7940 | /** |
| 7941 | * Notification style for custom views that are decorated by the system |
| 7942 | * |
| 7943 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 7944 | * style and still obtain system decorations like the notification header with the expand |
| 7945 | * affordance and actions. |
| 7946 | * |
| 7947 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 7948 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 7949 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 7950 | * corresponding custom views to display. |
| 7951 | * |
| 7952 | * To use this style with your Notification, feed it to |
| 7953 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7954 | * <pre class="prettyprint"> |
| 7955 | * Notification noti = new Notification.Builder() |
| 7956 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 7957 | * .setLargeIcon(albumArtBitmap)) |
| 7958 | * .setCustomContentView(contentView); |
| 7959 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 7960 | * .build(); |
| 7961 | * </pre> |
| 7962 | */ |
| 7963 | public static class DecoratedCustomViewStyle extends Style { |
| 7964 | |
| 7965 | public DecoratedCustomViewStyle() { |
| 7966 | } |
| 7967 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7968 | /** |
| 7969 | * @hide |
| 7970 | */ |
| 7971 | public boolean displayCustomViewInline() { |
| 7972 | return true; |
| 7973 | } |
| 7974 | |
| 7975 | /** |
| 7976 | * @hide |
| 7977 | */ |
| 7978 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7979 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7980 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 7981 | } |
| 7982 | |
| 7983 | /** |
| 7984 | * @hide |
| 7985 | */ |
| 7986 | @Override |
| 7987 | public RemoteViews makeBigContentView() { |
| 7988 | return makeDecoratedBigContentView(); |
| 7989 | } |
| 7990 | |
| 7991 | /** |
| 7992 | * @hide |
| 7993 | */ |
| 7994 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7995 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7996 | return makeDecoratedHeadsUpContentView(); |
| 7997 | } |
| 7998 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7999 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 8000 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 8001 | ? mBuilder.mN.contentView |
| 8002 | : mBuilder.mN.headsUpContentView; |
| 8003 | if (mBuilder.mActions.size() == 0) { |
| 8004 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 8005 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8006 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8007 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8008 | mBuilder.getBigBaseLayoutResource(), result); |
| 8009 | buildIntoRemoteViewContent(remoteViews, headsUpContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8010 | return remoteViews; |
| 8011 | } |
| 8012 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8013 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8014 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8015 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8016 | mBuilder.getBaseLayoutResource(), result); |
| 8017 | buildIntoRemoteViewContent(remoteViews, customContent, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8018 | return remoteViews; |
| 8019 | } |
| 8020 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8021 | private RemoteViews makeDecoratedBigContentView() { |
| 8022 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 8023 | ? mBuilder.mN.contentView |
| 8024 | : mBuilder.mN.bigContentView; |
| 8025 | if (mBuilder.mActions.size() == 0) { |
| 8026 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 8027 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8028 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8029 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8030 | mBuilder.getBigBaseLayoutResource(), result); |
| 8031 | buildIntoRemoteViewContent(remoteViews, bigContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8032 | return remoteViews; |
| 8033 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8034 | |
| 8035 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8036 | RemoteViews customContent, TemplateBindResult result) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8037 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8038 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8039 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8040 | customContent = customContent.clone(); |
Anthony Chen | 8f5f358 | 2017-04-11 11:18:37 -0700 | [diff] [blame] | 8041 | remoteViews.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress); |
| 8042 | remoteViews.addView(R.id.notification_main_column, customContent, 0 /* index */); |
Selim Cinek | fc8073c | 2017-08-16 17:50:20 -0700 | [diff] [blame] | 8043 | remoteViews.setReapplyDisallowed(); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8044 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8045 | // also update the end margin if there is an image |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8046 | Resources resources = mBuilder.mContext.getResources(); |
| 8047 | int endMargin = resources.getDimensionPixelSize( |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 8048 | R.dimen.notification_content_margin_end) + result.getIconMarginEnd(); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 8049 | remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 8050 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8051 | |
| 8052 | /** |
| 8053 | * @hide |
| 8054 | */ |
| 8055 | @Override |
| 8056 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8057 | if (other == null || getClass() != other.getClass()) { |
| 8058 | return true; |
| 8059 | } |
| 8060 | // Comparison done for all custom RemoteViews, independent of style |
| 8061 | return false; |
| 8062 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 8063 | } |
| 8064 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8065 | /** |
| 8066 | * Notification style for media custom views that are decorated by the system |
| 8067 | * |
| 8068 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 8069 | * this style and still obtain system decorations like the notification header with the expand |
| 8070 | * affordance and actions. |
| 8071 | * |
| 8072 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 8073 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 8074 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 8075 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 8076 | * <p> |
| 8077 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 8078 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 8079 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8080 | * To use this style with your Notification, feed it to |
| 8081 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 8082 | * <pre class="prettyprint"> |
| 8083 | * Notification noti = new Notification.Builder() |
| 8084 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 8085 | * .setLargeIcon(albumArtBitmap)) |
| 8086 | * .setCustomContentView(contentView); |
| 8087 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 8088 | * .setMediaSession(mySession)) |
| 8089 | * .build(); |
| 8090 | * </pre> |
| 8091 | * |
| 8092 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 8093 | * @see android.app.Notification.MediaStyle |
| 8094 | */ |
| 8095 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 8096 | |
| 8097 | public DecoratedMediaCustomViewStyle() { |
| 8098 | } |
| 8099 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8100 | /** |
| 8101 | * @hide |
| 8102 | */ |
| 8103 | public boolean displayCustomViewInline() { |
| 8104 | return true; |
| 8105 | } |
| 8106 | |
| 8107 | /** |
| 8108 | * @hide |
| 8109 | */ |
| 8110 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8111 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 8112 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8113 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8114 | mBuilder.mN.contentView); |
| 8115 | } |
| 8116 | |
| 8117 | /** |
| 8118 | * @hide |
| 8119 | */ |
| 8120 | @Override |
| 8121 | public RemoteViews makeBigContentView() { |
| 8122 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 8123 | ? mBuilder.mN.bigContentView |
| 8124 | : mBuilder.mN.contentView; |
| 8125 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8126 | } |
| 8127 | |
| 8128 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 8129 | RemoteViews remoteViews = super.makeBigContentView(); |
| 8130 | if (remoteViews != null) { |
| 8131 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 8132 | customRemoteView); |
| 8133 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 8134 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8135 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 8136 | customRemoteView); |
| 8137 | } else { |
| 8138 | return null; |
| 8139 | } |
| 8140 | } |
| 8141 | |
| 8142 | /** |
| 8143 | * @hide |
| 8144 | */ |
| 8145 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 8146 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8147 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 8148 | ? mBuilder.mN.headsUpContentView |
| 8149 | : mBuilder.mN.contentView; |
| 8150 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 8151 | } |
| 8152 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 8153 | /** |
| 8154 | * @hide |
| 8155 | */ |
| 8156 | @Override |
| 8157 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8158 | if (other == null || getClass() != other.getClass()) { |
| 8159 | return true; |
| 8160 | } |
| 8161 | // Comparison done for all custom RemoteViews, independent of style |
| 8162 | return false; |
| 8163 | } |
| 8164 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8165 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 8166 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8167 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8168 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8169 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8170 | customContent = customContent.clone(); |
Selim Cinek | 87c3153 | 2017-08-18 18:53:44 -0700 | [diff] [blame] | 8171 | customContent.overrideTextColors(mBuilder.getPrimaryTextColor()); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8172 | remoteViews.removeAllViews(id); |
| 8173 | remoteViews.addView(id, customContent); |
Selim Cinek | fc8073c | 2017-08-16 17:50:20 -0700 | [diff] [blame] | 8174 | remoteViews.setReapplyDisallowed(); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8175 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8176 | return remoteViews; |
| 8177 | } |
| 8178 | } |
| 8179 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8180 | // When adding a new Style subclass here, don't forget to update |
| 8181 | // Builder.getNotificationStyleClass. |
| 8182 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8183 | /** |
| 8184 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 8185 | * metadata or change options on a notification builder. |
| 8186 | */ |
| 8187 | public interface Extender { |
| 8188 | /** |
| 8189 | * Apply this extender to a notification builder. |
| 8190 | * @param builder the builder to be modified. |
| 8191 | * @return the build object for chaining. |
| 8192 | */ |
| 8193 | public Builder extend(Builder builder); |
| 8194 | } |
| 8195 | |
| 8196 | /** |
| 8197 | * Helper class to add wearable extensions to notifications. |
| 8198 | * <p class="note"> See |
| 8199 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 8200 | * for Android Wear</a> for more information on how to use this class. |
| 8201 | * <p> |
| 8202 | * To create a notification with wearable extensions: |
| 8203 | * <ol> |
| 8204 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 8205 | * properties. |
| 8206 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 8207 | * <li>Set wearable-specific properties using the |
| 8208 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 8209 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 8210 | * notification. |
| 8211 | * <li>Post the notification to the notification system with the |
| 8212 | * {@code NotificationManager.notify(...)} methods. |
| 8213 | * </ol> |
| 8214 | * |
| 8215 | * <pre class="prettyprint"> |
| 8216 | * Notification notif = new Notification.Builder(mContext) |
| 8217 | * .setContentTitle("New mail from " + sender.toString()) |
| 8218 | * .setContentText(subject) |
| 8219 | * .setSmallIcon(R.drawable.new_mail) |
| 8220 | * .extend(new Notification.WearableExtender() |
| 8221 | * .setContentIcon(R.drawable.new_mail)) |
| 8222 | * .build(); |
| 8223 | * NotificationManager notificationManger = |
| 8224 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 8225 | * notificationManger.notify(0, notif);</pre> |
| 8226 | * |
| 8227 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 8228 | * {@code WearableExtender(Notification)} constructor, |
| 8229 | * and then using the {@code get} methods to access values. |
| 8230 | * |
| 8231 | * <pre class="prettyprint"> |
| 8232 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 8233 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8234 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8235 | */ |
| 8236 | public static final class WearableExtender implements Extender { |
| 8237 | /** |
| 8238 | * Sentinel value for an action index that is unset. |
| 8239 | */ |
| 8240 | public static final int UNSET_ACTION_INDEX = -1; |
| 8241 | |
| 8242 | /** |
| 8243 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 8244 | * default sizing. |
| 8245 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 8246 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8247 | * on their content. |
| 8248 | */ |
| 8249 | public static final int SIZE_DEFAULT = 0; |
| 8250 | |
| 8251 | /** |
| 8252 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8253 | * with an extra small size. |
| 8254 | * <p>This value is only applicable for custom display notifications created using |
| 8255 | * {@link #setDisplayIntent}. |
| 8256 | */ |
| 8257 | public static final int SIZE_XSMALL = 1; |
| 8258 | |
| 8259 | /** |
| 8260 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8261 | * with a small size. |
| 8262 | * <p>This value is only applicable for custom display notifications created using |
| 8263 | * {@link #setDisplayIntent}. |
| 8264 | */ |
| 8265 | public static final int SIZE_SMALL = 2; |
| 8266 | |
| 8267 | /** |
| 8268 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8269 | * with a medium size. |
| 8270 | * <p>This value is only applicable for custom display notifications created using |
| 8271 | * {@link #setDisplayIntent}. |
| 8272 | */ |
| 8273 | public static final int SIZE_MEDIUM = 3; |
| 8274 | |
| 8275 | /** |
| 8276 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8277 | * with a large size. |
| 8278 | * <p>This value is only applicable for custom display notifications created using |
| 8279 | * {@link #setDisplayIntent}. |
| 8280 | */ |
| 8281 | public static final int SIZE_LARGE = 4; |
| 8282 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8283 | /** |
| 8284 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8285 | * full screen. |
| 8286 | * <p>This value is only applicable for custom display notifications created using |
| 8287 | * {@link #setDisplayIntent}. |
| 8288 | */ |
| 8289 | public static final int SIZE_FULL_SCREEN = 5; |
| 8290 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8291 | /** |
| 8292 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 8293 | * short amount of time when this notification is displayed on the screen. This |
| 8294 | * is the default value. |
| 8295 | */ |
| 8296 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 8297 | |
| 8298 | /** |
| 8299 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 8300 | * for a longer amount of time when this notification is displayed on the screen. |
| 8301 | */ |
| 8302 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 8303 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8304 | /** Notification extra which contains wearable extensions */ |
| 8305 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 8306 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 8307 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8308 | private static final String KEY_ACTIONS = "actions"; |
| 8309 | private static final String KEY_FLAGS = "flags"; |
| 8310 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 8311 | private static final String KEY_PAGES = "pages"; |
| 8312 | private static final String KEY_BACKGROUND = "background"; |
| 8313 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 8314 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 8315 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 8316 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 8317 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 8318 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8319 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8320 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8321 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8322 | |
| 8323 | // Flags bitwise-ored to mFlags |
| 8324 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 8325 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 8326 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 8327 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8328 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 8329 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8330 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8331 | |
| 8332 | // Default value for flags integer |
| 8333 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 8334 | |
| 8335 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 8336 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 8337 | |
| 8338 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 8339 | private int mFlags = DEFAULT_FLAGS; |
| 8340 | private PendingIntent mDisplayIntent; |
| 8341 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 8342 | private Bitmap mBackground; |
| 8343 | private int mContentIcon; |
| 8344 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 8345 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 8346 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 8347 | private int mCustomContentHeight; |
| 8348 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8349 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8350 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8351 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8352 | |
| 8353 | /** |
| 8354 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 8355 | * options. |
| 8356 | */ |
| 8357 | public WearableExtender() { |
| 8358 | } |
| 8359 | |
| 8360 | public WearableExtender(Notification notif) { |
| 8361 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 8362 | if (wearableBundle != null) { |
| 8363 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 8364 | if (actions != null) { |
| 8365 | mActions.addAll(actions); |
| 8366 | } |
| 8367 | |
| 8368 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 8369 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 8370 | |
| 8371 | Notification[] pages = getNotificationArrayFromBundle( |
| 8372 | wearableBundle, KEY_PAGES); |
| 8373 | if (pages != null) { |
| 8374 | Collections.addAll(mPages, pages); |
| 8375 | } |
| 8376 | |
| 8377 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 8378 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 8379 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 8380 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 8381 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 8382 | UNSET_ACTION_INDEX); |
| 8383 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 8384 | SIZE_DEFAULT); |
| 8385 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 8386 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8387 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8388 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8389 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8390 | } |
| 8391 | } |
| 8392 | |
| 8393 | /** |
| 8394 | * Apply wearable extensions to a notification that is being built. This is typically |
| 8395 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 8396 | * {@link android.app.Notification.Builder}. |
| 8397 | */ |
| 8398 | @Override |
| 8399 | public Notification.Builder extend(Notification.Builder builder) { |
| 8400 | Bundle wearableBundle = new Bundle(); |
| 8401 | |
| 8402 | if (!mActions.isEmpty()) { |
| 8403 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 8404 | } |
| 8405 | if (mFlags != DEFAULT_FLAGS) { |
| 8406 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 8407 | } |
| 8408 | if (mDisplayIntent != null) { |
| 8409 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 8410 | } |
| 8411 | if (!mPages.isEmpty()) { |
| 8412 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 8413 | new Notification[mPages.size()])); |
| 8414 | } |
| 8415 | if (mBackground != null) { |
| 8416 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 8417 | } |
| 8418 | if (mContentIcon != 0) { |
| 8419 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 8420 | } |
| 8421 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 8422 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 8423 | } |
| 8424 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 8425 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 8426 | mContentActionIndex); |
| 8427 | } |
| 8428 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 8429 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 8430 | } |
| 8431 | if (mCustomContentHeight != 0) { |
| 8432 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 8433 | } |
| 8434 | if (mGravity != DEFAULT_GRAVITY) { |
| 8435 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 8436 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8437 | if (mHintScreenTimeout != 0) { |
| 8438 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 8439 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8440 | if (mDismissalId != null) { |
| 8441 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 8442 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8443 | if (mBridgeTag != null) { |
| 8444 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 8445 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8446 | |
| 8447 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 8448 | return builder; |
| 8449 | } |
| 8450 | |
| 8451 | @Override |
| 8452 | public WearableExtender clone() { |
| 8453 | WearableExtender that = new WearableExtender(); |
| 8454 | that.mActions = new ArrayList<Action>(this.mActions); |
| 8455 | that.mFlags = this.mFlags; |
| 8456 | that.mDisplayIntent = this.mDisplayIntent; |
| 8457 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 8458 | that.mBackground = this.mBackground; |
| 8459 | that.mContentIcon = this.mContentIcon; |
| 8460 | that.mContentIconGravity = this.mContentIconGravity; |
| 8461 | that.mContentActionIndex = this.mContentActionIndex; |
| 8462 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 8463 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 8464 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8465 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8466 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8467 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8468 | return that; |
| 8469 | } |
| 8470 | |
| 8471 | /** |
| 8472 | * Add a wearable action to this notification. |
| 8473 | * |
| 8474 | * <p>When wearable actions are added using this method, the set of actions that |
| 8475 | * show on a wearable device splits from devices that only show actions added |
| 8476 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 8477 | * of which actions display on different devices. |
| 8478 | * |
| 8479 | * @param action the action to add to this notification |
| 8480 | * @return this object for method chaining |
| 8481 | * @see android.app.Notification.Action |
| 8482 | */ |
| 8483 | public WearableExtender addAction(Action action) { |
| 8484 | mActions.add(action); |
| 8485 | return this; |
| 8486 | } |
| 8487 | |
| 8488 | /** |
| 8489 | * Adds wearable actions to this notification. |
| 8490 | * |
| 8491 | * <p>When wearable actions are added using this method, the set of actions that |
| 8492 | * show on a wearable device splits from devices that only show actions added |
| 8493 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 8494 | * of which actions display on different devices. |
| 8495 | * |
| 8496 | * @param actions the actions to add to this notification |
| 8497 | * @return this object for method chaining |
| 8498 | * @see android.app.Notification.Action |
| 8499 | */ |
| 8500 | public WearableExtender addActions(List<Action> actions) { |
| 8501 | mActions.addAll(actions); |
| 8502 | return this; |
| 8503 | } |
| 8504 | |
| 8505 | /** |
| 8506 | * Clear all wearable actions present on this builder. |
| 8507 | * @return this object for method chaining. |
| 8508 | * @see #addAction |
| 8509 | */ |
| 8510 | public WearableExtender clearActions() { |
| 8511 | mActions.clear(); |
| 8512 | return this; |
| 8513 | } |
| 8514 | |
| 8515 | /** |
| 8516 | * Get the wearable actions present on this notification. |
| 8517 | */ |
| 8518 | public List<Action> getActions() { |
| 8519 | return mActions; |
| 8520 | } |
| 8521 | |
| 8522 | /** |
| 8523 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8524 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 8525 | * |
| 8526 | * <pre class="prettyprint"> |
| 8527 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 8528 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 8529 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 8530 | * Notification notif = new Notification.Builder(context) |
| 8531 | * .extend(new Notification.WearableExtender() |
| 8532 | * .setDisplayIntent(displayPendingIntent) |
| 8533 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 8534 | * .build();</pre> |
| 8535 | * |
| 8536 | * <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] | 8537 | * should have an empty task affinity. It is also recommended to use the device |
| 8538 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8539 | * |
| 8540 | * <p>Example AndroidManifest.xml entry: |
| 8541 | * <pre class="prettyprint"> |
| 8542 | * <activity android:name="com.example.MyDisplayActivity" |
| 8543 | * android:exported="true" |
| 8544 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 8545 | * android:taskAffinity="" |
| 8546 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8547 | * |
| 8548 | * @param intent the {@link PendingIntent} for an activity |
| 8549 | * @return this object for method chaining |
| 8550 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 8551 | */ |
| 8552 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 8553 | mDisplayIntent = intent; |
| 8554 | return this; |
| 8555 | } |
| 8556 | |
| 8557 | /** |
| 8558 | * Get the intent to launch inside of an activity view when displaying this |
| 8559 | * notification. This {@code PendingIntent} should be for an activity. |
| 8560 | */ |
| 8561 | public PendingIntent getDisplayIntent() { |
| 8562 | return mDisplayIntent; |
| 8563 | } |
| 8564 | |
| 8565 | /** |
| 8566 | * Add an additional page of content to display with this notification. The current |
| 8567 | * notification forms the first page, and pages added using this function form |
| 8568 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8569 | * sections. |
| 8570 | * |
| 8571 | * @param page the notification to add as another page |
| 8572 | * @return this object for method chaining |
| 8573 | * @see android.app.Notification.WearableExtender#getPages |
| 8574 | */ |
| 8575 | public WearableExtender addPage(Notification page) { |
| 8576 | mPages.add(page); |
| 8577 | return this; |
| 8578 | } |
| 8579 | |
| 8580 | /** |
| 8581 | * Add additional pages of content to display with this notification. The current |
| 8582 | * notification forms the first page, and pages added using this function form |
| 8583 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8584 | * sections. |
| 8585 | * |
| 8586 | * @param pages a list of notifications |
| 8587 | * @return this object for method chaining |
| 8588 | * @see android.app.Notification.WearableExtender#getPages |
| 8589 | */ |
| 8590 | public WearableExtender addPages(List<Notification> pages) { |
| 8591 | mPages.addAll(pages); |
| 8592 | return this; |
| 8593 | } |
| 8594 | |
| 8595 | /** |
| 8596 | * Clear all additional pages present on this builder. |
| 8597 | * @return this object for method chaining. |
| 8598 | * @see #addPage |
| 8599 | */ |
| 8600 | public WearableExtender clearPages() { |
| 8601 | mPages.clear(); |
| 8602 | return this; |
| 8603 | } |
| 8604 | |
| 8605 | /** |
| 8606 | * Get the array of additional pages of content for displaying this notification. The |
| 8607 | * current notification forms the first page, and elements within this array form |
| 8608 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8609 | * sections. |
| 8610 | * @return the pages for this notification |
| 8611 | */ |
| 8612 | public List<Notification> getPages() { |
| 8613 | return mPages; |
| 8614 | } |
| 8615 | |
| 8616 | /** |
| 8617 | * Set a background image to be displayed behind the notification content. |
| 8618 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 8619 | * will work with any notification style. |
| 8620 | * |
| 8621 | * @param background the background bitmap |
| 8622 | * @return this object for method chaining |
| 8623 | * @see android.app.Notification.WearableExtender#getBackground |
| 8624 | */ |
| 8625 | public WearableExtender setBackground(Bitmap background) { |
| 8626 | mBackground = background; |
| 8627 | return this; |
| 8628 | } |
| 8629 | |
| 8630 | /** |
| 8631 | * Get a background image to be displayed behind the notification content. |
| 8632 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 8633 | * will work with any notification style. |
| 8634 | * |
| 8635 | * @return the background image |
| 8636 | * @see android.app.Notification.WearableExtender#setBackground |
| 8637 | */ |
| 8638 | public Bitmap getBackground() { |
| 8639 | return mBackground; |
| 8640 | } |
| 8641 | |
| 8642 | /** |
| 8643 | * Set an icon that goes with the content of this notification. |
| 8644 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8645 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8646 | public WearableExtender setContentIcon(int icon) { |
| 8647 | mContentIcon = icon; |
| 8648 | return this; |
| 8649 | } |
| 8650 | |
| 8651 | /** |
| 8652 | * Get an icon that goes with the content of this notification. |
| 8653 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8654 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8655 | public int getContentIcon() { |
| 8656 | return mContentIcon; |
| 8657 | } |
| 8658 | |
| 8659 | /** |
| 8660 | * Set the gravity that the content icon should have within the notification display. |
| 8661 | * Supported values include {@link android.view.Gravity#START} and |
| 8662 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 8663 | * @see #setContentIcon |
| 8664 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8665 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8666 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 8667 | mContentIconGravity = contentIconGravity; |
| 8668 | return this; |
| 8669 | } |
| 8670 | |
| 8671 | /** |
| 8672 | * Get the gravity that the content icon should have within the notification display. |
| 8673 | * Supported values include {@link android.view.Gravity#START} and |
| 8674 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 8675 | * @see #getContentIcon |
| 8676 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8677 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8678 | public int getContentIconGravity() { |
| 8679 | return mContentIconGravity; |
| 8680 | } |
| 8681 | |
| 8682 | /** |
| 8683 | * Set an action from this notification's actions to be clickable with the content of |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8684 | * this notification. This action will no longer display separately from the |
| 8685 | * notification's content. |
| 8686 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 8687 | * <p>For notifications with multiple pages, child pages can also have content actions |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8688 | * set, although the list of available actions comes from the main notification and not |
| 8689 | * from the child page's notification. |
| 8690 | * |
| 8691 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 8692 | * If wearable actions were added to the main notification, this index |
| 8693 | * will apply to that list, otherwise it will apply to the regular |
| 8694 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8695 | */ |
| 8696 | public WearableExtender setContentAction(int actionIndex) { |
| 8697 | mContentActionIndex = actionIndex; |
| 8698 | return this; |
| 8699 | } |
| 8700 | |
| 8701 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 8702 | * Get the index of the notification action, if any, that was specified as being clickable |
| 8703 | * with the content of this notification. This action will no longer display separately |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8704 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8705 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 8706 | * <p>For notifications with multiple pages, child pages can also have content actions |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8707 | * set, although the list of available actions comes from the main notification and not |
| 8708 | * from the child page's notification. |
| 8709 | * |
| 8710 | * <p>If wearable specific actions were added to the main notification, this index will |
| 8711 | * 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] | 8712 | * |
| 8713 | * @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] | 8714 | */ |
| 8715 | public int getContentAction() { |
| 8716 | return mContentActionIndex; |
| 8717 | } |
| 8718 | |
| 8719 | /** |
| 8720 | * Set the gravity that this notification should have within the available viewport space. |
| 8721 | * Supported values include {@link android.view.Gravity#TOP}, |
| 8722 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 8723 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 8724 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8725 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8726 | public WearableExtender setGravity(int gravity) { |
| 8727 | mGravity = gravity; |
| 8728 | return this; |
| 8729 | } |
| 8730 | |
| 8731 | /** |
| 8732 | * Get the gravity that this notification should have within the available viewport space. |
| 8733 | * Supported values include {@link android.view.Gravity#TOP}, |
| 8734 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 8735 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 8736 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8737 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8738 | public int getGravity() { |
| 8739 | return mGravity; |
| 8740 | } |
| 8741 | |
| 8742 | /** |
| 8743 | * Set the custom size preset for the display of this notification out of the available |
| 8744 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 8745 | * {@link #SIZE_LARGE}. |
| 8746 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 8747 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 8748 | * documentation for the preset in question. See also |
| 8749 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 8750 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8751 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8752 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 8753 | mCustomSizePreset = sizePreset; |
| 8754 | return this; |
| 8755 | } |
| 8756 | |
| 8757 | /** |
| 8758 | * Get the custom size preset for the display of this notification out of the available |
| 8759 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 8760 | * {@link #SIZE_LARGE}. |
| 8761 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 8762 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 8763 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 8764 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8765 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8766 | public int getCustomSizePreset() { |
| 8767 | return mCustomSizePreset; |
| 8768 | } |
| 8769 | |
| 8770 | /** |
| 8771 | * Set the custom height in pixels for the display of this notification's content. |
| 8772 | * <p>This option is only available for custom display notifications created |
| 8773 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 8774 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 8775 | * {@link #getCustomContentHeight}. |
| 8776 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8777 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8778 | public WearableExtender setCustomContentHeight(int height) { |
| 8779 | mCustomContentHeight = height; |
| 8780 | return this; |
| 8781 | } |
| 8782 | |
| 8783 | /** |
| 8784 | * Get the custom height in pixels for the display of this notification's content. |
| 8785 | * <p>This option is only available for custom display notifications created |
| 8786 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 8787 | * {@link #setCustomContentHeight}. |
| 8788 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8789 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8790 | public int getCustomContentHeight() { |
| 8791 | return mCustomContentHeight; |
| 8792 | } |
| 8793 | |
| 8794 | /** |
| 8795 | * Set whether the scrolling position for the contents of this notification should start |
| 8796 | * at the bottom of the contents instead of the top when the contents are too long to |
| 8797 | * display within the screen. Default is false (start scroll at the top). |
| 8798 | */ |
| 8799 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 8800 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 8801 | return this; |
| 8802 | } |
| 8803 | |
| 8804 | /** |
| 8805 | * Get whether the scrolling position for the contents of this notification should start |
| 8806 | * at the bottom of the contents instead of the top when the contents are too long to |
| 8807 | * display within the screen. Default is false (start scroll at the top). |
| 8808 | */ |
| 8809 | public boolean getStartScrollBottom() { |
| 8810 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 8811 | } |
| 8812 | |
| 8813 | /** |
| 8814 | * Set whether the content intent is available when the wearable device is not connected |
| 8815 | * to a companion device. The user can still trigger this intent when the wearable device |
| 8816 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 8817 | * Defaults to true. |
| 8818 | */ |
| 8819 | public WearableExtender setContentIntentAvailableOffline( |
| 8820 | boolean contentIntentAvailableOffline) { |
| 8821 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 8822 | return this; |
| 8823 | } |
| 8824 | |
| 8825 | /** |
| 8826 | * Get whether the content intent is available when the wearable device is not connected |
| 8827 | * to a companion device. The user can still trigger this intent when the wearable device |
| 8828 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 8829 | * Defaults to true. |
| 8830 | */ |
| 8831 | public boolean getContentIntentAvailableOffline() { |
| 8832 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 8833 | } |
| 8834 | |
| 8835 | /** |
| 8836 | * Set a hint that this notification's icon should not be displayed. |
| 8837 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 8838 | * @return this object for method chaining |
| 8839 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8840 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8841 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 8842 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 8843 | return this; |
| 8844 | } |
| 8845 | |
| 8846 | /** |
| 8847 | * Get a hint that this notification's icon should not be displayed. |
| 8848 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 8849 | * The default value is {@code false} if this was never set. |
| 8850 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8851 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8852 | public boolean getHintHideIcon() { |
| 8853 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 8854 | } |
| 8855 | |
| 8856 | /** |
| 8857 | * Set a visual hint that only the background image of this notification should be |
| 8858 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 8859 | * to sub-pages added using {@link #addPage}. |
| 8860 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8861 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8862 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 8863 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 8864 | return this; |
| 8865 | } |
| 8866 | |
| 8867 | /** |
| 8868 | * Get a visual hint that only the background image of this notification should be |
| 8869 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 8870 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 8871 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8872 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8873 | public boolean getHintShowBackgroundOnly() { |
| 8874 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 8875 | } |
| 8876 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8877 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 8878 | * Set a hint that this notification's background should not be clipped if possible, |
| 8879 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 8880 | * 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] | 8881 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 8882 | * @return this object for method chaining |
| 8883 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8884 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8885 | public WearableExtender setHintAvoidBackgroundClipping( |
| 8886 | boolean hintAvoidBackgroundClipping) { |
| 8887 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 8888 | return this; |
| 8889 | } |
| 8890 | |
| 8891 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 8892 | * Get a hint that this notification's background should not be clipped if possible, |
| 8893 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 8894 | * 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] | 8895 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 8896 | * otherwise. The default value is {@code false} if this was never set. |
| 8897 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8898 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8899 | public boolean getHintAvoidBackgroundClipping() { |
| 8900 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 8901 | } |
| 8902 | |
| 8903 | /** |
| 8904 | * Set a hint that the screen should remain on for at least this duration when |
| 8905 | * this notification is displayed on the screen. |
| 8906 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 8907 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 8908 | * @return this object for method chaining |
| 8909 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8910 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8911 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 8912 | mHintScreenTimeout = timeout; |
| 8913 | return this; |
| 8914 | } |
| 8915 | |
| 8916 | /** |
| 8917 | * Get the duration, in milliseconds, that the screen should remain on for |
| 8918 | * when this notification is displayed. |
| 8919 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 8920 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 8921 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8922 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8923 | public int getHintScreenTimeout() { |
| 8924 | return mHintScreenTimeout; |
| 8925 | } |
| 8926 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8927 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 8928 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 8929 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 8930 | * qr codes, as well as other simple black-and-white tickets. |
| 8931 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 8932 | * @return this object for method chaining |
| 8933 | */ |
| 8934 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 8935 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 8936 | return this; |
| 8937 | } |
| 8938 | |
| 8939 | /** |
| 8940 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 8941 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 8942 | * qr codes, as well as other simple black-and-white tickets. |
| 8943 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 8944 | * otherwise. The default value is {@code false} if this was never set. |
| 8945 | */ |
| 8946 | public boolean getHintAmbientBigPicture() { |
| 8947 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 8948 | } |
| 8949 | |
| 8950 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8951 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 8952 | * directly, telling the platform that it can generate the appropriate transitions. |
| 8953 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 8954 | * an activity and transitions should be generated, false otherwise. |
| 8955 | * @return this object for method chaining |
| 8956 | */ |
| 8957 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 8958 | boolean hintContentIntentLaunchesActivity) { |
| 8959 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 8960 | return this; |
| 8961 | } |
| 8962 | |
| 8963 | /** |
| 8964 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 8965 | * directly, telling the platform that it can generate the appropriate transitions |
| 8966 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 8967 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 8968 | */ |
| 8969 | public boolean getHintContentIntentLaunchesActivity() { |
| 8970 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 8971 | } |
| 8972 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8973 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8974 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 8975 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 8976 | * 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] | 8977 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8978 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8979 | * @param dismissalId the dismissal id of the notification. |
| 8980 | * @return this object for method chaining |
| 8981 | */ |
| 8982 | public WearableExtender setDismissalId(String dismissalId) { |
| 8983 | mDismissalId = dismissalId; |
| 8984 | return this; |
| 8985 | } |
| 8986 | |
| 8987 | /** |
| 8988 | * Returns the dismissal id of the notification. |
| 8989 | * @return the dismissal id of the notification or null if it has not been set. |
| 8990 | */ |
| 8991 | public String getDismissalId() { |
| 8992 | return mDismissalId; |
| 8993 | } |
| 8994 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8995 | /** |
| 8996 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 8997 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 8998 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 8999 | * Features to Notifications</a> for more information. |
| 9000 | * @param bridgeTag the bridge tag of the notification. |
| 9001 | * @return this object for method chaining |
| 9002 | */ |
| 9003 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 9004 | mBridgeTag = bridgeTag; |
| 9005 | return this; |
| 9006 | } |
| 9007 | |
| 9008 | /** |
| 9009 | * Returns the bridge tag of the notification. |
| 9010 | * @return the bridge tag or null if not present. |
| 9011 | */ |
| 9012 | public String getBridgeTag() { |
| 9013 | return mBridgeTag; |
| 9014 | } |
| 9015 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9016 | private void setFlag(int mask, boolean value) { |
| 9017 | if (value) { |
| 9018 | mFlags |= mask; |
| 9019 | } else { |
| 9020 | mFlags &= ~mask; |
| 9021 | } |
| 9022 | } |
| 9023 | } |
| 9024 | |
| 9025 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9026 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 9027 | * with car extensions: |
| 9028 | * |
| 9029 | * <ol> |
| 9030 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 9031 | * properties. |
| 9032 | * <li>Create a {@link CarExtender}. |
| 9033 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 9034 | * {@link CarExtender}. |
| 9035 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9036 | * to apply the extensions to a notification. |
| 9037 | * </ol> |
| 9038 | * |
| 9039 | * <pre class="prettyprint"> |
| 9040 | * Notification notification = new Notification.Builder(context) |
| 9041 | * ... |
| 9042 | * .extend(new CarExtender() |
| 9043 | * .set*(...)) |
| 9044 | * .build(); |
| 9045 | * </pre> |
| 9046 | * |
| 9047 | * <p>Car extensions can be accessed on an existing notification by using the |
| 9048 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 9049 | * to access values. |
| 9050 | */ |
| 9051 | public static final class CarExtender implements Extender { |
| 9052 | private static final String TAG = "CarExtender"; |
| 9053 | |
| 9054 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 9055 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 9056 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 9057 | private static final String EXTRA_COLOR = "app_color"; |
| 9058 | |
| 9059 | private Bitmap mLargeIcon; |
| 9060 | private UnreadConversation mUnreadConversation; |
| 9061 | private int mColor = Notification.COLOR_DEFAULT; |
| 9062 | |
| 9063 | /** |
| 9064 | * Create a {@link CarExtender} with default options. |
| 9065 | */ |
| 9066 | public CarExtender() { |
| 9067 | } |
| 9068 | |
| 9069 | /** |
| 9070 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 9071 | * |
| 9072 | * @param notif The notification from which to copy options. |
| 9073 | */ |
| 9074 | public CarExtender(Notification notif) { |
| 9075 | Bundle carBundle = notif.extras == null ? |
| 9076 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 9077 | if (carBundle != null) { |
| 9078 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 9079 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 9080 | |
| 9081 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 9082 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 9083 | } |
| 9084 | } |
| 9085 | |
| 9086 | /** |
| 9087 | * Apply car extensions to a notification that is being built. This is typically called by |
| 9088 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9089 | * method of {@link Notification.Builder}. |
| 9090 | */ |
| 9091 | @Override |
| 9092 | public Notification.Builder extend(Notification.Builder builder) { |
| 9093 | Bundle carExtensions = new Bundle(); |
| 9094 | |
| 9095 | if (mLargeIcon != null) { |
| 9096 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 9097 | } |
| 9098 | if (mColor != Notification.COLOR_DEFAULT) { |
| 9099 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 9100 | } |
| 9101 | |
| 9102 | if (mUnreadConversation != null) { |
| 9103 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 9104 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 9105 | } |
| 9106 | |
| 9107 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 9108 | return builder; |
| 9109 | } |
| 9110 | |
| 9111 | /** |
| 9112 | * Sets the accent color to use when Android Auto presents the notification. |
| 9113 | * |
| 9114 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 9115 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 9116 | * automotive setting. This method can be used to override the color provided in the |
| 9117 | * notification in such a situation. |
| 9118 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9119 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9120 | mColor = color; |
| 9121 | return this; |
| 9122 | } |
| 9123 | |
| 9124 | /** |
| 9125 | * Gets the accent color. |
| 9126 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 9127 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9128 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 9129 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 9130 | public int getColor() { |
| 9131 | return mColor; |
| 9132 | } |
| 9133 | |
| 9134 | /** |
| 9135 | * Sets the large icon of the car notification. |
| 9136 | * |
| 9137 | * If no large icon is set in the extender, Android Auto will display the icon |
| 9138 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 9139 | * |
| 9140 | * @param largeIcon The large icon to use in the car notification. |
| 9141 | * @return This object for method chaining. |
| 9142 | */ |
| 9143 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 9144 | mLargeIcon = largeIcon; |
| 9145 | return this; |
| 9146 | } |
| 9147 | |
| 9148 | /** |
| 9149 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 9150 | * |
| 9151 | * @return The large icon for the car notification. |
| 9152 | * @see CarExtender#setLargeIcon |
| 9153 | */ |
| 9154 | public Bitmap getLargeIcon() { |
| 9155 | return mLargeIcon; |
| 9156 | } |
| 9157 | |
| 9158 | /** |
| 9159 | * Sets the unread conversation in a message notification. |
| 9160 | * |
| 9161 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 9162 | * @return This object for method chaining. |
| 9163 | */ |
| 9164 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 9165 | mUnreadConversation = unreadConversation; |
| 9166 | return this; |
| 9167 | } |
| 9168 | |
| 9169 | /** |
| 9170 | * Returns the unread conversation conveyed by this notification. |
| 9171 | * @see #setUnreadConversation(UnreadConversation) |
| 9172 | */ |
| 9173 | public UnreadConversation getUnreadConversation() { |
| 9174 | return mUnreadConversation; |
| 9175 | } |
| 9176 | |
| 9177 | /** |
| 9178 | * A class which holds the unread messages from a conversation. |
| 9179 | */ |
| 9180 | public static class UnreadConversation { |
| 9181 | private static final String KEY_AUTHOR = "author"; |
| 9182 | private static final String KEY_TEXT = "text"; |
| 9183 | private static final String KEY_MESSAGES = "messages"; |
| 9184 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 9185 | private static final String KEY_ON_REPLY = "on_reply"; |
| 9186 | private static final String KEY_ON_READ = "on_read"; |
| 9187 | private static final String KEY_PARTICIPANTS = "participants"; |
| 9188 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 9189 | |
| 9190 | private final String[] mMessages; |
| 9191 | private final RemoteInput mRemoteInput; |
| 9192 | private final PendingIntent mReplyPendingIntent; |
| 9193 | private final PendingIntent mReadPendingIntent; |
| 9194 | private final String[] mParticipants; |
| 9195 | private final long mLatestTimestamp; |
| 9196 | |
| 9197 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 9198 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 9199 | String[] participants, long latestTimestamp) { |
| 9200 | mMessages = messages; |
| 9201 | mRemoteInput = remoteInput; |
| 9202 | mReadPendingIntent = readPendingIntent; |
| 9203 | mReplyPendingIntent = replyPendingIntent; |
| 9204 | mParticipants = participants; |
| 9205 | mLatestTimestamp = latestTimestamp; |
| 9206 | } |
| 9207 | |
| 9208 | /** |
| 9209 | * Gets the list of messages conveyed by this notification. |
| 9210 | */ |
| 9211 | public String[] getMessages() { |
| 9212 | return mMessages; |
| 9213 | } |
| 9214 | |
| 9215 | /** |
| 9216 | * Gets the remote input that will be used to convey the response to a message list, or |
| 9217 | * null if no such remote input exists. |
| 9218 | */ |
| 9219 | public RemoteInput getRemoteInput() { |
| 9220 | return mRemoteInput; |
| 9221 | } |
| 9222 | |
| 9223 | /** |
| 9224 | * Gets the pending intent that will be triggered when the user replies to this |
| 9225 | * notification. |
| 9226 | */ |
| 9227 | public PendingIntent getReplyPendingIntent() { |
| 9228 | return mReplyPendingIntent; |
| 9229 | } |
| 9230 | |
| 9231 | /** |
| 9232 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 9233 | * in this object's message list. |
| 9234 | */ |
| 9235 | public PendingIntent getReadPendingIntent() { |
| 9236 | return mReadPendingIntent; |
| 9237 | } |
| 9238 | |
| 9239 | /** |
| 9240 | * Gets the participants in the conversation. |
| 9241 | */ |
| 9242 | public String[] getParticipants() { |
| 9243 | return mParticipants; |
| 9244 | } |
| 9245 | |
| 9246 | /** |
| 9247 | * Gets the firs participant in the conversation. |
| 9248 | */ |
| 9249 | public String getParticipant() { |
| 9250 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 9251 | } |
| 9252 | |
| 9253 | /** |
| 9254 | * Gets the timestamp of the conversation. |
| 9255 | */ |
| 9256 | public long getLatestTimestamp() { |
| 9257 | return mLatestTimestamp; |
| 9258 | } |
| 9259 | |
| 9260 | Bundle getBundleForUnreadConversation() { |
| 9261 | Bundle b = new Bundle(); |
| 9262 | String author = null; |
| 9263 | if (mParticipants != null && mParticipants.length > 1) { |
| 9264 | author = mParticipants[0]; |
| 9265 | } |
| 9266 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 9267 | for (int i = 0; i < messages.length; i++) { |
| 9268 | Bundle m = new Bundle(); |
| 9269 | m.putString(KEY_TEXT, mMessages[i]); |
| 9270 | m.putString(KEY_AUTHOR, author); |
| 9271 | messages[i] = m; |
| 9272 | } |
| 9273 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 9274 | if (mRemoteInput != null) { |
| 9275 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 9276 | } |
| 9277 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 9278 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 9279 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 9280 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 9281 | return b; |
| 9282 | } |
| 9283 | |
| 9284 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 9285 | if (b == null) { |
| 9286 | return null; |
| 9287 | } |
| 9288 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 9289 | String[] messages = null; |
| 9290 | if (parcelableMessages != null) { |
| 9291 | String[] tmp = new String[parcelableMessages.length]; |
| 9292 | boolean success = true; |
| 9293 | for (int i = 0; i < tmp.length; i++) { |
| 9294 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 9295 | success = false; |
| 9296 | break; |
| 9297 | } |
| 9298 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 9299 | if (tmp[i] == null) { |
| 9300 | success = false; |
| 9301 | break; |
| 9302 | } |
| 9303 | } |
| 9304 | if (success) { |
| 9305 | messages = tmp; |
| 9306 | } else { |
| 9307 | return null; |
| 9308 | } |
| 9309 | } |
| 9310 | |
| 9311 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 9312 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 9313 | |
| 9314 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 9315 | |
| 9316 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 9317 | if (participants == null || participants.length != 1) { |
| 9318 | return null; |
| 9319 | } |
| 9320 | |
| 9321 | return new UnreadConversation(messages, |
| 9322 | remoteInput, |
| 9323 | onReply, |
| 9324 | onRead, |
| 9325 | participants, b.getLong(KEY_TIMESTAMP)); |
| 9326 | } |
| 9327 | }; |
| 9328 | |
| 9329 | /** |
| 9330 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 9331 | */ |
| 9332 | public static class Builder { |
| 9333 | private final List<String> mMessages = new ArrayList<String>(); |
| 9334 | private final String mParticipant; |
| 9335 | private RemoteInput mRemoteInput; |
| 9336 | private PendingIntent mReadPendingIntent; |
| 9337 | private PendingIntent mReplyPendingIntent; |
| 9338 | private long mLatestTimestamp; |
| 9339 | |
| 9340 | /** |
| 9341 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 9342 | * |
| 9343 | * @param name The name of the other participant in the conversation. |
| 9344 | */ |
| 9345 | public Builder(String name) { |
| 9346 | mParticipant = name; |
| 9347 | } |
| 9348 | |
| 9349 | /** |
| 9350 | * Appends a new unread message to the list of messages for this conversation. |
| 9351 | * |
| 9352 | * The messages should be added from oldest to newest. |
| 9353 | * |
| 9354 | * @param message The text of the new unread message. |
| 9355 | * @return This object for method chaining. |
| 9356 | */ |
| 9357 | public Builder addMessage(String message) { |
| 9358 | mMessages.add(message); |
| 9359 | return this; |
| 9360 | } |
| 9361 | |
| 9362 | /** |
| 9363 | * Sets the pending intent and remote input which will convey the reply to this |
| 9364 | * notification. |
| 9365 | * |
| 9366 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 9367 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 9368 | * @return This object for method chaining. |
| 9369 | * |
| 9370 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 9371 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 9372 | */ |
| 9373 | public Builder setReplyAction( |
| 9374 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 9375 | mRemoteInput = remoteInput; |
| 9376 | mReplyPendingIntent = pendingIntent; |
| 9377 | |
| 9378 | return this; |
| 9379 | } |
| 9380 | |
| 9381 | /** |
| 9382 | * Sets the pending intent that will be sent once the messages in this notification |
| 9383 | * are read. |
| 9384 | * |
| 9385 | * @param pendingIntent The pending intent to use. |
| 9386 | * @return This object for method chaining. |
| 9387 | */ |
| 9388 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 9389 | mReadPendingIntent = pendingIntent; |
| 9390 | return this; |
| 9391 | } |
| 9392 | |
| 9393 | /** |
| 9394 | * Sets the timestamp of the most recent message in an unread conversation. |
| 9395 | * |
| 9396 | * If a messaging notification has been posted by your application and has not |
| 9397 | * yet been cancelled, posting a later notification with the same id and tag |
| 9398 | * but without a newer timestamp may result in Android Auto not displaying a |
| 9399 | * heads up notification for the later notification. |
| 9400 | * |
| 9401 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 9402 | * @return This object for method chaining. |
| 9403 | */ |
| 9404 | public Builder setLatestTimestamp(long timestamp) { |
| 9405 | mLatestTimestamp = timestamp; |
| 9406 | return this; |
| 9407 | } |
| 9408 | |
| 9409 | /** |
| 9410 | * Builds a new unread conversation object. |
| 9411 | * |
| 9412 | * @return The new unread conversation object. |
| 9413 | */ |
| 9414 | public UnreadConversation build() { |
| 9415 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 9416 | String[] participants = { mParticipant }; |
| 9417 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 9418 | mReadPendingIntent, participants, mLatestTimestamp); |
| 9419 | } |
| 9420 | } |
| 9421 | } |
| 9422 | |
| 9423 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9424 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 9425 | * with a TV extension: |
| 9426 | * |
| 9427 | * <ol> |
| 9428 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 9429 | * <li>Create a {@link TvExtender}. |
| 9430 | * <li>Set TV-specific properties using the {@code set} methods of |
| 9431 | * {@link TvExtender}. |
| 9432 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9433 | * to apply the extension to a notification. |
| 9434 | * </ol> |
| 9435 | * |
| 9436 | * <pre class="prettyprint"> |
| 9437 | * Notification notification = new Notification.Builder(context) |
| 9438 | * ... |
| 9439 | * .extend(new TvExtender() |
| 9440 | * .set*(...)) |
| 9441 | * .build(); |
| 9442 | * </pre> |
| 9443 | * |
| 9444 | * <p>TV extensions can be accessed on an existing notification by using the |
| 9445 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 9446 | * to access values. |
| 9447 | * |
| 9448 | * @hide |
| 9449 | */ |
| 9450 | @SystemApi |
| 9451 | public static final class TvExtender implements Extender { |
| 9452 | private static final String TAG = "TvExtender"; |
| 9453 | |
| 9454 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 9455 | private static final String EXTRA_FLAGS = "flags"; |
| 9456 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 9457 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9458 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9459 | private static final String EXTRA_SUPPRESS_SHOW_OVER_APPS = "suppressShowOverApps"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9460 | |
| 9461 | // Flags bitwise-ored to mFlags |
| 9462 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 9463 | |
| 9464 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9465 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9466 | private PendingIntent mContentIntent; |
| 9467 | private PendingIntent mDeleteIntent; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9468 | private boolean mSuppressShowOverApps; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9469 | |
| 9470 | /** |
| 9471 | * Create a {@link TvExtender} with default options. |
| 9472 | */ |
| 9473 | public TvExtender() { |
| 9474 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 9475 | } |
| 9476 | |
| 9477 | /** |
| 9478 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 9479 | * |
| 9480 | * @param notif The notification from which to copy options. |
| 9481 | */ |
| 9482 | public TvExtender(Notification notif) { |
| 9483 | Bundle bundle = notif.extras == null ? |
| 9484 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 9485 | if (bundle != null) { |
| 9486 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9487 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9488 | mSuppressShowOverApps = bundle.getBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9489 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 9490 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 9491 | } |
| 9492 | } |
| 9493 | |
| 9494 | /** |
| 9495 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 9496 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9497 | * method of {@link Notification.Builder}. |
| 9498 | */ |
| 9499 | @Override |
| 9500 | public Notification.Builder extend(Notification.Builder builder) { |
| 9501 | Bundle bundle = new Bundle(); |
| 9502 | |
| 9503 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9504 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9505 | bundle.putBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS, mSuppressShowOverApps); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9506 | if (mContentIntent != null) { |
| 9507 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 9508 | } |
| 9509 | |
| 9510 | if (mDeleteIntent != null) { |
| 9511 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 9512 | } |
| 9513 | |
| 9514 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 9515 | return builder; |
| 9516 | } |
| 9517 | |
| 9518 | /** |
| 9519 | * Returns true if this notification should be shown on TV. This method return true |
| 9520 | * if the notification was extended with a TvExtender. |
| 9521 | */ |
| 9522 | public boolean isAvailableOnTv() { |
| 9523 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 9524 | } |
| 9525 | |
| 9526 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9527 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 9528 | * It can be different from the channel that the notification is delivered to when |
| 9529 | * posting on a non-TV device. |
| 9530 | */ |
| 9531 | public TvExtender setChannel(String channelId) { |
| 9532 | mChannelId = channelId; |
| 9533 | return this; |
| 9534 | } |
| 9535 | |
| 9536 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 9537 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 9538 | * It can be different from the channel that the notification is delivered to when |
| 9539 | * posting on a non-TV device. |
| 9540 | */ |
| 9541 | public TvExtender setChannelId(String channelId) { |
| 9542 | mChannelId = channelId; |
| 9543 | return this; |
| 9544 | } |
| 9545 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 9546 | /** @removed */ |
| 9547 | @Deprecated |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9548 | public String getChannel() { |
| 9549 | return mChannelId; |
| 9550 | } |
| 9551 | |
| 9552 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 9553 | * Returns the id of the channel this notification posts to on TV. |
| 9554 | */ |
| 9555 | public String getChannelId() { |
| 9556 | return mChannelId; |
| 9557 | } |
| 9558 | |
| 9559 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9560 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 9561 | * If provided, it is used instead of the content intent specified |
| 9562 | * at the level of Notification. |
| 9563 | */ |
| 9564 | public TvExtender setContentIntent(PendingIntent intent) { |
| 9565 | mContentIntent = intent; |
| 9566 | return this; |
| 9567 | } |
| 9568 | |
| 9569 | /** |
| 9570 | * Returns the TV-specific content intent. If this method returns null, the |
| 9571 | * main content intent on the notification should be used. |
| 9572 | * |
| 9573 | * @see {@link Notification#contentIntent} |
| 9574 | */ |
| 9575 | public PendingIntent getContentIntent() { |
| 9576 | return mContentIntent; |
| 9577 | } |
| 9578 | |
| 9579 | /** |
| 9580 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 9581 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 9582 | * at the level of Notification. |
| 9583 | */ |
| 9584 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 9585 | mDeleteIntent = intent; |
| 9586 | return this; |
| 9587 | } |
| 9588 | |
| 9589 | /** |
| 9590 | * Returns the TV-specific delete intent. If this method returns null, the |
| 9591 | * main delete intent on the notification should be used. |
| 9592 | * |
| 9593 | * @see {@link Notification#deleteIntent} |
| 9594 | */ |
| 9595 | public PendingIntent getDeleteIntent() { |
| 9596 | return mDeleteIntent; |
| 9597 | } |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9598 | |
| 9599 | /** |
| 9600 | * Specifies whether this notification should suppress showing a message over top of apps |
| 9601 | * outside of the launcher. |
| 9602 | */ |
| 9603 | public TvExtender setSuppressShowOverApps(boolean suppress) { |
| 9604 | mSuppressShowOverApps = suppress; |
| 9605 | return this; |
| 9606 | } |
| 9607 | |
| 9608 | /** |
| 9609 | * Returns true if this notification should not show messages over top of apps |
| 9610 | * outside of the launcher. |
| 9611 | */ |
| 9612 | public boolean getSuppressShowOverApps() { |
| 9613 | return mSuppressShowOverApps; |
| 9614 | } |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9615 | } |
| 9616 | |
| 9617 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9618 | * Get an array of Notification objects from a parcelable array bundle field. |
| 9619 | * Update the bundle to have a typed array so fetches in the future don't need |
| 9620 | * to do an array copy. |
| 9621 | */ |
| 9622 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 9623 | Parcelable[] array = bundle.getParcelableArray(key); |
| 9624 | if (array instanceof Notification[] || array == null) { |
| 9625 | return (Notification[]) array; |
| 9626 | } |
| 9627 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 9628 | Notification[].class); |
| 9629 | bundle.putParcelableArray(key, typedArray); |
| 9630 | return typedArray; |
| 9631 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 9632 | |
| 9633 | private static class BuilderRemoteViews extends RemoteViews { |
| 9634 | public BuilderRemoteViews(Parcel parcel) { |
| 9635 | super(parcel); |
| 9636 | } |
| 9637 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 9638 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 9639 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 9640 | } |
| 9641 | |
| 9642 | @Override |
| 9643 | public BuilderRemoteViews clone() { |
| 9644 | Parcel p = Parcel.obtain(); |
| 9645 | writeToParcel(p, 0); |
| 9646 | p.setDataPosition(0); |
| 9647 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 9648 | p.recycle(); |
| 9649 | return brv; |
| 9650 | } |
| 9651 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9652 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9653 | /** |
| 9654 | * A result object where information about the template that was created is saved. |
| 9655 | */ |
| 9656 | private static class TemplateBindResult { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9657 | int mIconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9658 | |
| 9659 | /** |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9660 | * 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] | 9661 | * with the right actions. |
| 9662 | */ |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9663 | public int getIconMarginEnd() { |
| 9664 | return mIconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9665 | } |
| 9666 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9667 | public void setIconMarginEnd(int iconMarginEnd) { |
| 9668 | this.mIconMarginEnd = iconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9669 | } |
| 9670 | } |
| 9671 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9672 | private static class StandardTemplateParams { |
| 9673 | boolean hasProgress = true; |
| 9674 | boolean ambient = false; |
| 9675 | CharSequence title; |
| 9676 | CharSequence text; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9677 | CharSequence headerTextSecondary; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 9678 | int maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9679 | boolean hideLargeIcon; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9680 | boolean hideReplyIcon; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9681 | |
| 9682 | final StandardTemplateParams reset() { |
| 9683 | hasProgress = true; |
| 9684 | ambient = false; |
| 9685 | title = null; |
| 9686 | text = null; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9687 | headerTextSecondary = null; |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 9688 | maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9689 | return this; |
| 9690 | } |
| 9691 | |
| 9692 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 9693 | this.hasProgress = hasProgress; |
| 9694 | return this; |
| 9695 | } |
| 9696 | |
| 9697 | final StandardTemplateParams title(CharSequence title) { |
| 9698 | this.title = title; |
| 9699 | return this; |
| 9700 | } |
| 9701 | |
| 9702 | final StandardTemplateParams text(CharSequence text) { |
| 9703 | this.text = text; |
| 9704 | return this; |
| 9705 | } |
| 9706 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9707 | final StandardTemplateParams headerTextSecondary(CharSequence text) { |
| 9708 | this.headerTextSecondary = text; |
| 9709 | return this; |
| 9710 | } |
| 9711 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9712 | final StandardTemplateParams hideLargeIcon(boolean hideLargeIcon) { |
| 9713 | this.hideLargeIcon = hideLargeIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9714 | return this; |
| 9715 | } |
| 9716 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9717 | final StandardTemplateParams hideReplyIcon(boolean hideReplyIcon) { |
| 9718 | this.hideReplyIcon = hideReplyIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9719 | return this; |
| 9720 | } |
| 9721 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9722 | final StandardTemplateParams ambient(boolean ambient) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 9723 | Preconditions.checkState(title == null && text == null, "must set ambient before text"); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9724 | this.ambient = ambient; |
| 9725 | return this; |
| 9726 | } |
| 9727 | |
| 9728 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 9729 | Bundle extras = b.mN.extras; |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 9730 | this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE), ambient); |
| 9731 | |
| 9732 | // Big text notifications should contain their content when viewed in ambient mode. |
| 9733 | CharSequence text = extras.getCharSequence(EXTRA_BIG_TEXT); |
| 9734 | if (!ambient || TextUtils.isEmpty(text)) { |
| 9735 | text = extras.getCharSequence(EXTRA_TEXT); |
| 9736 | } |
| 9737 | this.text = b.processLegacyText(text, ambient); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9738 | return this; |
| 9739 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 9740 | |
| 9741 | /** |
| 9742 | * Set the maximum lines of remote input history lines allowed. |
| 9743 | * @param maxRemoteInputHistory The number of lines. |
| 9744 | * @return The builder for method chaining. |
| 9745 | */ |
| 9746 | public StandardTemplateParams setMaxRemoteInputHistory(int maxRemoteInputHistory) { |
| 9747 | this.maxRemoteInputHistory = maxRemoteInputHistory; |
| 9748 | return this; |
| 9749 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9750 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9751 | } |