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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 34 | import android.content.pm.PackageManager.NameNotFoundException; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 35 | import android.content.pm.ShortcutInfo; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 36 | import android.content.res.ColorStateList; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 37 | import android.content.res.Configuration; |
| 38 | import android.content.res.Resources; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 39 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 40 | import android.graphics.Canvas; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 41 | import android.graphics.Color; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 42 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 43 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 44 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 45 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 46 | import android.media.AudioManager; |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 47 | import android.media.PlayerBase; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 48 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 50 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 51 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 52 | import android.os.Bundle; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 53 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.os.Parcel; |
| 55 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 56 | import android.os.SystemClock; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 57 | import android.os.SystemProperties; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 58 | import android.os.UserHandle; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 59 | import android.text.BidiFormatter; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 60 | import android.text.SpannableStringBuilder; |
| 61 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 63 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 64 | import android.text.style.CharacterStyle; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 65 | import android.text.style.ForegroundColorSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 66 | import android.text.style.RelativeSizeSpan; |
| 67 | import android.text.style.TextAppearanceSpan; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 68 | import android.util.ArraySet; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 69 | import android.util.Log; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 70 | import android.util.SparseArray; |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 71 | import android.util.proto.ProtoOutputStream; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 72 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 73 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 74 | import android.view.View; |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 75 | import android.view.ViewGroup; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 76 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.widget.RemoteViews; |
| 78 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 79 | import com.android.internal.R; |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 80 | import com.android.internal.annotations.VisibleForTesting; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 81 | import com.android.internal.util.ArrayUtils; |
Griff Hazen | c091ba8 | 2014-05-16 10:13:26 -0700 | [diff] [blame] | 82 | import com.android.internal.util.NotificationColorUtil; |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 83 | import com.android.internal.util.Preconditions; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 84 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 85 | import java.lang.annotation.Retention; |
| 86 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 87 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 88 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 89 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 90 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 91 | import java.util.List; |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 92 | import java.util.Objects; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 93 | import java.util.Set; |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 94 | import java.util.function.Consumer; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 95 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | /** |
| 97 | * A class that represents how a persistent notification is to be presented to |
| 98 | * the user using the {@link android.app.NotificationManager}. |
| 99 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 100 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 101 | * easier to construct Notifications.</p> |
| 102 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 103 | * <div class="special reference"> |
| 104 | * <h3>Developer Guides</h3> |
| 105 | * <p>For a guide to creating notifications, read the |
| 106 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 107 | * developer guide.</p> |
| 108 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | */ |
| 110 | public class Notification implements Parcelable |
| 111 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 112 | private static final String TAG = "Notification"; |
| 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 115 | * 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] | 116 | * containing application. |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 117 | */ |
| 118 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 119 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 120 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 121 | |
| 122 | /** |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 123 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 124 | * 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] | 125 | * what settings should be shown in the target app. |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 126 | */ |
| 127 | public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 128 | |
| 129 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 130 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 005c8b9 | 2017-08-24 10:35:53 -0400 | [diff] [blame] | 131 | * contain a {@link NotificationChannelGroup#getId() group id} that can be used to narrow down |
| 132 | * what settings should be shown in the target app. |
| 133 | */ |
| 134 | public static final String EXTRA_CHANNEL_GROUP_ID = "android.intent.extra.CHANNEL_GROUP_ID"; |
| 135 | |
| 136 | /** |
| 137 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 138 | * contain the tag provided to {@link NotificationManager#notify(String, int, Notification)} |
| 139 | * that can be used to narrow down what settings should be shown in the target app. |
| 140 | */ |
| 141 | public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 142 | |
| 143 | /** |
| 144 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 145 | * contain the id provided to {@link NotificationManager#notify(String, int, Notification)} |
| 146 | * that can be used to narrow down what settings should be shown in the target app. |
| 147 | */ |
| 148 | public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 149 | |
| 150 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | * Use all default values (where applicable). |
| 152 | */ |
| 153 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | /** |
| 156 | * Use the default notification sound. This will ignore any given |
| 157 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 158 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 159 | * <p> |
| 160 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 161 | * </p> |
| 162 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 164 | */ |
| 165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | public static final int DEFAULT_SOUND = 1; |
| 167 | |
| 168 | /** |
| 169 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 170 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 171 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 172 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 173 | * <p> |
| 174 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 175 | * </p> |
| 176 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 178 | */ |
| 179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | /** |
| 183 | * Use the default notification lights. This will ignore the |
| 184 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 185 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 186 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 188 | */ |
| 189 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 191 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 193 | * Maximum length of CharSequences accepted by Builder and friends. |
| 194 | * |
| 195 | * <p> |
| 196 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 197 | */ |
| 198 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 199 | |
| 200 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 201 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 202 | */ |
| 203 | private static final int MAX_REPLY_HISTORY = 5; |
| 204 | |
Selim Cinek | de4de0e | 2018-01-24 16:21:07 -0800 | [diff] [blame] | 205 | |
| 206 | /** |
| 207 | * If the notification contained an unsent draft for a RemoteInput when the user clicked on it, |
| 208 | * we're adding the draft as a String extra to the {@link #contentIntent} using this key. |
| 209 | * |
| 210 | * <p>Apps may use this extra to prepopulate text fields in the app, where the user usually |
| 211 | * sends messages.</p> |
| 212 | */ |
| 213 | public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; |
| 214 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 215 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 216 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 217 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 218 | * Default value: {@link System#currentTimeMillis() Now}. |
| 219 | * |
| 220 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 221 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 222 | * 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] | 223 | * timestamped according to when the activity began. |
| 224 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 225 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 226 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 227 | * <ul> |
| 228 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 229 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 230 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 231 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 232 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 233 | * <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] | 234 | * </ul> |
| 235 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 236 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 237 | * anymore by default and must be opted into by using |
| 238 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | */ |
| 240 | public long when; |
| 241 | |
| 242 | /** |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 243 | * The creation time of the notification |
| 244 | */ |
| 245 | private long creationTime; |
| 246 | |
| 247 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | * 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] | 249 | * |
| 250 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 252 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 253 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | public int icon; |
| 255 | |
| 256 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 257 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 258 | * leave it at its default value of 0. |
| 259 | * |
| 260 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 261 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 262 | */ |
| 263 | public int iconLevel; |
| 264 | |
| 265 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 266 | * The number of events that this notification represents. For example, in a new mail |
| 267 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 268 | * |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 269 | * 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] | 270 | * Starting with {@link android.os.Build.VERSION_CODES#O}, the number may be displayed as a |
| 271 | * badge icon in Launchers that support badging. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | */ |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 273 | public int number = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | |
| 275 | /** |
| 276 | * The intent to execute when the expanded status entry is clicked. If |
| 277 | * this is an activity, it must include the |
| 278 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 279 | * that you take care of task management as described in the |
| 280 | * <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] | 281 | * Stack</a> document. In particular, make sure to read the notification section |
| 282 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 283 | * Notifications</a> for the correct ways to launch an application from a |
| 284 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | */ |
| 286 | public PendingIntent contentIntent; |
| 287 | |
| 288 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 289 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 290 | * the "Clear All" button or by swiping it away individually. |
| 291 | * |
| 292 | * This probably shouldn't be launching an activity since several of those will be sent |
| 293 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | */ |
| 295 | public PendingIntent deleteIntent; |
| 296 | |
| 297 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 298 | * 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] | 299 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 300 | * <p> |
| 301 | * The system UI may choose to display a heads-up notification, instead of |
| 302 | * launching this intent, while the user is using the device. |
| 303 | * </p> |
| 304 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 305 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 306 | */ |
| 307 | public PendingIntent fullScreenIntent; |
| 308 | |
| 309 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 310 | * Text that summarizes this notification for accessibility services. |
| 311 | * |
| 312 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 313 | * accessibility services (where it serves as an audible announcement of the notification's |
| 314 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 315 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 316 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | */ |
| 318 | public CharSequence tickerText; |
| 319 | |
| 320 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 321 | * Formerly, a view showing the {@link #tickerText}. |
| 322 | * |
| 323 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 324 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 325 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 326 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 327 | |
| 328 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 329 | * The view that will represent this notification in the notification list (which is pulled |
| 330 | * down from the status bar). |
| 331 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 332 | * As of N, this field may be null. The notification view is determined by the inputs |
| 333 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 334 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 336 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | public RemoteViews contentView; |
| 338 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 339 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 340 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 341 | * opportunity to show more detail. The system UI may choose to show this |
| 342 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 343 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 344 | * 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] | 345 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 346 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 347 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 348 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 349 | public RemoteViews bigContentView; |
| 350 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 351 | |
| 352 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 353 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 354 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 355 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 356 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 357 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 358 | * 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] | 359 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 360 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 361 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 362 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 363 | public RemoteViews headsUpContentView; |
| 364 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 365 | private boolean mUsesStandardHeader; |
| 366 | |
| 367 | private static final ArraySet<Integer> STANDARD_LAYOUTS = new ArraySet<>(); |
| 368 | static { |
| 369 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_base); |
| 370 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_base); |
| 371 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_picture); |
| 372 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text); |
| 373 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_inbox); |
| 374 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging); |
| 375 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_media); |
| 376 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media); |
| 377 | STANDARD_LAYOUTS.add(R.layout.notification_template_ambient_header); |
| 378 | STANDARD_LAYOUTS.add(R.layout.notification_template_header); |
| 379 | STANDARD_LAYOUTS.add(R.layout.notification_template_material_ambient); |
| 380 | } |
| 381 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 382 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 383 | * A large bitmap to be shown in the notification content area. |
| 384 | * |
| 385 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 387 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 388 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | |
| 390 | /** |
| 391 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 392 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 394 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 395 | * </p> |
| 396 | * |
| 397 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 398 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 400 | * @deprecated use {@link NotificationChannel#getSound()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 402 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | public Uri sound; |
| 404 | |
| 405 | /** |
| 406 | * Use this constant as the value for audioStreamType to request that |
| 407 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 408 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 409 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 410 | * @deprecated Use {@link NotificationChannel#getAudioAttributes()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 412 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | public static final int STREAM_DEFAULT = -1; |
| 414 | |
| 415 | /** |
| 416 | * The audio stream type to use when playing the sound. |
| 417 | * Should be one of the STREAM_ constants from |
| 418 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 419 | * |
| 420 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 422 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | public int audioStreamType = STREAM_DEFAULT; |
| 424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 426 | * The default value of {@link #audioAttributes}. |
| 427 | */ |
| 428 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 429 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 430 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 431 | .build(); |
| 432 | |
| 433 | /** |
| 434 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 435 | * |
| 436 | * @deprecated use {@link NotificationChannel#getAudioAttributes()} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 437 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 438 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 439 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 440 | |
| 441 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 442 | * The pattern with which to vibrate. |
| 443 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | * <p> |
| 445 | * To vibrate the default pattern, see {@link #defaults}. |
| 446 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 447 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | * @see android.os.Vibrator#vibrate(long[],int) |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 449 | * @deprecated use {@link NotificationChannel#getVibrationPattern()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 451 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | public long[] vibrate; |
| 453 | |
| 454 | /** |
| 455 | * The color of the led. The hardware will do its best approximation. |
| 456 | * |
| 457 | * @see #FLAG_SHOW_LIGHTS |
| 458 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 459 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 461 | @ColorInt |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 462 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | public int ledARGB; |
| 464 | |
| 465 | /** |
| 466 | * The number of milliseconds for the LED to be on while it's flashing. |
| 467 | * The hardware will do its best approximation. |
| 468 | * |
| 469 | * @see #FLAG_SHOW_LIGHTS |
| 470 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 471 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 473 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | public int ledOnMS; |
| 475 | |
| 476 | /** |
| 477 | * The number of milliseconds for the LED to be off while it's flashing. |
| 478 | * The hardware will do its best approximation. |
| 479 | * |
| 480 | * @see #FLAG_SHOW_LIGHTS |
| 481 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 482 | * |
| 483 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 485 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | public int ledOffMS; |
| 487 | |
| 488 | /** |
| 489 | * Specifies which values should be taken from the defaults. |
| 490 | * <p> |
| 491 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 492 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 493 | * values, use {@link #DEFAULT_ALL}. |
| 494 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 495 | * |
| 496 | * @deprecated use {@link NotificationChannel#getSound()} and |
| 497 | * {@link NotificationChannel#shouldShowLights()} and |
| 498 | * {@link NotificationChannel#shouldVibrate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 500 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | public int defaults; |
| 502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | /** |
| 504 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 505 | * set if you want the LED on for this notification. |
| 506 | * <ul> |
| 507 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 508 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 509 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 510 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 511 | * be on and off to ledOnMS and ledOffMS.</li> |
| 512 | * </ul> |
| 513 | * <p> |
| 514 | * 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] | 515 | * 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] | 516 | * because they will be set to values that work on any given hardware. |
| 517 | * <p> |
| 518 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 519 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 520 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 522 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 524 | |
| 525 | /** |
| 526 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 527 | * set if this notification is in reference to something that is ongoing, |
| 528 | * like a phone call. It should not be set if this notification is in |
| 529 | * reference to something that happened at a particular point in time, |
| 530 | * like a missed phone call. |
| 531 | */ |
| 532 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 533 | |
| 534 | /** |
| 535 | * 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] | 536 | * the audio will be repeated until the notification is |
| 537 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 538 | */ |
| 539 | public static final int FLAG_INSISTENT = 0x00000004; |
| 540 | |
| 541 | /** |
| 542 | * 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] | 543 | * set if you would only like the sound, vibrate and ticker to be played |
| 544 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 545 | */ |
| 546 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 547 | |
| 548 | /** |
| 549 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 550 | * 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] | 551 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | */ |
| 553 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 554 | |
| 555 | /** |
| 556 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 557 | * set if the notification should not be canceled when the user clicks |
| 558 | * the Clear all button. |
| 559 | */ |
| 560 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 561 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 562 | /** |
| 563 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 564 | * set if this notification represents a currently running service. This |
| 565 | * will normally be set for you by {@link Service#startForeground}. |
| 566 | */ |
| 567 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 568 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 569 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 570 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 571 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 572 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 573 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 574 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 575 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 576 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 577 | /** |
| 578 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 579 | * set if this notification is relevant to the current device only |
| 580 | * and it is not recommended that it bridge to other devices. |
| 581 | */ |
| 582 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 583 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 584 | /** |
| 585 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 586 | * set if this notification is the group summary for a group of notifications. |
| 587 | * Grouped notifications may display in a cluster or stack on devices which |
| 588 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 589 | */ |
| 590 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 591 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 592 | /** |
| 593 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 594 | * set if this notification is the group summary for an auto-group of notifications. |
| 595 | * |
| 596 | * @hide |
| 597 | */ |
| 598 | @SystemApi |
| 599 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 600 | |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 601 | /** |
| 602 | * @hide |
| 603 | */ |
| 604 | public static final int FLAG_CAN_COLORIZE = 0x00000800; |
| 605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | public int flags; |
| 607 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 608 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 609 | @IntDef(prefix = { "PRIORITY_" }, value = { |
| 610 | PRIORITY_DEFAULT, |
| 611 | PRIORITY_LOW, |
| 612 | PRIORITY_MIN, |
| 613 | PRIORITY_HIGH, |
| 614 | PRIORITY_MAX |
| 615 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 616 | @Retention(RetentionPolicy.SOURCE) |
| 617 | public @interface Priority {} |
| 618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 620 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 621 | * notifications, use this value for all notifications. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 622 | * |
| 623 | * @deprecated use {@link NotificationManager#IMPORTANCE_DEFAULT} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 624 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 625 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 626 | public static final int PRIORITY_DEFAULT = 0; |
| 627 | |
| 628 | /** |
| 629 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 630 | * items smaller, or at a different position in the list, compared with your app's |
| 631 | * {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 632 | * |
| 633 | * @deprecated use {@link NotificationManager#IMPORTANCE_LOW} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 634 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 635 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 636 | public static final int PRIORITY_LOW = -1; |
| 637 | |
| 638 | /** |
| 639 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 640 | * circumstances, such as detailed notification logs. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 641 | * |
| 642 | * @deprecated use {@link NotificationManager#IMPORTANCE_MIN} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 643 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 644 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 645 | public static final int PRIORITY_MIN = -2; |
| 646 | |
| 647 | /** |
| 648 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 649 | * show these items larger, or at a different position in notification lists, compared with |
| 650 | * your app's {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 651 | * |
| 652 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 653 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 654 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 655 | public static final int PRIORITY_HIGH = 1; |
| 656 | |
| 657 | /** |
| 658 | * Highest {@link #priority}, for your application's most important items that require the |
| 659 | * user's prompt attention or input. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 660 | * |
| 661 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 662 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 663 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 664 | public static final int PRIORITY_MAX = 2; |
| 665 | |
| 666 | /** |
| 667 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 668 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 669 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 670 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 671 | * 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] | 672 | * system will make a determination about how to interpret this priority when presenting |
| 673 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 674 | * |
| 675 | * <p> |
| 676 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 677 | * as a heads-up notification. |
| 678 | * </p> |
| 679 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 680 | * @deprecated use {@link NotificationChannel#getImportance()} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 681 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 682 | @Priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 683 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 684 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 685 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 686 | /** |
| 687 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 688 | * to be applied by the standard Style templates when presenting this notification. |
| 689 | * |
| 690 | * The current template design constructs a colorful header image by overlaying the |
| 691 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 692 | * ignored. |
| 693 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 694 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 695 | public int color = COLOR_DEFAULT; |
| 696 | |
| 697 | /** |
| 698 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 699 | * any special color but instead use default colors when presenting this notification. |
| 700 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 701 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 702 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 703 | |
| 704 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 705 | * 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] | 706 | * @hide |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 707 | */ |
| 708 | @ColorInt |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 709 | public static final int COLOR_INVALID = 1; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 710 | |
| 711 | /** |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 712 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 713 | * 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] | 714 | * lockscreen). |
| 715 | * |
| 716 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 717 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 718 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 719 | * the appropriate user. |
| 720 | * |
| 721 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 722 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 723 | * To modify the public version of this notification—for example, to redact some portions—see |
| 724 | * {@link Builder#setPublicVersion(Notification)}. |
| 725 | * |
| 726 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 727 | * and ticker until the user has bypassed the lockscreen. |
| 728 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 729 | public @Visibility int visibility; |
| 730 | |
| 731 | /** @hide */ |
| 732 | @IntDef(prefix = { "VISIBILITY_" }, value = { |
| 733 | VISIBILITY_PUBLIC, |
| 734 | VISIBILITY_PRIVATE, |
| 735 | VISIBILITY_SECRET, |
| 736 | }) |
| 737 | @Retention(RetentionPolicy.SOURCE) |
| 738 | public @interface Visibility {} |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 739 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 740 | /** |
| 741 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 742 | * |
| 743 | * {@see #visibility} |
| 744 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 745 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 746 | |
| 747 | /** |
| 748 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 749 | * private information on secure lockscreens. |
| 750 | * |
| 751 | * {@see #visibility} |
| 752 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 753 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 754 | |
| 755 | /** |
| 756 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 757 | * |
| 758 | * {@see #visibility} |
| 759 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 760 | public static final int VISIBILITY_SECRET = -1; |
| 761 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 762 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 763 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 764 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 765 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 766 | |
| 767 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 768 | * Notification category: map turn-by-turn navigation. |
| 769 | */ |
| 770 | public static final String CATEGORY_NAVIGATION = "navigation"; |
| 771 | |
| 772 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 773 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 774 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 775 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 776 | |
| 777 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 778 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 779 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 780 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 781 | |
| 782 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 783 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 784 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 785 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 786 | |
| 787 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 788 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 789 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 790 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 791 | |
| 792 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 793 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 794 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 795 | public static final String CATEGORY_ALARM = "alarm"; |
| 796 | |
| 797 | /** |
| 798 | * Notification category: progress of a long-running background operation. |
| 799 | */ |
| 800 | public static final String CATEGORY_PROGRESS = "progress"; |
| 801 | |
| 802 | /** |
| 803 | * Notification category: social network or sharing update. |
| 804 | */ |
| 805 | public static final String CATEGORY_SOCIAL = "social"; |
| 806 | |
| 807 | /** |
| 808 | * Notification category: error in background operation or authentication status. |
| 809 | */ |
| 810 | public static final String CATEGORY_ERROR = "err"; |
| 811 | |
| 812 | /** |
| 813 | * Notification category: media transport control for playback. |
| 814 | */ |
| 815 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 816 | |
| 817 | /** |
| 818 | * Notification category: system or device status update. Reserved for system use. |
| 819 | */ |
| 820 | public static final String CATEGORY_SYSTEM = "sys"; |
| 821 | |
| 822 | /** |
| 823 | * Notification category: indication of running background service. |
| 824 | */ |
| 825 | public static final String CATEGORY_SERVICE = "service"; |
| 826 | |
| 827 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 828 | * Notification category: a specific, timely recommendation for a single thing. |
| 829 | * For example, a news app might want to recommend a news story it believes the user will |
| 830 | * want to read next. |
| 831 | */ |
| 832 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 833 | |
| 834 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 835 | * Notification category: ongoing information about device or contextual status. |
| 836 | */ |
| 837 | public static final String CATEGORY_STATUS = "status"; |
| 838 | |
| 839 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 840 | * Notification category: user-scheduled reminder. |
| 841 | */ |
| 842 | public static final String CATEGORY_REMINDER = "reminder"; |
| 843 | |
| 844 | /** |
Adora Zhang | aa90e87 | 2018-03-12 14:07:50 -0700 | [diff] [blame] | 845 | * Notification category: extreme car emergencies. |
| 846 | * @hide |
| 847 | */ |
| 848 | @SystemApi |
| 849 | public static final String CATEGORY_CAR_EMERGENCY = "car_emergency"; |
| 850 | |
| 851 | /** |
| 852 | * Notification category: car warnings. |
| 853 | * @hide |
| 854 | */ |
| 855 | @SystemApi |
| 856 | public static final String CATEGORY_CAR_WARNING = "car_warning"; |
| 857 | |
| 858 | /** |
| 859 | * Notification category: general car system information. |
| 860 | * @hide |
| 861 | */ |
| 862 | @SystemApi |
| 863 | public static final String CATEGORY_CAR_INFORMATION = "car_information"; |
| 864 | |
| 865 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 866 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 867 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 868 | */ |
| 869 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 870 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 871 | private String mGroupKey; |
| 872 | |
| 873 | /** |
| 874 | * Get the key used to group this notification into a cluster or stack |
| 875 | * with other notifications on devices which support such rendering. |
| 876 | */ |
| 877 | public String getGroup() { |
| 878 | return mGroupKey; |
| 879 | } |
| 880 | |
| 881 | private String mSortKey; |
| 882 | |
| 883 | /** |
| 884 | * Get a sort key that orders this notification among other notifications from the |
| 885 | * same package. This can be useful if an external sort was already applied and an app |
| 886 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 887 | * value, although providing different priorities in addition to providing sort key may |
| 888 | * cause this value to be ignored. |
| 889 | * |
| 890 | * <p>This sort key can also be used to order members of a notification group. See |
| 891 | * {@link Builder#setGroup}. |
| 892 | * |
| 893 | * @see String#compareTo(String) |
| 894 | */ |
| 895 | public String getSortKey() { |
| 896 | return mSortKey; |
| 897 | } |
| 898 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 899 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 900 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 901 | * <p> |
| 902 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 903 | * APIs, and are intended to be used by |
| 904 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 905 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 906 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 907 | public Bundle extras = new Bundle(); |
| 908 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 909 | /** |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 910 | * All pending intents in the notification as the system needs to be able to access them but |
| 911 | * 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] | 912 | * custom parcelable objects. |
| 913 | * |
| 914 | * @hide |
| 915 | */ |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 916 | public ArraySet<PendingIntent> allPendingIntents; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 917 | |
| 918 | /** |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 919 | * Token identifying the notification that is applying doze/bgcheck whitelisting to the |
| 920 | * pending intents inside of it, so only those will get the behavior. |
| 921 | * |
| 922 | * @hide |
| 923 | */ |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 924 | private IBinder mWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 925 | |
| 926 | /** |
| 927 | * Must be set by a process to start associating tokens with Notification objects |
| 928 | * coming in to it. This is set by NotificationManagerService. |
| 929 | * |
| 930 | * @hide |
| 931 | */ |
| 932 | static public IBinder processWhitelistToken; |
| 933 | |
| 934 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 935 | * {@link #extras} key: this is the title of the notification, |
| 936 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 937 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 938 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 939 | |
| 940 | /** |
| 941 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 942 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 943 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 944 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 945 | |
| 946 | /** |
| 947 | * {@link #extras} key: this is the main text payload, as supplied to |
| 948 | * {@link Builder#setContentText(CharSequence)}. |
| 949 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 950 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 951 | |
| 952 | /** |
| 953 | * {@link #extras} key: this is a third line of text, as supplied to |
| 954 | * {@link Builder#setSubText(CharSequence)}. |
| 955 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 956 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 957 | |
| 958 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 959 | * {@link #extras} key: this is the remote input history, as supplied to |
| 960 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
Adrian Roos | 005e774 | 2016-04-13 15:02:20 -0700 | [diff] [blame] | 961 | * |
| 962 | * Apps can fill this through {@link Builder#setRemoteInputHistory(CharSequence[])} |
| 963 | * with the most recent inputs that have been sent through a {@link RemoteInput} of this |
| 964 | * Notification and are expected to clear it once the it is no longer relevant (e.g. for chat |
| 965 | * notifications once the other party has responded). |
| 966 | * |
| 967 | * The extra with this key is of type CharSequence[] and contains the most recent entry at |
| 968 | * the 0 index, the second most recent at the 1 index, etc. |
| 969 | * |
| 970 | * @see Builder#setRemoteInputHistory(CharSequence[]) |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 971 | */ |
| 972 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 973 | |
| 974 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 975 | * {@link #extras} key: boolean as supplied to |
| 976 | * {@link Builder#setShowRemoteInputSpinner(boolean)}. |
| 977 | * |
| 978 | * If set to true, then the view displaying the remote input history from |
| 979 | * {@link Builder#setRemoteInputHistory(CharSequence[])} will have a progress spinner. |
| 980 | * |
| 981 | * @see Builder#setShowRemoteInputSpinner(boolean) |
| 982 | * @hide |
| 983 | */ |
| 984 | public static final String EXTRA_SHOW_REMOTE_INPUT_SPINNER = "android.remoteInputSpinner"; |
| 985 | |
| 986 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 987 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 988 | * {@link Builder#setContentInfo(CharSequence)}. |
| 989 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 990 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 991 | |
| 992 | /** |
| 993 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 994 | * alongside expanded notifications, as supplied to (e.g.) |
| 995 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 996 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 997 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 998 | |
| 999 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1000 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 1001 | * {@link BigTextStyle} notification, as supplied to |
| 1002 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 1003 | */ |
| 1004 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 1005 | |
| 1006 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1007 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 1008 | * supplied to {@link Builder#setSmallIcon(int)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1009 | * |
| 1010 | * @deprecated Use {@link #getSmallIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1011 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1012 | @Deprecated |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1013 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1014 | |
| 1015 | /** |
| 1016 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 1017 | * notification payload, as |
| 1018 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1019 | * |
| 1020 | * @deprecated Use {@link #getLargeIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1021 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 1022 | @Deprecated |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1023 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1024 | |
| 1025 | /** |
| 1026 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 1027 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 1028 | * shown in its expanded form, as supplied to |
| 1029 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 1030 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1031 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1032 | |
| 1033 | /** |
| 1034 | * {@link #extras} key: this is the progress value supplied to |
| 1035 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1036 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1037 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1038 | |
| 1039 | /** |
| 1040 | * {@link #extras} key: this is the maximum value supplied to |
| 1041 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1042 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1043 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1044 | |
| 1045 | /** |
| 1046 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 1047 | * {@link Builder#setProgress(int, int, boolean)}. |
| 1048 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1049 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1050 | |
| 1051 | /** |
| 1052 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 1053 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 1054 | * {@link Builder#setUsesChronometer(boolean)}. |
| 1055 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1056 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1057 | |
| 1058 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1059 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 1060 | * 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] | 1061 | * This extra is a boolean. The default is false. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1062 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1063 | public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1064 | |
| 1065 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1066 | * {@link #extras} key: whether {@link #when} should be shown, |
| 1067 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 1068 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1069 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1070 | |
| 1071 | /** |
| 1072 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 1073 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 1074 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1075 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1076 | |
| 1077 | /** |
| 1078 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 1079 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 1080 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1081 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1082 | |
| 1083 | /** |
| 1084 | * {@link #extras} key: A string representing the name of the specific |
| 1085 | * {@link android.app.Notification.Style} used to create this notification. |
| 1086 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 1087 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1088 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1089 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 1090 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 1091 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1092 | * |
| 1093 | * @deprecated the actual objects are now in {@link #EXTRA_PEOPLE_LIST} |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1094 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1095 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1096 | |
| 1097 | /** |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1098 | * {@link #extras} key: An arrayList of {@link Person} objects containing the people that |
| 1099 | * this notification relates to. |
| 1100 | */ |
| 1101 | public static final String EXTRA_PEOPLE_LIST = "android.people.list"; |
| 1102 | |
| 1103 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1104 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 1105 | * Only available to notifications coming from the android package. |
| 1106 | * @hide |
| 1107 | */ |
Maurice Lam | 96c1003 | 2017-03-29 15:42:38 -0700 | [diff] [blame] | 1108 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1109 | @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1110 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 1111 | |
| 1112 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1113 | * {@link #extras} key: A |
| 1114 | * {@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] | 1115 | * in the background when the notification is selected. Used on television platforms. |
| 1116 | * The URI must point to an image stream suitable for passing into |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1117 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1118 | * BitmapFactory.decodeStream}; all other content types will be ignored. |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1119 | */ |
| 1120 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1121 | |
| 1122 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1123 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 1124 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1125 | * {@link android.app.Notification.MediaStyle} notification. |
| 1126 | */ |
| 1127 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1128 | |
| 1129 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 1130 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 1131 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 1132 | */ |
| 1133 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1134 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 1135 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1136 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 1137 | * direct replies |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1138 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1139 | * {@link CharSequence} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1140 | * |
| 1141 | * @deprecated use {@link #EXTRA_MESSAGING_PERSON} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1142 | */ |
| 1143 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1144 | |
| 1145 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1146 | * {@link #extras} key: the person to be displayed for all messages sent by the user including |
| 1147 | * direct replies |
| 1148 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1149 | * {@link Person} |
| 1150 | */ |
| 1151 | public static final String EXTRA_MESSAGING_PERSON = "android.messagingUser"; |
| 1152 | |
| 1153 | /** |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1154 | * {@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] | 1155 | * represented by a {@link android.app.Notification.MessagingStyle} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1156 | */ |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1157 | public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1158 | |
| 1159 | /** |
| 1160 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 1161 | * bundles provided by a |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1162 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1163 | * array of bundles. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1164 | */ |
| 1165 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 1166 | |
| 1167 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 1168 | * {@link #extras} key: an array of |
| 1169 | * {@link android.app.Notification.MessagingStyle#addHistoricMessage historic} |
| 1170 | * {@link android.app.Notification.MessagingStyle.Message} bundles provided by a |
| 1171 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1172 | * array of bundles. |
| 1173 | */ |
| 1174 | public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1175 | |
| 1176 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 1177 | * {@link #extras} key: whether the {@link android.app.Notification.MessagingStyle} notification |
| 1178 | * represents a group conversation. |
| 1179 | */ |
| 1180 | public static final String EXTRA_IS_GROUP_CONVERSATION = "android.isGroupConversation"; |
| 1181 | |
| 1182 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1183 | * {@link #extras} key: whether the notification should be colorized as |
| 1184 | * supplied to {@link Builder#setColorized(boolean)}}. |
| 1185 | */ |
| 1186 | public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1187 | |
| 1188 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1189 | * @hide |
| 1190 | */ |
| 1191 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1192 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 1193 | /** |
| 1194 | * @hide |
| 1195 | */ |
| 1196 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1197 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1198 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 1199 | * @hide |
| 1200 | */ |
| 1201 | public static final String EXTRA_REDUCED_IMAGES = "android.reduced.images"; |
| 1202 | |
| 1203 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1204 | * {@link #extras} key: the audio contents of this notification. |
| 1205 | * |
| 1206 | * This is for use when rendering the notification on an audio-focused interface; |
| 1207 | * the audio contents are a complete sound sample that contains the contents/body of the |
| 1208 | * notification. This may be used in substitute of a Text-to-Speech reading of the |
| 1209 | * notification. For example if the notification represents a voice message this should point |
| 1210 | * to the audio of that message. |
| 1211 | * |
| 1212 | * The data stored under this key should be a String representation of a Uri that contains the |
| 1213 | * audio contents in one of the following formats: WAV, PCM 16-bit, AMR-WB. |
| 1214 | * |
| 1215 | * This extra is unnecessary if you are using {@code MessagingStyle} since each {@code Message} |
| 1216 | * has a field for holding data URI. That field can be used for audio. |
| 1217 | * See {@code Message#setData}. |
| 1218 | * |
| 1219 | * Example usage: |
| 1220 | * <pre> |
| 1221 | * {@code |
| 1222 | * Notification.Builder myBuilder = (build your Notification as normal); |
| 1223 | * myBuilder.getExtras().putString(EXTRA_AUDIO_CONTENTS_URI, myAudioUri.toString()); |
| 1224 | * } |
| 1225 | * </pre> |
| 1226 | */ |
| 1227 | public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1228 | |
Dan Sandler | 80eaa59 | 2016-04-14 23:34:54 -0400 | [diff] [blame] | 1229 | /** @hide */ |
| 1230 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1231 | @RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME) |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1232 | public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1233 | |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1234 | /** |
Julia Reynolds | 3c7de11 | 2018-03-28 09:33:13 -0400 | [diff] [blame] | 1235 | * This is set on the notifications shown by system_server about apps running foreground |
| 1236 | * services. It indicates that the notification should be shown |
| 1237 | * only if any of the given apps do not already have a properly tagged |
| 1238 | * {@link #FLAG_FOREGROUND_SERVICE} notification currently visible to the user. |
| 1239 | * This is a string array of all package names of the apps. |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1240 | * @hide |
| 1241 | */ |
| 1242 | public static final String EXTRA_FOREGROUND_APPS = "android.foregroundApps"; |
| 1243 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1244 | private Icon mSmallIcon; |
| 1245 | private Icon mLargeIcon; |
| 1246 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1247 | private String mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1248 | private long mTimeout; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1249 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1250 | private String mShortcutId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1251 | private CharSequence mSettingsText; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1252 | |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1253 | /** @hide */ |
| 1254 | @IntDef(prefix = { "GROUP_ALERT_" }, value = { |
| 1255 | GROUP_ALERT_ALL, GROUP_ALERT_CHILDREN, GROUP_ALERT_SUMMARY |
| 1256 | }) |
| 1257 | @Retention(RetentionPolicy.SOURCE) |
| 1258 | public @interface GroupAlertBehavior {} |
| 1259 | |
| 1260 | /** |
| 1261 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all notifications in a |
| 1262 | * group with sound or vibration ought to make sound or vibrate (respectively), so this |
| 1263 | * notification will not be muted when it is in a group. |
| 1264 | */ |
| 1265 | public static final int GROUP_ALERT_ALL = 0; |
| 1266 | |
| 1267 | /** |
| 1268 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all children |
| 1269 | * notification in a group should be silenced (no sound or vibration) even if they are posted |
| 1270 | * 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] | 1271 | * mute this notification if this notification is a group child. This must be applied to all |
| 1272 | * children notifications you want to mute. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1273 | * |
| 1274 | * <p> For example, you might want to use this constant if you post a number of children |
| 1275 | * notifications at once (say, after a periodic sync), and only need to notify the user |
| 1276 | * audibly once. |
| 1277 | */ |
| 1278 | public static final int GROUP_ALERT_SUMMARY = 1; |
| 1279 | |
| 1280 | /** |
| 1281 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that the summary |
| 1282 | * notification in a group should be silenced (no sound or vibration) even if they are |
| 1283 | * posted to a {@link NotificationChannel} that has sound and/or vibration. Use this constant |
| 1284 | * to mute this notification if this notification is a group summary. |
| 1285 | * |
| 1286 | * <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] | 1287 | * in your group have content and the summary is only used to visually group notifications |
| 1288 | * rather than to alert the user that new information is available. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1289 | */ |
| 1290 | public static final int GROUP_ALERT_CHILDREN = 2; |
| 1291 | |
Julia Reynolds | 2f431e2 | 2017-06-07 14:12:09 +0000 | [diff] [blame] | 1292 | private int mGroupAlertBehavior = GROUP_ALERT_ALL; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1293 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1294 | /** |
| 1295 | * If this notification is being shown as a badge, always show as a number. |
| 1296 | */ |
| 1297 | public static final int BADGE_ICON_NONE = 0; |
| 1298 | |
| 1299 | /** |
| 1300 | * If this notification is being shown as a badge, use the {@link #getSmallIcon()} to |
| 1301 | * represent this notification. |
| 1302 | */ |
| 1303 | public static final int BADGE_ICON_SMALL = 1; |
| 1304 | |
| 1305 | /** |
| 1306 | * If this notification is being shown as a badge, use the {@link #getLargeIcon()} to |
| 1307 | * represent this notification. |
| 1308 | */ |
| 1309 | public static final int BADGE_ICON_LARGE = 2; |
Julia Reynolds | 7d5b4da | 2017-03-20 10:18:49 -0400 | [diff] [blame] | 1310 | private int mBadgeIcon = BADGE_ICON_NONE; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1311 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1312 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1313 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 1314 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 1315 | * selected by the user. |
| 1316 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1317 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 1318 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 1319 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1320 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1321 | public static class Action implements Parcelable { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1322 | /** |
| 1323 | * {@link #extras} key: Keys to a {@link Parcelable} {@link ArrayList} of |
| 1324 | * {@link RemoteInput}s. |
| 1325 | * |
| 1326 | * This is intended for {@link RemoteInput}s that only accept data, meaning |
| 1327 | * {@link RemoteInput#getAllowFreeFormInput} is false, {@link RemoteInput#getChoices} |
| 1328 | * is null or empty, and {@link RemoteInput#getAllowedDataTypes is non-null and not |
| 1329 | * empty. These {@link RemoteInput}s will be ignored by devices that do not |
| 1330 | * support non-text-based {@link RemoteInput}s. See {@link Builder#build}. |
| 1331 | * |
| 1332 | * You can test if a RemoteInput matches these constraints using |
| 1333 | * {@link RemoteInput#isDataOnly}. |
| 1334 | */ |
| 1335 | private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1336 | |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1337 | /** |
| 1338 | * {@link }: No semantic action defined. |
| 1339 | */ |
| 1340 | public static final int SEMANTIC_ACTION_NONE = 0; |
| 1341 | |
| 1342 | /** |
| 1343 | * {@code SemanticAction}: Reply to a conversation, chat, group, or wherever replies |
| 1344 | * may be appropriate. |
| 1345 | */ |
| 1346 | public static final int SEMANTIC_ACTION_REPLY = 1; |
| 1347 | |
| 1348 | /** |
| 1349 | * {@code SemanticAction}: Mark content as read. |
| 1350 | */ |
| 1351 | public static final int SEMANTIC_ACTION_MARK_AS_READ = 2; |
| 1352 | |
| 1353 | /** |
| 1354 | * {@code SemanticAction}: Mark content as unread. |
| 1355 | */ |
| 1356 | public static final int SEMANTIC_ACTION_MARK_AS_UNREAD = 3; |
| 1357 | |
| 1358 | /** |
| 1359 | * {@code SemanticAction}: Delete the content associated with the notification. This |
| 1360 | * could mean deleting an email, message, etc. |
| 1361 | */ |
| 1362 | public static final int SEMANTIC_ACTION_DELETE = 4; |
| 1363 | |
| 1364 | /** |
| 1365 | * {@code SemanticAction}: Archive the content associated with the notification. This |
| 1366 | * could mean archiving an email, message, etc. |
| 1367 | */ |
| 1368 | public static final int SEMANTIC_ACTION_ARCHIVE = 5; |
| 1369 | |
| 1370 | /** |
| 1371 | * {@code SemanticAction}: Mute the content associated with the notification. This could |
| 1372 | * mean silencing a conversation or currently playing media. |
| 1373 | */ |
| 1374 | public static final int SEMANTIC_ACTION_MUTE = 6; |
| 1375 | |
| 1376 | /** |
| 1377 | * {@code SemanticAction}: Unmute the content associated with the notification. This could |
| 1378 | * mean un-silencing a conversation or currently playing media. |
| 1379 | */ |
| 1380 | public static final int SEMANTIC_ACTION_UNMUTE = 7; |
| 1381 | |
| 1382 | /** |
| 1383 | * {@code SemanticAction}: Mark content with a thumbs up. |
| 1384 | */ |
| 1385 | public static final int SEMANTIC_ACTION_THUMBS_UP = 8; |
| 1386 | |
| 1387 | /** |
| 1388 | * {@code SemanticAction}: Mark content with a thumbs down. |
| 1389 | */ |
| 1390 | public static final int SEMANTIC_ACTION_THUMBS_DOWN = 9; |
| 1391 | |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 1392 | /** |
| 1393 | * {@code SemanticAction}: Call a contact, group, etc. |
| 1394 | */ |
| 1395 | public static final int SEMANTIC_ACTION_CALL = 10; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1396 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1397 | private final Bundle mExtras; |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1398 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1399 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1400 | private boolean mAllowGeneratedReplies = true; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1401 | private final @SemanticAction int mSemanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1402 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1403 | /** |
| 1404 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1405 | * |
| 1406 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1407 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1408 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1409 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1410 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1411 | /** |
| 1412 | * Title of the action. |
| 1413 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1414 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1415 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1416 | /** |
| 1417 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1418 | * may be rendered in a disabled presentation by the system UI. |
| 1419 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1420 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1421 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1422 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1423 | if (in.readInt() != 0) { |
| 1424 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1425 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1426 | icon = mIcon.getResId(); |
| 1427 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1428 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1429 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1430 | if (in.readInt() == 1) { |
| 1431 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1432 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1433 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1434 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1435 | mAllowGeneratedReplies = in.readInt() == 1; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1436 | mSemanticAction = in.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1437 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1438 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1439 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1440 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1441 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1442 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1443 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1444 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true, |
| 1445 | SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1448 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1449 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1450 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1451 | @SemanticAction int semanticAction) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1452 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1453 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1454 | this.icon = icon.getResId(); |
| 1455 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1456 | this.title = title; |
| 1457 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1458 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1459 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1460 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1461 | this.mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1465 | * Return an icon representing the action. |
| 1466 | */ |
| 1467 | public Icon getIcon() { |
| 1468 | if (mIcon == null && icon != 0) { |
| 1469 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1470 | mIcon = Icon.createWithResource("", icon); |
| 1471 | } |
| 1472 | return mIcon; |
| 1473 | } |
| 1474 | |
| 1475 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1476 | * Get additional metadata carried around with this Action. |
| 1477 | */ |
| 1478 | public Bundle getExtras() { |
| 1479 | return mExtras; |
| 1480 | } |
| 1481 | |
| 1482 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1483 | * Return whether the platform should automatically generate possible replies for this |
| 1484 | * {@link Action} |
| 1485 | */ |
| 1486 | public boolean getAllowGeneratedReplies() { |
| 1487 | return mAllowGeneratedReplies; |
| 1488 | } |
| 1489 | |
| 1490 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1491 | * 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] | 1492 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1493 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1494 | */ |
| 1495 | public RemoteInput[] getRemoteInputs() { |
| 1496 | return mRemoteInputs; |
| 1497 | } |
| 1498 | |
| 1499 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1500 | * Returns the {@code SemanticAction} associated with this {@link Action}. A |
| 1501 | * {@code SemanticAction} denotes what an {@link Action}'s {@link PendingIntent} will do |
| 1502 | * (eg. reply, mark as read, delete, etc). |
| 1503 | */ |
| 1504 | public @SemanticAction int getSemanticAction() { |
| 1505 | return mSemanticAction; |
| 1506 | } |
| 1507 | |
| 1508 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1509 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1510 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1511 | * {@link RemoteInput#isDataOnly}. |
| 1512 | * |
Shane Brennan | f670d6c | 2017-04-25 13:05:45 -0700 | [diff] [blame] | 1513 | * Returns null if there are no data-only remote inputs. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1514 | * |
| 1515 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1516 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1517 | */ |
| 1518 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1519 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1520 | } |
| 1521 | |
| 1522 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1523 | * Builder class for {@link Action} objects. |
| 1524 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1525 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1526 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1527 | private final CharSequence mTitle; |
| 1528 | private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1529 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1530 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1531 | private ArrayList<RemoteInput> mRemoteInputs; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1532 | private @SemanticAction int mSemanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1533 | |
| 1534 | /** |
| 1535 | * Construct a new builder for {@link Action} object. |
| 1536 | * @param icon icon to show for this action |
| 1537 | * @param title the title of the action |
| 1538 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1539 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1540 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1541 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1542 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | /** |
| 1546 | * Construct a new builder for {@link Action} object. |
| 1547 | * @param icon icon to show for this action |
| 1548 | * @param title the title of the action |
| 1549 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1550 | */ |
| 1551 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1552 | this(icon, title, intent, new Bundle(), null, true, SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | /** |
| 1556 | * Construct a new builder for {@link Action} object using the fields from an |
| 1557 | * {@link Action}. |
| 1558 | * @param action the action to read fields from. |
| 1559 | */ |
| 1560 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1561 | this(action.getIcon(), action.title, action.actionIntent, |
| 1562 | new Bundle(action.mExtras), action.getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1563 | action.getAllowGeneratedReplies(), action.getSemanticAction()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1566 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1567 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1568 | @SemanticAction int semanticAction) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1569 | mIcon = icon; |
| 1570 | mTitle = title; |
| 1571 | mIntent = intent; |
| 1572 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1573 | if (remoteInputs != null) { |
| 1574 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1575 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1576 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1577 | mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1578 | mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | /** |
| 1582 | * Merge additional metadata into this builder. |
| 1583 | * |
| 1584 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1585 | * |
| 1586 | * @see Notification.Action#extras |
| 1587 | */ |
| 1588 | public Builder addExtras(Bundle extras) { |
| 1589 | if (extras != null) { |
| 1590 | mExtras.putAll(extras); |
| 1591 | } |
| 1592 | return this; |
| 1593 | } |
| 1594 | |
| 1595 | /** |
| 1596 | * Get the metadata Bundle used by this Builder. |
| 1597 | * |
| 1598 | * <p>The returned Bundle is shared with this Builder. |
| 1599 | */ |
| 1600 | public Bundle getExtras() { |
| 1601 | return mExtras; |
| 1602 | } |
| 1603 | |
| 1604 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1605 | * Add an input to be collected from the user when this action is sent. |
| 1606 | * Response values can be retrieved from the fired intent by using the |
| 1607 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1608 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1609 | * @return this object for method chaining |
| 1610 | */ |
| 1611 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1612 | if (mRemoteInputs == null) { |
| 1613 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1614 | } |
| 1615 | mRemoteInputs.add(remoteInput); |
| 1616 | return this; |
| 1617 | } |
| 1618 | |
| 1619 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1620 | * Set whether the platform should automatically generate possible replies to add to |
| 1621 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1622 | * {@link RemoteInput}, this has no effect. |
| 1623 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1624 | * otherwise |
| 1625 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1626 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1627 | */ |
| 1628 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1629 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1630 | return this; |
| 1631 | } |
| 1632 | |
| 1633 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1634 | * Sets the {@code SemanticAction} for this {@link Action}. A |
| 1635 | * {@code SemanticAction} denotes what an {@link Action}'s |
| 1636 | * {@link PendingIntent} will do (eg. reply, mark as read, delete, etc). |
| 1637 | * @param semanticAction a SemanticAction defined within {@link Action} with |
| 1638 | * {@code SEMANTIC_ACTION_} prefixes |
| 1639 | * @return this object for method chaining |
| 1640 | */ |
| 1641 | public Builder setSemanticAction(@SemanticAction int semanticAction) { |
| 1642 | mSemanticAction = semanticAction; |
| 1643 | return this; |
| 1644 | } |
| 1645 | |
| 1646 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1647 | * Apply an extender to this action builder. Extenders may be used to add |
| 1648 | * metadata or change options on this builder. |
| 1649 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1650 | public Builder extend(Extender extender) { |
| 1651 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1652 | return this; |
| 1653 | } |
| 1654 | |
| 1655 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1656 | * Combine all of the options that have been set and return a new {@link Action} |
| 1657 | * object. |
| 1658 | * @return the built action |
| 1659 | */ |
| 1660 | public Action build() { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1661 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1662 | RemoteInput[] previousDataInputs = |
| 1663 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1664 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1665 | for (RemoteInput input : previousDataInputs) { |
| 1666 | dataOnlyInputs.add(input); |
| 1667 | } |
| 1668 | } |
| 1669 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1670 | if (mRemoteInputs != null) { |
| 1671 | for (RemoteInput input : mRemoteInputs) { |
| 1672 | if (input.isDataOnly()) { |
| 1673 | dataOnlyInputs.add(input); |
| 1674 | } else { |
| 1675 | textInputs.add(input); |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | if (!dataOnlyInputs.isEmpty()) { |
| 1680 | RemoteInput[] dataInputsArr = |
| 1681 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1682 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1683 | } |
| 1684 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1685 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1686 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1687 | mAllowGeneratedReplies, mSemanticAction); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1688 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1689 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1690 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1691 | @Override |
| 1692 | public Action clone() { |
| 1693 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1694 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1695 | title, |
| 1696 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1697 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1698 | getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1699 | getAllowGeneratedReplies(), |
| 1700 | getSemanticAction()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1701 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1702 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1703 | @Override |
| 1704 | public int describeContents() { |
| 1705 | return 0; |
| 1706 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1707 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1708 | @Override |
| 1709 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1710 | final Icon ic = getIcon(); |
| 1711 | if (ic != null) { |
| 1712 | out.writeInt(1); |
| 1713 | ic.writeToParcel(out, 0); |
| 1714 | } else { |
| 1715 | out.writeInt(0); |
| 1716 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1717 | TextUtils.writeToParcel(title, out, flags); |
| 1718 | if (actionIntent != null) { |
| 1719 | out.writeInt(1); |
| 1720 | actionIntent.writeToParcel(out, flags); |
| 1721 | } else { |
| 1722 | out.writeInt(0); |
| 1723 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1724 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1725 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1726 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1727 | out.writeInt(mSemanticAction); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1728 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1729 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1730 | public static final Parcelable.Creator<Action> CREATOR = |
| 1731 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1732 | public Action createFromParcel(Parcel in) { |
| 1733 | return new Action(in); |
| 1734 | } |
| 1735 | public Action[] newArray(int size) { |
| 1736 | return new Action[size]; |
| 1737 | } |
| 1738 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1739 | |
| 1740 | /** |
| 1741 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1742 | * metadata or change options on an action builder. |
| 1743 | */ |
| 1744 | public interface Extender { |
| 1745 | /** |
| 1746 | * Apply this extender to a notification action builder. |
| 1747 | * @param builder the builder to be modified. |
| 1748 | * @return the build object for chaining. |
| 1749 | */ |
| 1750 | public Builder extend(Builder builder); |
| 1751 | } |
| 1752 | |
| 1753 | /** |
| 1754 | * Wearable extender for notification actions. To add extensions to an action, |
| 1755 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1756 | * the {@code WearableExtender()} constructor and apply it to a |
| 1757 | * {@link android.app.Notification.Action.Builder} using |
| 1758 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1759 | * |
| 1760 | * <pre class="prettyprint"> |
| 1761 | * Notification.Action action = new Notification.Action.Builder( |
| 1762 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1763 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1764 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1765 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1766 | */ |
| 1767 | public static final class WearableExtender implements Extender { |
| 1768 | /** Notification action extra which contains wearable extensions */ |
| 1769 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1770 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1771 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1772 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1773 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1774 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1775 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1776 | |
| 1777 | // Flags bitwise-ored to mFlags |
| 1778 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1779 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1780 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1781 | |
| 1782 | // Default value for flags integer |
| 1783 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1784 | |
| 1785 | private int mFlags = DEFAULT_FLAGS; |
| 1786 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1787 | private CharSequence mInProgressLabel; |
| 1788 | private CharSequence mConfirmLabel; |
| 1789 | private CharSequence mCancelLabel; |
| 1790 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1791 | /** |
| 1792 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1793 | * options. |
| 1794 | */ |
| 1795 | public WearableExtender() { |
| 1796 | } |
| 1797 | |
| 1798 | /** |
| 1799 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1800 | * wearable options present in an existing notification action. |
| 1801 | * @param action the notification action to inspect. |
| 1802 | */ |
| 1803 | public WearableExtender(Action action) { |
| 1804 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1805 | if (wearableBundle != null) { |
| 1806 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1807 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1808 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1809 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * Apply wearable extensions to a notification action that is being built. This is |
| 1815 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1816 | * method of {@link android.app.Notification.Action.Builder}. |
| 1817 | */ |
| 1818 | @Override |
| 1819 | public Action.Builder extend(Action.Builder builder) { |
| 1820 | Bundle wearableBundle = new Bundle(); |
| 1821 | |
| 1822 | if (mFlags != DEFAULT_FLAGS) { |
| 1823 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1824 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1825 | if (mInProgressLabel != null) { |
| 1826 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1827 | } |
| 1828 | if (mConfirmLabel != null) { |
| 1829 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1830 | } |
| 1831 | if (mCancelLabel != null) { |
| 1832 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1833 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1834 | |
| 1835 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1836 | return builder; |
| 1837 | } |
| 1838 | |
| 1839 | @Override |
| 1840 | public WearableExtender clone() { |
| 1841 | WearableExtender that = new WearableExtender(); |
| 1842 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1843 | that.mInProgressLabel = this.mInProgressLabel; |
| 1844 | that.mConfirmLabel = this.mConfirmLabel; |
| 1845 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1846 | return that; |
| 1847 | } |
| 1848 | |
| 1849 | /** |
| 1850 | * Set whether this action is available when the wearable device is not connected to |
| 1851 | * a companion device. The user can still trigger this action when the wearable device is |
| 1852 | * offline, but a visual hint will indicate that the action may not be available. |
| 1853 | * Defaults to true. |
| 1854 | */ |
| 1855 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1856 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1857 | return this; |
| 1858 | } |
| 1859 | |
| 1860 | /** |
| 1861 | * Get whether this action is available when the wearable device is not connected to |
| 1862 | * a companion device. The user can still trigger this action when the wearable device is |
| 1863 | * offline, but a visual hint will indicate that the action may not be available. |
| 1864 | * Defaults to true. |
| 1865 | */ |
| 1866 | public boolean isAvailableOffline() { |
| 1867 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1868 | } |
| 1869 | |
| 1870 | private void setFlag(int mask, boolean value) { |
| 1871 | if (value) { |
| 1872 | mFlags |= mask; |
| 1873 | } else { |
| 1874 | mFlags &= ~mask; |
| 1875 | } |
| 1876 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1877 | |
| 1878 | /** |
| 1879 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1880 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1881 | * |
| 1882 | * @param label the label to display while the action is being prepared to execute |
| 1883 | * @return this object for method chaining |
| 1884 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1885 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1886 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1887 | mInProgressLabel = label; |
| 1888 | return this; |
| 1889 | } |
| 1890 | |
| 1891 | /** |
| 1892 | * Get the label to display while the wearable is preparing to automatically execute |
| 1893 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1894 | * |
| 1895 | * @return the label to display while the action is being prepared to execute |
| 1896 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1897 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1898 | public CharSequence getInProgressLabel() { |
| 1899 | return mInProgressLabel; |
| 1900 | } |
| 1901 | |
| 1902 | /** |
| 1903 | * Set a label to display to confirm that the action should be executed. |
| 1904 | * This is usually an imperative verb like "Send". |
| 1905 | * |
| 1906 | * @param label the label to confirm the action should be executed |
| 1907 | * @return this object for method chaining |
| 1908 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1909 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1910 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1911 | mConfirmLabel = label; |
| 1912 | return this; |
| 1913 | } |
| 1914 | |
| 1915 | /** |
| 1916 | * Get the label to display to confirm that the action should be executed. |
| 1917 | * This is usually an imperative verb like "Send". |
| 1918 | * |
| 1919 | * @return the label to confirm the action should be executed |
| 1920 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1921 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1922 | public CharSequence getConfirmLabel() { |
| 1923 | return mConfirmLabel; |
| 1924 | } |
| 1925 | |
| 1926 | /** |
| 1927 | * Set a label to display to cancel the action. |
| 1928 | * This is usually an imperative verb, like "Cancel". |
| 1929 | * |
| 1930 | * @param label the label to display to cancel the action |
| 1931 | * @return this object for method chaining |
| 1932 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1933 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1934 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1935 | mCancelLabel = label; |
| 1936 | return this; |
| 1937 | } |
| 1938 | |
| 1939 | /** |
| 1940 | * Get the label to display to cancel the action. |
| 1941 | * This is usually an imperative verb like "Cancel". |
| 1942 | * |
| 1943 | * @return the label to display to cancel the action |
| 1944 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1945 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1946 | public CharSequence getCancelLabel() { |
| 1947 | return mCancelLabel; |
| 1948 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1949 | |
| 1950 | /** |
| 1951 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 1952 | * platform that it can generate the appropriate transitions. |
| 1953 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 1954 | * an activity and transitions should be generated, false otherwise. |
| 1955 | * @return this object for method chaining |
| 1956 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1957 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1958 | boolean hintLaunchesActivity) { |
| 1959 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 1960 | return this; |
| 1961 | } |
| 1962 | |
| 1963 | /** |
| 1964 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 1965 | * platform that it can generate the appropriate transitions |
| 1966 | * @return {@code true} if the content intent will launch an activity and transitions |
| 1967 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 1968 | * never set. |
| 1969 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1970 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1971 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 1972 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1973 | |
| 1974 | /** |
| 1975 | * Set a hint that this Action should be displayed inline. |
| 1976 | * |
| 1977 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 1978 | * otherwise |
| 1979 | * @return this object for method chaining |
| 1980 | */ |
| 1981 | public WearableExtender setHintDisplayActionInline( |
| 1982 | boolean hintDisplayInline) { |
| 1983 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 1984 | return this; |
| 1985 | } |
| 1986 | |
| 1987 | /** |
| 1988 | * Get a hint that this Action should be displayed inline. |
| 1989 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 1990 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1991 | * otherwise. The default value is {@code false} if this was never set. |
| 1992 | */ |
| 1993 | public boolean getHintDisplayActionInline() { |
| 1994 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 1995 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1996 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1997 | |
| 1998 | /** |
| 1999 | * Provides meaning to an {@link Action} that hints at what the associated |
| 2000 | * {@link PendingIntent} will do. For example, an {@link Action} with a |
| 2001 | * {@link PendingIntent} that replies to a text message notification may have the |
| 2002 | * {@link #SEMANTIC_ACTION_REPLY} {@code SemanticAction} set within it. |
| 2003 | * |
| 2004 | * @hide |
| 2005 | */ |
| 2006 | @IntDef(prefix = { "SEMANTIC_ACTION_" }, value = { |
| 2007 | SEMANTIC_ACTION_NONE, |
| 2008 | SEMANTIC_ACTION_REPLY, |
| 2009 | SEMANTIC_ACTION_MARK_AS_READ, |
| 2010 | SEMANTIC_ACTION_MARK_AS_UNREAD, |
| 2011 | SEMANTIC_ACTION_DELETE, |
| 2012 | SEMANTIC_ACTION_ARCHIVE, |
| 2013 | SEMANTIC_ACTION_MUTE, |
| 2014 | SEMANTIC_ACTION_UNMUTE, |
| 2015 | SEMANTIC_ACTION_THUMBS_UP, |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 2016 | SEMANTIC_ACTION_THUMBS_DOWN, |
| 2017 | SEMANTIC_ACTION_CALL |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 2018 | }) |
| 2019 | @Retention(RetentionPolicy.SOURCE) |
| 2020 | public @interface SemanticAction {} |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2021 | } |
| 2022 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2023 | /** |
| 2024 | * Array of all {@link Action} structures attached to this notification by |
| 2025 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 2026 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 2027 | * interface for invoking actions. |
| 2028 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 2029 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2030 | |
| 2031 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2032 | * Replacement version of this notification whose content will be shown |
| 2033 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 2034 | * and {@link #VISIBILITY_PUBLIC}. |
| 2035 | */ |
| 2036 | public Notification publicVersion; |
| 2037 | |
| 2038 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2039 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2040 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2041 | */ |
| 2042 | public Notification() |
| 2043 | { |
| 2044 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2045 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2046 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2050 | * @hide |
| 2051 | */ |
| 2052 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 2053 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 2054 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2055 | new Builder(context) |
| 2056 | .setWhen(when) |
| 2057 | .setSmallIcon(icon) |
| 2058 | .setTicker(tickerText) |
| 2059 | .setContentTitle(contentTitle) |
| 2060 | .setContentText(contentText) |
| 2061 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 2062 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | /** |
| 2066 | * Constructs a Notification object with the information needed to |
| 2067 | * have a status bar icon without the standard expanded view. |
| 2068 | * |
| 2069 | * @param icon The resource id of the icon to put in the status bar. |
| 2070 | * @param tickerText The text that flows by in the status bar when the notification first |
| 2071 | * activates. |
| 2072 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 2073 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2074 | * |
| 2075 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2076 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2077 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | public Notification(int icon, CharSequence tickerText, long when) |
| 2079 | { |
| 2080 | this.icon = icon; |
| 2081 | this.tickerText = tickerText; |
| 2082 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2083 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | /** |
| 2087 | * Unflatten the notification from a parcel. |
| 2088 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2089 | @SuppressWarnings("unchecked") |
| 2090 | public Notification(Parcel parcel) { |
| 2091 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 2092 | // intents in extras are always written as the last entry. |
| 2093 | readFromParcelImpl(parcel); |
| 2094 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2095 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2099 | { |
| 2100 | int version = parcel.readInt(); |
| 2101 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2102 | mWhitelistToken = parcel.readStrongBinder(); |
| 2103 | if (mWhitelistToken == null) { |
| 2104 | mWhitelistToken = processWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2105 | } |
| 2106 | // 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] | 2107 | parcel.setClassCookie(PendingIntent.class, mWhitelistToken); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2110 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2111 | if (parcel.readInt() != 0) { |
| 2112 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2113 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 2114 | icon = mSmallIcon.getResId(); |
| 2115 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2116 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2117 | number = parcel.readInt(); |
| 2118 | if (parcel.readInt() != 0) { |
| 2119 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2120 | } |
| 2121 | if (parcel.readInt() != 0) { |
| 2122 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2123 | } |
| 2124 | if (parcel.readInt() != 0) { |
| 2125 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2126 | } |
| 2127 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2128 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2129 | } |
| 2130 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2131 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2132 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2133 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2134 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | defaults = parcel.readInt(); |
| 2137 | flags = parcel.readInt(); |
| 2138 | if (parcel.readInt() != 0) { |
| 2139 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 2140 | } |
| 2141 | |
| 2142 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2143 | if (parcel.readInt() != 0) { |
| 2144 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 2145 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | vibrate = parcel.createLongArray(); |
| 2147 | ledARGB = parcel.readInt(); |
| 2148 | ledOnMS = parcel.readInt(); |
| 2149 | ledOffMS = parcel.readInt(); |
| 2150 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2151 | |
| 2152 | if (parcel.readInt() != 0) { |
| 2153 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2154 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2155 | |
| 2156 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2157 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2158 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2159 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2160 | mGroupKey = parcel.readString(); |
| 2161 | |
| 2162 | mSortKey = parcel.readString(); |
| 2163 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 2164 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2165 | fixDuplicateExtras(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2166 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2167 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 2168 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2169 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2170 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2171 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2172 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2173 | if (parcel.readInt() != 0) { |
| 2174 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2175 | } |
| 2176 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2177 | visibility = parcel.readInt(); |
| 2178 | |
| 2179 | if (parcel.readInt() != 0) { |
| 2180 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 2181 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2182 | |
| 2183 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2184 | |
| 2185 | if (parcel.readInt() != 0) { |
| 2186 | mChannelId = parcel.readString(); |
| 2187 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2188 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2189 | |
| 2190 | if (parcel.readInt() != 0) { |
| 2191 | mShortcutId = parcel.readString(); |
| 2192 | } |
| 2193 | |
| 2194 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2195 | |
| 2196 | if (parcel.readInt() != 0) { |
| 2197 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2198 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2199 | |
| 2200 | mGroupAlertBehavior = parcel.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | } |
| 2202 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2203 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2204 | public Notification clone() { |
| 2205 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2206 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2207 | return that; |
| 2208 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2209 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2210 | /** |
| 2211 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 2212 | * of this into that. |
| 2213 | * @hide |
| 2214 | */ |
| 2215 | public void cloneInto(Notification that, boolean heavy) { |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2216 | that.mWhitelistToken = this.mWhitelistToken; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2217 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2218 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2219 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2220 | that.number = this.number; |
| 2221 | |
| 2222 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 2223 | that.contentIntent = this.contentIntent; |
| 2224 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2225 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2226 | |
| 2227 | if (this.tickerText != null) { |
| 2228 | that.tickerText = this.tickerText.toString(); |
| 2229 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2230 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2231 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2232 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2233 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2234 | that.contentView = this.contentView.clone(); |
| 2235 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2236 | if (heavy && this.mLargeIcon != null) { |
| 2237 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2238 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 2239 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2240 | that.sound = this.sound; // android.net.Uri is immutable |
| 2241 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2242 | if (this.audioAttributes != null) { |
| 2243 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 2244 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2245 | |
| 2246 | final long[] vibrate = this.vibrate; |
| 2247 | if (vibrate != null) { |
| 2248 | final int N = vibrate.length; |
| 2249 | final long[] vib = that.vibrate = new long[N]; |
| 2250 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 2251 | } |
| 2252 | |
| 2253 | that.ledARGB = this.ledARGB; |
| 2254 | that.ledOnMS = this.ledOnMS; |
| 2255 | that.ledOffMS = this.ledOffMS; |
| 2256 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2257 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2258 | that.flags = this.flags; |
| 2259 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2260 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2261 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2262 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2263 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2264 | that.mGroupKey = this.mGroupKey; |
| 2265 | |
| 2266 | that.mSortKey = this.mSortKey; |
| 2267 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2268 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2269 | try { |
| 2270 | that.extras = new Bundle(this.extras); |
| 2271 | // will unparcel |
| 2272 | that.extras.size(); |
| 2273 | } catch (BadParcelableException e) { |
| 2274 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2275 | that.extras = null; |
| 2276 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2277 | } |
| 2278 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2279 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2280 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2283 | if (this.actions != null) { |
| 2284 | that.actions = new Action[this.actions.length]; |
| 2285 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 2286 | if ( this.actions[i] != null) { |
| 2287 | that.actions[i] = this.actions[i].clone(); |
| 2288 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2289 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2290 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2291 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2292 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2293 | that.bigContentView = this.bigContentView.clone(); |
| 2294 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2295 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2296 | if (heavy && this.headsUpContentView != null) { |
| 2297 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 2298 | } |
| 2299 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2300 | that.visibility = this.visibility; |
| 2301 | |
| 2302 | if (this.publicVersion != null) { |
| 2303 | that.publicVersion = new Notification(); |
| 2304 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2305 | } |
| 2306 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2307 | that.color = this.color; |
| 2308 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2309 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2310 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2311 | that.mShortcutId = this.mShortcutId; |
| 2312 | that.mBadgeIcon = this.mBadgeIcon; |
| 2313 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2314 | that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2315 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2316 | if (!heavy) { |
| 2317 | that.lightenPayload(); // will clean out extras |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | /** |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 2322 | * Note all {@link Uri} that are referenced internally, with the expectation |
| 2323 | * that Uri permission grants will need to be issued to ensure the recipient |
| 2324 | * of this object is able to render its contents. |
| 2325 | * |
| 2326 | * @hide |
| 2327 | */ |
| 2328 | public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 2329 | visitor.accept(sound); |
| 2330 | |
| 2331 | if (tickerView != null) tickerView.visitUris(visitor); |
| 2332 | if (contentView != null) contentView.visitUris(visitor); |
| 2333 | if (bigContentView != null) bigContentView.visitUris(visitor); |
| 2334 | if (headsUpContentView != null) headsUpContentView.visitUris(visitor); |
| 2335 | |
| 2336 | if (extras != null) { |
| 2337 | visitor.accept(extras.getParcelable(EXTRA_AUDIO_CONTENTS_URI)); |
| 2338 | visitor.accept(extras.getParcelable(EXTRA_BACKGROUND_IMAGE_URI)); |
| 2339 | } |
| 2340 | |
| 2341 | if (MessagingStyle.class.equals(getNotificationStyle()) && extras != null) { |
| 2342 | final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 2343 | if (!ArrayUtils.isEmpty(messages)) { |
| 2344 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2345 | .getMessagesFromBundleArray(messages)) { |
| 2346 | visitor.accept(message.getDataUri()); |
| 2347 | } |
| 2348 | } |
| 2349 | |
| 2350 | final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 2351 | if (!ArrayUtils.isEmpty(historic)) { |
| 2352 | for (MessagingStyle.Message message : MessagingStyle.Message |
| 2353 | .getMessagesFromBundleArray(historic)) { |
| 2354 | visitor.accept(message.getDataUri()); |
| 2355 | } |
| 2356 | } |
| 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | /** |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2361 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 2362 | * listeners when the full contents are not necessary. |
| 2363 | * @hide |
| 2364 | */ |
| 2365 | public final void lightenPayload() { |
| 2366 | tickerView = null; |
| 2367 | contentView = null; |
| 2368 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2369 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2370 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2371 | if (extras != null && !extras.isEmpty()) { |
| 2372 | final Set<String> keyset = extras.keySet(); |
| 2373 | final int N = keyset.size(); |
| 2374 | final String[] keys = keyset.toArray(new String[N]); |
| 2375 | for (int i=0; i<N; i++) { |
| 2376 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2377 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2378 | continue; |
| 2379 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2380 | final Object obj = extras.get(key); |
| 2381 | if (obj != null && |
| 2382 | ( obj instanceof Parcelable |
| 2383 | || obj instanceof Parcelable[] |
| 2384 | || obj instanceof SparseArray |
| 2385 | || obj instanceof ArrayList)) { |
| 2386 | extras.remove(key); |
| 2387 | } |
| 2388 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2389 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2390 | } |
| 2391 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2392 | /** |
| 2393 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2394 | * means it had better not be some custom Parcelable implementation. |
| 2395 | * @hide |
| 2396 | */ |
| 2397 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2398 | if (cs == null) return cs; |
| 2399 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2400 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2401 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2402 | if (cs instanceof Parcelable) { |
| 2403 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2404 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2405 | return cs.toString(); |
| 2406 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2407 | return removeTextSizeSpans(cs); |
| 2408 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2409 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2410 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2411 | if (charSequence instanceof Spanned) { |
| 2412 | Spanned ss = (Spanned) charSequence; |
| 2413 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2414 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2415 | for (Object span : spans) { |
| 2416 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2417 | if (resultSpan instanceof CharacterStyle) { |
| 2418 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2419 | } |
| 2420 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2421 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2422 | resultSpan = new TextAppearanceSpan( |
| 2423 | originalSpan.getFamily(), |
| 2424 | originalSpan.getTextStyle(), |
| 2425 | -1, |
| 2426 | originalSpan.getTextColor(), |
| 2427 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2428 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2429 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2430 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2431 | } else { |
| 2432 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2433 | } |
| 2434 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2435 | ss.getSpanFlags(span)); |
| 2436 | } |
| 2437 | return builder; |
| 2438 | } |
| 2439 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2440 | } |
| 2441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2442 | public int describeContents() { |
| 2443 | return 0; |
| 2444 | } |
| 2445 | |
| 2446 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2447 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2449 | public void writeToParcel(Parcel parcel, int flags) { |
| 2450 | // We need to mark all pending intents getting into the notification |
| 2451 | // system as being put there to later allow the notification ranker |
| 2452 | // to launch them and by doing so add the app to the battery saver white |
| 2453 | // list for a short period of time. The problem is that the system |
| 2454 | // cannot look into the extras as there may be parcelables there that |
| 2455 | // the platform does not know how to handle. To go around that we have |
| 2456 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2457 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2458 | if (collectPendingIntents) { |
| 2459 | PendingIntent.setOnMarshaledListener( |
| 2460 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2461 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2462 | if (allPendingIntents == null) { |
| 2463 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2464 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2465 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2466 | } |
| 2467 | }); |
| 2468 | } |
| 2469 | try { |
| 2470 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2471 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2472 | writeToParcelImpl(parcel, flags); |
| 2473 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2474 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2475 | } finally { |
| 2476 | if (collectPendingIntents) { |
| 2477 | PendingIntent.setOnMarshaledListener(null); |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | parcel.writeInt(1); |
| 2484 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2485 | parcel.writeStrongBinder(mWhitelistToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2487 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2488 | if (mSmallIcon == null && icon != 0) { |
| 2489 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2490 | mSmallIcon = Icon.createWithResource("", icon); |
| 2491 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2492 | if (mSmallIcon != null) { |
| 2493 | parcel.writeInt(1); |
| 2494 | mSmallIcon.writeToParcel(parcel, 0); |
| 2495 | } else { |
| 2496 | parcel.writeInt(0); |
| 2497 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2498 | parcel.writeInt(number); |
| 2499 | if (contentIntent != null) { |
| 2500 | parcel.writeInt(1); |
| 2501 | contentIntent.writeToParcel(parcel, 0); |
| 2502 | } else { |
| 2503 | parcel.writeInt(0); |
| 2504 | } |
| 2505 | if (deleteIntent != null) { |
| 2506 | parcel.writeInt(1); |
| 2507 | deleteIntent.writeToParcel(parcel, 0); |
| 2508 | } else { |
| 2509 | parcel.writeInt(0); |
| 2510 | } |
| 2511 | if (tickerText != null) { |
| 2512 | parcel.writeInt(1); |
| 2513 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2514 | } else { |
| 2515 | parcel.writeInt(0); |
| 2516 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2517 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2518 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2519 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2520 | } else { |
| 2521 | parcel.writeInt(0); |
| 2522 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2523 | if (contentView != null) { |
| 2524 | parcel.writeInt(1); |
| 2525 | contentView.writeToParcel(parcel, 0); |
| 2526 | } else { |
| 2527 | parcel.writeInt(0); |
| 2528 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2529 | if (mLargeIcon == null && largeIcon != null) { |
| 2530 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2531 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2532 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2533 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2534 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2535 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2536 | } else { |
| 2537 | parcel.writeInt(0); |
| 2538 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2539 | |
| 2540 | parcel.writeInt(defaults); |
| 2541 | parcel.writeInt(this.flags); |
| 2542 | |
| 2543 | if (sound != null) { |
| 2544 | parcel.writeInt(1); |
| 2545 | sound.writeToParcel(parcel, 0); |
| 2546 | } else { |
| 2547 | parcel.writeInt(0); |
| 2548 | } |
| 2549 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2550 | |
| 2551 | if (audioAttributes != null) { |
| 2552 | parcel.writeInt(1); |
| 2553 | audioAttributes.writeToParcel(parcel, 0); |
| 2554 | } else { |
| 2555 | parcel.writeInt(0); |
| 2556 | } |
| 2557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2558 | parcel.writeLongArray(vibrate); |
| 2559 | parcel.writeInt(ledARGB); |
| 2560 | parcel.writeInt(ledOnMS); |
| 2561 | parcel.writeInt(ledOffMS); |
| 2562 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2563 | |
| 2564 | if (fullScreenIntent != null) { |
| 2565 | parcel.writeInt(1); |
| 2566 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2567 | } else { |
| 2568 | parcel.writeInt(0); |
| 2569 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2570 | |
| 2571 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2572 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2573 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2574 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2575 | parcel.writeString(mGroupKey); |
| 2576 | |
| 2577 | parcel.writeString(mSortKey); |
| 2578 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2579 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2580 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2581 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2582 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2583 | if (bigContentView != null) { |
| 2584 | parcel.writeInt(1); |
| 2585 | bigContentView.writeToParcel(parcel, 0); |
| 2586 | } else { |
| 2587 | parcel.writeInt(0); |
| 2588 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2589 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2590 | if (headsUpContentView != null) { |
| 2591 | parcel.writeInt(1); |
| 2592 | headsUpContentView.writeToParcel(parcel, 0); |
| 2593 | } else { |
| 2594 | parcel.writeInt(0); |
| 2595 | } |
| 2596 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2597 | parcel.writeInt(visibility); |
| 2598 | |
| 2599 | if (publicVersion != null) { |
| 2600 | parcel.writeInt(1); |
| 2601 | publicVersion.writeToParcel(parcel, 0); |
| 2602 | } else { |
| 2603 | parcel.writeInt(0); |
| 2604 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2605 | |
| 2606 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2607 | |
| 2608 | if (mChannelId != null) { |
| 2609 | parcel.writeInt(1); |
| 2610 | parcel.writeString(mChannelId); |
| 2611 | } else { |
| 2612 | parcel.writeInt(0); |
| 2613 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2614 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2615 | |
| 2616 | if (mShortcutId != null) { |
| 2617 | parcel.writeInt(1); |
| 2618 | parcel.writeString(mShortcutId); |
| 2619 | } else { |
| 2620 | parcel.writeInt(0); |
| 2621 | } |
| 2622 | |
| 2623 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2624 | |
| 2625 | if (mSettingsText != null) { |
| 2626 | parcel.writeInt(1); |
| 2627 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2628 | } else { |
| 2629 | parcel.writeInt(0); |
| 2630 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2631 | |
| 2632 | parcel.writeInt(mGroupAlertBehavior); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2633 | |
| 2634 | // 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] | 2635 | } |
| 2636 | |
| 2637 | /** |
| 2638 | * Parcelable.Creator that instantiates Notification objects |
| 2639 | */ |
| 2640 | public static final Parcelable.Creator<Notification> CREATOR |
| 2641 | = new Parcelable.Creator<Notification>() |
| 2642 | { |
| 2643 | public Notification createFromParcel(Parcel parcel) |
| 2644 | { |
| 2645 | return new Notification(parcel); |
| 2646 | } |
| 2647 | |
| 2648 | public Notification[] newArray(int size) |
| 2649 | { |
| 2650 | return new Notification[size]; |
| 2651 | } |
| 2652 | }; |
| 2653 | |
| 2654 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2655 | * @hide |
| 2656 | */ |
| 2657 | public static boolean areActionsVisiblyDifferent(Notification first, Notification second) { |
| 2658 | Notification.Action[] firstAs = first.actions; |
| 2659 | Notification.Action[] secondAs = second.actions; |
| 2660 | if (firstAs == null && secondAs != null || firstAs != null && secondAs == null) { |
| 2661 | return true; |
| 2662 | } |
| 2663 | if (firstAs != null && secondAs != null) { |
| 2664 | if (firstAs.length != secondAs.length) { |
| 2665 | return true; |
| 2666 | } |
| 2667 | for (int i = 0; i < firstAs.length; i++) { |
| 2668 | if (!Objects.equals(firstAs[i].title, secondAs[i].title)) { |
| 2669 | return true; |
| 2670 | } |
| 2671 | RemoteInput[] firstRs = firstAs[i].getRemoteInputs(); |
| 2672 | RemoteInput[] secondRs = secondAs[i].getRemoteInputs(); |
| 2673 | if (firstRs == null) { |
| 2674 | firstRs = new RemoteInput[0]; |
| 2675 | } |
| 2676 | if (secondRs == null) { |
| 2677 | secondRs = new RemoteInput[0]; |
| 2678 | } |
| 2679 | if (firstRs.length != secondRs.length) { |
| 2680 | return true; |
| 2681 | } |
| 2682 | for (int j = 0; j < firstRs.length; j++) { |
| 2683 | if (!Objects.equals(firstRs[j].getLabel(), secondRs[j].getLabel())) { |
| 2684 | return true; |
| 2685 | } |
Julia Reynolds | 5a366fb | 2018-03-21 15:40:53 -0400 | [diff] [blame] | 2686 | CharSequence[] firstCs = firstRs[j].getChoices(); |
| 2687 | CharSequence[] secondCs = secondRs[j].getChoices(); |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 2688 | if (firstCs == null) { |
| 2689 | firstCs = new CharSequence[0]; |
| 2690 | } |
| 2691 | if (secondCs == null) { |
| 2692 | secondCs = new CharSequence[0]; |
| 2693 | } |
| 2694 | if (firstCs.length != secondCs.length) { |
| 2695 | return true; |
| 2696 | } |
| 2697 | for (int k = 0; k < firstCs.length; k++) { |
| 2698 | if (!Objects.equals(firstCs[k], secondCs[k])) { |
| 2699 | return true; |
| 2700 | } |
| 2701 | } |
| 2702 | } |
| 2703 | } |
| 2704 | } |
| 2705 | return false; |
| 2706 | } |
| 2707 | |
| 2708 | /** |
| 2709 | * @hide |
| 2710 | */ |
| 2711 | public static boolean areStyledNotificationsVisiblyDifferent(Builder first, Builder second) { |
| 2712 | if (first.getStyle() == null) { |
| 2713 | return second.getStyle() != null; |
| 2714 | } |
| 2715 | if (second.getStyle() == null) { |
| 2716 | return true; |
| 2717 | } |
| 2718 | return first.getStyle().areNotificationsVisiblyDifferent(second.getStyle()); |
| 2719 | } |
| 2720 | |
| 2721 | /** |
| 2722 | * @hide |
| 2723 | */ |
| 2724 | public static boolean areRemoteViewsChanged(Builder first, Builder second) { |
| 2725 | return !first.usesStandardHeader() || !second.usesStandardHeader(); |
| 2726 | } |
| 2727 | |
| 2728 | /** |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2729 | * Parcelling creates multiple copies of objects in {@code extras}. Fix them. |
| 2730 | * <p> |
| 2731 | * For backwards compatibility {@code extras} holds some references to "real" member data such |
| 2732 | * as {@link getLargeIcon()} which is mirrored by {@link #EXTRA_LARGE_ICON}. This is mostly |
| 2733 | * fine as long as the object stays in one process. |
| 2734 | * <p> |
| 2735 | * However, once the notification goes into a parcel each reference gets marshalled separately, |
| 2736 | * wasting memory. Especially with large images on Auto and TV, this is worth fixing. |
| 2737 | */ |
| 2738 | private void fixDuplicateExtras() { |
| 2739 | if (extras != null) { |
| 2740 | fixDuplicateExtra(mSmallIcon, EXTRA_SMALL_ICON); |
| 2741 | fixDuplicateExtra(mLargeIcon, EXTRA_LARGE_ICON); |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | /** |
| 2746 | * If we find an extra that's exactly the same as one of the "real" fields but refers to a |
| 2747 | * separate object, replace it with the field's version to avoid holding duplicate copies. |
| 2748 | */ |
| 2749 | private void fixDuplicateExtra(@Nullable Parcelable original, @NonNull String extraName) { |
| 2750 | if (original != null && extras.getParcelable(extraName) != null) { |
| 2751 | extras.putParcelable(extraName, original); |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2757 | * layout. |
| 2758 | * |
| 2759 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2760 | * in the view.</p> |
| 2761 | * @param context The context for your application / activity. |
| 2762 | * @param contentTitle The title that goes in the expanded entry. |
| 2763 | * @param contentText The text that goes in the expanded entry. |
| 2764 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2765 | * If this is an activity, it must include the |
| 2766 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2767 | * that you take care of task management as described in the |
| 2768 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2769 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2770 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2771 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2772 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2774 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2775 | public void setLatestEventInfo(Context context, |
| 2776 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2777 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2778 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2779 | new Throwable()); |
| 2780 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2781 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2782 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2783 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2784 | } |
| 2785 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2786 | // ensure that any information already set directly is preserved |
| 2787 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2788 | |
| 2789 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2790 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2791 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2792 | } |
| 2793 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2794 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2796 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2797 | |
| 2798 | 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] | 2799 | } |
| 2800 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2801 | /** |
| 2802 | * @hide |
| 2803 | */ |
| 2804 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2805 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | /** |
| 2809 | * @hide |
| 2810 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2811 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2812 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2813 | } |
| 2814 | |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 2815 | /** |
| 2816 | * @hide |
| 2817 | */ |
| 2818 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 2819 | long token = proto.start(fieldId); |
| 2820 | proto.write(NotificationProto.CHANNEL_ID, getChannelId()); |
| 2821 | proto.write(NotificationProto.HAS_TICKER_TEXT, this.tickerText != null); |
| 2822 | proto.write(NotificationProto.FLAGS, this.flags); |
| 2823 | proto.write(NotificationProto.COLOR, this.color); |
| 2824 | proto.write(NotificationProto.CATEGORY, this.category); |
| 2825 | proto.write(NotificationProto.GROUP_KEY, this.mGroupKey); |
| 2826 | proto.write(NotificationProto.SORT_KEY, this.mSortKey); |
| 2827 | if (this.actions != null) { |
| 2828 | proto.write(NotificationProto.ACTION_LENGTH, this.actions.length); |
| 2829 | } |
| 2830 | if (this.visibility >= VISIBILITY_SECRET && this.visibility <= VISIBILITY_PUBLIC) { |
| 2831 | proto.write(NotificationProto.VISIBILITY, this.visibility); |
| 2832 | } |
| 2833 | if (publicVersion != null) { |
| 2834 | publicVersion.writeToProto(proto, NotificationProto.PUBLIC_VERSION); |
| 2835 | } |
| 2836 | proto.end(token); |
| 2837 | } |
| 2838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | @Override |
| 2840 | public String toString() { |
| 2841 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2842 | sb.append("Notification(channel="); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2843 | sb.append(getChannelId()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2844 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2845 | sb.append(priority); |
| 2846 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2847 | if (contentView != null) { |
| 2848 | sb.append(contentView.getPackage()); |
| 2849 | sb.append("/0x"); |
| 2850 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2851 | } else { |
| 2852 | sb.append("null"); |
| 2853 | } |
| 2854 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2855 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2856 | sb.append("default"); |
| 2857 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2858 | int N = this.vibrate.length-1; |
| 2859 | sb.append("["); |
| 2860 | for (int i=0; i<N; i++) { |
| 2861 | sb.append(this.vibrate[i]); |
| 2862 | sb.append(','); |
| 2863 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 2864 | if (N != -1) { |
| 2865 | sb.append(this.vibrate[N]); |
| 2866 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2868 | } else { |
| 2869 | sb.append("null"); |
| 2870 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2871 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2872 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2873 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2874 | } else if (this.sound != null) { |
| 2875 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | } else { |
| 2877 | sb.append("null"); |
| 2878 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 2879 | if (this.tickerText != null) { |
| 2880 | sb.append(" tick"); |
| 2881 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2882 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2884 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2885 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2886 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2887 | if (this.category != null) { |
| 2888 | sb.append(" category="); |
| 2889 | sb.append(this.category); |
| 2890 | } |
| 2891 | if (this.mGroupKey != null) { |
| 2892 | sb.append(" groupKey="); |
| 2893 | sb.append(this.mGroupKey); |
| 2894 | } |
| 2895 | if (this.mSortKey != null) { |
| 2896 | sb.append(" sortKey="); |
| 2897 | sb.append(this.mSortKey); |
| 2898 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2899 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2900 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2901 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2902 | } |
| 2903 | sb.append(" vis="); |
| 2904 | sb.append(visibilityToString(this.visibility)); |
| 2905 | if (this.publicVersion != null) { |
| 2906 | sb.append(" publicVersion="); |
| 2907 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2908 | } |
| 2909 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | return sb.toString(); |
| 2911 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2912 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2913 | /** |
| 2914 | * {@hide} |
| 2915 | */ |
| 2916 | public static String visibilityToString(int vis) { |
| 2917 | switch (vis) { |
| 2918 | case VISIBILITY_PRIVATE: |
| 2919 | return "PRIVATE"; |
| 2920 | case VISIBILITY_PUBLIC: |
| 2921 | return "PUBLIC"; |
| 2922 | case VISIBILITY_SECRET: |
| 2923 | return "SECRET"; |
| 2924 | default: |
| 2925 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 2926 | } |
| 2927 | } |
| 2928 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2929 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 2930 | * {@hide} |
| 2931 | */ |
| 2932 | public static String priorityToString(@Priority int pri) { |
| 2933 | switch (pri) { |
| 2934 | case PRIORITY_MIN: |
| 2935 | return "MIN"; |
| 2936 | case PRIORITY_LOW: |
| 2937 | return "LOW"; |
| 2938 | case PRIORITY_DEFAULT: |
| 2939 | return "DEFAULT"; |
| 2940 | case PRIORITY_HIGH: |
| 2941 | return "HIGH"; |
| 2942 | case PRIORITY_MAX: |
| 2943 | return "MAX"; |
| 2944 | default: |
| 2945 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 2946 | } |
| 2947 | } |
| 2948 | |
Julia Reynolds | 6ad0aec | 2017-07-05 08:47:03 -0400 | [diff] [blame] | 2949 | /** |
| 2950 | * @hide |
| 2951 | */ |
| 2952 | public boolean hasCompletedProgress() { |
| 2953 | // not a progress notification; can't be complete |
| 2954 | if (!extras.containsKey(EXTRA_PROGRESS) |
| 2955 | || !extras.containsKey(EXTRA_PROGRESS_MAX)) { |
| 2956 | return false; |
| 2957 | } |
| 2958 | // many apps use max 0 for 'indeterminate'; not complete |
| 2959 | if (extras.getInt(EXTRA_PROGRESS_MAX) == 0) { |
| 2960 | return false; |
| 2961 | } |
| 2962 | return extras.getInt(EXTRA_PROGRESS) == extras.getInt(EXTRA_PROGRESS_MAX); |
| 2963 | } |
| 2964 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2965 | /** @removed */ |
| 2966 | @Deprecated |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 2967 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2968 | return mChannelId; |
| 2969 | } |
| 2970 | |
| 2971 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2972 | * Returns the id of the channel this notification posts to. |
| 2973 | */ |
| 2974 | public String getChannelId() { |
| 2975 | return mChannelId; |
| 2976 | } |
| 2977 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2978 | /** @removed */ |
| 2979 | @Deprecated |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2980 | public long getTimeout() { |
| 2981 | return mTimeout; |
| 2982 | } |
| 2983 | |
| 2984 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2985 | * Returns the duration from posting after which this notification should be canceled by the |
| 2986 | * system, if it's not canceled already. |
| 2987 | */ |
| 2988 | public long getTimeoutAfter() { |
| 2989 | return mTimeout; |
| 2990 | } |
| 2991 | |
| 2992 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2993 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 2994 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 2995 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 2996 | */ |
| 2997 | public int getBadgeIconType() { |
| 2998 | return mBadgeIcon; |
| 2999 | } |
| 3000 | |
| 3001 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3002 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3003 | * |
| 3004 | * <p>Used by some Launchers that display notification content to hide shortcuts that duplicate |
| 3005 | * notifications. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3006 | */ |
| 3007 | public String getShortcutId() { |
| 3008 | return mShortcutId; |
| 3009 | } |
| 3010 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3011 | |
| 3012 | /** |
| 3013 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 3014 | */ |
| 3015 | public CharSequence getSettingsText() { |
| 3016 | return mSettingsText; |
| 3017 | } |
| 3018 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3019 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3020 | * Returns which type of notifications in a group are responsible for audibly alerting the |
| 3021 | * user. See {@link #GROUP_ALERT_ALL}, {@link #GROUP_ALERT_CHILDREN}, |
| 3022 | * {@link #GROUP_ALERT_SUMMARY}. |
| 3023 | */ |
| 3024 | public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 3025 | return mGroupAlertBehavior; |
| 3026 | } |
| 3027 | |
| 3028 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3029 | * The small icon representing this notification in the status bar and content view. |
| 3030 | * |
| 3031 | * @return the small icon representing this notification. |
| 3032 | * |
| 3033 | * @see Builder#getSmallIcon() |
| 3034 | * @see Builder#setSmallIcon(Icon) |
| 3035 | */ |
| 3036 | public Icon getSmallIcon() { |
| 3037 | return mSmallIcon; |
| 3038 | } |
| 3039 | |
| 3040 | /** |
| 3041 | * Used when notifying to clean up legacy small icons. |
| 3042 | * @hide |
| 3043 | */ |
| 3044 | public void setSmallIcon(Icon icon) { |
| 3045 | mSmallIcon = icon; |
| 3046 | } |
| 3047 | |
| 3048 | /** |
| 3049 | * The large icon shown in this notification's content view. |
| 3050 | * @see Builder#getLargeIcon() |
| 3051 | * @see Builder#setLargeIcon(Icon) |
| 3052 | */ |
| 3053 | public Icon getLargeIcon() { |
| 3054 | return mLargeIcon; |
| 3055 | } |
| 3056 | |
| 3057 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3058 | * @hide |
| 3059 | */ |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 3060 | public boolean isGroupSummary() { |
| 3061 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 3062 | } |
| 3063 | |
| 3064 | /** |
| 3065 | * @hide |
| 3066 | */ |
| 3067 | public boolean isGroupChild() { |
| 3068 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 3069 | } |
| 3070 | |
| 3071 | /** |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 3072 | * @hide |
| 3073 | */ |
| 3074 | public boolean suppressAlertingDueToGrouping() { |
| 3075 | if (isGroupSummary() |
| 3076 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { |
| 3077 | return true; |
| 3078 | } else if (isGroupChild() |
| 3079 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { |
| 3080 | return true; |
| 3081 | } |
| 3082 | return false; |
| 3083 | } |
| 3084 | |
| 3085 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3086 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3087 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3088 | * 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] | 3089 | * content views using the platform's notification layout template. If your app supports |
| 3090 | * versions of Android as old as API level 4, you can instead use |
| 3091 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 3092 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 3093 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3094 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3095 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3096 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3097 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 3098 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3099 | * .setContentTitle("New mail from " + sender.toString()) |
| 3100 | * .setContentText(subject) |
| 3101 | * .setSmallIcon(R.drawable.new_mail) |
| 3102 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3103 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3104 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3105 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3106 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 3107 | /** |
| 3108 | * @hide |
| 3109 | */ |
| 3110 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 3111 | "android.rebuild.contentViewActionCount"; |
| 3112 | /** |
| 3113 | * @hide |
| 3114 | */ |
| 3115 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 3116 | = "android.rebuild.bigViewActionCount"; |
| 3117 | /** |
| 3118 | * @hide |
| 3119 | */ |
| 3120 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 3121 | = "android.rebuild.hudViewActionCount"; |
| 3122 | |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 3123 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3124 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 3125 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 3126 | SystemProperties.getBoolean("notifications.only_title", true); |
| 3127 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3128 | /** |
| 3129 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3130 | * secondary text color when the background is light. |
| 3131 | */ |
| 3132 | private static final int LIGHTNESS_TEXT_DIFFERENCE_LIGHT = 20; |
| 3133 | |
| 3134 | /** |
| 3135 | * The lightness difference that has to be added to the primary text color to obtain the |
| 3136 | * secondary text color when the background is dark. |
| 3137 | * A bit less then the above value, since it looks better on dark backgrounds. |
| 3138 | */ |
| 3139 | private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10; |
| 3140 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3141 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3142 | private Notification mN; |
| 3143 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3144 | private Style mStyle; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3145 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3146 | private ArrayList<Person> mPersonList = new ArrayList<>(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3147 | private NotificationColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3148 | private boolean mIsLegacy; |
| 3149 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3150 | |
| 3151 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3152 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 3153 | */ |
| 3154 | private int mCachedContrastColor = COLOR_INVALID; |
| 3155 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3156 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3157 | * Caches a ambient version of {@link #mCachedAmbientColorIsFor}. |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3158 | */ |
| 3159 | private int mCachedAmbientColor = COLOR_INVALID; |
| 3160 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 3161 | /** |
| 3162 | * A neutral color color that can be used for icons. |
| 3163 | */ |
| 3164 | private int mNeutralColor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3165 | |
| 3166 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3167 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 3168 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 3169 | */ |
| 3170 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3171 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 3172 | private int mPrimaryTextColor = COLOR_INVALID; |
| 3173 | private int mSecondaryTextColor = COLOR_INVALID; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3174 | private int mBackgroundColor = COLOR_INVALID; |
| 3175 | private int mForegroundColor = COLOR_INVALID; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 3176 | /** |
| 3177 | * A temporary location where actions are stored. If != null the view originally has action |
| 3178 | * but doesn't have any for this inflation. |
| 3179 | */ |
| 3180 | private ArrayList<Action> mOriginalActions; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 3181 | private boolean mRebuildStyledRemoteViews; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3182 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3183 | private boolean mTintActionButtons; |
| 3184 | private boolean mInNightMode; |
| 3185 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3186 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3187 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3188 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3189 | * @param context |
| 3190 | * A {@link Context} that will be used by the Builder to construct the |
| 3191 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 3192 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3193 | * @param channelId |
| 3194 | * The constructed Notification will be posted on this |
| 3195 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 3196 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3197 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3198 | public Builder(Context context, String channelId) { |
| 3199 | this(context, (Notification) null); |
| 3200 | mN.mChannelId = channelId; |
| 3201 | } |
| 3202 | |
| 3203 | /** |
| 3204 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 3205 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 3206 | */ |
| 3207 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3208 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3209 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3210 | } |
| 3211 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3212 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3213 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3214 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3215 | public Builder(Context context, Notification toAdopt) { |
| 3216 | mContext = context; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3217 | Resources res = mContext.getResources(); |
| 3218 | mTintActionButtons = res.getBoolean(R.bool.config_tintNotificationActionButtons); |
| 3219 | |
| 3220 | if (res.getBoolean(R.bool.config_enableNightMode)) { |
| 3221 | Configuration currentConfig = res.getConfiguration(); |
| 3222 | mInNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 3223 | == Configuration.UI_MODE_NIGHT_YES; |
| 3224 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3225 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3226 | if (toAdopt == null) { |
| 3227 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3228 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 3229 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 3230 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3231 | mN.priority = PRIORITY_DEFAULT; |
| 3232 | mN.visibility = VISIBILITY_PRIVATE; |
| 3233 | } else { |
| 3234 | mN = toAdopt; |
| 3235 | if (mN.actions != null) { |
| 3236 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3237 | } |
| 3238 | |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3239 | if (mN.extras.containsKey(EXTRA_PEOPLE_LIST)) { |
| 3240 | ArrayList<Person> people = mN.extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 3241 | mPersonList.addAll(people); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3242 | } |
| 3243 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 3244 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 3245 | setSmallIcon(mN.icon); |
| 3246 | } |
| 3247 | |
| 3248 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 3249 | setLargeIcon(mN.largeIcon); |
| 3250 | } |
| 3251 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3252 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 3253 | if (!TextUtils.isEmpty(templateClass)) { |
| 3254 | final Class<? extends Style> styleClass |
| 3255 | = getNotificationStyleClass(templateClass); |
| 3256 | if (styleClass == null) { |
| 3257 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 3258 | } else { |
| 3259 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3260 | final Constructor<? extends Style> ctor = |
| 3261 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3262 | ctor.setAccessible(true); |
| 3263 | final Style style = ctor.newInstance(); |
| 3264 | style.restoreFromExtras(mN.extras); |
| 3265 | |
| 3266 | if (style != null) { |
| 3267 | setStyle(style); |
| 3268 | } |
| 3269 | } catch (Throwable t) { |
| 3270 | Log.e(TAG, "Could not create Style", t); |
| 3271 | } |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | private NotificationColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3279 | if (mColorUtil == null) { |
| 3280 | mColorUtil = NotificationColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3281 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3282 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3283 | } |
| 3284 | |
| 3285 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3286 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 3287 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 3288 | * the shortcut. |
| 3289 | * |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3290 | * This field will be ignored by Launchers that don't support badging, don't show |
| 3291 | * notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3292 | * |
| 3293 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 3294 | * supersedes |
| 3295 | */ |
| 3296 | public Builder setShortcutId(String shortcutId) { |
| 3297 | mN.mShortcutId = shortcutId; |
| 3298 | return this; |
| 3299 | } |
| 3300 | |
| 3301 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3302 | * Sets which icon to display as a badge for this notification. |
| 3303 | * |
| 3304 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 3305 | * {@link #BADGE_ICON_LARGE}. |
| 3306 | * |
| 3307 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 3308 | */ |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 3309 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3310 | mN.mBadgeIcon = icon; |
| 3311 | return this; |
| 3312 | } |
| 3313 | |
| 3314 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3315 | * Sets the group alert behavior for this notification. Use this method to mute this |
| 3316 | * notification if alerts for this notification's group should be handled by a different |
| 3317 | * notification. This is only applicable for notifications that belong to a |
Julia Reynolds | 399d9bf | 2017-08-11 12:52:14 -0400 | [diff] [blame] | 3318 | * {@link #setGroup(String) group}. This must be called on all notifications you want to |
| 3319 | * mute. For example, if you want only the summary of your group to make noise, all |
| 3320 | * 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] | 3321 | * |
| 3322 | * <p> The default value is {@link #GROUP_ALERT_ALL}.</p> |
| 3323 | */ |
| 3324 | public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 3325 | mN.mGroupAlertBehavior = groupAlertBehavior; |
| 3326 | return this; |
| 3327 | } |
| 3328 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3329 | /** @removed */ |
| 3330 | @Deprecated |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3331 | public Builder setChannel(String channelId) { |
| 3332 | mN.mChannelId = channelId; |
| 3333 | return this; |
| 3334 | } |
| 3335 | |
| 3336 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3337 | * Specifies the channel the notification should be delivered on. |
| 3338 | */ |
| 3339 | public Builder setChannelId(String channelId) { |
| 3340 | mN.mChannelId = channelId; |
| 3341 | return this; |
| 3342 | } |
| 3343 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3344 | /** @removed */ |
| 3345 | @Deprecated |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 3346 | public Builder setTimeout(long durationMs) { |
| 3347 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3348 | return this; |
| 3349 | } |
| 3350 | |
| 3351 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3352 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 3353 | * if it is not already canceled. |
| 3354 | */ |
| 3355 | public Builder setTimeoutAfter(long durationMs) { |
| 3356 | mN.mTimeout = durationMs; |
| 3357 | return this; |
| 3358 | } |
| 3359 | |
| 3360 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3361 | * 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] | 3362 | * |
| 3363 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 3364 | * shown anymore by default and must be opted into by using |
| 3365 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3366 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3367 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3368 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3369 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3370 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3371 | return this; |
| 3372 | } |
| 3373 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3374 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 3375 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3376 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3377 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 3378 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3379 | */ |
| 3380 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3381 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3382 | return this; |
| 3383 | } |
| 3384 | |
| 3385 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3386 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3387 | * |
| 3388 | * 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] | 3389 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3390 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3391 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 3392 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3393 | * 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] | 3394 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3395 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3396 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3397 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3398 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3399 | */ |
| 3400 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3401 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3402 | return this; |
| 3403 | } |
| 3404 | |
| 3405 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3406 | * Sets the Chronometer to count down instead of counting up. |
| 3407 | * |
| 3408 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 3409 | * If it isn't set the chronometer will count up. |
| 3410 | * |
| 3411 | * @see #setUsesChronometer(boolean) |
| 3412 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3413 | public Builder setChronometerCountDown(boolean countDown) { |
| 3414 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3415 | return this; |
| 3416 | } |
| 3417 | |
| 3418 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3419 | * Set the small icon resource, which will be used to represent the notification in the |
| 3420 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3421 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3422 | |
| 3423 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 3424 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 3425 | * icon will be moved to the right-hand side. |
| 3426 | * |
| 3427 | |
| 3428 | * @param icon |
| 3429 | * A resource ID in the application's package of the drawable to use. |
| 3430 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3431 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3432 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3433 | return setSmallIcon(icon != 0 |
| 3434 | ? Icon.createWithResource(mContext, icon) |
| 3435 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3436 | } |
| 3437 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3438 | /** |
| 3439 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 3440 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 3441 | * LevelListDrawable}. |
| 3442 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3443 | * @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] | 3444 | * @param level The level to use for the icon. |
| 3445 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3446 | * @see Notification#icon |
| 3447 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3448 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3449 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3450 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3451 | return setSmallIcon(icon); |
| 3452 | } |
| 3453 | |
| 3454 | /** |
| 3455 | * Set the small icon, which will be used to represent the notification in the |
| 3456 | * status bar and content view (unless overriden there by a |
| 3457 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 3458 | * |
| 3459 | * @param icon An Icon object to use. |
| 3460 | * @see Notification#icon |
| 3461 | */ |
| 3462 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3463 | mN.setSmallIcon(icon); |
| 3464 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 3465 | mN.icon = icon.getResId(); |
| 3466 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3467 | return this; |
| 3468 | } |
| 3469 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3470 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3471 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3472 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3473 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3474 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3475 | return this; |
| 3476 | } |
| 3477 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3478 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3479 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3480 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3481 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3482 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3483 | return this; |
| 3484 | } |
| 3485 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3486 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3487 | * This provides some additional information that is displayed in the notification. No |
| 3488 | * guarantees are given where exactly it is displayed. |
| 3489 | * |
| 3490 | * <p>This information should only be provided if it provides an essential |
| 3491 | * benefit to the understanding of the notification. The more text you provide the |
| 3492 | * less readable it becomes. For example, an email client should only provide the account |
| 3493 | * name here if more than one email account has been added.</p> |
| 3494 | * |
| 3495 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 3496 | * notification header area. |
| 3497 | * |
| 3498 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 3499 | * this will be shown in the third line of text in the platform notification template. |
| 3500 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 3501 | * same time on those versions; they occupy the same place. |
| 3502 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3503 | */ |
| 3504 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3505 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3506 | return this; |
| 3507 | } |
| 3508 | |
| 3509 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3510 | * Provides text that will appear as a link to your application's settings. |
| 3511 | * |
| 3512 | * <p>This text does not appear within notification {@link Style templates} but may |
| 3513 | * appear when the user uses an affordance to learn more about the notification. |
| 3514 | * Additionally, this text will not appear unless you provide a valid link target by |
| 3515 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 3516 | * |
| 3517 | * <p>This text is meant to be concise description about what the user can customize |
| 3518 | * when they click on this link. The recommended maximum length is 40 characters. |
| 3519 | * @param text |
| 3520 | * @return |
| 3521 | */ |
| 3522 | public Builder setSettingsText(CharSequence text) { |
| 3523 | mN.mSettingsText = safeCharSequence(text); |
| 3524 | return this; |
| 3525 | } |
| 3526 | |
| 3527 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3528 | * Set the remote input history. |
| 3529 | * |
| 3530 | * This should be set to the most recent inputs that have been sent |
| 3531 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 3532 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 3533 | * |
| 3534 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 3535 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 3536 | * and how much of each individual input is shown. |
| 3537 | * |
| 3538 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 3539 | * with a {@code RemoteInput}.</p> |
| 3540 | */ |
| 3541 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 3542 | if (text == null) { |
| 3543 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 3544 | } else { |
| 3545 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 3546 | CharSequence[] safe = new CharSequence[N]; |
| 3547 | for (int i = 0; i < N; i++) { |
| 3548 | safe[i] = safeCharSequence(text[i]); |
| 3549 | } |
| 3550 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 3551 | } |
| 3552 | return this; |
| 3553 | } |
| 3554 | |
| 3555 | /** |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 3556 | * Sets whether remote history entries view should have a spinner. |
| 3557 | * @hide |
| 3558 | */ |
| 3559 | public Builder setShowRemoteInputSpinner(boolean showSpinner) { |
| 3560 | mN.extras.putBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER, showSpinner); |
| 3561 | return this; |
| 3562 | } |
| 3563 | |
| 3564 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3565 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 3566 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3567 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3568 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3569 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3570 | return this; |
| 3571 | } |
| 3572 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3573 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3574 | * A small piece of additional information pertaining to this notification. |
| 3575 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3576 | * The platform template will draw this on the last line of the notification, at the far |
| 3577 | * 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] | 3578 | * |
| 3579 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 3580 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 3581 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3582 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3583 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3584 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3585 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3586 | return this; |
| 3587 | } |
| 3588 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3589 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3590 | * Set the progress this notification represents. |
| 3591 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3592 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3593 | */ |
| 3594 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3595 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3596 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3597 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3598 | return this; |
| 3599 | } |
| 3600 | |
| 3601 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3602 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3603 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3604 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3605 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3606 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3607 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3608 | return setCustomContentView(views); |
| 3609 | } |
| 3610 | |
| 3611 | /** |
| 3612 | * Supply custom RemoteViews to use instead of the platform template. |
| 3613 | * |
| 3614 | * This will override the layout that would otherwise be constructed by this Builder |
| 3615 | * object. |
| 3616 | */ |
| 3617 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3618 | mN.contentView = contentView; |
| 3619 | return this; |
| 3620 | } |
| 3621 | |
| 3622 | /** |
| 3623 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3624 | * |
| 3625 | * This will override the expanded layout that would otherwise be constructed by this |
| 3626 | * Builder object. |
| 3627 | */ |
| 3628 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3629 | mN.bigContentView = contentView; |
| 3630 | return this; |
| 3631 | } |
| 3632 | |
| 3633 | /** |
| 3634 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3635 | * |
| 3636 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3637 | * Builder object. |
| 3638 | */ |
| 3639 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3640 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3641 | return this; |
| 3642 | } |
| 3643 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3644 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3645 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3646 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3647 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3648 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3649 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3650 | * 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] | 3651 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3652 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3653 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3654 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3655 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3656 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3657 | return this; |
| 3658 | } |
| 3659 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3660 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3661 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3662 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3663 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3664 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3665 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3666 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3667 | return this; |
| 3668 | } |
| 3669 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3670 | /** |
| 3671 | * An intent to launch instead of posting the notification to the status bar. |
| 3672 | * Only for use with extremely high-priority notifications demanding the user's |
| 3673 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3674 | * alarm clock that the user has explicitly set to a particular time. |
| 3675 | * If this facility is used for something else, please give the user an option |
| 3676 | * to turn it off and use a normal notification, as this can be extremely |
| 3677 | * disruptive. |
| 3678 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3679 | * <p> |
| 3680 | * The system UI may choose to display a heads-up notification, instead of |
| 3681 | * launching this intent, while the user is using the device. |
| 3682 | * </p> |
| 3683 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3684 | * @param intent The pending intent to launch. |
| 3685 | * @param highPriority Passing true will cause this notification to be sent |
| 3686 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3687 | * |
| 3688 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3689 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3690 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3691 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3692 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3693 | return this; |
| 3694 | } |
| 3695 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3696 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3697 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3698 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3699 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3700 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3701 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3702 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3703 | return this; |
| 3704 | } |
| 3705 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3706 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3707 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3708 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3709 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3710 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3711 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3712 | setTicker(tickerText); |
| 3713 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3714 | return this; |
| 3715 | } |
| 3716 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3717 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3718 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3719 | * |
| 3720 | * 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] | 3721 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3722 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3723 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3724 | public Builder setLargeIcon(Bitmap b) { |
| 3725 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3726 | } |
| 3727 | |
| 3728 | /** |
| 3729 | * Add a large icon to the notification content view. |
| 3730 | * |
| 3731 | * In the platform template, this image will be shown on the left of the notification view |
| 3732 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3733 | * badge atop the large icon). |
| 3734 | */ |
| 3735 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3736 | mN.mLargeIcon = icon; |
| 3737 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3738 | return this; |
| 3739 | } |
| 3740 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3741 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3742 | * Set the sound to play. |
| 3743 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3744 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 3745 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3746 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3747 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3748 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3749 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3750 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3751 | mN.sound = sound; |
| 3752 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3753 | return this; |
| 3754 | } |
| 3755 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3756 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3757 | * 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] | 3758 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3759 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 3760 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3761 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3762 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 3763 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3764 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 3765 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3766 | mN.sound = sound; |
| 3767 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3768 | return this; |
| 3769 | } |
| 3770 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3771 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3772 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 3773 | * use during playback. |
| 3774 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3775 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3776 | * @see Notification#sound |
| 3777 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3778 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3779 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3780 | mN.sound = sound; |
| 3781 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3782 | return this; |
| 3783 | } |
| 3784 | |
| 3785 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3786 | * Set the vibration pattern to use. |
| 3787 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3788 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 3789 | * <code>pattern</code> parameter. |
| 3790 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3791 | * <p> |
| 3792 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 3793 | * </p> |
| 3794 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3795 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3796 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3797 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3798 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3799 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3800 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3801 | return this; |
| 3802 | } |
| 3803 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3804 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3805 | * Set the desired color for the indicator LED on the device, as well as the |
| 3806 | * blink duty cycle (specified in milliseconds). |
| 3807 | * |
| 3808 | |
| 3809 | * Not all devices will honor all (or even any) of these values. |
| 3810 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3811 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3812 | * @see Notification#ledARGB |
| 3813 | * @see Notification#ledOnMS |
| 3814 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3815 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3816 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3817 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3818 | mN.ledARGB = argb; |
| 3819 | mN.ledOnMS = onMs; |
| 3820 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3821 | if (onMs != 0 || offMs != 0) { |
| 3822 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 3823 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3824 | return this; |
| 3825 | } |
| 3826 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3827 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3828 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3829 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3830 | |
| 3831 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 3832 | * must take care of canceling them. |
| 3833 | * |
| 3834 | |
| 3835 | * They are typically used to indicate a background task that the user is actively engaged |
| 3836 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 3837 | * (e.g., a file download, sync operation, active network connection). |
| 3838 | * |
| 3839 | |
| 3840 | * @see Notification#FLAG_ONGOING_EVENT |
| 3841 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3842 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3843 | public Builder setOngoing(boolean ongoing) { |
| 3844 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 3845 | return this; |
| 3846 | } |
| 3847 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3848 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3849 | * Set whether this notification should be colorized. When set, the color set with |
| 3850 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 3851 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3852 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 3853 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3854 | * <p> |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3855 | * For most styles, the coloring will only be applied if the notification is for a |
| 3856 | * foreground service notification. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3857 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3858 | * that have a media session attached there is no such requirement. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3859 | * |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3860 | * @see Builder#setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3861 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3862 | */ |
| 3863 | public Builder setColorized(boolean colorize) { |
| 3864 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 3865 | return this; |
| 3866 | } |
| 3867 | |
| 3868 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3869 | * Set this flag if you would only like the sound, vibrate |
| 3870 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3871 | * |
| 3872 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3873 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3874 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 3875 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 3876 | return this; |
| 3877 | } |
| 3878 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3879 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 3880 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3881 | * |
| 3882 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3883 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3884 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 3885 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3886 | return this; |
| 3887 | } |
| 3888 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3889 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3890 | * Set whether or not this notification should not bridge to other devices. |
| 3891 | * |
| 3892 | * <p>Some notifications can be bridged to other devices for remote display. |
| 3893 | * This hint can be set to recommend this notification not be bridged. |
| 3894 | */ |
| 3895 | public Builder setLocalOnly(boolean localOnly) { |
| 3896 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 3897 | return this; |
| 3898 | } |
| 3899 | |
| 3900 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3901 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3902 | * <p> |
| 3903 | * The value should be one or more of the following fields combined with |
| 3904 | * bitwise-or: |
| 3905 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 3906 | * <p> |
| 3907 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3908 | * |
| 3909 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3910 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3911 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3912 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3913 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3914 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3915 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3916 | return this; |
| 3917 | } |
| 3918 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3919 | /** |
| 3920 | * Set the priority of this notification. |
| 3921 | * |
| 3922 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3923 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3924 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3925 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3926 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3927 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3928 | return this; |
| 3929 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3930 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3931 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3932 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3933 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3934 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3935 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3936 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3937 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3938 | return this; |
| 3939 | } |
| 3940 | |
| 3941 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3942 | * Add a person that is relevant to this notification. |
| 3943 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3944 | * <P> |
| 3945 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3946 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 3947 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 3948 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3949 | * </P> |
| 3950 | * |
| 3951 | * <P> |
| 3952 | * The person should be specified by the {@code String} representation of a |
| 3953 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 3954 | * </P> |
| 3955 | * |
| 3956 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 3957 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 3958 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 3959 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3960 | * It is also possible to provide a URI with the schema {@code name:} in order to uniquely |
| 3961 | * identify a person without an entry in the contacts database. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3962 | * </P> |
| 3963 | * |
| 3964 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3965 | * @see Notification#EXTRA_PEOPLE |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3966 | * @deprecated use {@link #addPerson(Person)} |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3967 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3968 | public Builder addPerson(String uri) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 3969 | addPerson(new Person.Builder().setUri(uri).build()); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3970 | return this; |
| 3971 | } |
| 3972 | |
| 3973 | /** |
| 3974 | * Add a person that is relevant to this notification. |
| 3975 | * |
| 3976 | * <P> |
| 3977 | * Depending on user preferences, this annotation may allow the notification to pass |
| 3978 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 3979 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 3980 | * appear more prominently in the user interface. |
| 3981 | * </P> |
| 3982 | * |
| 3983 | * <P> |
| 3984 | * A person should usually contain a uri in order to benefit from the ranking boost. |
| 3985 | * However, even if no uri is provided, it's beneficial to provide other people in the |
| 3986 | * notification, such that listeners and voice only devices can announce and handle them |
| 3987 | * properly. |
| 3988 | * </P> |
| 3989 | * |
| 3990 | * @param person the person to add. |
| 3991 | * @see Notification#EXTRA_PEOPLE_LIST |
| 3992 | */ |
| 3993 | public Builder addPerson(Person person) { |
| 3994 | mPersonList.add(person); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3995 | return this; |
| 3996 | } |
| 3997 | |
| 3998 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3999 | * Set this notification to be part of a group of notifications sharing the same key. |
| 4000 | * Grouped notifications may display in a cluster or stack on devices which |
| 4001 | * support such rendering. |
| 4002 | * |
| 4003 | * <p>To make this notification the summary for its group, also call |
| 4004 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 4005 | * {@link #setSortKey}. |
| 4006 | * @param groupKey The group key of the group. |
| 4007 | * @return this object for method chaining |
| 4008 | */ |
| 4009 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4010 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4011 | return this; |
| 4012 | } |
| 4013 | |
| 4014 | /** |
| 4015 | * Set this notification to be the group summary for a group of notifications. |
| 4016 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 4017 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 4018 | * 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] | 4019 | * @param isGroupSummary Whether this notification should be a group summary. |
| 4020 | * @return this object for method chaining |
| 4021 | */ |
| 4022 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 4023 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 4024 | return this; |
| 4025 | } |
| 4026 | |
| 4027 | /** |
| 4028 | * Set a sort key that orders this notification among other notifications from the |
| 4029 | * same package. This can be useful if an external sort was already applied and an app |
| 4030 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 4031 | * value, although providing different priorities in addition to providing sort key may |
| 4032 | * cause this value to be ignored. |
| 4033 | * |
| 4034 | * <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] | 4035 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4036 | * |
| 4037 | * @see String#compareTo(String) |
| 4038 | */ |
| 4039 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4040 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4041 | return this; |
| 4042 | } |
| 4043 | |
| 4044 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4045 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4046 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4047 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 4048 | * |
| 4049 | * @see Notification#extras |
| 4050 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4051 | public Builder addExtras(Bundle extras) { |
| 4052 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4053 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4054 | } |
| 4055 | return this; |
| 4056 | } |
| 4057 | |
| 4058 | /** |
| 4059 | * Set metadata for this notification. |
| 4060 | * |
| 4061 | * <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] | 4062 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4063 | * called. |
| 4064 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4065 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 4066 | * Use {@link #addExtras} to merge in metadata instead. |
| 4067 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4068 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4069 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4070 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4071 | if (extras != null) { |
| 4072 | mUserExtras = extras; |
| 4073 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 4074 | return this; |
| 4075 | } |
| 4076 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4077 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4078 | * Get the current metadata Bundle used by this notification Builder. |
| 4079 | * |
| 4080 | * <p>The returned Bundle is shared with this Builder. |
| 4081 | * |
| 4082 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 4083 | * {@link #build()} is called. |
| 4084 | * |
| 4085 | * @see Notification#extras |
| 4086 | */ |
| 4087 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4088 | return mUserExtras; |
| 4089 | } |
| 4090 | |
| 4091 | private Bundle getAllExtras() { |
| 4092 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 4093 | saveExtras.putAll(mN.extras); |
| 4094 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4098 | * Add an action to this notification. Actions are typically displayed by |
| 4099 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4100 | * <p> |
| 4101 | * Every action must have an icon (32dp square and matching the |
| 4102 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4103 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4104 | * <p> |
| 4105 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4106 | * the order they were added. Actions will not be displayed when the notification is |
| 4107 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4108 | * 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] | 4109 | * |
| 4110 | * @param icon Resource ID of a drawable that represents the action. |
| 4111 | * @param title Text describing the action. |
| 4112 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4113 | * |
| 4114 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4115 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 4116 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4117 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4118 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4119 | return this; |
| 4120 | } |
| 4121 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4122 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4123 | * Add an action to this notification. Actions are typically displayed by |
| 4124 | * the system as a button adjacent to the notification content. |
| 4125 | * <p> |
| 4126 | * Every action must have an icon (32dp square and matching the |
| 4127 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 4128 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 4129 | * <p> |
| 4130 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 4131 | * the order they were added. Actions will not be displayed when the notification is |
| 4132 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 4133 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 4134 | * |
| 4135 | * @param action The action to add. |
| 4136 | */ |
| 4137 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4138 | if (action != null) { |
| 4139 | mActions.add(action); |
| 4140 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 4141 | return this; |
| 4142 | } |
| 4143 | |
| 4144 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4145 | * Alter the complete list of actions attached to this notification. |
| 4146 | * @see #addAction(Action). |
| 4147 | * |
| 4148 | * @param actions |
| 4149 | * @return |
| 4150 | */ |
| 4151 | public Builder setActions(Action... actions) { |
| 4152 | mActions.clear(); |
| 4153 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 4154 | if (actions[i] != null) { |
| 4155 | mActions.add(actions[i]); |
| 4156 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4157 | } |
| 4158 | return this; |
| 4159 | } |
| 4160 | |
| 4161 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4162 | * Add a rich notification style to be applied at build time. |
| 4163 | * |
| 4164 | * @param style Object responsible for modifying the notification style. |
| 4165 | */ |
| 4166 | public Builder setStyle(Style style) { |
| 4167 | if (mStyle != style) { |
| 4168 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4169 | if (mStyle != null) { |
| 4170 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4171 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 4172 | } else { |
| 4173 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4174 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4175 | } |
| 4176 | return this; |
| 4177 | } |
| 4178 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4179 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 4180 | * Returns the style set by {@link #setStyle(Style)}. |
| 4181 | */ |
| 4182 | public Style getStyle() { |
| 4183 | return mStyle; |
| 4184 | } |
| 4185 | |
| 4186 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4187 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4188 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4189 | * @return The same Builder. |
| 4190 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 4191 | public Builder setVisibility(@Visibility int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4192 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4193 | return this; |
| 4194 | } |
| 4195 | |
| 4196 | /** |
| 4197 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 4198 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 4199 | * @param n A replacement notification, presumably with some or all info redacted. |
| 4200 | * @return The same Builder. |
| 4201 | */ |
| 4202 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4203 | if (n != null) { |
| 4204 | mN.publicVersion = new Notification(); |
| 4205 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 4206 | } else { |
| 4207 | mN.publicVersion = null; |
| 4208 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4209 | return this; |
| 4210 | } |
| 4211 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4212 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4213 | * Apply an extender to this notification builder. Extenders may be used to add |
| 4214 | * metadata or change options on this builder. |
| 4215 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4216 | public Builder extend(Extender extender) { |
| 4217 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4218 | return this; |
| 4219 | } |
| 4220 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 4221 | /** |
| 4222 | * @hide |
| 4223 | */ |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4224 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4225 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4226 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4227 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4228 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4229 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4230 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4231 | } |
| 4232 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4233 | /** |
| 4234 | * Sets {@link Notification#color}. |
| 4235 | * |
| 4236 | * @param argb The accent color to use |
| 4237 | * |
| 4238 | * @return The same Builder. |
| 4239 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4240 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4241 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4242 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4243 | return this; |
| 4244 | } |
| 4245 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4246 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 4247 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 4248 | // This user can never be a badged profile, |
| 4249 | // and also includes USER_ALL system notifications. |
| 4250 | return null; |
| 4251 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 4252 | // Note: This assumes that the current user can read the profile badge of the |
| 4253 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 4254 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4255 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4256 | } |
| 4257 | |
| 4258 | private Bitmap getProfileBadge() { |
| 4259 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4260 | if (badge == null) { |
| 4261 | return null; |
| 4262 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4263 | final int size = mContext.getResources().getDimensionPixelSize( |
| 4264 | R.dimen.notification_badge_size); |
| 4265 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4266 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4267 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4268 | badge.draw(canvas); |
| 4269 | return bitmap; |
| 4270 | } |
| 4271 | |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4272 | private void bindProfileBadge(RemoteViews contentView) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4273 | Bitmap profileBadge = getProfileBadge(); |
| 4274 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4275 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4276 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 4277 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4278 | if (isColorized()) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4279 | contentView.setDrawableTint(R.id.profile_badge, false, |
| 4280 | getPrimaryTextColor(), PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4281 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4282 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4283 | } |
| 4284 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4285 | /** |
| 4286 | * @hide |
| 4287 | */ |
| 4288 | public boolean usesStandardHeader() { |
| 4289 | if (mN.mUsesStandardHeader) { |
| 4290 | return true; |
| 4291 | } |
| 4292 | if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.N) { |
| 4293 | if (mN.contentView == null && mN.bigContentView == null) { |
| 4294 | return true; |
| 4295 | } |
| 4296 | } |
| 4297 | boolean contentViewUsesHeader = mN.contentView == null |
| 4298 | || STANDARD_LAYOUTS.contains(mN.contentView.getLayoutId()); |
| 4299 | boolean bigContentViewUsesHeader = mN.bigContentView == null |
| 4300 | || STANDARD_LAYOUTS.contains(mN.bigContentView.getLayoutId()); |
| 4301 | return contentViewUsesHeader && bigContentViewUsesHeader; |
| 4302 | } |
| 4303 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4304 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4305 | resetNotificationHeader(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4306 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4307 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4308 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4309 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4310 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4311 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4312 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4313 | } |
| 4314 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4315 | /** |
| 4316 | * Resets the notification header to its original state |
| 4317 | */ |
| 4318 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 4319 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 4320 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 4321 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4322 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 4323 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4324 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 4325 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4326 | contentView.setViewVisibility(R.id.header_text_secondary, View.GONE); |
| 4327 | contentView.setTextViewText(R.id.header_text_secondary, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4328 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4329 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4330 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4331 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4332 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 4333 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4334 | mN.mUsesStandardHeader = false; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4335 | } |
| 4336 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4337 | private RemoteViews applyStandardTemplate(int resId, TemplateBindResult result) { |
| 4338 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this), |
| 4339 | result); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4340 | } |
| 4341 | |
| 4342 | /** |
| 4343 | * @param hasProgress whether the progress bar should be shown and set |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4344 | * @param result |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4345 | */ |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4346 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress, |
| 4347 | TemplateBindResult result) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4348 | return applyStandardTemplate(resId, mParams.reset().hasProgress(hasProgress) |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4349 | .fillTextsFrom(this), result); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 4350 | } |
| 4351 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4352 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p, |
| 4353 | TemplateBindResult result) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 4354 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 4355 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4356 | resetStandardTemplate(contentView); |
| 4357 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4358 | final Bundle ex = mN.extras; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4359 | updateBackgroundColor(contentView); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4360 | bindNotificationHeader(contentView, p.ambient, p.headerTextSecondary); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4361 | bindLargeIconAndReply(contentView, p, result); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4362 | boolean showProgress = handleProgressBar(p.hasProgress, contentView, ex); |
| 4363 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4364 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4365 | contentView.setTextViewText(R.id.title, processTextSpans(p.title)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4366 | if (!p.ambient) { |
| 4367 | setTextViewColorPrimary(contentView, R.id.title); |
| 4368 | } |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 4369 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 4370 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 4371 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4372 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4373 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4374 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 4375 | : com.android.internal.R.id.text; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4376 | contentView.setTextViewText(textId, processTextSpans(p.text)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4377 | if (!p.ambient) { |
| 4378 | setTextViewColorSecondary(contentView, textId); |
| 4379 | } |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4380 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4381 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4382 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4383 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4384 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4385 | return contentView; |
| 4386 | } |
| 4387 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4388 | private CharSequence processTextSpans(CharSequence text) { |
| 4389 | if (hasForegroundColor()) { |
Selim Cinek | 87c3153 | 2017-08-18 18:53:44 -0700 | [diff] [blame] | 4390 | return NotificationColorUtil.clearColorSpans(text); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4391 | } |
| 4392 | return text; |
| 4393 | } |
| 4394 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4395 | private void setTextViewColorPrimary(RemoteViews contentView, int id) { |
| 4396 | ensureColors(); |
| 4397 | contentView.setTextColor(id, mPrimaryTextColor); |
| 4398 | } |
| 4399 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4400 | private boolean hasForegroundColor() { |
| 4401 | return mForegroundColor != COLOR_INVALID; |
| 4402 | } |
| 4403 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4404 | /** |
| 4405 | * @return the primary text color |
| 4406 | * @hide |
| 4407 | */ |
| 4408 | @VisibleForTesting |
| 4409 | public int getPrimaryTextColor() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4410 | ensureColors(); |
| 4411 | return mPrimaryTextColor; |
| 4412 | } |
| 4413 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4414 | /** |
| 4415 | * @return the secondary text color |
| 4416 | * @hide |
| 4417 | */ |
| 4418 | @VisibleForTesting |
| 4419 | public int getSecondaryTextColor() { |
| 4420 | ensureColors(); |
| 4421 | return mSecondaryTextColor; |
| 4422 | } |
| 4423 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4424 | private void setTextViewColorSecondary(RemoteViews contentView, int id) { |
| 4425 | ensureColors(); |
| 4426 | contentView.setTextColor(id, mSecondaryTextColor); |
| 4427 | } |
| 4428 | |
| 4429 | private void ensureColors() { |
| 4430 | int backgroundColor = getBackgroundColor(); |
| 4431 | if (mPrimaryTextColor == COLOR_INVALID |
| 4432 | || mSecondaryTextColor == COLOR_INVALID |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4433 | || mTextColorsAreForBackground != backgroundColor) { |
| 4434 | mTextColorsAreForBackground = backgroundColor; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4435 | if (!hasForegroundColor() || !isColorized()) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4436 | mPrimaryTextColor = NotificationColorUtil.resolvePrimaryColor(mContext, |
| 4437 | backgroundColor); |
| 4438 | mSecondaryTextColor = NotificationColorUtil.resolveSecondaryColor(mContext, |
| 4439 | backgroundColor); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 4440 | if (backgroundColor != COLOR_DEFAULT && isColorized()) { |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4441 | mPrimaryTextColor = NotificationColorUtil.findAlphaToMeetContrast( |
| 4442 | mPrimaryTextColor, backgroundColor, 4.5); |
| 4443 | mSecondaryTextColor = NotificationColorUtil.findAlphaToMeetContrast( |
| 4444 | mSecondaryTextColor, backgroundColor, 4.5); |
| 4445 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4446 | } else { |
| 4447 | double backLum = NotificationColorUtil.calculateLuminance(backgroundColor); |
| 4448 | double textLum = NotificationColorUtil.calculateLuminance(mForegroundColor); |
| 4449 | double contrast = NotificationColorUtil.calculateContrast(mForegroundColor, |
| 4450 | backgroundColor); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4451 | // We only respect the given colors if worst case Black or White still has |
| 4452 | // contrast |
| 4453 | boolean backgroundLight = backLum > textLum |
| 4454 | && satisfiesTextContrast(backgroundColor, Color.BLACK) |
| 4455 | || backLum <= textLum |
| 4456 | && !satisfiesTextContrast(backgroundColor, Color.WHITE); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4457 | if (contrast < 4.5f) { |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4458 | if (backgroundLight) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4459 | mSecondaryTextColor = NotificationColorUtil.findContrastColor( |
| 4460 | mForegroundColor, |
| 4461 | backgroundColor, |
| 4462 | true /* findFG */, |
| 4463 | 4.5f); |
| 4464 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4465 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_LIGHT); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4466 | } else { |
| 4467 | mSecondaryTextColor = |
| 4468 | NotificationColorUtil.findContrastColorAgainstDark( |
| 4469 | mForegroundColor, |
| 4470 | backgroundColor, |
| 4471 | true /* findFG */, |
| 4472 | 4.5f); |
| 4473 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4474 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4475 | } |
| 4476 | } else { |
| 4477 | mPrimaryTextColor = mForegroundColor; |
| 4478 | mSecondaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4479 | mPrimaryTextColor, backgroundLight ? LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4480 | : LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4481 | if (NotificationColorUtil.calculateContrast(mSecondaryTextColor, |
| 4482 | backgroundColor) < 4.5f) { |
| 4483 | // oh well the secondary is not good enough |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4484 | if (backgroundLight) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4485 | mSecondaryTextColor = NotificationColorUtil.findContrastColor( |
| 4486 | mSecondaryTextColor, |
| 4487 | backgroundColor, |
| 4488 | true /* findFG */, |
| 4489 | 4.5f); |
| 4490 | } else { |
| 4491 | mSecondaryTextColor |
| 4492 | = NotificationColorUtil.findContrastColorAgainstDark( |
| 4493 | mSecondaryTextColor, |
| 4494 | backgroundColor, |
| 4495 | true /* findFG */, |
| 4496 | 4.5f); |
| 4497 | } |
| 4498 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4499 | mSecondaryTextColor, backgroundLight |
| 4500 | ? -LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4501 | : -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4502 | } |
| 4503 | } |
| 4504 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4505 | } |
| 4506 | } |
| 4507 | |
| 4508 | private void updateBackgroundColor(RemoteViews contentView) { |
| 4509 | if (isColorized()) { |
| 4510 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
| 4511 | getBackgroundColor()); |
| 4512 | } else { |
| 4513 | // Clear it! |
| 4514 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 4515 | 0); |
| 4516 | } |
| 4517 | } |
| 4518 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4519 | /** |
| 4520 | * @param remoteView the remote view to update the minheight in |
| 4521 | * @param hasMinHeight does it have a mimHeight |
| 4522 | * @hide |
| 4523 | */ |
| 4524 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 4525 | int minHeight = 0; |
| 4526 | if (hasMinHeight) { |
| 4527 | // we need to set the minHeight of the notification |
| 4528 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 4529 | com.android.internal.R.dimen.notification_min_content_height); |
| 4530 | } |
| 4531 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 4532 | } |
| 4533 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4534 | private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4535 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4536 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 4537 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 4538 | if (hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4539 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4540 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4541 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4542 | contentView.setProgressBackgroundTintList( |
| 4543 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 4544 | R.color.notification_progress_background_color))); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4545 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4546 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4547 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 4548 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4549 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4550 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4551 | } else { |
| 4552 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4553 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 4554 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4555 | } |
| 4556 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4557 | private void bindLargeIconAndReply(RemoteViews contentView, StandardTemplateParams p, |
| 4558 | TemplateBindResult result) { |
| 4559 | boolean largeIconShown = bindLargeIcon(contentView, p.hideLargeIcon || p.ambient); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4560 | boolean replyIconShown = bindReplyIcon(contentView, p.hideReplyIcon || p.ambient); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4561 | contentView.setViewVisibility(R.id.right_icon_container, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4562 | largeIconShown || replyIconShown ? View.VISIBLE : View.GONE); |
| 4563 | int marginEnd = calculateMarginEnd(largeIconShown, replyIconShown); |
| 4564 | contentView.setViewLayoutMarginEnd(R.id.line1, marginEnd); |
| 4565 | contentView.setViewLayoutMarginEnd(R.id.text, marginEnd); |
| 4566 | contentView.setViewLayoutMarginEnd(R.id.progress, marginEnd); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4567 | if (result != null) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4568 | result.setIconMarginEnd(marginEnd); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4569 | } |
| 4570 | } |
| 4571 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 4572 | private int calculateMarginEnd(boolean largeIconShown, boolean replyIconShown) { |
| 4573 | int marginEnd = 0; |
| 4574 | int contentMargin = mContext.getResources().getDimensionPixelSize( |
| 4575 | R.dimen.notification_content_margin_end); |
| 4576 | int iconSize = mContext.getResources().getDimensionPixelSize( |
| 4577 | R.dimen.notification_right_icon_size); |
| 4578 | if (replyIconShown) { |
| 4579 | // The size of the reply icon |
| 4580 | marginEnd += iconSize; |
| 4581 | |
| 4582 | int replyInset = mContext.getResources().getDimensionPixelSize( |
| 4583 | R.dimen.notification_reply_inset); |
| 4584 | // We're subtracting the inset of the reply icon to make sure it's |
| 4585 | // aligned nicely on the right, and remove it from the following padding |
| 4586 | marginEnd -= replyInset * 2; |
| 4587 | } |
| 4588 | if (largeIconShown) { |
| 4589 | // adding size of the right icon |
| 4590 | marginEnd += iconSize; |
| 4591 | |
| 4592 | if (replyIconShown) { |
| 4593 | // We also add some padding to the reply icon if it's around |
| 4594 | marginEnd += contentMargin; |
| 4595 | } |
| 4596 | } |
| 4597 | if (replyIconShown || largeIconShown) { |
| 4598 | // The padding to the content |
| 4599 | marginEnd += contentMargin; |
| 4600 | } |
| 4601 | return marginEnd; |
| 4602 | } |
| 4603 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4604 | /** |
| 4605 | * Bind the large icon. |
| 4606 | * @return if the largeIcon is visible |
| 4607 | */ |
| 4608 | private boolean bindLargeIcon(RemoteViews contentView, boolean hideLargeIcon) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4609 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 4610 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 4611 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4612 | boolean showLargeIcon = mN.mLargeIcon != null && !hideLargeIcon; |
| 4613 | if (showLargeIcon) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4614 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 4615 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
| 4616 | processLargeLegacyIcon(mN.mLargeIcon, contentView); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4617 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4618 | return showLargeIcon; |
| 4619 | } |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4620 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4621 | /** |
| 4622 | * Bind the reply icon. |
| 4623 | * @return if the reply icon is visible |
| 4624 | */ |
| 4625 | private boolean bindReplyIcon(RemoteViews contentView, boolean hideReplyIcon) { |
| 4626 | boolean actionVisible = !hideReplyIcon; |
| 4627 | Action action = null; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4628 | if (actionVisible) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4629 | action = findReplyAction(); |
| 4630 | actionVisible = action != null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4631 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4632 | if (actionVisible) { |
| 4633 | contentView.setViewVisibility(R.id.reply_icon_action, View.VISIBLE); |
| 4634 | contentView.setDrawableTint(R.id.reply_icon_action, |
| 4635 | false /* targetBackground */, |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 4636 | getNeutralColor(), |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4637 | PorterDuff.Mode.SRC_ATOP); |
| 4638 | contentView.setOnClickPendingIntent(R.id.reply_icon_action, action.actionIntent); |
| 4639 | contentView.setRemoteInputs(R.id.reply_icon_action, action.mRemoteInputs); |
| 4640 | } else { |
| 4641 | contentView.setRemoteInputs(R.id.reply_icon_action, null); |
| 4642 | } |
| 4643 | contentView.setViewVisibility(R.id.reply_icon_action, |
| 4644 | actionVisible ? View.VISIBLE : View.GONE); |
| 4645 | return actionVisible; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | private Action findReplyAction() { |
| 4649 | ArrayList<Action> actions = mActions; |
| 4650 | if (mOriginalActions != null) { |
| 4651 | actions = mOriginalActions; |
| 4652 | } |
| 4653 | int numActions = actions.size(); |
| 4654 | for (int i = 0; i < numActions; i++) { |
| 4655 | Action action = actions.get(i); |
| 4656 | if (hasValidRemoteInput(action)) { |
| 4657 | return action; |
| 4658 | } |
| 4659 | } |
| 4660 | return null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4661 | } |
| 4662 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4663 | private void bindNotificationHeader(RemoteViews contentView, boolean ambient, |
| 4664 | CharSequence secondaryHeaderText) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4665 | bindSmallIcon(contentView, ambient); |
| 4666 | bindHeaderAppName(contentView, ambient); |
| 4667 | if (!ambient) { |
| 4668 | // Ambient view does not have these |
| 4669 | bindHeaderText(contentView); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4670 | bindHeaderTextSecondary(contentView, secondaryHeaderText); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4671 | bindHeaderChronometerAndTime(contentView); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4672 | bindProfileBadge(contentView); |
| 4673 | } |
Julia Reynolds | 6013e5c | 2018-04-18 08:43:34 -0400 | [diff] [blame] | 4674 | bindActivePermissions(contentView, ambient); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 4675 | bindExpandButton(contentView); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 4676 | mN.mUsesStandardHeader = true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4677 | } |
| 4678 | |
Julia Reynolds | 6013e5c | 2018-04-18 08:43:34 -0400 | [diff] [blame] | 4679 | private void bindActivePermissions(RemoteViews contentView, boolean ambient) { |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 4680 | int color = ambient ? resolveAmbientColor() : getNeutralColor(); |
Julia Reynolds | b887b23 | 2018-04-10 16:38:08 -0400 | [diff] [blame] | 4681 | contentView.setDrawableTint(R.id.camera, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4682 | contentView.setDrawableTint(R.id.mic, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4683 | contentView.setDrawableTint(R.id.overlay, false, color, PorterDuff.Mode.SRC_ATOP); |
| 4684 | } |
| 4685 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4686 | private void bindExpandButton(RemoteViews contentView) { |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 4687 | int color = isColorized() ? getPrimaryTextColor() : getSecondaryTextColor(); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4688 | contentView.setDrawableTint(R.id.expand_button, false, color, |
| 4689 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4690 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4691 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4692 | } |
| 4693 | |
| 4694 | private void bindHeaderChronometerAndTime(RemoteViews contentView) { |
| 4695 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4696 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4697 | setTextViewColorSecondary(contentView, R.id.time_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4698 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 4699 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 4700 | contentView.setLong(R.id.chronometer, "setBase", |
| 4701 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 4702 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4703 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 4704 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4705 | setTextViewColorSecondary(contentView, R.id.chronometer); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4706 | } else { |
| 4707 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 4708 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4709 | setTextViewColorSecondary(contentView, R.id.time); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4710 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4711 | } else { |
| 4712 | // We still want a time to be set but gone, such that we can show and hide it |
| 4713 | // on demand in case it's a child notification without anything in the header |
| 4714 | 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] | 4715 | } |
| 4716 | } |
| 4717 | |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4718 | private void bindHeaderText(RemoteViews contentView) { |
| 4719 | CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 4720 | if (headerText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4721 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4722 | headerText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4723 | } |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4724 | if (headerText == null |
| 4725 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 4726 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 4727 | headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 4728 | } |
| 4729 | if (headerText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4730 | // 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] | 4731 | contentView.setTextViewText(R.id.header_text, processTextSpans( |
| 4732 | processLegacyText(headerText))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4733 | setTextViewColorSecondary(contentView, R.id.header_text); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4734 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 4735 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4736 | setTextViewColorSecondary(contentView, R.id.header_text_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4737 | } |
| 4738 | } |
| 4739 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4740 | private void bindHeaderTextSecondary(RemoteViews contentView, CharSequence secondaryText) { |
| 4741 | if (!TextUtils.isEmpty(secondaryText)) { |
| 4742 | contentView.setTextViewText(R.id.header_text_secondary, processTextSpans( |
| 4743 | processLegacyText(secondaryText))); |
| 4744 | setTextViewColorSecondary(contentView, R.id.header_text_secondary); |
| 4745 | contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE); |
| 4746 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE); |
| 4747 | setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider); |
| 4748 | } |
| 4749 | } |
| 4750 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4751 | /** |
| 4752 | * @hide |
| 4753 | */ |
| 4754 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4755 | CharSequence name = null; |
| 4756 | final PackageManager pm = mContext.getPackageManager(); |
| 4757 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 4758 | // only system packages which lump together a bunch of unrelated stuff |
| 4759 | // may substitute a different name to make the purpose of the |
| 4760 | // notification more clear. the correct package label should always |
| 4761 | // be accessible via SystemUI. |
| 4762 | final String pkg = mContext.getPackageName(); |
| 4763 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 4764 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 4765 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 4766 | name = subName; |
| 4767 | } else { |
| 4768 | Log.w(TAG, "warning: pkg " |
| 4769 | + pkg + " attempting to substitute app name '" + subName |
| 4770 | + "' without holding perm " |
| 4771 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 4772 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4773 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4774 | if (TextUtils.isEmpty(name)) { |
| 4775 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 4776 | } |
| 4777 | if (TextUtils.isEmpty(name)) { |
| 4778 | // still nothing? |
| 4779 | return null; |
| 4780 | } |
| 4781 | |
| 4782 | return String.valueOf(name); |
| 4783 | } |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4784 | private void bindHeaderAppName(RemoteViews contentView, boolean ambient) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4785 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4786 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4787 | setTextViewColorPrimary(contentView, R.id.app_name_text); |
| 4788 | } else { |
| 4789 | contentView.setTextColor(R.id.app_name_text, |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 4790 | ambient ? resolveAmbientColor() : getSecondaryTextColor()); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4791 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4792 | } |
| 4793 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4794 | private void bindSmallIcon(RemoteViews contentView, boolean ambient) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4795 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 4796 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 4797 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4798 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4799 | contentView.setInt(R.id.icon, "setImageLevel", mN.iconLevel); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4800 | processSmallIconColor(mN.mSmallIcon, contentView, ambient); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4801 | } |
| 4802 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4803 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4804 | * @return true if the built notification will show the time or the chronometer; false |
| 4805 | * otherwise |
| 4806 | */ |
| 4807 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 4808 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4809 | } |
| 4810 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4811 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4812 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 4813 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4814 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4815 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4816 | |
| 4817 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 4818 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 4819 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, View.GONE); |
| 4820 | big.setViewVisibility(R.id.notification_material_reply_progress, View.GONE); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4821 | |
| 4822 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 4823 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 4824 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 4825 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 4826 | |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 4827 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 4828 | R.dimen.notification_content_margin); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4829 | } |
| 4830 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4831 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 4832 | TemplateBindResult result) { |
| 4833 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this), |
| 4834 | result); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 4835 | } |
| 4836 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4837 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4838 | StandardTemplateParams p, TemplateBindResult result) { |
| 4839 | RemoteViews big = applyStandardTemplate(layoutId, p, result); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4840 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4841 | resetStandardTemplateWithActions(big); |
| 4842 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4843 | boolean validRemoteInput = false; |
| 4844 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4845 | int N = mActions.size(); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4846 | boolean emphazisedMode = mN.fullScreenIntent != null && !p.ambient; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4847 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4848 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 4849 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4850 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 4851 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4852 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4853 | for (int i=0; i<N; i++) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4854 | Action action = mActions.get(i); |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 4855 | boolean actionHasValidInput = hasValidRemoteInput(action); |
| 4856 | validRemoteInput |= actionHasValidInput; |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4857 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4858 | final RemoteViews button = generateActionButton(action, emphazisedMode, |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 4859 | p.ambient); |
| 4860 | if (actionHasValidInput && !emphazisedMode) { |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 4861 | // Clear the drawable |
| 4862 | button.setInt(R.id.action0, "setBackgroundResource", 0); |
| 4863 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4864 | big.addView(R.id.actions, button); |
| 4865 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4866 | } else { |
| 4867 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4868 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4869 | |
| 4870 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4871 | if (!p.ambient && validRemoteInput && replyText != null |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4872 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 4873 | boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4874 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 4875 | big.setViewVisibility(R.id.notification_material_reply_text_1_container, |
| 4876 | View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4877 | big.setTextViewText(R.id.notification_material_reply_text_1, |
| 4878 | processTextSpans(replyText[0])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4879 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 4880 | big.setViewVisibility(R.id.notification_material_reply_progress, |
| 4881 | showSpinner ? View.VISIBLE : View.GONE); |
| 4882 | big.setProgressIndeterminateTintList( |
| 4883 | R.id.notification_material_reply_progress, |
| 4884 | ColorStateList.valueOf( |
| 4885 | isColorized() ? getPrimaryTextColor() : resolveContrastColor())); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4886 | |
| 4887 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) { |
| 4888 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4889 | big.setTextViewText(R.id.notification_material_reply_text_2, |
| 4890 | processTextSpans(replyText[1])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4891 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4892 | |
| 4893 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) { |
| 4894 | big.setViewVisibility( |
| 4895 | R.id.notification_material_reply_text_3, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4896 | big.setTextViewText(R.id.notification_material_reply_text_3, |
| 4897 | processTextSpans(replyText[2])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4898 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4899 | } |
| 4900 | } |
| 4901 | } |
| 4902 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4903 | return big; |
| 4904 | } |
| 4905 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4906 | private boolean hasValidRemoteInput(Action action) { |
| 4907 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 4908 | // Weird actions |
| 4909 | return false; |
| 4910 | } |
| 4911 | |
| 4912 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 4913 | if (remoteInputs == null) { |
| 4914 | return false; |
| 4915 | } |
| 4916 | |
| 4917 | for (RemoteInput r : remoteInputs) { |
| 4918 | CharSequence[] choices = r.getChoices(); |
| 4919 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 4920 | return true; |
| 4921 | } |
| 4922 | } |
| 4923 | return false; |
| 4924 | } |
| 4925 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4926 | /** |
| 4927 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 4928 | * 1. Custom contentView from the caller |
| 4929 | * 2. Style's proposed content view |
| 4930 | * 3. Standard template view |
| 4931 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4932 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4933 | return createContentView(false /* increasedheight */ ); |
| 4934 | } |
| 4935 | |
| 4936 | /** |
| 4937 | * Construct a RemoteViews for the smaller content view. |
| 4938 | * |
| 4939 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 4940 | * styles may support showing more then just that basic 1U size |
| 4941 | * and the system may decide to render important notifications |
| 4942 | * slightly bigger even when collapsed. |
| 4943 | * |
| 4944 | * @hide |
| 4945 | */ |
| 4946 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4947 | if (mN.contentView != null && useExistingRemoteView()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4948 | return mN.contentView; |
| 4949 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4950 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4951 | if (styleView != null) { |
| 4952 | return styleView; |
| 4953 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4954 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4955 | return applyStandardTemplate(getBaseLayoutResource(), null /* result */); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4956 | } |
| 4957 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4958 | private boolean useExistingRemoteView() { |
| 4959 | return mStyle == null || (!mStyle.displayCustomViewInline() |
| 4960 | && !mRebuildStyledRemoteViews); |
| 4961 | } |
| 4962 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4963 | /** |
| 4964 | * Construct a RemoteViews for the final big notification layout. |
| 4965 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4966 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4967 | RemoteViews result = null; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4968 | if (mN.bigContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4969 | return mN.bigContentView; |
| 4970 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4971 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 4972 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4973 | } else if (mActions.size() != 0) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 4974 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 4975 | null /* result */); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4976 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4977 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4978 | return result; |
| 4979 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4980 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4981 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4982 | * Construct a RemoteViews for the final notification header only. This will not be |
| 4983 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4984 | * |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4985 | * @param ambient if true, generate the header for the ambient display layout. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4986 | * @hide |
| 4987 | */ |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4988 | public RemoteViews makeNotificationHeader(boolean ambient) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4989 | Boolean colorized = (Boolean) mN.extras.get(EXTRA_COLORIZED); |
| 4990 | mN.extras.putBoolean(EXTRA_COLORIZED, false); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4991 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4992 | ambient ? R.layout.notification_template_ambient_header |
| 4993 | : R.layout.notification_template_header); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4994 | resetNotificationHeader(header); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4995 | bindNotificationHeader(header, ambient, null); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4996 | if (colorized != null) { |
| 4997 | mN.extras.putBoolean(EXTRA_COLORIZED, colorized); |
| 4998 | } else { |
| 4999 | mN.extras.remove(EXTRA_COLORIZED); |
| 5000 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 5001 | return header; |
| 5002 | } |
| 5003 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5004 | /** |
| 5005 | * Construct a RemoteViews for the ambient version of the notification. |
| 5006 | * |
| 5007 | * @hide |
| 5008 | */ |
| 5009 | public RemoteViews makeAmbientNotification() { |
| 5010 | RemoteViews ambient = applyStandardTemplateWithActions( |
| 5011 | R.layout.notification_template_material_ambient, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5012 | mParams.reset().ambient(true).fillTextsFrom(this).hasProgress(false), |
| 5013 | null /* result */); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5014 | return ambient; |
| 5015 | } |
| 5016 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5017 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5018 | if (result != null) { |
| 5019 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 5020 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 5021 | } |
| 5022 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5023 | /** |
| 5024 | * Adapt the Notification header if this view is used as an expanded view. |
| 5025 | * |
| 5026 | * @hide |
| 5027 | */ |
| 5028 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 5029 | if (result != null) { |
| 5030 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 5031 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5032 | } |
| 5033 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5034 | /** |
| 5035 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5036 | * |
| 5037 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 5038 | * styles may support showing more then just that basic 1U size |
| 5039 | * and the system may decide to render important notifications |
| 5040 | * slightly bigger even when collapsed. |
| 5041 | * |
| 5042 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5043 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5044 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5045 | if (mN.headsUpContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5046 | return mN.headsUpContentView; |
| 5047 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5048 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 5049 | if (styleView != null) { |
| 5050 | return styleView; |
| 5051 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 5052 | } else if (mActions.size() == 0) { |
| 5053 | return null; |
| 5054 | } |
| 5055 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5056 | return applyStandardTemplateWithActions(getBigBaseLayoutResource(), null /* result */); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5057 | } |
| 5058 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5059 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5060 | * Construct a RemoteViews for the final heads-up notification layout. |
| 5061 | */ |
| 5062 | public RemoteViews createHeadsUpContentView() { |
| 5063 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 5064 | } |
| 5065 | |
| 5066 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5067 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5068 | * |
| 5069 | * @hide |
| 5070 | */ |
| 5071 | public RemoteViews makePublicContentView() { |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5072 | return makePublicView(false /* ambient */); |
| 5073 | } |
| 5074 | |
| 5075 | /** |
| 5076 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 5077 | * |
| 5078 | * @hide |
| 5079 | */ |
| 5080 | public RemoteViews makePublicAmbientNotification() { |
| 5081 | return makePublicView(true /* ambient */); |
| 5082 | } |
| 5083 | |
| 5084 | private RemoteViews makePublicView(boolean ambient) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5085 | if (mN.publicVersion != null) { |
| 5086 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5087 | return ambient ? builder.makeAmbientNotification() : builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5088 | } |
| 5089 | Bundle savedBundle = mN.extras; |
| 5090 | Style style = mStyle; |
| 5091 | mStyle = null; |
| 5092 | Icon largeIcon = mN.mLargeIcon; |
| 5093 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5094 | Bitmap largeIconLegacy = mN.largeIcon; |
| 5095 | mN.largeIcon = null; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5096 | ArrayList<Action> actions = mActions; |
| 5097 | mActions = new ArrayList<>(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5098 | Bundle publicExtras = new Bundle(); |
| 5099 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 5100 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 5101 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 5102 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5103 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 5104 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5105 | mN.extras = publicExtras; |
Selim Cinek | 499c20f | 2017-07-20 14:06:09 -0700 | [diff] [blame] | 5106 | RemoteViews view; |
| 5107 | if (ambient) { |
| 5108 | publicExtras.putCharSequence(EXTRA_TITLE, |
| 5109 | mContext.getString(com.android.internal.R.string.notification_hidden_text)); |
| 5110 | view = makeAmbientNotification(); |
| 5111 | } else{ |
| 5112 | view = makeNotificationHeader(false /* ambient */); |
| 5113 | view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true); |
| 5114 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5115 | mN.extras = savedBundle; |
| 5116 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5117 | mN.largeIcon = largeIconLegacy; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 5118 | mActions = actions; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5119 | mStyle = style; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 5120 | return view; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5121 | } |
| 5122 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5123 | /** |
| 5124 | * Construct a content view for the display when low - priority |
| 5125 | * |
| 5126 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 5127 | * a new subtext is created consisting of the content of the |
| 5128 | * notification. |
| 5129 | * @hide |
| 5130 | */ |
| 5131 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
| 5132 | int color = mN.color; |
| 5133 | mN.color = COLOR_DEFAULT; |
| 5134 | CharSequence summary = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 5135 | if (!useRegularSubtext || TextUtils.isEmpty(summary)) { |
| 5136 | CharSequence newSummary = createSummaryText(); |
| 5137 | if (!TextUtils.isEmpty(newSummary)) { |
| 5138 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, newSummary); |
| 5139 | } |
| 5140 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 5141 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 5142 | RemoteViews header = makeNotificationHeader(false /* ambient */); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 5143 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5144 | if (summary != null) { |
| 5145 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, summary); |
| 5146 | } else { |
| 5147 | mN.extras.remove(EXTRA_SUB_TEXT); |
| 5148 | } |
| 5149 | mN.color = color; |
| 5150 | return header; |
| 5151 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 5152 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 5153 | private CharSequence createSummaryText() { |
| 5154 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 5155 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 5156 | return titleText; |
| 5157 | } |
| 5158 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 5159 | if (titleText == null) { |
| 5160 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 5161 | } |
| 5162 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5163 | if (titleText != null) { |
| 5164 | summary.append(bidi.unicodeWrap(titleText)); |
| 5165 | } |
| 5166 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 5167 | if (titleText != null && contentText != null) { |
| 5168 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 5169 | R.string.notification_header_divider_symbol_with_spaces))); |
| 5170 | } |
| 5171 | if (contentText != null) { |
| 5172 | summary.append(bidi.unicodeWrap(contentText)); |
| 5173 | } |
| 5174 | return summary; |
| 5175 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 5176 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5177 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5178 | boolean ambient) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5179 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 5180 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5181 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 5182 | : tombstone ? getActionTombstoneLayoutResource() |
| 5183 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 5184 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5185 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 5186 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5187 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5188 | if (action.mRemoteInputs != null) { |
| 5189 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 5190 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5191 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5192 | // change the background bgColor |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5193 | CharSequence title = action.title; |
| 5194 | ColorStateList[] outResultColor = null; |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5195 | int background = resolveBackgroundColor(); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5196 | if (isLegacy()) { |
Selim Cinek | 87c3153 | 2017-08-18 18:53:44 -0700 | [diff] [blame] | 5197 | title = NotificationColorUtil.clearColorSpans(title); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5198 | } else { |
| 5199 | outResultColor = new ColorStateList[1]; |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5200 | title = ensureColorSpanContrast(title, background, outResultColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5201 | } |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5202 | button.setTextViewText(R.id.action0, processTextSpans(title)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5203 | setTextViewColorPrimary(button, R.id.action0); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5204 | int rippleColor; |
| 5205 | boolean hasColorOverride = outResultColor != null && outResultColor[0] != null; |
| 5206 | if (hasColorOverride) { |
| 5207 | // There's a span spanning the full text, let's take it and use it as the |
| 5208 | // background color |
| 5209 | background = outResultColor[0].getDefaultColor(); |
| 5210 | int textColor = NotificationColorUtil.resolvePrimaryColor(mContext, |
| 5211 | background); |
| 5212 | button.setTextColor(R.id.action0, textColor); |
| 5213 | rippleColor = textColor; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5214 | } else if (mN.color != COLOR_DEFAULT && !isColorized() && mTintActionButtons) { |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5215 | rippleColor = resolveContrastColor(); |
| 5216 | button.setTextColor(R.id.action0, rippleColor); |
| 5217 | } else { |
| 5218 | rippleColor = getPrimaryTextColor(); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5219 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5220 | // We only want about 20% alpha for the ripple |
| 5221 | rippleColor = (rippleColor & 0x00ffffff) | 0x33000000; |
| 5222 | button.setColorStateList(R.id.action0, "setRippleColor", |
| 5223 | ColorStateList.valueOf(rippleColor)); |
| 5224 | button.setColorStateList(R.id.action0, "setButtonBackground", |
| 5225 | ColorStateList.valueOf(background)); |
| 5226 | button.setBoolean(R.id.action0, "setHasStroke", !hasColorOverride); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5227 | } else { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5228 | button.setTextViewText(R.id.action0, processTextSpans( |
| 5229 | processLegacyText(action.title))); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 5230 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5231 | setTextViewColorPrimary(button, R.id.action0); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5232 | } else if (mN.color != COLOR_DEFAULT && mTintActionButtons) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5233 | button.setTextColor(R.id.action0, |
| 5234 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5235 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 5236 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 5237 | return button; |
| 5238 | } |
| 5239 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5240 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5241 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 5242 | * text if a span was found that spans over the whole text. |
| 5243 | * |
| 5244 | * @param charSequence the charSequence on which the spans are |
| 5245 | * @param background the background color to ensure the contrast against |
| 5246 | * @param outResultColor an array in which a color will be returned as the first element if |
| 5247 | * there exists a full length color span. |
| 5248 | * @return the contrasted charSequence |
| 5249 | */ |
| 5250 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 5251 | ColorStateList[] outResultColor) { |
| 5252 | if (charSequence instanceof Spanned) { |
| 5253 | Spanned ss = (Spanned) charSequence; |
| 5254 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 5255 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 5256 | for (Object span : spans) { |
| 5257 | Object resultSpan = span; |
| 5258 | int spanStart = ss.getSpanStart(span); |
| 5259 | int spanEnd = ss.getSpanEnd(span); |
| 5260 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 5261 | if (resultSpan instanceof CharacterStyle) { |
| 5262 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 5263 | } |
| 5264 | if (resultSpan instanceof TextAppearanceSpan) { |
| 5265 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 5266 | ColorStateList textColor = originalSpan.getTextColor(); |
| 5267 | if (textColor != null) { |
| 5268 | int[] colors = textColor.getColors(); |
| 5269 | int[] newColors = new int[colors.length]; |
| 5270 | for (int i = 0; i < newColors.length; i++) { |
| 5271 | newColors[i] = NotificationColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5272 | colors[i], background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5273 | } |
| 5274 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 5275 | newColors); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5276 | if (fullLength) { |
| 5277 | outResultColor[0] = textColor; |
| 5278 | // Let's drop the color from the span |
| 5279 | textColor = null; |
| 5280 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5281 | resultSpan = new TextAppearanceSpan( |
| 5282 | originalSpan.getFamily(), |
| 5283 | originalSpan.getTextStyle(), |
| 5284 | originalSpan.getTextSize(), |
| 5285 | textColor, |
| 5286 | originalSpan.getLinkTextColor()); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5287 | } |
| 5288 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 5289 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 5290 | int foregroundColor = originalSpan.getForegroundColor(); |
| 5291 | foregroundColor = NotificationColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5292 | foregroundColor, background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5293 | if (fullLength) { |
| 5294 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5295 | resultSpan = null; |
| 5296 | } else { |
| 5297 | resultSpan = new ForegroundColorSpan(foregroundColor); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5298 | } |
| 5299 | } else { |
| 5300 | resultSpan = span; |
| 5301 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5302 | if (resultSpan != null) { |
| 5303 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 5304 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5305 | } |
| 5306 | return builder; |
| 5307 | } |
| 5308 | return charSequence; |
| 5309 | } |
| 5310 | |
| 5311 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5312 | * @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] | 5313 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5314 | */ |
| 5315 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5316 | if (!mIsLegacyInitialized) { |
| 5317 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 5318 | < Build.VERSION_CODES.LOLLIPOP; |
| 5319 | mIsLegacyInitialized = true; |
| 5320 | } |
| 5321 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5322 | } |
| 5323 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5324 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 5325 | return processLegacyText(charSequence, false /* ambient */); |
| 5326 | } |
| 5327 | |
| 5328 | private CharSequence processLegacyText(CharSequence charSequence, boolean ambient) { |
| 5329 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
| 5330 | boolean wantLightText = ambient; |
| 5331 | if (isAlreadyLightText != wantLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5332 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5333 | } else { |
| 5334 | return charSequence; |
| 5335 | } |
| 5336 | } |
| 5337 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5338 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5339 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5340 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5341 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
| 5342 | boolean ambient) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5343 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5344 | int color; |
| 5345 | if (ambient) { |
| 5346 | color = resolveAmbientColor(); |
| 5347 | } else if (isColorized()) { |
| 5348 | color = getPrimaryTextColor(); |
| 5349 | } else { |
| 5350 | color = resolveContrastColor(); |
| 5351 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5352 | if (colorable) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5353 | contentView.setDrawableTint(R.id.icon, false, color, |
| 5354 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5355 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5356 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5357 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5358 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5359 | } |
| 5360 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5361 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5362 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5363 | * if it's grayscale). |
| 5364 | */ |
| 5365 | // TODO: also check bounds, transparency, that sort of thing. |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5366 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) { |
| 5367 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5368 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5369 | // resolve color will fall back to the default when legacy |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5370 | contentView.setDrawableTint(R.id.icon, false, resolveContrastColor(), |
| 5371 | PorterDuff.Mode.SRC_ATOP); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 5372 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5373 | } |
| 5374 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 5375 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5376 | if (mN.color != COLOR_DEFAULT) { |
| 5377 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5378 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5379 | } |
| 5380 | |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5381 | int resolveContrastColor() { |
| 5382 | if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) { |
| 5383 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5384 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5385 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5386 | int color; |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5387 | int background = mContext.getColor( |
| 5388 | com.android.internal.R.color.notification_material_background_color); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5389 | if (mN.color == COLOR_DEFAULT) { |
| 5390 | ensureColors(); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5391 | color = NotificationColorUtil.resolveDefaultColor(mContext, background); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5392 | } else { |
| 5393 | color = NotificationColorUtil.resolveContrastColor(mContext, mN.color, |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5394 | background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5395 | } |
| 5396 | if (Color.alpha(color) < 255) { |
| 5397 | // alpha doesn't go well for color filters, so let's blend it manually |
| 5398 | color = NotificationColorUtil.compositeColors(color, background); |
| 5399 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5400 | mCachedContrastColorIsFor = mN.color; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5401 | return mCachedContrastColor = color; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5402 | } |
| 5403 | |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5404 | int resolveNeutralColor() { |
| 5405 | if (mNeutralColor != COLOR_INVALID) { |
| 5406 | return mNeutralColor; |
| 5407 | } |
| 5408 | int background = mContext.getColor( |
| 5409 | com.android.internal.R.color.notification_material_background_color); |
| 5410 | mNeutralColor = NotificationColorUtil.resolveDefaultColor(mContext, background); |
| 5411 | if (Color.alpha(mNeutralColor) < 255) { |
| 5412 | // alpha doesn't go well for color filters, so let's blend it manually |
| 5413 | mNeutralColor = NotificationColorUtil.compositeColors(mNeutralColor, background); |
| 5414 | } |
| 5415 | return mNeutralColor; |
| 5416 | } |
| 5417 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5418 | int resolveAmbientColor() { |
| 5419 | if (mCachedAmbientColorIsFor == mN.color && mCachedAmbientColorIsFor != COLOR_INVALID) { |
| 5420 | return mCachedAmbientColor; |
| 5421 | } |
| 5422 | final int contrasted = NotificationColorUtil.resolveAmbientColor(mContext, mN.color); |
| 5423 | |
| 5424 | mCachedAmbientColorIsFor = mN.color; |
| 5425 | return mCachedAmbientColor = contrasted; |
| 5426 | } |
| 5427 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5428 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5429 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5430 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5431 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5432 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5433 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5434 | mN.actions = new Action[mActions.size()]; |
| 5435 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5436 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5437 | if (!mPersonList.isEmpty()) { |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 5438 | mN.extras.putParcelableArrayList(EXTRA_PEOPLE_LIST, mPersonList); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 5439 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5440 | if (mN.bigContentView != null || mN.contentView != null |
| 5441 | || mN.headsUpContentView != null) { |
| 5442 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 5443 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5444 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5445 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5446 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5447 | /** |
| 5448 | * Creates a Builder from an existing notification so further changes can be made. |
| 5449 | * @param context The context for your application / activity. |
| 5450 | * @param n The notification to create a Builder from. |
| 5451 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5452 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5453 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5454 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 5455 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5456 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5457 | if (applicationInfo != null) { |
| 5458 | try { |
| 5459 | builderContext = context.createApplicationContext(applicationInfo, |
| 5460 | Context.CONTEXT_RESTRICTED); |
| 5461 | } catch (NameNotFoundException e) { |
| 5462 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 5463 | builderContext = context; // try with our context |
| 5464 | } |
| 5465 | } else { |
| 5466 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5467 | } |
| 5468 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5469 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5470 | } |
| 5471 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5472 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5473 | * @deprecated Use {@link #build()} instead. |
| 5474 | */ |
| 5475 | @Deprecated |
| 5476 | public Notification getNotification() { |
| 5477 | return build(); |
| 5478 | } |
| 5479 | |
| 5480 | /** |
| 5481 | * Combine all of the options that have been set and return a new {@link Notification} |
| 5482 | * object. |
| 5483 | */ |
| 5484 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5485 | // first, add any extras from the calling code |
| 5486 | if (mUserExtras != null) { |
| 5487 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5488 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5489 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5490 | mN.creationTime = System.currentTimeMillis(); |
| 5491 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5492 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5493 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 5494 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5495 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5496 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5497 | if (mStyle != null) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5498 | mStyle.reduceImageSizes(mContext); |
| 5499 | mStyle.purgeResources(); |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 5500 | mStyle.validate(mContext); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5501 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5502 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5503 | mN.reduceImageSizes(mContext); |
| 5504 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5505 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5506 | && (useExistingRemoteView())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5507 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5508 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5509 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 5510 | mN.contentView.getSequenceNumber()); |
| 5511 | } |
| 5512 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5513 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5514 | if (mN.bigContentView != null) { |
| 5515 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 5516 | mN.bigContentView.getSequenceNumber()); |
| 5517 | } |
| 5518 | } |
| 5519 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5520 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5521 | if (mN.headsUpContentView != null) { |
| 5522 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 5523 | mN.headsUpContentView.getSequenceNumber()); |
| 5524 | } |
| 5525 | } |
| 5526 | } |
| 5527 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 5528 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 5529 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 5530 | } |
| 5531 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 5532 | mN.allPendingIntents = null; |
| 5533 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5534 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5535 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5536 | |
| 5537 | /** |
| 5538 | * Apply this Builder to an existing {@link Notification} object. |
| 5539 | * |
| 5540 | * @hide |
| 5541 | */ |
| 5542 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 5543 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5544 | return n; |
| 5545 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5546 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5547 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5548 | * 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] | 5549 | * change. Also removes extenders on low ram devices, as |
| 5550 | * {@link android.service.notification.NotificationListenerService} services are disabled. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5551 | * |
| 5552 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 5553 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5554 | * @hide |
| 5555 | */ |
Kristian Monsen | 30f59b2 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5556 | public static Notification maybeCloneStrippedForDelivery(Notification n, boolean isLowRam, |
| 5557 | Context context) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5558 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5559 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5560 | // Only strip views for known Styles because we won't know how to |
| 5561 | // re-create them otherwise. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5562 | if (!isLowRam |
| 5563 | && !TextUtils.isEmpty(templateClass) |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5564 | && getNotificationStyleClass(templateClass) == null) { |
| 5565 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5566 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5567 | |
| 5568 | // Only strip unmodified BuilderRemoteViews. |
| 5569 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5570 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5571 | n.contentView.getSequenceNumber(); |
| 5572 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5573 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5574 | n.bigContentView.getSequenceNumber(); |
| 5575 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5576 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5577 | n.headsUpContentView.getSequenceNumber(); |
| 5578 | |
| 5579 | // Nothing to do here, no need to clone. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5580 | if (!isLowRam |
| 5581 | && !stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5582 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5583 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5584 | |
| 5585 | Notification clone = n.clone(); |
| 5586 | if (stripContentView) { |
| 5587 | clone.contentView = null; |
| 5588 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 5589 | } |
| 5590 | if (stripBigContentView) { |
| 5591 | clone.bigContentView = null; |
| 5592 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 5593 | } |
| 5594 | if (stripHeadsUpContentView) { |
| 5595 | clone.headsUpContentView = null; |
| 5596 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 5597 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5598 | if (isLowRam) { |
Kristian Monsen | 30f59b2 | 2018-04-09 10:27:16 +0200 | [diff] [blame] | 5599 | String[] allowedServices = context.getResources().getStringArray( |
| 5600 | R.array.config_allowedManagedServicesOnLowRamDevices); |
| 5601 | if (allowedServices.length == 0) { |
| 5602 | clone.extras.remove(Notification.TvExtender.EXTRA_TV_EXTENDER); |
| 5603 | clone.extras.remove(WearableExtender.EXTRA_WEARABLE_EXTENSIONS); |
| 5604 | clone.extras.remove(CarExtender.EXTRA_CAR_EXTENDER); |
| 5605 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5606 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5607 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5608 | } |
| 5609 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5610 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5611 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5615 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5616 | } |
| 5617 | |
| 5618 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5619 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5623 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5627 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5628 | } |
| 5629 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5630 | private int getMessagingLayoutResource() { |
| 5631 | return R.layout.notification_template_material_messaging; |
| 5632 | } |
| 5633 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5634 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5635 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5636 | } |
| 5637 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5638 | private int getEmphasizedActionLayoutResource() { |
| 5639 | return R.layout.notification_material_action_emphasized; |
| 5640 | } |
| 5641 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5642 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5643 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5644 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5645 | |
| 5646 | private int getBackgroundColor() { |
| 5647 | if (isColorized()) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5648 | return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : mN.color; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5649 | } else { |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 5650 | return COLOR_DEFAULT; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5651 | } |
| 5652 | } |
| 5653 | |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5654 | /** |
Selim Cinek | 4717d86 | 2018-04-19 09:19:15 +0800 | [diff] [blame] | 5655 | * Gets a neutral color that can be used for icons or similar that should not stand out. |
| 5656 | */ |
| 5657 | private int getNeutralColor() { |
| 5658 | if (isColorized()) { |
| 5659 | return getSecondaryTextColor(); |
| 5660 | } else { |
| 5661 | return resolveNeutralColor(); |
| 5662 | } |
| 5663 | } |
| 5664 | |
| 5665 | /** |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 5666 | * Same as getBackgroundColor but also resolved the default color to the background. |
| 5667 | */ |
| 5668 | private int resolveBackgroundColor() { |
| 5669 | int backgroundColor = getBackgroundColor(); |
| 5670 | if (backgroundColor == COLOR_DEFAULT) { |
| 5671 | backgroundColor = mContext.getColor( |
| 5672 | com.android.internal.R.color.notification_material_background_color); |
| 5673 | } |
| 5674 | return backgroundColor; |
| 5675 | } |
| 5676 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5677 | private boolean isColorized() { |
| 5678 | return mN.isColorized(); |
| 5679 | } |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5680 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5681 | private boolean shouldTintActionButtons() { |
| 5682 | return mTintActionButtons; |
| 5683 | } |
| 5684 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5685 | private boolean textColorsNeedInversion() { |
| 5686 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 5687 | return false; |
| 5688 | } |
| 5689 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 5690 | return targetSdkVersion > Build.VERSION_CODES.M |
| 5691 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 5692 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5693 | |
| 5694 | /** |
| 5695 | * Set a color palette to be used as the background and textColors |
| 5696 | * |
| 5697 | * @param backgroundColor the color to be used as the background |
| 5698 | * @param foregroundColor the color to be used as the foreground |
| 5699 | * |
| 5700 | * @hide |
| 5701 | */ |
| 5702 | public void setColorPalette(int backgroundColor, int foregroundColor) { |
| 5703 | mBackgroundColor = backgroundColor; |
| 5704 | mForegroundColor = foregroundColor; |
| 5705 | mTextColorsAreForBackground = COLOR_INVALID; |
| 5706 | ensureColors(); |
| 5707 | } |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5708 | |
| 5709 | /** |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5710 | * Forces all styled remoteViews to be built from scratch and not use any cached |
| 5711 | * RemoteViews. |
| 5712 | * This is needed for legacy apps that are baking in their remoteviews into the |
| 5713 | * notification. |
| 5714 | * |
| 5715 | * @hide |
| 5716 | */ |
| 5717 | public void setRebuildStyledRemoteViews(boolean rebuild) { |
| 5718 | mRebuildStyledRemoteViews = rebuild; |
| 5719 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 5720 | |
| 5721 | /** |
| 5722 | * Get the text that should be displayed in the statusBar when heads upped. This is |
| 5723 | * usually just the app name, but may be different depending on the style. |
| 5724 | * |
| 5725 | * @param publicMode If true, return a text that is safe to display in public. |
| 5726 | * |
| 5727 | * @hide |
| 5728 | */ |
| 5729 | public CharSequence getHeadsUpStatusBarText(boolean publicMode) { |
| 5730 | if (mStyle != null && !publicMode) { |
| 5731 | CharSequence text = mStyle.getHeadsUpStatusBarText(); |
| 5732 | if (!TextUtils.isEmpty(text)) { |
| 5733 | return text; |
| 5734 | } |
| 5735 | } |
| 5736 | return loadHeaderAppName(); |
| 5737 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5738 | } |
| 5739 | |
| 5740 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5741 | * Reduces the image sizes to conform to a maximum allowed size. This also processes all custom |
| 5742 | * remote views. |
| 5743 | * |
| 5744 | * @hide |
| 5745 | */ |
| 5746 | void reduceImageSizes(Context context) { |
| 5747 | if (extras.getBoolean(EXTRA_REDUCED_IMAGES)) { |
| 5748 | return; |
| 5749 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5750 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5751 | if (mLargeIcon != null || largeIcon != null) { |
| 5752 | Resources resources = context.getResources(); |
| 5753 | Class<? extends Style> style = getNotificationStyle(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5754 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5755 | ? R.dimen.notification_right_icon_size_low_ram |
| 5756 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5757 | int maxHeight = maxWidth; |
| 5758 | if (MediaStyle.class.equals(style) |
| 5759 | || DecoratedMediaCustomViewStyle.class.equals(style)) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5760 | maxHeight = resources.getDimensionPixelSize(isLowRam |
| 5761 | ? R.dimen.notification_media_image_max_height_low_ram |
| 5762 | : R.dimen.notification_media_image_max_height); |
| 5763 | maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5764 | ? R.dimen.notification_media_image_max_width_low_ram |
| 5765 | : R.dimen.notification_media_image_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5766 | } |
| 5767 | if (mLargeIcon != null) { |
| 5768 | mLargeIcon.scaleDownIfNecessary(maxWidth, maxHeight); |
| 5769 | } |
| 5770 | if (largeIcon != null) { |
| 5771 | largeIcon = Icon.scaleDownIfNecessary(largeIcon, maxWidth, maxHeight); |
| 5772 | } |
| 5773 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5774 | reduceImageSizesForRemoteView(contentView, context, isLowRam); |
| 5775 | reduceImageSizesForRemoteView(headsUpContentView, context, isLowRam); |
| 5776 | reduceImageSizesForRemoteView(bigContentView, context, isLowRam); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5777 | extras.putBoolean(EXTRA_REDUCED_IMAGES, true); |
| 5778 | } |
| 5779 | |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5780 | private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context, |
| 5781 | boolean isLowRam) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5782 | if (remoteView != null) { |
| 5783 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5784 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5785 | ? R.dimen.notification_custom_view_max_image_width_low_ram |
| 5786 | : R.dimen.notification_custom_view_max_image_width); |
| 5787 | int maxHeight = resources.getDimensionPixelSize(isLowRam |
| 5788 | ? R.dimen.notification_custom_view_max_image_height_low_ram |
| 5789 | : R.dimen.notification_custom_view_max_image_height); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5790 | remoteView.reduceImageSizes(maxWidth, maxHeight); |
| 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5795 | * @return whether this notification is a foreground service notification |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5796 | */ |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5797 | private boolean isForegroundService() { |
| 5798 | return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5799 | } |
| 5800 | |
| 5801 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5802 | * @return whether this notification has a media session attached |
| 5803 | * @hide |
| 5804 | */ |
| 5805 | public boolean hasMediaSession() { |
| 5806 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 5807 | } |
| 5808 | |
| 5809 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5810 | * @return the style class of this notification |
| 5811 | * @hide |
| 5812 | */ |
| 5813 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 5814 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 5815 | |
| 5816 | if (!TextUtils.isEmpty(templateClass)) { |
| 5817 | return Notification.getNotificationStyleClass(templateClass); |
| 5818 | } |
| 5819 | return null; |
| 5820 | } |
| 5821 | |
| 5822 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5823 | * @return true if this notification is colorized. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5824 | * |
| 5825 | * @hide |
| 5826 | */ |
| 5827 | public boolean isColorized() { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5828 | if (isColorizedMedia()) { |
| 5829 | return true; |
| 5830 | } |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 5831 | return extras.getBoolean(EXTRA_COLORIZED) |
| 5832 | && (hasColorizedPermission() || isForegroundService()); |
| 5833 | } |
| 5834 | |
| 5835 | /** |
| 5836 | * Returns whether an app can colorize due to the android.permission.USE_COLORIZED_NOTIFICATIONS |
| 5837 | * permission. The permission is checked when a notification is enqueued. |
| 5838 | */ |
| 5839 | private boolean hasColorizedPermission() { |
| 5840 | return (flags & Notification.FLAG_CAN_COLORIZE) != 0; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5841 | } |
| 5842 | |
| 5843 | /** |
| 5844 | * @return true if this notification is colorized and it is a media notification |
| 5845 | * |
| 5846 | * @hide |
| 5847 | */ |
| 5848 | public boolean isColorizedMedia() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5849 | Class<? extends Style> style = getNotificationStyle(); |
| 5850 | if (MediaStyle.class.equals(style)) { |
| 5851 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 5852 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 5853 | return true; |
| 5854 | } |
| 5855 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 5856 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 5857 | return true; |
| 5858 | } |
| 5859 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5860 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5861 | } |
| 5862 | |
Selim Cinek | 0847acd | 2017-04-24 19:48:29 -0700 | [diff] [blame] | 5863 | |
| 5864 | /** |
| 5865 | * @return true if this is a media notification |
| 5866 | * |
| 5867 | * @hide |
| 5868 | */ |
| 5869 | public boolean isMediaNotification() { |
| 5870 | Class<? extends Style> style = getNotificationStyle(); |
| 5871 | if (MediaStyle.class.equals(style)) { |
| 5872 | return true; |
| 5873 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 5874 | return true; |
| 5875 | } |
| 5876 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5877 | } |
| 5878 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5879 | private boolean hasLargeIcon() { |
| 5880 | return mLargeIcon != null || largeIcon != null; |
| 5881 | } |
| 5882 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5883 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5884 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5885 | * @hide |
| 5886 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5887 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5888 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 5889 | } |
| 5890 | |
| 5891 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5892 | * @return true if the notification will show a chronometer; false otherwise |
| 5893 | * @hide |
| 5894 | */ |
| 5895 | public boolean showsChronometer() { |
| 5896 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 5897 | } |
| 5898 | |
| 5899 | /** |
Julia Reynolds | 7ca3307 | 2017-06-29 13:58:24 -0400 | [diff] [blame] | 5900 | * @removed |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 5901 | */ |
| 5902 | @SystemApi |
| 5903 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 5904 | Class<? extends Style>[] classes = new Class[] { |
| 5905 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 5906 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 5907 | MessagingStyle.class }; |
| 5908 | for (Class<? extends Style> innerClass : classes) { |
| 5909 | if (templateClass.equals(innerClass.getName())) { |
| 5910 | return innerClass; |
| 5911 | } |
| 5912 | } |
| 5913 | return null; |
| 5914 | } |
| 5915 | |
| 5916 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5917 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 5918 | * object. |
| 5919 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 5920 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5921 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 5922 | |
| 5923 | /** |
| 5924 | * @hide |
| 5925 | */ |
| 5926 | protected CharSequence mSummaryText = null; |
| 5927 | |
| 5928 | /** |
| 5929 | * @hide |
| 5930 | */ |
| 5931 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5932 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5933 | protected Builder mBuilder; |
| 5934 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5935 | /** |
| 5936 | * Overrides ContentTitle in the big form of the template. |
| 5937 | * This defaults to the value passed to setContentTitle(). |
| 5938 | */ |
| 5939 | protected void internalSetBigContentTitle(CharSequence title) { |
| 5940 | mBigContentTitle = title; |
| 5941 | } |
| 5942 | |
| 5943 | /** |
| 5944 | * Set the first line of text after the detail section in the big form of the template. |
| 5945 | */ |
| 5946 | protected void internalSetSummaryText(CharSequence cs) { |
| 5947 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 5948 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5949 | } |
| 5950 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5951 | public void setBuilder(Builder builder) { |
| 5952 | if (mBuilder != builder) { |
| 5953 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 5954 | if (mBuilder != null) { |
| 5955 | mBuilder.setStyle(this); |
| 5956 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5957 | } |
| 5958 | } |
| 5959 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5960 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5961 | if (mBuilder == null) { |
| 5962 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 5963 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5964 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5965 | |
| 5966 | protected RemoteViews getStandardView(int layoutId) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5967 | return getStandardView(layoutId, null); |
| 5968 | } |
| 5969 | |
| 5970 | /** |
| 5971 | * Get the standard view for this style. |
| 5972 | * |
| 5973 | * @param layoutId The layout id to use |
| 5974 | * @param result The result where template bind information is saved. |
| 5975 | * @return A remoteView for this style. |
| 5976 | * @hide |
| 5977 | */ |
| 5978 | protected RemoteViews getStandardView(int layoutId, TemplateBindResult result) { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5979 | checkBuilder(); |
| 5980 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5981 | // Nasty. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5982 | CharSequence oldBuilderContentTitle = |
| 5983 | mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5984 | if (mBigContentTitle != null) { |
| 5985 | mBuilder.setContentTitle(mBigContentTitle); |
| 5986 | } |
| 5987 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 5988 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId, result); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5989 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5990 | mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5991 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5992 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 5993 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 5994 | } else { |
| 5995 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5996 | } |
| 5997 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5998 | return contentView; |
| 5999 | } |
| 6000 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6001 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6002 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6003 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6004 | * |
| 6005 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6006 | * @hide |
| 6007 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6008 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6009 | return null; |
| 6010 | } |
| 6011 | |
| 6012 | /** |
| 6013 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 6014 | * @hide |
| 6015 | */ |
| 6016 | public RemoteViews makeBigContentView() { |
| 6017 | return null; |
| 6018 | } |
| 6019 | |
| 6020 | /** |
| 6021 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6022 | * |
| 6023 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6024 | * @hide |
| 6025 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6026 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6027 | return null; |
| 6028 | } |
| 6029 | |
| 6030 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6031 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6032 | * @hide |
| 6033 | */ |
| 6034 | public void addExtras(Bundle extras) { |
| 6035 | if (mSummaryTextSet) { |
| 6036 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 6037 | } |
| 6038 | if (mBigContentTitle != null) { |
| 6039 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 6040 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 6041 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6042 | } |
| 6043 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6044 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6045 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6046 | * @hide |
| 6047 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6048 | protected void restoreFromExtras(Bundle extras) { |
| 6049 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 6050 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 6051 | mSummaryTextSet = true; |
| 6052 | } |
| 6053 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 6054 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 6055 | } |
| 6056 | } |
| 6057 | |
| 6058 | |
| 6059 | /** |
| 6060 | * @hide |
| 6061 | */ |
| 6062 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6063 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6064 | return wip; |
| 6065 | } |
| 6066 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6067 | /** |
| 6068 | * @hide |
| 6069 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6070 | public void purgeResources() {} |
| 6071 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6072 | /** |
| 6073 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 6074 | * attached to. |
| 6075 | * |
| 6076 | * @return the fully constructed Notification. |
| 6077 | */ |
| 6078 | public Notification build() { |
| 6079 | checkBuilder(); |
| 6080 | return mBuilder.build(); |
| 6081 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6082 | |
| 6083 | /** |
| 6084 | * @hide |
| 6085 | * @return true if the style positions the progress bar on the second line; false if the |
| 6086 | * style hides the progress bar |
| 6087 | */ |
| 6088 | protected boolean hasProgress() { |
| 6089 | return true; |
| 6090 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6091 | |
| 6092 | /** |
| 6093 | * @hide |
| 6094 | * @return Whether we should put the summary be put into the notification header |
| 6095 | */ |
| 6096 | public boolean hasSummaryInHeader() { |
| 6097 | return true; |
| 6098 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6099 | |
| 6100 | /** |
| 6101 | * @hide |
| 6102 | * @return Whether custom content views are displayed inline in the style |
| 6103 | */ |
| 6104 | public boolean displayCustomViewInline() { |
| 6105 | return false; |
| 6106 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6107 | |
| 6108 | /** |
| 6109 | * Reduces the image sizes contained in this style. |
| 6110 | * |
| 6111 | * @hide |
| 6112 | */ |
| 6113 | public void reduceImageSizes(Context context) { |
| 6114 | } |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6115 | |
| 6116 | /** |
| 6117 | * Validate that this style was properly composed. This is called at build time. |
| 6118 | * @hide |
| 6119 | */ |
| 6120 | public void validate(Context context) { |
| 6121 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6122 | |
| 6123 | /** |
| 6124 | * @hide |
| 6125 | */ |
| 6126 | public abstract boolean areNotificationsVisiblyDifferent(Style other); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 6127 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6128 | /** |
| 6129 | * @return the the text that should be displayed in the statusBar when heads-upped. |
| 6130 | * If {@code null} is returned, the default implementation will be used. |
| 6131 | * |
| 6132 | * @hide |
| 6133 | */ |
| 6134 | public CharSequence getHeadsUpStatusBarText() { |
| 6135 | return null; |
| 6136 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 6137 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6138 | |
| 6139 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6140 | * 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] | 6141 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6142 | * 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] | 6143 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6144 | * Notification notif = new Notification.Builder(mContext) |
| 6145 | * .setContentTitle("New photo from " + sender.toString()) |
| 6146 | * .setContentText(subject) |
| 6147 | * .setSmallIcon(R.drawable.new_post) |
| 6148 | * .setLargeIcon(aBitmap) |
| 6149 | * .setStyle(new Notification.BigPictureStyle() |
| 6150 | * .bigPicture(aBigBitmap)) |
| 6151 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6152 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6153 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6154 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6155 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6156 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6157 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6158 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6159 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6160 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6161 | public BigPictureStyle() { |
| 6162 | } |
| 6163 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6164 | /** |
| 6165 | * @deprecated use {@code BigPictureStyle()}. |
| 6166 | */ |
| 6167 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6168 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6169 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6170 | } |
| 6171 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6172 | /** |
| 6173 | * Overrides ContentTitle in the big form of the template. |
| 6174 | * This defaults to the value passed to setContentTitle(). |
| 6175 | */ |
| 6176 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6177 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6178 | return this; |
| 6179 | } |
| 6180 | |
| 6181 | /** |
| 6182 | * Set the first line of text after the detail section in the big form of the template. |
| 6183 | */ |
| 6184 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6185 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6186 | return this; |
| 6187 | } |
| 6188 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6189 | /** |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6190 | * @hide |
| 6191 | */ |
| 6192 | public Bitmap getBigPicture() { |
| 6193 | return mPicture; |
| 6194 | } |
| 6195 | |
| 6196 | /** |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6197 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 6198 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6199 | public BigPictureStyle bigPicture(Bitmap b) { |
| 6200 | mPicture = b; |
| 6201 | return this; |
| 6202 | } |
| 6203 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6204 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6205 | * Override the large icon when the big notification is shown. |
| 6206 | */ |
| 6207 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6208 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 6209 | } |
| 6210 | |
| 6211 | /** |
| 6212 | * Override the large icon when the big notification is shown. |
| 6213 | */ |
| 6214 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6215 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6216 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6217 | return this; |
| 6218 | } |
| 6219 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6220 | /** @hide */ |
| 6221 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 6222 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 6223 | /** |
| 6224 | * @hide |
| 6225 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6226 | @Override |
| 6227 | public void purgeResources() { |
| 6228 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 6229 | if (mPicture != null && |
| 6230 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 6231 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 6232 | mPicture = mPicture.createAshmemBitmap(); |
| 6233 | } |
| 6234 | if (mBigLargeIcon != null) { |
| 6235 | mBigLargeIcon.convertToAshmem(); |
| 6236 | } |
| 6237 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6238 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6239 | /** |
| 6240 | * @hide |
| 6241 | */ |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6242 | @Override |
| 6243 | public void reduceImageSizes(Context context) { |
| 6244 | super.reduceImageSizes(context); |
| 6245 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6246 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6247 | if (mPicture != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6248 | int maxPictureWidth = resources.getDimensionPixelSize(isLowRam |
| 6249 | ? R.dimen.notification_big_picture_max_height_low_ram |
| 6250 | : R.dimen.notification_big_picture_max_height); |
| 6251 | int maxPictureHeight = resources.getDimensionPixelSize(isLowRam |
| 6252 | ? R.dimen.notification_big_picture_max_width_low_ram |
| 6253 | : R.dimen.notification_big_picture_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6254 | mPicture = Icon.scaleDownIfNecessary(mPicture, maxPictureWidth, maxPictureHeight); |
| 6255 | } |
| 6256 | if (mBigLargeIcon != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 6257 | int rightIconSize = resources.getDimensionPixelSize(isLowRam |
| 6258 | ? R.dimen.notification_right_icon_size_low_ram |
| 6259 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 6260 | mBigLargeIcon.scaleDownIfNecessary(rightIconSize, rightIconSize); |
| 6261 | } |
| 6262 | } |
| 6263 | |
| 6264 | /** |
| 6265 | * @hide |
| 6266 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6267 | public RemoteViews makeBigContentView() { |
| 6268 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6269 | // This covers the following cases: |
| 6270 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6271 | // mN.mLargeIcon |
| 6272 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 6273 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6274 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6275 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6276 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 6277 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6278 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 6279 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 6280 | // for old listeners, this is in general non-null. |
| 6281 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 6282 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6283 | } |
| 6284 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6285 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource(), |
| 6286 | null /* result */); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6287 | if (mSummaryTextSet) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6288 | contentView.setTextViewText(R.id.text, mBuilder.processTextSpans( |
| 6289 | mBuilder.processLegacyText(mSummaryText))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6290 | mBuilder.setTextViewColorSecondary(contentView, R.id.text); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 6291 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6292 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6293 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 6294 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6295 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6296 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 6297 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6298 | } |
| 6299 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6300 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6301 | return contentView; |
| 6302 | } |
| 6303 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6304 | /** |
| 6305 | * @hide |
| 6306 | */ |
| 6307 | public void addExtras(Bundle extras) { |
| 6308 | super.addExtras(extras); |
| 6309 | |
| 6310 | if (mBigLargeIconSet) { |
| 6311 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 6312 | } |
| 6313 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 6314 | } |
| 6315 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 6316 | /** |
| 6317 | * @hide |
| 6318 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6319 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6320 | protected void restoreFromExtras(Bundle extras) { |
| 6321 | super.restoreFromExtras(extras); |
| 6322 | |
| 6323 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 6324 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6325 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 6326 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6327 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 6328 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 6329 | |
| 6330 | /** |
| 6331 | * @hide |
| 6332 | */ |
| 6333 | @Override |
| 6334 | public boolean hasSummaryInHeader() { |
| 6335 | return false; |
| 6336 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6337 | |
| 6338 | /** |
| 6339 | * @hide |
| 6340 | */ |
| 6341 | @Override |
| 6342 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6343 | if (other == null || getClass() != other.getClass()) { |
| 6344 | return true; |
| 6345 | } |
| 6346 | BigPictureStyle otherS = (BigPictureStyle) other; |
| 6347 | return !Objects.equals(getBigPicture(), otherS.getBigPicture()); |
| 6348 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6349 | } |
| 6350 | |
| 6351 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6352 | * 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] | 6353 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6354 | * 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] | 6355 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6356 | * Notification notif = new Notification.Builder(mContext) |
| 6357 | * .setContentTitle("New mail from " + sender.toString()) |
| 6358 | * .setContentText(subject) |
| 6359 | * .setSmallIcon(R.drawable.new_mail) |
| 6360 | * .setLargeIcon(aBitmap) |
| 6361 | * .setStyle(new Notification.BigTextStyle() |
| 6362 | * .bigText(aVeryLongString)) |
| 6363 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6364 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6365 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6366 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6367 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6368 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6369 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6370 | private CharSequence mBigText; |
| 6371 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6372 | public BigTextStyle() { |
| 6373 | } |
| 6374 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6375 | /** |
| 6376 | * @deprecated use {@code BigTextStyle()}. |
| 6377 | */ |
| 6378 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6379 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6380 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6381 | } |
| 6382 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6383 | /** |
| 6384 | * Overrides ContentTitle in the big form of the template. |
| 6385 | * This defaults to the value passed to setContentTitle(). |
| 6386 | */ |
| 6387 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6388 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6389 | return this; |
| 6390 | } |
| 6391 | |
| 6392 | /** |
| 6393 | * Set the first line of text after the detail section in the big form of the template. |
| 6394 | */ |
| 6395 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6396 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6397 | return this; |
| 6398 | } |
| 6399 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6400 | /** |
| 6401 | * Provide the longer text to be displayed in the big form of the |
| 6402 | * template in place of the content text. |
| 6403 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6404 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6405 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6406 | return this; |
| 6407 | } |
| 6408 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6409 | /** |
| 6410 | * @hide |
| 6411 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6412 | public CharSequence getBigText() { |
| 6413 | return mBigText; |
| 6414 | } |
| 6415 | |
| 6416 | /** |
| 6417 | * @hide |
| 6418 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6419 | public void addExtras(Bundle extras) { |
| 6420 | super.addExtras(extras); |
| 6421 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6422 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 6423 | } |
| 6424 | |
| 6425 | /** |
| 6426 | * @hide |
| 6427 | */ |
| 6428 | @Override |
| 6429 | protected void restoreFromExtras(Bundle extras) { |
| 6430 | super.restoreFromExtras(extras); |
| 6431 | |
| 6432 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6433 | } |
| 6434 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6435 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6436 | * @param increasedHeight true if this layout be created with an increased height. |
| 6437 | * |
| 6438 | * @hide |
| 6439 | */ |
| 6440 | @Override |
| 6441 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6442 | if (increasedHeight) { |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6443 | mBuilder.mOriginalActions = mBuilder.mActions; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6444 | mBuilder.mActions = new ArrayList<>(); |
| 6445 | RemoteViews remoteViews = makeBigContentView(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6446 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6447 | mBuilder.mOriginalActions = null; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6448 | return remoteViews; |
| 6449 | } |
| 6450 | return super.makeContentView(increasedHeight); |
| 6451 | } |
| 6452 | |
| 6453 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6454 | * @hide |
| 6455 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6456 | @Override |
| 6457 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 6458 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 6459 | return makeBigContentView(); |
| 6460 | } |
| 6461 | return super.makeHeadsUpContentView(increasedHeight); |
| 6462 | } |
| 6463 | |
| 6464 | /** |
| 6465 | * @hide |
| 6466 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6467 | public RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6468 | |
| 6469 | // Nasty |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6470 | CharSequence text = mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6471 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 6472 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6473 | TemplateBindResult result = new TemplateBindResult(); |
| 6474 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource(), result); |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 6475 | contentView.setInt(R.id.big_text, "setImageEndMargin", result.getIconMarginEnd()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6476 | |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6477 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, text); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6478 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 6479 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6480 | if (TextUtils.isEmpty(bigTextText)) { |
| 6481 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 6482 | // experience |
| 6483 | bigTextText = mBuilder.processLegacyText(text); |
| 6484 | } |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6485 | applyBigTextContentView(mBuilder, contentView, bigTextText); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 6486 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6487 | return contentView; |
| 6488 | } |
| 6489 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6490 | /** |
| 6491 | * @hide |
| 6492 | */ |
| 6493 | @Override |
| 6494 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6495 | if (other == null || getClass() != other.getClass()) { |
| 6496 | return true; |
| 6497 | } |
| 6498 | BigTextStyle newS = (BigTextStyle) other; |
| 6499 | return !Objects.equals(getBigText(), newS.getBigText()); |
| 6500 | } |
| 6501 | |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6502 | static void applyBigTextContentView(Builder builder, |
| 6503 | RemoteViews contentView, CharSequence bigTextText) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6504 | contentView.setTextViewText(R.id.big_text, builder.processTextSpans(bigTextText)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6505 | builder.setTextViewColorSecondary(contentView, R.id.big_text); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6506 | contentView.setViewVisibility(R.id.big_text, |
| 6507 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6508 | contentView.setBoolean(R.id.big_text, "setHasImage", builder.mN.hasLargeIcon()); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6509 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6510 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6511 | |
| 6512 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6513 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 6514 | * messages of varying types between any number of people. |
| 6515 | * |
| 6516 | * <br> |
| 6517 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 6518 | * user will always see the normal notification view. |
| 6519 | * <br> |
| 6520 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like |
| 6521 | * so: |
| 6522 | * <pre class="prettyprint"> |
| 6523 | * |
| 6524 | * Notification noti = new Notification.Builder() |
| 6525 | * .setContentTitle("2 new messages wtih " + sender.toString()) |
| 6526 | * .setContentText(subject) |
| 6527 | * .setSmallIcon(R.drawable.new_message) |
| 6528 | * .setLargeIcon(aBitmap) |
| 6529 | * .setStyle(new Notification.MessagingStyle(resources.getString(R.string.reply_name)) |
| 6530 | * .addMessage(messages[0].getText(), messages[0].getTime(), messages[0].getSender()) |
| 6531 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getSender())) |
| 6532 | * .build(); |
| 6533 | * </pre> |
| 6534 | */ |
| 6535 | public static class MessagingStyle extends Style { |
| 6536 | |
| 6537 | /** |
| 6538 | * The maximum number of messages that will be retained in the Notification itself (the |
| 6539 | * number displayed is up to the platform). |
| 6540 | */ |
| 6541 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 6542 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6543 | @NonNull Person mUser; |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6544 | @Nullable CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6545 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6546 | List<Message> mHistoricMessages = new ArrayList<>(); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6547 | boolean mIsGroupConversation; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6548 | |
| 6549 | MessagingStyle() { |
| 6550 | } |
| 6551 | |
| 6552 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6553 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 6554 | * user before the posting app reposts the notification with those messages after they've |
| 6555 | * 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] | 6556 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6557 | * |
| 6558 | * @deprecated use {@code MessagingStyle(Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6559 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6560 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6561 | this(new Person.Builder().setName(userDisplayName).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6562 | } |
| 6563 | |
| 6564 | /** |
| 6565 | * @param user Required - The person displayed for any messages that are sent by the |
| 6566 | * user. Any messages added with {@link #addMessage(Notification.MessagingStyle.Message)} |
| 6567 | * 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] | 6568 | * by this user. The user also needs to have a valid name associated with it, which will |
| 6569 | * be enforced starting in Android P. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6570 | */ |
| 6571 | public MessagingStyle(@NonNull Person user) { |
| 6572 | mUser = user; |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6573 | } |
| 6574 | |
| 6575 | /** |
| 6576 | * Validate that this style was properly composed. This is called at build time. |
| 6577 | * @hide |
| 6578 | */ |
| 6579 | @Override |
| 6580 | public void validate(Context context) { |
| 6581 | super.validate(context); |
| 6582 | if (context.getApplicationInfo().targetSdkVersion |
| 6583 | >= Build.VERSION_CODES.P && (mUser == null || mUser.getName() == null)) { |
| 6584 | throw new RuntimeException("User must be valid and have a name."); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6585 | } |
| 6586 | } |
| 6587 | |
| 6588 | /** |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 6589 | * @return the the text that should be displayed in the statusBar when heads upped. |
| 6590 | * If {@code null} is returned, the default implementation will be used. |
| 6591 | * |
| 6592 | * @hide |
| 6593 | */ |
| 6594 | @Override |
| 6595 | public CharSequence getHeadsUpStatusBarText() { |
| 6596 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
| 6597 | ? super.mBigContentTitle |
| 6598 | : mConversationTitle; |
| 6599 | if (!TextUtils.isEmpty(conversationTitle) && !hasOnlyWhiteSpaceSenders()) { |
| 6600 | return conversationTitle; |
| 6601 | } |
| 6602 | return null; |
| 6603 | } |
| 6604 | |
| 6605 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6606 | * @return the user to be displayed for any replies sent by the user |
| 6607 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6608 | @NonNull |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6609 | public Person getUser() { |
| 6610 | return mUser; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6611 | } |
| 6612 | |
| 6613 | /** |
| 6614 | * 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] | 6615 | * |
| 6616 | * @deprecated use {@link #getUser()} instead |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6617 | */ |
| 6618 | public CharSequence getUserDisplayName() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6619 | return mUser.getName(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6620 | } |
| 6621 | |
| 6622 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6623 | * Sets the title to be displayed on this conversation. May be set to {@code null}. |
| 6624 | * |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6625 | * <p>This API's behavior was changed in SDK version {@link Build.VERSION_CODES#P}. If your |
| 6626 | * application's target version is less than {@link Build.VERSION_CODES#P}, setting a |
| 6627 | * conversation title to a non-null value will make {@link #isGroupConversation()} return |
| 6628 | * {@code true} and passing {@code null} will make it return {@code false}. In |
| 6629 | * {@link Build.VERSION_CODES#P} and beyond, use {@link #setGroupConversation(boolean)} |
| 6630 | * to set group conversation status. |
| 6631 | * |
| 6632 | * @param conversationTitle Title displayed for this conversation |
| 6633 | * @return this object for method chaining |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6634 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6635 | public MessagingStyle setConversationTitle(@Nullable CharSequence conversationTitle) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6636 | mConversationTitle = conversationTitle; |
| 6637 | return this; |
| 6638 | } |
| 6639 | |
| 6640 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6641 | * 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] | 6642 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6643 | @Nullable |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6644 | public CharSequence getConversationTitle() { |
| 6645 | return mConversationTitle; |
| 6646 | } |
| 6647 | |
| 6648 | /** |
| 6649 | * Adds a message for display by this notification. Convenience call for a simple |
| 6650 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6651 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6652 | * @param timestamp Time at which the message arrived |
| 6653 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 6654 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 6655 | * the platform will insert {@link #getUserDisplayName()}. |
| 6656 | * Should be unique amongst all individuals in the conversation, and should be |
| 6657 | * consistent during re-posts of the notification. |
| 6658 | * |
| 6659 | * @see Message#Message(CharSequence, long, CharSequence) |
| 6660 | * |
| 6661 | * @return this object for method chaining |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6662 | * |
| 6663 | * @deprecated use {@link #addMessage(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6664 | */ |
| 6665 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6666 | return addMessage(text, timestamp, |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6667 | sender == null ? null : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | /** |
| 6671 | * Adds a message for display by this notification. Convenience call for a simple |
| 6672 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6673 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6674 | * @param timestamp Time at which the message arrived |
| 6675 | * @param sender The {@link Person} who sent the message. |
| 6676 | * Should be <code>null</code> for messages by the current user, in which case |
| 6677 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 6678 | * |
| 6679 | * @see Message#Message(CharSequence, long, CharSequence) |
| 6680 | * |
| 6681 | * @return this object for method chaining |
| 6682 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 6683 | public MessagingStyle addMessage(@NonNull CharSequence text, long timestamp, |
| 6684 | @Nullable Person sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6685 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6686 | } |
| 6687 | |
| 6688 | /** |
| 6689 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6690 | * |
| 6691 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6692 | * the newest last. |
| 6693 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6694 | * @param message The {@link Message} to be displayed |
| 6695 | * @return this object for method chaining |
| 6696 | */ |
| 6697 | public MessagingStyle addMessage(Message message) { |
| 6698 | mMessages.add(message); |
| 6699 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 6700 | mMessages.remove(0); |
| 6701 | } |
| 6702 | return this; |
| 6703 | } |
| 6704 | |
| 6705 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6706 | * Adds a {@link Message} for historic context in this notification. |
| 6707 | * |
| 6708 | * <p>Messages should be added as historic if they are not the main subject of the |
| 6709 | * notification but may give context to a conversation. The system may choose to present |
| 6710 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 6711 | * |
| 6712 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6713 | * the newest last. |
| 6714 | * |
| 6715 | * @param message The historic {@link Message} to be added |
| 6716 | * @return this object for method chaining |
| 6717 | */ |
| 6718 | public MessagingStyle addHistoricMessage(Message message) { |
| 6719 | mHistoricMessages.add(message); |
| 6720 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 6721 | mHistoricMessages.remove(0); |
| 6722 | } |
| 6723 | return this; |
| 6724 | } |
| 6725 | |
| 6726 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6727 | * Gets the list of {@code Message} objects that represent the notification |
| 6728 | */ |
| 6729 | public List<Message> getMessages() { |
| 6730 | return mMessages; |
| 6731 | } |
| 6732 | |
| 6733 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6734 | * Gets the list of historic {@code Message}s in the notification. |
| 6735 | */ |
| 6736 | public List<Message> getHistoricMessages() { |
| 6737 | return mHistoricMessages; |
| 6738 | } |
| 6739 | |
| 6740 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6741 | * Sets whether this conversation notification represents a group. |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6742 | * |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6743 | * @param isGroupConversation {@code true} if the conversation represents a group, |
| 6744 | * {@code false} otherwise. |
| 6745 | * @return this object for method chaining |
| 6746 | */ |
| 6747 | public MessagingStyle setGroupConversation(boolean isGroupConversation) { |
| 6748 | mIsGroupConversation = isGroupConversation; |
| 6749 | return this; |
| 6750 | } |
| 6751 | |
| 6752 | /** |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6753 | * Returns {@code true} if this notification represents a group conversation, otherwise |
| 6754 | * {@code false}. |
| 6755 | * |
| 6756 | * <p> If the application that generated this {@link MessagingStyle} targets an SDK version |
| 6757 | * less than {@link Build.VERSION_CODES#P}, this method becomes dependent on whether or |
| 6758 | * not the conversation title is set; returning {@code true} if the conversation title is |
| 6759 | * a non-null value, or {@code false} otherwise. From {@link Build.VERSION_CODES#P} forward, |
| 6760 | * this method returns what's set by {@link #setGroupConversation(boolean)} allowing for |
| 6761 | * named, non-group conversations. |
| 6762 | * |
| 6763 | * @see #setConversationTitle(CharSequence) |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6764 | */ |
| 6765 | public boolean isGroupConversation() { |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6766 | // When target SDK version is < P, a non-null conversation title dictates if this is |
| 6767 | // as group conversation. |
| 6768 | if (mBuilder != null |
| 6769 | && mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 6770 | < Build.VERSION_CODES.P) { |
| 6771 | return mConversationTitle != null; |
| 6772 | } |
| 6773 | |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6774 | return mIsGroupConversation; |
| 6775 | } |
| 6776 | |
| 6777 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6778 | * @hide |
| 6779 | */ |
| 6780 | @Override |
| 6781 | public void addExtras(Bundle extras) { |
| 6782 | super.addExtras(extras); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6783 | if (mUser != null) { |
| 6784 | // For legacy usages |
| 6785 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUser.getName()); |
| 6786 | extras.putParcelable(EXTRA_MESSAGING_PERSON, mUser); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6787 | } |
| 6788 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6789 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6790 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6791 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 6792 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6793 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6794 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 6795 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 6796 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6797 | |
| 6798 | fixTitleAndTextExtras(extras); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6799 | extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6800 | } |
| 6801 | |
| 6802 | private void fixTitleAndTextExtras(Bundle extras) { |
| 6803 | Message m = findLatestIncomingMessage(); |
| 6804 | CharSequence text = (m == null) ? null : m.mText; |
| 6805 | CharSequence sender = m == null ? null |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6806 | : m.mSender == null || TextUtils.isEmpty(m.mSender.getName()) |
| 6807 | ? mUser.getName() : m.mSender.getName(); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6808 | CharSequence title; |
| 6809 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 6810 | if (!TextUtils.isEmpty(sender)) { |
| 6811 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 6812 | title = mBuilder.mContext.getString( |
| 6813 | com.android.internal.R.string.notification_messaging_title_template, |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6814 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(sender)); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6815 | } else { |
| 6816 | title = mConversationTitle; |
| 6817 | } |
| 6818 | } else { |
| 6819 | title = sender; |
| 6820 | } |
| 6821 | |
| 6822 | if (title != null) { |
| 6823 | extras.putCharSequence(EXTRA_TITLE, title); |
| 6824 | } |
| 6825 | if (text != null) { |
| 6826 | extras.putCharSequence(EXTRA_TEXT, text); |
| 6827 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6828 | } |
| 6829 | |
| 6830 | /** |
| 6831 | * @hide |
| 6832 | */ |
| 6833 | @Override |
| 6834 | protected void restoreFromExtras(Bundle extras) { |
| 6835 | super.restoreFromExtras(extras); |
| 6836 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6837 | mUser = extras.getParcelable(EXTRA_MESSAGING_PERSON); |
| 6838 | if (mUser == null) { |
| 6839 | CharSequence displayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 6840 | mUser = new Person.Builder().setName(displayName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6841 | } |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 6842 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6843 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6844 | mMessages = Message.getMessagesFromBundleArray(messages); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6845 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6846 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6847 | mIsGroupConversation = extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6848 | } |
| 6849 | |
| 6850 | /** |
| 6851 | * @hide |
| 6852 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6853 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6854 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 6855 | mBuilder.mOriginalActions = mBuilder.mActions; |
| 6856 | mBuilder.mActions = new ArrayList<>(); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 6857 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6858 | false /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 6859 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6860 | mBuilder.mOriginalActions = null; |
| 6861 | return remoteViews; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6862 | } |
| 6863 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 6864 | /** |
| 6865 | * @hide |
| 6866 | */ |
| 6867 | @Override |
| 6868 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 6869 | if (other == null || getClass() != other.getClass()) { |
| 6870 | return true; |
| 6871 | } |
| 6872 | MessagingStyle newS = (MessagingStyle) other; |
| 6873 | List<MessagingStyle.Message> oldMs = getMessages(); |
| 6874 | List<MessagingStyle.Message> newMs = newS.getMessages(); |
| 6875 | |
| 6876 | if (oldMs == null) { |
| 6877 | oldMs = new ArrayList<>(); |
| 6878 | } |
| 6879 | if (newMs == null) { |
| 6880 | newMs = new ArrayList<>(); |
| 6881 | } |
| 6882 | |
| 6883 | int n = oldMs.size(); |
| 6884 | if (n != newMs.size()) { |
| 6885 | return true; |
| 6886 | } |
| 6887 | for (int i = 0; i < n; i++) { |
| 6888 | MessagingStyle.Message oldM = oldMs.get(i); |
| 6889 | MessagingStyle.Message newM = newMs.get(i); |
| 6890 | if (!Objects.equals(oldM.getText(), newM.getText())) { |
| 6891 | return true; |
| 6892 | } |
| 6893 | if (!Objects.equals(oldM.getDataUri(), newM.getDataUri())) { |
| 6894 | return true; |
| 6895 | } |
| 6896 | CharSequence oldSender = oldM.getSenderPerson() == null ? oldM.getSender() |
| 6897 | : oldM.getSenderPerson().getName(); |
| 6898 | CharSequence newSender = newM.getSenderPerson() == null ? newM.getSender() |
| 6899 | : newM.getSenderPerson().getName(); |
| 6900 | if (!Objects.equals(oldSender, newSender)) { |
| 6901 | return true; |
| 6902 | } |
| 6903 | |
| 6904 | String oldKey = oldM.getSenderPerson() == null |
| 6905 | ? null : oldM.getSenderPerson().getKey(); |
| 6906 | String newKey = newM.getSenderPerson() == null |
| 6907 | ? null : newM.getSenderPerson().getKey(); |
| 6908 | if (!Objects.equals(oldKey, newKey)) { |
| 6909 | return true; |
| 6910 | } |
| 6911 | // Other fields (like timestamp) intentionally excluded |
| 6912 | } |
| 6913 | return false; |
| 6914 | } |
| 6915 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6916 | private Message findLatestIncomingMessage() { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6917 | return findLatestIncomingMessage(mMessages); |
| 6918 | } |
| 6919 | |
| 6920 | /** |
| 6921 | * @hide |
| 6922 | */ |
| 6923 | @Nullable |
| 6924 | public static Message findLatestIncomingMessage( |
| 6925 | List<Message> messages) { |
| 6926 | for (int i = messages.size() - 1; i >= 0; i--) { |
| 6927 | Message m = messages.get(i); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6928 | // Incoming messages have a non-empty sender. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6929 | if (m.mSender != null && !TextUtils.isEmpty(m.mSender.getName())) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6930 | return m; |
| 6931 | } |
| 6932 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6933 | if (!messages.isEmpty()) { |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6934 | // No incoming messages, fall back to outgoing message |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6935 | return messages.get(messages.size() - 1); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6936 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6937 | return null; |
| 6938 | } |
| 6939 | |
| 6940 | /** |
| 6941 | * @hide |
| 6942 | */ |
| 6943 | @Override |
| 6944 | public RemoteViews makeBigContentView() { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6945 | return makeMessagingView(false /* displayImagesAtEnd */, true /* hideLargeIcon */); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 6946 | } |
| 6947 | |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 6948 | /** |
| 6949 | * Create a messaging layout. |
| 6950 | * |
| 6951 | * @param displayImagesAtEnd should images be displayed at the end of the content instead |
| 6952 | * of inline. |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6953 | * @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] | 6954 | * @return the created remoteView. |
| 6955 | */ |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 6956 | @NonNull |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6957 | private RemoteViews makeMessagingView(boolean displayImagesAtEnd, boolean hideRightIcons) { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6958 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6959 | ? super.mBigContentTitle |
| 6960 | : mConversationTitle; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6961 | boolean isOneToOne = TextUtils.isEmpty(conversationTitle); |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 6962 | CharSequence nameReplacement = null; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 6963 | if (hasOnlyWhiteSpaceSenders()) { |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 6964 | isOneToOne = true; |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 6965 | nameReplacement = conversationTitle; |
| 6966 | conversationTitle = null; |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6967 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6968 | TemplateBindResult bindResult = new TemplateBindResult(); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 6969 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6970 | mBuilder.getMessagingLayoutResource(), |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6971 | mBuilder.mParams.reset().hasProgress(false).title(conversationTitle).text(null) |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 6972 | .hideLargeIcon(hideRightIcons || isOneToOne) |
| 6973 | .hideReplyIcon(hideRightIcons) |
| 6974 | .headerTextSecondary(conversationTitle), |
| 6975 | bindResult); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6976 | addExtras(mBuilder.mN.extras); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 6977 | // also update the end margin if there is an image |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 6978 | contentView.setViewLayoutMarginEnd(R.id.notification_messaging, |
| 6979 | bindResult.getIconMarginEnd()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6980 | contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", |
| 6981 | mBuilder.resolveContrastColor()); |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 6982 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd", |
| 6983 | displayImagesAtEnd); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6984 | contentView.setIcon(R.id.status_bar_latest_event_content, "setLargeIcon", |
| 6985 | mBuilder.mN.mLargeIcon); |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 6986 | contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement", |
| 6987 | nameReplacement); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6988 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne", |
| 6989 | isOneToOne); |
| 6990 | contentView.setBundle(R.id.status_bar_latest_event_content, "setData", |
| 6991 | mBuilder.mN.extras); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6992 | return contentView; |
| 6993 | } |
| 6994 | |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 6995 | private boolean hasOnlyWhiteSpaceSenders() { |
| 6996 | for (int i = 0; i < mMessages.size(); i++) { |
| 6997 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6998 | Person sender = m.getSenderPerson(); |
| 6999 | if (sender != null && !isWhiteSpace(sender.getName())) { |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 7000 | return false; |
| 7001 | } |
| 7002 | } |
| 7003 | return true; |
| 7004 | } |
| 7005 | |
| 7006 | private boolean isWhiteSpace(CharSequence sender) { |
| 7007 | if (TextUtils.isEmpty(sender)) { |
| 7008 | return true; |
| 7009 | } |
| 7010 | if (sender.toString().matches("^\\s*$")) { |
| 7011 | return true; |
| 7012 | } |
| 7013 | // Let's check if we only have 0 whitespace chars. Some apps did this as a workaround |
| 7014 | // For the presentation that we had. |
| 7015 | for (int i = 0; i < sender.length(); i++) { |
| 7016 | char c = sender.charAt(i); |
| 7017 | if (c != '\u200B') { |
| 7018 | return false; |
| 7019 | } |
| 7020 | } |
| 7021 | return true; |
| 7022 | } |
| 7023 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7024 | private CharSequence createConversationTitleFromMessages() { |
| 7025 | ArraySet<CharSequence> names = new ArraySet<>(); |
| 7026 | for (int i = 0; i < mMessages.size(); i++) { |
| 7027 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7028 | Person sender = m.getSenderPerson(); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7029 | if (sender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7030 | names.add(sender.getName()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7031 | } |
| 7032 | } |
| 7033 | SpannableStringBuilder title = new SpannableStringBuilder(); |
| 7034 | int size = names.size(); |
| 7035 | for (int i = 0; i < size; i++) { |
| 7036 | CharSequence name = names.valueAt(i); |
| 7037 | if (!TextUtils.isEmpty(title)) { |
| 7038 | title.append(", "); |
| 7039 | } |
| 7040 | title.append(BidiFormatter.getInstance().unicodeWrap(name)); |
| 7041 | } |
| 7042 | return title; |
| 7043 | } |
| 7044 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7045 | /** |
| 7046 | * @hide |
| 7047 | */ |
| 7048 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7049 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 85d0e6e | 2018-03-23 18:08:32 -0700 | [diff] [blame] | 7050 | RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7051 | true /* hideLargeIcon */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 7052 | remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1); |
| 7053 | return remoteViews; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7054 | } |
| 7055 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 7056 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 7057 | return new TextAppearanceSpan(null, 0, 0, |
| 7058 | ColorStateList.valueOf(color), null); |
| 7059 | } |
| 7060 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7061 | public static final class Message { |
| 7062 | |
| 7063 | static final String KEY_TEXT = "text"; |
| 7064 | static final String KEY_TIMESTAMP = "time"; |
| 7065 | static final String KEY_SENDER = "sender"; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7066 | static final String KEY_SENDER_PERSON = "sender_person"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7067 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 7068 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7069 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7070 | static final String KEY_REMOTE_INPUT_HISTORY = "remote_input_history"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7071 | |
| 7072 | private final CharSequence mText; |
| 7073 | private final long mTimestamp; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7074 | @Nullable |
| 7075 | private final Person mSender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7076 | /** True if this message was generated from the extra |
| 7077 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY} |
| 7078 | */ |
| 7079 | private final boolean mRemoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7080 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7081 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7082 | private String mDataMimeType; |
| 7083 | private Uri mDataUri; |
| 7084 | |
| 7085 | /** |
| 7086 | * Constructor |
| 7087 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7088 | * @param timestamp Time at which the message arrived |
| 7089 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 7090 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 7091 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 7092 | * Should be unique amongst all individuals in the conversation, and should be |
| 7093 | * consistent during re-posts of the notification. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7094 | * |
| 7095 | * @deprecated use {@code Message(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7096 | */ |
| 7097 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7098 | this(text, timestamp, sender == null ? null |
| 7099 | : new Person.Builder().setName(sender).build()); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | /** |
| 7103 | * Constructor |
| 7104 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7105 | * @param timestamp Time at which the message arrived |
| 7106 | * @param sender The {@link Person} who sent the message. |
| 7107 | * Should be <code>null</code> for messages by the current user, in which case |
| 7108 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7109 | * <p> |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7110 | * The person provided should contain an Icon, set with |
| 7111 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7112 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7113 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7114 | * to differentiate between the different users. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7115 | * </p> |
| 7116 | */ |
Selim Cinek | eb53c22 | 2018-04-06 12:56:09 -0700 | [diff] [blame] | 7117 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender) { |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7118 | this(text, timestamp, sender, false /* remoteHistory */); |
| 7119 | } |
| 7120 | |
| 7121 | /** |
| 7122 | * Constructor |
| 7123 | * @param text A {@link CharSequence} to be displayed as the message content |
| 7124 | * @param timestamp Time at which the message arrived |
| 7125 | * @param sender The {@link Person} who sent the message. |
| 7126 | * Should be <code>null</code> for messages by the current user, in which case |
| 7127 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 7128 | * @param remoteInputHistory True if the messages was generated from the extra |
| 7129 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7130 | * <p> |
| 7131 | * The person provided should contain an Icon, set with |
| 7132 | * {@link Person.Builder#setIcon(Icon)} and also have a name provided |
| 7133 | * with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same |
| 7134 | * name, consider providing a key with {@link Person.Builder#setKey(String)} in order |
| 7135 | * to differentiate between the different users. |
| 7136 | * </p> |
| 7137 | * @hide |
| 7138 | */ |
| 7139 | public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender, |
| 7140 | boolean remoteInputHistory) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7141 | mText = text; |
| 7142 | mTimestamp = timestamp; |
| 7143 | mSender = sender; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7144 | mRemoteInputHistory = remoteInputHistory; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7145 | } |
| 7146 | |
| 7147 | /** |
| 7148 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 7149 | * where the platform doesn't support the MIME type, the original text provided in the |
| 7150 | * constructor will be used. |
| 7151 | * @param dataMimeType The MIME type of the content. See |
| 7152 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 7153 | * types on Android and Android Wear. |
| 7154 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 7155 | * <p class="note"> |
| 7156 | * <ol> |
| 7157 | * <li>Notification Listeners including the System UI need permission to access the |
| 7158 | * data the Uri points to. The recommended ways to do this are:</li> |
| 7159 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 7160 | * the correct permission to access your provider. The preferred mechanism for |
| 7161 | * providing access is to use per-URI permissions which are temporary and only |
| 7162 | * grant access to the receiving application. An easy way to create a |
| 7163 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 7164 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 7165 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 7166 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 7167 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 7168 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 7169 | * Note that once added to the system MediaStore the content is accessible to any |
| 7170 | * app on the device.</li> |
| 7171 | * </ol> |
| 7172 | * @return this object for method chaining |
| 7173 | */ |
| 7174 | public Message setData(String dataMimeType, Uri dataUri) { |
| 7175 | mDataMimeType = dataMimeType; |
| 7176 | mDataUri = dataUri; |
| 7177 | return this; |
| 7178 | } |
| 7179 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7180 | /** |
| 7181 | * Get the text to be used for this message, or the fallback text if a type and content |
| 7182 | * Uri have been set |
| 7183 | */ |
| 7184 | public CharSequence getText() { |
| 7185 | return mText; |
| 7186 | } |
| 7187 | |
| 7188 | /** |
| 7189 | * Get the time at which this message arrived |
| 7190 | */ |
| 7191 | public long getTimestamp() { |
| 7192 | return mTimestamp; |
| 7193 | } |
| 7194 | |
| 7195 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7196 | * Get the extras Bundle for this message. |
| 7197 | */ |
| 7198 | public Bundle getExtras() { |
| 7199 | return mExtras; |
| 7200 | } |
| 7201 | |
| 7202 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7203 | * 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] | 7204 | * |
| 7205 | * @deprecated use {@link #getSenderPerson()} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7206 | */ |
| 7207 | public CharSequence getSender() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7208 | return mSender == null ? null : mSender.getName(); |
| 7209 | } |
| 7210 | |
| 7211 | /** |
| 7212 | * Get the sender associated with this message. |
| 7213 | */ |
| 7214 | @Nullable |
| 7215 | public Person getSenderPerson() { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7216 | return mSender; |
| 7217 | } |
| 7218 | |
| 7219 | /** |
| 7220 | * Get the MIME type of the data pointed to by the Uri |
| 7221 | */ |
| 7222 | public String getDataMimeType() { |
| 7223 | return mDataMimeType; |
| 7224 | } |
| 7225 | |
| 7226 | /** |
| 7227 | * Get the the Uri pointing to the content of the message. Can be null, in which case |
| 7228 | * {@see #getText()} is used. |
| 7229 | */ |
| 7230 | public Uri getDataUri() { |
| 7231 | return mDataUri; |
| 7232 | } |
| 7233 | |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7234 | /** |
| 7235 | * @return True if the message was generated from |
| 7236 | * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}. |
| 7237 | * @hide |
| 7238 | */ |
| 7239 | public boolean isRemoteInputHistory() { |
| 7240 | return mRemoteInputHistory; |
| 7241 | } |
| 7242 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7243 | private Bundle toBundle() { |
| 7244 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7245 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7246 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7247 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7248 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7249 | if (mSender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7250 | // Legacy listeners need this |
| 7251 | bundle.putCharSequence(KEY_SENDER, mSender.getName()); |
| 7252 | bundle.putParcelable(KEY_SENDER_PERSON, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7253 | } |
| 7254 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7255 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7256 | } |
| 7257 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7258 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7259 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7260 | if (mExtras != null) { |
| 7261 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 7262 | } |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7263 | if (mRemoteInputHistory) { |
| 7264 | bundle.putBoolean(KEY_REMOTE_INPUT_HISTORY, mRemoteInputHistory); |
| 7265 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7266 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7267 | } |
| 7268 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7269 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 7270 | Bundle[] bundles = new Bundle[messages.size()]; |
| 7271 | final int N = messages.size(); |
| 7272 | for (int i = 0; i < N; i++) { |
| 7273 | bundles[i] = messages.get(i).toBundle(); |
| 7274 | } |
| 7275 | return bundles; |
| 7276 | } |
| 7277 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 7278 | /** |
| 7279 | * @return A list of messages read from the bundles. |
| 7280 | * |
| 7281 | * @hide |
| 7282 | */ |
| 7283 | public static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
| 7284 | if (bundles == null) { |
| 7285 | return new ArrayList<>(); |
| 7286 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7287 | List<Message> messages = new ArrayList<>(bundles.length); |
| 7288 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 7289 | if (bundles[i] instanceof Bundle) { |
| 7290 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 7291 | if (message != null) { |
| 7292 | messages.add(message); |
| 7293 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7294 | } |
| 7295 | } |
| 7296 | return messages; |
| 7297 | } |
| 7298 | |
| 7299 | static Message getMessageFromBundle(Bundle bundle) { |
| 7300 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 7301 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7302 | return null; |
| 7303 | } else { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7304 | |
| 7305 | Person senderPerson = bundle.getParcelable(KEY_SENDER_PERSON); |
| 7306 | if (senderPerson == null) { |
| 7307 | // Legacy apps that use compat don't actually provide the sender objects |
| 7308 | // We need to fix the compat version to provide people / use |
| 7309 | // the native api instead |
| 7310 | CharSequence senderName = bundle.getCharSequence(KEY_SENDER); |
| 7311 | if (senderName != null) { |
Selim Cinek | 9acd673 | 2018-03-23 16:39:02 -0700 | [diff] [blame] | 7312 | senderPerson = new Person.Builder().setName(senderName).build(); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7313 | } |
| 7314 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7315 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 7316 | bundle.getLong(KEY_TIMESTAMP), |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 7317 | senderPerson, |
| 7318 | bundle.getBoolean(KEY_REMOTE_INPUT_HISTORY, false)); |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7319 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 7320 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7321 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 7322 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7323 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 7324 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 7325 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 7326 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 7327 | return message; |
| 7328 | } |
| 7329 | } catch (ClassCastException e) { |
| 7330 | return null; |
| 7331 | } |
| 7332 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 7333 | } |
| 7334 | } |
| 7335 | |
| 7336 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7337 | * 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] | 7338 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7339 | * 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] | 7340 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 7341 | * Notification notif = new Notification.Builder(mContext) |
| 7342 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 7343 | * .setContentText(subject) |
| 7344 | * .setSmallIcon(R.drawable.new_mail) |
| 7345 | * .setLargeIcon(aBitmap) |
| 7346 | * .setStyle(new Notification.InboxStyle() |
| 7347 | * .addLine(str1) |
| 7348 | * .addLine(str2) |
| 7349 | * .setContentTitle("") |
| 7350 | * .setSummaryText("+3 more")) |
| 7351 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7352 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 7353 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7354 | * @see Notification#bigContentView |
| 7355 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7356 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7357 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 7358 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7359 | public InboxStyle() { |
| 7360 | } |
| 7361 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7362 | /** |
| 7363 | * @deprecated use {@code InboxStyle()}. |
| 7364 | */ |
| 7365 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7366 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 7367 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7368 | } |
| 7369 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7370 | /** |
| 7371 | * Overrides ContentTitle in the big form of the template. |
| 7372 | * This defaults to the value passed to setContentTitle(). |
| 7373 | */ |
| 7374 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7375 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7376 | return this; |
| 7377 | } |
| 7378 | |
| 7379 | /** |
| 7380 | * Set the first line of text after the detail section in the big form of the template. |
| 7381 | */ |
| 7382 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7383 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7384 | return this; |
| 7385 | } |
| 7386 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 7387 | /** |
| 7388 | * Append a line to the digest section of the Inbox notification. |
| 7389 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7390 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 7391 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7392 | return this; |
| 7393 | } |
| 7394 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7395 | /** |
| 7396 | * @hide |
| 7397 | */ |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7398 | public ArrayList<CharSequence> getLines() { |
| 7399 | return mTexts; |
| 7400 | } |
| 7401 | |
| 7402 | /** |
| 7403 | * @hide |
| 7404 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7405 | public void addExtras(Bundle extras) { |
| 7406 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7407 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 7408 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 7409 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 7410 | } |
| 7411 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7412 | /** |
| 7413 | * @hide |
| 7414 | */ |
| 7415 | @Override |
| 7416 | protected void restoreFromExtras(Bundle extras) { |
| 7417 | super.restoreFromExtras(extras); |
| 7418 | |
| 7419 | mTexts.clear(); |
| 7420 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 7421 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 7422 | } |
| 7423 | } |
| 7424 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7425 | /** |
| 7426 | * @hide |
| 7427 | */ |
| 7428 | public RemoteViews makeBigContentView() { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 7429 | // Remove the content text so it disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7430 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7431 | CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT); |
| 7432 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7433 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7434 | TemplateBindResult result = new TemplateBindResult(); |
| 7435 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource(), result); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 7436 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7437 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7438 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7439 | 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] | 7440 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 7441 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 7442 | // Make sure all rows are gone in case we reuse a view. |
| 7443 | for (int rowId : rowIds) { |
| 7444 | contentView.setViewVisibility(rowId, View.GONE); |
| 7445 | } |
| 7446 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7447 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7448 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7449 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7450 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7451 | int onlyViewId = 0; |
| 7452 | int maxRows = rowIds.length; |
| 7453 | if (mBuilder.mActions.size() > 0) { |
| 7454 | maxRows--; |
| 7455 | } |
| 7456 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7457 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7458 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7459 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 7460 | contentView.setTextViewText(rowIds[i], |
| 7461 | mBuilder.processTextSpans(mBuilder.processLegacyText(str))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 7462 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i]); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7463 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7464 | handleInboxImageMargin(contentView, rowIds[i], first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7465 | result.getIconMarginEnd()); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7466 | if (first) { |
| 7467 | onlyViewId = rowIds[i]; |
| 7468 | } else { |
| 7469 | onlyViewId = 0; |
| 7470 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7471 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7472 | } |
| 7473 | i++; |
| 7474 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 7475 | if (onlyViewId != 0) { |
| 7476 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 7477 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 7478 | R.dimen.notification_text_margin_top); |
| 7479 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 7480 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7481 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7482 | return contentView; |
| 7483 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7484 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7485 | /** |
| 7486 | * @hide |
| 7487 | */ |
| 7488 | @Override |
| 7489 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7490 | if (other == null || getClass() != other.getClass()) { |
| 7491 | return true; |
| 7492 | } |
| 7493 | InboxStyle newS = (InboxStyle) other; |
| 7494 | return !Objects.equals(getLines(), newS.getLines()); |
| 7495 | } |
| 7496 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7497 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first, |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7498 | int marginEndValue) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7499 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7500 | if (first) { |
| 7501 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 7502 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 7503 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7504 | if (!hasProgress) { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7505 | endMargin = marginEndValue; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7506 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7507 | } |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7508 | contentView.setViewLayoutMarginEnd(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 7509 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 7510 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7511 | |
| 7512 | /** |
| 7513 | * Notification style for media playback notifications. |
| 7514 | * |
| 7515 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 7516 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 7517 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7518 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 7519 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 7520 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7521 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7522 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 7523 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 7524 | * {@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] | 7525 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7526 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7527 | * Notifications created with MediaStyle will have their category set to |
| 7528 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 7529 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7530 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7531 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 7532 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7533 | * the System UI can identify this as a notification representing an active media session |
| 7534 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 7535 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7536 | * <p> |
| 7537 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 7538 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 7539 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 7540 | * <p> |
| 7541 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7542 | * To use this style with your Notification, feed it to |
| 7543 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7544 | * <pre class="prettyprint"> |
| 7545 | * Notification noti = new Notification.Builder() |
| 7546 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 7547 | * .setContentTitle("Track title") |
| 7548 | * .setContentText("Artist - Album") |
| 7549 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7550 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 7551 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7552 | * .build(); |
| 7553 | * </pre> |
| 7554 | * |
| 7555 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7556 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7557 | */ |
| 7558 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7559 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7560 | static final int MAX_MEDIA_BUTTONS = 5; |
| 7561 | |
| 7562 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7563 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7564 | |
| 7565 | public MediaStyle() { |
| 7566 | } |
| 7567 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7568 | /** |
| 7569 | * @deprecated use {@code MediaStyle()}. |
| 7570 | */ |
| 7571 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7572 | public MediaStyle(Builder builder) { |
| 7573 | setBuilder(builder); |
| 7574 | } |
| 7575 | |
| 7576 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7577 | * 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] | 7578 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7579 | * |
| 7580 | * @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] | 7581 | */ |
| 7582 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 7583 | mActionsToShowInCompact = actions; |
| 7584 | return this; |
| 7585 | } |
| 7586 | |
| 7587 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7588 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 7589 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7590 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7591 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7592 | mToken = token; |
| 7593 | return this; |
| 7594 | } |
| 7595 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7596 | /** |
| 7597 | * @hide |
| 7598 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7599 | @Override |
| 7600 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7601 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7602 | if (wip.category == null) { |
| 7603 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 7604 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7605 | return wip; |
| 7606 | } |
| 7607 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7608 | /** |
| 7609 | * @hide |
| 7610 | */ |
| 7611 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7612 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7613 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7614 | } |
| 7615 | |
| 7616 | /** |
| 7617 | * @hide |
| 7618 | */ |
| 7619 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7620 | public RemoteViews makeBigContentView() { |
| 7621 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7622 | } |
| 7623 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7624 | /** |
| 7625 | * @hide |
| 7626 | */ |
| 7627 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7628 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7629 | RemoteViews expanded = makeMediaBigContentView(); |
| 7630 | return expanded != null ? expanded : makeMediaContentView(); |
| 7631 | } |
| 7632 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7633 | /** @hide */ |
| 7634 | @Override |
| 7635 | public void addExtras(Bundle extras) { |
| 7636 | super.addExtras(extras); |
| 7637 | |
| 7638 | if (mToken != null) { |
| 7639 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 7640 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 7641 | if (mActionsToShowInCompact != null) { |
| 7642 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 7643 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7644 | } |
| 7645 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7646 | /** |
| 7647 | * @hide |
| 7648 | */ |
| 7649 | @Override |
| 7650 | protected void restoreFromExtras(Bundle extras) { |
| 7651 | super.restoreFromExtras(extras); |
| 7652 | |
| 7653 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 7654 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 7655 | } |
| 7656 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 7657 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 7658 | } |
| 7659 | } |
| 7660 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7661 | /** |
| 7662 | * @hide |
| 7663 | */ |
| 7664 | @Override |
| 7665 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7666 | if (other == null || getClass() != other.getClass()) { |
| 7667 | return true; |
| 7668 | } |
| 7669 | // All fields to compare are on the Notification object |
| 7670 | return false; |
| 7671 | } |
| 7672 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7673 | private RemoteViews generateMediaActionButton(Action action, int color) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7674 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 7675 | RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 7676 | R.layout.notification_material_media_action); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 7677 | button.setImageViewIcon(R.id.action0, action.getIcon()); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 7678 | |
| 7679 | // If the action buttons should not be tinted, then just use the default |
| 7680 | // notification color. Otherwise, just use the passed-in color. |
| 7681 | int tintColor = mBuilder.shouldTintActionButtons() || mBuilder.isColorized() |
| 7682 | ? color |
| 7683 | : NotificationColorUtil.resolveColor(mBuilder.mContext, |
| 7684 | Notification.COLOR_DEFAULT); |
| 7685 | |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 7686 | button.setDrawableTint(R.id.action0, false, tintColor, |
| 7687 | PorterDuff.Mode.SRC_ATOP); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7688 | if (!tombstone) { |
| 7689 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 7690 | } |
| 7691 | button.setContentDescription(R.id.action0, action.title); |
| 7692 | return button; |
| 7693 | } |
| 7694 | |
| 7695 | private RemoteViews makeMediaContentView() { |
| 7696 | RemoteViews view = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7697 | R.layout.notification_template_material_media, false, /* hasProgress */ |
| 7698 | null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7699 | |
| 7700 | final int numActions = mBuilder.mActions.size(); |
| 7701 | final int N = mActionsToShowInCompact == null |
| 7702 | ? 0 |
| 7703 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 7704 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7705 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7706 | for (int i = 0; i < N; i++) { |
| 7707 | if (i >= numActions) { |
| 7708 | throw new IllegalArgumentException(String.format( |
| 7709 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 7710 | i, numActions - 1)); |
| 7711 | } |
| 7712 | |
| 7713 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 7714 | final RemoteViews button = generateMediaActionButton(action, getActionColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7715 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7716 | } |
| 7717 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 7718 | handleImage(view); |
| 7719 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7720 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 7721 | if (mBuilder.mN.hasLargeIcon()) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7722 | endMargin = R.dimen.notification_media_image_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 7723 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7724 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7725 | return view; |
| 7726 | } |
| 7727 | |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 7728 | private int getActionColor() { |
| 7729 | return mBuilder.isColorized() ? mBuilder.getPrimaryTextColor() |
| 7730 | : mBuilder.resolveContrastColor(); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7731 | } |
| 7732 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7733 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7734 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7735 | // Dont add an expanded view if there is no more content to be revealed |
| 7736 | int actionsInCompact = mActionsToShowInCompact == null |
| 7737 | ? 0 |
| 7738 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 7739 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7740 | return null; |
| 7741 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7742 | RemoteViews big = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7743 | R.layout.notification_template_material_big_media, false, null /* result */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7744 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7745 | if (actionCount > 0) { |
| 7746 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 7747 | for (int i = 0; i < actionCount; i++) { |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7748 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i), |
Selim Cinek | c7f5a82 | 2018-03-20 19:32:06 -0700 | [diff] [blame] | 7749 | getActionColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7750 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7751 | } |
| 7752 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7753 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7754 | return big; |
| 7755 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7756 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7757 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 7758 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7759 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 7760 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7761 | } |
| 7762 | } |
| 7763 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7764 | /** |
| 7765 | * @hide |
| 7766 | */ |
| 7767 | @Override |
| 7768 | protected boolean hasProgress() { |
| 7769 | return false; |
| 7770 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7771 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7772 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7773 | /** |
| 7774 | * Notification style for custom views that are decorated by the system |
| 7775 | * |
| 7776 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 7777 | * style and still obtain system decorations like the notification header with the expand |
| 7778 | * affordance and actions. |
| 7779 | * |
| 7780 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 7781 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 7782 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 7783 | * corresponding custom views to display. |
| 7784 | * |
| 7785 | * To use this style with your Notification, feed it to |
| 7786 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7787 | * <pre class="prettyprint"> |
| 7788 | * Notification noti = new Notification.Builder() |
| 7789 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 7790 | * .setLargeIcon(albumArtBitmap)) |
| 7791 | * .setCustomContentView(contentView); |
| 7792 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 7793 | * .build(); |
| 7794 | * </pre> |
| 7795 | */ |
| 7796 | public static class DecoratedCustomViewStyle extends Style { |
| 7797 | |
| 7798 | public DecoratedCustomViewStyle() { |
| 7799 | } |
| 7800 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7801 | /** |
| 7802 | * @hide |
| 7803 | */ |
| 7804 | public boolean displayCustomViewInline() { |
| 7805 | return true; |
| 7806 | } |
| 7807 | |
| 7808 | /** |
| 7809 | * @hide |
| 7810 | */ |
| 7811 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7812 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7813 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 7814 | } |
| 7815 | |
| 7816 | /** |
| 7817 | * @hide |
| 7818 | */ |
| 7819 | @Override |
| 7820 | public RemoteViews makeBigContentView() { |
| 7821 | return makeDecoratedBigContentView(); |
| 7822 | } |
| 7823 | |
| 7824 | /** |
| 7825 | * @hide |
| 7826 | */ |
| 7827 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7828 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7829 | return makeDecoratedHeadsUpContentView(); |
| 7830 | } |
| 7831 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7832 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 7833 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 7834 | ? mBuilder.mN.contentView |
| 7835 | : mBuilder.mN.headsUpContentView; |
| 7836 | if (mBuilder.mActions.size() == 0) { |
| 7837 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 7838 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7839 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7840 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7841 | mBuilder.getBigBaseLayoutResource(), result); |
| 7842 | buildIntoRemoteViewContent(remoteViews, headsUpContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7843 | return remoteViews; |
| 7844 | } |
| 7845 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7846 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7847 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7848 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7849 | mBuilder.getBaseLayoutResource(), result); |
| 7850 | buildIntoRemoteViewContent(remoteViews, customContent, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7851 | return remoteViews; |
| 7852 | } |
| 7853 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7854 | private RemoteViews makeDecoratedBigContentView() { |
| 7855 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 7856 | ? mBuilder.mN.contentView |
| 7857 | : mBuilder.mN.bigContentView; |
| 7858 | if (mBuilder.mActions.size() == 0) { |
| 7859 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 7860 | } |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7861 | TemplateBindResult result = new TemplateBindResult(); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7862 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7863 | mBuilder.getBigBaseLayoutResource(), result); |
| 7864 | buildIntoRemoteViewContent(remoteViews, bigContentView, result); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7865 | return remoteViews; |
| 7866 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7867 | |
| 7868 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7869 | RemoteViews customContent, TemplateBindResult result) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 7870 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 7871 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 7872 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 7873 | customContent = customContent.clone(); |
Anthony Chen | 8f5f358 | 2017-04-11 11:18:37 -0700 | [diff] [blame] | 7874 | remoteViews.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress); |
| 7875 | remoteViews.addView(R.id.notification_main_column, customContent, 0 /* index */); |
Selim Cinek | fc8073c | 2017-08-16 17:50:20 -0700 | [diff] [blame] | 7876 | remoteViews.setReapplyDisallowed(); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 7877 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7878 | // also update the end margin if there is an image |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7879 | Resources resources = mBuilder.mContext.getResources(); |
| 7880 | int endMargin = resources.getDimensionPixelSize( |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 7881 | R.dimen.notification_content_margin_end) + result.getIconMarginEnd(); |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 7882 | remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7883 | } |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7884 | |
| 7885 | /** |
| 7886 | * @hide |
| 7887 | */ |
| 7888 | @Override |
| 7889 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7890 | if (other == null || getClass() != other.getClass()) { |
| 7891 | return true; |
| 7892 | } |
| 7893 | // Comparison done for all custom RemoteViews, independent of style |
| 7894 | return false; |
| 7895 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7896 | } |
| 7897 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7898 | /** |
| 7899 | * Notification style for media custom views that are decorated by the system |
| 7900 | * |
| 7901 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 7902 | * this style and still obtain system decorations like the notification header with the expand |
| 7903 | * affordance and actions. |
| 7904 | * |
| 7905 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 7906 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 7907 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 7908 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7909 | * <p> |
| 7910 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 7911 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 7912 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7913 | * To use this style with your Notification, feed it to |
| 7914 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7915 | * <pre class="prettyprint"> |
| 7916 | * Notification noti = new Notification.Builder() |
| 7917 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 7918 | * .setLargeIcon(albumArtBitmap)) |
| 7919 | * .setCustomContentView(contentView); |
| 7920 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 7921 | * .setMediaSession(mySession)) |
| 7922 | * .build(); |
| 7923 | * </pre> |
| 7924 | * |
| 7925 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 7926 | * @see android.app.Notification.MediaStyle |
| 7927 | */ |
| 7928 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 7929 | |
| 7930 | public DecoratedMediaCustomViewStyle() { |
| 7931 | } |
| 7932 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7933 | /** |
| 7934 | * @hide |
| 7935 | */ |
| 7936 | public boolean displayCustomViewInline() { |
| 7937 | return true; |
| 7938 | } |
| 7939 | |
| 7940 | /** |
| 7941 | * @hide |
| 7942 | */ |
| 7943 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7944 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 7945 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7946 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 7947 | mBuilder.mN.contentView); |
| 7948 | } |
| 7949 | |
| 7950 | /** |
| 7951 | * @hide |
| 7952 | */ |
| 7953 | @Override |
| 7954 | public RemoteViews makeBigContentView() { |
| 7955 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 7956 | ? mBuilder.mN.bigContentView |
| 7957 | : mBuilder.mN.contentView; |
| 7958 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 7959 | } |
| 7960 | |
| 7961 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 7962 | RemoteViews remoteViews = super.makeBigContentView(); |
| 7963 | if (remoteViews != null) { |
| 7964 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 7965 | customRemoteView); |
| 7966 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7967 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7968 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 7969 | customRemoteView); |
| 7970 | } else { |
| 7971 | return null; |
| 7972 | } |
| 7973 | } |
| 7974 | |
| 7975 | /** |
| 7976 | * @hide |
| 7977 | */ |
| 7978 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7979 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7980 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 7981 | ? mBuilder.mN.headsUpContentView |
| 7982 | : mBuilder.mN.contentView; |
| 7983 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 7984 | } |
| 7985 | |
Julia Reynolds | 7217dc9 | 2018-03-07 12:12:09 -0500 | [diff] [blame] | 7986 | /** |
| 7987 | * @hide |
| 7988 | */ |
| 7989 | @Override |
| 7990 | public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7991 | if (other == null || getClass() != other.getClass()) { |
| 7992 | return true; |
| 7993 | } |
| 7994 | // Comparison done for all custom RemoteViews, independent of style |
| 7995 | return false; |
| 7996 | } |
| 7997 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7998 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 7999 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8000 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8001 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 8002 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8003 | customContent = customContent.clone(); |
Selim Cinek | 87c3153 | 2017-08-18 18:53:44 -0700 | [diff] [blame] | 8004 | customContent.overrideTextColors(mBuilder.getPrimaryTextColor()); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 8005 | remoteViews.removeAllViews(id); |
| 8006 | remoteViews.addView(id, customContent); |
Selim Cinek | fc8073c | 2017-08-16 17:50:20 -0700 | [diff] [blame] | 8007 | remoteViews.setReapplyDisallowed(); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 8008 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 8009 | return remoteViews; |
| 8010 | } |
| 8011 | } |
| 8012 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8013 | // When adding a new Style subclass here, don't forget to update |
| 8014 | // Builder.getNotificationStyleClass. |
| 8015 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8016 | /** |
| 8017 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 8018 | * metadata or change options on a notification builder. |
| 8019 | */ |
| 8020 | public interface Extender { |
| 8021 | /** |
| 8022 | * Apply this extender to a notification builder. |
| 8023 | * @param builder the builder to be modified. |
| 8024 | * @return the build object for chaining. |
| 8025 | */ |
| 8026 | public Builder extend(Builder builder); |
| 8027 | } |
| 8028 | |
| 8029 | /** |
| 8030 | * Helper class to add wearable extensions to notifications. |
| 8031 | * <p class="note"> See |
| 8032 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 8033 | * for Android Wear</a> for more information on how to use this class. |
| 8034 | * <p> |
| 8035 | * To create a notification with wearable extensions: |
| 8036 | * <ol> |
| 8037 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 8038 | * properties. |
| 8039 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 8040 | * <li>Set wearable-specific properties using the |
| 8041 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 8042 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 8043 | * notification. |
| 8044 | * <li>Post the notification to the notification system with the |
| 8045 | * {@code NotificationManager.notify(...)} methods. |
| 8046 | * </ol> |
| 8047 | * |
| 8048 | * <pre class="prettyprint"> |
| 8049 | * Notification notif = new Notification.Builder(mContext) |
| 8050 | * .setContentTitle("New mail from " + sender.toString()) |
| 8051 | * .setContentText(subject) |
| 8052 | * .setSmallIcon(R.drawable.new_mail) |
| 8053 | * .extend(new Notification.WearableExtender() |
| 8054 | * .setContentIcon(R.drawable.new_mail)) |
| 8055 | * .build(); |
| 8056 | * NotificationManager notificationManger = |
| 8057 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 8058 | * notificationManger.notify(0, notif);</pre> |
| 8059 | * |
| 8060 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 8061 | * {@code WearableExtender(Notification)} constructor, |
| 8062 | * and then using the {@code get} methods to access values. |
| 8063 | * |
| 8064 | * <pre class="prettyprint"> |
| 8065 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 8066 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8067 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8068 | */ |
| 8069 | public static final class WearableExtender implements Extender { |
| 8070 | /** |
| 8071 | * Sentinel value for an action index that is unset. |
| 8072 | */ |
| 8073 | public static final int UNSET_ACTION_INDEX = -1; |
| 8074 | |
| 8075 | /** |
| 8076 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 8077 | * default sizing. |
| 8078 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 8079 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8080 | * on their content. |
| 8081 | */ |
| 8082 | public static final int SIZE_DEFAULT = 0; |
| 8083 | |
| 8084 | /** |
| 8085 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8086 | * with an extra small size. |
| 8087 | * <p>This value is only applicable for custom display notifications created using |
| 8088 | * {@link #setDisplayIntent}. |
| 8089 | */ |
| 8090 | public static final int SIZE_XSMALL = 1; |
| 8091 | |
| 8092 | /** |
| 8093 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8094 | * with a small size. |
| 8095 | * <p>This value is only applicable for custom display notifications created using |
| 8096 | * {@link #setDisplayIntent}. |
| 8097 | */ |
| 8098 | public static final int SIZE_SMALL = 2; |
| 8099 | |
| 8100 | /** |
| 8101 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8102 | * with a medium size. |
| 8103 | * <p>This value is only applicable for custom display notifications created using |
| 8104 | * {@link #setDisplayIntent}. |
| 8105 | */ |
| 8106 | public static final int SIZE_MEDIUM = 3; |
| 8107 | |
| 8108 | /** |
| 8109 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8110 | * with a large size. |
| 8111 | * <p>This value is only applicable for custom display notifications created using |
| 8112 | * {@link #setDisplayIntent}. |
| 8113 | */ |
| 8114 | public static final int SIZE_LARGE = 4; |
| 8115 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 8116 | /** |
| 8117 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 8118 | * full screen. |
| 8119 | * <p>This value is only applicable for custom display notifications created using |
| 8120 | * {@link #setDisplayIntent}. |
| 8121 | */ |
| 8122 | public static final int SIZE_FULL_SCREEN = 5; |
| 8123 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8124 | /** |
| 8125 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 8126 | * short amount of time when this notification is displayed on the screen. This |
| 8127 | * is the default value. |
| 8128 | */ |
| 8129 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 8130 | |
| 8131 | /** |
| 8132 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 8133 | * for a longer amount of time when this notification is displayed on the screen. |
| 8134 | */ |
| 8135 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 8136 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8137 | /** Notification extra which contains wearable extensions */ |
| 8138 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 8139 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 8140 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8141 | private static final String KEY_ACTIONS = "actions"; |
| 8142 | private static final String KEY_FLAGS = "flags"; |
| 8143 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 8144 | private static final String KEY_PAGES = "pages"; |
| 8145 | private static final String KEY_BACKGROUND = "background"; |
| 8146 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 8147 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 8148 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 8149 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 8150 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 8151 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8152 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8153 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8154 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8155 | |
| 8156 | // Flags bitwise-ored to mFlags |
| 8157 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 8158 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 8159 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 8160 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8161 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 8162 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8163 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8164 | |
| 8165 | // Default value for flags integer |
| 8166 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 8167 | |
| 8168 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 8169 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 8170 | |
| 8171 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 8172 | private int mFlags = DEFAULT_FLAGS; |
| 8173 | private PendingIntent mDisplayIntent; |
| 8174 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 8175 | private Bitmap mBackground; |
| 8176 | private int mContentIcon; |
| 8177 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 8178 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 8179 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 8180 | private int mCustomContentHeight; |
| 8181 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8182 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8183 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8184 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8185 | |
| 8186 | /** |
| 8187 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 8188 | * options. |
| 8189 | */ |
| 8190 | public WearableExtender() { |
| 8191 | } |
| 8192 | |
| 8193 | public WearableExtender(Notification notif) { |
| 8194 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 8195 | if (wearableBundle != null) { |
| 8196 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 8197 | if (actions != null) { |
| 8198 | mActions.addAll(actions); |
| 8199 | } |
| 8200 | |
| 8201 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 8202 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 8203 | |
| 8204 | Notification[] pages = getNotificationArrayFromBundle( |
| 8205 | wearableBundle, KEY_PAGES); |
| 8206 | if (pages != null) { |
| 8207 | Collections.addAll(mPages, pages); |
| 8208 | } |
| 8209 | |
| 8210 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 8211 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 8212 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 8213 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 8214 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 8215 | UNSET_ACTION_INDEX); |
| 8216 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 8217 | SIZE_DEFAULT); |
| 8218 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 8219 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8220 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8221 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8222 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8223 | } |
| 8224 | } |
| 8225 | |
| 8226 | /** |
| 8227 | * Apply wearable extensions to a notification that is being built. This is typically |
| 8228 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 8229 | * {@link android.app.Notification.Builder}. |
| 8230 | */ |
| 8231 | @Override |
| 8232 | public Notification.Builder extend(Notification.Builder builder) { |
| 8233 | Bundle wearableBundle = new Bundle(); |
| 8234 | |
| 8235 | if (!mActions.isEmpty()) { |
| 8236 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 8237 | } |
| 8238 | if (mFlags != DEFAULT_FLAGS) { |
| 8239 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 8240 | } |
| 8241 | if (mDisplayIntent != null) { |
| 8242 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 8243 | } |
| 8244 | if (!mPages.isEmpty()) { |
| 8245 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 8246 | new Notification[mPages.size()])); |
| 8247 | } |
| 8248 | if (mBackground != null) { |
| 8249 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 8250 | } |
| 8251 | if (mContentIcon != 0) { |
| 8252 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 8253 | } |
| 8254 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 8255 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 8256 | } |
| 8257 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 8258 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 8259 | mContentActionIndex); |
| 8260 | } |
| 8261 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 8262 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 8263 | } |
| 8264 | if (mCustomContentHeight != 0) { |
| 8265 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 8266 | } |
| 8267 | if (mGravity != DEFAULT_GRAVITY) { |
| 8268 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 8269 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8270 | if (mHintScreenTimeout != 0) { |
| 8271 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 8272 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8273 | if (mDismissalId != null) { |
| 8274 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 8275 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8276 | if (mBridgeTag != null) { |
| 8277 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 8278 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8279 | |
| 8280 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 8281 | return builder; |
| 8282 | } |
| 8283 | |
| 8284 | @Override |
| 8285 | public WearableExtender clone() { |
| 8286 | WearableExtender that = new WearableExtender(); |
| 8287 | that.mActions = new ArrayList<Action>(this.mActions); |
| 8288 | that.mFlags = this.mFlags; |
| 8289 | that.mDisplayIntent = this.mDisplayIntent; |
| 8290 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 8291 | that.mBackground = this.mBackground; |
| 8292 | that.mContentIcon = this.mContentIcon; |
| 8293 | that.mContentIconGravity = this.mContentIconGravity; |
| 8294 | that.mContentActionIndex = this.mContentActionIndex; |
| 8295 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 8296 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 8297 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8298 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8299 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8300 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8301 | return that; |
| 8302 | } |
| 8303 | |
| 8304 | /** |
| 8305 | * Add a wearable action to this notification. |
| 8306 | * |
| 8307 | * <p>When wearable actions are added using this method, the set of actions that |
| 8308 | * show on a wearable device splits from devices that only show actions added |
| 8309 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 8310 | * of which actions display on different devices. |
| 8311 | * |
| 8312 | * @param action the action to add to this notification |
| 8313 | * @return this object for method chaining |
| 8314 | * @see android.app.Notification.Action |
| 8315 | */ |
| 8316 | public WearableExtender addAction(Action action) { |
| 8317 | mActions.add(action); |
| 8318 | return this; |
| 8319 | } |
| 8320 | |
| 8321 | /** |
| 8322 | * Adds wearable actions to this notification. |
| 8323 | * |
| 8324 | * <p>When wearable actions are added using this method, the set of actions that |
| 8325 | * show on a wearable device splits from devices that only show actions added |
| 8326 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 8327 | * of which actions display on different devices. |
| 8328 | * |
| 8329 | * @param actions the actions to add to this notification |
| 8330 | * @return this object for method chaining |
| 8331 | * @see android.app.Notification.Action |
| 8332 | */ |
| 8333 | public WearableExtender addActions(List<Action> actions) { |
| 8334 | mActions.addAll(actions); |
| 8335 | return this; |
| 8336 | } |
| 8337 | |
| 8338 | /** |
| 8339 | * Clear all wearable actions present on this builder. |
| 8340 | * @return this object for method chaining. |
| 8341 | * @see #addAction |
| 8342 | */ |
| 8343 | public WearableExtender clearActions() { |
| 8344 | mActions.clear(); |
| 8345 | return this; |
| 8346 | } |
| 8347 | |
| 8348 | /** |
| 8349 | * Get the wearable actions present on this notification. |
| 8350 | */ |
| 8351 | public List<Action> getActions() { |
| 8352 | return mActions; |
| 8353 | } |
| 8354 | |
| 8355 | /** |
| 8356 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8357 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 8358 | * |
| 8359 | * <pre class="prettyprint"> |
| 8360 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 8361 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 8362 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 8363 | * Notification notif = new Notification.Builder(context) |
| 8364 | * .extend(new Notification.WearableExtender() |
| 8365 | * .setDisplayIntent(displayPendingIntent) |
| 8366 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 8367 | * .build();</pre> |
| 8368 | * |
| 8369 | * <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] | 8370 | * should have an empty task affinity. It is also recommended to use the device |
| 8371 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 8372 | * |
| 8373 | * <p>Example AndroidManifest.xml entry: |
| 8374 | * <pre class="prettyprint"> |
| 8375 | * <activity android:name="com.example.MyDisplayActivity" |
| 8376 | * android:exported="true" |
| 8377 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 8378 | * android:taskAffinity="" |
| 8379 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8380 | * |
| 8381 | * @param intent the {@link PendingIntent} for an activity |
| 8382 | * @return this object for method chaining |
| 8383 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 8384 | */ |
| 8385 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 8386 | mDisplayIntent = intent; |
| 8387 | return this; |
| 8388 | } |
| 8389 | |
| 8390 | /** |
| 8391 | * Get the intent to launch inside of an activity view when displaying this |
| 8392 | * notification. This {@code PendingIntent} should be for an activity. |
| 8393 | */ |
| 8394 | public PendingIntent getDisplayIntent() { |
| 8395 | return mDisplayIntent; |
| 8396 | } |
| 8397 | |
| 8398 | /** |
| 8399 | * Add an additional page of content to display with this notification. The current |
| 8400 | * notification forms the first page, and pages added using this function form |
| 8401 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8402 | * sections. |
| 8403 | * |
| 8404 | * @param page the notification to add as another page |
| 8405 | * @return this object for method chaining |
| 8406 | * @see android.app.Notification.WearableExtender#getPages |
| 8407 | */ |
| 8408 | public WearableExtender addPage(Notification page) { |
| 8409 | mPages.add(page); |
| 8410 | return this; |
| 8411 | } |
| 8412 | |
| 8413 | /** |
| 8414 | * Add additional pages of content to display with this notification. The current |
| 8415 | * notification forms the first page, and pages added using this function form |
| 8416 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8417 | * sections. |
| 8418 | * |
| 8419 | * @param pages a list of notifications |
| 8420 | * @return this object for method chaining |
| 8421 | * @see android.app.Notification.WearableExtender#getPages |
| 8422 | */ |
| 8423 | public WearableExtender addPages(List<Notification> pages) { |
| 8424 | mPages.addAll(pages); |
| 8425 | return this; |
| 8426 | } |
| 8427 | |
| 8428 | /** |
| 8429 | * Clear all additional pages present on this builder. |
| 8430 | * @return this object for method chaining. |
| 8431 | * @see #addPage |
| 8432 | */ |
| 8433 | public WearableExtender clearPages() { |
| 8434 | mPages.clear(); |
| 8435 | return this; |
| 8436 | } |
| 8437 | |
| 8438 | /** |
| 8439 | * Get the array of additional pages of content for displaying this notification. The |
| 8440 | * current notification forms the first page, and elements within this array form |
| 8441 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8442 | * sections. |
| 8443 | * @return the pages for this notification |
| 8444 | */ |
| 8445 | public List<Notification> getPages() { |
| 8446 | return mPages; |
| 8447 | } |
| 8448 | |
| 8449 | /** |
| 8450 | * Set a background image to be displayed behind the notification content. |
| 8451 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 8452 | * will work with any notification style. |
| 8453 | * |
| 8454 | * @param background the background bitmap |
| 8455 | * @return this object for method chaining |
| 8456 | * @see android.app.Notification.WearableExtender#getBackground |
| 8457 | */ |
| 8458 | public WearableExtender setBackground(Bitmap background) { |
| 8459 | mBackground = background; |
| 8460 | return this; |
| 8461 | } |
| 8462 | |
| 8463 | /** |
| 8464 | * Get a background image to be displayed behind the notification content. |
| 8465 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 8466 | * will work with any notification style. |
| 8467 | * |
| 8468 | * @return the background image |
| 8469 | * @see android.app.Notification.WearableExtender#setBackground |
| 8470 | */ |
| 8471 | public Bitmap getBackground() { |
| 8472 | return mBackground; |
| 8473 | } |
| 8474 | |
| 8475 | /** |
| 8476 | * Set an icon that goes with the content of this notification. |
| 8477 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8478 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8479 | public WearableExtender setContentIcon(int icon) { |
| 8480 | mContentIcon = icon; |
| 8481 | return this; |
| 8482 | } |
| 8483 | |
| 8484 | /** |
| 8485 | * Get an icon that goes with the content of this notification. |
| 8486 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8487 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8488 | public int getContentIcon() { |
| 8489 | return mContentIcon; |
| 8490 | } |
| 8491 | |
| 8492 | /** |
| 8493 | * Set the gravity that the content icon should have within the notification display. |
| 8494 | * Supported values include {@link android.view.Gravity#START} and |
| 8495 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 8496 | * @see #setContentIcon |
| 8497 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8498 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8499 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 8500 | mContentIconGravity = contentIconGravity; |
| 8501 | return this; |
| 8502 | } |
| 8503 | |
| 8504 | /** |
| 8505 | * Get the gravity that the content icon should have within the notification display. |
| 8506 | * Supported values include {@link android.view.Gravity#START} and |
| 8507 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 8508 | * @see #getContentIcon |
| 8509 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8510 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8511 | public int getContentIconGravity() { |
| 8512 | return mContentIconGravity; |
| 8513 | } |
| 8514 | |
| 8515 | /** |
| 8516 | * 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] | 8517 | * this notification. This action will no longer display separately from the |
| 8518 | * notification's content. |
| 8519 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 8520 | * <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] | 8521 | * set, although the list of available actions comes from the main notification and not |
| 8522 | * from the child page's notification. |
| 8523 | * |
| 8524 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 8525 | * If wearable actions were added to the main notification, this index |
| 8526 | * will apply to that list, otherwise it will apply to the regular |
| 8527 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8528 | */ |
| 8529 | public WearableExtender setContentAction(int actionIndex) { |
| 8530 | mContentActionIndex = actionIndex; |
| 8531 | return this; |
| 8532 | } |
| 8533 | |
| 8534 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 8535 | * Get the index of the notification action, if any, that was specified as being clickable |
| 8536 | * 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] | 8537 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8538 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 8539 | * <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] | 8540 | * set, although the list of available actions comes from the main notification and not |
| 8541 | * from the child page's notification. |
| 8542 | * |
| 8543 | * <p>If wearable specific actions were added to the main notification, this index will |
| 8544 | * 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] | 8545 | * |
| 8546 | * @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] | 8547 | */ |
| 8548 | public int getContentAction() { |
| 8549 | return mContentActionIndex; |
| 8550 | } |
| 8551 | |
| 8552 | /** |
| 8553 | * Set the gravity that this notification should have within the available viewport space. |
| 8554 | * Supported values include {@link android.view.Gravity#TOP}, |
| 8555 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 8556 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 8557 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8558 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8559 | public WearableExtender setGravity(int gravity) { |
| 8560 | mGravity = gravity; |
| 8561 | return this; |
| 8562 | } |
| 8563 | |
| 8564 | /** |
| 8565 | * Get the gravity that this notification should have within the available viewport space. |
| 8566 | * Supported values include {@link android.view.Gravity#TOP}, |
| 8567 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 8568 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 8569 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8570 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8571 | public int getGravity() { |
| 8572 | return mGravity; |
| 8573 | } |
| 8574 | |
| 8575 | /** |
| 8576 | * Set the custom size preset for the display of this notification out of the available |
| 8577 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 8578 | * {@link #SIZE_LARGE}. |
| 8579 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 8580 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 8581 | * documentation for the preset in question. See also |
| 8582 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 8583 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8584 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8585 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 8586 | mCustomSizePreset = sizePreset; |
| 8587 | return this; |
| 8588 | } |
| 8589 | |
| 8590 | /** |
| 8591 | * Get the custom size preset for the display of this notification out of the available |
| 8592 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 8593 | * {@link #SIZE_LARGE}. |
| 8594 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 8595 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 8596 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 8597 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8598 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8599 | public int getCustomSizePreset() { |
| 8600 | return mCustomSizePreset; |
| 8601 | } |
| 8602 | |
| 8603 | /** |
| 8604 | * Set the custom height in pixels for the display of this notification's content. |
| 8605 | * <p>This option is only available for custom display notifications created |
| 8606 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 8607 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 8608 | * {@link #getCustomContentHeight}. |
| 8609 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8610 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8611 | public WearableExtender setCustomContentHeight(int height) { |
| 8612 | mCustomContentHeight = height; |
| 8613 | return this; |
| 8614 | } |
| 8615 | |
| 8616 | /** |
| 8617 | * Get the custom height in pixels for the display of this notification's content. |
| 8618 | * <p>This option is only available for custom display notifications created |
| 8619 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 8620 | * {@link #setCustomContentHeight}. |
| 8621 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8622 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8623 | public int getCustomContentHeight() { |
| 8624 | return mCustomContentHeight; |
| 8625 | } |
| 8626 | |
| 8627 | /** |
| 8628 | * Set whether the scrolling position for the contents of this notification should start |
| 8629 | * at the bottom of the contents instead of the top when the contents are too long to |
| 8630 | * display within the screen. Default is false (start scroll at the top). |
| 8631 | */ |
| 8632 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 8633 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 8634 | return this; |
| 8635 | } |
| 8636 | |
| 8637 | /** |
| 8638 | * Get whether the scrolling position for the contents of this notification should start |
| 8639 | * at the bottom of the contents instead of the top when the contents are too long to |
| 8640 | * display within the screen. Default is false (start scroll at the top). |
| 8641 | */ |
| 8642 | public boolean getStartScrollBottom() { |
| 8643 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 8644 | } |
| 8645 | |
| 8646 | /** |
| 8647 | * Set whether the content intent is available when the wearable device is not connected |
| 8648 | * to a companion device. The user can still trigger this intent when the wearable device |
| 8649 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 8650 | * Defaults to true. |
| 8651 | */ |
| 8652 | public WearableExtender setContentIntentAvailableOffline( |
| 8653 | boolean contentIntentAvailableOffline) { |
| 8654 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 8655 | return this; |
| 8656 | } |
| 8657 | |
| 8658 | /** |
| 8659 | * Get whether the content intent is available when the wearable device is not connected |
| 8660 | * to a companion device. The user can still trigger this intent when the wearable device |
| 8661 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 8662 | * Defaults to true. |
| 8663 | */ |
| 8664 | public boolean getContentIntentAvailableOffline() { |
| 8665 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 8666 | } |
| 8667 | |
| 8668 | /** |
| 8669 | * Set a hint that this notification's icon should not be displayed. |
| 8670 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 8671 | * @return this object for method chaining |
| 8672 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8673 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8674 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 8675 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 8676 | return this; |
| 8677 | } |
| 8678 | |
| 8679 | /** |
| 8680 | * Get a hint that this notification's icon should not be displayed. |
| 8681 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 8682 | * The default value is {@code false} if this was never set. |
| 8683 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8684 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8685 | public boolean getHintHideIcon() { |
| 8686 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 8687 | } |
| 8688 | |
| 8689 | /** |
| 8690 | * Set a visual hint that only the background image of this notification should be |
| 8691 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 8692 | * to sub-pages added using {@link #addPage}. |
| 8693 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8694 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8695 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 8696 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 8697 | return this; |
| 8698 | } |
| 8699 | |
| 8700 | /** |
| 8701 | * Get a visual hint that only the background image of this notification should be |
| 8702 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 8703 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 8704 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8705 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8706 | public boolean getHintShowBackgroundOnly() { |
| 8707 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 8708 | } |
| 8709 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8710 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 8711 | * Set a hint that this notification's background should not be clipped if possible, |
| 8712 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 8713 | * 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] | 8714 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 8715 | * @return this object for method chaining |
| 8716 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8717 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8718 | public WearableExtender setHintAvoidBackgroundClipping( |
| 8719 | boolean hintAvoidBackgroundClipping) { |
| 8720 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 8721 | return this; |
| 8722 | } |
| 8723 | |
| 8724 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 8725 | * Get a hint that this notification's background should not be clipped if possible, |
| 8726 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 8727 | * 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] | 8728 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 8729 | * otherwise. The default value is {@code false} if this was never set. |
| 8730 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8731 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8732 | public boolean getHintAvoidBackgroundClipping() { |
| 8733 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 8734 | } |
| 8735 | |
| 8736 | /** |
| 8737 | * Set a hint that the screen should remain on for at least this duration when |
| 8738 | * this notification is displayed on the screen. |
| 8739 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 8740 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 8741 | * @return this object for method chaining |
| 8742 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8743 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8744 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 8745 | mHintScreenTimeout = timeout; |
| 8746 | return this; |
| 8747 | } |
| 8748 | |
| 8749 | /** |
| 8750 | * Get the duration, in milliseconds, that the screen should remain on for |
| 8751 | * when this notification is displayed. |
| 8752 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 8753 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 8754 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8755 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8756 | public int getHintScreenTimeout() { |
| 8757 | return mHintScreenTimeout; |
| 8758 | } |
| 8759 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8760 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 8761 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 8762 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 8763 | * qr codes, as well as other simple black-and-white tickets. |
| 8764 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 8765 | * @return this object for method chaining |
| 8766 | */ |
| 8767 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 8768 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 8769 | return this; |
| 8770 | } |
| 8771 | |
| 8772 | /** |
| 8773 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 8774 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 8775 | * qr codes, as well as other simple black-and-white tickets. |
| 8776 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 8777 | * otherwise. The default value is {@code false} if this was never set. |
| 8778 | */ |
| 8779 | public boolean getHintAmbientBigPicture() { |
| 8780 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 8781 | } |
| 8782 | |
| 8783 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8784 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 8785 | * directly, telling the platform that it can generate the appropriate transitions. |
| 8786 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 8787 | * an activity and transitions should be generated, false otherwise. |
| 8788 | * @return this object for method chaining |
| 8789 | */ |
| 8790 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 8791 | boolean hintContentIntentLaunchesActivity) { |
| 8792 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 8793 | return this; |
| 8794 | } |
| 8795 | |
| 8796 | /** |
| 8797 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 8798 | * directly, telling the platform that it can generate the appropriate transitions |
| 8799 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 8800 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 8801 | */ |
| 8802 | public boolean getHintContentIntentLaunchesActivity() { |
| 8803 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 8804 | } |
| 8805 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8806 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8807 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 8808 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 8809 | * 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] | 8810 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8811 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8812 | * @param dismissalId the dismissal id of the notification. |
| 8813 | * @return this object for method chaining |
| 8814 | */ |
| 8815 | public WearableExtender setDismissalId(String dismissalId) { |
| 8816 | mDismissalId = dismissalId; |
| 8817 | return this; |
| 8818 | } |
| 8819 | |
| 8820 | /** |
| 8821 | * Returns the dismissal id of the notification. |
| 8822 | * @return the dismissal id of the notification or null if it has not been set. |
| 8823 | */ |
| 8824 | public String getDismissalId() { |
| 8825 | return mDismissalId; |
| 8826 | } |
| 8827 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8828 | /** |
| 8829 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 8830 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 8831 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 8832 | * Features to Notifications</a> for more information. |
| 8833 | * @param bridgeTag the bridge tag of the notification. |
| 8834 | * @return this object for method chaining |
| 8835 | */ |
| 8836 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 8837 | mBridgeTag = bridgeTag; |
| 8838 | return this; |
| 8839 | } |
| 8840 | |
| 8841 | /** |
| 8842 | * Returns the bridge tag of the notification. |
| 8843 | * @return the bridge tag or null if not present. |
| 8844 | */ |
| 8845 | public String getBridgeTag() { |
| 8846 | return mBridgeTag; |
| 8847 | } |
| 8848 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8849 | private void setFlag(int mask, boolean value) { |
| 8850 | if (value) { |
| 8851 | mFlags |= mask; |
| 8852 | } else { |
| 8853 | mFlags &= ~mask; |
| 8854 | } |
| 8855 | } |
| 8856 | } |
| 8857 | |
| 8858 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 8859 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 8860 | * with car extensions: |
| 8861 | * |
| 8862 | * <ol> |
| 8863 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 8864 | * properties. |
| 8865 | * <li>Create a {@link CarExtender}. |
| 8866 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 8867 | * {@link CarExtender}. |
| 8868 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 8869 | * to apply the extensions to a notification. |
| 8870 | * </ol> |
| 8871 | * |
| 8872 | * <pre class="prettyprint"> |
| 8873 | * Notification notification = new Notification.Builder(context) |
| 8874 | * ... |
| 8875 | * .extend(new CarExtender() |
| 8876 | * .set*(...)) |
| 8877 | * .build(); |
| 8878 | * </pre> |
| 8879 | * |
| 8880 | * <p>Car extensions can be accessed on an existing notification by using the |
| 8881 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 8882 | * to access values. |
| 8883 | */ |
| 8884 | public static final class CarExtender implements Extender { |
| 8885 | private static final String TAG = "CarExtender"; |
| 8886 | |
| 8887 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 8888 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 8889 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 8890 | private static final String EXTRA_COLOR = "app_color"; |
| 8891 | |
| 8892 | private Bitmap mLargeIcon; |
| 8893 | private UnreadConversation mUnreadConversation; |
| 8894 | private int mColor = Notification.COLOR_DEFAULT; |
| 8895 | |
| 8896 | /** |
| 8897 | * Create a {@link CarExtender} with default options. |
| 8898 | */ |
| 8899 | public CarExtender() { |
| 8900 | } |
| 8901 | |
| 8902 | /** |
| 8903 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 8904 | * |
| 8905 | * @param notif The notification from which to copy options. |
| 8906 | */ |
| 8907 | public CarExtender(Notification notif) { |
| 8908 | Bundle carBundle = notif.extras == null ? |
| 8909 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 8910 | if (carBundle != null) { |
| 8911 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 8912 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 8913 | |
| 8914 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 8915 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 8916 | } |
| 8917 | } |
| 8918 | |
| 8919 | /** |
| 8920 | * Apply car extensions to a notification that is being built. This is typically called by |
| 8921 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 8922 | * method of {@link Notification.Builder}. |
| 8923 | */ |
| 8924 | @Override |
| 8925 | public Notification.Builder extend(Notification.Builder builder) { |
| 8926 | Bundle carExtensions = new Bundle(); |
| 8927 | |
| 8928 | if (mLargeIcon != null) { |
| 8929 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 8930 | } |
| 8931 | if (mColor != Notification.COLOR_DEFAULT) { |
| 8932 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 8933 | } |
| 8934 | |
| 8935 | if (mUnreadConversation != null) { |
| 8936 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 8937 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 8938 | } |
| 8939 | |
| 8940 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 8941 | return builder; |
| 8942 | } |
| 8943 | |
| 8944 | /** |
| 8945 | * Sets the accent color to use when Android Auto presents the notification. |
| 8946 | * |
| 8947 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 8948 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 8949 | * automotive setting. This method can be used to override the color provided in the |
| 8950 | * notification in such a situation. |
| 8951 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 8952 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 8953 | mColor = color; |
| 8954 | return this; |
| 8955 | } |
| 8956 | |
| 8957 | /** |
| 8958 | * Gets the accent color. |
| 8959 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 8960 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 8961 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 8962 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 8963 | public int getColor() { |
| 8964 | return mColor; |
| 8965 | } |
| 8966 | |
| 8967 | /** |
| 8968 | * Sets the large icon of the car notification. |
| 8969 | * |
| 8970 | * If no large icon is set in the extender, Android Auto will display the icon |
| 8971 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 8972 | * |
| 8973 | * @param largeIcon The large icon to use in the car notification. |
| 8974 | * @return This object for method chaining. |
| 8975 | */ |
| 8976 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 8977 | mLargeIcon = largeIcon; |
| 8978 | return this; |
| 8979 | } |
| 8980 | |
| 8981 | /** |
| 8982 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 8983 | * |
| 8984 | * @return The large icon for the car notification. |
| 8985 | * @see CarExtender#setLargeIcon |
| 8986 | */ |
| 8987 | public Bitmap getLargeIcon() { |
| 8988 | return mLargeIcon; |
| 8989 | } |
| 8990 | |
| 8991 | /** |
| 8992 | * Sets the unread conversation in a message notification. |
| 8993 | * |
| 8994 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 8995 | * @return This object for method chaining. |
| 8996 | */ |
| 8997 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 8998 | mUnreadConversation = unreadConversation; |
| 8999 | return this; |
| 9000 | } |
| 9001 | |
| 9002 | /** |
| 9003 | * Returns the unread conversation conveyed by this notification. |
| 9004 | * @see #setUnreadConversation(UnreadConversation) |
| 9005 | */ |
| 9006 | public UnreadConversation getUnreadConversation() { |
| 9007 | return mUnreadConversation; |
| 9008 | } |
| 9009 | |
| 9010 | /** |
| 9011 | * A class which holds the unread messages from a conversation. |
| 9012 | */ |
| 9013 | public static class UnreadConversation { |
| 9014 | private static final String KEY_AUTHOR = "author"; |
| 9015 | private static final String KEY_TEXT = "text"; |
| 9016 | private static final String KEY_MESSAGES = "messages"; |
| 9017 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 9018 | private static final String KEY_ON_REPLY = "on_reply"; |
| 9019 | private static final String KEY_ON_READ = "on_read"; |
| 9020 | private static final String KEY_PARTICIPANTS = "participants"; |
| 9021 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 9022 | |
| 9023 | private final String[] mMessages; |
| 9024 | private final RemoteInput mRemoteInput; |
| 9025 | private final PendingIntent mReplyPendingIntent; |
| 9026 | private final PendingIntent mReadPendingIntent; |
| 9027 | private final String[] mParticipants; |
| 9028 | private final long mLatestTimestamp; |
| 9029 | |
| 9030 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 9031 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 9032 | String[] participants, long latestTimestamp) { |
| 9033 | mMessages = messages; |
| 9034 | mRemoteInput = remoteInput; |
| 9035 | mReadPendingIntent = readPendingIntent; |
| 9036 | mReplyPendingIntent = replyPendingIntent; |
| 9037 | mParticipants = participants; |
| 9038 | mLatestTimestamp = latestTimestamp; |
| 9039 | } |
| 9040 | |
| 9041 | /** |
| 9042 | * Gets the list of messages conveyed by this notification. |
| 9043 | */ |
| 9044 | public String[] getMessages() { |
| 9045 | return mMessages; |
| 9046 | } |
| 9047 | |
| 9048 | /** |
| 9049 | * Gets the remote input that will be used to convey the response to a message list, or |
| 9050 | * null if no such remote input exists. |
| 9051 | */ |
| 9052 | public RemoteInput getRemoteInput() { |
| 9053 | return mRemoteInput; |
| 9054 | } |
| 9055 | |
| 9056 | /** |
| 9057 | * Gets the pending intent that will be triggered when the user replies to this |
| 9058 | * notification. |
| 9059 | */ |
| 9060 | public PendingIntent getReplyPendingIntent() { |
| 9061 | return mReplyPendingIntent; |
| 9062 | } |
| 9063 | |
| 9064 | /** |
| 9065 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 9066 | * in this object's message list. |
| 9067 | */ |
| 9068 | public PendingIntent getReadPendingIntent() { |
| 9069 | return mReadPendingIntent; |
| 9070 | } |
| 9071 | |
| 9072 | /** |
| 9073 | * Gets the participants in the conversation. |
| 9074 | */ |
| 9075 | public String[] getParticipants() { |
| 9076 | return mParticipants; |
| 9077 | } |
| 9078 | |
| 9079 | /** |
| 9080 | * Gets the firs participant in the conversation. |
| 9081 | */ |
| 9082 | public String getParticipant() { |
| 9083 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 9084 | } |
| 9085 | |
| 9086 | /** |
| 9087 | * Gets the timestamp of the conversation. |
| 9088 | */ |
| 9089 | public long getLatestTimestamp() { |
| 9090 | return mLatestTimestamp; |
| 9091 | } |
| 9092 | |
| 9093 | Bundle getBundleForUnreadConversation() { |
| 9094 | Bundle b = new Bundle(); |
| 9095 | String author = null; |
| 9096 | if (mParticipants != null && mParticipants.length > 1) { |
| 9097 | author = mParticipants[0]; |
| 9098 | } |
| 9099 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 9100 | for (int i = 0; i < messages.length; i++) { |
| 9101 | Bundle m = new Bundle(); |
| 9102 | m.putString(KEY_TEXT, mMessages[i]); |
| 9103 | m.putString(KEY_AUTHOR, author); |
| 9104 | messages[i] = m; |
| 9105 | } |
| 9106 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 9107 | if (mRemoteInput != null) { |
| 9108 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 9109 | } |
| 9110 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 9111 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 9112 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 9113 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 9114 | return b; |
| 9115 | } |
| 9116 | |
| 9117 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 9118 | if (b == null) { |
| 9119 | return null; |
| 9120 | } |
| 9121 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 9122 | String[] messages = null; |
| 9123 | if (parcelableMessages != null) { |
| 9124 | String[] tmp = new String[parcelableMessages.length]; |
| 9125 | boolean success = true; |
| 9126 | for (int i = 0; i < tmp.length; i++) { |
| 9127 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 9128 | success = false; |
| 9129 | break; |
| 9130 | } |
| 9131 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 9132 | if (tmp[i] == null) { |
| 9133 | success = false; |
| 9134 | break; |
| 9135 | } |
| 9136 | } |
| 9137 | if (success) { |
| 9138 | messages = tmp; |
| 9139 | } else { |
| 9140 | return null; |
| 9141 | } |
| 9142 | } |
| 9143 | |
| 9144 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 9145 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 9146 | |
| 9147 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 9148 | |
| 9149 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 9150 | if (participants == null || participants.length != 1) { |
| 9151 | return null; |
| 9152 | } |
| 9153 | |
| 9154 | return new UnreadConversation(messages, |
| 9155 | remoteInput, |
| 9156 | onReply, |
| 9157 | onRead, |
| 9158 | participants, b.getLong(KEY_TIMESTAMP)); |
| 9159 | } |
| 9160 | }; |
| 9161 | |
| 9162 | /** |
| 9163 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 9164 | */ |
| 9165 | public static class Builder { |
| 9166 | private final List<String> mMessages = new ArrayList<String>(); |
| 9167 | private final String mParticipant; |
| 9168 | private RemoteInput mRemoteInput; |
| 9169 | private PendingIntent mReadPendingIntent; |
| 9170 | private PendingIntent mReplyPendingIntent; |
| 9171 | private long mLatestTimestamp; |
| 9172 | |
| 9173 | /** |
| 9174 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 9175 | * |
| 9176 | * @param name The name of the other participant in the conversation. |
| 9177 | */ |
| 9178 | public Builder(String name) { |
| 9179 | mParticipant = name; |
| 9180 | } |
| 9181 | |
| 9182 | /** |
| 9183 | * Appends a new unread message to the list of messages for this conversation. |
| 9184 | * |
| 9185 | * The messages should be added from oldest to newest. |
| 9186 | * |
| 9187 | * @param message The text of the new unread message. |
| 9188 | * @return This object for method chaining. |
| 9189 | */ |
| 9190 | public Builder addMessage(String message) { |
| 9191 | mMessages.add(message); |
| 9192 | return this; |
| 9193 | } |
| 9194 | |
| 9195 | /** |
| 9196 | * Sets the pending intent and remote input which will convey the reply to this |
| 9197 | * notification. |
| 9198 | * |
| 9199 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 9200 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 9201 | * @return This object for method chaining. |
| 9202 | * |
| 9203 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 9204 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 9205 | */ |
| 9206 | public Builder setReplyAction( |
| 9207 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 9208 | mRemoteInput = remoteInput; |
| 9209 | mReplyPendingIntent = pendingIntent; |
| 9210 | |
| 9211 | return this; |
| 9212 | } |
| 9213 | |
| 9214 | /** |
| 9215 | * Sets the pending intent that will be sent once the messages in this notification |
| 9216 | * are read. |
| 9217 | * |
| 9218 | * @param pendingIntent The pending intent to use. |
| 9219 | * @return This object for method chaining. |
| 9220 | */ |
| 9221 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 9222 | mReadPendingIntent = pendingIntent; |
| 9223 | return this; |
| 9224 | } |
| 9225 | |
| 9226 | /** |
| 9227 | * Sets the timestamp of the most recent message in an unread conversation. |
| 9228 | * |
| 9229 | * If a messaging notification has been posted by your application and has not |
| 9230 | * yet been cancelled, posting a later notification with the same id and tag |
| 9231 | * but without a newer timestamp may result in Android Auto not displaying a |
| 9232 | * heads up notification for the later notification. |
| 9233 | * |
| 9234 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 9235 | * @return This object for method chaining. |
| 9236 | */ |
| 9237 | public Builder setLatestTimestamp(long timestamp) { |
| 9238 | mLatestTimestamp = timestamp; |
| 9239 | return this; |
| 9240 | } |
| 9241 | |
| 9242 | /** |
| 9243 | * Builds a new unread conversation object. |
| 9244 | * |
| 9245 | * @return The new unread conversation object. |
| 9246 | */ |
| 9247 | public UnreadConversation build() { |
| 9248 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 9249 | String[] participants = { mParticipant }; |
| 9250 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 9251 | mReadPendingIntent, participants, mLatestTimestamp); |
| 9252 | } |
| 9253 | } |
| 9254 | } |
| 9255 | |
| 9256 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9257 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 9258 | * with a TV extension: |
| 9259 | * |
| 9260 | * <ol> |
| 9261 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 9262 | * <li>Create a {@link TvExtender}. |
| 9263 | * <li>Set TV-specific properties using the {@code set} methods of |
| 9264 | * {@link TvExtender}. |
| 9265 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 9266 | * to apply the extension to a notification. |
| 9267 | * </ol> |
| 9268 | * |
| 9269 | * <pre class="prettyprint"> |
| 9270 | * Notification notification = new Notification.Builder(context) |
| 9271 | * ... |
| 9272 | * .extend(new TvExtender() |
| 9273 | * .set*(...)) |
| 9274 | * .build(); |
| 9275 | * </pre> |
| 9276 | * |
| 9277 | * <p>TV extensions can be accessed on an existing notification by using the |
| 9278 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 9279 | * to access values. |
| 9280 | * |
| 9281 | * @hide |
| 9282 | */ |
| 9283 | @SystemApi |
| 9284 | public static final class TvExtender implements Extender { |
| 9285 | private static final String TAG = "TvExtender"; |
| 9286 | |
| 9287 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 9288 | private static final String EXTRA_FLAGS = "flags"; |
| 9289 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 9290 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9291 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9292 | private static final String EXTRA_SUPPRESS_SHOW_OVER_APPS = "suppressShowOverApps"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9293 | |
| 9294 | // Flags bitwise-ored to mFlags |
| 9295 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 9296 | |
| 9297 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9298 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9299 | private PendingIntent mContentIntent; |
| 9300 | private PendingIntent mDeleteIntent; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9301 | private boolean mSuppressShowOverApps; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9302 | |
| 9303 | /** |
| 9304 | * Create a {@link TvExtender} with default options. |
| 9305 | */ |
| 9306 | public TvExtender() { |
| 9307 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 9308 | } |
| 9309 | |
| 9310 | /** |
| 9311 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 9312 | * |
| 9313 | * @param notif The notification from which to copy options. |
| 9314 | */ |
| 9315 | public TvExtender(Notification notif) { |
| 9316 | Bundle bundle = notif.extras == null ? |
| 9317 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 9318 | if (bundle != null) { |
| 9319 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9320 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9321 | mSuppressShowOverApps = bundle.getBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9322 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 9323 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 9324 | } |
| 9325 | } |
| 9326 | |
| 9327 | /** |
| 9328 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 9329 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 9330 | * method of {@link Notification.Builder}. |
| 9331 | */ |
| 9332 | @Override |
| 9333 | public Notification.Builder extend(Notification.Builder builder) { |
| 9334 | Bundle bundle = new Bundle(); |
| 9335 | |
| 9336 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9337 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9338 | bundle.putBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS, mSuppressShowOverApps); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9339 | if (mContentIntent != null) { |
| 9340 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 9341 | } |
| 9342 | |
| 9343 | if (mDeleteIntent != null) { |
| 9344 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 9345 | } |
| 9346 | |
| 9347 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 9348 | return builder; |
| 9349 | } |
| 9350 | |
| 9351 | /** |
| 9352 | * Returns true if this notification should be shown on TV. This method return true |
| 9353 | * if the notification was extended with a TvExtender. |
| 9354 | */ |
| 9355 | public boolean isAvailableOnTv() { |
| 9356 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 9357 | } |
| 9358 | |
| 9359 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9360 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 9361 | * It can be different from the channel that the notification is delivered to when |
| 9362 | * posting on a non-TV device. |
| 9363 | */ |
| 9364 | public TvExtender setChannel(String channelId) { |
| 9365 | mChannelId = channelId; |
| 9366 | return this; |
| 9367 | } |
| 9368 | |
| 9369 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 9370 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 9371 | * It can be different from the channel that the notification is delivered to when |
| 9372 | * posting on a non-TV device. |
| 9373 | */ |
| 9374 | public TvExtender setChannelId(String channelId) { |
| 9375 | mChannelId = channelId; |
| 9376 | return this; |
| 9377 | } |
| 9378 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 9379 | /** @removed */ |
| 9380 | @Deprecated |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 9381 | public String getChannel() { |
| 9382 | return mChannelId; |
| 9383 | } |
| 9384 | |
| 9385 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 9386 | * Returns the id of the channel this notification posts to on TV. |
| 9387 | */ |
| 9388 | public String getChannelId() { |
| 9389 | return mChannelId; |
| 9390 | } |
| 9391 | |
| 9392 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9393 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 9394 | * If provided, it is used instead of the content intent specified |
| 9395 | * at the level of Notification. |
| 9396 | */ |
| 9397 | public TvExtender setContentIntent(PendingIntent intent) { |
| 9398 | mContentIntent = intent; |
| 9399 | return this; |
| 9400 | } |
| 9401 | |
| 9402 | /** |
| 9403 | * Returns the TV-specific content intent. If this method returns null, the |
| 9404 | * main content intent on the notification should be used. |
| 9405 | * |
| 9406 | * @see {@link Notification#contentIntent} |
| 9407 | */ |
| 9408 | public PendingIntent getContentIntent() { |
| 9409 | return mContentIntent; |
| 9410 | } |
| 9411 | |
| 9412 | /** |
| 9413 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 9414 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 9415 | * at the level of Notification. |
| 9416 | */ |
| 9417 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 9418 | mDeleteIntent = intent; |
| 9419 | return this; |
| 9420 | } |
| 9421 | |
| 9422 | /** |
| 9423 | * Returns the TV-specific delete intent. If this method returns null, the |
| 9424 | * main delete intent on the notification should be used. |
| 9425 | * |
| 9426 | * @see {@link Notification#deleteIntent} |
| 9427 | */ |
| 9428 | public PendingIntent getDeleteIntent() { |
| 9429 | return mDeleteIntent; |
| 9430 | } |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9431 | |
| 9432 | /** |
| 9433 | * Specifies whether this notification should suppress showing a message over top of apps |
| 9434 | * outside of the launcher. |
| 9435 | */ |
| 9436 | public TvExtender setSuppressShowOverApps(boolean suppress) { |
| 9437 | mSuppressShowOverApps = suppress; |
| 9438 | return this; |
| 9439 | } |
| 9440 | |
| 9441 | /** |
| 9442 | * Returns true if this notification should not show messages over top of apps |
| 9443 | * outside of the launcher. |
| 9444 | */ |
| 9445 | public boolean getSuppressShowOverApps() { |
| 9446 | return mSuppressShowOverApps; |
| 9447 | } |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9448 | } |
| 9449 | |
| 9450 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9451 | * Get an array of Notification objects from a parcelable array bundle field. |
| 9452 | * Update the bundle to have a typed array so fetches in the future don't need |
| 9453 | * to do an array copy. |
| 9454 | */ |
| 9455 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 9456 | Parcelable[] array = bundle.getParcelableArray(key); |
| 9457 | if (array instanceof Notification[] || array == null) { |
| 9458 | return (Notification[]) array; |
| 9459 | } |
| 9460 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 9461 | Notification[].class); |
| 9462 | bundle.putParcelableArray(key, typedArray); |
| 9463 | return typedArray; |
| 9464 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 9465 | |
| 9466 | private static class BuilderRemoteViews extends RemoteViews { |
| 9467 | public BuilderRemoteViews(Parcel parcel) { |
| 9468 | super(parcel); |
| 9469 | } |
| 9470 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 9471 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 9472 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 9473 | } |
| 9474 | |
| 9475 | @Override |
| 9476 | public BuilderRemoteViews clone() { |
| 9477 | Parcel p = Parcel.obtain(); |
| 9478 | writeToParcel(p, 0); |
| 9479 | p.setDataPosition(0); |
| 9480 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 9481 | p.recycle(); |
| 9482 | return brv; |
| 9483 | } |
| 9484 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9485 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9486 | /** |
| 9487 | * A result object where information about the template that was created is saved. |
| 9488 | */ |
| 9489 | private static class TemplateBindResult { |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9490 | int mIconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9491 | |
| 9492 | /** |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9493 | * 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] | 9494 | * with the right actions. |
| 9495 | */ |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9496 | public int getIconMarginEnd() { |
| 9497 | return mIconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9498 | } |
| 9499 | |
Selim Cinek | 1c72fa0 | 2018-04-23 18:00:54 +0800 | [diff] [blame] | 9500 | public void setIconMarginEnd(int iconMarginEnd) { |
| 9501 | this.mIconMarginEnd = iconMarginEnd; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9502 | } |
| 9503 | } |
| 9504 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9505 | private static class StandardTemplateParams { |
| 9506 | boolean hasProgress = true; |
| 9507 | boolean ambient = false; |
| 9508 | CharSequence title; |
| 9509 | CharSequence text; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9510 | CharSequence headerTextSecondary; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9511 | boolean hideLargeIcon; |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9512 | boolean hideReplyIcon; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9513 | |
| 9514 | final StandardTemplateParams reset() { |
| 9515 | hasProgress = true; |
| 9516 | ambient = false; |
| 9517 | title = null; |
| 9518 | text = null; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9519 | headerTextSecondary = null; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9520 | return this; |
| 9521 | } |
| 9522 | |
| 9523 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 9524 | this.hasProgress = hasProgress; |
| 9525 | return this; |
| 9526 | } |
| 9527 | |
| 9528 | final StandardTemplateParams title(CharSequence title) { |
| 9529 | this.title = title; |
| 9530 | return this; |
| 9531 | } |
| 9532 | |
| 9533 | final StandardTemplateParams text(CharSequence text) { |
| 9534 | this.text = text; |
| 9535 | return this; |
| 9536 | } |
| 9537 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9538 | final StandardTemplateParams headerTextSecondary(CharSequence text) { |
| 9539 | this.headerTextSecondary = text; |
| 9540 | return this; |
| 9541 | } |
| 9542 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9543 | final StandardTemplateParams hideLargeIcon(boolean hideLargeIcon) { |
| 9544 | this.hideLargeIcon = hideLargeIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9545 | return this; |
| 9546 | } |
| 9547 | |
Selim Cinek | 384804b | 2018-04-18 14:31:07 +0800 | [diff] [blame] | 9548 | final StandardTemplateParams hideReplyIcon(boolean hideReplyIcon) { |
| 9549 | this.hideReplyIcon = hideReplyIcon; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9550 | return this; |
| 9551 | } |
| 9552 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9553 | final StandardTemplateParams ambient(boolean ambient) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 9554 | Preconditions.checkState(title == null && text == null, "must set ambient before text"); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9555 | this.ambient = ambient; |
| 9556 | return this; |
| 9557 | } |
| 9558 | |
| 9559 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 9560 | Bundle extras = b.mN.extras; |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 9561 | this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE), ambient); |
| 9562 | |
| 9563 | // Big text notifications should contain their content when viewed in ambient mode. |
| 9564 | CharSequence text = extras.getCharSequence(EXTRA_BIG_TEXT); |
| 9565 | if (!ambient || TextUtils.isEmpty(text)) { |
| 9566 | text = extras.getCharSequence(EXTRA_TEXT); |
| 9567 | } |
| 9568 | this.text = b.processLegacyText(text, ambient); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9569 | return this; |
| 9570 | } |
| 9571 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9572 | } |