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; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 92 | import java.util.Set; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 93 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | /** |
| 95 | * A class that represents how a persistent notification is to be presented to |
| 96 | * the user using the {@link android.app.NotificationManager}. |
| 97 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 98 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 99 | * easier to construct Notifications.</p> |
| 100 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 101 | * <div class="special reference"> |
| 102 | * <h3>Developer Guides</h3> |
| 103 | * <p>For a guide to creating notifications, read the |
| 104 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 105 | * developer guide.</p> |
| 106 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | */ |
| 108 | public class Notification implements Parcelable |
| 109 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 110 | private static final String TAG = "Notification"; |
| 111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 113 | * 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] | 114 | * containing application. |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 115 | */ |
| 116 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 117 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 118 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 119 | |
| 120 | /** |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 121 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 122 | * 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] | 123 | * what settings should be shown in the target app. |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 124 | */ |
| 125 | public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 126 | |
| 127 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 128 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 005c8b9 | 2017-08-24 10:35:53 -0400 | [diff] [blame] | 129 | * contain a {@link NotificationChannelGroup#getId() group id} that can be used to narrow down |
| 130 | * what settings should be shown in the target app. |
| 131 | */ |
| 132 | public static final String EXTRA_CHANNEL_GROUP_ID = "android.intent.extra.CHANNEL_GROUP_ID"; |
| 133 | |
| 134 | /** |
| 135 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 136 | * contain the tag provided to {@link NotificationManager#notify(String, int, Notification)} |
| 137 | * that can be used to narrow down what settings should be shown in the target app. |
| 138 | */ |
| 139 | public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 140 | |
| 141 | /** |
| 142 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 143 | * contain the id provided to {@link NotificationManager#notify(String, int, Notification)} |
| 144 | * that can be used to narrow down what settings should be shown in the target app. |
| 145 | */ |
| 146 | public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 147 | |
| 148 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | * Use all default values (where applicable). |
| 150 | */ |
| 151 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | /** |
| 154 | * Use the default notification sound. This will ignore any given |
| 155 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 156 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 157 | * <p> |
| 158 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 159 | * </p> |
| 160 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 162 | */ |
| 163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | public static final int DEFAULT_SOUND = 1; |
| 165 | |
| 166 | /** |
| 167 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 168 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 169 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 170 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 171 | * <p> |
| 172 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 173 | * </p> |
| 174 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 176 | */ |
| 177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | /** |
| 181 | * Use the default notification lights. This will ignore the |
| 182 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 183 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 184 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 186 | */ |
| 187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 189 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 191 | * Maximum length of CharSequences accepted by Builder and friends. |
| 192 | * |
| 193 | * <p> |
| 194 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 195 | */ |
| 196 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 197 | |
| 198 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 199 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 200 | */ |
| 201 | private static final int MAX_REPLY_HISTORY = 5; |
| 202 | |
Selim Cinek | de4de0e | 2018-01-24 16:21:07 -0800 | [diff] [blame] | 203 | |
| 204 | /** |
| 205 | * If the notification contained an unsent draft for a RemoteInput when the user clicked on it, |
| 206 | * we're adding the draft as a String extra to the {@link #contentIntent} using this key. |
| 207 | * |
| 208 | * <p>Apps may use this extra to prepopulate text fields in the app, where the user usually |
| 209 | * sends messages.</p> |
| 210 | */ |
| 211 | public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; |
| 212 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 213 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 214 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 215 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 216 | * Default value: {@link System#currentTimeMillis() Now}. |
| 217 | * |
| 218 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 219 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 220 | * 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] | 221 | * timestamped according to when the activity began. |
| 222 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 223 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 224 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 225 | * <ul> |
| 226 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 227 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 228 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 229 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 230 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 231 | * <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] | 232 | * </ul> |
| 233 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 234 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 235 | * anymore by default and must be opted into by using |
| 236 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | */ |
| 238 | public long when; |
| 239 | |
| 240 | /** |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 241 | * The creation time of the notification |
| 242 | */ |
| 243 | private long creationTime; |
| 244 | |
| 245 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | * 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] | 247 | * |
| 248 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 250 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 251 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | public int icon; |
| 253 | |
| 254 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 255 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 256 | * leave it at its default value of 0. |
| 257 | * |
| 258 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 259 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 260 | */ |
| 261 | public int iconLevel; |
| 262 | |
| 263 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 264 | * The number of events that this notification represents. For example, in a new mail |
| 265 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 266 | * |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 267 | * 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] | 268 | * Starting with {@link android.os.Build.VERSION_CODES#O}, the number may be displayed as a |
| 269 | * badge icon in Launchers that support badging. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | */ |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 271 | public int number = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * The intent to execute when the expanded status entry is clicked. If |
| 275 | * this is an activity, it must include the |
| 276 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 277 | * that you take care of task management as described in the |
| 278 | * <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] | 279 | * Stack</a> document. In particular, make sure to read the notification section |
| 280 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 281 | * Notifications</a> for the correct ways to launch an application from a |
| 282 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | */ |
| 284 | public PendingIntent contentIntent; |
| 285 | |
| 286 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 287 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 288 | * the "Clear All" button or by swiping it away individually. |
| 289 | * |
| 290 | * This probably shouldn't be launching an activity since several of those will be sent |
| 291 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | */ |
| 293 | public PendingIntent deleteIntent; |
| 294 | |
| 295 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 296 | * 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] | 297 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 298 | * <p> |
| 299 | * The system UI may choose to display a heads-up notification, instead of |
| 300 | * launching this intent, while the user is using the device. |
| 301 | * </p> |
| 302 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 303 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 304 | */ |
| 305 | public PendingIntent fullScreenIntent; |
| 306 | |
| 307 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 308 | * Text that summarizes this notification for accessibility services. |
| 309 | * |
| 310 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 311 | * accessibility services (where it serves as an audible announcement of the notification's |
| 312 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 313 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 314 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | */ |
| 316 | public CharSequence tickerText; |
| 317 | |
| 318 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 319 | * Formerly, a view showing the {@link #tickerText}. |
| 320 | * |
| 321 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 322 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 323 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 324 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 325 | |
| 326 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 327 | * The view that will represent this notification in the notification list (which is pulled |
| 328 | * down from the status bar). |
| 329 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 330 | * As of N, this field may be null. The notification view is determined by the inputs |
| 331 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 332 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 334 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | public RemoteViews contentView; |
| 336 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 337 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 338 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 339 | * opportunity to show more detail. The system UI may choose to show this |
| 340 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 341 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 342 | * 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] | 343 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 344 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 345 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 346 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 347 | public RemoteViews bigContentView; |
| 348 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 349 | |
| 350 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 351 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 352 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 353 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 354 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 355 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 356 | * 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] | 357 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 358 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 359 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 360 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 361 | public RemoteViews headsUpContentView; |
| 362 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 363 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 364 | * A large bitmap to be shown in the notification content area. |
| 365 | * |
| 366 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 368 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 369 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | |
| 371 | /** |
| 372 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 373 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 375 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 376 | * </p> |
| 377 | * |
| 378 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 379 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 381 | * @deprecated use {@link NotificationChannel#getSound()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 383 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | public Uri sound; |
| 385 | |
| 386 | /** |
| 387 | * Use this constant as the value for audioStreamType to request that |
| 388 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 389 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 390 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 391 | * @deprecated Use {@link NotificationChannel#getAudioAttributes()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 393 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | public static final int STREAM_DEFAULT = -1; |
| 395 | |
| 396 | /** |
| 397 | * The audio stream type to use when playing the sound. |
| 398 | * Should be one of the STREAM_ constants from |
| 399 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 400 | * |
| 401 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 403 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | public int audioStreamType = STREAM_DEFAULT; |
| 405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 407 | * The default value of {@link #audioAttributes}. |
| 408 | */ |
| 409 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 410 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 411 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 412 | .build(); |
| 413 | |
| 414 | /** |
| 415 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 416 | * |
| 417 | * @deprecated use {@link NotificationChannel#getAudioAttributes()} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 418 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 419 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 420 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 421 | |
| 422 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 423 | * The pattern with which to vibrate. |
| 424 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | * <p> |
| 426 | * To vibrate the default pattern, see {@link #defaults}. |
| 427 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 428 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | * @see android.os.Vibrator#vibrate(long[],int) |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 430 | * @deprecated use {@link NotificationChannel#getVibrationPattern()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 432 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | public long[] vibrate; |
| 434 | |
| 435 | /** |
| 436 | * The color of the led. The hardware will do its best approximation. |
| 437 | * |
| 438 | * @see #FLAG_SHOW_LIGHTS |
| 439 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 440 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 442 | @ColorInt |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 443 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | public int ledARGB; |
| 445 | |
| 446 | /** |
| 447 | * The number of milliseconds for the LED to be on while it's flashing. |
| 448 | * The hardware will do its best approximation. |
| 449 | * |
| 450 | * @see #FLAG_SHOW_LIGHTS |
| 451 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 452 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 454 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | public int ledOnMS; |
| 456 | |
| 457 | /** |
| 458 | * The number of milliseconds for the LED to be off while it's flashing. |
| 459 | * The hardware will do its best approximation. |
| 460 | * |
| 461 | * @see #FLAG_SHOW_LIGHTS |
| 462 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 463 | * |
| 464 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 466 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | public int ledOffMS; |
| 468 | |
| 469 | /** |
| 470 | * Specifies which values should be taken from the defaults. |
| 471 | * <p> |
| 472 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 473 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 474 | * values, use {@link #DEFAULT_ALL}. |
| 475 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 476 | * |
| 477 | * @deprecated use {@link NotificationChannel#getSound()} and |
| 478 | * {@link NotificationChannel#shouldShowLights()} and |
| 479 | * {@link NotificationChannel#shouldVibrate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 481 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | public int defaults; |
| 483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | /** |
| 485 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 486 | * set if you want the LED on for this notification. |
| 487 | * <ul> |
| 488 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 489 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 490 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 491 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 492 | * be on and off to ledOnMS and ledOffMS.</li> |
| 493 | * </ul> |
| 494 | * <p> |
| 495 | * 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] | 496 | * 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] | 497 | * because they will be set to values that work on any given hardware. |
| 498 | * <p> |
| 499 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 500 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 501 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 503 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 505 | |
| 506 | /** |
| 507 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 508 | * set if this notification is in reference to something that is ongoing, |
| 509 | * like a phone call. It should not be set if this notification is in |
| 510 | * reference to something that happened at a particular point in time, |
| 511 | * like a missed phone call. |
| 512 | */ |
| 513 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 514 | |
| 515 | /** |
| 516 | * 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] | 517 | * the audio will be repeated until the notification is |
| 518 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | */ |
| 520 | public static final int FLAG_INSISTENT = 0x00000004; |
| 521 | |
| 522 | /** |
| 523 | * 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] | 524 | * set if you would only like the sound, vibrate and ticker to be played |
| 525 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | */ |
| 527 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 528 | |
| 529 | /** |
| 530 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 531 | * 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] | 532 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | */ |
| 534 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 535 | |
| 536 | /** |
| 537 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 538 | * set if the notification should not be canceled when the user clicks |
| 539 | * the Clear all button. |
| 540 | */ |
| 541 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 542 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 543 | /** |
| 544 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 545 | * set if this notification represents a currently running service. This |
| 546 | * will normally be set for you by {@link Service#startForeground}. |
| 547 | */ |
| 548 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 549 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 550 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 551 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 552 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 553 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 554 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 555 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 556 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 557 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 558 | /** |
| 559 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 560 | * set if this notification is relevant to the current device only |
| 561 | * and it is not recommended that it bridge to other devices. |
| 562 | */ |
| 563 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 564 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 565 | /** |
| 566 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 567 | * set if this notification is the group summary for a group of notifications. |
| 568 | * Grouped notifications may display in a cluster or stack on devices which |
| 569 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 570 | */ |
| 571 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 572 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 573 | /** |
| 574 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 575 | * set if this notification is the group summary for an auto-group of notifications. |
| 576 | * |
| 577 | * @hide |
| 578 | */ |
| 579 | @SystemApi |
| 580 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 581 | |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 582 | /** |
| 583 | * @hide |
| 584 | */ |
| 585 | public static final int FLAG_CAN_COLORIZE = 0x00000800; |
| 586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | public int flags; |
| 588 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 589 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 590 | @IntDef(prefix = { "PRIORITY_" }, value = { |
| 591 | PRIORITY_DEFAULT, |
| 592 | PRIORITY_LOW, |
| 593 | PRIORITY_MIN, |
| 594 | PRIORITY_HIGH, |
| 595 | PRIORITY_MAX |
| 596 | }) |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 597 | @Retention(RetentionPolicy.SOURCE) |
| 598 | public @interface Priority {} |
| 599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 601 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 602 | * notifications, use this value for all notifications. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 603 | * |
| 604 | * @deprecated use {@link NotificationManager#IMPORTANCE_DEFAULT} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 605 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 606 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 607 | public static final int PRIORITY_DEFAULT = 0; |
| 608 | |
| 609 | /** |
| 610 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 611 | * items smaller, or at a different position in the list, compared with your app's |
| 612 | * {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 613 | * |
| 614 | * @deprecated use {@link NotificationManager#IMPORTANCE_LOW} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 615 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 616 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 617 | public static final int PRIORITY_LOW = -1; |
| 618 | |
| 619 | /** |
| 620 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 621 | * circumstances, such as detailed notification logs. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 622 | * |
| 623 | * @deprecated use {@link NotificationManager#IMPORTANCE_MIN} 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_MIN = -2; |
| 627 | |
| 628 | /** |
| 629 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 630 | * show these items larger, or at a different position in notification lists, compared with |
| 631 | * your app's {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 632 | * |
| 633 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} 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_HIGH = 1; |
| 637 | |
| 638 | /** |
| 639 | * Highest {@link #priority}, for your application's most important items that require the |
| 640 | * user's prompt attention or input. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 641 | * |
| 642 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} 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_MAX = 2; |
| 646 | |
| 647 | /** |
| 648 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 649 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 650 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 651 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 652 | * 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] | 653 | * system will make a determination about how to interpret this priority when presenting |
| 654 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 655 | * |
| 656 | * <p> |
| 657 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 658 | * as a heads-up notification. |
| 659 | * </p> |
| 660 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 661 | * @deprecated use {@link NotificationChannel#getImportance()} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 662 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 663 | @Priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 664 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 665 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 666 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 667 | /** |
| 668 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 669 | * to be applied by the standard Style templates when presenting this notification. |
| 670 | * |
| 671 | * The current template design constructs a colorful header image by overlaying the |
| 672 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 673 | * ignored. |
| 674 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 675 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 676 | public int color = COLOR_DEFAULT; |
| 677 | |
| 678 | /** |
| 679 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 680 | * any special color but instead use default colors when presenting this notification. |
| 681 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 682 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 683 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 684 | |
| 685 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 686 | * 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] | 687 | * @hide |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 688 | */ |
| 689 | @ColorInt |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 690 | public static final int COLOR_INVALID = 1; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 691 | |
| 692 | /** |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 693 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 694 | * 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] | 695 | * lockscreen). |
| 696 | * |
| 697 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 698 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 699 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 700 | * the appropriate user. |
| 701 | * |
| 702 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 703 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 704 | * To modify the public version of this notification—for example, to redact some portions—see |
| 705 | * {@link Builder#setPublicVersion(Notification)}. |
| 706 | * |
| 707 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 708 | * and ticker until the user has bypassed the lockscreen. |
| 709 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 710 | public @Visibility int visibility; |
| 711 | |
| 712 | /** @hide */ |
| 713 | @IntDef(prefix = { "VISIBILITY_" }, value = { |
| 714 | VISIBILITY_PUBLIC, |
| 715 | VISIBILITY_PRIVATE, |
| 716 | VISIBILITY_SECRET, |
| 717 | }) |
| 718 | @Retention(RetentionPolicy.SOURCE) |
| 719 | public @interface Visibility {} |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 720 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 721 | /** |
| 722 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 723 | * |
| 724 | * {@see #visibility} |
| 725 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 726 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 727 | |
| 728 | /** |
| 729 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 730 | * private information on secure lockscreens. |
| 731 | * |
| 732 | * {@see #visibility} |
| 733 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 734 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 735 | |
| 736 | /** |
| 737 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 738 | * |
| 739 | * {@see #visibility} |
| 740 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 741 | public static final int VISIBILITY_SECRET = -1; |
| 742 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 743 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 744 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 745 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 746 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 747 | |
| 748 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 749 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 750 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 751 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 752 | |
| 753 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 754 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 755 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 756 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 757 | |
| 758 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 759 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 760 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 761 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 762 | |
| 763 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 764 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 765 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 766 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 767 | |
| 768 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 769 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 770 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 771 | public static final String CATEGORY_ALARM = "alarm"; |
| 772 | |
| 773 | /** |
| 774 | * Notification category: progress of a long-running background operation. |
| 775 | */ |
| 776 | public static final String CATEGORY_PROGRESS = "progress"; |
| 777 | |
| 778 | /** |
| 779 | * Notification category: social network or sharing update. |
| 780 | */ |
| 781 | public static final String CATEGORY_SOCIAL = "social"; |
| 782 | |
| 783 | /** |
| 784 | * Notification category: error in background operation or authentication status. |
| 785 | */ |
| 786 | public static final String CATEGORY_ERROR = "err"; |
| 787 | |
| 788 | /** |
| 789 | * Notification category: media transport control for playback. |
| 790 | */ |
| 791 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 792 | |
| 793 | /** |
| 794 | * Notification category: system or device status update. Reserved for system use. |
| 795 | */ |
| 796 | public static final String CATEGORY_SYSTEM = "sys"; |
| 797 | |
| 798 | /** |
| 799 | * Notification category: indication of running background service. |
| 800 | */ |
| 801 | public static final String CATEGORY_SERVICE = "service"; |
| 802 | |
| 803 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 804 | * Notification category: a specific, timely recommendation for a single thing. |
| 805 | * For example, a news app might want to recommend a news story it believes the user will |
| 806 | * want to read next. |
| 807 | */ |
| 808 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 809 | |
| 810 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 811 | * Notification category: ongoing information about device or contextual status. |
| 812 | */ |
| 813 | public static final String CATEGORY_STATUS = "status"; |
| 814 | |
| 815 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 816 | * Notification category: user-scheduled reminder. |
| 817 | */ |
| 818 | public static final String CATEGORY_REMINDER = "reminder"; |
| 819 | |
| 820 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 821 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 822 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 823 | */ |
| 824 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 825 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 826 | private String mGroupKey; |
| 827 | |
| 828 | /** |
| 829 | * Get the key used to group this notification into a cluster or stack |
| 830 | * with other notifications on devices which support such rendering. |
| 831 | */ |
| 832 | public String getGroup() { |
| 833 | return mGroupKey; |
| 834 | } |
| 835 | |
| 836 | private String mSortKey; |
| 837 | |
| 838 | /** |
| 839 | * Get a sort key that orders this notification among other notifications from the |
| 840 | * same package. This can be useful if an external sort was already applied and an app |
| 841 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 842 | * value, although providing different priorities in addition to providing sort key may |
| 843 | * cause this value to be ignored. |
| 844 | * |
| 845 | * <p>This sort key can also be used to order members of a notification group. See |
| 846 | * {@link Builder#setGroup}. |
| 847 | * |
| 848 | * @see String#compareTo(String) |
| 849 | */ |
| 850 | public String getSortKey() { |
| 851 | return mSortKey; |
| 852 | } |
| 853 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 854 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 855 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 856 | * <p> |
| 857 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 858 | * APIs, and are intended to be used by |
| 859 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 860 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 861 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 862 | public Bundle extras = new Bundle(); |
| 863 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 864 | /** |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 865 | * All pending intents in the notification as the system needs to be able to access them but |
| 866 | * 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] | 867 | * custom parcelable objects. |
| 868 | * |
| 869 | * @hide |
| 870 | */ |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 871 | public ArraySet<PendingIntent> allPendingIntents; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 872 | |
| 873 | /** |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 874 | * Token identifying the notification that is applying doze/bgcheck whitelisting to the |
| 875 | * pending intents inside of it, so only those will get the behavior. |
| 876 | * |
| 877 | * @hide |
| 878 | */ |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 879 | private IBinder mWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 880 | |
| 881 | /** |
| 882 | * Must be set by a process to start associating tokens with Notification objects |
| 883 | * coming in to it. This is set by NotificationManagerService. |
| 884 | * |
| 885 | * @hide |
| 886 | */ |
| 887 | static public IBinder processWhitelistToken; |
| 888 | |
| 889 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 890 | * {@link #extras} key: this is the title of the notification, |
| 891 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 892 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 893 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 894 | |
| 895 | /** |
| 896 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 897 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 898 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 899 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 900 | |
| 901 | /** |
| 902 | * {@link #extras} key: this is the main text payload, as supplied to |
| 903 | * {@link Builder#setContentText(CharSequence)}. |
| 904 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 905 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 906 | |
| 907 | /** |
| 908 | * {@link #extras} key: this is a third line of text, as supplied to |
| 909 | * {@link Builder#setSubText(CharSequence)}. |
| 910 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 911 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 912 | |
| 913 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 914 | * {@link #extras} key: this is the remote input history, as supplied to |
| 915 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
Adrian Roos | 005e774 | 2016-04-13 15:02:20 -0700 | [diff] [blame] | 916 | * |
| 917 | * Apps can fill this through {@link Builder#setRemoteInputHistory(CharSequence[])} |
| 918 | * with the most recent inputs that have been sent through a {@link RemoteInput} of this |
| 919 | * Notification and are expected to clear it once the it is no longer relevant (e.g. for chat |
| 920 | * notifications once the other party has responded). |
| 921 | * |
| 922 | * The extra with this key is of type CharSequence[] and contains the most recent entry at |
| 923 | * the 0 index, the second most recent at the 1 index, etc. |
| 924 | * |
| 925 | * @see Builder#setRemoteInputHistory(CharSequence[]) |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 926 | */ |
| 927 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 928 | |
| 929 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 930 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 931 | * {@link Builder#setContentInfo(CharSequence)}. |
| 932 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 933 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 934 | |
| 935 | /** |
| 936 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 937 | * alongside expanded notifications, as supplied to (e.g.) |
| 938 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 939 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 940 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 941 | |
| 942 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 943 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 944 | * {@link BigTextStyle} notification, as supplied to |
| 945 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 946 | */ |
| 947 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 948 | |
| 949 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 950 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 951 | * supplied to {@link Builder#setSmallIcon(int)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 952 | * |
| 953 | * @deprecated Use {@link #getSmallIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 954 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 955 | @Deprecated |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 956 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 957 | |
| 958 | /** |
| 959 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 960 | * notification payload, as |
| 961 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 962 | * |
| 963 | * @deprecated Use {@link #getLargeIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 964 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 965 | @Deprecated |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 966 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 967 | |
| 968 | /** |
| 969 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 970 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 971 | * shown in its expanded form, as supplied to |
| 972 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 973 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 974 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 975 | |
| 976 | /** |
| 977 | * {@link #extras} key: this is the progress value supplied to |
| 978 | * {@link Builder#setProgress(int, int, boolean)}. |
| 979 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 980 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 981 | |
| 982 | /** |
| 983 | * {@link #extras} key: this is the maximum value supplied to |
| 984 | * {@link Builder#setProgress(int, int, boolean)}. |
| 985 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 986 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 987 | |
| 988 | /** |
| 989 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 990 | * {@link Builder#setProgress(int, int, boolean)}. |
| 991 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 992 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 993 | |
| 994 | /** |
| 995 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 996 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 997 | * {@link Builder#setUsesChronometer(boolean)}. |
| 998 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 999 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1000 | |
| 1001 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1002 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 1003 | * 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] | 1004 | * This extra is a boolean. The default is false. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1005 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1006 | public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 1007 | |
| 1008 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1009 | * {@link #extras} key: whether {@link #when} should be shown, |
| 1010 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 1011 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1012 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1013 | |
| 1014 | /** |
| 1015 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 1016 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 1017 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1018 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1019 | |
| 1020 | /** |
| 1021 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 1022 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 1023 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1024 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1025 | |
| 1026 | /** |
| 1027 | * {@link #extras} key: A string representing the name of the specific |
| 1028 | * {@link android.app.Notification.Style} used to create this notification. |
| 1029 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 1030 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1031 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1032 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 1033 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 1034 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1035 | * |
| 1036 | * @deprecated the actual objects are now in {@link #EXTRA_PEOPLE_LIST} |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1037 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1038 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1039 | |
| 1040 | /** |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 1041 | * {@link #extras} key: An arrayList of {@link Person} objects containing the people that |
| 1042 | * this notification relates to. |
| 1043 | */ |
| 1044 | public static final String EXTRA_PEOPLE_LIST = "android.people.list"; |
| 1045 | |
| 1046 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1047 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 1048 | * Only available to notifications coming from the android package. |
| 1049 | * @hide |
| 1050 | */ |
Maurice Lam | 96c1003 | 2017-03-29 15:42:38 -0700 | [diff] [blame] | 1051 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1052 | @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1053 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 1054 | |
| 1055 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1056 | * {@link #extras} key: A |
| 1057 | * {@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] | 1058 | * in the background when the notification is selected. Used on television platforms. |
| 1059 | * The URI must point to an image stream suitable for passing into |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1060 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1061 | * BitmapFactory.decodeStream}; all other content types will be ignored. |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1062 | */ |
| 1063 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1064 | |
| 1065 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1066 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 1067 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1068 | * {@link android.app.Notification.MediaStyle} notification. |
| 1069 | */ |
| 1070 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1071 | |
| 1072 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 1073 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 1074 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 1075 | */ |
| 1076 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1077 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 1078 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1079 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 1080 | * direct replies |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1081 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1082 | * {@link CharSequence} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1083 | * |
| 1084 | * @deprecated use {@link #EXTRA_MESSAGING_PERSON} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1085 | */ |
| 1086 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1087 | |
| 1088 | /** |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 1089 | * {@link #extras} key: the person to be displayed for all messages sent by the user including |
| 1090 | * direct replies |
| 1091 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1092 | * {@link Person} |
| 1093 | */ |
| 1094 | public static final String EXTRA_MESSAGING_PERSON = "android.messagingUser"; |
| 1095 | |
| 1096 | /** |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1097 | * {@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] | 1098 | * represented by a {@link android.app.Notification.MessagingStyle} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1099 | */ |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1100 | public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1101 | |
| 1102 | /** |
| 1103 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 1104 | * bundles provided by a |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1105 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1106 | * array of bundles. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1107 | */ |
| 1108 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 1109 | |
| 1110 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 1111 | * {@link #extras} key: an array of |
| 1112 | * {@link android.app.Notification.MessagingStyle#addHistoricMessage historic} |
| 1113 | * {@link android.app.Notification.MessagingStyle.Message} bundles provided by a |
| 1114 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1115 | * array of bundles. |
| 1116 | */ |
| 1117 | public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1118 | |
| 1119 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 1120 | * {@link #extras} key: whether the {@link android.app.Notification.MessagingStyle} notification |
| 1121 | * represents a group conversation. |
| 1122 | */ |
| 1123 | public static final String EXTRA_IS_GROUP_CONVERSATION = "android.isGroupConversation"; |
| 1124 | |
| 1125 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1126 | * {@link #extras} key: whether the notification should be colorized as |
| 1127 | * supplied to {@link Builder#setColorized(boolean)}}. |
| 1128 | */ |
| 1129 | public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1130 | |
| 1131 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1132 | * @hide |
| 1133 | */ |
| 1134 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1135 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 1136 | /** |
| 1137 | * @hide |
| 1138 | */ |
| 1139 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1140 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1141 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 1142 | * @hide |
| 1143 | */ |
| 1144 | public static final String EXTRA_REDUCED_IMAGES = "android.reduced.images"; |
| 1145 | |
| 1146 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1147 | * {@link #extras} key: the audio contents of this notification. |
| 1148 | * |
| 1149 | * This is for use when rendering the notification on an audio-focused interface; |
| 1150 | * the audio contents are a complete sound sample that contains the contents/body of the |
| 1151 | * notification. This may be used in substitute of a Text-to-Speech reading of the |
| 1152 | * notification. For example if the notification represents a voice message this should point |
| 1153 | * to the audio of that message. |
| 1154 | * |
| 1155 | * The data stored under this key should be a String representation of a Uri that contains the |
| 1156 | * audio contents in one of the following formats: WAV, PCM 16-bit, AMR-WB. |
| 1157 | * |
| 1158 | * This extra is unnecessary if you are using {@code MessagingStyle} since each {@code Message} |
| 1159 | * has a field for holding data URI. That field can be used for audio. |
| 1160 | * See {@code Message#setData}. |
| 1161 | * |
| 1162 | * Example usage: |
| 1163 | * <pre> |
| 1164 | * {@code |
| 1165 | * Notification.Builder myBuilder = (build your Notification as normal); |
| 1166 | * myBuilder.getExtras().putString(EXTRA_AUDIO_CONTENTS_URI, myAudioUri.toString()); |
| 1167 | * } |
| 1168 | * </pre> |
| 1169 | */ |
| 1170 | public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1171 | |
Dan Sandler | 80eaa59 | 2016-04-14 23:34:54 -0400 | [diff] [blame] | 1172 | /** @hide */ |
| 1173 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1174 | @RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME) |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1175 | public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1176 | |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1177 | /** |
| 1178 | * This is set on the notification shown by the activity manager about all apps |
| 1179 | * running in the background. It indicates that the notification should be shown |
| 1180 | * only if any of the given apps do not already have a {@link #FLAG_FOREGROUND_SERVICE} |
| 1181 | * notification currently visible to the user. This is a string array of all |
| 1182 | * package names of the apps. |
| 1183 | * @hide |
| 1184 | */ |
| 1185 | public static final String EXTRA_FOREGROUND_APPS = "android.foregroundApps"; |
| 1186 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1187 | private Icon mSmallIcon; |
| 1188 | private Icon mLargeIcon; |
| 1189 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1190 | private String mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1191 | private long mTimeout; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1192 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1193 | private String mShortcutId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1194 | private CharSequence mSettingsText; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1195 | |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1196 | /** @hide */ |
| 1197 | @IntDef(prefix = { "GROUP_ALERT_" }, value = { |
| 1198 | GROUP_ALERT_ALL, GROUP_ALERT_CHILDREN, GROUP_ALERT_SUMMARY |
| 1199 | }) |
| 1200 | @Retention(RetentionPolicy.SOURCE) |
| 1201 | public @interface GroupAlertBehavior {} |
| 1202 | |
| 1203 | /** |
| 1204 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all notifications in a |
| 1205 | * group with sound or vibration ought to make sound or vibrate (respectively), so this |
| 1206 | * notification will not be muted when it is in a group. |
| 1207 | */ |
| 1208 | public static final int GROUP_ALERT_ALL = 0; |
| 1209 | |
| 1210 | /** |
| 1211 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all children |
| 1212 | * notification in a group should be silenced (no sound or vibration) even if they are posted |
| 1213 | * 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] | 1214 | * mute this notification if this notification is a group child. This must be applied to all |
| 1215 | * children notifications you want to mute. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1216 | * |
| 1217 | * <p> For example, you might want to use this constant if you post a number of children |
| 1218 | * notifications at once (say, after a periodic sync), and only need to notify the user |
| 1219 | * audibly once. |
| 1220 | */ |
| 1221 | public static final int GROUP_ALERT_SUMMARY = 1; |
| 1222 | |
| 1223 | /** |
| 1224 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that the summary |
| 1225 | * notification in a group should be silenced (no sound or vibration) even if they are |
| 1226 | * posted to a {@link NotificationChannel} that has sound and/or vibration. Use this constant |
| 1227 | * to mute this notification if this notification is a group summary. |
| 1228 | * |
| 1229 | * <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] | 1230 | * in your group have content and the summary is only used to visually group notifications |
| 1231 | * rather than to alert the user that new information is available. |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1232 | */ |
| 1233 | public static final int GROUP_ALERT_CHILDREN = 2; |
| 1234 | |
Julia Reynolds | 2f431e2 | 2017-06-07 14:12:09 +0000 | [diff] [blame] | 1235 | private int mGroupAlertBehavior = GROUP_ALERT_ALL; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1236 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1237 | /** |
| 1238 | * If this notification is being shown as a badge, always show as a number. |
| 1239 | */ |
| 1240 | public static final int BADGE_ICON_NONE = 0; |
| 1241 | |
| 1242 | /** |
| 1243 | * If this notification is being shown as a badge, use the {@link #getSmallIcon()} to |
| 1244 | * represent this notification. |
| 1245 | */ |
| 1246 | public static final int BADGE_ICON_SMALL = 1; |
| 1247 | |
| 1248 | /** |
| 1249 | * If this notification is being shown as a badge, use the {@link #getLargeIcon()} to |
| 1250 | * represent this notification. |
| 1251 | */ |
| 1252 | public static final int BADGE_ICON_LARGE = 2; |
Julia Reynolds | 7d5b4da | 2017-03-20 10:18:49 -0400 | [diff] [blame] | 1253 | private int mBadgeIcon = BADGE_ICON_NONE; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1254 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1255 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1256 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 1257 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 1258 | * selected by the user. |
| 1259 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1260 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 1261 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 1262 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1263 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1264 | public static class Action implements Parcelable { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1265 | /** |
| 1266 | * {@link #extras} key: Keys to a {@link Parcelable} {@link ArrayList} of |
| 1267 | * {@link RemoteInput}s. |
| 1268 | * |
| 1269 | * This is intended for {@link RemoteInput}s that only accept data, meaning |
| 1270 | * {@link RemoteInput#getAllowFreeFormInput} is false, {@link RemoteInput#getChoices} |
| 1271 | * is null or empty, and {@link RemoteInput#getAllowedDataTypes is non-null and not |
| 1272 | * empty. These {@link RemoteInput}s will be ignored by devices that do not |
| 1273 | * support non-text-based {@link RemoteInput}s. See {@link Builder#build}. |
| 1274 | * |
| 1275 | * You can test if a RemoteInput matches these constraints using |
| 1276 | * {@link RemoteInput#isDataOnly}. |
| 1277 | */ |
| 1278 | private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1279 | |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1280 | /** |
| 1281 | * {@link }: No semantic action defined. |
| 1282 | */ |
| 1283 | public static final int SEMANTIC_ACTION_NONE = 0; |
| 1284 | |
| 1285 | /** |
| 1286 | * {@code SemanticAction}: Reply to a conversation, chat, group, or wherever replies |
| 1287 | * may be appropriate. |
| 1288 | */ |
| 1289 | public static final int SEMANTIC_ACTION_REPLY = 1; |
| 1290 | |
| 1291 | /** |
| 1292 | * {@code SemanticAction}: Mark content as read. |
| 1293 | */ |
| 1294 | public static final int SEMANTIC_ACTION_MARK_AS_READ = 2; |
| 1295 | |
| 1296 | /** |
| 1297 | * {@code SemanticAction}: Mark content as unread. |
| 1298 | */ |
| 1299 | public static final int SEMANTIC_ACTION_MARK_AS_UNREAD = 3; |
| 1300 | |
| 1301 | /** |
| 1302 | * {@code SemanticAction}: Delete the content associated with the notification. This |
| 1303 | * could mean deleting an email, message, etc. |
| 1304 | */ |
| 1305 | public static final int SEMANTIC_ACTION_DELETE = 4; |
| 1306 | |
| 1307 | /** |
| 1308 | * {@code SemanticAction}: Archive the content associated with the notification. This |
| 1309 | * could mean archiving an email, message, etc. |
| 1310 | */ |
| 1311 | public static final int SEMANTIC_ACTION_ARCHIVE = 5; |
| 1312 | |
| 1313 | /** |
| 1314 | * {@code SemanticAction}: Mute the content associated with the notification. This could |
| 1315 | * mean silencing a conversation or currently playing media. |
| 1316 | */ |
| 1317 | public static final int SEMANTIC_ACTION_MUTE = 6; |
| 1318 | |
| 1319 | /** |
| 1320 | * {@code SemanticAction}: Unmute the content associated with the notification. This could |
| 1321 | * mean un-silencing a conversation or currently playing media. |
| 1322 | */ |
| 1323 | public static final int SEMANTIC_ACTION_UNMUTE = 7; |
| 1324 | |
| 1325 | /** |
| 1326 | * {@code SemanticAction}: Mark content with a thumbs up. |
| 1327 | */ |
| 1328 | public static final int SEMANTIC_ACTION_THUMBS_UP = 8; |
| 1329 | |
| 1330 | /** |
| 1331 | * {@code SemanticAction}: Mark content with a thumbs down. |
| 1332 | */ |
| 1333 | public static final int SEMANTIC_ACTION_THUMBS_DOWN = 9; |
| 1334 | |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 1335 | /** |
| 1336 | * {@code SemanticAction}: Call a contact, group, etc. |
| 1337 | */ |
| 1338 | public static final int SEMANTIC_ACTION_CALL = 10; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1339 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1340 | private final Bundle mExtras; |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1341 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1342 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1343 | private boolean mAllowGeneratedReplies = true; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1344 | private final @SemanticAction int mSemanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1345 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1346 | /** |
| 1347 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1348 | * |
| 1349 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1350 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1351 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1352 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1353 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1354 | /** |
| 1355 | * Title of the action. |
| 1356 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1357 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1358 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1359 | /** |
| 1360 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1361 | * may be rendered in a disabled presentation by the system UI. |
| 1362 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1363 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1364 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1365 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1366 | if (in.readInt() != 0) { |
| 1367 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1368 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1369 | icon = mIcon.getResId(); |
| 1370 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1371 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1372 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1373 | if (in.readInt() == 1) { |
| 1374 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1375 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1376 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1377 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1378 | mAllowGeneratedReplies = in.readInt() == 1; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1379 | mSemanticAction = in.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1380 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1381 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1382 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1383 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1384 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1385 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1386 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1387 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true, |
| 1388 | SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1391 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1392 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1393 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1394 | @SemanticAction int semanticAction) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1395 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1396 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1397 | this.icon = icon.getResId(); |
| 1398 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1399 | this.title = title; |
| 1400 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1401 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1402 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1403 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1404 | this.mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1408 | * Return an icon representing the action. |
| 1409 | */ |
| 1410 | public Icon getIcon() { |
| 1411 | if (mIcon == null && icon != 0) { |
| 1412 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1413 | mIcon = Icon.createWithResource("", icon); |
| 1414 | } |
| 1415 | return mIcon; |
| 1416 | } |
| 1417 | |
| 1418 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1419 | * Get additional metadata carried around with this Action. |
| 1420 | */ |
| 1421 | public Bundle getExtras() { |
| 1422 | return mExtras; |
| 1423 | } |
| 1424 | |
| 1425 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1426 | * Return whether the platform should automatically generate possible replies for this |
| 1427 | * {@link Action} |
| 1428 | */ |
| 1429 | public boolean getAllowGeneratedReplies() { |
| 1430 | return mAllowGeneratedReplies; |
| 1431 | } |
| 1432 | |
| 1433 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1434 | * 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] | 1435 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1436 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1437 | */ |
| 1438 | public RemoteInput[] getRemoteInputs() { |
| 1439 | return mRemoteInputs; |
| 1440 | } |
| 1441 | |
| 1442 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1443 | * Returns the {@code SemanticAction} associated with this {@link Action}. A |
| 1444 | * {@code SemanticAction} denotes what an {@link Action}'s {@link PendingIntent} will do |
| 1445 | * (eg. reply, mark as read, delete, etc). |
| 1446 | */ |
| 1447 | public @SemanticAction int getSemanticAction() { |
| 1448 | return mSemanticAction; |
| 1449 | } |
| 1450 | |
| 1451 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1452 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1453 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1454 | * {@link RemoteInput#isDataOnly}. |
| 1455 | * |
Shane Brennan | f670d6c | 2017-04-25 13:05:45 -0700 | [diff] [blame] | 1456 | * Returns null if there are no data-only remote inputs. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1457 | * |
| 1458 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1459 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1460 | */ |
| 1461 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1462 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1463 | } |
| 1464 | |
| 1465 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1466 | * Builder class for {@link Action} objects. |
| 1467 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1468 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1469 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1470 | private final CharSequence mTitle; |
| 1471 | private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1472 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1473 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1474 | private ArrayList<RemoteInput> mRemoteInputs; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1475 | private @SemanticAction int mSemanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1476 | |
| 1477 | /** |
| 1478 | * Construct a new builder for {@link Action} object. |
| 1479 | * @param icon icon to show for this action |
| 1480 | * @param title the title of the action |
| 1481 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1482 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1483 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1484 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1485 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | /** |
| 1489 | * Construct a new builder for {@link Action} object. |
| 1490 | * @param icon icon to show for this action |
| 1491 | * @param title the title of the action |
| 1492 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1493 | */ |
| 1494 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1495 | this(icon, title, intent, new Bundle(), null, true, SEMANTIC_ACTION_NONE); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | /** |
| 1499 | * Construct a new builder for {@link Action} object using the fields from an |
| 1500 | * {@link Action}. |
| 1501 | * @param action the action to read fields from. |
| 1502 | */ |
| 1503 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1504 | this(action.getIcon(), action.title, action.actionIntent, |
| 1505 | new Bundle(action.mExtras), action.getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1506 | action.getAllowGeneratedReplies(), action.getSemanticAction()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1509 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1510 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1511 | @SemanticAction int semanticAction) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1512 | mIcon = icon; |
| 1513 | mTitle = title; |
| 1514 | mIntent = intent; |
| 1515 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1516 | if (remoteInputs != null) { |
| 1517 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1518 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1519 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1520 | mAllowGeneratedReplies = allowGeneratedReplies; |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1521 | mSemanticAction = semanticAction; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | /** |
| 1525 | * Merge additional metadata into this builder. |
| 1526 | * |
| 1527 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1528 | * |
| 1529 | * @see Notification.Action#extras |
| 1530 | */ |
| 1531 | public Builder addExtras(Bundle extras) { |
| 1532 | if (extras != null) { |
| 1533 | mExtras.putAll(extras); |
| 1534 | } |
| 1535 | return this; |
| 1536 | } |
| 1537 | |
| 1538 | /** |
| 1539 | * Get the metadata Bundle used by this Builder. |
| 1540 | * |
| 1541 | * <p>The returned Bundle is shared with this Builder. |
| 1542 | */ |
| 1543 | public Bundle getExtras() { |
| 1544 | return mExtras; |
| 1545 | } |
| 1546 | |
| 1547 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1548 | * Add an input to be collected from the user when this action is sent. |
| 1549 | * Response values can be retrieved from the fired intent by using the |
| 1550 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1551 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1552 | * @return this object for method chaining |
| 1553 | */ |
| 1554 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1555 | if (mRemoteInputs == null) { |
| 1556 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1557 | } |
| 1558 | mRemoteInputs.add(remoteInput); |
| 1559 | return this; |
| 1560 | } |
| 1561 | |
| 1562 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1563 | * Set whether the platform should automatically generate possible replies to add to |
| 1564 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1565 | * {@link RemoteInput}, this has no effect. |
| 1566 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1567 | * otherwise |
| 1568 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1569 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1570 | */ |
| 1571 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1572 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1573 | return this; |
| 1574 | } |
| 1575 | |
| 1576 | /** |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1577 | * Sets the {@code SemanticAction} for this {@link Action}. A |
| 1578 | * {@code SemanticAction} denotes what an {@link Action}'s |
| 1579 | * {@link PendingIntent} will do (eg. reply, mark as read, delete, etc). |
| 1580 | * @param semanticAction a SemanticAction defined within {@link Action} with |
| 1581 | * {@code SEMANTIC_ACTION_} prefixes |
| 1582 | * @return this object for method chaining |
| 1583 | */ |
| 1584 | public Builder setSemanticAction(@SemanticAction int semanticAction) { |
| 1585 | mSemanticAction = semanticAction; |
| 1586 | return this; |
| 1587 | } |
| 1588 | |
| 1589 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1590 | * Apply an extender to this action builder. Extenders may be used to add |
| 1591 | * metadata or change options on this builder. |
| 1592 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1593 | public Builder extend(Extender extender) { |
| 1594 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1595 | return this; |
| 1596 | } |
| 1597 | |
| 1598 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1599 | * Combine all of the options that have been set and return a new {@link Action} |
| 1600 | * object. |
| 1601 | * @return the built action |
| 1602 | */ |
| 1603 | public Action build() { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1604 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1605 | RemoteInput[] previousDataInputs = |
| 1606 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1607 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1608 | for (RemoteInput input : previousDataInputs) { |
| 1609 | dataOnlyInputs.add(input); |
| 1610 | } |
| 1611 | } |
| 1612 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1613 | if (mRemoteInputs != null) { |
| 1614 | for (RemoteInput input : mRemoteInputs) { |
| 1615 | if (input.isDataOnly()) { |
| 1616 | dataOnlyInputs.add(input); |
| 1617 | } else { |
| 1618 | textInputs.add(input); |
| 1619 | } |
| 1620 | } |
| 1621 | } |
| 1622 | if (!dataOnlyInputs.isEmpty()) { |
| 1623 | RemoteInput[] dataInputsArr = |
| 1624 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1625 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1626 | } |
| 1627 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1628 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1629 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1630 | mAllowGeneratedReplies, mSemanticAction); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1631 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1632 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1633 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1634 | @Override |
| 1635 | public Action clone() { |
| 1636 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1637 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1638 | title, |
| 1639 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1640 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1641 | getRemoteInputs(), |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1642 | getAllowGeneratedReplies(), |
| 1643 | getSemanticAction()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1644 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1645 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1646 | @Override |
| 1647 | public int describeContents() { |
| 1648 | return 0; |
| 1649 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1650 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1651 | @Override |
| 1652 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1653 | final Icon ic = getIcon(); |
| 1654 | if (ic != null) { |
| 1655 | out.writeInt(1); |
| 1656 | ic.writeToParcel(out, 0); |
| 1657 | } else { |
| 1658 | out.writeInt(0); |
| 1659 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1660 | TextUtils.writeToParcel(title, out, flags); |
| 1661 | if (actionIntent != null) { |
| 1662 | out.writeInt(1); |
| 1663 | actionIntent.writeToParcel(out, flags); |
| 1664 | } else { |
| 1665 | out.writeInt(0); |
| 1666 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1667 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1668 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1669 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1670 | out.writeInt(mSemanticAction); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1671 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1672 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1673 | public static final Parcelable.Creator<Action> CREATOR = |
| 1674 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1675 | public Action createFromParcel(Parcel in) { |
| 1676 | return new Action(in); |
| 1677 | } |
| 1678 | public Action[] newArray(int size) { |
| 1679 | return new Action[size]; |
| 1680 | } |
| 1681 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1682 | |
| 1683 | /** |
| 1684 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1685 | * metadata or change options on an action builder. |
| 1686 | */ |
| 1687 | public interface Extender { |
| 1688 | /** |
| 1689 | * Apply this extender to a notification action builder. |
| 1690 | * @param builder the builder to be modified. |
| 1691 | * @return the build object for chaining. |
| 1692 | */ |
| 1693 | public Builder extend(Builder builder); |
| 1694 | } |
| 1695 | |
| 1696 | /** |
| 1697 | * Wearable extender for notification actions. To add extensions to an action, |
| 1698 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1699 | * the {@code WearableExtender()} constructor and apply it to a |
| 1700 | * {@link android.app.Notification.Action.Builder} using |
| 1701 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1702 | * |
| 1703 | * <pre class="prettyprint"> |
| 1704 | * Notification.Action action = new Notification.Action.Builder( |
| 1705 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1706 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1707 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1708 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1709 | */ |
| 1710 | public static final class WearableExtender implements Extender { |
| 1711 | /** Notification action extra which contains wearable extensions */ |
| 1712 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1713 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1714 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1715 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1716 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1717 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1718 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1719 | |
| 1720 | // Flags bitwise-ored to mFlags |
| 1721 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1722 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1723 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1724 | |
| 1725 | // Default value for flags integer |
| 1726 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1727 | |
| 1728 | private int mFlags = DEFAULT_FLAGS; |
| 1729 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1730 | private CharSequence mInProgressLabel; |
| 1731 | private CharSequence mConfirmLabel; |
| 1732 | private CharSequence mCancelLabel; |
| 1733 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1734 | /** |
| 1735 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1736 | * options. |
| 1737 | */ |
| 1738 | public WearableExtender() { |
| 1739 | } |
| 1740 | |
| 1741 | /** |
| 1742 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1743 | * wearable options present in an existing notification action. |
| 1744 | * @param action the notification action to inspect. |
| 1745 | */ |
| 1746 | public WearableExtender(Action action) { |
| 1747 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1748 | if (wearableBundle != null) { |
| 1749 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1750 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1751 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1752 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1753 | } |
| 1754 | } |
| 1755 | |
| 1756 | /** |
| 1757 | * Apply wearable extensions to a notification action that is being built. This is |
| 1758 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1759 | * method of {@link android.app.Notification.Action.Builder}. |
| 1760 | */ |
| 1761 | @Override |
| 1762 | public Action.Builder extend(Action.Builder builder) { |
| 1763 | Bundle wearableBundle = new Bundle(); |
| 1764 | |
| 1765 | if (mFlags != DEFAULT_FLAGS) { |
| 1766 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1767 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1768 | if (mInProgressLabel != null) { |
| 1769 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1770 | } |
| 1771 | if (mConfirmLabel != null) { |
| 1772 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1773 | } |
| 1774 | if (mCancelLabel != null) { |
| 1775 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1776 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1777 | |
| 1778 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1779 | return builder; |
| 1780 | } |
| 1781 | |
| 1782 | @Override |
| 1783 | public WearableExtender clone() { |
| 1784 | WearableExtender that = new WearableExtender(); |
| 1785 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1786 | that.mInProgressLabel = this.mInProgressLabel; |
| 1787 | that.mConfirmLabel = this.mConfirmLabel; |
| 1788 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1789 | return that; |
| 1790 | } |
| 1791 | |
| 1792 | /** |
| 1793 | * Set whether this action is available when the wearable device is not connected to |
| 1794 | * a companion device. The user can still trigger this action when the wearable device is |
| 1795 | * offline, but a visual hint will indicate that the action may not be available. |
| 1796 | * Defaults to true. |
| 1797 | */ |
| 1798 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1799 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1800 | return this; |
| 1801 | } |
| 1802 | |
| 1803 | /** |
| 1804 | * Get whether this action is available when the wearable device is not connected to |
| 1805 | * a companion device. The user can still trigger this action when the wearable device is |
| 1806 | * offline, but a visual hint will indicate that the action may not be available. |
| 1807 | * Defaults to true. |
| 1808 | */ |
| 1809 | public boolean isAvailableOffline() { |
| 1810 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1811 | } |
| 1812 | |
| 1813 | private void setFlag(int mask, boolean value) { |
| 1814 | if (value) { |
| 1815 | mFlags |= mask; |
| 1816 | } else { |
| 1817 | mFlags &= ~mask; |
| 1818 | } |
| 1819 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1820 | |
| 1821 | /** |
| 1822 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1823 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1824 | * |
| 1825 | * @param label the label to display while the action is being prepared to execute |
| 1826 | * @return this object for method chaining |
| 1827 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1828 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1829 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1830 | mInProgressLabel = label; |
| 1831 | return this; |
| 1832 | } |
| 1833 | |
| 1834 | /** |
| 1835 | * Get the label to display while the wearable is preparing to automatically execute |
| 1836 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1837 | * |
| 1838 | * @return the label to display while the action is being prepared to execute |
| 1839 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1840 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1841 | public CharSequence getInProgressLabel() { |
| 1842 | return mInProgressLabel; |
| 1843 | } |
| 1844 | |
| 1845 | /** |
| 1846 | * Set a label to display to confirm that the action should be executed. |
| 1847 | * This is usually an imperative verb like "Send". |
| 1848 | * |
| 1849 | * @param label the label to confirm the action should be executed |
| 1850 | * @return this object for method chaining |
| 1851 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1852 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1853 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1854 | mConfirmLabel = label; |
| 1855 | return this; |
| 1856 | } |
| 1857 | |
| 1858 | /** |
| 1859 | * Get the label to display to confirm that the action should be executed. |
| 1860 | * This is usually an imperative verb like "Send". |
| 1861 | * |
| 1862 | * @return the label to confirm the action should be executed |
| 1863 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1864 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1865 | public CharSequence getConfirmLabel() { |
| 1866 | return mConfirmLabel; |
| 1867 | } |
| 1868 | |
| 1869 | /** |
| 1870 | * Set a label to display to cancel the action. |
| 1871 | * This is usually an imperative verb, like "Cancel". |
| 1872 | * |
| 1873 | * @param label the label to display to cancel the action |
| 1874 | * @return this object for method chaining |
| 1875 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1876 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1877 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1878 | mCancelLabel = label; |
| 1879 | return this; |
| 1880 | } |
| 1881 | |
| 1882 | /** |
| 1883 | * Get the label to display to cancel the action. |
| 1884 | * This is usually an imperative verb like "Cancel". |
| 1885 | * |
| 1886 | * @return the label to display to cancel the action |
| 1887 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 1888 | @Deprecated |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1889 | public CharSequence getCancelLabel() { |
| 1890 | return mCancelLabel; |
| 1891 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1892 | |
| 1893 | /** |
| 1894 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 1895 | * platform that it can generate the appropriate transitions. |
| 1896 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 1897 | * an activity and transitions should be generated, false otherwise. |
| 1898 | * @return this object for method chaining |
| 1899 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1900 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1901 | boolean hintLaunchesActivity) { |
| 1902 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 1903 | return this; |
| 1904 | } |
| 1905 | |
| 1906 | /** |
| 1907 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 1908 | * platform that it can generate the appropriate transitions |
| 1909 | * @return {@code true} if the content intent will launch an activity and transitions |
| 1910 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 1911 | * never set. |
| 1912 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1913 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1914 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 1915 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1916 | |
| 1917 | /** |
| 1918 | * Set a hint that this Action should be displayed inline. |
| 1919 | * |
| 1920 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 1921 | * otherwise |
| 1922 | * @return this object for method chaining |
| 1923 | */ |
| 1924 | public WearableExtender setHintDisplayActionInline( |
| 1925 | boolean hintDisplayInline) { |
| 1926 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 1927 | return this; |
| 1928 | } |
| 1929 | |
| 1930 | /** |
| 1931 | * Get a hint that this Action should be displayed inline. |
| 1932 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 1933 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1934 | * otherwise. The default value is {@code false} if this was never set. |
| 1935 | */ |
| 1936 | public boolean getHintDisplayActionInline() { |
| 1937 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 1938 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1939 | } |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1940 | |
| 1941 | /** |
| 1942 | * Provides meaning to an {@link Action} that hints at what the associated |
| 1943 | * {@link PendingIntent} will do. For example, an {@link Action} with a |
| 1944 | * {@link PendingIntent} that replies to a text message notification may have the |
| 1945 | * {@link #SEMANTIC_ACTION_REPLY} {@code SemanticAction} set within it. |
| 1946 | * |
| 1947 | * @hide |
| 1948 | */ |
| 1949 | @IntDef(prefix = { "SEMANTIC_ACTION_" }, value = { |
| 1950 | SEMANTIC_ACTION_NONE, |
| 1951 | SEMANTIC_ACTION_REPLY, |
| 1952 | SEMANTIC_ACTION_MARK_AS_READ, |
| 1953 | SEMANTIC_ACTION_MARK_AS_UNREAD, |
| 1954 | SEMANTIC_ACTION_DELETE, |
| 1955 | SEMANTIC_ACTION_ARCHIVE, |
| 1956 | SEMANTIC_ACTION_MUTE, |
| 1957 | SEMANTIC_ACTION_UNMUTE, |
| 1958 | SEMANTIC_ACTION_THUMBS_UP, |
Kodlee Yin | cda5b09 | 2018-02-15 15:34:53 -0800 | [diff] [blame] | 1959 | SEMANTIC_ACTION_THUMBS_DOWN, |
| 1960 | SEMANTIC_ACTION_CALL |
Kodlee Yin | c72c44d | 2017-12-21 22:07:15 +0000 | [diff] [blame] | 1961 | }) |
| 1962 | @Retention(RetentionPolicy.SOURCE) |
| 1963 | public @interface SemanticAction {} |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1964 | } |
| 1965 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1966 | /** |
| 1967 | * Array of all {@link Action} structures attached to this notification by |
| 1968 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 1969 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 1970 | * interface for invoking actions. |
| 1971 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1972 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1973 | |
| 1974 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1975 | * Replacement version of this notification whose content will be shown |
| 1976 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 1977 | * and {@link #VISIBILITY_PUBLIC}. |
| 1978 | */ |
| 1979 | public Notification publicVersion; |
| 1980 | |
| 1981 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1982 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1983 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | */ |
| 1985 | public Notification() |
| 1986 | { |
| 1987 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1988 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1989 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | * @hide |
| 1994 | */ |
| 1995 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 1996 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 1997 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1998 | new Builder(context) |
| 1999 | .setWhen(when) |
| 2000 | .setSmallIcon(icon) |
| 2001 | .setTicker(tickerText) |
| 2002 | .setContentTitle(contentTitle) |
| 2003 | .setContentText(contentText) |
| 2004 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 2005 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | /** |
| 2009 | * Constructs a Notification object with the information needed to |
| 2010 | * have a status bar icon without the standard expanded view. |
| 2011 | * |
| 2012 | * @param icon The resource id of the icon to put in the status bar. |
| 2013 | * @param tickerText The text that flows by in the status bar when the notification first |
| 2014 | * activates. |
| 2015 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 2016 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2017 | * |
| 2018 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2020 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | public Notification(int icon, CharSequence tickerText, long when) |
| 2022 | { |
| 2023 | this.icon = icon; |
| 2024 | this.tickerText = tickerText; |
| 2025 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2026 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | /** |
| 2030 | * Unflatten the notification from a parcel. |
| 2031 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2032 | @SuppressWarnings("unchecked") |
| 2033 | public Notification(Parcel parcel) { |
| 2034 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 2035 | // intents in extras are always written as the last entry. |
| 2036 | readFromParcelImpl(parcel); |
| 2037 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2038 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2042 | { |
| 2043 | int version = parcel.readInt(); |
| 2044 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2045 | mWhitelistToken = parcel.readStrongBinder(); |
| 2046 | if (mWhitelistToken == null) { |
| 2047 | mWhitelistToken = processWhitelistToken; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2048 | } |
| 2049 | // 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] | 2050 | parcel.setClassCookie(PendingIntent.class, mWhitelistToken); |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2051 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2052 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2053 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2054 | if (parcel.readInt() != 0) { |
| 2055 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2056 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 2057 | icon = mSmallIcon.getResId(); |
| 2058 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2059 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | number = parcel.readInt(); |
| 2061 | if (parcel.readInt() != 0) { |
| 2062 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2063 | } |
| 2064 | if (parcel.readInt() != 0) { |
| 2065 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2066 | } |
| 2067 | if (parcel.readInt() != 0) { |
| 2068 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2069 | } |
| 2070 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2071 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2072 | } |
| 2073 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2075 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2076 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2077 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2078 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | defaults = parcel.readInt(); |
| 2080 | flags = parcel.readInt(); |
| 2081 | if (parcel.readInt() != 0) { |
| 2082 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 2083 | } |
| 2084 | |
| 2085 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2086 | if (parcel.readInt() != 0) { |
| 2087 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 2088 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | vibrate = parcel.createLongArray(); |
| 2090 | ledARGB = parcel.readInt(); |
| 2091 | ledOnMS = parcel.readInt(); |
| 2092 | ledOffMS = parcel.readInt(); |
| 2093 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2094 | |
| 2095 | if (parcel.readInt() != 0) { |
| 2096 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2097 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2098 | |
| 2099 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2100 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2101 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2102 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2103 | mGroupKey = parcel.readString(); |
| 2104 | |
| 2105 | mSortKey = parcel.readString(); |
| 2106 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 2107 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2108 | fixDuplicateExtras(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2109 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2110 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 2111 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2112 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2113 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2114 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2115 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2116 | if (parcel.readInt() != 0) { |
| 2117 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2118 | } |
| 2119 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2120 | visibility = parcel.readInt(); |
| 2121 | |
| 2122 | if (parcel.readInt() != 0) { |
| 2123 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 2124 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2125 | |
| 2126 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2127 | |
| 2128 | if (parcel.readInt() != 0) { |
| 2129 | mChannelId = parcel.readString(); |
| 2130 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2131 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2132 | |
| 2133 | if (parcel.readInt() != 0) { |
| 2134 | mShortcutId = parcel.readString(); |
| 2135 | } |
| 2136 | |
| 2137 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2138 | |
| 2139 | if (parcel.readInt() != 0) { |
| 2140 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2141 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2142 | |
| 2143 | mGroupAlertBehavior = parcel.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2144 | } |
| 2145 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2146 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2147 | public Notification clone() { |
| 2148 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2149 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2150 | return that; |
| 2151 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2152 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2153 | /** |
| 2154 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 2155 | * of this into that. |
| 2156 | * @hide |
| 2157 | */ |
| 2158 | public void cloneInto(Notification that, boolean heavy) { |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2159 | that.mWhitelistToken = this.mWhitelistToken; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2160 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2161 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2162 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2163 | that.number = this.number; |
| 2164 | |
| 2165 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 2166 | that.contentIntent = this.contentIntent; |
| 2167 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2168 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2169 | |
| 2170 | if (this.tickerText != null) { |
| 2171 | that.tickerText = this.tickerText.toString(); |
| 2172 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2173 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2174 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2175 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2176 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2177 | that.contentView = this.contentView.clone(); |
| 2178 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2179 | if (heavy && this.mLargeIcon != null) { |
| 2180 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2181 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 2182 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2183 | that.sound = this.sound; // android.net.Uri is immutable |
| 2184 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2185 | if (this.audioAttributes != null) { |
| 2186 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 2187 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2188 | |
| 2189 | final long[] vibrate = this.vibrate; |
| 2190 | if (vibrate != null) { |
| 2191 | final int N = vibrate.length; |
| 2192 | final long[] vib = that.vibrate = new long[N]; |
| 2193 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 2194 | } |
| 2195 | |
| 2196 | that.ledARGB = this.ledARGB; |
| 2197 | that.ledOnMS = this.ledOnMS; |
| 2198 | that.ledOffMS = this.ledOffMS; |
| 2199 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2200 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2201 | that.flags = this.flags; |
| 2202 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2203 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2204 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2205 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2206 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2207 | that.mGroupKey = this.mGroupKey; |
| 2208 | |
| 2209 | that.mSortKey = this.mSortKey; |
| 2210 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2211 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2212 | try { |
| 2213 | that.extras = new Bundle(this.extras); |
| 2214 | // will unparcel |
| 2215 | that.extras.size(); |
| 2216 | } catch (BadParcelableException e) { |
| 2217 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2218 | that.extras = null; |
| 2219 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2220 | } |
| 2221 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2222 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2223 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2224 | } |
| 2225 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2226 | if (this.actions != null) { |
| 2227 | that.actions = new Action[this.actions.length]; |
| 2228 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 2229 | if ( this.actions[i] != null) { |
| 2230 | that.actions[i] = this.actions[i].clone(); |
| 2231 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2232 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2233 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2234 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2235 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2236 | that.bigContentView = this.bigContentView.clone(); |
| 2237 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2238 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2239 | if (heavy && this.headsUpContentView != null) { |
| 2240 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 2241 | } |
| 2242 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2243 | that.visibility = this.visibility; |
| 2244 | |
| 2245 | if (this.publicVersion != null) { |
| 2246 | that.publicVersion = new Notification(); |
| 2247 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2248 | } |
| 2249 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2250 | that.color = this.color; |
| 2251 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2252 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2253 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2254 | that.mShortcutId = this.mShortcutId; |
| 2255 | that.mBadgeIcon = this.mBadgeIcon; |
| 2256 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2257 | that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2258 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2259 | if (!heavy) { |
| 2260 | that.lightenPayload(); // will clean out extras |
| 2261 | } |
| 2262 | } |
| 2263 | |
| 2264 | /** |
| 2265 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 2266 | * listeners when the full contents are not necessary. |
| 2267 | * @hide |
| 2268 | */ |
| 2269 | public final void lightenPayload() { |
| 2270 | tickerView = null; |
| 2271 | contentView = null; |
| 2272 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2273 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2274 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2275 | if (extras != null && !extras.isEmpty()) { |
| 2276 | final Set<String> keyset = extras.keySet(); |
| 2277 | final int N = keyset.size(); |
| 2278 | final String[] keys = keyset.toArray(new String[N]); |
| 2279 | for (int i=0; i<N; i++) { |
| 2280 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2281 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2282 | continue; |
| 2283 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2284 | final Object obj = extras.get(key); |
| 2285 | if (obj != null && |
| 2286 | ( obj instanceof Parcelable |
| 2287 | || obj instanceof Parcelable[] |
| 2288 | || obj instanceof SparseArray |
| 2289 | || obj instanceof ArrayList)) { |
| 2290 | extras.remove(key); |
| 2291 | } |
| 2292 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2293 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2296 | /** |
| 2297 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2298 | * means it had better not be some custom Parcelable implementation. |
| 2299 | * @hide |
| 2300 | */ |
| 2301 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2302 | if (cs == null) return cs; |
| 2303 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2304 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2305 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2306 | if (cs instanceof Parcelable) { |
| 2307 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2308 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2309 | return cs.toString(); |
| 2310 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2311 | return removeTextSizeSpans(cs); |
| 2312 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2313 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2314 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2315 | if (charSequence instanceof Spanned) { |
| 2316 | Spanned ss = (Spanned) charSequence; |
| 2317 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2318 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2319 | for (Object span : spans) { |
| 2320 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2321 | if (resultSpan instanceof CharacterStyle) { |
| 2322 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2323 | } |
| 2324 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2325 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2326 | resultSpan = new TextAppearanceSpan( |
| 2327 | originalSpan.getFamily(), |
| 2328 | originalSpan.getTextStyle(), |
| 2329 | -1, |
| 2330 | originalSpan.getTextColor(), |
| 2331 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2332 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2333 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2334 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2335 | } else { |
| 2336 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2337 | } |
| 2338 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2339 | ss.getSpanFlags(span)); |
| 2340 | } |
| 2341 | return builder; |
| 2342 | } |
| 2343 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2344 | } |
| 2345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2346 | public int describeContents() { |
| 2347 | return 0; |
| 2348 | } |
| 2349 | |
| 2350 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2351 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2352 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2353 | public void writeToParcel(Parcel parcel, int flags) { |
| 2354 | // We need to mark all pending intents getting into the notification |
| 2355 | // system as being put there to later allow the notification ranker |
| 2356 | // to launch them and by doing so add the app to the battery saver white |
| 2357 | // list for a short period of time. The problem is that the system |
| 2358 | // cannot look into the extras as there may be parcelables there that |
| 2359 | // the platform does not know how to handle. To go around that we have |
| 2360 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2361 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2362 | if (collectPendingIntents) { |
| 2363 | PendingIntent.setOnMarshaledListener( |
| 2364 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2365 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2366 | if (allPendingIntents == null) { |
| 2367 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2368 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2369 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2370 | } |
| 2371 | }); |
| 2372 | } |
| 2373 | try { |
| 2374 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2375 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2376 | writeToParcelImpl(parcel, flags); |
| 2377 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2378 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2379 | } finally { |
| 2380 | if (collectPendingIntents) { |
| 2381 | PendingIntent.setOnMarshaledListener(null); |
| 2382 | } |
| 2383 | } |
| 2384 | } |
| 2385 | |
| 2386 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | parcel.writeInt(1); |
| 2388 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 2389 | parcel.writeStrongBinder(mWhitelistToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2391 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2392 | if (mSmallIcon == null && icon != 0) { |
| 2393 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2394 | mSmallIcon = Icon.createWithResource("", icon); |
| 2395 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2396 | if (mSmallIcon != null) { |
| 2397 | parcel.writeInt(1); |
| 2398 | mSmallIcon.writeToParcel(parcel, 0); |
| 2399 | } else { |
| 2400 | parcel.writeInt(0); |
| 2401 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | parcel.writeInt(number); |
| 2403 | if (contentIntent != null) { |
| 2404 | parcel.writeInt(1); |
| 2405 | contentIntent.writeToParcel(parcel, 0); |
| 2406 | } else { |
| 2407 | parcel.writeInt(0); |
| 2408 | } |
| 2409 | if (deleteIntent != null) { |
| 2410 | parcel.writeInt(1); |
| 2411 | deleteIntent.writeToParcel(parcel, 0); |
| 2412 | } else { |
| 2413 | parcel.writeInt(0); |
| 2414 | } |
| 2415 | if (tickerText != null) { |
| 2416 | parcel.writeInt(1); |
| 2417 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2418 | } else { |
| 2419 | parcel.writeInt(0); |
| 2420 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2421 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2422 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2423 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2424 | } else { |
| 2425 | parcel.writeInt(0); |
| 2426 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | if (contentView != null) { |
| 2428 | parcel.writeInt(1); |
| 2429 | contentView.writeToParcel(parcel, 0); |
| 2430 | } else { |
| 2431 | parcel.writeInt(0); |
| 2432 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2433 | if (mLargeIcon == null && largeIcon != null) { |
| 2434 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2435 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2436 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2437 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2438 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2439 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2440 | } else { |
| 2441 | parcel.writeInt(0); |
| 2442 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2443 | |
| 2444 | parcel.writeInt(defaults); |
| 2445 | parcel.writeInt(this.flags); |
| 2446 | |
| 2447 | if (sound != null) { |
| 2448 | parcel.writeInt(1); |
| 2449 | sound.writeToParcel(parcel, 0); |
| 2450 | } else { |
| 2451 | parcel.writeInt(0); |
| 2452 | } |
| 2453 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2454 | |
| 2455 | if (audioAttributes != null) { |
| 2456 | parcel.writeInt(1); |
| 2457 | audioAttributes.writeToParcel(parcel, 0); |
| 2458 | } else { |
| 2459 | parcel.writeInt(0); |
| 2460 | } |
| 2461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2462 | parcel.writeLongArray(vibrate); |
| 2463 | parcel.writeInt(ledARGB); |
| 2464 | parcel.writeInt(ledOnMS); |
| 2465 | parcel.writeInt(ledOffMS); |
| 2466 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2467 | |
| 2468 | if (fullScreenIntent != null) { |
| 2469 | parcel.writeInt(1); |
| 2470 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2471 | } else { |
| 2472 | parcel.writeInt(0); |
| 2473 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2474 | |
| 2475 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2476 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2477 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2478 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2479 | parcel.writeString(mGroupKey); |
| 2480 | |
| 2481 | parcel.writeString(mSortKey); |
| 2482 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2483 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2484 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2485 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2486 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2487 | if (bigContentView != null) { |
| 2488 | parcel.writeInt(1); |
| 2489 | bigContentView.writeToParcel(parcel, 0); |
| 2490 | } else { |
| 2491 | parcel.writeInt(0); |
| 2492 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2493 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2494 | if (headsUpContentView != null) { |
| 2495 | parcel.writeInt(1); |
| 2496 | headsUpContentView.writeToParcel(parcel, 0); |
| 2497 | } else { |
| 2498 | parcel.writeInt(0); |
| 2499 | } |
| 2500 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2501 | parcel.writeInt(visibility); |
| 2502 | |
| 2503 | if (publicVersion != null) { |
| 2504 | parcel.writeInt(1); |
| 2505 | publicVersion.writeToParcel(parcel, 0); |
| 2506 | } else { |
| 2507 | parcel.writeInt(0); |
| 2508 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2509 | |
| 2510 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2511 | |
| 2512 | if (mChannelId != null) { |
| 2513 | parcel.writeInt(1); |
| 2514 | parcel.writeString(mChannelId); |
| 2515 | } else { |
| 2516 | parcel.writeInt(0); |
| 2517 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2518 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2519 | |
| 2520 | if (mShortcutId != null) { |
| 2521 | parcel.writeInt(1); |
| 2522 | parcel.writeString(mShortcutId); |
| 2523 | } else { |
| 2524 | parcel.writeInt(0); |
| 2525 | } |
| 2526 | |
| 2527 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2528 | |
| 2529 | if (mSettingsText != null) { |
| 2530 | parcel.writeInt(1); |
| 2531 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2532 | } else { |
| 2533 | parcel.writeInt(0); |
| 2534 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2535 | |
| 2536 | parcel.writeInt(mGroupAlertBehavior); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | /** |
| 2540 | * Parcelable.Creator that instantiates Notification objects |
| 2541 | */ |
| 2542 | public static final Parcelable.Creator<Notification> CREATOR |
| 2543 | = new Parcelable.Creator<Notification>() |
| 2544 | { |
| 2545 | public Notification createFromParcel(Parcel parcel) |
| 2546 | { |
| 2547 | return new Notification(parcel); |
| 2548 | } |
| 2549 | |
| 2550 | public Notification[] newArray(int size) |
| 2551 | { |
| 2552 | return new Notification[size]; |
| 2553 | } |
| 2554 | }; |
| 2555 | |
| 2556 | /** |
Robin Lee | ad7e72a | 2017-12-04 15:45:46 +0100 | [diff] [blame] | 2557 | * Parcelling creates multiple copies of objects in {@code extras}. Fix them. |
| 2558 | * <p> |
| 2559 | * For backwards compatibility {@code extras} holds some references to "real" member data such |
| 2560 | * as {@link getLargeIcon()} which is mirrored by {@link #EXTRA_LARGE_ICON}. This is mostly |
| 2561 | * fine as long as the object stays in one process. |
| 2562 | * <p> |
| 2563 | * However, once the notification goes into a parcel each reference gets marshalled separately, |
| 2564 | * wasting memory. Especially with large images on Auto and TV, this is worth fixing. |
| 2565 | */ |
| 2566 | private void fixDuplicateExtras() { |
| 2567 | if (extras != null) { |
| 2568 | fixDuplicateExtra(mSmallIcon, EXTRA_SMALL_ICON); |
| 2569 | fixDuplicateExtra(mLargeIcon, EXTRA_LARGE_ICON); |
| 2570 | } |
| 2571 | } |
| 2572 | |
| 2573 | /** |
| 2574 | * If we find an extra that's exactly the same as one of the "real" fields but refers to a |
| 2575 | * separate object, replace it with the field's version to avoid holding duplicate copies. |
| 2576 | */ |
| 2577 | private void fixDuplicateExtra(@Nullable Parcelable original, @NonNull String extraName) { |
| 2578 | if (original != null && extras.getParcelable(extraName) != null) { |
| 2579 | extras.putParcelable(extraName, original); |
| 2580 | } |
| 2581 | } |
| 2582 | |
| 2583 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2584 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2585 | * layout. |
| 2586 | * |
| 2587 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2588 | * in the view.</p> |
| 2589 | * @param context The context for your application / activity. |
| 2590 | * @param contentTitle The title that goes in the expanded entry. |
| 2591 | * @param contentText The text that goes in the expanded entry. |
| 2592 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2593 | * If this is an activity, it must include the |
| 2594 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2595 | * that you take care of task management as described in the |
| 2596 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2597 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2598 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2599 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2600 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2602 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2603 | public void setLatestEventInfo(Context context, |
| 2604 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2605 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2606 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2607 | new Throwable()); |
| 2608 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2609 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2610 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2611 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2612 | } |
| 2613 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2614 | // ensure that any information already set directly is preserved |
| 2615 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2616 | |
| 2617 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2619 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2620 | } |
| 2621 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2622 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2623 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2624 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2625 | |
| 2626 | 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] | 2627 | } |
| 2628 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2629 | /** |
| 2630 | * @hide |
| 2631 | */ |
| 2632 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2633 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | /** |
| 2637 | * @hide |
| 2638 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2639 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2640 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2641 | } |
| 2642 | |
Yi Jin | 6b51414 | 2017-10-30 14:54:12 -0700 | [diff] [blame] | 2643 | /** |
| 2644 | * @hide |
| 2645 | */ |
| 2646 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 2647 | long token = proto.start(fieldId); |
| 2648 | proto.write(NotificationProto.CHANNEL_ID, getChannelId()); |
| 2649 | proto.write(NotificationProto.HAS_TICKER_TEXT, this.tickerText != null); |
| 2650 | proto.write(NotificationProto.FLAGS, this.flags); |
| 2651 | proto.write(NotificationProto.COLOR, this.color); |
| 2652 | proto.write(NotificationProto.CATEGORY, this.category); |
| 2653 | proto.write(NotificationProto.GROUP_KEY, this.mGroupKey); |
| 2654 | proto.write(NotificationProto.SORT_KEY, this.mSortKey); |
| 2655 | if (this.actions != null) { |
| 2656 | proto.write(NotificationProto.ACTION_LENGTH, this.actions.length); |
| 2657 | } |
| 2658 | if (this.visibility >= VISIBILITY_SECRET && this.visibility <= VISIBILITY_PUBLIC) { |
| 2659 | proto.write(NotificationProto.VISIBILITY, this.visibility); |
| 2660 | } |
| 2661 | if (publicVersion != null) { |
| 2662 | publicVersion.writeToProto(proto, NotificationProto.PUBLIC_VERSION); |
| 2663 | } |
| 2664 | proto.end(token); |
| 2665 | } |
| 2666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | @Override |
| 2668 | public String toString() { |
| 2669 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2670 | sb.append("Notification(channel="); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2671 | sb.append(getChannelId()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2672 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2673 | sb.append(priority); |
| 2674 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2675 | if (contentView != null) { |
| 2676 | sb.append(contentView.getPackage()); |
| 2677 | sb.append("/0x"); |
| 2678 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2679 | } else { |
| 2680 | sb.append("null"); |
| 2681 | } |
| 2682 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2683 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2684 | sb.append("default"); |
| 2685 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2686 | int N = this.vibrate.length-1; |
| 2687 | sb.append("["); |
| 2688 | for (int i=0; i<N; i++) { |
| 2689 | sb.append(this.vibrate[i]); |
| 2690 | sb.append(','); |
| 2691 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 2692 | if (N != -1) { |
| 2693 | sb.append(this.vibrate[N]); |
| 2694 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2696 | } else { |
| 2697 | sb.append("null"); |
| 2698 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2699 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2700 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2701 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2702 | } else if (this.sound != null) { |
| 2703 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2704 | } else { |
| 2705 | sb.append("null"); |
| 2706 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 2707 | if (this.tickerText != null) { |
| 2708 | sb.append(" tick"); |
| 2709 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2710 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2711 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2712 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2713 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2714 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2715 | if (this.category != null) { |
| 2716 | sb.append(" category="); |
| 2717 | sb.append(this.category); |
| 2718 | } |
| 2719 | if (this.mGroupKey != null) { |
| 2720 | sb.append(" groupKey="); |
| 2721 | sb.append(this.mGroupKey); |
| 2722 | } |
| 2723 | if (this.mSortKey != null) { |
| 2724 | sb.append(" sortKey="); |
| 2725 | sb.append(this.mSortKey); |
| 2726 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2727 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2728 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2729 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2730 | } |
| 2731 | sb.append(" vis="); |
| 2732 | sb.append(visibilityToString(this.visibility)); |
| 2733 | if (this.publicVersion != null) { |
| 2734 | sb.append(" publicVersion="); |
| 2735 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2736 | } |
| 2737 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | return sb.toString(); |
| 2739 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2740 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2741 | /** |
| 2742 | * {@hide} |
| 2743 | */ |
| 2744 | public static String visibilityToString(int vis) { |
| 2745 | switch (vis) { |
| 2746 | case VISIBILITY_PRIVATE: |
| 2747 | return "PRIVATE"; |
| 2748 | case VISIBILITY_PUBLIC: |
| 2749 | return "PUBLIC"; |
| 2750 | case VISIBILITY_SECRET: |
| 2751 | return "SECRET"; |
| 2752 | default: |
| 2753 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 2754 | } |
| 2755 | } |
| 2756 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2757 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 2758 | * {@hide} |
| 2759 | */ |
| 2760 | public static String priorityToString(@Priority int pri) { |
| 2761 | switch (pri) { |
| 2762 | case PRIORITY_MIN: |
| 2763 | return "MIN"; |
| 2764 | case PRIORITY_LOW: |
| 2765 | return "LOW"; |
| 2766 | case PRIORITY_DEFAULT: |
| 2767 | return "DEFAULT"; |
| 2768 | case PRIORITY_HIGH: |
| 2769 | return "HIGH"; |
| 2770 | case PRIORITY_MAX: |
| 2771 | return "MAX"; |
| 2772 | default: |
| 2773 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 2774 | } |
| 2775 | } |
| 2776 | |
Julia Reynolds | 6ad0aec | 2017-07-05 08:47:03 -0400 | [diff] [blame] | 2777 | /** |
| 2778 | * @hide |
| 2779 | */ |
| 2780 | public boolean hasCompletedProgress() { |
| 2781 | // not a progress notification; can't be complete |
| 2782 | if (!extras.containsKey(EXTRA_PROGRESS) |
| 2783 | || !extras.containsKey(EXTRA_PROGRESS_MAX)) { |
| 2784 | return false; |
| 2785 | } |
| 2786 | // many apps use max 0 for 'indeterminate'; not complete |
| 2787 | if (extras.getInt(EXTRA_PROGRESS_MAX) == 0) { |
| 2788 | return false; |
| 2789 | } |
| 2790 | return extras.getInt(EXTRA_PROGRESS) == extras.getInt(EXTRA_PROGRESS_MAX); |
| 2791 | } |
| 2792 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2793 | /** @removed */ |
| 2794 | @Deprecated |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 2795 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2796 | return mChannelId; |
| 2797 | } |
| 2798 | |
| 2799 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2800 | * Returns the id of the channel this notification posts to. |
| 2801 | */ |
| 2802 | public String getChannelId() { |
| 2803 | return mChannelId; |
| 2804 | } |
| 2805 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2806 | /** @removed */ |
| 2807 | @Deprecated |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2808 | public long getTimeout() { |
| 2809 | return mTimeout; |
| 2810 | } |
| 2811 | |
| 2812 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2813 | * Returns the duration from posting after which this notification should be canceled by the |
| 2814 | * system, if it's not canceled already. |
| 2815 | */ |
| 2816 | public long getTimeoutAfter() { |
| 2817 | return mTimeout; |
| 2818 | } |
| 2819 | |
| 2820 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2821 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 2822 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 2823 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 2824 | */ |
| 2825 | public int getBadgeIconType() { |
| 2826 | return mBadgeIcon; |
| 2827 | } |
| 2828 | |
| 2829 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2830 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2831 | * |
| 2832 | * <p>Used by some Launchers that display notification content to hide shortcuts that duplicate |
| 2833 | * notifications. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2834 | */ |
| 2835 | public String getShortcutId() { |
| 2836 | return mShortcutId; |
| 2837 | } |
| 2838 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2839 | |
| 2840 | /** |
| 2841 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 2842 | */ |
| 2843 | public CharSequence getSettingsText() { |
| 2844 | return mSettingsText; |
| 2845 | } |
| 2846 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2847 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2848 | * Returns which type of notifications in a group are responsible for audibly alerting the |
| 2849 | * user. See {@link #GROUP_ALERT_ALL}, {@link #GROUP_ALERT_CHILDREN}, |
| 2850 | * {@link #GROUP_ALERT_SUMMARY}. |
| 2851 | */ |
| 2852 | public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 2853 | return mGroupAlertBehavior; |
| 2854 | } |
| 2855 | |
| 2856 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2857 | * The small icon representing this notification in the status bar and content view. |
| 2858 | * |
| 2859 | * @return the small icon representing this notification. |
| 2860 | * |
| 2861 | * @see Builder#getSmallIcon() |
| 2862 | * @see Builder#setSmallIcon(Icon) |
| 2863 | */ |
| 2864 | public Icon getSmallIcon() { |
| 2865 | return mSmallIcon; |
| 2866 | } |
| 2867 | |
| 2868 | /** |
| 2869 | * Used when notifying to clean up legacy small icons. |
| 2870 | * @hide |
| 2871 | */ |
| 2872 | public void setSmallIcon(Icon icon) { |
| 2873 | mSmallIcon = icon; |
| 2874 | } |
| 2875 | |
| 2876 | /** |
| 2877 | * The large icon shown in this notification's content view. |
| 2878 | * @see Builder#getLargeIcon() |
| 2879 | * @see Builder#setLargeIcon(Icon) |
| 2880 | */ |
| 2881 | public Icon getLargeIcon() { |
| 2882 | return mLargeIcon; |
| 2883 | } |
| 2884 | |
| 2885 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2886 | * @hide |
| 2887 | */ |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 2888 | public boolean isGroupSummary() { |
| 2889 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 2890 | } |
| 2891 | |
| 2892 | /** |
| 2893 | * @hide |
| 2894 | */ |
| 2895 | public boolean isGroupChild() { |
| 2896 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 2897 | } |
| 2898 | |
| 2899 | /** |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 2900 | * @hide |
| 2901 | */ |
| 2902 | public boolean suppressAlertingDueToGrouping() { |
| 2903 | if (isGroupSummary() |
| 2904 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { |
| 2905 | return true; |
| 2906 | } else if (isGroupChild() |
| 2907 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { |
| 2908 | return true; |
| 2909 | } |
| 2910 | return false; |
| 2911 | } |
| 2912 | |
| 2913 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2914 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2915 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2916 | * 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] | 2917 | * content views using the platform's notification layout template. If your app supports |
| 2918 | * versions of Android as old as API level 4, you can instead use |
| 2919 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 2920 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 2921 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2922 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2923 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2924 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2925 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2926 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2927 | * .setContentTitle("New mail from " + sender.toString()) |
| 2928 | * .setContentText(subject) |
| 2929 | * .setSmallIcon(R.drawable.new_mail) |
| 2930 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2931 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2932 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2933 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2934 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 2935 | /** |
| 2936 | * @hide |
| 2937 | */ |
| 2938 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 2939 | "android.rebuild.contentViewActionCount"; |
| 2940 | /** |
| 2941 | * @hide |
| 2942 | */ |
| 2943 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 2944 | = "android.rebuild.bigViewActionCount"; |
| 2945 | /** |
| 2946 | * @hide |
| 2947 | */ |
| 2948 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 2949 | = "android.rebuild.hudViewActionCount"; |
| 2950 | |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 2951 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2952 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 2953 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 2954 | SystemProperties.getBoolean("notifications.only_title", true); |
| 2955 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 2956 | /** |
| 2957 | * The lightness difference that has to be added to the primary text color to obtain the |
| 2958 | * secondary text color when the background is light. |
| 2959 | */ |
| 2960 | private static final int LIGHTNESS_TEXT_DIFFERENCE_LIGHT = 20; |
| 2961 | |
| 2962 | /** |
| 2963 | * The lightness difference that has to be added to the primary text color to obtain the |
| 2964 | * secondary text color when the background is dark. |
| 2965 | * A bit less then the above value, since it looks better on dark backgrounds. |
| 2966 | */ |
| 2967 | private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10; |
| 2968 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2969 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2970 | private Notification mN; |
| 2971 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2972 | private Style mStyle; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2973 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 2974 | private ArrayList<Person> mPersonList = new ArrayList<>(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2975 | private NotificationColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 2976 | private boolean mIsLegacy; |
| 2977 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2978 | |
| 2979 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2980 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 2981 | */ |
| 2982 | private int mCachedContrastColor = COLOR_INVALID; |
| 2983 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 2984 | /** |
| 2985 | * Caches a ambient version of {@link #mCachedContrastColorIsFor}. |
| 2986 | */ |
| 2987 | private int mCachedAmbientColor = COLOR_INVALID; |
| 2988 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2989 | |
| 2990 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 2991 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 2992 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 2993 | */ |
| 2994 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 2995 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 2996 | private int mPrimaryTextColor = COLOR_INVALID; |
| 2997 | private int mSecondaryTextColor = COLOR_INVALID; |
| 2998 | private int mActionBarColor = COLOR_INVALID; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 2999 | private int mBackgroundColor = COLOR_INVALID; |
| 3000 | private int mForegroundColor = COLOR_INVALID; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 3001 | private int mBackgroundColorHint = COLOR_INVALID; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 3002 | /** |
| 3003 | * A temporary location where actions are stored. If != null the view originally has action |
| 3004 | * but doesn't have any for this inflation. |
| 3005 | */ |
| 3006 | private ArrayList<Action> mOriginalActions; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 3007 | private boolean mRebuildStyledRemoteViews; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3008 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3009 | private boolean mTintActionButtons; |
| 3010 | private boolean mInNightMode; |
| 3011 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3012 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3013 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3014 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3015 | * @param context |
| 3016 | * A {@link Context} that will be used by the Builder to construct the |
| 3017 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 3018 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3019 | * @param channelId |
| 3020 | * The constructed Notification will be posted on this |
| 3021 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 3022 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3023 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3024 | public Builder(Context context, String channelId) { |
| 3025 | this(context, (Notification) null); |
| 3026 | mN.mChannelId = channelId; |
| 3027 | } |
| 3028 | |
| 3029 | /** |
| 3030 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 3031 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 3032 | */ |
| 3033 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3034 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 3035 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3036 | } |
| 3037 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3038 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3039 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3040 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3041 | public Builder(Context context, Notification toAdopt) { |
| 3042 | mContext = context; |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 3043 | Resources res = mContext.getResources(); |
| 3044 | mTintActionButtons = res.getBoolean(R.bool.config_tintNotificationActionButtons); |
| 3045 | |
| 3046 | if (res.getBoolean(R.bool.config_enableNightMode)) { |
| 3047 | Configuration currentConfig = res.getConfiguration(); |
| 3048 | mInNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 3049 | == Configuration.UI_MODE_NIGHT_YES; |
| 3050 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3051 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3052 | if (toAdopt == null) { |
| 3053 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3054 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 3055 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 3056 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3057 | mN.priority = PRIORITY_DEFAULT; |
| 3058 | mN.visibility = VISIBILITY_PRIVATE; |
| 3059 | } else { |
| 3060 | mN = toAdopt; |
| 3061 | if (mN.actions != null) { |
| 3062 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3063 | } |
| 3064 | |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3065 | if (mN.extras.containsKey(EXTRA_PEOPLE_LIST)) { |
| 3066 | ArrayList<Person> people = mN.extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 3067 | mPersonList.addAll(people); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3068 | } |
| 3069 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 3070 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 3071 | setSmallIcon(mN.icon); |
| 3072 | } |
| 3073 | |
| 3074 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 3075 | setLargeIcon(mN.largeIcon); |
| 3076 | } |
| 3077 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3078 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 3079 | if (!TextUtils.isEmpty(templateClass)) { |
| 3080 | final Class<? extends Style> styleClass |
| 3081 | = getNotificationStyleClass(templateClass); |
| 3082 | if (styleClass == null) { |
| 3083 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 3084 | } else { |
| 3085 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3086 | final Constructor<? extends Style> ctor = |
| 3087 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3088 | ctor.setAccessible(true); |
| 3089 | final Style style = ctor.newInstance(); |
| 3090 | style.restoreFromExtras(mN.extras); |
| 3091 | |
| 3092 | if (style != null) { |
| 3093 | setStyle(style); |
| 3094 | } |
| 3095 | } catch (Throwable t) { |
| 3096 | Log.e(TAG, "Could not create Style", t); |
| 3097 | } |
| 3098 | } |
| 3099 | } |
| 3100 | |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | private NotificationColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3105 | if (mColorUtil == null) { |
| 3106 | mColorUtil = NotificationColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3107 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3108 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3112 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 3113 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 3114 | * the shortcut. |
| 3115 | * |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3116 | * This field will be ignored by Launchers that don't support badging, don't show |
| 3117 | * notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3118 | * |
| 3119 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 3120 | * supersedes |
| 3121 | */ |
| 3122 | public Builder setShortcutId(String shortcutId) { |
| 3123 | mN.mShortcutId = shortcutId; |
| 3124 | return this; |
| 3125 | } |
| 3126 | |
| 3127 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3128 | * Sets which icon to display as a badge for this notification. |
| 3129 | * |
| 3130 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 3131 | * {@link #BADGE_ICON_LARGE}. |
| 3132 | * |
| 3133 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 3134 | */ |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 3135 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3136 | mN.mBadgeIcon = icon; |
| 3137 | return this; |
| 3138 | } |
| 3139 | |
| 3140 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 3141 | * Sets the group alert behavior for this notification. Use this method to mute this |
| 3142 | * notification if alerts for this notification's group should be handled by a different |
| 3143 | * notification. This is only applicable for notifications that belong to a |
Julia Reynolds | 399d9bf | 2017-08-11 12:52:14 -0400 | [diff] [blame] | 3144 | * {@link #setGroup(String) group}. This must be called on all notifications you want to |
| 3145 | * mute. For example, if you want only the summary of your group to make noise, all |
| 3146 | * 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] | 3147 | * |
| 3148 | * <p> The default value is {@link #GROUP_ALERT_ALL}.</p> |
| 3149 | */ |
| 3150 | public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 3151 | mN.mGroupAlertBehavior = groupAlertBehavior; |
| 3152 | return this; |
| 3153 | } |
| 3154 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3155 | /** @removed */ |
| 3156 | @Deprecated |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 3157 | public Builder setChannel(String channelId) { |
| 3158 | mN.mChannelId = channelId; |
| 3159 | return this; |
| 3160 | } |
| 3161 | |
| 3162 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3163 | * Specifies the channel the notification should be delivered on. |
| 3164 | */ |
| 3165 | public Builder setChannelId(String channelId) { |
| 3166 | mN.mChannelId = channelId; |
| 3167 | return this; |
| 3168 | } |
| 3169 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 3170 | /** @removed */ |
| 3171 | @Deprecated |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 3172 | public Builder setTimeout(long durationMs) { |
| 3173 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 3174 | return this; |
| 3175 | } |
| 3176 | |
| 3177 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 3178 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 3179 | * if it is not already canceled. |
| 3180 | */ |
| 3181 | public Builder setTimeoutAfter(long durationMs) { |
| 3182 | mN.mTimeout = durationMs; |
| 3183 | return this; |
| 3184 | } |
| 3185 | |
| 3186 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3187 | * 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] | 3188 | * |
| 3189 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 3190 | * shown anymore by default and must be opted into by using |
| 3191 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3192 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3193 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3194 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3195 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3196 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3197 | return this; |
| 3198 | } |
| 3199 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3200 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 3201 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3202 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 3203 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 3204 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3205 | */ |
| 3206 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3207 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 3208 | return this; |
| 3209 | } |
| 3210 | |
| 3211 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3212 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3213 | * |
| 3214 | * 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] | 3215 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3216 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3217 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 3218 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3219 | * 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] | 3220 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3221 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 3222 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3223 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3224 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3225 | */ |
| 3226 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3227 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 3228 | return this; |
| 3229 | } |
| 3230 | |
| 3231 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3232 | * Sets the Chronometer to count down instead of counting up. |
| 3233 | * |
| 3234 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 3235 | * If it isn't set the chronometer will count up. |
| 3236 | * |
| 3237 | * @see #setUsesChronometer(boolean) |
| 3238 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3239 | public Builder setChronometerCountDown(boolean countDown) { |
| 3240 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 3241 | return this; |
| 3242 | } |
| 3243 | |
| 3244 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3245 | * Set the small icon resource, which will be used to represent the notification in the |
| 3246 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3247 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3248 | |
| 3249 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 3250 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 3251 | * icon will be moved to the right-hand side. |
| 3252 | * |
| 3253 | |
| 3254 | * @param icon |
| 3255 | * A resource ID in the application's package of the drawable to use. |
| 3256 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3257 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3258 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3259 | return setSmallIcon(icon != 0 |
| 3260 | ? Icon.createWithResource(mContext, icon) |
| 3261 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3262 | } |
| 3263 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3264 | /** |
| 3265 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 3266 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 3267 | * LevelListDrawable}. |
| 3268 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3269 | * @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] | 3270 | * @param level The level to use for the icon. |
| 3271 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3272 | * @see Notification#icon |
| 3273 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3274 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3275 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3276 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3277 | return setSmallIcon(icon); |
| 3278 | } |
| 3279 | |
| 3280 | /** |
| 3281 | * Set the small icon, which will be used to represent the notification in the |
| 3282 | * status bar and content view (unless overriden there by a |
| 3283 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 3284 | * |
| 3285 | * @param icon An Icon object to use. |
| 3286 | * @see Notification#icon |
| 3287 | */ |
| 3288 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3289 | mN.setSmallIcon(icon); |
| 3290 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 3291 | mN.icon = icon.getResId(); |
| 3292 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3293 | return this; |
| 3294 | } |
| 3295 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3296 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3297 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3298 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3299 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3300 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3301 | return this; |
| 3302 | } |
| 3303 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3304 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3305 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3306 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3307 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3308 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3309 | return this; |
| 3310 | } |
| 3311 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3312 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3313 | * This provides some additional information that is displayed in the notification. No |
| 3314 | * guarantees are given where exactly it is displayed. |
| 3315 | * |
| 3316 | * <p>This information should only be provided if it provides an essential |
| 3317 | * benefit to the understanding of the notification. The more text you provide the |
| 3318 | * less readable it becomes. For example, an email client should only provide the account |
| 3319 | * name here if more than one email account has been added.</p> |
| 3320 | * |
| 3321 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 3322 | * notification header area. |
| 3323 | * |
| 3324 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 3325 | * this will be shown in the third line of text in the platform notification template. |
| 3326 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 3327 | * same time on those versions; they occupy the same place. |
| 3328 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3329 | */ |
| 3330 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3331 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3332 | return this; |
| 3333 | } |
| 3334 | |
| 3335 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3336 | * Provides text that will appear as a link to your application's settings. |
| 3337 | * |
| 3338 | * <p>This text does not appear within notification {@link Style templates} but may |
| 3339 | * appear when the user uses an affordance to learn more about the notification. |
| 3340 | * Additionally, this text will not appear unless you provide a valid link target by |
| 3341 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 3342 | * |
| 3343 | * <p>This text is meant to be concise description about what the user can customize |
| 3344 | * when they click on this link. The recommended maximum length is 40 characters. |
| 3345 | * @param text |
| 3346 | * @return |
| 3347 | */ |
| 3348 | public Builder setSettingsText(CharSequence text) { |
| 3349 | mN.mSettingsText = safeCharSequence(text); |
| 3350 | return this; |
| 3351 | } |
| 3352 | |
| 3353 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3354 | * Set the remote input history. |
| 3355 | * |
| 3356 | * This should be set to the most recent inputs that have been sent |
| 3357 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 3358 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 3359 | * |
| 3360 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 3361 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 3362 | * and how much of each individual input is shown. |
| 3363 | * |
| 3364 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 3365 | * with a {@code RemoteInput}.</p> |
| 3366 | */ |
| 3367 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 3368 | if (text == null) { |
| 3369 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 3370 | } else { |
| 3371 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 3372 | CharSequence[] safe = new CharSequence[N]; |
| 3373 | for (int i = 0; i < N; i++) { |
| 3374 | safe[i] = safeCharSequence(text[i]); |
| 3375 | } |
| 3376 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 3377 | } |
| 3378 | return this; |
| 3379 | } |
| 3380 | |
| 3381 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3382 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 3383 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3384 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3385 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3386 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3387 | return this; |
| 3388 | } |
| 3389 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3390 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3391 | * A small piece of additional information pertaining to this notification. |
| 3392 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3393 | * The platform template will draw this on the last line of the notification, at the far |
| 3394 | * 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] | 3395 | * |
| 3396 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 3397 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 3398 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3399 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3400 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3401 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3402 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3403 | return this; |
| 3404 | } |
| 3405 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3406 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3407 | * Set the progress this notification represents. |
| 3408 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3409 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3410 | */ |
| 3411 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3412 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3413 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3414 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3415 | return this; |
| 3416 | } |
| 3417 | |
| 3418 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3419 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3420 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3421 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3422 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3423 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3424 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3425 | return setCustomContentView(views); |
| 3426 | } |
| 3427 | |
| 3428 | /** |
| 3429 | * Supply custom RemoteViews to use instead of the platform template. |
| 3430 | * |
| 3431 | * This will override the layout that would otherwise be constructed by this Builder |
| 3432 | * object. |
| 3433 | */ |
| 3434 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3435 | mN.contentView = contentView; |
| 3436 | return this; |
| 3437 | } |
| 3438 | |
| 3439 | /** |
| 3440 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3441 | * |
| 3442 | * This will override the expanded layout that would otherwise be constructed by this |
| 3443 | * Builder object. |
| 3444 | */ |
| 3445 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3446 | mN.bigContentView = contentView; |
| 3447 | return this; |
| 3448 | } |
| 3449 | |
| 3450 | /** |
| 3451 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3452 | * |
| 3453 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3454 | * Builder object. |
| 3455 | */ |
| 3456 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3457 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3458 | return this; |
| 3459 | } |
| 3460 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3461 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3462 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3463 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3464 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3465 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3466 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3467 | * 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] | 3468 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3469 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3470 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3471 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3472 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3473 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3474 | return this; |
| 3475 | } |
| 3476 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3477 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3478 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3479 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3480 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3481 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3482 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3483 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3484 | return this; |
| 3485 | } |
| 3486 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3487 | /** |
| 3488 | * An intent to launch instead of posting the notification to the status bar. |
| 3489 | * Only for use with extremely high-priority notifications demanding the user's |
| 3490 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3491 | * alarm clock that the user has explicitly set to a particular time. |
| 3492 | * If this facility is used for something else, please give the user an option |
| 3493 | * to turn it off and use a normal notification, as this can be extremely |
| 3494 | * disruptive. |
| 3495 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3496 | * <p> |
| 3497 | * The system UI may choose to display a heads-up notification, instead of |
| 3498 | * launching this intent, while the user is using the device. |
| 3499 | * </p> |
| 3500 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3501 | * @param intent The pending intent to launch. |
| 3502 | * @param highPriority Passing true will cause this notification to be sent |
| 3503 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3504 | * |
| 3505 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3506 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3507 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3508 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3509 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3510 | return this; |
| 3511 | } |
| 3512 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3513 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3514 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3515 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3516 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3517 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3518 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3519 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3520 | return this; |
| 3521 | } |
| 3522 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3523 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3524 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3525 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3526 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3527 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3528 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3529 | setTicker(tickerText); |
| 3530 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3531 | return this; |
| 3532 | } |
| 3533 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3534 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3535 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3536 | * |
| 3537 | * 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] | 3538 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3539 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3540 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3541 | public Builder setLargeIcon(Bitmap b) { |
| 3542 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3543 | } |
| 3544 | |
| 3545 | /** |
| 3546 | * Add a large icon to the notification content view. |
| 3547 | * |
| 3548 | * In the platform template, this image will be shown on the left of the notification view |
| 3549 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3550 | * badge atop the large icon). |
| 3551 | */ |
| 3552 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3553 | mN.mLargeIcon = icon; |
| 3554 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3555 | return this; |
| 3556 | } |
| 3557 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3558 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3559 | * Set the sound to play. |
| 3560 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3561 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 3562 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3563 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3564 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3565 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3566 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3567 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3568 | mN.sound = sound; |
| 3569 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -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 | * 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] | 3575 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3576 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 3577 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3578 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3579 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 3580 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3581 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 3582 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3583 | mN.sound = sound; |
| 3584 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3585 | return this; |
| 3586 | } |
| 3587 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3588 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3589 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 3590 | * use during playback. |
| 3591 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3592 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3593 | * @see Notification#sound |
| 3594 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3595 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3596 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3597 | mN.sound = sound; |
| 3598 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3599 | return this; |
| 3600 | } |
| 3601 | |
| 3602 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3603 | * Set the vibration pattern to use. |
| 3604 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3605 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 3606 | * <code>pattern</code> parameter. |
| 3607 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3608 | * <p> |
| 3609 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 3610 | * </p> |
| 3611 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3612 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3613 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3614 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3615 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3616 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3617 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3618 | return this; |
| 3619 | } |
| 3620 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3621 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3622 | * Set the desired color for the indicator LED on the device, as well as the |
| 3623 | * blink duty cycle (specified in milliseconds). |
| 3624 | * |
| 3625 | |
| 3626 | * Not all devices will honor all (or even any) of these values. |
| 3627 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3628 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3629 | * @see Notification#ledARGB |
| 3630 | * @see Notification#ledOnMS |
| 3631 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3632 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3633 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3634 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3635 | mN.ledARGB = argb; |
| 3636 | mN.ledOnMS = onMs; |
| 3637 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3638 | if (onMs != 0 || offMs != 0) { |
| 3639 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 3640 | } |
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 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3646 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3647 | |
| 3648 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 3649 | * must take care of canceling them. |
| 3650 | * |
| 3651 | |
| 3652 | * They are typically used to indicate a background task that the user is actively engaged |
| 3653 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 3654 | * (e.g., a file download, sync operation, active network connection). |
| 3655 | * |
| 3656 | |
| 3657 | * @see Notification#FLAG_ONGOING_EVENT |
| 3658 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3659 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3660 | public Builder setOngoing(boolean ongoing) { |
| 3661 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 3662 | return this; |
| 3663 | } |
| 3664 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3665 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3666 | * Set whether this notification should be colorized. When set, the color set with |
| 3667 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 3668 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3669 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 3670 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3671 | * <p> |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3672 | * For most styles, the coloring will only be applied if the notification is for a |
| 3673 | * foreground service notification. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3674 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3675 | * that have a media session attached there is no such requirement. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3676 | * |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3677 | * @see Builder#setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3678 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3679 | */ |
| 3680 | public Builder setColorized(boolean colorize) { |
| 3681 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 3682 | return this; |
| 3683 | } |
| 3684 | |
| 3685 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3686 | * Set this flag if you would only like the sound, vibrate |
| 3687 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3688 | * |
| 3689 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3690 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3691 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 3692 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 3693 | return this; |
| 3694 | } |
| 3695 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3696 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 3697 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3698 | * |
| 3699 | * @see Notification#FLAG_AUTO_CANCEL |
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 setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 3702 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
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 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3707 | * Set whether or not this notification should not bridge to other devices. |
| 3708 | * |
| 3709 | * <p>Some notifications can be bridged to other devices for remote display. |
| 3710 | * This hint can be set to recommend this notification not be bridged. |
| 3711 | */ |
| 3712 | public Builder setLocalOnly(boolean localOnly) { |
| 3713 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 3714 | return this; |
| 3715 | } |
| 3716 | |
| 3717 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3718 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3719 | * <p> |
| 3720 | * The value should be one or more of the following fields combined with |
| 3721 | * bitwise-or: |
| 3722 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 3723 | * <p> |
| 3724 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3725 | * |
| 3726 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3727 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3728 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3729 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3730 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3731 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3732 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3733 | return this; |
| 3734 | } |
| 3735 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3736 | /** |
| 3737 | * Set the priority of this notification. |
| 3738 | * |
| 3739 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3740 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3741 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3742 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3743 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3744 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3745 | return this; |
| 3746 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3747 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3748 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3749 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3750 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3751 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3752 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3753 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3754 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3755 | return this; |
| 3756 | } |
| 3757 | |
| 3758 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3759 | * Add a person that is relevant to this notification. |
| 3760 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3761 | * <P> |
| 3762 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3763 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 3764 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 3765 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3766 | * </P> |
| 3767 | * |
| 3768 | * <P> |
| 3769 | * The person should be specified by the {@code String} representation of a |
| 3770 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 3771 | * </P> |
| 3772 | * |
| 3773 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 3774 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 3775 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 3776 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3777 | * It is also possible to provide a URI with the schema {@code name:} in order to uniquely |
| 3778 | * identify a person without an entry in the contacts database. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3779 | * </P> |
| 3780 | * |
| 3781 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3782 | * @see Notification#EXTRA_PEOPLE |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3783 | * @deprecated use {@link #addPerson(Person)} |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3784 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3785 | public Builder addPerson(String uri) { |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 3786 | addPerson(new Person().setUri(uri)); |
| 3787 | return this; |
| 3788 | } |
| 3789 | |
| 3790 | /** |
| 3791 | * Add a person that is relevant to this notification. |
| 3792 | * |
| 3793 | * <P> |
| 3794 | * Depending on user preferences, this annotation may allow the notification to pass |
| 3795 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 3796 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 3797 | * appear more prominently in the user interface. |
| 3798 | * </P> |
| 3799 | * |
| 3800 | * <P> |
| 3801 | * A person should usually contain a uri in order to benefit from the ranking boost. |
| 3802 | * However, even if no uri is provided, it's beneficial to provide other people in the |
| 3803 | * notification, such that listeners and voice only devices can announce and handle them |
| 3804 | * properly. |
| 3805 | * </P> |
| 3806 | * |
| 3807 | * @param person the person to add. |
| 3808 | * @see Notification#EXTRA_PEOPLE_LIST |
| 3809 | */ |
| 3810 | public Builder addPerson(Person person) { |
| 3811 | mPersonList.add(person); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3812 | return this; |
| 3813 | } |
| 3814 | |
| 3815 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3816 | * Set this notification to be part of a group of notifications sharing the same key. |
| 3817 | * Grouped notifications may display in a cluster or stack on devices which |
| 3818 | * support such rendering. |
| 3819 | * |
| 3820 | * <p>To make this notification the summary for its group, also call |
| 3821 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 3822 | * {@link #setSortKey}. |
| 3823 | * @param groupKey The group key of the group. |
| 3824 | * @return this object for method chaining |
| 3825 | */ |
| 3826 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3827 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3828 | return this; |
| 3829 | } |
| 3830 | |
| 3831 | /** |
| 3832 | * Set this notification to be the group summary for a group of notifications. |
| 3833 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 3834 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 3835 | * 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] | 3836 | * @param isGroupSummary Whether this notification should be a group summary. |
| 3837 | * @return this object for method chaining |
| 3838 | */ |
| 3839 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 3840 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 3841 | return this; |
| 3842 | } |
| 3843 | |
| 3844 | /** |
| 3845 | * Set a sort key that orders this notification among other notifications from the |
| 3846 | * same package. This can be useful if an external sort was already applied and an app |
| 3847 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 3848 | * value, although providing different priorities in addition to providing sort key may |
| 3849 | * cause this value to be ignored. |
| 3850 | * |
| 3851 | * <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] | 3852 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3853 | * |
| 3854 | * @see String#compareTo(String) |
| 3855 | */ |
| 3856 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3857 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3858 | return this; |
| 3859 | } |
| 3860 | |
| 3861 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3862 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3863 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3864 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 3865 | * |
| 3866 | * @see Notification#extras |
| 3867 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3868 | public Builder addExtras(Bundle extras) { |
| 3869 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3870 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3871 | } |
| 3872 | return this; |
| 3873 | } |
| 3874 | |
| 3875 | /** |
| 3876 | * Set metadata for this notification. |
| 3877 | * |
| 3878 | * <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] | 3879 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3880 | * called. |
| 3881 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3882 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 3883 | * Use {@link #addExtras} to merge in metadata instead. |
| 3884 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3885 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3886 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3887 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3888 | if (extras != null) { |
| 3889 | mUserExtras = extras; |
| 3890 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3891 | return this; |
| 3892 | } |
| 3893 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3894 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3895 | * Get the current metadata Bundle used by this notification Builder. |
| 3896 | * |
| 3897 | * <p>The returned Bundle is shared with this Builder. |
| 3898 | * |
| 3899 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 3900 | * {@link #build()} is called. |
| 3901 | * |
| 3902 | * @see Notification#extras |
| 3903 | */ |
| 3904 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3905 | return mUserExtras; |
| 3906 | } |
| 3907 | |
| 3908 | private Bundle getAllExtras() { |
| 3909 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 3910 | saveExtras.putAll(mN.extras); |
| 3911 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3915 | * Add an action to this notification. Actions are typically displayed by |
| 3916 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3917 | * <p> |
| 3918 | * Every action must have an icon (32dp square and matching the |
| 3919 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 3920 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 3921 | * <p> |
| 3922 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 3923 | * the order they were added. Actions will not be displayed when the notification is |
| 3924 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 3925 | * 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] | 3926 | * |
| 3927 | * @param icon Resource ID of a drawable that represents the action. |
| 3928 | * @param title Text describing the action. |
| 3929 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 3930 | * |
| 3931 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3932 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 3933 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3934 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3935 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3936 | return this; |
| 3937 | } |
| 3938 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3939 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3940 | * Add an action to this notification. Actions are typically displayed by |
| 3941 | * the system as a button adjacent to the notification content. |
| 3942 | * <p> |
| 3943 | * Every action must have an icon (32dp square and matching the |
| 3944 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 3945 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 3946 | * <p> |
| 3947 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 3948 | * the order they were added. Actions will not be displayed when the notification is |
| 3949 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 3950 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 3951 | * |
| 3952 | * @param action The action to add. |
| 3953 | */ |
| 3954 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 3955 | if (action != null) { |
| 3956 | mActions.add(action); |
| 3957 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3958 | return this; |
| 3959 | } |
| 3960 | |
| 3961 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3962 | * Alter the complete list of actions attached to this notification. |
| 3963 | * @see #addAction(Action). |
| 3964 | * |
| 3965 | * @param actions |
| 3966 | * @return |
| 3967 | */ |
| 3968 | public Builder setActions(Action... actions) { |
| 3969 | mActions.clear(); |
| 3970 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 3971 | if (actions[i] != null) { |
| 3972 | mActions.add(actions[i]); |
| 3973 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3974 | } |
| 3975 | return this; |
| 3976 | } |
| 3977 | |
| 3978 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3979 | * Add a rich notification style to be applied at build time. |
| 3980 | * |
| 3981 | * @param style Object responsible for modifying the notification style. |
| 3982 | */ |
| 3983 | public Builder setStyle(Style style) { |
| 3984 | if (mStyle != style) { |
| 3985 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3986 | if (mStyle != null) { |
| 3987 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3988 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 3989 | } else { |
| 3990 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3991 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3992 | } |
| 3993 | return this; |
| 3994 | } |
| 3995 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3996 | /** |
| 3997 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 3998 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3999 | * @return The same Builder. |
| 4000 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 4001 | public Builder setVisibility(@Visibility int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4002 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4003 | return this; |
| 4004 | } |
| 4005 | |
| 4006 | /** |
| 4007 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 4008 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 4009 | * @param n A replacement notification, presumably with some or all info redacted. |
| 4010 | * @return The same Builder. |
| 4011 | */ |
| 4012 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4013 | if (n != null) { |
| 4014 | mN.publicVersion = new Notification(); |
| 4015 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 4016 | } else { |
| 4017 | mN.publicVersion = null; |
| 4018 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4019 | return this; |
| 4020 | } |
| 4021 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 4022 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4023 | * Apply an extender to this notification builder. Extenders may be used to add |
| 4024 | * metadata or change options on this builder. |
| 4025 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4026 | public Builder extend(Extender extender) { |
| 4027 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 4028 | return this; |
| 4029 | } |
| 4030 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 4031 | /** |
| 4032 | * @hide |
| 4033 | */ |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4034 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4035 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4036 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4037 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4038 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4039 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 4040 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4041 | } |
| 4042 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4043 | /** |
| 4044 | * Sets {@link Notification#color}. |
| 4045 | * |
| 4046 | * @param argb The accent color to use |
| 4047 | * |
| 4048 | * @return The same Builder. |
| 4049 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 4050 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4051 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4052 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4053 | return this; |
| 4054 | } |
| 4055 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4056 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 4057 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 4058 | // This user can never be a badged profile, |
| 4059 | // and also includes USER_ALL system notifications. |
| 4060 | return null; |
| 4061 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 4062 | // Note: This assumes that the current user can read the profile badge of the |
| 4063 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 4064 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4065 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | private Bitmap getProfileBadge() { |
| 4069 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4070 | if (badge == null) { |
| 4071 | return null; |
| 4072 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4073 | final int size = mContext.getResources().getDimensionPixelSize( |
| 4074 | R.dimen.notification_badge_size); |
| 4075 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4076 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4077 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 4078 | badge.draw(canvas); |
| 4079 | return bitmap; |
| 4080 | } |
| 4081 | |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4082 | private void bindProfileBadge(RemoteViews contentView) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4083 | Bitmap profileBadge = getProfileBadge(); |
| 4084 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4085 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4086 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 4087 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4088 | if (isColorized()) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4089 | contentView.setDrawableTint(R.id.profile_badge, false, |
| 4090 | getPrimaryTextColor(), PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4091 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4092 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4093 | } |
| 4094 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4095 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4096 | resetNotificationHeader(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4097 | resetContentMargins(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4098 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4099 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4100 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4101 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4102 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4103 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4104 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4105 | } |
| 4106 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4107 | /** |
| 4108 | * Resets the notification header to its original state |
| 4109 | */ |
| 4110 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 4111 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 4112 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 4113 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4114 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 4115 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4116 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 4117 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4118 | contentView.setViewVisibility(R.id.header_text_secondary, View.GONE); |
| 4119 | contentView.setTextViewText(R.id.header_text_secondary, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4120 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4121 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4122 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4123 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4124 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 4125 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4126 | } |
| 4127 | |
| 4128 | private void resetContentMargins(RemoteViews contentView) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 4129 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 4130 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4131 | } |
| 4132 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4133 | private RemoteViews applyStandardTemplate(int resId) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4134 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this)); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | /** |
| 4138 | * @param hasProgress whether the progress bar should be shown and set |
| 4139 | */ |
| 4140 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4141 | return applyStandardTemplate(resId, mParams.reset().hasProgress(hasProgress) |
| 4142 | .fillTextsFrom(this)); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 4143 | } |
| 4144 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4145 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 4146 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 4147 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4148 | resetStandardTemplate(contentView); |
| 4149 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4150 | final Bundle ex = mN.extras; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4151 | updateBackgroundColor(contentView); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4152 | bindNotificationHeader(contentView, p.ambient, p.headerTextSecondary); |
Lucas Dupin | 90158d0 | 2018-01-23 16:36:12 -0800 | [diff] [blame] | 4153 | bindLargeIcon(contentView, p.hideLargeIcon || p.ambient, p.alwaysShowReply); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4154 | boolean showProgress = handleProgressBar(p.hasProgress, contentView, ex); |
| 4155 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4156 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4157 | contentView.setTextViewText(R.id.title, processTextSpans(p.title)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4158 | if (!p.ambient) { |
| 4159 | setTextViewColorPrimary(contentView, R.id.title); |
| 4160 | } |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 4161 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 4162 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 4163 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4164 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4165 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4166 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 4167 | : com.android.internal.R.id.text; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4168 | contentView.setTextViewText(textId, processTextSpans(p.text)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4169 | if (!p.ambient) { |
| 4170 | setTextViewColorSecondary(contentView, textId); |
| 4171 | } |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 4172 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4173 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 4174 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4175 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4176 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4177 | return contentView; |
| 4178 | } |
| 4179 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4180 | private CharSequence processTextSpans(CharSequence text) { |
| 4181 | if (hasForegroundColor()) { |
Selim Cinek | 87c3153 | 2017-08-18 18:53:44 -0700 | [diff] [blame] | 4182 | return NotificationColorUtil.clearColorSpans(text); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4183 | } |
| 4184 | return text; |
| 4185 | } |
| 4186 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4187 | private void setTextViewColorPrimary(RemoteViews contentView, int id) { |
| 4188 | ensureColors(); |
| 4189 | contentView.setTextColor(id, mPrimaryTextColor); |
| 4190 | } |
| 4191 | |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4192 | private boolean hasForegroundColor() { |
| 4193 | return mForegroundColor != COLOR_INVALID; |
| 4194 | } |
| 4195 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4196 | /** |
| 4197 | * @return the primary text color |
| 4198 | * @hide |
| 4199 | */ |
| 4200 | @VisibleForTesting |
| 4201 | public int getPrimaryTextColor() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4202 | ensureColors(); |
| 4203 | return mPrimaryTextColor; |
| 4204 | } |
| 4205 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4206 | /** |
| 4207 | * @return the secondary text color |
| 4208 | * @hide |
| 4209 | */ |
| 4210 | @VisibleForTesting |
| 4211 | public int getSecondaryTextColor() { |
| 4212 | ensureColors(); |
| 4213 | return mSecondaryTextColor; |
| 4214 | } |
| 4215 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4216 | private int getActionBarColor() { |
| 4217 | ensureColors(); |
| 4218 | return mActionBarColor; |
| 4219 | } |
| 4220 | |
Selim Cinek | 622c64a | 2017-04-17 17:10:05 -0700 | [diff] [blame] | 4221 | private int getActionBarColorDeEmphasized() { |
| 4222 | int backgroundColor = getBackgroundColor(); |
| 4223 | return NotificationColorUtil.getShiftedColor(backgroundColor, 12); |
| 4224 | } |
| 4225 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4226 | private void setTextViewColorSecondary(RemoteViews contentView, int id) { |
| 4227 | ensureColors(); |
| 4228 | contentView.setTextColor(id, mSecondaryTextColor); |
| 4229 | } |
| 4230 | |
| 4231 | private void ensureColors() { |
| 4232 | int backgroundColor = getBackgroundColor(); |
| 4233 | if (mPrimaryTextColor == COLOR_INVALID |
| 4234 | || mSecondaryTextColor == COLOR_INVALID |
| 4235 | || mActionBarColor == COLOR_INVALID |
| 4236 | || mTextColorsAreForBackground != backgroundColor) { |
| 4237 | mTextColorsAreForBackground = backgroundColor; |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4238 | if (!hasForegroundColor() || !isColorized()) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4239 | mPrimaryTextColor = NotificationColorUtil.resolvePrimaryColor(mContext, |
| 4240 | backgroundColor); |
| 4241 | mSecondaryTextColor = NotificationColorUtil.resolveSecondaryColor(mContext, |
| 4242 | backgroundColor); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4243 | if (backgroundColor != COLOR_DEFAULT |
| 4244 | && (mBackgroundColorHint != COLOR_INVALID || isColorized())) { |
| 4245 | mPrimaryTextColor = NotificationColorUtil.findAlphaToMeetContrast( |
| 4246 | mPrimaryTextColor, backgroundColor, 4.5); |
| 4247 | mSecondaryTextColor = NotificationColorUtil.findAlphaToMeetContrast( |
| 4248 | mSecondaryTextColor, backgroundColor, 4.5); |
| 4249 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4250 | } else { |
| 4251 | double backLum = NotificationColorUtil.calculateLuminance(backgroundColor); |
| 4252 | double textLum = NotificationColorUtil.calculateLuminance(mForegroundColor); |
| 4253 | double contrast = NotificationColorUtil.calculateContrast(mForegroundColor, |
| 4254 | backgroundColor); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4255 | // We only respect the given colors if worst case Black or White still has |
| 4256 | // contrast |
| 4257 | boolean backgroundLight = backLum > textLum |
| 4258 | && satisfiesTextContrast(backgroundColor, Color.BLACK) |
| 4259 | || backLum <= textLum |
| 4260 | && !satisfiesTextContrast(backgroundColor, Color.WHITE); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4261 | if (contrast < 4.5f) { |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4262 | if (backgroundLight) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4263 | mSecondaryTextColor = NotificationColorUtil.findContrastColor( |
| 4264 | mForegroundColor, |
| 4265 | backgroundColor, |
| 4266 | true /* findFG */, |
| 4267 | 4.5f); |
| 4268 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4269 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_LIGHT); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4270 | } else { |
| 4271 | mSecondaryTextColor = |
| 4272 | NotificationColorUtil.findContrastColorAgainstDark( |
| 4273 | mForegroundColor, |
| 4274 | backgroundColor, |
| 4275 | true /* findFG */, |
| 4276 | 4.5f); |
| 4277 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4278 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4279 | } |
| 4280 | } else { |
| 4281 | mPrimaryTextColor = mForegroundColor; |
| 4282 | mSecondaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4283 | mPrimaryTextColor, backgroundLight ? LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4284 | : LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4285 | if (NotificationColorUtil.calculateContrast(mSecondaryTextColor, |
| 4286 | backgroundColor) < 4.5f) { |
| 4287 | // oh well the secondary is not good enough |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4288 | if (backgroundLight) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4289 | mSecondaryTextColor = NotificationColorUtil.findContrastColor( |
| 4290 | mSecondaryTextColor, |
| 4291 | backgroundColor, |
| 4292 | true /* findFG */, |
| 4293 | 4.5f); |
| 4294 | } else { |
| 4295 | mSecondaryTextColor |
| 4296 | = NotificationColorUtil.findContrastColorAgainstDark( |
| 4297 | mSecondaryTextColor, |
| 4298 | backgroundColor, |
| 4299 | true /* findFG */, |
| 4300 | 4.5f); |
| 4301 | } |
| 4302 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4303 | mSecondaryTextColor, backgroundLight |
| 4304 | ? -LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4305 | : -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4306 | } |
| 4307 | } |
| 4308 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 4309 | mActionBarColor = NotificationColorUtil.resolveActionBarColor(mContext, |
| 4310 | backgroundColor); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | private void updateBackgroundColor(RemoteViews contentView) { |
| 4315 | if (isColorized()) { |
| 4316 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
| 4317 | getBackgroundColor()); |
| 4318 | } else { |
| 4319 | // Clear it! |
| 4320 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 4321 | 0); |
| 4322 | } |
| 4323 | } |
| 4324 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4325 | /** |
| 4326 | * @param remoteView the remote view to update the minheight in |
| 4327 | * @param hasMinHeight does it have a mimHeight |
| 4328 | * @hide |
| 4329 | */ |
| 4330 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 4331 | int minHeight = 0; |
| 4332 | if (hasMinHeight) { |
| 4333 | // we need to set the minHeight of the notification |
| 4334 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 4335 | com.android.internal.R.dimen.notification_min_content_height); |
| 4336 | } |
| 4337 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 4338 | } |
| 4339 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4340 | private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4341 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4342 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 4343 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 4344 | if (hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4345 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4346 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4347 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4348 | contentView.setProgressBackgroundTintList( |
| 4349 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 4350 | R.color.notification_progress_background_color))); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4351 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4352 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4353 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 4354 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4355 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4356 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4357 | } else { |
| 4358 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4359 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 4360 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4361 | } |
| 4362 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4363 | private void bindLargeIcon(RemoteViews contentView, boolean hideLargeIcon, |
| 4364 | boolean alwaysShowReply) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4365 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 4366 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 4367 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4368 | boolean showLargeIcon = mN.mLargeIcon != null && !hideLargeIcon; |
| 4369 | if (showLargeIcon) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4370 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 4371 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
| 4372 | processLargeLegacyIcon(mN.mLargeIcon, contentView); |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 4373 | int endMargin = R.dimen.notification_content_picture_margin; |
| 4374 | contentView.setViewLayoutMarginEndDimen(R.id.line1, endMargin); |
| 4375 | contentView.setViewLayoutMarginEndDimen(R.id.text, endMargin); |
| 4376 | contentView.setViewLayoutMarginEndDimen(R.id.progress, endMargin); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4377 | } |
| 4378 | // Bind the reply action |
| 4379 | Action action = findReplyAction(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4380 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4381 | boolean actionVisible = action != null && (showLargeIcon || alwaysShowReply); |
| 4382 | int replyId = showLargeIcon ? R.id.reply_icon_action : R.id.right_icon; |
| 4383 | if (actionVisible) { |
| 4384 | // We're only showing the icon as big if we're hiding the large icon |
| 4385 | int contrastColor = resolveContrastColor(); |
| 4386 | int iconColor; |
| 4387 | if (showLargeIcon) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4388 | contentView.setDrawableTint(R.id.reply_icon_action, |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4389 | true /* targetBackground */, |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4390 | contrastColor, PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4391 | contentView.setOnClickPendingIntent(R.id.right_icon, |
| 4392 | action.actionIntent); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4393 | contentView.setRemoteInputs(R.id.right_icon, action.mRemoteInputs); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4394 | iconColor = NotificationColorUtil.isColorLight(contrastColor) |
| 4395 | ? Color.BLACK : Color.WHITE; |
| 4396 | } else { |
| 4397 | contentView.setImageViewResource(R.id.right_icon, |
| 4398 | R.drawable.ic_reply_notification_large); |
| 4399 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 4400 | iconColor = contrastColor; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4401 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4402 | contentView.setDrawableTint(replyId, |
| 4403 | false /* targetBackground */, |
| 4404 | iconColor, |
| 4405 | PorterDuff.Mode.SRC_ATOP); |
| 4406 | contentView.setOnClickPendingIntent(replyId, |
| 4407 | action.actionIntent); |
| 4408 | contentView.setRemoteInputs(replyId, action.mRemoteInputs); |
| 4409 | } else { |
| 4410 | contentView.setRemoteInputs(R.id.right_icon, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4411 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 4412 | contentView.setViewVisibility(R.id.reply_icon_action, actionVisible && showLargeIcon |
| 4413 | ? View.VISIBLE |
| 4414 | : View.GONE); |
| 4415 | contentView.setViewVisibility(R.id.right_icon_container, actionVisible || showLargeIcon |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4416 | ? View.VISIBLE |
| 4417 | : View.GONE); |
| 4418 | } |
| 4419 | |
| 4420 | private Action findReplyAction() { |
| 4421 | ArrayList<Action> actions = mActions; |
| 4422 | if (mOriginalActions != null) { |
| 4423 | actions = mOriginalActions; |
| 4424 | } |
| 4425 | int numActions = actions.size(); |
| 4426 | for (int i = 0; i < numActions; i++) { |
| 4427 | Action action = actions.get(i); |
| 4428 | if (hasValidRemoteInput(action)) { |
| 4429 | return action; |
| 4430 | } |
| 4431 | } |
| 4432 | return null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4433 | } |
| 4434 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4435 | private void bindNotificationHeader(RemoteViews contentView, boolean ambient, |
| 4436 | CharSequence secondaryHeaderText) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4437 | bindSmallIcon(contentView, ambient); |
| 4438 | bindHeaderAppName(contentView, ambient); |
| 4439 | if (!ambient) { |
| 4440 | // Ambient view does not have these |
| 4441 | bindHeaderText(contentView); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4442 | bindHeaderTextSecondary(contentView, secondaryHeaderText); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4443 | bindHeaderChronometerAndTime(contentView); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4444 | bindProfileBadge(contentView); |
| 4445 | } |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 4446 | bindExpandButton(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | private void bindExpandButton(RemoteViews contentView) { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4450 | int color = getPrimaryHighlightColor(); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4451 | contentView.setDrawableTint(R.id.expand_button, false, color, |
| 4452 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4453 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4454 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4455 | } |
| 4456 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4457 | /** |
| 4458 | * @return the color that is used as the first primary highlight color. This is applied |
| 4459 | * in several places like the action buttons or the app name in the header. |
| 4460 | */ |
| 4461 | private int getPrimaryHighlightColor() { |
| 4462 | return isColorized() ? getPrimaryTextColor() : resolveContrastColor(); |
| 4463 | } |
| 4464 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4465 | private void bindHeaderChronometerAndTime(RemoteViews contentView) { |
| 4466 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4467 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4468 | setTextViewColorSecondary(contentView, R.id.time_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4469 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 4470 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 4471 | contentView.setLong(R.id.chronometer, "setBase", |
| 4472 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 4473 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4474 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 4475 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4476 | setTextViewColorSecondary(contentView, R.id.chronometer); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4477 | } else { |
| 4478 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 4479 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4480 | setTextViewColorSecondary(contentView, R.id.time); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4481 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4482 | } else { |
| 4483 | // We still want a time to be set but gone, such that we can show and hide it |
| 4484 | // on demand in case it's a child notification without anything in the header |
| 4485 | 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] | 4486 | } |
| 4487 | } |
| 4488 | |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4489 | private void bindHeaderText(RemoteViews contentView) { |
| 4490 | CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 4491 | if (headerText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4492 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4493 | headerText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4494 | } |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4495 | if (headerText == null |
| 4496 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 4497 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 4498 | headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 4499 | } |
| 4500 | if (headerText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4501 | // 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] | 4502 | contentView.setTextViewText(R.id.header_text, processTextSpans( |
| 4503 | processLegacyText(headerText))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4504 | setTextViewColorSecondary(contentView, R.id.header_text); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4505 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 4506 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4507 | setTextViewColorSecondary(contentView, R.id.header_text_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4508 | } |
| 4509 | } |
| 4510 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4511 | private void bindHeaderTextSecondary(RemoteViews contentView, CharSequence secondaryText) { |
| 4512 | if (!TextUtils.isEmpty(secondaryText)) { |
| 4513 | contentView.setTextViewText(R.id.header_text_secondary, processTextSpans( |
| 4514 | processLegacyText(secondaryText))); |
| 4515 | setTextViewColorSecondary(contentView, R.id.header_text_secondary); |
| 4516 | contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE); |
| 4517 | contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE); |
| 4518 | setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider); |
| 4519 | } |
| 4520 | } |
| 4521 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4522 | /** |
| 4523 | * @hide |
| 4524 | */ |
| 4525 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4526 | CharSequence name = null; |
| 4527 | final PackageManager pm = mContext.getPackageManager(); |
| 4528 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 4529 | // only system packages which lump together a bunch of unrelated stuff |
| 4530 | // may substitute a different name to make the purpose of the |
| 4531 | // notification more clear. the correct package label should always |
| 4532 | // be accessible via SystemUI. |
| 4533 | final String pkg = mContext.getPackageName(); |
| 4534 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 4535 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 4536 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 4537 | name = subName; |
| 4538 | } else { |
| 4539 | Log.w(TAG, "warning: pkg " |
| 4540 | + pkg + " attempting to substitute app name '" + subName |
| 4541 | + "' without holding perm " |
| 4542 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 4543 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4544 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4545 | if (TextUtils.isEmpty(name)) { |
| 4546 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 4547 | } |
| 4548 | if (TextUtils.isEmpty(name)) { |
| 4549 | // still nothing? |
| 4550 | return null; |
| 4551 | } |
| 4552 | |
| 4553 | return String.valueOf(name); |
| 4554 | } |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4555 | private void bindHeaderAppName(RemoteViews contentView, boolean ambient) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4556 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4557 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4558 | setTextViewColorPrimary(contentView, R.id.app_name_text); |
| 4559 | } else { |
| 4560 | contentView.setTextColor(R.id.app_name_text, |
| 4561 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
| 4562 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4563 | } |
| 4564 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4565 | private void bindSmallIcon(RemoteViews contentView, boolean ambient) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4566 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 4567 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 4568 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4569 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4570 | contentView.setInt(R.id.icon, "setImageLevel", mN.iconLevel); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4571 | processSmallIconColor(mN.mSmallIcon, contentView, ambient); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4572 | } |
| 4573 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4574 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4575 | * @return true if the built notification will show the time or the chronometer; false |
| 4576 | * otherwise |
| 4577 | */ |
| 4578 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 4579 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4580 | } |
| 4581 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4582 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4583 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 4584 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4585 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4586 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4587 | |
| 4588 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 4589 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
| 4590 | |
| 4591 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 4592 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 4593 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 4594 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 4595 | |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 4596 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 4597 | R.dimen.notification_content_margin); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4598 | } |
| 4599 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4600 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4601 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this)); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 4602 | } |
| 4603 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4604 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 4605 | StandardTemplateParams p) { |
| 4606 | RemoteViews big = applyStandardTemplate(layoutId, p); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4607 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4608 | resetStandardTemplateWithActions(big); |
| 4609 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4610 | boolean validRemoteInput = false; |
| 4611 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4612 | int N = mActions.size(); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4613 | boolean emphazisedMode = mN.fullScreenIntent != null && !p.ambient; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4614 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4615 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 4616 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4617 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 4618 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4619 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4620 | for (int i=0; i<N; i++) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4621 | Action action = mActions.get(i); |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 4622 | boolean actionHasValidInput = hasValidRemoteInput(action); |
| 4623 | validRemoteInput |= actionHasValidInput; |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4624 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4625 | final RemoteViews button = generateActionButton(action, emphazisedMode, |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4626 | i % 2 != 0, p.ambient); |
Selim Cinek | ffcc7cf | 2018-02-06 17:43:51 -0800 | [diff] [blame] | 4627 | if (actionHasValidInput) { |
| 4628 | // Clear the drawable |
| 4629 | button.setInt(R.id.action0, "setBackgroundResource", 0); |
| 4630 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4631 | big.addView(R.id.actions, button); |
| 4632 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4633 | } else { |
| 4634 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4635 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4636 | |
| 4637 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4638 | if (!p.ambient && validRemoteInput && replyText != null |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4639 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) { |
| 4640 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4641 | big.setTextViewText(R.id.notification_material_reply_text_1, |
| 4642 | processTextSpans(replyText[0])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4643 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4644 | |
| 4645 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) { |
| 4646 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4647 | big.setTextViewText(R.id.notification_material_reply_text_2, |
| 4648 | processTextSpans(replyText[1])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4649 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4650 | |
| 4651 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) { |
| 4652 | big.setViewVisibility( |
| 4653 | R.id.notification_material_reply_text_3, View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4654 | big.setTextViewText(R.id.notification_material_reply_text_3, |
| 4655 | processTextSpans(replyText[2])); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4656 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4657 | } |
| 4658 | } |
| 4659 | } |
| 4660 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4661 | return big; |
| 4662 | } |
| 4663 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4664 | private boolean hasValidRemoteInput(Action action) { |
| 4665 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 4666 | // Weird actions |
| 4667 | return false; |
| 4668 | } |
| 4669 | |
| 4670 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 4671 | if (remoteInputs == null) { |
| 4672 | return false; |
| 4673 | } |
| 4674 | |
| 4675 | for (RemoteInput r : remoteInputs) { |
| 4676 | CharSequence[] choices = r.getChoices(); |
| 4677 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 4678 | return true; |
| 4679 | } |
| 4680 | } |
| 4681 | return false; |
| 4682 | } |
| 4683 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4684 | /** |
| 4685 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 4686 | * 1. Custom contentView from the caller |
| 4687 | * 2. Style's proposed content view |
| 4688 | * 3. Standard template view |
| 4689 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4690 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4691 | return createContentView(false /* increasedheight */ ); |
| 4692 | } |
| 4693 | |
| 4694 | /** |
| 4695 | * Construct a RemoteViews for the smaller content view. |
| 4696 | * |
| 4697 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 4698 | * styles may support showing more then just that basic 1U size |
| 4699 | * and the system may decide to render important notifications |
| 4700 | * slightly bigger even when collapsed. |
| 4701 | * |
| 4702 | * @hide |
| 4703 | */ |
| 4704 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4705 | if (mN.contentView != null && useExistingRemoteView()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4706 | return mN.contentView; |
| 4707 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4708 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4709 | if (styleView != null) { |
| 4710 | return styleView; |
| 4711 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4712 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4713 | return applyStandardTemplate(getBaseLayoutResource()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4714 | } |
| 4715 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4716 | private boolean useExistingRemoteView() { |
| 4717 | return mStyle == null || (!mStyle.displayCustomViewInline() |
| 4718 | && !mRebuildStyledRemoteViews); |
| 4719 | } |
| 4720 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4721 | /** |
| 4722 | * Construct a RemoteViews for the final big notification layout. |
| 4723 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4724 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4725 | RemoteViews result = null; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4726 | if (mN.bigContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4727 | return mN.bigContentView; |
| 4728 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4729 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 4730 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4731 | } else if (mActions.size() != 0) { |
| 4732 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4733 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4734 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4735 | return result; |
| 4736 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4737 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4738 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4739 | * Construct a RemoteViews for the final notification header only. This will not be |
| 4740 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4741 | * |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4742 | * @param ambient if true, generate the header for the ambient display layout. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4743 | * @hide |
| 4744 | */ |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4745 | public RemoteViews makeNotificationHeader(boolean ambient) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4746 | Boolean colorized = (Boolean) mN.extras.get(EXTRA_COLORIZED); |
| 4747 | mN.extras.putBoolean(EXTRA_COLORIZED, false); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4748 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4749 | ambient ? R.layout.notification_template_ambient_header |
| 4750 | : R.layout.notification_template_header); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4751 | resetNotificationHeader(header); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 4752 | bindNotificationHeader(header, ambient, null); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4753 | if (colorized != null) { |
| 4754 | mN.extras.putBoolean(EXTRA_COLORIZED, colorized); |
| 4755 | } else { |
| 4756 | mN.extras.remove(EXTRA_COLORIZED); |
| 4757 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4758 | return header; |
| 4759 | } |
| 4760 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4761 | /** |
| 4762 | * Construct a RemoteViews for the ambient version of the notification. |
| 4763 | * |
| 4764 | * @hide |
| 4765 | */ |
| 4766 | public RemoteViews makeAmbientNotification() { |
| 4767 | RemoteViews ambient = applyStandardTemplateWithActions( |
| 4768 | R.layout.notification_template_material_ambient, |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 4769 | mParams.reset().ambient(true).fillTextsFrom(this).hasProgress(false)); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4770 | return ambient; |
| 4771 | } |
| 4772 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4773 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4774 | if (result != null) { |
| 4775 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 4776 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4777 | } |
| 4778 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4779 | /** |
| 4780 | * Adapt the Notification header if this view is used as an expanded view. |
| 4781 | * |
| 4782 | * @hide |
| 4783 | */ |
| 4784 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4785 | if (result != null) { |
| 4786 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 4787 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4788 | } |
| 4789 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4790 | /** |
| 4791 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4792 | * |
| 4793 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 4794 | * styles may support showing more then just that basic 1U size |
| 4795 | * and the system may decide to render important notifications |
| 4796 | * slightly bigger even when collapsed. |
| 4797 | * |
| 4798 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4799 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4800 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4801 | if (mN.headsUpContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4802 | return mN.headsUpContentView; |
| 4803 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4804 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 4805 | if (styleView != null) { |
| 4806 | return styleView; |
| 4807 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4808 | } else if (mActions.size() == 0) { |
| 4809 | return null; |
| 4810 | } |
| 4811 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4812 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 4813 | } |
| 4814 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4815 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4816 | * Construct a RemoteViews for the final heads-up notification layout. |
| 4817 | */ |
| 4818 | public RemoteViews createHeadsUpContentView() { |
| 4819 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 4820 | } |
| 4821 | |
| 4822 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4823 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 4824 | * |
| 4825 | * @hide |
| 4826 | */ |
| 4827 | public RemoteViews makePublicContentView() { |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4828 | return makePublicView(false /* ambient */); |
| 4829 | } |
| 4830 | |
| 4831 | /** |
| 4832 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 4833 | * |
| 4834 | * @hide |
| 4835 | */ |
| 4836 | public RemoteViews makePublicAmbientNotification() { |
| 4837 | return makePublicView(true /* ambient */); |
| 4838 | } |
| 4839 | |
| 4840 | private RemoteViews makePublicView(boolean ambient) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4841 | if (mN.publicVersion != null) { |
| 4842 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4843 | return ambient ? builder.makeAmbientNotification() : builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4844 | } |
| 4845 | Bundle savedBundle = mN.extras; |
| 4846 | Style style = mStyle; |
| 4847 | mStyle = null; |
| 4848 | Icon largeIcon = mN.mLargeIcon; |
| 4849 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4850 | Bitmap largeIconLegacy = mN.largeIcon; |
| 4851 | mN.largeIcon = null; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 4852 | ArrayList<Action> actions = mActions; |
| 4853 | mActions = new ArrayList<>(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4854 | Bundle publicExtras = new Bundle(); |
| 4855 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 4856 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 4857 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 4858 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4859 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 4860 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4861 | mN.extras = publicExtras; |
Selim Cinek | 499c20f | 2017-07-20 14:06:09 -0700 | [diff] [blame] | 4862 | RemoteViews view; |
| 4863 | if (ambient) { |
| 4864 | publicExtras.putCharSequence(EXTRA_TITLE, |
| 4865 | mContext.getString(com.android.internal.R.string.notification_hidden_text)); |
| 4866 | view = makeAmbientNotification(); |
| 4867 | } else{ |
| 4868 | view = makeNotificationHeader(false /* ambient */); |
| 4869 | view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true); |
| 4870 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4871 | mN.extras = savedBundle; |
| 4872 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4873 | mN.largeIcon = largeIconLegacy; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 4874 | mActions = actions; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4875 | mStyle = style; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4876 | return view; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4877 | } |
| 4878 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4879 | /** |
| 4880 | * Construct a content view for the display when low - priority |
| 4881 | * |
| 4882 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 4883 | * a new subtext is created consisting of the content of the |
| 4884 | * notification. |
| 4885 | * @hide |
| 4886 | */ |
| 4887 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
| 4888 | int color = mN.color; |
| 4889 | mN.color = COLOR_DEFAULT; |
| 4890 | CharSequence summary = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 4891 | if (!useRegularSubtext || TextUtils.isEmpty(summary)) { |
| 4892 | CharSequence newSummary = createSummaryText(); |
| 4893 | if (!TextUtils.isEmpty(newSummary)) { |
| 4894 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, newSummary); |
| 4895 | } |
| 4896 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 4897 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4898 | RemoteViews header = makeNotificationHeader(false /* ambient */); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 4899 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4900 | if (summary != null) { |
| 4901 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, summary); |
| 4902 | } else { |
| 4903 | mN.extras.remove(EXTRA_SUB_TEXT); |
| 4904 | } |
| 4905 | mN.color = color; |
| 4906 | return header; |
| 4907 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4908 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4909 | private CharSequence createSummaryText() { |
| 4910 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 4911 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 4912 | return titleText; |
| 4913 | } |
| 4914 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 4915 | if (titleText == null) { |
| 4916 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 4917 | } |
| 4918 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 4919 | if (titleText != null) { |
| 4920 | summary.append(bidi.unicodeWrap(titleText)); |
| 4921 | } |
| 4922 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 4923 | if (titleText != null && contentText != null) { |
| 4924 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 4925 | R.string.notification_header_divider_symbol_with_spaces))); |
| 4926 | } |
| 4927 | if (contentText != null) { |
| 4928 | summary.append(bidi.unicodeWrap(contentText)); |
| 4929 | } |
| 4930 | return summary; |
| 4931 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 4932 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4933 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4934 | boolean oddAction, boolean ambient) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4935 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 4936 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4937 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 4938 | : tombstone ? getActionTombstoneLayoutResource() |
| 4939 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4940 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 4941 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 4942 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4943 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 4944 | if (action.mRemoteInputs != null) { |
| 4945 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 4946 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4947 | // TODO: handle emphasized mode / actions right |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4948 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4949 | // change the background bgColor |
Selim Cinek | 622c64a | 2017-04-17 17:10:05 -0700 | [diff] [blame] | 4950 | int bgColor; |
| 4951 | if (isColorized()) { |
| 4952 | bgColor = oddAction ? getActionBarColor() : getActionBarColorDeEmphasized(); |
| 4953 | } else { |
| 4954 | bgColor = mContext.getColor(oddAction ? R.color.notification_action_list |
| 4955 | : R.color.notification_action_list_dark); |
| 4956 | } |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 4957 | button.setDrawableTint(R.id.button_holder, true, |
| 4958 | bgColor, PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4959 | CharSequence title = action.title; |
| 4960 | ColorStateList[] outResultColor = null; |
| 4961 | if (isLegacy()) { |
Selim Cinek | 87c3153 | 2017-08-18 18:53:44 -0700 | [diff] [blame] | 4962 | title = NotificationColorUtil.clearColorSpans(title); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4963 | } else { |
| 4964 | outResultColor = new ColorStateList[1]; |
| 4965 | title = ensureColorSpanContrast(title, bgColor, outResultColor); |
| 4966 | } |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4967 | button.setTextViewText(R.id.action0, processTextSpans(title)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4968 | setTextViewColorPrimary(button, R.id.action0); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4969 | if (outResultColor != null && outResultColor[0] != null) { |
| 4970 | // We need to set the text color as well since changing a text to uppercase |
| 4971 | // clears its spans. |
| 4972 | button.setTextColor(R.id.action0, outResultColor[0]); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 4973 | } else if (mN.color != COLOR_DEFAULT && !isColorized() && mTintActionButtons) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4974 | button.setTextColor(R.id.action0,resolveContrastColor()); |
| 4975 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4976 | } else { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 4977 | button.setTextViewText(R.id.action0, processTextSpans( |
| 4978 | processLegacyText(action.title))); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4979 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4980 | setTextViewColorPrimary(button, R.id.action0); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 4981 | } else if (mN.color != COLOR_DEFAULT && mTintActionButtons) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4982 | button.setTextColor(R.id.action0, |
| 4983 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4984 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 4985 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4986 | return button; |
| 4987 | } |
| 4988 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4989 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4990 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 4991 | * text if a span was found that spans over the whole text. |
| 4992 | * |
| 4993 | * @param charSequence the charSequence on which the spans are |
| 4994 | * @param background the background color to ensure the contrast against |
| 4995 | * @param outResultColor an array in which a color will be returned as the first element if |
| 4996 | * there exists a full length color span. |
| 4997 | * @return the contrasted charSequence |
| 4998 | */ |
| 4999 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 5000 | ColorStateList[] outResultColor) { |
| 5001 | if (charSequence instanceof Spanned) { |
| 5002 | Spanned ss = (Spanned) charSequence; |
| 5003 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 5004 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 5005 | for (Object span : spans) { |
| 5006 | Object resultSpan = span; |
| 5007 | int spanStart = ss.getSpanStart(span); |
| 5008 | int spanEnd = ss.getSpanEnd(span); |
| 5009 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 5010 | if (resultSpan instanceof CharacterStyle) { |
| 5011 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 5012 | } |
| 5013 | if (resultSpan instanceof TextAppearanceSpan) { |
| 5014 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 5015 | ColorStateList textColor = originalSpan.getTextColor(); |
| 5016 | if (textColor != null) { |
| 5017 | int[] colors = textColor.getColors(); |
| 5018 | int[] newColors = new int[colors.length]; |
| 5019 | for (int i = 0; i < newColors.length; i++) { |
| 5020 | newColors[i] = NotificationColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5021 | colors[i], background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5022 | } |
| 5023 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 5024 | newColors); |
| 5025 | resultSpan = new TextAppearanceSpan( |
| 5026 | originalSpan.getFamily(), |
| 5027 | originalSpan.getTextStyle(), |
| 5028 | originalSpan.getTextSize(), |
| 5029 | textColor, |
| 5030 | originalSpan.getLinkTextColor()); |
| 5031 | if (fullLength) { |
| 5032 | outResultColor[0] = new ColorStateList( |
| 5033 | textColor.getStates().clone(), newColors); |
| 5034 | } |
| 5035 | } |
| 5036 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 5037 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 5038 | int foregroundColor = originalSpan.getForegroundColor(); |
| 5039 | foregroundColor = NotificationColorUtil.ensureLargeTextContrast( |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5040 | foregroundColor, background, mInNightMode); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 5041 | resultSpan = new ForegroundColorSpan(foregroundColor); |
| 5042 | if (fullLength) { |
| 5043 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
| 5044 | } |
| 5045 | } else { |
| 5046 | resultSpan = span; |
| 5047 | } |
| 5048 | |
| 5049 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 5050 | } |
| 5051 | return builder; |
| 5052 | } |
| 5053 | return charSequence; |
| 5054 | } |
| 5055 | |
| 5056 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5057 | * @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] | 5058 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5059 | */ |
| 5060 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5061 | if (!mIsLegacyInitialized) { |
| 5062 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 5063 | < Build.VERSION_CODES.LOLLIPOP; |
| 5064 | mIsLegacyInitialized = true; |
| 5065 | } |
| 5066 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5067 | } |
| 5068 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5069 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 5070 | return processLegacyText(charSequence, false /* ambient */); |
| 5071 | } |
| 5072 | |
| 5073 | private CharSequence processLegacyText(CharSequence charSequence, boolean ambient) { |
| 5074 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
| 5075 | boolean wantLightText = ambient; |
| 5076 | if (isAlreadyLightText != wantLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5077 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5078 | } else { |
| 5079 | return charSequence; |
| 5080 | } |
| 5081 | } |
| 5082 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5083 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5084 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5085 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5086 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
| 5087 | boolean ambient) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5088 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5089 | int color = ambient ? resolveAmbientColor() : getPrimaryHighlightColor(); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5090 | if (colorable) { |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5091 | contentView.setDrawableTint(R.id.icon, false, color, |
| 5092 | PorterDuff.Mode.SRC_ATOP); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5093 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5094 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 5095 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5096 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5097 | } |
| 5098 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5099 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5100 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5101 | * if it's grayscale). |
| 5102 | */ |
| 5103 | // TODO: also check bounds, transparency, that sort of thing. |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5104 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) { |
| 5105 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5106 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 5107 | // resolve color will fall back to the default when legacy |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 5108 | contentView.setDrawableTint(R.id.icon, false, resolveContrastColor(), |
| 5109 | PorterDuff.Mode.SRC_ATOP); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 5110 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5111 | } |
| 5112 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 5113 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5114 | if (mN.color != COLOR_DEFAULT) { |
| 5115 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5116 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 5117 | } |
| 5118 | |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5119 | int resolveContrastColor() { |
| 5120 | if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) { |
| 5121 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5122 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5123 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5124 | int color; |
| 5125 | int background = mBackgroundColorHint; |
| 5126 | if (mBackgroundColorHint == COLOR_INVALID) { |
| 5127 | background = mContext.getColor( |
| 5128 | com.android.internal.R.color.notification_material_background_color); |
| 5129 | } |
| 5130 | if (mN.color == COLOR_DEFAULT) { |
| 5131 | ensureColors(); |
| 5132 | color = mSecondaryTextColor; |
| 5133 | } else { |
| 5134 | color = NotificationColorUtil.resolveContrastColor(mContext, mN.color, |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5135 | background, mInNightMode); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5136 | } |
| 5137 | if (Color.alpha(color) < 255) { |
| 5138 | // alpha doesn't go well for color filters, so let's blend it manually |
| 5139 | color = NotificationColorUtil.compositeColors(color, background); |
| 5140 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 5141 | mCachedContrastColorIsFor = mN.color; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5142 | return mCachedContrastColor = color; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 5143 | } |
| 5144 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 5145 | int resolveAmbientColor() { |
| 5146 | if (mCachedAmbientColorIsFor == mN.color && mCachedAmbientColorIsFor != COLOR_INVALID) { |
| 5147 | return mCachedAmbientColor; |
| 5148 | } |
| 5149 | final int contrasted = NotificationColorUtil.resolveAmbientColor(mContext, mN.color); |
| 5150 | |
| 5151 | mCachedAmbientColorIsFor = mN.color; |
| 5152 | return mCachedAmbientColor = contrasted; |
| 5153 | } |
| 5154 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 5155 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5156 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5157 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 5158 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5159 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5160 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5161 | mN.actions = new Action[mActions.size()]; |
| 5162 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 5163 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5164 | if (!mPersonList.isEmpty()) { |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 5165 | mN.extras.putParcelableArrayList(EXTRA_PEOPLE_LIST, mPersonList); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 5166 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 5167 | if (mN.bigContentView != null || mN.contentView != null |
| 5168 | || mN.headsUpContentView != null) { |
| 5169 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 5170 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5171 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5172 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5173 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5174 | /** |
| 5175 | * Creates a Builder from an existing notification so further changes can be made. |
| 5176 | * @param context The context for your application / activity. |
| 5177 | * @param n The notification to create a Builder from. |
| 5178 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5179 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5180 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5181 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 5182 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5183 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5184 | if (applicationInfo != null) { |
| 5185 | try { |
| 5186 | builderContext = context.createApplicationContext(applicationInfo, |
| 5187 | Context.CONTEXT_RESTRICTED); |
| 5188 | } catch (NameNotFoundException e) { |
| 5189 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 5190 | builderContext = context; // try with our context |
| 5191 | } |
| 5192 | } else { |
| 5193 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5194 | } |
| 5195 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5196 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5197 | } |
| 5198 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5199 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5200 | * @deprecated Use {@link #build()} instead. |
| 5201 | */ |
| 5202 | @Deprecated |
| 5203 | public Notification getNotification() { |
| 5204 | return build(); |
| 5205 | } |
| 5206 | |
| 5207 | /** |
| 5208 | * Combine all of the options that have been set and return a new {@link Notification} |
| 5209 | * object. |
| 5210 | */ |
| 5211 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5212 | // first, add any extras from the calling code |
| 5213 | if (mUserExtras != null) { |
| 5214 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5215 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5216 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5217 | mN.creationTime = System.currentTimeMillis(); |
| 5218 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5219 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 5220 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 5221 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5222 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5223 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5224 | if (mStyle != null) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5225 | mStyle.reduceImageSizes(mContext); |
| 5226 | mStyle.purgeResources(); |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 5227 | mStyle.validate(mContext); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5228 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5229 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5230 | mN.reduceImageSizes(mContext); |
| 5231 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 5232 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5233 | && (useExistingRemoteView())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5234 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5235 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5236 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 5237 | mN.contentView.getSequenceNumber()); |
| 5238 | } |
| 5239 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5240 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5241 | if (mN.bigContentView != null) { |
| 5242 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 5243 | mN.bigContentView.getSequenceNumber()); |
| 5244 | } |
| 5245 | } |
| 5246 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 5247 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5248 | if (mN.headsUpContentView != null) { |
| 5249 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 5250 | mN.headsUpContentView.getSequenceNumber()); |
| 5251 | } |
| 5252 | } |
| 5253 | } |
| 5254 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 5255 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 5256 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 5257 | } |
| 5258 | |
Adrian Roos | fb92184 | 2017-10-26 14:49:56 +0200 | [diff] [blame] | 5259 | mN.allPendingIntents = null; |
| 5260 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5261 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5262 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5263 | |
| 5264 | /** |
| 5265 | * Apply this Builder to an existing {@link Notification} object. |
| 5266 | * |
| 5267 | * @hide |
| 5268 | */ |
| 5269 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 5270 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 5271 | return n; |
| 5272 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5273 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5274 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5275 | * 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] | 5276 | * change. Also removes extenders on low ram devices, as |
| 5277 | * {@link android.service.notification.NotificationListenerService} services are disabled. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5278 | * |
| 5279 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 5280 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5281 | * @hide |
| 5282 | */ |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5283 | public static Notification maybeCloneStrippedForDelivery(Notification n, boolean isLowRam) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5284 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5285 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5286 | // Only strip views for known Styles because we won't know how to |
| 5287 | // re-create them otherwise. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5288 | if (!isLowRam |
| 5289 | && !TextUtils.isEmpty(templateClass) |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5290 | && getNotificationStyleClass(templateClass) == null) { |
| 5291 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5292 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5293 | |
| 5294 | // Only strip unmodified BuilderRemoteViews. |
| 5295 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5296 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5297 | n.contentView.getSequenceNumber(); |
| 5298 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5299 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5300 | n.bigContentView.getSequenceNumber(); |
| 5301 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5302 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5303 | n.headsUpContentView.getSequenceNumber(); |
| 5304 | |
| 5305 | // Nothing to do here, no need to clone. |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5306 | if (!isLowRam |
| 5307 | && !stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5308 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5309 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5310 | |
| 5311 | Notification clone = n.clone(); |
| 5312 | if (stripContentView) { |
| 5313 | clone.contentView = null; |
| 5314 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 5315 | } |
| 5316 | if (stripBigContentView) { |
| 5317 | clone.bigContentView = null; |
| 5318 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 5319 | } |
| 5320 | if (stripHeadsUpContentView) { |
| 5321 | clone.headsUpContentView = null; |
| 5322 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 5323 | } |
Julia Reynolds | 8a3b459 | 2017-06-26 17:15:14 -0400 | [diff] [blame] | 5324 | if (isLowRam) { |
| 5325 | clone.extras.remove(Notification.TvExtender.EXTRA_TV_EXTENDER); |
| 5326 | clone.extras.remove(WearableExtender.EXTRA_WEARABLE_EXTENSIONS); |
| 5327 | clone.extras.remove(CarExtender.EXTRA_CAR_EXTENDER); |
| 5328 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5329 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5330 | } |
| 5331 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5332 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5333 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5337 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5341 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5345 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5349 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5350 | } |
| 5351 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5352 | private int getMessagingLayoutResource() { |
| 5353 | return R.layout.notification_template_material_messaging; |
| 5354 | } |
| 5355 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5356 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5357 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5358 | } |
| 5359 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5360 | private int getEmphasizedActionLayoutResource() { |
| 5361 | return R.layout.notification_material_action_emphasized; |
| 5362 | } |
| 5363 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5364 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5365 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5366 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5367 | |
| 5368 | private int getBackgroundColor() { |
| 5369 | if (isColorized()) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5370 | return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : mN.color; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5371 | } else { |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5372 | return mBackgroundColorHint != COLOR_INVALID ? mBackgroundColorHint |
| 5373 | : COLOR_DEFAULT; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5374 | } |
| 5375 | } |
| 5376 | |
| 5377 | private boolean isColorized() { |
| 5378 | return mN.isColorized(); |
| 5379 | } |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5380 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 5381 | private boolean shouldTintActionButtons() { |
| 5382 | return mTintActionButtons; |
| 5383 | } |
| 5384 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5385 | private boolean textColorsNeedInversion() { |
| 5386 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 5387 | return false; |
| 5388 | } |
| 5389 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 5390 | return targetSdkVersion > Build.VERSION_CODES.M |
| 5391 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 5392 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5393 | |
| 5394 | /** |
| 5395 | * Set a color palette to be used as the background and textColors |
| 5396 | * |
| 5397 | * @param backgroundColor the color to be used as the background |
| 5398 | * @param foregroundColor the color to be used as the foreground |
| 5399 | * |
| 5400 | * @hide |
| 5401 | */ |
| 5402 | public void setColorPalette(int backgroundColor, int foregroundColor) { |
| 5403 | mBackgroundColor = backgroundColor; |
| 5404 | mForegroundColor = foregroundColor; |
| 5405 | mTextColorsAreForBackground = COLOR_INVALID; |
| 5406 | ensureColors(); |
| 5407 | } |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5408 | |
| 5409 | /** |
| 5410 | * Sets the background color for this notification to be a different one then the default. |
| 5411 | * This is mainly used to calculate contrast and won't necessarily be applied to the |
| 5412 | * background. |
| 5413 | * |
| 5414 | * @hide |
| 5415 | */ |
| 5416 | public void setBackgroundColorHint(int backgroundColor) { |
| 5417 | mBackgroundColorHint = backgroundColor; |
| 5418 | } |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5419 | |
| 5420 | |
| 5421 | /** |
| 5422 | * Forces all styled remoteViews to be built from scratch and not use any cached |
| 5423 | * RemoteViews. |
| 5424 | * This is needed for legacy apps that are baking in their remoteviews into the |
| 5425 | * notification. |
| 5426 | * |
| 5427 | * @hide |
| 5428 | */ |
| 5429 | public void setRebuildStyledRemoteViews(boolean rebuild) { |
| 5430 | mRebuildStyledRemoteViews = rebuild; |
| 5431 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | /** |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5435 | * Reduces the image sizes to conform to a maximum allowed size. This also processes all custom |
| 5436 | * remote views. |
| 5437 | * |
| 5438 | * @hide |
| 5439 | */ |
| 5440 | void reduceImageSizes(Context context) { |
| 5441 | if (extras.getBoolean(EXTRA_REDUCED_IMAGES)) { |
| 5442 | return; |
| 5443 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5444 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5445 | if (mLargeIcon != null || largeIcon != null) { |
| 5446 | Resources resources = context.getResources(); |
| 5447 | Class<? extends Style> style = getNotificationStyle(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5448 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5449 | ? R.dimen.notification_right_icon_size_low_ram |
| 5450 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5451 | int maxHeight = maxWidth; |
| 5452 | if (MediaStyle.class.equals(style) |
| 5453 | || DecoratedMediaCustomViewStyle.class.equals(style)) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5454 | maxHeight = resources.getDimensionPixelSize(isLowRam |
| 5455 | ? R.dimen.notification_media_image_max_height_low_ram |
| 5456 | : R.dimen.notification_media_image_max_height); |
| 5457 | maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5458 | ? R.dimen.notification_media_image_max_width_low_ram |
| 5459 | : R.dimen.notification_media_image_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5460 | } |
| 5461 | if (mLargeIcon != null) { |
| 5462 | mLargeIcon.scaleDownIfNecessary(maxWidth, maxHeight); |
| 5463 | } |
| 5464 | if (largeIcon != null) { |
| 5465 | largeIcon = Icon.scaleDownIfNecessary(largeIcon, maxWidth, maxHeight); |
| 5466 | } |
| 5467 | } |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5468 | reduceImageSizesForRemoteView(contentView, context, isLowRam); |
| 5469 | reduceImageSizesForRemoteView(headsUpContentView, context, isLowRam); |
| 5470 | reduceImageSizesForRemoteView(bigContentView, context, isLowRam); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5471 | extras.putBoolean(EXTRA_REDUCED_IMAGES, true); |
| 5472 | } |
| 5473 | |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5474 | private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context, |
| 5475 | boolean isLowRam) { |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5476 | if (remoteView != null) { |
| 5477 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5478 | int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 5479 | ? R.dimen.notification_custom_view_max_image_width_low_ram |
| 5480 | : R.dimen.notification_custom_view_max_image_width); |
| 5481 | int maxHeight = resources.getDimensionPixelSize(isLowRam |
| 5482 | ? R.dimen.notification_custom_view_max_image_height_low_ram |
| 5483 | : R.dimen.notification_custom_view_max_image_height); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5484 | remoteView.reduceImageSizes(maxWidth, maxHeight); |
| 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5489 | * @return whether this notification is a foreground service notification |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5490 | */ |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5491 | private boolean isForegroundService() { |
| 5492 | return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5496 | * @return whether this notification has a media session attached |
| 5497 | * @hide |
| 5498 | */ |
| 5499 | public boolean hasMediaSession() { |
| 5500 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 5501 | } |
| 5502 | |
| 5503 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5504 | * @return the style class of this notification |
| 5505 | * @hide |
| 5506 | */ |
| 5507 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 5508 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 5509 | |
| 5510 | if (!TextUtils.isEmpty(templateClass)) { |
| 5511 | return Notification.getNotificationStyleClass(templateClass); |
| 5512 | } |
| 5513 | return null; |
| 5514 | } |
| 5515 | |
| 5516 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5517 | * @return true if this notification is colorized. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5518 | * |
| 5519 | * @hide |
| 5520 | */ |
| 5521 | public boolean isColorized() { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5522 | if (isColorizedMedia()) { |
| 5523 | return true; |
| 5524 | } |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 5525 | return extras.getBoolean(EXTRA_COLORIZED) |
| 5526 | && (hasColorizedPermission() || isForegroundService()); |
| 5527 | } |
| 5528 | |
| 5529 | /** |
| 5530 | * Returns whether an app can colorize due to the android.permission.USE_COLORIZED_NOTIFICATIONS |
| 5531 | * permission. The permission is checked when a notification is enqueued. |
| 5532 | */ |
| 5533 | private boolean hasColorizedPermission() { |
| 5534 | return (flags & Notification.FLAG_CAN_COLORIZE) != 0; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | /** |
| 5538 | * @return true if this notification is colorized and it is a media notification |
| 5539 | * |
| 5540 | * @hide |
| 5541 | */ |
| 5542 | public boolean isColorizedMedia() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5543 | Class<? extends Style> style = getNotificationStyle(); |
| 5544 | if (MediaStyle.class.equals(style)) { |
| 5545 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 5546 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 5547 | return true; |
| 5548 | } |
| 5549 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 5550 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 5551 | return true; |
| 5552 | } |
| 5553 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5554 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5555 | } |
| 5556 | |
Selim Cinek | 0847acd | 2017-04-24 19:48:29 -0700 | [diff] [blame] | 5557 | |
| 5558 | /** |
| 5559 | * @return true if this is a media notification |
| 5560 | * |
| 5561 | * @hide |
| 5562 | */ |
| 5563 | public boolean isMediaNotification() { |
| 5564 | Class<? extends Style> style = getNotificationStyle(); |
| 5565 | if (MediaStyle.class.equals(style)) { |
| 5566 | return true; |
| 5567 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 5568 | return true; |
| 5569 | } |
| 5570 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5571 | } |
| 5572 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5573 | private boolean hasLargeIcon() { |
| 5574 | return mLargeIcon != null || largeIcon != null; |
| 5575 | } |
| 5576 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5577 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5578 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5579 | * @hide |
| 5580 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5581 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5582 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 5583 | } |
| 5584 | |
| 5585 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5586 | * @return true if the notification will show a chronometer; false otherwise |
| 5587 | * @hide |
| 5588 | */ |
| 5589 | public boolean showsChronometer() { |
| 5590 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 5591 | } |
| 5592 | |
| 5593 | /** |
Julia Reynolds | 7ca3307 | 2017-06-29 13:58:24 -0400 | [diff] [blame] | 5594 | * @removed |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 5595 | */ |
| 5596 | @SystemApi |
| 5597 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 5598 | Class<? extends Style>[] classes = new Class[] { |
| 5599 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 5600 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 5601 | MessagingStyle.class }; |
| 5602 | for (Class<? extends Style> innerClass : classes) { |
| 5603 | if (templateClass.equals(innerClass.getName())) { |
| 5604 | return innerClass; |
| 5605 | } |
| 5606 | } |
| 5607 | return null; |
| 5608 | } |
| 5609 | |
| 5610 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5611 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 5612 | * object. |
| 5613 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 5614 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5615 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 5616 | |
| 5617 | /** |
| 5618 | * @hide |
| 5619 | */ |
| 5620 | protected CharSequence mSummaryText = null; |
| 5621 | |
| 5622 | /** |
| 5623 | * @hide |
| 5624 | */ |
| 5625 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5626 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5627 | protected Builder mBuilder; |
| 5628 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5629 | /** |
| 5630 | * Overrides ContentTitle in the big form of the template. |
| 5631 | * This defaults to the value passed to setContentTitle(). |
| 5632 | */ |
| 5633 | protected void internalSetBigContentTitle(CharSequence title) { |
| 5634 | mBigContentTitle = title; |
| 5635 | } |
| 5636 | |
| 5637 | /** |
| 5638 | * Set the first line of text after the detail section in the big form of the template. |
| 5639 | */ |
| 5640 | protected void internalSetSummaryText(CharSequence cs) { |
| 5641 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 5642 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5643 | } |
| 5644 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5645 | public void setBuilder(Builder builder) { |
| 5646 | if (mBuilder != builder) { |
| 5647 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 5648 | if (mBuilder != null) { |
| 5649 | mBuilder.setStyle(this); |
| 5650 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5651 | } |
| 5652 | } |
| 5653 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5654 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5655 | if (mBuilder == null) { |
| 5656 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 5657 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5658 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5659 | |
| 5660 | protected RemoteViews getStandardView(int layoutId) { |
| 5661 | checkBuilder(); |
| 5662 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5663 | // Nasty. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5664 | CharSequence oldBuilderContentTitle = |
| 5665 | mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5666 | if (mBigContentTitle != null) { |
| 5667 | mBuilder.setContentTitle(mBigContentTitle); |
| 5668 | } |
| 5669 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5670 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 5671 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5672 | mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5673 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5674 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 5675 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 5676 | } else { |
| 5677 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5678 | } |
| 5679 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5680 | return contentView; |
| 5681 | } |
| 5682 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5683 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5684 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5685 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5686 | * |
| 5687 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5688 | * @hide |
| 5689 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5690 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5691 | return null; |
| 5692 | } |
| 5693 | |
| 5694 | /** |
| 5695 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 5696 | * @hide |
| 5697 | */ |
| 5698 | public RemoteViews makeBigContentView() { |
| 5699 | return null; |
| 5700 | } |
| 5701 | |
| 5702 | /** |
| 5703 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5704 | * |
| 5705 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5706 | * @hide |
| 5707 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5708 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5709 | return null; |
| 5710 | } |
| 5711 | |
| 5712 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5713 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5714 | * @hide |
| 5715 | */ |
| 5716 | public void addExtras(Bundle extras) { |
| 5717 | if (mSummaryTextSet) { |
| 5718 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 5719 | } |
| 5720 | if (mBigContentTitle != null) { |
| 5721 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 5722 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 5723 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5724 | } |
| 5725 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5726 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5727 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5728 | * @hide |
| 5729 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5730 | protected void restoreFromExtras(Bundle extras) { |
| 5731 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 5732 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 5733 | mSummaryTextSet = true; |
| 5734 | } |
| 5735 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 5736 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | |
| 5741 | /** |
| 5742 | * @hide |
| 5743 | */ |
| 5744 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5745 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5746 | return wip; |
| 5747 | } |
| 5748 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 5749 | /** |
| 5750 | * @hide |
| 5751 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5752 | public void purgeResources() {} |
| 5753 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5754 | /** |
| 5755 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 5756 | * attached to. |
| 5757 | * |
| 5758 | * @return the fully constructed Notification. |
| 5759 | */ |
| 5760 | public Notification build() { |
| 5761 | checkBuilder(); |
| 5762 | return mBuilder.build(); |
| 5763 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5764 | |
| 5765 | /** |
| 5766 | * @hide |
| 5767 | * @return true if the style positions the progress bar on the second line; false if the |
| 5768 | * style hides the progress bar |
| 5769 | */ |
| 5770 | protected boolean hasProgress() { |
| 5771 | return true; |
| 5772 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5773 | |
| 5774 | /** |
| 5775 | * @hide |
| 5776 | * @return Whether we should put the summary be put into the notification header |
| 5777 | */ |
| 5778 | public boolean hasSummaryInHeader() { |
| 5779 | return true; |
| 5780 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 5781 | |
| 5782 | /** |
| 5783 | * @hide |
| 5784 | * @return Whether custom content views are displayed inline in the style |
| 5785 | */ |
| 5786 | public boolean displayCustomViewInline() { |
| 5787 | return false; |
| 5788 | } |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5789 | |
| 5790 | /** |
| 5791 | * Reduces the image sizes contained in this style. |
| 5792 | * |
| 5793 | * @hide |
| 5794 | */ |
| 5795 | public void reduceImageSizes(Context context) { |
| 5796 | } |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 5797 | |
| 5798 | /** |
| 5799 | * Validate that this style was properly composed. This is called at build time. |
| 5800 | * @hide |
| 5801 | */ |
| 5802 | public void validate(Context context) { |
| 5803 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5804 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5805 | |
| 5806 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5807 | * 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] | 5808 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5809 | * 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] | 5810 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5811 | * Notification notif = new Notification.Builder(mContext) |
| 5812 | * .setContentTitle("New photo from " + sender.toString()) |
| 5813 | * .setContentText(subject) |
| 5814 | * .setSmallIcon(R.drawable.new_post) |
| 5815 | * .setLargeIcon(aBitmap) |
| 5816 | * .setStyle(new Notification.BigPictureStyle() |
| 5817 | * .bigPicture(aBigBitmap)) |
| 5818 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5819 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5820 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5821 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5822 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5823 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5824 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5825 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5826 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5827 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5828 | public BigPictureStyle() { |
| 5829 | } |
| 5830 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 5831 | /** |
| 5832 | * @deprecated use {@code BigPictureStyle()}. |
| 5833 | */ |
| 5834 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5835 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5836 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5837 | } |
| 5838 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5839 | /** |
| 5840 | * Overrides ContentTitle in the big form of the template. |
| 5841 | * This defaults to the value passed to setContentTitle(). |
| 5842 | */ |
| 5843 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5844 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5845 | return this; |
| 5846 | } |
| 5847 | |
| 5848 | /** |
| 5849 | * Set the first line of text after the detail section in the big form of the template. |
| 5850 | */ |
| 5851 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5852 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5853 | return this; |
| 5854 | } |
| 5855 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 5856 | /** |
| 5857 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 5858 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5859 | public BigPictureStyle bigPicture(Bitmap b) { |
| 5860 | mPicture = b; |
| 5861 | return this; |
| 5862 | } |
| 5863 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5864 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5865 | * Override the large icon when the big notification is shown. |
| 5866 | */ |
| 5867 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5868 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 5869 | } |
| 5870 | |
| 5871 | /** |
| 5872 | * Override the large icon when the big notification is shown. |
| 5873 | */ |
| 5874 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5875 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5876 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5877 | return this; |
| 5878 | } |
| 5879 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 5880 | /** @hide */ |
| 5881 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 5882 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 5883 | /** |
| 5884 | * @hide |
| 5885 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5886 | @Override |
| 5887 | public void purgeResources() { |
| 5888 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 5889 | if (mPicture != null && |
| 5890 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 5891 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5892 | mPicture = mPicture.createAshmemBitmap(); |
| 5893 | } |
| 5894 | if (mBigLargeIcon != null) { |
| 5895 | mBigLargeIcon.convertToAshmem(); |
| 5896 | } |
| 5897 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5898 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5899 | /** |
| 5900 | * @hide |
| 5901 | */ |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5902 | @Override |
| 5903 | public void reduceImageSizes(Context context) { |
| 5904 | super.reduceImageSizes(context); |
| 5905 | Resources resources = context.getResources(); |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5906 | boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5907 | if (mPicture != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5908 | int maxPictureWidth = resources.getDimensionPixelSize(isLowRam |
| 5909 | ? R.dimen.notification_big_picture_max_height_low_ram |
| 5910 | : R.dimen.notification_big_picture_max_height); |
| 5911 | int maxPictureHeight = resources.getDimensionPixelSize(isLowRam |
| 5912 | ? R.dimen.notification_big_picture_max_width_low_ram |
| 5913 | : R.dimen.notification_big_picture_max_width); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5914 | mPicture = Icon.scaleDownIfNecessary(mPicture, maxPictureWidth, maxPictureHeight); |
| 5915 | } |
| 5916 | if (mBigLargeIcon != null) { |
Selim Cinek | a8cb126 | 2017-08-15 16:53:44 -0700 | [diff] [blame] | 5917 | int rightIconSize = resources.getDimensionPixelSize(isLowRam |
| 5918 | ? R.dimen.notification_right_icon_size_low_ram |
| 5919 | : R.dimen.notification_right_icon_size); |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 5920 | mBigLargeIcon.scaleDownIfNecessary(rightIconSize, rightIconSize); |
| 5921 | } |
| 5922 | } |
| 5923 | |
| 5924 | /** |
| 5925 | * @hide |
| 5926 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5927 | public RemoteViews makeBigContentView() { |
| 5928 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5929 | // This covers the following cases: |
| 5930 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5931 | // mN.mLargeIcon |
| 5932 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5933 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5934 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5935 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5936 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 5937 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5938 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 5939 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 5940 | // for old listeners, this is in general non-null. |
| 5941 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 5942 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5943 | } |
| 5944 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5945 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5946 | if (mSummaryTextSet) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 5947 | contentView.setTextViewText(R.id.text, mBuilder.processTextSpans( |
| 5948 | mBuilder.processLegacyText(mSummaryText))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5949 | mBuilder.setTextViewColorSecondary(contentView, R.id.text); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 5950 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5951 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5952 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 5953 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5954 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5955 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5956 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5957 | } |
| 5958 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5959 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5960 | return contentView; |
| 5961 | } |
| 5962 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5963 | /** |
| 5964 | * @hide |
| 5965 | */ |
| 5966 | public void addExtras(Bundle extras) { |
| 5967 | super.addExtras(extras); |
| 5968 | |
| 5969 | if (mBigLargeIconSet) { |
| 5970 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 5971 | } |
| 5972 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 5973 | } |
| 5974 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5975 | /** |
| 5976 | * @hide |
| 5977 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5978 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5979 | protected void restoreFromExtras(Bundle extras) { |
| 5980 | super.restoreFromExtras(extras); |
| 5981 | |
| 5982 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5983 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5984 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5985 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5986 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 5987 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5988 | |
| 5989 | /** |
| 5990 | * @hide |
| 5991 | */ |
| 5992 | @Override |
| 5993 | public boolean hasSummaryInHeader() { |
| 5994 | return false; |
| 5995 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5996 | } |
| 5997 | |
| 5998 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5999 | * 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] | 6000 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6001 | * 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] | 6002 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6003 | * Notification notif = new Notification.Builder(mContext) |
| 6004 | * .setContentTitle("New mail from " + sender.toString()) |
| 6005 | * .setContentText(subject) |
| 6006 | * .setSmallIcon(R.drawable.new_mail) |
| 6007 | * .setLargeIcon(aBitmap) |
| 6008 | * .setStyle(new Notification.BigTextStyle() |
| 6009 | * .bigText(aVeryLongString)) |
| 6010 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6011 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6012 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 6013 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6014 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6015 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 6016 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6017 | private CharSequence mBigText; |
| 6018 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6019 | public BigTextStyle() { |
| 6020 | } |
| 6021 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6022 | /** |
| 6023 | * @deprecated use {@code BigTextStyle()}. |
| 6024 | */ |
| 6025 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6026 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6027 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6028 | } |
| 6029 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6030 | /** |
| 6031 | * Overrides ContentTitle in the big form of the template. |
| 6032 | * This defaults to the value passed to setContentTitle(). |
| 6033 | */ |
| 6034 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6035 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6036 | return this; |
| 6037 | } |
| 6038 | |
| 6039 | /** |
| 6040 | * Set the first line of text after the detail section in the big form of the template. |
| 6041 | */ |
| 6042 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6043 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6044 | return this; |
| 6045 | } |
| 6046 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6047 | /** |
| 6048 | * Provide the longer text to be displayed in the big form of the |
| 6049 | * template in place of the content text. |
| 6050 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6051 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6052 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6053 | return this; |
| 6054 | } |
| 6055 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6056 | /** |
| 6057 | * @hide |
| 6058 | */ |
| 6059 | public void addExtras(Bundle extras) { |
| 6060 | super.addExtras(extras); |
| 6061 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6062 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 6063 | } |
| 6064 | |
| 6065 | /** |
| 6066 | * @hide |
| 6067 | */ |
| 6068 | @Override |
| 6069 | protected void restoreFromExtras(Bundle extras) { |
| 6070 | super.restoreFromExtras(extras); |
| 6071 | |
| 6072 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6073 | } |
| 6074 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6075 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6076 | * @param increasedHeight true if this layout be created with an increased height. |
| 6077 | * |
| 6078 | * @hide |
| 6079 | */ |
| 6080 | @Override |
| 6081 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6082 | if (increasedHeight) { |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6083 | mBuilder.mOriginalActions = mBuilder.mActions; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6084 | mBuilder.mActions = new ArrayList<>(); |
| 6085 | RemoteViews remoteViews = makeBigContentView(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 6086 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6087 | mBuilder.mOriginalActions = null; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6088 | return remoteViews; |
| 6089 | } |
| 6090 | return super.makeContentView(increasedHeight); |
| 6091 | } |
| 6092 | |
| 6093 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6094 | * @hide |
| 6095 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6096 | @Override |
| 6097 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 6098 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 6099 | return makeBigContentView(); |
| 6100 | } |
| 6101 | return super.makeHeadsUpContentView(increasedHeight); |
| 6102 | } |
| 6103 | |
| 6104 | /** |
| 6105 | * @hide |
| 6106 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6107 | public RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6108 | |
| 6109 | // Nasty |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6110 | CharSequence text = mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6111 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 6112 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 6113 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6114 | |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6115 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, text); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6116 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 6117 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 6118 | if (TextUtils.isEmpty(bigTextText)) { |
| 6119 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 6120 | // experience |
| 6121 | bigTextText = mBuilder.processLegacyText(text); |
| 6122 | } |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6123 | applyBigTextContentView(mBuilder, contentView, bigTextText); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 6124 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6125 | return contentView; |
| 6126 | } |
| 6127 | |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6128 | static void applyBigTextContentView(Builder builder, |
| 6129 | RemoteViews contentView, CharSequence bigTextText) { |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6130 | contentView.setTextViewText(R.id.big_text, builder.processTextSpans(bigTextText)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6131 | builder.setTextViewColorSecondary(contentView, R.id.big_text); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6132 | contentView.setViewVisibility(R.id.big_text, |
| 6133 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6134 | contentView.setBoolean(R.id.big_text, "setHasImage", builder.mN.hasLargeIcon()); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6135 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 6136 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6137 | |
| 6138 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6139 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 6140 | * messages of varying types between any number of people. |
| 6141 | * |
| 6142 | * <br> |
| 6143 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 6144 | * user will always see the normal notification view. |
| 6145 | * <br> |
| 6146 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like |
| 6147 | * so: |
| 6148 | * <pre class="prettyprint"> |
| 6149 | * |
| 6150 | * Notification noti = new Notification.Builder() |
| 6151 | * .setContentTitle("2 new messages wtih " + sender.toString()) |
| 6152 | * .setContentText(subject) |
| 6153 | * .setSmallIcon(R.drawable.new_message) |
| 6154 | * .setLargeIcon(aBitmap) |
| 6155 | * .setStyle(new Notification.MessagingStyle(resources.getString(R.string.reply_name)) |
| 6156 | * .addMessage(messages[0].getText(), messages[0].getTime(), messages[0].getSender()) |
| 6157 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getSender())) |
| 6158 | * .build(); |
| 6159 | * </pre> |
| 6160 | */ |
| 6161 | public static class MessagingStyle extends Style { |
| 6162 | |
| 6163 | /** |
| 6164 | * The maximum number of messages that will be retained in the Notification itself (the |
| 6165 | * number displayed is up to the platform). |
| 6166 | */ |
| 6167 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 6168 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6169 | @NonNull Person mUser; |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6170 | @Nullable CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6171 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6172 | List<Message> mHistoricMessages = new ArrayList<>(); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6173 | boolean mIsGroupConversation; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6174 | |
| 6175 | MessagingStyle() { |
| 6176 | } |
| 6177 | |
| 6178 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6179 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 6180 | * user before the posting app reposts the notification with those messages after they've |
| 6181 | * 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] | 6182 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6183 | * |
| 6184 | * @deprecated use {@code MessagingStyle(Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6185 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 6186 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6187 | this(new Person().setName(userDisplayName)); |
| 6188 | } |
| 6189 | |
| 6190 | /** |
| 6191 | * @param user Required - The person displayed for any messages that are sent by the |
| 6192 | * user. Any messages added with {@link #addMessage(Notification.MessagingStyle.Message)} |
| 6193 | * 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] | 6194 | * by this user. The user also needs to have a valid name associated with it, which will |
| 6195 | * be enforced starting in Android P. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6196 | */ |
| 6197 | public MessagingStyle(@NonNull Person user) { |
| 6198 | mUser = user; |
Selim Cinek | 9034386 | 2018-02-01 11:07:11 -0800 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | /** |
| 6202 | * Validate that this style was properly composed. This is called at build time. |
| 6203 | * @hide |
| 6204 | */ |
| 6205 | @Override |
| 6206 | public void validate(Context context) { |
| 6207 | super.validate(context); |
| 6208 | if (context.getApplicationInfo().targetSdkVersion |
| 6209 | >= Build.VERSION_CODES.P && (mUser == null || mUser.getName() == null)) { |
| 6210 | throw new RuntimeException("User must be valid and have a name."); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6211 | } |
| 6212 | } |
| 6213 | |
| 6214 | /** |
| 6215 | * @return the user to be displayed for any replies sent by the user |
| 6216 | */ |
| 6217 | public Person getUser() { |
| 6218 | return mUser; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6219 | } |
| 6220 | |
| 6221 | /** |
| 6222 | * 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] | 6223 | * |
| 6224 | * @deprecated use {@link #getUser()} instead |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6225 | */ |
| 6226 | public CharSequence getUserDisplayName() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6227 | return mUser.getName(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6231 | * Sets the title to be displayed on this conversation. May be set to {@code null}. |
| 6232 | * |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6233 | * <p>This API's behavior was changed in SDK version {@link Build.VERSION_CODES#P}. If your |
| 6234 | * application's target version is less than {@link Build.VERSION_CODES#P}, setting a |
| 6235 | * conversation title to a non-null value will make {@link #isGroupConversation()} return |
| 6236 | * {@code true} and passing {@code null} will make it return {@code false}. In |
| 6237 | * {@link Build.VERSION_CODES#P} and beyond, use {@link #setGroupConversation(boolean)} |
| 6238 | * to set group conversation status. |
| 6239 | * |
| 6240 | * @param conversationTitle Title displayed for this conversation |
| 6241 | * @return this object for method chaining |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6242 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6243 | public MessagingStyle setConversationTitle(@Nullable CharSequence conversationTitle) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6244 | mConversationTitle = conversationTitle; |
| 6245 | return this; |
| 6246 | } |
| 6247 | |
| 6248 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6249 | * 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] | 6250 | */ |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6251 | @Nullable |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6252 | public CharSequence getConversationTitle() { |
| 6253 | return mConversationTitle; |
| 6254 | } |
| 6255 | |
| 6256 | /** |
| 6257 | * Adds a message for display by this notification. Convenience call for a simple |
| 6258 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6259 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6260 | * @param timestamp Time at which the message arrived |
| 6261 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 6262 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 6263 | * the platform will insert {@link #getUserDisplayName()}. |
| 6264 | * Should be unique amongst all individuals in the conversation, and should be |
| 6265 | * consistent during re-posts of the notification. |
| 6266 | * |
| 6267 | * @see Message#Message(CharSequence, long, CharSequence) |
| 6268 | * |
| 6269 | * @return this object for method chaining |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6270 | * |
| 6271 | * @deprecated use {@link #addMessage(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6272 | */ |
| 6273 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6274 | return addMessage(text, timestamp, |
| 6275 | sender == null ? null : new Person().setName(sender)); |
| 6276 | } |
| 6277 | |
| 6278 | /** |
| 6279 | * Adds a message for display by this notification. Convenience call for a simple |
| 6280 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 6281 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6282 | * @param timestamp Time at which the message arrived |
| 6283 | * @param sender The {@link Person} who sent the message. |
| 6284 | * Should be <code>null</code> for messages by the current user, in which case |
| 6285 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 6286 | * |
| 6287 | * @see Message#Message(CharSequence, long, CharSequence) |
| 6288 | * |
| 6289 | * @return this object for method chaining |
| 6290 | */ |
| 6291 | public MessagingStyle addMessage(CharSequence text, long timestamp, Person sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6292 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | /** |
| 6296 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6297 | * |
| 6298 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6299 | * the newest last. |
| 6300 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6301 | * @param message The {@link Message} to be displayed |
| 6302 | * @return this object for method chaining |
| 6303 | */ |
| 6304 | public MessagingStyle addMessage(Message message) { |
| 6305 | mMessages.add(message); |
| 6306 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 6307 | mMessages.remove(0); |
| 6308 | } |
| 6309 | return this; |
| 6310 | } |
| 6311 | |
| 6312 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6313 | * Adds a {@link Message} for historic context in this notification. |
| 6314 | * |
| 6315 | * <p>Messages should be added as historic if they are not the main subject of the |
| 6316 | * notification but may give context to a conversation. The system may choose to present |
| 6317 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 6318 | * |
| 6319 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 6320 | * the newest last. |
| 6321 | * |
| 6322 | * @param message The historic {@link Message} to be added |
| 6323 | * @return this object for method chaining |
| 6324 | */ |
| 6325 | public MessagingStyle addHistoricMessage(Message message) { |
| 6326 | mHistoricMessages.add(message); |
| 6327 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 6328 | mHistoricMessages.remove(0); |
| 6329 | } |
| 6330 | return this; |
| 6331 | } |
| 6332 | |
| 6333 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6334 | * Gets the list of {@code Message} objects that represent the notification |
| 6335 | */ |
| 6336 | public List<Message> getMessages() { |
| 6337 | return mMessages; |
| 6338 | } |
| 6339 | |
| 6340 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6341 | * Gets the list of historic {@code Message}s in the notification. |
| 6342 | */ |
| 6343 | public List<Message> getHistoricMessages() { |
| 6344 | return mHistoricMessages; |
| 6345 | } |
| 6346 | |
| 6347 | /** |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6348 | * Sets whether this conversation notification represents a group. |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6349 | * |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6350 | * @param isGroupConversation {@code true} if the conversation represents a group, |
| 6351 | * {@code false} otherwise. |
| 6352 | * @return this object for method chaining |
| 6353 | */ |
| 6354 | public MessagingStyle setGroupConversation(boolean isGroupConversation) { |
| 6355 | mIsGroupConversation = isGroupConversation; |
| 6356 | return this; |
| 6357 | } |
| 6358 | |
| 6359 | /** |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6360 | * Returns {@code true} if this notification represents a group conversation, otherwise |
| 6361 | * {@code false}. |
| 6362 | * |
| 6363 | * <p> If the application that generated this {@link MessagingStyle} targets an SDK version |
| 6364 | * less than {@link Build.VERSION_CODES#P}, this method becomes dependent on whether or |
| 6365 | * not the conversation title is set; returning {@code true} if the conversation title is |
| 6366 | * a non-null value, or {@code false} otherwise. From {@link Build.VERSION_CODES#P} forward, |
| 6367 | * this method returns what's set by {@link #setGroupConversation(boolean)} allowing for |
| 6368 | * named, non-group conversations. |
| 6369 | * |
| 6370 | * @see #setConversationTitle(CharSequence) |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6371 | */ |
| 6372 | public boolean isGroupConversation() { |
Kodlee Yin | 1465642 | 2017-12-22 17:00:46 -0800 | [diff] [blame] | 6373 | // When target SDK version is < P, a non-null conversation title dictates if this is |
| 6374 | // as group conversation. |
| 6375 | if (mBuilder != null |
| 6376 | && mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 6377 | < Build.VERSION_CODES.P) { |
| 6378 | return mConversationTitle != null; |
| 6379 | } |
| 6380 | |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6381 | return mIsGroupConversation; |
| 6382 | } |
| 6383 | |
| 6384 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6385 | * @hide |
| 6386 | */ |
| 6387 | @Override |
| 6388 | public void addExtras(Bundle extras) { |
| 6389 | super.addExtras(extras); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6390 | if (mUser != null) { |
| 6391 | // For legacy usages |
| 6392 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUser.getName()); |
| 6393 | extras.putParcelable(EXTRA_MESSAGING_PERSON, mUser); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6394 | } |
| 6395 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6396 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6397 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6398 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 6399 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6400 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6401 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 6402 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 6403 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6404 | |
| 6405 | fixTitleAndTextExtras(extras); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6406 | extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6407 | } |
| 6408 | |
| 6409 | private void fixTitleAndTextExtras(Bundle extras) { |
| 6410 | Message m = findLatestIncomingMessage(); |
| 6411 | CharSequence text = (m == null) ? null : m.mText; |
| 6412 | CharSequence sender = m == null ? null |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6413 | : m.mSender == null || TextUtils.isEmpty(m.mSender.getName()) |
| 6414 | ? mUser.getName() : m.mSender.getName(); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6415 | CharSequence title; |
| 6416 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 6417 | if (!TextUtils.isEmpty(sender)) { |
| 6418 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 6419 | title = mBuilder.mContext.getString( |
| 6420 | com.android.internal.R.string.notification_messaging_title_template, |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6421 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(sender)); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6422 | } else { |
| 6423 | title = mConversationTitle; |
| 6424 | } |
| 6425 | } else { |
| 6426 | title = sender; |
| 6427 | } |
| 6428 | |
| 6429 | if (title != null) { |
| 6430 | extras.putCharSequence(EXTRA_TITLE, title); |
| 6431 | } |
| 6432 | if (text != null) { |
| 6433 | extras.putCharSequence(EXTRA_TEXT, text); |
| 6434 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6435 | } |
| 6436 | |
| 6437 | /** |
| 6438 | * @hide |
| 6439 | */ |
| 6440 | @Override |
| 6441 | protected void restoreFromExtras(Bundle extras) { |
| 6442 | super.restoreFromExtras(extras); |
| 6443 | |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6444 | mUser = extras.getParcelable(EXTRA_MESSAGING_PERSON); |
| 6445 | if (mUser == null) { |
| 6446 | CharSequence displayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
| 6447 | mUser = new Person().setName(displayName); |
| 6448 | } |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 6449 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6450 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6451 | mMessages = Message.getMessagesFromBundleArray(messages); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6452 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6453 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Kodlee Yin | 9ac617c | 2017-12-19 11:20:50 -0800 | [diff] [blame] | 6454 | mIsGroupConversation = extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6455 | } |
| 6456 | |
| 6457 | /** |
| 6458 | * @hide |
| 6459 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6460 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6461 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 6462 | mBuilder.mOriginalActions = mBuilder.mActions; |
| 6463 | mBuilder.mActions = new ArrayList<>(); |
Selim Cinek | 7199ed9 | 2018-01-26 13:36:43 -0800 | [diff] [blame] | 6464 | RemoteViews remoteViews = makeMessagingView(true /* isCollapsed */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 6465 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 6466 | mBuilder.mOriginalActions = null; |
| 6467 | return remoteViews; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6468 | } |
| 6469 | |
| 6470 | private Message findLatestIncomingMessage() { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6471 | return findLatestIncomingMessage(mMessages); |
| 6472 | } |
| 6473 | |
| 6474 | /** |
| 6475 | * @hide |
| 6476 | */ |
| 6477 | @Nullable |
| 6478 | public static Message findLatestIncomingMessage( |
| 6479 | List<Message> messages) { |
| 6480 | for (int i = messages.size() - 1; i >= 0; i--) { |
| 6481 | Message m = messages.get(i); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6482 | // Incoming messages have a non-empty sender. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6483 | if (m.mSender != null && !TextUtils.isEmpty(m.mSender.getName())) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6484 | return m; |
| 6485 | } |
| 6486 | } |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6487 | if (!messages.isEmpty()) { |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6488 | // No incoming messages, fall back to outgoing message |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6489 | return messages.get(messages.size() - 1); |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6490 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6491 | return null; |
| 6492 | } |
| 6493 | |
| 6494 | /** |
| 6495 | * @hide |
| 6496 | */ |
| 6497 | @Override |
| 6498 | public RemoteViews makeBigContentView() { |
Selim Cinek | 7199ed9 | 2018-01-26 13:36:43 -0800 | [diff] [blame] | 6499 | return makeMessagingView(false /* isCollapsed */); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | @NonNull |
Selim Cinek | 7199ed9 | 2018-01-26 13:36:43 -0800 | [diff] [blame] | 6503 | private RemoteViews makeMessagingView(boolean isCollapsed) { |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6504 | CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6505 | ? super.mBigContentTitle |
| 6506 | : mConversationTitle; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6507 | boolean isOneToOne = TextUtils.isEmpty(conversationTitle); |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 6508 | CharSequence nameReplacement = null; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 6509 | if (hasOnlyWhiteSpaceSenders()) { |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 6510 | isOneToOne = true; |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 6511 | nameReplacement = conversationTitle; |
| 6512 | conversationTitle = null; |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6513 | } |
Selim Cinek | 7199ed9 | 2018-01-26 13:36:43 -0800 | [diff] [blame] | 6514 | boolean hideLargeIcon = !isCollapsed || isOneToOne; |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 6515 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6516 | mBuilder.getMessagingLayoutResource(), |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6517 | mBuilder.mParams.reset().hasProgress(false).title(conversationTitle).text(null) |
Selim Cinek | 7199ed9 | 2018-01-26 13:36:43 -0800 | [diff] [blame] | 6518 | .hideLargeIcon(hideLargeIcon) |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 6519 | .headerTextSecondary(conversationTitle) |
Selim Cinek | 7199ed9 | 2018-01-26 13:36:43 -0800 | [diff] [blame] | 6520 | .alwaysShowReply(isCollapsed)); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6521 | addExtras(mBuilder.mN.extras); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 6522 | // also update the end margin if there is an image |
| 6523 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 7199ed9 | 2018-01-26 13:36:43 -0800 | [diff] [blame] | 6524 | if (isCollapsed) { |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 6525 | endMargin = R.dimen.notification_content_plus_picture_margin_end; |
| 6526 | } |
| 6527 | contentView.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6528 | contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", |
| 6529 | mBuilder.resolveContrastColor()); |
Selim Cinek | 7199ed9 | 2018-01-26 13:36:43 -0800 | [diff] [blame] | 6530 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsCollapsed", |
| 6531 | isCollapsed); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6532 | contentView.setIcon(R.id.status_bar_latest_event_content, "setLargeIcon", |
| 6533 | mBuilder.mN.mLargeIcon); |
Selim Cinek | 2dd3e72 | 2018-01-19 11:06:06 -0800 | [diff] [blame] | 6534 | contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement", |
| 6535 | nameReplacement); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6536 | contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne", |
| 6537 | isOneToOne); |
| 6538 | contentView.setBundle(R.id.status_bar_latest_event_content, "setData", |
| 6539 | mBuilder.mN.extras); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6540 | return contentView; |
| 6541 | } |
| 6542 | |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 6543 | private boolean hasOnlyWhiteSpaceSenders() { |
| 6544 | for (int i = 0; i < mMessages.size(); i++) { |
| 6545 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6546 | Person sender = m.getSenderPerson(); |
| 6547 | if (sender != null && !isWhiteSpace(sender.getName())) { |
Selim Cinek | f7409db | 2017-10-24 16:17:14 -0700 | [diff] [blame] | 6548 | return false; |
| 6549 | } |
| 6550 | } |
| 6551 | return true; |
| 6552 | } |
| 6553 | |
| 6554 | private boolean isWhiteSpace(CharSequence sender) { |
| 6555 | if (TextUtils.isEmpty(sender)) { |
| 6556 | return true; |
| 6557 | } |
| 6558 | if (sender.toString().matches("^\\s*$")) { |
| 6559 | return true; |
| 6560 | } |
| 6561 | // Let's check if we only have 0 whitespace chars. Some apps did this as a workaround |
| 6562 | // For the presentation that we had. |
| 6563 | for (int i = 0; i < sender.length(); i++) { |
| 6564 | char c = sender.charAt(i); |
| 6565 | if (c != '\u200B') { |
| 6566 | return false; |
| 6567 | } |
| 6568 | } |
| 6569 | return true; |
| 6570 | } |
| 6571 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6572 | private CharSequence createConversationTitleFromMessages() { |
| 6573 | ArraySet<CharSequence> names = new ArraySet<>(); |
| 6574 | for (int i = 0; i < mMessages.size(); i++) { |
| 6575 | Message m = mMessages.get(i); |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6576 | Person sender = m.getSenderPerson(); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6577 | if (sender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6578 | names.add(sender.getName()); |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6579 | } |
| 6580 | } |
| 6581 | SpannableStringBuilder title = new SpannableStringBuilder(); |
| 6582 | int size = names.size(); |
| 6583 | for (int i = 0; i < size; i++) { |
| 6584 | CharSequence name = names.valueAt(i); |
| 6585 | if (!TextUtils.isEmpty(title)) { |
| 6586 | title.append(", "); |
| 6587 | } |
| 6588 | title.append(BidiFormatter.getInstance().unicodeWrap(name)); |
| 6589 | } |
| 6590 | return title; |
| 6591 | } |
| 6592 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6593 | /** |
| 6594 | * @hide |
| 6595 | */ |
| 6596 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6597 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 7199ed9 | 2018-01-26 13:36:43 -0800 | [diff] [blame] | 6598 | RemoteViews remoteViews = makeMessagingView(true /* isCollapsed */); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 6599 | remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1); |
| 6600 | return remoteViews; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6601 | } |
| 6602 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6603 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 6604 | return new TextAppearanceSpan(null, 0, 0, |
| 6605 | ColorStateList.valueOf(color), null); |
| 6606 | } |
| 6607 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6608 | public static final class Message { |
| 6609 | |
| 6610 | static final String KEY_TEXT = "text"; |
| 6611 | static final String KEY_TIMESTAMP = "time"; |
| 6612 | static final String KEY_SENDER = "sender"; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6613 | static final String KEY_SENDER_PERSON = "sender_person"; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6614 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 6615 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6616 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6617 | |
| 6618 | private final CharSequence mText; |
| 6619 | private final long mTimestamp; |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6620 | @Nullable |
| 6621 | private final Person mSender; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6622 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6623 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6624 | private String mDataMimeType; |
| 6625 | private Uri mDataUri; |
| 6626 | |
| 6627 | /** |
| 6628 | * Constructor |
| 6629 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6630 | * @param timestamp Time at which the message arrived |
| 6631 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 6632 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 6633 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 6634 | * Should be unique amongst all individuals in the conversation, and should be |
| 6635 | * consistent during re-posts of the notification. |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6636 | * |
| 6637 | * @deprecated use {@code Message(CharSequence, long, Person)} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6638 | */ |
| 6639 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6640 | this(text, timestamp, sender == null ? null : new Person().setName(sender)); |
| 6641 | } |
| 6642 | |
| 6643 | /** |
| 6644 | * Constructor |
| 6645 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6646 | * @param timestamp Time at which the message arrived |
| 6647 | * @param sender The {@link Person} who sent the message. |
| 6648 | * Should be <code>null</code> for messages by the current user, in which case |
| 6649 | * the platform will insert the user set in {@code MessagingStyle(Person)}. |
| 6650 | * <p> |
| 6651 | * The person provided should contain an Icon, set with {@link Person#setIcon(Icon)} |
| 6652 | * and also have a name provided with {@link Person#setName(CharSequence)}. If multiple |
| 6653 | * users have the same name, consider providing a key with {@link Person#setKey(String)} |
| 6654 | * in order to differentiate between the different users. |
| 6655 | * </p> |
| 6656 | */ |
| 6657 | public Message(CharSequence text, long timestamp, @Nullable Person sender){ |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6658 | mText = text; |
| 6659 | mTimestamp = timestamp; |
| 6660 | mSender = sender; |
| 6661 | } |
| 6662 | |
| 6663 | /** |
| 6664 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 6665 | * where the platform doesn't support the MIME type, the original text provided in the |
| 6666 | * constructor will be used. |
| 6667 | * @param dataMimeType The MIME type of the content. See |
| 6668 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 6669 | * types on Android and Android Wear. |
| 6670 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 6671 | * <p class="note"> |
| 6672 | * <ol> |
| 6673 | * <li>Notification Listeners including the System UI need permission to access the |
| 6674 | * data the Uri points to. The recommended ways to do this are:</li> |
| 6675 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 6676 | * the correct permission to access your provider. The preferred mechanism for |
| 6677 | * providing access is to use per-URI permissions which are temporary and only |
| 6678 | * grant access to the receiving application. An easy way to create a |
| 6679 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 6680 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 6681 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 6682 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 6683 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 6684 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 6685 | * Note that once added to the system MediaStore the content is accessible to any |
| 6686 | * app on the device.</li> |
| 6687 | * </ol> |
| 6688 | * @return this object for method chaining |
| 6689 | */ |
| 6690 | public Message setData(String dataMimeType, Uri dataUri) { |
| 6691 | mDataMimeType = dataMimeType; |
| 6692 | mDataUri = dataUri; |
| 6693 | return this; |
| 6694 | } |
| 6695 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6696 | /** |
| 6697 | * Get the text to be used for this message, or the fallback text if a type and content |
| 6698 | * Uri have been set |
| 6699 | */ |
| 6700 | public CharSequence getText() { |
| 6701 | return mText; |
| 6702 | } |
| 6703 | |
| 6704 | /** |
| 6705 | * Get the time at which this message arrived |
| 6706 | */ |
| 6707 | public long getTimestamp() { |
| 6708 | return mTimestamp; |
| 6709 | } |
| 6710 | |
| 6711 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6712 | * Get the extras Bundle for this message. |
| 6713 | */ |
| 6714 | public Bundle getExtras() { |
| 6715 | return mExtras; |
| 6716 | } |
| 6717 | |
| 6718 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6719 | * 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] | 6720 | * |
| 6721 | * @deprecated use {@link #getSenderPerson()} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6722 | */ |
| 6723 | public CharSequence getSender() { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6724 | return mSender == null ? null : mSender.getName(); |
| 6725 | } |
| 6726 | |
| 6727 | /** |
| 6728 | * Get the sender associated with this message. |
| 6729 | */ |
| 6730 | @Nullable |
| 6731 | public Person getSenderPerson() { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6732 | return mSender; |
| 6733 | } |
| 6734 | |
| 6735 | /** |
| 6736 | * Get the MIME type of the data pointed to by the Uri |
| 6737 | */ |
| 6738 | public String getDataMimeType() { |
| 6739 | return mDataMimeType; |
| 6740 | } |
| 6741 | |
| 6742 | /** |
| 6743 | * Get the the Uri pointing to the content of the message. Can be null, in which case |
| 6744 | * {@see #getText()} is used. |
| 6745 | */ |
| 6746 | public Uri getDataUri() { |
| 6747 | return mDataUri; |
| 6748 | } |
| 6749 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6750 | private Bundle toBundle() { |
| 6751 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6752 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6753 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6754 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6755 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6756 | if (mSender != null) { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6757 | // Legacy listeners need this |
| 6758 | bundle.putCharSequence(KEY_SENDER, mSender.getName()); |
| 6759 | bundle.putParcelable(KEY_SENDER_PERSON, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6760 | } |
| 6761 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6762 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6763 | } |
| 6764 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6765 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6766 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6767 | if (mExtras != null) { |
| 6768 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 6769 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6770 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6771 | } |
| 6772 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6773 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 6774 | Bundle[] bundles = new Bundle[messages.size()]; |
| 6775 | final int N = messages.size(); |
| 6776 | for (int i = 0; i < N; i++) { |
| 6777 | bundles[i] = messages.get(i).toBundle(); |
| 6778 | } |
| 6779 | return bundles; |
| 6780 | } |
| 6781 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 6782 | /** |
| 6783 | * @return A list of messages read from the bundles. |
| 6784 | * |
| 6785 | * @hide |
| 6786 | */ |
| 6787 | public static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
| 6788 | if (bundles == null) { |
| 6789 | return new ArrayList<>(); |
| 6790 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6791 | List<Message> messages = new ArrayList<>(bundles.length); |
| 6792 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6793 | if (bundles[i] instanceof Bundle) { |
| 6794 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 6795 | if (message != null) { |
| 6796 | messages.add(message); |
| 6797 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6798 | } |
| 6799 | } |
| 6800 | return messages; |
| 6801 | } |
| 6802 | |
| 6803 | static Message getMessageFromBundle(Bundle bundle) { |
| 6804 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 6805 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6806 | return null; |
| 6807 | } else { |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6808 | |
| 6809 | Person senderPerson = bundle.getParcelable(KEY_SENDER_PERSON); |
| 6810 | if (senderPerson == null) { |
| 6811 | // Legacy apps that use compat don't actually provide the sender objects |
| 6812 | // We need to fix the compat version to provide people / use |
| 6813 | // the native api instead |
| 6814 | CharSequence senderName = bundle.getCharSequence(KEY_SENDER); |
| 6815 | if (senderName != null) { |
| 6816 | senderPerson = new Person().setName(senderName); |
| 6817 | } |
| 6818 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6819 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
Selim Cinek | cb8b985 | 2017-12-15 18:01:52 -0800 | [diff] [blame] | 6820 | bundle.getLong(KEY_TIMESTAMP), |
| 6821 | senderPerson); |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6822 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 6823 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6824 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 6825 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6826 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6827 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 6828 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 6829 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6830 | return message; |
| 6831 | } |
| 6832 | } catch (ClassCastException e) { |
| 6833 | return null; |
| 6834 | } |
| 6835 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6836 | } |
| 6837 | } |
| 6838 | |
| 6839 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6840 | * 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] | 6841 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6842 | * 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] | 6843 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6844 | * Notification notif = new Notification.Builder(mContext) |
| 6845 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 6846 | * .setContentText(subject) |
| 6847 | * .setSmallIcon(R.drawable.new_mail) |
| 6848 | * .setLargeIcon(aBitmap) |
| 6849 | * .setStyle(new Notification.InboxStyle() |
| 6850 | * .addLine(str1) |
| 6851 | * .addLine(str2) |
| 6852 | * .setContentTitle("") |
| 6853 | * .setSummaryText("+3 more")) |
| 6854 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6855 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6856 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6857 | * @see Notification#bigContentView |
| 6858 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6859 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6860 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 6861 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6862 | public InboxStyle() { |
| 6863 | } |
| 6864 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6865 | /** |
| 6866 | * @deprecated use {@code InboxStyle()}. |
| 6867 | */ |
| 6868 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6869 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6870 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6871 | } |
| 6872 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6873 | /** |
| 6874 | * Overrides ContentTitle in the big form of the template. |
| 6875 | * This defaults to the value passed to setContentTitle(). |
| 6876 | */ |
| 6877 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6878 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6879 | return this; |
| 6880 | } |
| 6881 | |
| 6882 | /** |
| 6883 | * Set the first line of text after the detail section in the big form of the template. |
| 6884 | */ |
| 6885 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6886 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6887 | return this; |
| 6888 | } |
| 6889 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6890 | /** |
| 6891 | * Append a line to the digest section of the Inbox notification. |
| 6892 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6893 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6894 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6895 | return this; |
| 6896 | } |
| 6897 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6898 | /** |
| 6899 | * @hide |
| 6900 | */ |
| 6901 | public void addExtras(Bundle extras) { |
| 6902 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6903 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6904 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 6905 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 6906 | } |
| 6907 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6908 | /** |
| 6909 | * @hide |
| 6910 | */ |
| 6911 | @Override |
| 6912 | protected void restoreFromExtras(Bundle extras) { |
| 6913 | super.restoreFromExtras(extras); |
| 6914 | |
| 6915 | mTexts.clear(); |
| 6916 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 6917 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 6918 | } |
| 6919 | } |
| 6920 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6921 | /** |
| 6922 | * @hide |
| 6923 | */ |
| 6924 | public RemoteViews makeBigContentView() { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 6925 | // Remove the content text so it disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6926 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6927 | CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT); |
| 6928 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6929 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 6930 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource()); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 6931 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6932 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6933 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6934 | 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] | 6935 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6936 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 6937 | // Make sure all rows are gone in case we reuse a view. |
| 6938 | for (int rowId : rowIds) { |
| 6939 | contentView.setViewVisibility(rowId, View.GONE); |
| 6940 | } |
| 6941 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6942 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6943 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 6944 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6945 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6946 | int onlyViewId = 0; |
| 6947 | int maxRows = rowIds.length; |
| 6948 | if (mBuilder.mActions.size() > 0) { |
| 6949 | maxRows--; |
| 6950 | } |
| 6951 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6952 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6953 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6954 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Selim Cinek | 48f66b7 | 2017-08-18 16:17:51 -0700 | [diff] [blame] | 6955 | contentView.setTextViewText(rowIds[i], |
| 6956 | mBuilder.processTextSpans(mBuilder.processLegacyText(str))); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6957 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i]); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6958 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6959 | handleInboxImageMargin(contentView, rowIds[i], first); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6960 | if (first) { |
| 6961 | onlyViewId = rowIds[i]; |
| 6962 | } else { |
| 6963 | onlyViewId = 0; |
| 6964 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6965 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6966 | } |
| 6967 | i++; |
| 6968 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6969 | if (onlyViewId != 0) { |
| 6970 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 6971 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 6972 | R.dimen.notification_text_margin_top); |
| 6973 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 6974 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6975 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6976 | return contentView; |
| 6977 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6978 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6979 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6980 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6981 | if (first) { |
| 6982 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 6983 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 6984 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6985 | if (mBuilder.mN.hasLargeIcon() && !hasProgress) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6986 | endMargin = R.dimen.notification_content_picture_margin; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6987 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6988 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6989 | contentView.setViewLayoutMarginEndDimen(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6990 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6991 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6992 | |
| 6993 | /** |
| 6994 | * Notification style for media playback notifications. |
| 6995 | * |
| 6996 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 6997 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 6998 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6999 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 7000 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 7001 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7002 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7003 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 7004 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 7005 | * {@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] | 7006 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7007 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7008 | * Notifications created with MediaStyle will have their category set to |
| 7009 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 7010 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7011 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7012 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 7013 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7014 | * the System UI can identify this as a notification representing an active media session |
| 7015 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 7016 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7017 | * <p> |
| 7018 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 7019 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 7020 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 7021 | * <p> |
| 7022 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7023 | * To use this style with your Notification, feed it to |
| 7024 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7025 | * <pre class="prettyprint"> |
| 7026 | * Notification noti = new Notification.Builder() |
| 7027 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 7028 | * .setContentTitle("Track title") |
| 7029 | * .setContentText("Artist - Album") |
| 7030 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7031 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 7032 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7033 | * .build(); |
| 7034 | * </pre> |
| 7035 | * |
| 7036 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7037 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7038 | */ |
| 7039 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7040 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7041 | static final int MAX_MEDIA_BUTTONS = 5; |
| 7042 | |
| 7043 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7044 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7045 | |
| 7046 | public MediaStyle() { |
| 7047 | } |
| 7048 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 7049 | /** |
| 7050 | * @deprecated use {@code MediaStyle()}. |
| 7051 | */ |
| 7052 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7053 | public MediaStyle(Builder builder) { |
| 7054 | setBuilder(builder); |
| 7055 | } |
| 7056 | |
| 7057 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7058 | * 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] | 7059 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7060 | * |
| 7061 | * @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] | 7062 | */ |
| 7063 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 7064 | mActionsToShowInCompact = actions; |
| 7065 | return this; |
| 7066 | } |
| 7067 | |
| 7068 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7069 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 7070 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7071 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 7072 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7073 | mToken = token; |
| 7074 | return this; |
| 7075 | } |
| 7076 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7077 | /** |
| 7078 | * @hide |
| 7079 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7080 | @Override |
| 7081 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7082 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 7083 | if (wip.category == null) { |
| 7084 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 7085 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7086 | return wip; |
| 7087 | } |
| 7088 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7089 | /** |
| 7090 | * @hide |
| 7091 | */ |
| 7092 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7093 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7094 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | /** |
| 7098 | * @hide |
| 7099 | */ |
| 7100 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7101 | public RemoteViews makeBigContentView() { |
| 7102 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7103 | } |
| 7104 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7105 | /** |
| 7106 | * @hide |
| 7107 | */ |
| 7108 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7109 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7110 | RemoteViews expanded = makeMediaBigContentView(); |
| 7111 | return expanded != null ? expanded : makeMediaContentView(); |
| 7112 | } |
| 7113 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7114 | /** @hide */ |
| 7115 | @Override |
| 7116 | public void addExtras(Bundle extras) { |
| 7117 | super.addExtras(extras); |
| 7118 | |
| 7119 | if (mToken != null) { |
| 7120 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 7121 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 7122 | if (mActionsToShowInCompact != null) { |
| 7123 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 7124 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7125 | } |
| 7126 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7127 | /** |
| 7128 | * @hide |
| 7129 | */ |
| 7130 | @Override |
| 7131 | protected void restoreFromExtras(Bundle extras) { |
| 7132 | super.restoreFromExtras(extras); |
| 7133 | |
| 7134 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 7135 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 7136 | } |
| 7137 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 7138 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 7139 | } |
| 7140 | } |
| 7141 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7142 | private RemoteViews generateMediaActionButton(Action action, int color) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7143 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 7144 | RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 7145 | R.layout.notification_material_media_action); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 7146 | button.setImageViewIcon(R.id.action0, action.getIcon()); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 7147 | |
| 7148 | // If the action buttons should not be tinted, then just use the default |
| 7149 | // notification color. Otherwise, just use the passed-in color. |
| 7150 | int tintColor = mBuilder.shouldTintActionButtons() || mBuilder.isColorized() |
| 7151 | ? color |
| 7152 | : NotificationColorUtil.resolveColor(mBuilder.mContext, |
| 7153 | Notification.COLOR_DEFAULT); |
| 7154 | |
Sunny Goyal | 5b15392 | 2017-09-21 21:00:36 -0700 | [diff] [blame] | 7155 | button.setDrawableTint(R.id.action0, false, tintColor, |
| 7156 | PorterDuff.Mode.SRC_ATOP); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7157 | if (!tombstone) { |
| 7158 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 7159 | } |
| 7160 | button.setContentDescription(R.id.action0, action.title); |
| 7161 | return button; |
| 7162 | } |
| 7163 | |
| 7164 | private RemoteViews makeMediaContentView() { |
| 7165 | RemoteViews view = mBuilder.applyStandardTemplate( |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7166 | R.layout.notification_template_material_media, false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7167 | |
| 7168 | final int numActions = mBuilder.mActions.size(); |
| 7169 | final int N = mActionsToShowInCompact == null |
| 7170 | ? 0 |
| 7171 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 7172 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7173 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7174 | for (int i = 0; i < N; i++) { |
| 7175 | if (i >= numActions) { |
| 7176 | throw new IllegalArgumentException(String.format( |
| 7177 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 7178 | i, numActions - 1)); |
| 7179 | } |
| 7180 | |
| 7181 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7182 | final RemoteViews button = generateMediaActionButton(action, |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7183 | getPrimaryHighlightColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7184 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7185 | } |
| 7186 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 7187 | handleImage(view); |
| 7188 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7189 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 7190 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7191 | endMargin = R.dimen.notification_content_plus_picture_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 7192 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7193 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7194 | return view; |
| 7195 | } |
| 7196 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7197 | private int getPrimaryHighlightColor() { |
| 7198 | return mBuilder.getPrimaryHighlightColor(); |
| 7199 | } |
| 7200 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7201 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7202 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7203 | // Dont add an expanded view if there is no more content to be revealed |
| 7204 | int actionsInCompact = mActionsToShowInCompact == null |
| 7205 | ? 0 |
| 7206 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 7207 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 7208 | return null; |
| 7209 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7210 | RemoteViews big = mBuilder.applyStandardTemplate( |
| 7211 | R.layout.notification_template_material_big_media, |
| 7212 | false); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7213 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7214 | if (actionCount > 0) { |
| 7215 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 7216 | for (int i = 0; i < actionCount; i++) { |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7217 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i), |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7218 | getPrimaryHighlightColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7219 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7220 | } |
| 7221 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7222 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7223 | return big; |
| 7224 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7225 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 7226 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 7227 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7228 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 7229 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7230 | } |
| 7231 | } |
| 7232 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 7233 | /** |
| 7234 | * @hide |
| 7235 | */ |
| 7236 | @Override |
| 7237 | protected boolean hasProgress() { |
| 7238 | return false; |
| 7239 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 7240 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7241 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7242 | /** |
| 7243 | * Notification style for custom views that are decorated by the system |
| 7244 | * |
| 7245 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 7246 | * style and still obtain system decorations like the notification header with the expand |
| 7247 | * affordance and actions. |
| 7248 | * |
| 7249 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 7250 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 7251 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 7252 | * corresponding custom views to display. |
| 7253 | * |
| 7254 | * To use this style with your Notification, feed it to |
| 7255 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7256 | * <pre class="prettyprint"> |
| 7257 | * Notification noti = new Notification.Builder() |
| 7258 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 7259 | * .setLargeIcon(albumArtBitmap)) |
| 7260 | * .setCustomContentView(contentView); |
| 7261 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 7262 | * .build(); |
| 7263 | * </pre> |
| 7264 | */ |
| 7265 | public static class DecoratedCustomViewStyle extends Style { |
| 7266 | |
| 7267 | public DecoratedCustomViewStyle() { |
| 7268 | } |
| 7269 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7270 | /** |
| 7271 | * @hide |
| 7272 | */ |
| 7273 | public boolean displayCustomViewInline() { |
| 7274 | return true; |
| 7275 | } |
| 7276 | |
| 7277 | /** |
| 7278 | * @hide |
| 7279 | */ |
| 7280 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7281 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7282 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 7283 | } |
| 7284 | |
| 7285 | /** |
| 7286 | * @hide |
| 7287 | */ |
| 7288 | @Override |
| 7289 | public RemoteViews makeBigContentView() { |
| 7290 | return makeDecoratedBigContentView(); |
| 7291 | } |
| 7292 | |
| 7293 | /** |
| 7294 | * @hide |
| 7295 | */ |
| 7296 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7297 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7298 | return makeDecoratedHeadsUpContentView(); |
| 7299 | } |
| 7300 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7301 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 7302 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 7303 | ? mBuilder.mN.contentView |
| 7304 | : mBuilder.mN.headsUpContentView; |
| 7305 | if (mBuilder.mActions.size() == 0) { |
| 7306 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 7307 | } |
| 7308 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 7309 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7310 | buildIntoRemoteViewContent(remoteViews, headsUpContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7311 | return remoteViews; |
| 7312 | } |
| 7313 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7314 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
| 7315 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
| 7316 | mBuilder.getBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7317 | buildIntoRemoteViewContent(remoteViews, customContent); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7318 | return remoteViews; |
| 7319 | } |
| 7320 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7321 | private RemoteViews makeDecoratedBigContentView() { |
| 7322 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 7323 | ? mBuilder.mN.contentView |
| 7324 | : mBuilder.mN.bigContentView; |
| 7325 | if (mBuilder.mActions.size() == 0) { |
| 7326 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 7327 | } |
| 7328 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 7329 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7330 | buildIntoRemoteViewContent(remoteViews, bigContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7331 | return remoteViews; |
| 7332 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7333 | |
| 7334 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
| 7335 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 7336 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 7337 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 7338 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 7339 | customContent = customContent.clone(); |
Anthony Chen | 8f5f358 | 2017-04-11 11:18:37 -0700 | [diff] [blame] | 7340 | remoteViews.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress); |
| 7341 | remoteViews.addView(R.id.notification_main_column, customContent, 0 /* index */); |
Selim Cinek | fc8073c | 2017-08-16 17:50:20 -0700 | [diff] [blame] | 7342 | remoteViews.setReapplyDisallowed(); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 7343 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7344 | // also update the end margin if there is an image |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7345 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 7346 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7347 | endMargin = R.dimen.notification_content_plus_picture_margin_end; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7348 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 7349 | remoteViews.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 7350 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 7351 | } |
| 7352 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7353 | /** |
| 7354 | * Notification style for media custom views that are decorated by the system |
| 7355 | * |
| 7356 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 7357 | * this style and still obtain system decorations like the notification header with the expand |
| 7358 | * affordance and actions. |
| 7359 | * |
| 7360 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 7361 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 7362 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 7363 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 7364 | * <p> |
| 7365 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 7366 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 7367 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7368 | * To use this style with your Notification, feed it to |
| 7369 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 7370 | * <pre class="prettyprint"> |
| 7371 | * Notification noti = new Notification.Builder() |
| 7372 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 7373 | * .setLargeIcon(albumArtBitmap)) |
| 7374 | * .setCustomContentView(contentView); |
| 7375 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 7376 | * .setMediaSession(mySession)) |
| 7377 | * .build(); |
| 7378 | * </pre> |
| 7379 | * |
| 7380 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 7381 | * @see android.app.Notification.MediaStyle |
| 7382 | */ |
| 7383 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 7384 | |
| 7385 | public DecoratedMediaCustomViewStyle() { |
| 7386 | } |
| 7387 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7388 | /** |
| 7389 | * @hide |
| 7390 | */ |
| 7391 | public boolean displayCustomViewInline() { |
| 7392 | return true; |
| 7393 | } |
| 7394 | |
| 7395 | /** |
| 7396 | * @hide |
| 7397 | */ |
| 7398 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7399 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 7400 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7401 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 7402 | mBuilder.mN.contentView); |
| 7403 | } |
| 7404 | |
| 7405 | /** |
| 7406 | * @hide |
| 7407 | */ |
| 7408 | @Override |
| 7409 | public RemoteViews makeBigContentView() { |
| 7410 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 7411 | ? mBuilder.mN.bigContentView |
| 7412 | : mBuilder.mN.contentView; |
| 7413 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 7414 | } |
| 7415 | |
| 7416 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 7417 | RemoteViews remoteViews = super.makeBigContentView(); |
| 7418 | if (remoteViews != null) { |
| 7419 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 7420 | customRemoteView); |
| 7421 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 7422 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7423 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 7424 | customRemoteView); |
| 7425 | } else { |
| 7426 | return null; |
| 7427 | } |
| 7428 | } |
| 7429 | |
| 7430 | /** |
| 7431 | * @hide |
| 7432 | */ |
| 7433 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 7434 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7435 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 7436 | ? mBuilder.mN.headsUpContentView |
| 7437 | : mBuilder.mN.contentView; |
| 7438 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 7439 | } |
| 7440 | |
| 7441 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 7442 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 7443 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 7444 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 7445 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 7446 | customContent = customContent.clone(); |
Selim Cinek | 87c3153 | 2017-08-18 18:53:44 -0700 | [diff] [blame] | 7447 | customContent.overrideTextColors(mBuilder.getPrimaryTextColor()); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 7448 | remoteViews.removeAllViews(id); |
| 7449 | remoteViews.addView(id, customContent); |
Selim Cinek | fc8073c | 2017-08-16 17:50:20 -0700 | [diff] [blame] | 7450 | remoteViews.setReapplyDisallowed(); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 7451 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 7452 | return remoteViews; |
| 7453 | } |
| 7454 | } |
| 7455 | |
Selim Cinek | e7238dd | 2017-12-14 17:48:32 -0800 | [diff] [blame] | 7456 | /** |
| 7457 | * A Person associated with this Notification. |
| 7458 | */ |
| 7459 | public static final class Person implements Parcelable { |
| 7460 | @Nullable private CharSequence mName; |
| 7461 | @Nullable private Icon mIcon; |
| 7462 | @Nullable private String mUri; |
| 7463 | @Nullable private String mKey; |
| 7464 | |
| 7465 | protected Person(Parcel in) { |
| 7466 | mName = in.readCharSequence(); |
| 7467 | if (in.readInt() != 0) { |
| 7468 | mIcon = Icon.CREATOR.createFromParcel(in); |
| 7469 | } |
| 7470 | mUri = in.readString(); |
| 7471 | mKey = in.readString(); |
| 7472 | } |
| 7473 | |
| 7474 | /** |
| 7475 | * Create a new person. |
| 7476 | */ |
| 7477 | public Person() { |
| 7478 | } |
| 7479 | |
| 7480 | /** |
| 7481 | * Give this person a name. |
| 7482 | * |
| 7483 | * @param name the name of this person |
| 7484 | */ |
| 7485 | public Person setName(@Nullable CharSequence name) { |
| 7486 | this.mName = name; |
| 7487 | return this; |
| 7488 | } |
| 7489 | |
| 7490 | /** |
| 7491 | * Add an icon for this person. |
| 7492 | * <br /> |
| 7493 | * This is currently only used for {@link MessagingStyle} notifications and should not be |
| 7494 | * provided otherwise, in order to save memory. The system will prefer this icon over any |
| 7495 | * images that are resolved from the URI. |
| 7496 | * |
| 7497 | * @param icon the icon of the person |
| 7498 | */ |
| 7499 | public Person setIcon(@Nullable Icon icon) { |
| 7500 | this.mIcon = icon; |
| 7501 | return this; |
| 7502 | } |
| 7503 | |
| 7504 | /** |
| 7505 | * Set a URI associated with this person. |
| 7506 | * |
| 7507 | * <P> |
| 7508 | * Depending on user preferences, adding a URI to a Person may allow the notification to |
| 7509 | * pass through interruption filters, if this notification is of |
| 7510 | * category {@link #CATEGORY_CALL} or {@link #CATEGORY_MESSAGE}. |
| 7511 | * The addition of people may also cause this notification to appear more prominently in |
| 7512 | * the user interface. |
| 7513 | * </P> |
| 7514 | * |
| 7515 | * <P> |
| 7516 | * The person should be specified by the {@code String} representation of a |
| 7517 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 7518 | * </P> |
| 7519 | * |
| 7520 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 7521 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 7522 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 7523 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
| 7524 | * </P> |
| 7525 | * |
| 7526 | * @param uri a URI for the person |
| 7527 | */ |
| 7528 | public Person setUri(@Nullable String uri) { |
| 7529 | mUri = uri; |
| 7530 | return this; |
| 7531 | } |
| 7532 | |
| 7533 | /** |
| 7534 | * Add a key to this person in order to uniquely identify it. |
| 7535 | * This is especially useful if the name doesn't uniquely identify this person or if the |
| 7536 | * display name is a short handle of the actual name. |
| 7537 | * |
| 7538 | * <P>If no key is provided, the name serves as as the key for the purpose of |
| 7539 | * identification.</P> |
| 7540 | * |
| 7541 | * @param key the key that uniquely identifies this person |
| 7542 | */ |
| 7543 | public Person setKey(@Nullable String key) { |
| 7544 | mKey = key; |
| 7545 | return this; |
| 7546 | } |
| 7547 | |
| 7548 | |
| 7549 | /** |
| 7550 | * @return the uri provided for this person or {@code null} if no Uri was provided |
| 7551 | */ |
| 7552 | @Nullable |
| 7553 | public String getUri() { |
| 7554 | return mUri; |
| 7555 | } |
| 7556 | |
| 7557 | /** |
| 7558 | * @return the name provided for this person or {@code null} if no name was provided |
| 7559 | */ |
| 7560 | @Nullable |
| 7561 | public CharSequence getName() { |
| 7562 | return mName; |
| 7563 | } |
| 7564 | |
| 7565 | /** |
| 7566 | * @return the icon provided for this person or {@code null} if no icon was provided |
| 7567 | */ |
| 7568 | @Nullable |
| 7569 | public Icon getIcon() { |
| 7570 | return mIcon; |
| 7571 | } |
| 7572 | |
| 7573 | /** |
| 7574 | * @return the key provided for this person or {@code null} if no key was provided |
| 7575 | */ |
| 7576 | @Nullable |
| 7577 | public String getKey() { |
| 7578 | return mKey; |
| 7579 | } |
| 7580 | |
| 7581 | /** |
| 7582 | * @return the URI associated with this person, or "name:mName" otherwise |
| 7583 | * @hide |
| 7584 | */ |
| 7585 | public String resolveToLegacyUri() { |
| 7586 | if (mUri != null) { |
| 7587 | return mUri; |
| 7588 | } |
| 7589 | if (mName != null) { |
| 7590 | return "name:" + mName; |
| 7591 | } |
| 7592 | return ""; |
| 7593 | } |
| 7594 | |
| 7595 | @Override |
| 7596 | public int describeContents() { |
| 7597 | return 0; |
| 7598 | } |
| 7599 | |
| 7600 | @Override |
| 7601 | public void writeToParcel(Parcel dest, @WriteFlags int flags) { |
| 7602 | dest.writeCharSequence(mName); |
| 7603 | if (mIcon != null) { |
| 7604 | dest.writeInt(1); |
| 7605 | mIcon.writeToParcel(dest, 0); |
| 7606 | } else { |
| 7607 | dest.writeInt(0); |
| 7608 | } |
| 7609 | dest.writeString(mUri); |
| 7610 | dest.writeString(mKey); |
| 7611 | } |
| 7612 | |
| 7613 | public static final Creator<Person> CREATOR = new Creator<Person>() { |
| 7614 | @Override |
| 7615 | public Person createFromParcel(Parcel in) { |
| 7616 | return new Person(in); |
| 7617 | } |
| 7618 | |
| 7619 | @Override |
| 7620 | public Person[] newArray(int size) { |
| 7621 | return new Person[size]; |
| 7622 | } |
| 7623 | }; |
| 7624 | } |
| 7625 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7626 | // When adding a new Style subclass here, don't forget to update |
| 7627 | // Builder.getNotificationStyleClass. |
| 7628 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7629 | /** |
| 7630 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 7631 | * metadata or change options on a notification builder. |
| 7632 | */ |
| 7633 | public interface Extender { |
| 7634 | /** |
| 7635 | * Apply this extender to a notification builder. |
| 7636 | * @param builder the builder to be modified. |
| 7637 | * @return the build object for chaining. |
| 7638 | */ |
| 7639 | public Builder extend(Builder builder); |
| 7640 | } |
| 7641 | |
| 7642 | /** |
| 7643 | * Helper class to add wearable extensions to notifications. |
| 7644 | * <p class="note"> See |
| 7645 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 7646 | * for Android Wear</a> for more information on how to use this class. |
| 7647 | * <p> |
| 7648 | * To create a notification with wearable extensions: |
| 7649 | * <ol> |
| 7650 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 7651 | * properties. |
| 7652 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 7653 | * <li>Set wearable-specific properties using the |
| 7654 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 7655 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 7656 | * notification. |
| 7657 | * <li>Post the notification to the notification system with the |
| 7658 | * {@code NotificationManager.notify(...)} methods. |
| 7659 | * </ol> |
| 7660 | * |
| 7661 | * <pre class="prettyprint"> |
| 7662 | * Notification notif = new Notification.Builder(mContext) |
| 7663 | * .setContentTitle("New mail from " + sender.toString()) |
| 7664 | * .setContentText(subject) |
| 7665 | * .setSmallIcon(R.drawable.new_mail) |
| 7666 | * .extend(new Notification.WearableExtender() |
| 7667 | * .setContentIcon(R.drawable.new_mail)) |
| 7668 | * .build(); |
| 7669 | * NotificationManager notificationManger = |
| 7670 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 7671 | * notificationManger.notify(0, notif);</pre> |
| 7672 | * |
| 7673 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 7674 | * {@code WearableExtender(Notification)} constructor, |
| 7675 | * and then using the {@code get} methods to access values. |
| 7676 | * |
| 7677 | * <pre class="prettyprint"> |
| 7678 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 7679 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 7680 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7681 | */ |
| 7682 | public static final class WearableExtender implements Extender { |
| 7683 | /** |
| 7684 | * Sentinel value for an action index that is unset. |
| 7685 | */ |
| 7686 | public static final int UNSET_ACTION_INDEX = -1; |
| 7687 | |
| 7688 | /** |
| 7689 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 7690 | * default sizing. |
| 7691 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 7692 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7693 | * on their content. |
| 7694 | */ |
| 7695 | public static final int SIZE_DEFAULT = 0; |
| 7696 | |
| 7697 | /** |
| 7698 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 7699 | * with an extra small size. |
| 7700 | * <p>This value is only applicable for custom display notifications created using |
| 7701 | * {@link #setDisplayIntent}. |
| 7702 | */ |
| 7703 | public static final int SIZE_XSMALL = 1; |
| 7704 | |
| 7705 | /** |
| 7706 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 7707 | * with a small size. |
| 7708 | * <p>This value is only applicable for custom display notifications created using |
| 7709 | * {@link #setDisplayIntent}. |
| 7710 | */ |
| 7711 | public static final int SIZE_SMALL = 2; |
| 7712 | |
| 7713 | /** |
| 7714 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 7715 | * with a medium size. |
| 7716 | * <p>This value is only applicable for custom display notifications created using |
| 7717 | * {@link #setDisplayIntent}. |
| 7718 | */ |
| 7719 | public static final int SIZE_MEDIUM = 3; |
| 7720 | |
| 7721 | /** |
| 7722 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 7723 | * with a large size. |
| 7724 | * <p>This value is only applicable for custom display notifications created using |
| 7725 | * {@link #setDisplayIntent}. |
| 7726 | */ |
| 7727 | public static final int SIZE_LARGE = 4; |
| 7728 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 7729 | /** |
| 7730 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 7731 | * full screen. |
| 7732 | * <p>This value is only applicable for custom display notifications created using |
| 7733 | * {@link #setDisplayIntent}. |
| 7734 | */ |
| 7735 | public static final int SIZE_FULL_SCREEN = 5; |
| 7736 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7737 | /** |
| 7738 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 7739 | * short amount of time when this notification is displayed on the screen. This |
| 7740 | * is the default value. |
| 7741 | */ |
| 7742 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 7743 | |
| 7744 | /** |
| 7745 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 7746 | * for a longer amount of time when this notification is displayed on the screen. |
| 7747 | */ |
| 7748 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 7749 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7750 | /** Notification extra which contains wearable extensions */ |
| 7751 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 7752 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 7753 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7754 | private static final String KEY_ACTIONS = "actions"; |
| 7755 | private static final String KEY_FLAGS = "flags"; |
| 7756 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 7757 | private static final String KEY_PAGES = "pages"; |
| 7758 | private static final String KEY_BACKGROUND = "background"; |
| 7759 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 7760 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 7761 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 7762 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 7763 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 7764 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7765 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7766 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7767 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7768 | |
| 7769 | // Flags bitwise-ored to mFlags |
| 7770 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 7771 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 7772 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 7773 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7774 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 7775 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 7776 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7777 | |
| 7778 | // Default value for flags integer |
| 7779 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 7780 | |
| 7781 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 7782 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 7783 | |
| 7784 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 7785 | private int mFlags = DEFAULT_FLAGS; |
| 7786 | private PendingIntent mDisplayIntent; |
| 7787 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 7788 | private Bitmap mBackground; |
| 7789 | private int mContentIcon; |
| 7790 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 7791 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 7792 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 7793 | private int mCustomContentHeight; |
| 7794 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7795 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7796 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7797 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7798 | |
| 7799 | /** |
| 7800 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 7801 | * options. |
| 7802 | */ |
| 7803 | public WearableExtender() { |
| 7804 | } |
| 7805 | |
| 7806 | public WearableExtender(Notification notif) { |
| 7807 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 7808 | if (wearableBundle != null) { |
| 7809 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 7810 | if (actions != null) { |
| 7811 | mActions.addAll(actions); |
| 7812 | } |
| 7813 | |
| 7814 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 7815 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 7816 | |
| 7817 | Notification[] pages = getNotificationArrayFromBundle( |
| 7818 | wearableBundle, KEY_PAGES); |
| 7819 | if (pages != null) { |
| 7820 | Collections.addAll(mPages, pages); |
| 7821 | } |
| 7822 | |
| 7823 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 7824 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 7825 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 7826 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 7827 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 7828 | UNSET_ACTION_INDEX); |
| 7829 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 7830 | SIZE_DEFAULT); |
| 7831 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 7832 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7833 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7834 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7835 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7836 | } |
| 7837 | } |
| 7838 | |
| 7839 | /** |
| 7840 | * Apply wearable extensions to a notification that is being built. This is typically |
| 7841 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 7842 | * {@link android.app.Notification.Builder}. |
| 7843 | */ |
| 7844 | @Override |
| 7845 | public Notification.Builder extend(Notification.Builder builder) { |
| 7846 | Bundle wearableBundle = new Bundle(); |
| 7847 | |
| 7848 | if (!mActions.isEmpty()) { |
| 7849 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 7850 | } |
| 7851 | if (mFlags != DEFAULT_FLAGS) { |
| 7852 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 7853 | } |
| 7854 | if (mDisplayIntent != null) { |
| 7855 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 7856 | } |
| 7857 | if (!mPages.isEmpty()) { |
| 7858 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 7859 | new Notification[mPages.size()])); |
| 7860 | } |
| 7861 | if (mBackground != null) { |
| 7862 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 7863 | } |
| 7864 | if (mContentIcon != 0) { |
| 7865 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 7866 | } |
| 7867 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 7868 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 7869 | } |
| 7870 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 7871 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 7872 | mContentActionIndex); |
| 7873 | } |
| 7874 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 7875 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 7876 | } |
| 7877 | if (mCustomContentHeight != 0) { |
| 7878 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 7879 | } |
| 7880 | if (mGravity != DEFAULT_GRAVITY) { |
| 7881 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 7882 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7883 | if (mHintScreenTimeout != 0) { |
| 7884 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 7885 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7886 | if (mDismissalId != null) { |
| 7887 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 7888 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7889 | if (mBridgeTag != null) { |
| 7890 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 7891 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7892 | |
| 7893 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 7894 | return builder; |
| 7895 | } |
| 7896 | |
| 7897 | @Override |
| 7898 | public WearableExtender clone() { |
| 7899 | WearableExtender that = new WearableExtender(); |
| 7900 | that.mActions = new ArrayList<Action>(this.mActions); |
| 7901 | that.mFlags = this.mFlags; |
| 7902 | that.mDisplayIntent = this.mDisplayIntent; |
| 7903 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 7904 | that.mBackground = this.mBackground; |
| 7905 | that.mContentIcon = this.mContentIcon; |
| 7906 | that.mContentIconGravity = this.mContentIconGravity; |
| 7907 | that.mContentActionIndex = this.mContentActionIndex; |
| 7908 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 7909 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 7910 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7911 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7912 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7913 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7914 | return that; |
| 7915 | } |
| 7916 | |
| 7917 | /** |
| 7918 | * Add a wearable action to this notification. |
| 7919 | * |
| 7920 | * <p>When wearable actions are added using this method, the set of actions that |
| 7921 | * show on a wearable device splits from devices that only show actions added |
| 7922 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 7923 | * of which actions display on different devices. |
| 7924 | * |
| 7925 | * @param action the action to add to this notification |
| 7926 | * @return this object for method chaining |
| 7927 | * @see android.app.Notification.Action |
| 7928 | */ |
| 7929 | public WearableExtender addAction(Action action) { |
| 7930 | mActions.add(action); |
| 7931 | return this; |
| 7932 | } |
| 7933 | |
| 7934 | /** |
| 7935 | * Adds wearable actions to this notification. |
| 7936 | * |
| 7937 | * <p>When wearable actions are added using this method, the set of actions that |
| 7938 | * show on a wearable device splits from devices that only show actions added |
| 7939 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 7940 | * of which actions display on different devices. |
| 7941 | * |
| 7942 | * @param actions the actions to add to this notification |
| 7943 | * @return this object for method chaining |
| 7944 | * @see android.app.Notification.Action |
| 7945 | */ |
| 7946 | public WearableExtender addActions(List<Action> actions) { |
| 7947 | mActions.addAll(actions); |
| 7948 | return this; |
| 7949 | } |
| 7950 | |
| 7951 | /** |
| 7952 | * Clear all wearable actions present on this builder. |
| 7953 | * @return this object for method chaining. |
| 7954 | * @see #addAction |
| 7955 | */ |
| 7956 | public WearableExtender clearActions() { |
| 7957 | mActions.clear(); |
| 7958 | return this; |
| 7959 | } |
| 7960 | |
| 7961 | /** |
| 7962 | * Get the wearable actions present on this notification. |
| 7963 | */ |
| 7964 | public List<Action> getActions() { |
| 7965 | return mActions; |
| 7966 | } |
| 7967 | |
| 7968 | /** |
| 7969 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 7970 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 7971 | * |
| 7972 | * <pre class="prettyprint"> |
| 7973 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 7974 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 7975 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 7976 | * Notification notif = new Notification.Builder(context) |
| 7977 | * .extend(new Notification.WearableExtender() |
| 7978 | * .setDisplayIntent(displayPendingIntent) |
| 7979 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 7980 | * .build();</pre> |
| 7981 | * |
| 7982 | * <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] | 7983 | * should have an empty task affinity. It is also recommended to use the device |
| 7984 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 7985 | * |
| 7986 | * <p>Example AndroidManifest.xml entry: |
| 7987 | * <pre class="prettyprint"> |
| 7988 | * <activity android:name="com.example.MyDisplayActivity" |
| 7989 | * android:exported="true" |
| 7990 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 7991 | * android:taskAffinity="" |
| 7992 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7993 | * |
| 7994 | * @param intent the {@link PendingIntent} for an activity |
| 7995 | * @return this object for method chaining |
| 7996 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 7997 | */ |
| 7998 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 7999 | mDisplayIntent = intent; |
| 8000 | return this; |
| 8001 | } |
| 8002 | |
| 8003 | /** |
| 8004 | * Get the intent to launch inside of an activity view when displaying this |
| 8005 | * notification. This {@code PendingIntent} should be for an activity. |
| 8006 | */ |
| 8007 | public PendingIntent getDisplayIntent() { |
| 8008 | return mDisplayIntent; |
| 8009 | } |
| 8010 | |
| 8011 | /** |
| 8012 | * Add an additional page of content to display with this notification. The current |
| 8013 | * notification forms the first page, and pages added using this function form |
| 8014 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8015 | * sections. |
| 8016 | * |
| 8017 | * @param page the notification to add as another page |
| 8018 | * @return this object for method chaining |
| 8019 | * @see android.app.Notification.WearableExtender#getPages |
| 8020 | */ |
| 8021 | public WearableExtender addPage(Notification page) { |
| 8022 | mPages.add(page); |
| 8023 | return this; |
| 8024 | } |
| 8025 | |
| 8026 | /** |
| 8027 | * Add additional pages of content to display with this notification. The current |
| 8028 | * notification forms the first page, and pages added using this function form |
| 8029 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8030 | * sections. |
| 8031 | * |
| 8032 | * @param pages a list of notifications |
| 8033 | * @return this object for method chaining |
| 8034 | * @see android.app.Notification.WearableExtender#getPages |
| 8035 | */ |
| 8036 | public WearableExtender addPages(List<Notification> pages) { |
| 8037 | mPages.addAll(pages); |
| 8038 | return this; |
| 8039 | } |
| 8040 | |
| 8041 | /** |
| 8042 | * Clear all additional pages present on this builder. |
| 8043 | * @return this object for method chaining. |
| 8044 | * @see #addPage |
| 8045 | */ |
| 8046 | public WearableExtender clearPages() { |
| 8047 | mPages.clear(); |
| 8048 | return this; |
| 8049 | } |
| 8050 | |
| 8051 | /** |
| 8052 | * Get the array of additional pages of content for displaying this notification. The |
| 8053 | * current notification forms the first page, and elements within this array form |
| 8054 | * subsequent pages. This field can be used to separate a notification into multiple |
| 8055 | * sections. |
| 8056 | * @return the pages for this notification |
| 8057 | */ |
| 8058 | public List<Notification> getPages() { |
| 8059 | return mPages; |
| 8060 | } |
| 8061 | |
| 8062 | /** |
| 8063 | * Set a background image to be displayed behind the notification content. |
| 8064 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 8065 | * will work with any notification style. |
| 8066 | * |
| 8067 | * @param background the background bitmap |
| 8068 | * @return this object for method chaining |
| 8069 | * @see android.app.Notification.WearableExtender#getBackground |
| 8070 | */ |
| 8071 | public WearableExtender setBackground(Bitmap background) { |
| 8072 | mBackground = background; |
| 8073 | return this; |
| 8074 | } |
| 8075 | |
| 8076 | /** |
| 8077 | * Get a background image to be displayed behind the notification content. |
| 8078 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 8079 | * will work with any notification style. |
| 8080 | * |
| 8081 | * @return the background image |
| 8082 | * @see android.app.Notification.WearableExtender#setBackground |
| 8083 | */ |
| 8084 | public Bitmap getBackground() { |
| 8085 | return mBackground; |
| 8086 | } |
| 8087 | |
| 8088 | /** |
| 8089 | * Set an icon that goes with the content of this notification. |
| 8090 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8091 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8092 | public WearableExtender setContentIcon(int icon) { |
| 8093 | mContentIcon = icon; |
| 8094 | return this; |
| 8095 | } |
| 8096 | |
| 8097 | /** |
| 8098 | * Get an icon that goes with the content of this notification. |
| 8099 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8100 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8101 | public int getContentIcon() { |
| 8102 | return mContentIcon; |
| 8103 | } |
| 8104 | |
| 8105 | /** |
| 8106 | * Set the gravity that the content icon should have within the notification display. |
| 8107 | * Supported values include {@link android.view.Gravity#START} and |
| 8108 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 8109 | * @see #setContentIcon |
| 8110 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8111 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8112 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 8113 | mContentIconGravity = contentIconGravity; |
| 8114 | return this; |
| 8115 | } |
| 8116 | |
| 8117 | /** |
| 8118 | * Get the gravity that the content icon should have within the notification display. |
| 8119 | * Supported values include {@link android.view.Gravity#START} and |
| 8120 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 8121 | * @see #getContentIcon |
| 8122 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8123 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8124 | public int getContentIconGravity() { |
| 8125 | return mContentIconGravity; |
| 8126 | } |
| 8127 | |
| 8128 | /** |
| 8129 | * 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] | 8130 | * this notification. This action will no longer display separately from the |
| 8131 | * notification's content. |
| 8132 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 8133 | * <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] | 8134 | * set, although the list of available actions comes from the main notification and not |
| 8135 | * from the child page's notification. |
| 8136 | * |
| 8137 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 8138 | * If wearable actions were added to the main notification, this index |
| 8139 | * will apply to that list, otherwise it will apply to the regular |
| 8140 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8141 | */ |
| 8142 | public WearableExtender setContentAction(int actionIndex) { |
| 8143 | mContentActionIndex = actionIndex; |
| 8144 | return this; |
| 8145 | } |
| 8146 | |
| 8147 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 8148 | * Get the index of the notification action, if any, that was specified as being clickable |
| 8149 | * 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] | 8150 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8151 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 8152 | * <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] | 8153 | * set, although the list of available actions comes from the main notification and not |
| 8154 | * from the child page's notification. |
| 8155 | * |
| 8156 | * <p>If wearable specific actions were added to the main notification, this index will |
| 8157 | * 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] | 8158 | * |
| 8159 | * @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] | 8160 | */ |
| 8161 | public int getContentAction() { |
| 8162 | return mContentActionIndex; |
| 8163 | } |
| 8164 | |
| 8165 | /** |
| 8166 | * Set the gravity that this notification should have within the available viewport space. |
| 8167 | * Supported values include {@link android.view.Gravity#TOP}, |
| 8168 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 8169 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 8170 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8171 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8172 | public WearableExtender setGravity(int gravity) { |
| 8173 | mGravity = gravity; |
| 8174 | return this; |
| 8175 | } |
| 8176 | |
| 8177 | /** |
| 8178 | * Get the gravity that this notification should have within the available viewport space. |
| 8179 | * Supported values include {@link android.view.Gravity#TOP}, |
| 8180 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 8181 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 8182 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8183 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8184 | public int getGravity() { |
| 8185 | return mGravity; |
| 8186 | } |
| 8187 | |
| 8188 | /** |
| 8189 | * Set the custom size preset for the display of this notification out of the available |
| 8190 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 8191 | * {@link #SIZE_LARGE}. |
| 8192 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 8193 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 8194 | * documentation for the preset in question. See also |
| 8195 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 8196 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8197 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8198 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 8199 | mCustomSizePreset = sizePreset; |
| 8200 | return this; |
| 8201 | } |
| 8202 | |
| 8203 | /** |
| 8204 | * Get the custom size preset for the display of this notification out of the available |
| 8205 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 8206 | * {@link #SIZE_LARGE}. |
| 8207 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 8208 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 8209 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 8210 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8211 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8212 | public int getCustomSizePreset() { |
| 8213 | return mCustomSizePreset; |
| 8214 | } |
| 8215 | |
| 8216 | /** |
| 8217 | * Set the custom height in pixels for the display of this notification's content. |
| 8218 | * <p>This option is only available for custom display notifications created |
| 8219 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 8220 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 8221 | * {@link #getCustomContentHeight}. |
| 8222 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8223 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8224 | public WearableExtender setCustomContentHeight(int height) { |
| 8225 | mCustomContentHeight = height; |
| 8226 | return this; |
| 8227 | } |
| 8228 | |
| 8229 | /** |
| 8230 | * Get the custom height in pixels for the display of this notification's content. |
| 8231 | * <p>This option is only available for custom display notifications created |
| 8232 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 8233 | * {@link #setCustomContentHeight}. |
| 8234 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8235 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8236 | public int getCustomContentHeight() { |
| 8237 | return mCustomContentHeight; |
| 8238 | } |
| 8239 | |
| 8240 | /** |
| 8241 | * Set whether the scrolling position for the contents of this notification should start |
| 8242 | * at the bottom of the contents instead of the top when the contents are too long to |
| 8243 | * display within the screen. Default is false (start scroll at the top). |
| 8244 | */ |
| 8245 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 8246 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 8247 | return this; |
| 8248 | } |
| 8249 | |
| 8250 | /** |
| 8251 | * Get whether the scrolling position for the contents of this notification should start |
| 8252 | * at the bottom of the contents instead of the top when the contents are too long to |
| 8253 | * display within the screen. Default is false (start scroll at the top). |
| 8254 | */ |
| 8255 | public boolean getStartScrollBottom() { |
| 8256 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 8257 | } |
| 8258 | |
| 8259 | /** |
| 8260 | * Set whether the content intent is available when the wearable device is not connected |
| 8261 | * to a companion device. The user can still trigger this intent when the wearable device |
| 8262 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 8263 | * Defaults to true. |
| 8264 | */ |
| 8265 | public WearableExtender setContentIntentAvailableOffline( |
| 8266 | boolean contentIntentAvailableOffline) { |
| 8267 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 8268 | return this; |
| 8269 | } |
| 8270 | |
| 8271 | /** |
| 8272 | * Get whether the content intent is available when the wearable device is not connected |
| 8273 | * to a companion device. The user can still trigger this intent when the wearable device |
| 8274 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 8275 | * Defaults to true. |
| 8276 | */ |
| 8277 | public boolean getContentIntentAvailableOffline() { |
| 8278 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 8279 | } |
| 8280 | |
| 8281 | /** |
| 8282 | * Set a hint that this notification's icon should not be displayed. |
| 8283 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 8284 | * @return this object for method chaining |
| 8285 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8286 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8287 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 8288 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 8289 | return this; |
| 8290 | } |
| 8291 | |
| 8292 | /** |
| 8293 | * Get a hint that this notification's icon should not be displayed. |
| 8294 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 8295 | * The default value is {@code false} if this was never set. |
| 8296 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8297 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8298 | public boolean getHintHideIcon() { |
| 8299 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 8300 | } |
| 8301 | |
| 8302 | /** |
| 8303 | * Set a visual hint that only the background image of this notification should be |
| 8304 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 8305 | * to sub-pages added using {@link #addPage}. |
| 8306 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8307 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8308 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 8309 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 8310 | return this; |
| 8311 | } |
| 8312 | |
| 8313 | /** |
| 8314 | * Get a visual hint that only the background image of this notification should be |
| 8315 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 8316 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 8317 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8318 | @Deprecated |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8319 | public boolean getHintShowBackgroundOnly() { |
| 8320 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 8321 | } |
| 8322 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8323 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 8324 | * Set a hint that this notification's background should not be clipped if possible, |
| 8325 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 8326 | * 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] | 8327 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 8328 | * @return this object for method chaining |
| 8329 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8330 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8331 | public WearableExtender setHintAvoidBackgroundClipping( |
| 8332 | boolean hintAvoidBackgroundClipping) { |
| 8333 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 8334 | return this; |
| 8335 | } |
| 8336 | |
| 8337 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 8338 | * Get a hint that this notification's background should not be clipped if possible, |
| 8339 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 8340 | * 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] | 8341 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 8342 | * otherwise. The default value is {@code false} if this was never set. |
| 8343 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8344 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8345 | public boolean getHintAvoidBackgroundClipping() { |
| 8346 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 8347 | } |
| 8348 | |
| 8349 | /** |
| 8350 | * Set a hint that the screen should remain on for at least this duration when |
| 8351 | * this notification is displayed on the screen. |
| 8352 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 8353 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 8354 | * @return this object for method chaining |
| 8355 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8356 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8357 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 8358 | mHintScreenTimeout = timeout; |
| 8359 | return this; |
| 8360 | } |
| 8361 | |
| 8362 | /** |
| 8363 | * Get the duration, in milliseconds, that the screen should remain on for |
| 8364 | * when this notification is displayed. |
| 8365 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 8366 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 8367 | */ |
Gus Prevas | b5f9cf5 | 2018-02-21 14:21:50 -0500 | [diff] [blame] | 8368 | @Deprecated |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 8369 | public int getHintScreenTimeout() { |
| 8370 | return mHintScreenTimeout; |
| 8371 | } |
| 8372 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8373 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 8374 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 8375 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 8376 | * qr codes, as well as other simple black-and-white tickets. |
| 8377 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 8378 | * @return this object for method chaining |
| 8379 | */ |
| 8380 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 8381 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 8382 | return this; |
| 8383 | } |
| 8384 | |
| 8385 | /** |
| 8386 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 8387 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 8388 | * qr codes, as well as other simple black-and-white tickets. |
| 8389 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 8390 | * otherwise. The default value is {@code false} if this was never set. |
| 8391 | */ |
| 8392 | public boolean getHintAmbientBigPicture() { |
| 8393 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 8394 | } |
| 8395 | |
| 8396 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 8397 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 8398 | * directly, telling the platform that it can generate the appropriate transitions. |
| 8399 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 8400 | * an activity and transitions should be generated, false otherwise. |
| 8401 | * @return this object for method chaining |
| 8402 | */ |
| 8403 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 8404 | boolean hintContentIntentLaunchesActivity) { |
| 8405 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 8406 | return this; |
| 8407 | } |
| 8408 | |
| 8409 | /** |
| 8410 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 8411 | * directly, telling the platform that it can generate the appropriate transitions |
| 8412 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 8413 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 8414 | */ |
| 8415 | public boolean getHintContentIntentLaunchesActivity() { |
| 8416 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 8417 | } |
| 8418 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8419 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8420 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 8421 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 8422 | * 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] | 8423 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8424 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 8425 | * @param dismissalId the dismissal id of the notification. |
| 8426 | * @return this object for method chaining |
| 8427 | */ |
| 8428 | public WearableExtender setDismissalId(String dismissalId) { |
| 8429 | mDismissalId = dismissalId; |
| 8430 | return this; |
| 8431 | } |
| 8432 | |
| 8433 | /** |
| 8434 | * Returns the dismissal id of the notification. |
| 8435 | * @return the dismissal id of the notification or null if it has not been set. |
| 8436 | */ |
| 8437 | public String getDismissalId() { |
| 8438 | return mDismissalId; |
| 8439 | } |
| 8440 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 8441 | /** |
| 8442 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 8443 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 8444 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 8445 | * Features to Notifications</a> for more information. |
| 8446 | * @param bridgeTag the bridge tag of the notification. |
| 8447 | * @return this object for method chaining |
| 8448 | */ |
| 8449 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 8450 | mBridgeTag = bridgeTag; |
| 8451 | return this; |
| 8452 | } |
| 8453 | |
| 8454 | /** |
| 8455 | * Returns the bridge tag of the notification. |
| 8456 | * @return the bridge tag or null if not present. |
| 8457 | */ |
| 8458 | public String getBridgeTag() { |
| 8459 | return mBridgeTag; |
| 8460 | } |
| 8461 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8462 | private void setFlag(int mask, boolean value) { |
| 8463 | if (value) { |
| 8464 | mFlags |= mask; |
| 8465 | } else { |
| 8466 | mFlags &= ~mask; |
| 8467 | } |
| 8468 | } |
| 8469 | } |
| 8470 | |
| 8471 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 8472 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 8473 | * with car extensions: |
| 8474 | * |
| 8475 | * <ol> |
| 8476 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 8477 | * properties. |
| 8478 | * <li>Create a {@link CarExtender}. |
| 8479 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 8480 | * {@link CarExtender}. |
| 8481 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 8482 | * to apply the extensions to a notification. |
| 8483 | * </ol> |
| 8484 | * |
| 8485 | * <pre class="prettyprint"> |
| 8486 | * Notification notification = new Notification.Builder(context) |
| 8487 | * ... |
| 8488 | * .extend(new CarExtender() |
| 8489 | * .set*(...)) |
| 8490 | * .build(); |
| 8491 | * </pre> |
| 8492 | * |
| 8493 | * <p>Car extensions can be accessed on an existing notification by using the |
| 8494 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 8495 | * to access values. |
| 8496 | */ |
| 8497 | public static final class CarExtender implements Extender { |
| 8498 | private static final String TAG = "CarExtender"; |
| 8499 | |
| 8500 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 8501 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 8502 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 8503 | private static final String EXTRA_COLOR = "app_color"; |
| 8504 | |
| 8505 | private Bitmap mLargeIcon; |
| 8506 | private UnreadConversation mUnreadConversation; |
| 8507 | private int mColor = Notification.COLOR_DEFAULT; |
| 8508 | |
| 8509 | /** |
| 8510 | * Create a {@link CarExtender} with default options. |
| 8511 | */ |
| 8512 | public CarExtender() { |
| 8513 | } |
| 8514 | |
| 8515 | /** |
| 8516 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 8517 | * |
| 8518 | * @param notif The notification from which to copy options. |
| 8519 | */ |
| 8520 | public CarExtender(Notification notif) { |
| 8521 | Bundle carBundle = notif.extras == null ? |
| 8522 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 8523 | if (carBundle != null) { |
| 8524 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 8525 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 8526 | |
| 8527 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 8528 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 8529 | } |
| 8530 | } |
| 8531 | |
| 8532 | /** |
| 8533 | * Apply car extensions to a notification that is being built. This is typically called by |
| 8534 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 8535 | * method of {@link Notification.Builder}. |
| 8536 | */ |
| 8537 | @Override |
| 8538 | public Notification.Builder extend(Notification.Builder builder) { |
| 8539 | Bundle carExtensions = new Bundle(); |
| 8540 | |
| 8541 | if (mLargeIcon != null) { |
| 8542 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 8543 | } |
| 8544 | if (mColor != Notification.COLOR_DEFAULT) { |
| 8545 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 8546 | } |
| 8547 | |
| 8548 | if (mUnreadConversation != null) { |
| 8549 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 8550 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 8551 | } |
| 8552 | |
| 8553 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 8554 | return builder; |
| 8555 | } |
| 8556 | |
| 8557 | /** |
| 8558 | * Sets the accent color to use when Android Auto presents the notification. |
| 8559 | * |
| 8560 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 8561 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 8562 | * automotive setting. This method can be used to override the color provided in the |
| 8563 | * notification in such a situation. |
| 8564 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 8565 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 8566 | mColor = color; |
| 8567 | return this; |
| 8568 | } |
| 8569 | |
| 8570 | /** |
| 8571 | * Gets the accent color. |
| 8572 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 8573 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 8574 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 8575 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 8576 | public int getColor() { |
| 8577 | return mColor; |
| 8578 | } |
| 8579 | |
| 8580 | /** |
| 8581 | * Sets the large icon of the car notification. |
| 8582 | * |
| 8583 | * If no large icon is set in the extender, Android Auto will display the icon |
| 8584 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 8585 | * |
| 8586 | * @param largeIcon The large icon to use in the car notification. |
| 8587 | * @return This object for method chaining. |
| 8588 | */ |
| 8589 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 8590 | mLargeIcon = largeIcon; |
| 8591 | return this; |
| 8592 | } |
| 8593 | |
| 8594 | /** |
| 8595 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 8596 | * |
| 8597 | * @return The large icon for the car notification. |
| 8598 | * @see CarExtender#setLargeIcon |
| 8599 | */ |
| 8600 | public Bitmap getLargeIcon() { |
| 8601 | return mLargeIcon; |
| 8602 | } |
| 8603 | |
| 8604 | /** |
| 8605 | * Sets the unread conversation in a message notification. |
| 8606 | * |
| 8607 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 8608 | * @return This object for method chaining. |
| 8609 | */ |
| 8610 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 8611 | mUnreadConversation = unreadConversation; |
| 8612 | return this; |
| 8613 | } |
| 8614 | |
| 8615 | /** |
| 8616 | * Returns the unread conversation conveyed by this notification. |
| 8617 | * @see #setUnreadConversation(UnreadConversation) |
| 8618 | */ |
| 8619 | public UnreadConversation getUnreadConversation() { |
| 8620 | return mUnreadConversation; |
| 8621 | } |
| 8622 | |
| 8623 | /** |
| 8624 | * A class which holds the unread messages from a conversation. |
| 8625 | */ |
| 8626 | public static class UnreadConversation { |
| 8627 | private static final String KEY_AUTHOR = "author"; |
| 8628 | private static final String KEY_TEXT = "text"; |
| 8629 | private static final String KEY_MESSAGES = "messages"; |
| 8630 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 8631 | private static final String KEY_ON_REPLY = "on_reply"; |
| 8632 | private static final String KEY_ON_READ = "on_read"; |
| 8633 | private static final String KEY_PARTICIPANTS = "participants"; |
| 8634 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 8635 | |
| 8636 | private final String[] mMessages; |
| 8637 | private final RemoteInput mRemoteInput; |
| 8638 | private final PendingIntent mReplyPendingIntent; |
| 8639 | private final PendingIntent mReadPendingIntent; |
| 8640 | private final String[] mParticipants; |
| 8641 | private final long mLatestTimestamp; |
| 8642 | |
| 8643 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 8644 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 8645 | String[] participants, long latestTimestamp) { |
| 8646 | mMessages = messages; |
| 8647 | mRemoteInput = remoteInput; |
| 8648 | mReadPendingIntent = readPendingIntent; |
| 8649 | mReplyPendingIntent = replyPendingIntent; |
| 8650 | mParticipants = participants; |
| 8651 | mLatestTimestamp = latestTimestamp; |
| 8652 | } |
| 8653 | |
| 8654 | /** |
| 8655 | * Gets the list of messages conveyed by this notification. |
| 8656 | */ |
| 8657 | public String[] getMessages() { |
| 8658 | return mMessages; |
| 8659 | } |
| 8660 | |
| 8661 | /** |
| 8662 | * Gets the remote input that will be used to convey the response to a message list, or |
| 8663 | * null if no such remote input exists. |
| 8664 | */ |
| 8665 | public RemoteInput getRemoteInput() { |
| 8666 | return mRemoteInput; |
| 8667 | } |
| 8668 | |
| 8669 | /** |
| 8670 | * Gets the pending intent that will be triggered when the user replies to this |
| 8671 | * notification. |
| 8672 | */ |
| 8673 | public PendingIntent getReplyPendingIntent() { |
| 8674 | return mReplyPendingIntent; |
| 8675 | } |
| 8676 | |
| 8677 | /** |
| 8678 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 8679 | * in this object's message list. |
| 8680 | */ |
| 8681 | public PendingIntent getReadPendingIntent() { |
| 8682 | return mReadPendingIntent; |
| 8683 | } |
| 8684 | |
| 8685 | /** |
| 8686 | * Gets the participants in the conversation. |
| 8687 | */ |
| 8688 | public String[] getParticipants() { |
| 8689 | return mParticipants; |
| 8690 | } |
| 8691 | |
| 8692 | /** |
| 8693 | * Gets the firs participant in the conversation. |
| 8694 | */ |
| 8695 | public String getParticipant() { |
| 8696 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 8697 | } |
| 8698 | |
| 8699 | /** |
| 8700 | * Gets the timestamp of the conversation. |
| 8701 | */ |
| 8702 | public long getLatestTimestamp() { |
| 8703 | return mLatestTimestamp; |
| 8704 | } |
| 8705 | |
| 8706 | Bundle getBundleForUnreadConversation() { |
| 8707 | Bundle b = new Bundle(); |
| 8708 | String author = null; |
| 8709 | if (mParticipants != null && mParticipants.length > 1) { |
| 8710 | author = mParticipants[0]; |
| 8711 | } |
| 8712 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 8713 | for (int i = 0; i < messages.length; i++) { |
| 8714 | Bundle m = new Bundle(); |
| 8715 | m.putString(KEY_TEXT, mMessages[i]); |
| 8716 | m.putString(KEY_AUTHOR, author); |
| 8717 | messages[i] = m; |
| 8718 | } |
| 8719 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 8720 | if (mRemoteInput != null) { |
| 8721 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 8722 | } |
| 8723 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 8724 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 8725 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 8726 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 8727 | return b; |
| 8728 | } |
| 8729 | |
| 8730 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 8731 | if (b == null) { |
| 8732 | return null; |
| 8733 | } |
| 8734 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 8735 | String[] messages = null; |
| 8736 | if (parcelableMessages != null) { |
| 8737 | String[] tmp = new String[parcelableMessages.length]; |
| 8738 | boolean success = true; |
| 8739 | for (int i = 0; i < tmp.length; i++) { |
| 8740 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 8741 | success = false; |
| 8742 | break; |
| 8743 | } |
| 8744 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 8745 | if (tmp[i] == null) { |
| 8746 | success = false; |
| 8747 | break; |
| 8748 | } |
| 8749 | } |
| 8750 | if (success) { |
| 8751 | messages = tmp; |
| 8752 | } else { |
| 8753 | return null; |
| 8754 | } |
| 8755 | } |
| 8756 | |
| 8757 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 8758 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 8759 | |
| 8760 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 8761 | |
| 8762 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 8763 | if (participants == null || participants.length != 1) { |
| 8764 | return null; |
| 8765 | } |
| 8766 | |
| 8767 | return new UnreadConversation(messages, |
| 8768 | remoteInput, |
| 8769 | onReply, |
| 8770 | onRead, |
| 8771 | participants, b.getLong(KEY_TIMESTAMP)); |
| 8772 | } |
| 8773 | }; |
| 8774 | |
| 8775 | /** |
| 8776 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 8777 | */ |
| 8778 | public static class Builder { |
| 8779 | private final List<String> mMessages = new ArrayList<String>(); |
| 8780 | private final String mParticipant; |
| 8781 | private RemoteInput mRemoteInput; |
| 8782 | private PendingIntent mReadPendingIntent; |
| 8783 | private PendingIntent mReplyPendingIntent; |
| 8784 | private long mLatestTimestamp; |
| 8785 | |
| 8786 | /** |
| 8787 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 8788 | * |
| 8789 | * @param name The name of the other participant in the conversation. |
| 8790 | */ |
| 8791 | public Builder(String name) { |
| 8792 | mParticipant = name; |
| 8793 | } |
| 8794 | |
| 8795 | /** |
| 8796 | * Appends a new unread message to the list of messages for this conversation. |
| 8797 | * |
| 8798 | * The messages should be added from oldest to newest. |
| 8799 | * |
| 8800 | * @param message The text of the new unread message. |
| 8801 | * @return This object for method chaining. |
| 8802 | */ |
| 8803 | public Builder addMessage(String message) { |
| 8804 | mMessages.add(message); |
| 8805 | return this; |
| 8806 | } |
| 8807 | |
| 8808 | /** |
| 8809 | * Sets the pending intent and remote input which will convey the reply to this |
| 8810 | * notification. |
| 8811 | * |
| 8812 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 8813 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 8814 | * @return This object for method chaining. |
| 8815 | * |
| 8816 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 8817 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 8818 | */ |
| 8819 | public Builder setReplyAction( |
| 8820 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 8821 | mRemoteInput = remoteInput; |
| 8822 | mReplyPendingIntent = pendingIntent; |
| 8823 | |
| 8824 | return this; |
| 8825 | } |
| 8826 | |
| 8827 | /** |
| 8828 | * Sets the pending intent that will be sent once the messages in this notification |
| 8829 | * are read. |
| 8830 | * |
| 8831 | * @param pendingIntent The pending intent to use. |
| 8832 | * @return This object for method chaining. |
| 8833 | */ |
| 8834 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 8835 | mReadPendingIntent = pendingIntent; |
| 8836 | return this; |
| 8837 | } |
| 8838 | |
| 8839 | /** |
| 8840 | * Sets the timestamp of the most recent message in an unread conversation. |
| 8841 | * |
| 8842 | * If a messaging notification has been posted by your application and has not |
| 8843 | * yet been cancelled, posting a later notification with the same id and tag |
| 8844 | * but without a newer timestamp may result in Android Auto not displaying a |
| 8845 | * heads up notification for the later notification. |
| 8846 | * |
| 8847 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 8848 | * @return This object for method chaining. |
| 8849 | */ |
| 8850 | public Builder setLatestTimestamp(long timestamp) { |
| 8851 | mLatestTimestamp = timestamp; |
| 8852 | return this; |
| 8853 | } |
| 8854 | |
| 8855 | /** |
| 8856 | * Builds a new unread conversation object. |
| 8857 | * |
| 8858 | * @return The new unread conversation object. |
| 8859 | */ |
| 8860 | public UnreadConversation build() { |
| 8861 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 8862 | String[] participants = { mParticipant }; |
| 8863 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 8864 | mReadPendingIntent, participants, mLatestTimestamp); |
| 8865 | } |
| 8866 | } |
| 8867 | } |
| 8868 | |
| 8869 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8870 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 8871 | * with a TV extension: |
| 8872 | * |
| 8873 | * <ol> |
| 8874 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 8875 | * <li>Create a {@link TvExtender}. |
| 8876 | * <li>Set TV-specific properties using the {@code set} methods of |
| 8877 | * {@link TvExtender}. |
| 8878 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 8879 | * to apply the extension to a notification. |
| 8880 | * </ol> |
| 8881 | * |
| 8882 | * <pre class="prettyprint"> |
| 8883 | * Notification notification = new Notification.Builder(context) |
| 8884 | * ... |
| 8885 | * .extend(new TvExtender() |
| 8886 | * .set*(...)) |
| 8887 | * .build(); |
| 8888 | * </pre> |
| 8889 | * |
| 8890 | * <p>TV extensions can be accessed on an existing notification by using the |
| 8891 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 8892 | * to access values. |
| 8893 | * |
| 8894 | * @hide |
| 8895 | */ |
| 8896 | @SystemApi |
| 8897 | public static final class TvExtender implements Extender { |
| 8898 | private static final String TAG = "TvExtender"; |
| 8899 | |
| 8900 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 8901 | private static final String EXTRA_FLAGS = "flags"; |
| 8902 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 8903 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8904 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 8905 | private static final String EXTRA_SUPPRESS_SHOW_OVER_APPS = "suppressShowOverApps"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8906 | |
| 8907 | // Flags bitwise-ored to mFlags |
| 8908 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 8909 | |
| 8910 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8911 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8912 | private PendingIntent mContentIntent; |
| 8913 | private PendingIntent mDeleteIntent; |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 8914 | private boolean mSuppressShowOverApps; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8915 | |
| 8916 | /** |
| 8917 | * Create a {@link TvExtender} with default options. |
| 8918 | */ |
| 8919 | public TvExtender() { |
| 8920 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 8921 | } |
| 8922 | |
| 8923 | /** |
| 8924 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 8925 | * |
| 8926 | * @param notif The notification from which to copy options. |
| 8927 | */ |
| 8928 | public TvExtender(Notification notif) { |
| 8929 | Bundle bundle = notif.extras == null ? |
| 8930 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 8931 | if (bundle != null) { |
| 8932 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8933 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 8934 | mSuppressShowOverApps = bundle.getBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8935 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 8936 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 8937 | } |
| 8938 | } |
| 8939 | |
| 8940 | /** |
| 8941 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 8942 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 8943 | * method of {@link Notification.Builder}. |
| 8944 | */ |
| 8945 | @Override |
| 8946 | public Notification.Builder extend(Notification.Builder builder) { |
| 8947 | Bundle bundle = new Bundle(); |
| 8948 | |
| 8949 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8950 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 8951 | bundle.putBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS, mSuppressShowOverApps); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8952 | if (mContentIntent != null) { |
| 8953 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 8954 | } |
| 8955 | |
| 8956 | if (mDeleteIntent != null) { |
| 8957 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 8958 | } |
| 8959 | |
| 8960 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 8961 | return builder; |
| 8962 | } |
| 8963 | |
| 8964 | /** |
| 8965 | * Returns true if this notification should be shown on TV. This method return true |
| 8966 | * if the notification was extended with a TvExtender. |
| 8967 | */ |
| 8968 | public boolean isAvailableOnTv() { |
| 8969 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 8970 | } |
| 8971 | |
| 8972 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8973 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 8974 | * It can be different from the channel that the notification is delivered to when |
| 8975 | * posting on a non-TV device. |
| 8976 | */ |
| 8977 | public TvExtender setChannel(String channelId) { |
| 8978 | mChannelId = channelId; |
| 8979 | return this; |
| 8980 | } |
| 8981 | |
| 8982 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 8983 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 8984 | * It can be different from the channel that the notification is delivered to when |
| 8985 | * posting on a non-TV device. |
| 8986 | */ |
| 8987 | public TvExtender setChannelId(String channelId) { |
| 8988 | mChannelId = channelId; |
| 8989 | return this; |
| 8990 | } |
| 8991 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 8992 | /** @removed */ |
| 8993 | @Deprecated |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8994 | public String getChannel() { |
| 8995 | return mChannelId; |
| 8996 | } |
| 8997 | |
| 8998 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 8999 | * Returns the id of the channel this notification posts to on TV. |
| 9000 | */ |
| 9001 | public String getChannelId() { |
| 9002 | return mChannelId; |
| 9003 | } |
| 9004 | |
| 9005 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9006 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 9007 | * If provided, it is used instead of the content intent specified |
| 9008 | * at the level of Notification. |
| 9009 | */ |
| 9010 | public TvExtender setContentIntent(PendingIntent intent) { |
| 9011 | mContentIntent = intent; |
| 9012 | return this; |
| 9013 | } |
| 9014 | |
| 9015 | /** |
| 9016 | * Returns the TV-specific content intent. If this method returns null, the |
| 9017 | * main content intent on the notification should be used. |
| 9018 | * |
| 9019 | * @see {@link Notification#contentIntent} |
| 9020 | */ |
| 9021 | public PendingIntent getContentIntent() { |
| 9022 | return mContentIntent; |
| 9023 | } |
| 9024 | |
| 9025 | /** |
| 9026 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 9027 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 9028 | * at the level of Notification. |
| 9029 | */ |
| 9030 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 9031 | mDeleteIntent = intent; |
| 9032 | return this; |
| 9033 | } |
| 9034 | |
| 9035 | /** |
| 9036 | * Returns the TV-specific delete intent. If this method returns null, the |
| 9037 | * main delete intent on the notification should be used. |
| 9038 | * |
| 9039 | * @see {@link Notification#deleteIntent} |
| 9040 | */ |
| 9041 | public PendingIntent getDeleteIntent() { |
| 9042 | return mDeleteIntent; |
| 9043 | } |
Rhiannon Malia | 1a08393 | 2018-01-24 15:02:30 -0800 | [diff] [blame] | 9044 | |
| 9045 | /** |
| 9046 | * Specifies whether this notification should suppress showing a message over top of apps |
| 9047 | * outside of the launcher. |
| 9048 | */ |
| 9049 | public TvExtender setSuppressShowOverApps(boolean suppress) { |
| 9050 | mSuppressShowOverApps = suppress; |
| 9051 | return this; |
| 9052 | } |
| 9053 | |
| 9054 | /** |
| 9055 | * Returns true if this notification should not show messages over top of apps |
| 9056 | * outside of the launcher. |
| 9057 | */ |
| 9058 | public boolean getSuppressShowOverApps() { |
| 9059 | return mSuppressShowOverApps; |
| 9060 | } |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 9061 | } |
| 9062 | |
| 9063 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 9064 | * Get an array of Notification objects from a parcelable array bundle field. |
| 9065 | * Update the bundle to have a typed array so fetches in the future don't need |
| 9066 | * to do an array copy. |
| 9067 | */ |
| 9068 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 9069 | Parcelable[] array = bundle.getParcelableArray(key); |
| 9070 | if (array instanceof Notification[] || array == null) { |
| 9071 | return (Notification[]) array; |
| 9072 | } |
| 9073 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 9074 | Notification[].class); |
| 9075 | bundle.putParcelableArray(key, typedArray); |
| 9076 | return typedArray; |
| 9077 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 9078 | |
| 9079 | private static class BuilderRemoteViews extends RemoteViews { |
| 9080 | public BuilderRemoteViews(Parcel parcel) { |
| 9081 | super(parcel); |
| 9082 | } |
| 9083 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 9084 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 9085 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 9086 | } |
| 9087 | |
| 9088 | @Override |
| 9089 | public BuilderRemoteViews clone() { |
| 9090 | Parcel p = Parcel.obtain(); |
| 9091 | writeToParcel(p, 0); |
| 9092 | p.setDataPosition(0); |
| 9093 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 9094 | p.recycle(); |
| 9095 | return brv; |
| 9096 | } |
| 9097 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9098 | |
| 9099 | private static class StandardTemplateParams { |
| 9100 | boolean hasProgress = true; |
| 9101 | boolean ambient = false; |
| 9102 | CharSequence title; |
| 9103 | CharSequence text; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9104 | CharSequence headerTextSecondary; |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9105 | boolean hideLargeIcon; |
| 9106 | public boolean alwaysShowReply; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9107 | |
| 9108 | final StandardTemplateParams reset() { |
| 9109 | hasProgress = true; |
| 9110 | ambient = false; |
| 9111 | title = null; |
| 9112 | text = null; |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9113 | headerTextSecondary = null; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9114 | return this; |
| 9115 | } |
| 9116 | |
| 9117 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 9118 | this.hasProgress = hasProgress; |
| 9119 | return this; |
| 9120 | } |
| 9121 | |
| 9122 | final StandardTemplateParams title(CharSequence title) { |
| 9123 | this.title = title; |
| 9124 | return this; |
| 9125 | } |
| 9126 | |
| 9127 | final StandardTemplateParams text(CharSequence text) { |
| 9128 | this.text = text; |
| 9129 | return this; |
| 9130 | } |
| 9131 | |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 9132 | final StandardTemplateParams headerTextSecondary(CharSequence text) { |
| 9133 | this.headerTextSecondary = text; |
| 9134 | return this; |
| 9135 | } |
| 9136 | |
Selim Cinek | 88188f2 | 2017-09-19 16:46:56 -0700 | [diff] [blame] | 9137 | final StandardTemplateParams alwaysShowReply(boolean alwaysShowReply) { |
| 9138 | this.alwaysShowReply = alwaysShowReply; |
| 9139 | return this; |
| 9140 | } |
| 9141 | |
| 9142 | final StandardTemplateParams hideLargeIcon(boolean hideLargeIcon) { |
| 9143 | this.hideLargeIcon = hideLargeIcon; |
| 9144 | return this; |
| 9145 | } |
| 9146 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9147 | final StandardTemplateParams ambient(boolean ambient) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 9148 | Preconditions.checkState(title == null && text == null, "must set ambient before text"); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9149 | this.ambient = ambient; |
| 9150 | return this; |
| 9151 | } |
| 9152 | |
| 9153 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 9154 | Bundle extras = b.mN.extras; |
Lucas Dupin | 06c5e64 | 2017-09-13 16:34:58 -0700 | [diff] [blame] | 9155 | this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE), ambient); |
| 9156 | |
| 9157 | // Big text notifications should contain their content when viewed in ambient mode. |
| 9158 | CharSequence text = extras.getCharSequence(EXTRA_BIG_TEXT); |
| 9159 | if (!ambient || TextUtils.isEmpty(text)) { |
| 9160 | text = extras.getCharSequence(EXTRA_TEXT); |
| 9161 | } |
| 9162 | this.text = b.processLegacyText(text, ambient); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 9163 | return this; |
| 9164 | } |
| 9165 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9166 | } |