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 | |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 20 | import android.annotation.DrawableRes; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 21 | import android.annotation.IntDef; |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 22 | import android.annotation.NonNull; |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 23 | import android.annotation.SdkConstant; |
| 24 | import android.annotation.SdkConstant.SdkConstantType; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 25 | import android.annotation.SystemApi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 28 | import android.content.pm.ApplicationInfo; |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 29 | import android.content.pm.PackageManager; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 30 | import android.content.pm.PackageManager.NameNotFoundException; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 31 | import android.content.pm.ShortcutInfo; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 32 | import android.content.res.ColorStateList; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 33 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 34 | import android.graphics.Canvas; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 35 | import android.graphics.Color; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 36 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 37 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 38 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 39 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 40 | import android.media.AudioManager; |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 41 | import android.media.PlayerBase; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 42 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 44 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 45 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 46 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.os.Parcel; |
| 48 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 49 | import android.os.SystemClock; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 50 | import android.os.SystemProperties; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 51 | import android.os.UserHandle; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 52 | import android.text.BidiFormatter; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 53 | import android.text.SpannableStringBuilder; |
| 54 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 56 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 57 | import android.text.style.BackgroundColorSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 58 | import android.text.style.CharacterStyle; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 59 | import android.text.style.ForegroundColorSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 60 | import android.text.style.RelativeSizeSpan; |
| 61 | import android.text.style.TextAppearanceSpan; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 62 | import android.util.ArraySet; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 63 | import android.util.Log; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 64 | import android.util.SparseArray; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 65 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 66 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 67 | import android.view.View; |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 68 | import android.view.ViewGroup; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 69 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.widget.RemoteViews; |
| 71 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 72 | import com.android.internal.R; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 73 | import com.android.internal.util.ArrayUtils; |
Griff Hazen | c091ba8 | 2014-05-16 10:13:26 -0700 | [diff] [blame] | 74 | import com.android.internal.util.NotificationColorUtil; |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 75 | import com.android.internal.util.Preconditions; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 76 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 77 | import java.lang.annotation.Retention; |
| 78 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 79 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 80 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 81 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 82 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 83 | import java.util.List; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 84 | import java.util.Set; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 85 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | /** |
| 87 | * A class that represents how a persistent notification is to be presented to |
| 88 | * the user using the {@link android.app.NotificationManager}. |
| 89 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 90 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 91 | * easier to construct Notifications.</p> |
| 92 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 93 | * <div class="special reference"> |
| 94 | * <h3>Developer Guides</h3> |
| 95 | * <p>For a guide to creating notifications, read the |
| 96 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 97 | * developer guide.</p> |
| 98 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | */ |
| 100 | public class Notification implements Parcelable |
| 101 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 102 | private static final String TAG = "Notification"; |
| 103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 105 | * 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] | 106 | * containing application. |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 107 | */ |
| 108 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 109 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 110 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 111 | |
| 112 | /** |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 113 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 114 | * 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] | 115 | * what settings should be shown in the target app. |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 116 | */ |
| 117 | public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 118 | |
| 119 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 120 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 121 | * contain the tag provided to {@link NotificationManager#notify(String, int, Notification)} |
| 122 | * that can be used to narrow down what settings should be shown in the target app. |
| 123 | */ |
| 124 | public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 125 | |
| 126 | /** |
| 127 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 128 | * contain the id provided to {@link NotificationManager#notify(String, int, Notification)} |
| 129 | * that can be used to narrow down what settings should be shown in the target app. |
| 130 | */ |
| 131 | public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 132 | |
| 133 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | * Use all default values (where applicable). |
| 135 | */ |
| 136 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | /** |
| 139 | * Use the default notification sound. This will ignore any given |
| 140 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 141 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 142 | * <p> |
| 143 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 144 | * </p> |
| 145 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 147 | */ |
| 148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | public static final int DEFAULT_SOUND = 1; |
| 150 | |
| 151 | /** |
| 152 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 153 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 154 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 155 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 156 | * <p> |
| 157 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 158 | * </p> |
| 159 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 161 | */ |
| 162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | /** |
| 166 | * Use the default notification lights. This will ignore the |
| 167 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 168 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 169 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 171 | */ |
| 172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 176 | * Maximum length of CharSequences accepted by Builder and friends. |
| 177 | * |
| 178 | * <p> |
| 179 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 180 | */ |
| 181 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 182 | |
| 183 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 184 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 185 | */ |
| 186 | private static final int MAX_REPLY_HISTORY = 5; |
| 187 | |
| 188 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 189 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 190 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 191 | * Default value: {@link System#currentTimeMillis() Now}. |
| 192 | * |
| 193 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 194 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 195 | * 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] | 196 | * timestamped according to when the activity began. |
| 197 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 198 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 199 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 200 | * <ul> |
| 201 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 202 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 203 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 204 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 205 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 206 | * <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] | 207 | * </ul> |
| 208 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 209 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 210 | * anymore by default and must be opted into by using |
| 211 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | */ |
| 213 | public long when; |
| 214 | |
| 215 | /** |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 216 | * The creation time of the notification |
| 217 | */ |
| 218 | private long creationTime; |
| 219 | |
| 220 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | * 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] | 222 | * |
| 223 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 225 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 226 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | public int icon; |
| 228 | |
| 229 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 230 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 231 | * leave it at its default value of 0. |
| 232 | * |
| 233 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 234 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 235 | */ |
| 236 | public int iconLevel; |
| 237 | |
| 238 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 239 | * The number of events that this notification represents. For example, in a new mail |
| 240 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 241 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 242 | * The system may or may not use this field to modify the appearance of the notification. For |
| 243 | * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was |
| 244 | * superimposed over the icon in the status bar. Starting with |
| 245 | * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by |
| 246 | * {@link Notification.Builder} has displayed the number in the expanded notification view. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 247 | * Starting with {@link android.os.Build.VERSION_CODES#O}, the number may be displayed as a |
| 248 | * badge icon in Launchers that support badging. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 249 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | */ |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 251 | public int number = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | |
| 253 | /** |
| 254 | * The intent to execute when the expanded status entry is clicked. If |
| 255 | * this is an activity, it must include the |
| 256 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 257 | * that you take care of task management as described in the |
| 258 | * <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] | 259 | * Stack</a> document. In particular, make sure to read the notification section |
| 260 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 261 | * Notifications</a> for the correct ways to launch an application from a |
| 262 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | */ |
| 264 | public PendingIntent contentIntent; |
| 265 | |
| 266 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 267 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 268 | * the "Clear All" button or by swiping it away individually. |
| 269 | * |
| 270 | * This probably shouldn't be launching an activity since several of those will be sent |
| 271 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | */ |
| 273 | public PendingIntent deleteIntent; |
| 274 | |
| 275 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 276 | * 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] | 277 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 278 | * <p> |
| 279 | * The system UI may choose to display a heads-up notification, instead of |
| 280 | * launching this intent, while the user is using the device. |
| 281 | * </p> |
| 282 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 283 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 284 | */ |
| 285 | public PendingIntent fullScreenIntent; |
| 286 | |
| 287 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 288 | * Text that summarizes this notification for accessibility services. |
| 289 | * |
| 290 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 291 | * accessibility services (where it serves as an audible announcement of the notification's |
| 292 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 293 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 294 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | */ |
| 296 | public CharSequence tickerText; |
| 297 | |
| 298 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 299 | * Formerly, a view showing the {@link #tickerText}. |
| 300 | * |
| 301 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 302 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 303 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 304 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 305 | |
| 306 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 307 | * The view that will represent this notification in the notification list (which is pulled |
| 308 | * down from the status bar). |
| 309 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 310 | * As of N, this field may be null. The notification view is determined by the inputs |
| 311 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 312 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 314 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | public RemoteViews contentView; |
| 316 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 317 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 318 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 319 | * opportunity to show more detail. The system UI may choose to show this |
| 320 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 321 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 322 | * 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] | 323 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 324 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 325 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 326 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 327 | public RemoteViews bigContentView; |
| 328 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 329 | |
| 330 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 331 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 332 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 333 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 334 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 335 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 336 | * 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] | 337 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 338 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 339 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 340 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 341 | public RemoteViews headsUpContentView; |
| 342 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 343 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 344 | * A large bitmap to be shown in the notification content area. |
| 345 | * |
| 346 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 348 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 349 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | |
| 351 | /** |
| 352 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 353 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 355 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 356 | * </p> |
| 357 | * |
| 358 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 359 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 361 | * @deprecated use {@link NotificationChannel#getSound()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 363 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | public Uri sound; |
| 365 | |
| 366 | /** |
| 367 | * Use this constant as the value for audioStreamType to request that |
| 368 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 369 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 370 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 371 | * @deprecated Use {@link NotificationChannel#getAudioAttributes()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 373 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | public static final int STREAM_DEFAULT = -1; |
| 375 | |
| 376 | /** |
| 377 | * The audio stream type to use when playing the sound. |
| 378 | * Should be one of the STREAM_ constants from |
| 379 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 380 | * |
| 381 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 383 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | public int audioStreamType = STREAM_DEFAULT; |
| 385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 387 | * The default value of {@link #audioAttributes}. |
| 388 | */ |
| 389 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 390 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 391 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 392 | .build(); |
| 393 | |
| 394 | /** |
| 395 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 396 | * |
| 397 | * @deprecated use {@link NotificationChannel#getAudioAttributes()} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 398 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 399 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 400 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 401 | |
| 402 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 403 | * The pattern with which to vibrate. |
| 404 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | * <p> |
| 406 | * To vibrate the default pattern, see {@link #defaults}. |
| 407 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 408 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | * @see android.os.Vibrator#vibrate(long[],int) |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 410 | * @deprecated use {@link NotificationChannel#getVibrationPattern()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 412 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | public long[] vibrate; |
| 414 | |
| 415 | /** |
| 416 | * The color of the led. The hardware will do its best approximation. |
| 417 | * |
| 418 | * @see #FLAG_SHOW_LIGHTS |
| 419 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 420 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 422 | @ColorInt |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 423 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | public int ledARGB; |
| 425 | |
| 426 | /** |
| 427 | * The number of milliseconds for the LED to be on while it's flashing. |
| 428 | * The hardware will do its best approximation. |
| 429 | * |
| 430 | * @see #FLAG_SHOW_LIGHTS |
| 431 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 432 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 434 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | public int ledOnMS; |
| 436 | |
| 437 | /** |
| 438 | * The number of milliseconds for the LED to be off while it's flashing. |
| 439 | * The hardware will do its best approximation. |
| 440 | * |
| 441 | * @see #FLAG_SHOW_LIGHTS |
| 442 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 443 | * |
| 444 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 446 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | public int ledOffMS; |
| 448 | |
| 449 | /** |
| 450 | * Specifies which values should be taken from the defaults. |
| 451 | * <p> |
| 452 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 453 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 454 | * values, use {@link #DEFAULT_ALL}. |
| 455 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 456 | * |
| 457 | * @deprecated use {@link NotificationChannel#getSound()} and |
| 458 | * {@link NotificationChannel#shouldShowLights()} and |
| 459 | * {@link NotificationChannel#shouldVibrate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 461 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | public int defaults; |
| 463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | /** |
| 465 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 466 | * set if you want the LED on for this notification. |
| 467 | * <ul> |
| 468 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 469 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 470 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 471 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 472 | * be on and off to ledOnMS and ledOffMS.</li> |
| 473 | * </ul> |
| 474 | * <p> |
| 475 | * Since hardware varies, you are not guaranteed that any of the values |
| 476 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 477 | * because they will be set to values that work on any given hardware. |
| 478 | * <p> |
| 479 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 480 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 481 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 483 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 485 | |
| 486 | /** |
| 487 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 488 | * set if this notification is in reference to something that is ongoing, |
| 489 | * like a phone call. It should not be set if this notification is in |
| 490 | * reference to something that happened at a particular point in time, |
| 491 | * like a missed phone call. |
| 492 | */ |
| 493 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 494 | |
| 495 | /** |
| 496 | * 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] | 497 | * the audio will be repeated until the notification is |
| 498 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | */ |
| 500 | public static final int FLAG_INSISTENT = 0x00000004; |
| 501 | |
| 502 | /** |
| 503 | * 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] | 504 | * set if you would only like the sound, vibrate and ticker to be played |
| 505 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | */ |
| 507 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 508 | |
| 509 | /** |
| 510 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 511 | * 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] | 512 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | */ |
| 514 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 515 | |
| 516 | /** |
| 517 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 518 | * set if the notification should not be canceled when the user clicks |
| 519 | * the Clear all button. |
| 520 | */ |
| 521 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 522 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 523 | /** |
| 524 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 525 | * set if this notification represents a currently running service. This |
| 526 | * will normally be set for you by {@link Service#startForeground}. |
| 527 | */ |
| 528 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 529 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 530 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 531 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 532 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 533 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 534 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 535 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 536 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 537 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 538 | /** |
| 539 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 540 | * set if this notification is relevant to the current device only |
| 541 | * and it is not recommended that it bridge to other devices. |
| 542 | */ |
| 543 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 544 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 545 | /** |
| 546 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 547 | * set if this notification is the group summary for a group of notifications. |
| 548 | * Grouped notifications may display in a cluster or stack on devices which |
| 549 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 550 | */ |
| 551 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 552 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 553 | /** |
| 554 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 555 | * set if this notification is the group summary for an auto-group of notifications. |
| 556 | * |
| 557 | * @hide |
| 558 | */ |
| 559 | @SystemApi |
| 560 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | public int flags; |
| 563 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 564 | /** @hide */ |
| 565 | @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX}) |
| 566 | @Retention(RetentionPolicy.SOURCE) |
| 567 | public @interface Priority {} |
| 568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 570 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 571 | * notifications, use this value for all notifications. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 572 | * |
| 573 | * @deprecated use {@link NotificationManager#IMPORTANCE_DEFAULT} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 574 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 575 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 576 | public static final int PRIORITY_DEFAULT = 0; |
| 577 | |
| 578 | /** |
| 579 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 580 | * items smaller, or at a different position in the list, compared with your app's |
| 581 | * {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 582 | * |
| 583 | * @deprecated use {@link NotificationManager#IMPORTANCE_LOW} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 584 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 585 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 586 | public static final int PRIORITY_LOW = -1; |
| 587 | |
| 588 | /** |
| 589 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 590 | * circumstances, such as detailed notification logs. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 591 | * |
| 592 | * @deprecated use {@link NotificationManager#IMPORTANCE_MIN} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 593 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 594 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 595 | public static final int PRIORITY_MIN = -2; |
| 596 | |
| 597 | /** |
| 598 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 599 | * show these items larger, or at a different position in notification lists, compared with |
| 600 | * your app's {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 601 | * |
| 602 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 603 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 604 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 605 | public static final int PRIORITY_HIGH = 1; |
| 606 | |
| 607 | /** |
| 608 | * Highest {@link #priority}, for your application's most important items that require the |
| 609 | * user's prompt attention or input. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 610 | * |
| 611 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 612 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 613 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 614 | public static final int PRIORITY_MAX = 2; |
| 615 | |
| 616 | /** |
| 617 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 618 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 619 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 620 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 621 | * 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] | 622 | * system will make a determination about how to interpret this priority when presenting |
| 623 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 624 | * |
| 625 | * <p> |
| 626 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 627 | * as a heads-up notification. |
| 628 | * </p> |
| 629 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 630 | * @deprecated use {@link NotificationChannel#getImportance()} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 631 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 632 | @Priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 633 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 634 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 635 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 636 | /** |
| 637 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 638 | * to be applied by the standard Style templates when presenting this notification. |
| 639 | * |
| 640 | * The current template design constructs a colorful header image by overlaying the |
| 641 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 642 | * ignored. |
| 643 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 644 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 645 | public int color = COLOR_DEFAULT; |
| 646 | |
| 647 | /** |
| 648 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 649 | * any special color but instead use default colors when presenting this notification. |
| 650 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 651 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 652 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 653 | |
| 654 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 655 | * 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] | 656 | * @hide |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 657 | */ |
| 658 | @ColorInt |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 659 | public static final int COLOR_INVALID = 1; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 660 | |
| 661 | /** |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 662 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 663 | * 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] | 664 | * lockscreen). |
| 665 | * |
| 666 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 667 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 668 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 669 | * the appropriate user. |
| 670 | * |
| 671 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 672 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 673 | * To modify the public version of this notification—for example, to redact some portions—see |
| 674 | * {@link Builder#setPublicVersion(Notification)}. |
| 675 | * |
| 676 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 677 | * and ticker until the user has bypassed the lockscreen. |
| 678 | */ |
| 679 | public int visibility; |
| 680 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 681 | /** |
| 682 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 683 | * |
| 684 | * {@see #visibility} |
| 685 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 686 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 687 | |
| 688 | /** |
| 689 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 690 | * private information on secure lockscreens. |
| 691 | * |
| 692 | * {@see #visibility} |
| 693 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 694 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 695 | |
| 696 | /** |
| 697 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 698 | * |
| 699 | * {@see #visibility} |
| 700 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 701 | public static final int VISIBILITY_SECRET = -1; |
| 702 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 703 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 704 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 705 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 706 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 707 | |
| 708 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 709 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 710 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 711 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 712 | |
| 713 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 714 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 715 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 716 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 717 | |
| 718 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 719 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 720 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 721 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 722 | |
| 723 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 724 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 725 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 726 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 727 | |
| 728 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 729 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 730 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 731 | public static final String CATEGORY_ALARM = "alarm"; |
| 732 | |
| 733 | /** |
| 734 | * Notification category: progress of a long-running background operation. |
| 735 | */ |
| 736 | public static final String CATEGORY_PROGRESS = "progress"; |
| 737 | |
| 738 | /** |
| 739 | * Notification category: social network or sharing update. |
| 740 | */ |
| 741 | public static final String CATEGORY_SOCIAL = "social"; |
| 742 | |
| 743 | /** |
| 744 | * Notification category: error in background operation or authentication status. |
| 745 | */ |
| 746 | public static final String CATEGORY_ERROR = "err"; |
| 747 | |
| 748 | /** |
| 749 | * Notification category: media transport control for playback. |
| 750 | */ |
| 751 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 752 | |
| 753 | /** |
| 754 | * Notification category: system or device status update. Reserved for system use. |
| 755 | */ |
| 756 | public static final String CATEGORY_SYSTEM = "sys"; |
| 757 | |
| 758 | /** |
| 759 | * Notification category: indication of running background service. |
| 760 | */ |
| 761 | public static final String CATEGORY_SERVICE = "service"; |
| 762 | |
| 763 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 764 | * Notification category: a specific, timely recommendation for a single thing. |
| 765 | * For example, a news app might want to recommend a news story it believes the user will |
| 766 | * want to read next. |
| 767 | */ |
| 768 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 769 | |
| 770 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 771 | * Notification category: ongoing information about device or contextual status. |
| 772 | */ |
| 773 | public static final String CATEGORY_STATUS = "status"; |
| 774 | |
| 775 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 776 | * Notification category: user-scheduled reminder. |
| 777 | */ |
| 778 | public static final String CATEGORY_REMINDER = "reminder"; |
| 779 | |
| 780 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 781 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 782 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 783 | */ |
| 784 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 785 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 786 | private String mGroupKey; |
| 787 | |
| 788 | /** |
| 789 | * Get the key used to group this notification into a cluster or stack |
| 790 | * with other notifications on devices which support such rendering. |
| 791 | */ |
| 792 | public String getGroup() { |
| 793 | return mGroupKey; |
| 794 | } |
| 795 | |
| 796 | private String mSortKey; |
| 797 | |
| 798 | /** |
| 799 | * Get a sort key that orders this notification among other notifications from the |
| 800 | * same package. This can be useful if an external sort was already applied and an app |
| 801 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 802 | * value, although providing different priorities in addition to providing sort key may |
| 803 | * cause this value to be ignored. |
| 804 | * |
| 805 | * <p>This sort key can also be used to order members of a notification group. See |
| 806 | * {@link Builder#setGroup}. |
| 807 | * |
| 808 | * @see String#compareTo(String) |
| 809 | */ |
| 810 | public String getSortKey() { |
| 811 | return mSortKey; |
| 812 | } |
| 813 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 814 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 815 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 816 | * <p> |
| 817 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 818 | * APIs, and are intended to be used by |
| 819 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 820 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 821 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 822 | public Bundle extras = new Bundle(); |
| 823 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 824 | /** |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 825 | * All pending intents in the notification as the system needs to be able to access them but |
| 826 | * 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] | 827 | * custom parcelable objects. |
| 828 | * |
| 829 | * @hide |
| 830 | */ |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 831 | public ArraySet<PendingIntent> allPendingIntents; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 832 | |
| 833 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 834 | * {@link #extras} key: this is the title of the notification, |
| 835 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 836 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 837 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 838 | |
| 839 | /** |
| 840 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 841 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 842 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 843 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 844 | |
| 845 | /** |
| 846 | * {@link #extras} key: this is the main text payload, as supplied to |
| 847 | * {@link Builder#setContentText(CharSequence)}. |
| 848 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 849 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 850 | |
| 851 | /** |
| 852 | * {@link #extras} key: this is a third line of text, as supplied to |
| 853 | * {@link Builder#setSubText(CharSequence)}. |
| 854 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 855 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 856 | |
| 857 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 858 | * {@link #extras} key: this is the remote input history, as supplied to |
| 859 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
Adrian Roos | 005e774 | 2016-04-13 15:02:20 -0700 | [diff] [blame] | 860 | * |
| 861 | * Apps can fill this through {@link Builder#setRemoteInputHistory(CharSequence[])} |
| 862 | * with the most recent inputs that have been sent through a {@link RemoteInput} of this |
| 863 | * Notification and are expected to clear it once the it is no longer relevant (e.g. for chat |
| 864 | * notifications once the other party has responded). |
| 865 | * |
| 866 | * The extra with this key is of type CharSequence[] and contains the most recent entry at |
| 867 | * the 0 index, the second most recent at the 1 index, etc. |
| 868 | * |
| 869 | * @see Builder#setRemoteInputHistory(CharSequence[]) |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 870 | */ |
| 871 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 872 | |
| 873 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 874 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 875 | * {@link Builder#setContentInfo(CharSequence)}. |
| 876 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 877 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 878 | |
| 879 | /** |
| 880 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 881 | * alongside expanded notifications, as supplied to (e.g.) |
| 882 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 883 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 884 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 885 | |
| 886 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 887 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 888 | * {@link BigTextStyle} notification, as supplied to |
| 889 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 890 | */ |
| 891 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 892 | |
| 893 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 894 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 895 | * supplied to {@link Builder#setSmallIcon(int)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 896 | * |
| 897 | * @deprecated Use {@link #getSmallIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 898 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 899 | @Deprecated |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 900 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 901 | |
| 902 | /** |
| 903 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 904 | * notification payload, as |
| 905 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 906 | * |
| 907 | * @deprecated Use {@link #getLargeIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 908 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 909 | @Deprecated |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 910 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 911 | |
| 912 | /** |
| 913 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 914 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 915 | * shown in its expanded form, as supplied to |
| 916 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 917 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 918 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 919 | |
| 920 | /** |
| 921 | * {@link #extras} key: this is the progress value supplied to |
| 922 | * {@link Builder#setProgress(int, int, boolean)}. |
| 923 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 924 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 925 | |
| 926 | /** |
| 927 | * {@link #extras} key: this is the maximum value supplied to |
| 928 | * {@link Builder#setProgress(int, int, boolean)}. |
| 929 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 930 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 931 | |
| 932 | /** |
| 933 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 934 | * {@link Builder#setProgress(int, int, boolean)}. |
| 935 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 936 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 937 | |
| 938 | /** |
| 939 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 940 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 941 | * {@link Builder#setUsesChronometer(boolean)}. |
| 942 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 943 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 944 | |
| 945 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 946 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 947 | * 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] | 948 | * This extra is a boolean. The default is false. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 949 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 950 | public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 951 | |
| 952 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 953 | * {@link #extras} key: whether {@link #when} should be shown, |
| 954 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 955 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 956 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 957 | |
| 958 | /** |
| 959 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 960 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 961 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 962 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 963 | |
| 964 | /** |
| 965 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 966 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 967 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 968 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 969 | |
| 970 | /** |
| 971 | * {@link #extras} key: A string representing the name of the specific |
| 972 | * {@link android.app.Notification.Style} used to create this notification. |
| 973 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 974 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 975 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 976 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 977 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 978 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 979 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 980 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 981 | |
| 982 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 983 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 984 | * Only available to notifications coming from the android package. |
| 985 | * @hide |
| 986 | */ |
Maurice Lam | 96c1003 | 2017-03-29 15:42:38 -0700 | [diff] [blame] | 987 | @SystemApi |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 988 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 989 | |
| 990 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 991 | * {@link #extras} key: A |
| 992 | * {@link android.content.ContentUris content URI} pointing to an image that can be displayed |
| 993 | * in the background when the notification is selected. The URI must point to an image stream |
| 994 | * suitable for passing into |
| 995 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
| 996 | * BitmapFactory.decodeStream}; all other content types will be ignored. The content provider |
| 997 | * URI used for this purpose must require no permissions to read the image data. |
| 998 | */ |
| 999 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1000 | |
| 1001 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1002 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 1003 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1004 | * {@link android.app.Notification.MediaStyle} notification. |
| 1005 | */ |
| 1006 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1007 | |
| 1008 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 1009 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 1010 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 1011 | */ |
| 1012 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1013 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 1014 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1015 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 1016 | * direct replies |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1017 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1018 | * {@link CharSequence} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1019 | */ |
| 1020 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1021 | |
| 1022 | /** |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1023 | * {@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] | 1024 | * represented by a {@link android.app.Notification.MessagingStyle} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1025 | */ |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1026 | public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1027 | |
| 1028 | /** |
| 1029 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 1030 | * bundles provided by a |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1031 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1032 | * array of bundles. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1033 | */ |
| 1034 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 1035 | |
| 1036 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 1037 | * {@link #extras} key: an array of |
| 1038 | * {@link android.app.Notification.MessagingStyle#addHistoricMessage historic} |
| 1039 | * {@link android.app.Notification.MessagingStyle.Message} bundles provided by a |
| 1040 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1041 | * array of bundles. |
| 1042 | */ |
| 1043 | public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1044 | |
| 1045 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1046 | * {@link #extras} key: whether the notification should be colorized as |
| 1047 | * supplied to {@link Builder#setColorized(boolean)}}. |
| 1048 | */ |
| 1049 | public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1050 | |
| 1051 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1052 | * @hide |
| 1053 | */ |
| 1054 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1055 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 1056 | /** |
| 1057 | * @hide |
| 1058 | */ |
| 1059 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1060 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1061 | /** |
| 1062 | * {@link #extras} key: the audio contents of this notification. |
| 1063 | * |
| 1064 | * This is for use when rendering the notification on an audio-focused interface; |
| 1065 | * the audio contents are a complete sound sample that contains the contents/body of the |
| 1066 | * notification. This may be used in substitute of a Text-to-Speech reading of the |
| 1067 | * notification. For example if the notification represents a voice message this should point |
| 1068 | * to the audio of that message. |
| 1069 | * |
| 1070 | * The data stored under this key should be a String representation of a Uri that contains the |
| 1071 | * audio contents in one of the following formats: WAV, PCM 16-bit, AMR-WB. |
| 1072 | * |
| 1073 | * This extra is unnecessary if you are using {@code MessagingStyle} since each {@code Message} |
| 1074 | * has a field for holding data URI. That field can be used for audio. |
| 1075 | * See {@code Message#setData}. |
| 1076 | * |
| 1077 | * Example usage: |
| 1078 | * <pre> |
| 1079 | * {@code |
| 1080 | * Notification.Builder myBuilder = (build your Notification as normal); |
| 1081 | * myBuilder.getExtras().putString(EXTRA_AUDIO_CONTENTS_URI, myAudioUri.toString()); |
| 1082 | * } |
| 1083 | * </pre> |
| 1084 | */ |
| 1085 | public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1086 | |
Dan Sandler | 80eaa59 | 2016-04-14 23:34:54 -0400 | [diff] [blame] | 1087 | /** @hide */ |
| 1088 | @SystemApi |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1089 | public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1090 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1091 | private Icon mSmallIcon; |
| 1092 | private Icon mLargeIcon; |
| 1093 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1094 | private String mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1095 | private long mTimeout; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1096 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1097 | private String mShortcutId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1098 | private CharSequence mSettingsText; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1099 | |
| 1100 | /** |
| 1101 | * If this notification is being shown as a badge, always show as a number. |
| 1102 | */ |
| 1103 | public static final int BADGE_ICON_NONE = 0; |
| 1104 | |
| 1105 | /** |
| 1106 | * If this notification is being shown as a badge, use the {@link #getSmallIcon()} to |
| 1107 | * represent this notification. |
| 1108 | */ |
| 1109 | public static final int BADGE_ICON_SMALL = 1; |
| 1110 | |
| 1111 | /** |
| 1112 | * If this notification is being shown as a badge, use the {@link #getLargeIcon()} to |
| 1113 | * represent this notification. |
| 1114 | */ |
| 1115 | public static final int BADGE_ICON_LARGE = 2; |
Julia Reynolds | 7d5b4da | 2017-03-20 10:18:49 -0400 | [diff] [blame] | 1116 | private int mBadgeIcon = BADGE_ICON_NONE; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1117 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1118 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1119 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 1120 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 1121 | * selected by the user. |
| 1122 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1123 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 1124 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 1125 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1126 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1127 | public static class Action implements Parcelable { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1128 | /** |
| 1129 | * {@link #extras} key: Keys to a {@link Parcelable} {@link ArrayList} of |
| 1130 | * {@link RemoteInput}s. |
| 1131 | * |
| 1132 | * This is intended for {@link RemoteInput}s that only accept data, meaning |
| 1133 | * {@link RemoteInput#getAllowFreeFormInput} is false, {@link RemoteInput#getChoices} |
| 1134 | * is null or empty, and {@link RemoteInput#getAllowedDataTypes is non-null and not |
| 1135 | * empty. These {@link RemoteInput}s will be ignored by devices that do not |
| 1136 | * support non-text-based {@link RemoteInput}s. See {@link Builder#build}. |
| 1137 | * |
| 1138 | * You can test if a RemoteInput matches these constraints using |
| 1139 | * {@link RemoteInput#isDataOnly}. |
| 1140 | */ |
| 1141 | private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1142 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1143 | private final Bundle mExtras; |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1144 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1145 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1146 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1147 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1148 | /** |
| 1149 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1150 | * |
| 1151 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1152 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1153 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1154 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1155 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1156 | /** |
| 1157 | * Title of the action. |
| 1158 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1159 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1160 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1161 | /** |
| 1162 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1163 | * may be rendered in a disabled presentation by the system UI. |
| 1164 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1165 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1166 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1167 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1168 | if (in.readInt() != 0) { |
| 1169 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1170 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1171 | icon = mIcon.getResId(); |
| 1172 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1173 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1174 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1175 | if (in.readInt() == 1) { |
| 1176 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1177 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1178 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1179 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1180 | mAllowGeneratedReplies = in.readInt() == 1; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1181 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1182 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1183 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1184 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1185 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1186 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1187 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1188 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1191 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1192 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1193 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1194 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1195 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1196 | this.icon = icon.getResId(); |
| 1197 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1198 | this.title = title; |
| 1199 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1200 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1201 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1202 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1206 | * Return an icon representing the action. |
| 1207 | */ |
| 1208 | public Icon getIcon() { |
| 1209 | if (mIcon == null && icon != 0) { |
| 1210 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1211 | mIcon = Icon.createWithResource("", icon); |
| 1212 | } |
| 1213 | return mIcon; |
| 1214 | } |
| 1215 | |
| 1216 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1217 | * Get additional metadata carried around with this Action. |
| 1218 | */ |
| 1219 | public Bundle getExtras() { |
| 1220 | return mExtras; |
| 1221 | } |
| 1222 | |
| 1223 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1224 | * Return whether the platform should automatically generate possible replies for this |
| 1225 | * {@link Action} |
| 1226 | */ |
| 1227 | public boolean getAllowGeneratedReplies() { |
| 1228 | return mAllowGeneratedReplies; |
| 1229 | } |
| 1230 | |
| 1231 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1232 | * 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] | 1233 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1234 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1235 | */ |
| 1236 | public RemoteInput[] getRemoteInputs() { |
| 1237 | return mRemoteInputs; |
| 1238 | } |
| 1239 | |
| 1240 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1241 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1242 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1243 | * {@link RemoteInput#isDataOnly}. |
| 1244 | * |
| 1245 | * May return null if no data-only remote inputs were added. |
| 1246 | * |
| 1247 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1248 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1249 | */ |
| 1250 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1251 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1252 | } |
| 1253 | |
| 1254 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1255 | * Builder class for {@link Action} objects. |
| 1256 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1257 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1258 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1259 | private final CharSequence mTitle; |
| 1260 | private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1261 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1262 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1263 | private ArrayList<RemoteInput> mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1264 | |
| 1265 | /** |
| 1266 | * Construct a new builder for {@link Action} object. |
| 1267 | * @param icon icon to show for this action |
| 1268 | * @param title the title of the action |
| 1269 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1270 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1271 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1272 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1273 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | /** |
| 1277 | * Construct a new builder for {@link Action} object. |
| 1278 | * @param icon icon to show for this action |
| 1279 | * @param title the title of the action |
| 1280 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1281 | */ |
| 1282 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1283 | this(icon, title, intent, new Bundle(), null, true); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * Construct a new builder for {@link Action} object using the fields from an |
| 1288 | * {@link Action}. |
| 1289 | * @param action the action to read fields from. |
| 1290 | */ |
| 1291 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1292 | this(action.getIcon(), action.title, action.actionIntent, |
| 1293 | new Bundle(action.mExtras), action.getRemoteInputs(), |
| 1294 | action.getAllowGeneratedReplies()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1297 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1298 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1299 | mIcon = icon; |
| 1300 | mTitle = title; |
| 1301 | mIntent = intent; |
| 1302 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1303 | if (remoteInputs != null) { |
| 1304 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1305 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1306 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1307 | mAllowGeneratedReplies = allowGeneratedReplies; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | /** |
| 1311 | * Merge additional metadata into this builder. |
| 1312 | * |
| 1313 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1314 | * |
| 1315 | * @see Notification.Action#extras |
| 1316 | */ |
| 1317 | public Builder addExtras(Bundle extras) { |
| 1318 | if (extras != null) { |
| 1319 | mExtras.putAll(extras); |
| 1320 | } |
| 1321 | return this; |
| 1322 | } |
| 1323 | |
| 1324 | /** |
| 1325 | * Get the metadata Bundle used by this Builder. |
| 1326 | * |
| 1327 | * <p>The returned Bundle is shared with this Builder. |
| 1328 | */ |
| 1329 | public Bundle getExtras() { |
| 1330 | return mExtras; |
| 1331 | } |
| 1332 | |
| 1333 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1334 | * Add an input to be collected from the user when this action is sent. |
| 1335 | * Response values can be retrieved from the fired intent by using the |
| 1336 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1337 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1338 | * @return this object for method chaining |
| 1339 | */ |
| 1340 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1341 | if (mRemoteInputs == null) { |
| 1342 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1343 | } |
| 1344 | mRemoteInputs.add(remoteInput); |
| 1345 | return this; |
| 1346 | } |
| 1347 | |
| 1348 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1349 | * Set whether the platform should automatically generate possible replies to add to |
| 1350 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1351 | * {@link RemoteInput}, this has no effect. |
| 1352 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1353 | * otherwise |
| 1354 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1355 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1356 | */ |
| 1357 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1358 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1359 | return this; |
| 1360 | } |
| 1361 | |
| 1362 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1363 | * Apply an extender to this action builder. Extenders may be used to add |
| 1364 | * metadata or change options on this builder. |
| 1365 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1366 | public Builder extend(Extender extender) { |
| 1367 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1368 | return this; |
| 1369 | } |
| 1370 | |
| 1371 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1372 | * Combine all of the options that have been set and return a new {@link Action} |
| 1373 | * object. |
| 1374 | * @return the built action |
| 1375 | */ |
| 1376 | public Action build() { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1377 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1378 | RemoteInput[] previousDataInputs = |
| 1379 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1380 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1381 | for (RemoteInput input : previousDataInputs) { |
| 1382 | dataOnlyInputs.add(input); |
| 1383 | } |
| 1384 | } |
| 1385 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1386 | if (mRemoteInputs != null) { |
| 1387 | for (RemoteInput input : mRemoteInputs) { |
| 1388 | if (input.isDataOnly()) { |
| 1389 | dataOnlyInputs.add(input); |
| 1390 | } else { |
| 1391 | textInputs.add(input); |
| 1392 | } |
| 1393 | } |
| 1394 | } |
| 1395 | if (!dataOnlyInputs.isEmpty()) { |
| 1396 | RemoteInput[] dataInputsArr = |
| 1397 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1398 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1399 | } |
| 1400 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1401 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1402 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1403 | mAllowGeneratedReplies); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1404 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1405 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1406 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1407 | @Override |
| 1408 | public Action clone() { |
| 1409 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1410 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1411 | title, |
| 1412 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1413 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1414 | getRemoteInputs(), |
| 1415 | getAllowGeneratedReplies()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1416 | } |
| 1417 | @Override |
| 1418 | public int describeContents() { |
| 1419 | return 0; |
| 1420 | } |
| 1421 | @Override |
| 1422 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1423 | final Icon ic = getIcon(); |
| 1424 | if (ic != null) { |
| 1425 | out.writeInt(1); |
| 1426 | ic.writeToParcel(out, 0); |
| 1427 | } else { |
| 1428 | out.writeInt(0); |
| 1429 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1430 | TextUtils.writeToParcel(title, out, flags); |
| 1431 | if (actionIntent != null) { |
| 1432 | out.writeInt(1); |
| 1433 | actionIntent.writeToParcel(out, flags); |
| 1434 | } else { |
| 1435 | out.writeInt(0); |
| 1436 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1437 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1438 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1439 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1440 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1441 | public static final Parcelable.Creator<Action> CREATOR = |
| 1442 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1443 | public Action createFromParcel(Parcel in) { |
| 1444 | return new Action(in); |
| 1445 | } |
| 1446 | public Action[] newArray(int size) { |
| 1447 | return new Action[size]; |
| 1448 | } |
| 1449 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1450 | |
| 1451 | /** |
| 1452 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1453 | * metadata or change options on an action builder. |
| 1454 | */ |
| 1455 | public interface Extender { |
| 1456 | /** |
| 1457 | * Apply this extender to a notification action builder. |
| 1458 | * @param builder the builder to be modified. |
| 1459 | * @return the build object for chaining. |
| 1460 | */ |
| 1461 | public Builder extend(Builder builder); |
| 1462 | } |
| 1463 | |
| 1464 | /** |
| 1465 | * Wearable extender for notification actions. To add extensions to an action, |
| 1466 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1467 | * the {@code WearableExtender()} constructor and apply it to a |
| 1468 | * {@link android.app.Notification.Action.Builder} using |
| 1469 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1470 | * |
| 1471 | * <pre class="prettyprint"> |
| 1472 | * Notification.Action action = new Notification.Action.Builder( |
| 1473 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1474 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1475 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1476 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1477 | */ |
| 1478 | public static final class WearableExtender implements Extender { |
| 1479 | /** Notification action extra which contains wearable extensions */ |
| 1480 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1481 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1482 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1483 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1484 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1485 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1486 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1487 | |
| 1488 | // Flags bitwise-ored to mFlags |
| 1489 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1490 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1491 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1492 | |
| 1493 | // Default value for flags integer |
| 1494 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1495 | |
| 1496 | private int mFlags = DEFAULT_FLAGS; |
| 1497 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1498 | private CharSequence mInProgressLabel; |
| 1499 | private CharSequence mConfirmLabel; |
| 1500 | private CharSequence mCancelLabel; |
| 1501 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1502 | /** |
| 1503 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1504 | * options. |
| 1505 | */ |
| 1506 | public WearableExtender() { |
| 1507 | } |
| 1508 | |
| 1509 | /** |
| 1510 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1511 | * wearable options present in an existing notification action. |
| 1512 | * @param action the notification action to inspect. |
| 1513 | */ |
| 1514 | public WearableExtender(Action action) { |
| 1515 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1516 | if (wearableBundle != null) { |
| 1517 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1518 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1519 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1520 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | /** |
| 1525 | * Apply wearable extensions to a notification action that is being built. This is |
| 1526 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1527 | * method of {@link android.app.Notification.Action.Builder}. |
| 1528 | */ |
| 1529 | @Override |
| 1530 | public Action.Builder extend(Action.Builder builder) { |
| 1531 | Bundle wearableBundle = new Bundle(); |
| 1532 | |
| 1533 | if (mFlags != DEFAULT_FLAGS) { |
| 1534 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1535 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1536 | if (mInProgressLabel != null) { |
| 1537 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1538 | } |
| 1539 | if (mConfirmLabel != null) { |
| 1540 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1541 | } |
| 1542 | if (mCancelLabel != null) { |
| 1543 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1544 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1545 | |
| 1546 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1547 | return builder; |
| 1548 | } |
| 1549 | |
| 1550 | @Override |
| 1551 | public WearableExtender clone() { |
| 1552 | WearableExtender that = new WearableExtender(); |
| 1553 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1554 | that.mInProgressLabel = this.mInProgressLabel; |
| 1555 | that.mConfirmLabel = this.mConfirmLabel; |
| 1556 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1557 | return that; |
| 1558 | } |
| 1559 | |
| 1560 | /** |
| 1561 | * Set whether this action is available when the wearable device is not connected to |
| 1562 | * a companion device. The user can still trigger this action when the wearable device is |
| 1563 | * offline, but a visual hint will indicate that the action may not be available. |
| 1564 | * Defaults to true. |
| 1565 | */ |
| 1566 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1567 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1568 | return this; |
| 1569 | } |
| 1570 | |
| 1571 | /** |
| 1572 | * Get whether this action is available when the wearable device is not connected to |
| 1573 | * a companion device. The user can still trigger this action when the wearable device is |
| 1574 | * offline, but a visual hint will indicate that the action may not be available. |
| 1575 | * Defaults to true. |
| 1576 | */ |
| 1577 | public boolean isAvailableOffline() { |
| 1578 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1579 | } |
| 1580 | |
| 1581 | private void setFlag(int mask, boolean value) { |
| 1582 | if (value) { |
| 1583 | mFlags |= mask; |
| 1584 | } else { |
| 1585 | mFlags &= ~mask; |
| 1586 | } |
| 1587 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1588 | |
| 1589 | /** |
| 1590 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1591 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1592 | * |
| 1593 | * @param label the label to display while the action is being prepared to execute |
| 1594 | * @return this object for method chaining |
| 1595 | */ |
| 1596 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1597 | mInProgressLabel = label; |
| 1598 | return this; |
| 1599 | } |
| 1600 | |
| 1601 | /** |
| 1602 | * Get the label to display while the wearable is preparing to automatically execute |
| 1603 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1604 | * |
| 1605 | * @return the label to display while the action is being prepared to execute |
| 1606 | */ |
| 1607 | public CharSequence getInProgressLabel() { |
| 1608 | return mInProgressLabel; |
| 1609 | } |
| 1610 | |
| 1611 | /** |
| 1612 | * Set a label to display to confirm that the action should be executed. |
| 1613 | * This is usually an imperative verb like "Send". |
| 1614 | * |
| 1615 | * @param label the label to confirm the action should be executed |
| 1616 | * @return this object for method chaining |
| 1617 | */ |
| 1618 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1619 | mConfirmLabel = label; |
| 1620 | return this; |
| 1621 | } |
| 1622 | |
| 1623 | /** |
| 1624 | * Get the label to display to confirm that the action should be executed. |
| 1625 | * This is usually an imperative verb like "Send". |
| 1626 | * |
| 1627 | * @return the label to confirm the action should be executed |
| 1628 | */ |
| 1629 | public CharSequence getConfirmLabel() { |
| 1630 | return mConfirmLabel; |
| 1631 | } |
| 1632 | |
| 1633 | /** |
| 1634 | * Set a label to display to cancel the action. |
| 1635 | * This is usually an imperative verb, like "Cancel". |
| 1636 | * |
| 1637 | * @param label the label to display to cancel the action |
| 1638 | * @return this object for method chaining |
| 1639 | */ |
| 1640 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1641 | mCancelLabel = label; |
| 1642 | return this; |
| 1643 | } |
| 1644 | |
| 1645 | /** |
| 1646 | * Get the label to display to cancel the action. |
| 1647 | * This is usually an imperative verb like "Cancel". |
| 1648 | * |
| 1649 | * @return the label to display to cancel the action |
| 1650 | */ |
| 1651 | public CharSequence getCancelLabel() { |
| 1652 | return mCancelLabel; |
| 1653 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1654 | |
| 1655 | /** |
| 1656 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 1657 | * platform that it can generate the appropriate transitions. |
| 1658 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 1659 | * an activity and transitions should be generated, false otherwise. |
| 1660 | * @return this object for method chaining |
| 1661 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1662 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1663 | boolean hintLaunchesActivity) { |
| 1664 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 1665 | return this; |
| 1666 | } |
| 1667 | |
| 1668 | /** |
| 1669 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 1670 | * platform that it can generate the appropriate transitions |
| 1671 | * @return {@code true} if the content intent will launch an activity and transitions |
| 1672 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 1673 | * never set. |
| 1674 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1675 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1676 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 1677 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1678 | |
| 1679 | /** |
| 1680 | * Set a hint that this Action should be displayed inline. |
| 1681 | * |
| 1682 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 1683 | * otherwise |
| 1684 | * @return this object for method chaining |
| 1685 | */ |
| 1686 | public WearableExtender setHintDisplayActionInline( |
| 1687 | boolean hintDisplayInline) { |
| 1688 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 1689 | return this; |
| 1690 | } |
| 1691 | |
| 1692 | /** |
| 1693 | * Get a hint that this Action should be displayed inline. |
| 1694 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 1695 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1696 | * otherwise. The default value is {@code false} if this was never set. |
| 1697 | */ |
| 1698 | public boolean getHintDisplayActionInline() { |
| 1699 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 1700 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1701 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1702 | } |
| 1703 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1704 | /** |
| 1705 | * Array of all {@link Action} structures attached to this notification by |
| 1706 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 1707 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 1708 | * interface for invoking actions. |
| 1709 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1710 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1711 | |
| 1712 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1713 | * Replacement version of this notification whose content will be shown |
| 1714 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 1715 | * and {@link #VISIBILITY_PUBLIC}. |
| 1716 | */ |
| 1717 | public Notification publicVersion; |
| 1718 | |
| 1719 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1720 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1721 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1722 | */ |
| 1723 | public Notification() |
| 1724 | { |
| 1725 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1726 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1727 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1731 | * @hide |
| 1732 | */ |
| 1733 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 1734 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 1735 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1736 | new Builder(context) |
| 1737 | .setWhen(when) |
| 1738 | .setSmallIcon(icon) |
| 1739 | .setTicker(tickerText) |
| 1740 | .setContentTitle(contentTitle) |
| 1741 | .setContentText(contentText) |
| 1742 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 1743 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | /** |
| 1747 | * Constructs a Notification object with the information needed to |
| 1748 | * have a status bar icon without the standard expanded view. |
| 1749 | * |
| 1750 | * @param icon The resource id of the icon to put in the status bar. |
| 1751 | * @param tickerText The text that flows by in the status bar when the notification first |
| 1752 | * activates. |
| 1753 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 1754 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1755 | * |
| 1756 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1757 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1758 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1759 | public Notification(int icon, CharSequence tickerText, long when) |
| 1760 | { |
| 1761 | this.icon = icon; |
| 1762 | this.tickerText = tickerText; |
| 1763 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1764 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | /** |
| 1768 | * Unflatten the notification from a parcel. |
| 1769 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 1770 | @SuppressWarnings("unchecked") |
| 1771 | public Notification(Parcel parcel) { |
| 1772 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 1773 | // intents in extras are always written as the last entry. |
| 1774 | readFromParcelImpl(parcel); |
| 1775 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 1776 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1780 | { |
| 1781 | int version = parcel.readInt(); |
| 1782 | |
| 1783 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1784 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1785 | if (parcel.readInt() != 0) { |
| 1786 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1787 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1788 | icon = mSmallIcon.getResId(); |
| 1789 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1790 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1791 | number = parcel.readInt(); |
| 1792 | if (parcel.readInt() != 0) { |
| 1793 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1794 | } |
| 1795 | if (parcel.readInt() != 0) { |
| 1796 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1797 | } |
| 1798 | if (parcel.readInt() != 0) { |
| 1799 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1800 | } |
| 1801 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1802 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1803 | } |
| 1804 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1805 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1806 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1807 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1808 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1810 | defaults = parcel.readInt(); |
| 1811 | flags = parcel.readInt(); |
| 1812 | if (parcel.readInt() != 0) { |
| 1813 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 1814 | } |
| 1815 | |
| 1816 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1817 | if (parcel.readInt() != 0) { |
| 1818 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 1819 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1820 | vibrate = parcel.createLongArray(); |
| 1821 | ledARGB = parcel.readInt(); |
| 1822 | ledOnMS = parcel.readInt(); |
| 1823 | ledOffMS = parcel.readInt(); |
| 1824 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1825 | |
| 1826 | if (parcel.readInt() != 0) { |
| 1827 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1828 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1829 | |
| 1830 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1831 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1832 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1833 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1834 | mGroupKey = parcel.readString(); |
| 1835 | |
| 1836 | mSortKey = parcel.readString(); |
| 1837 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1838 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1839 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1840 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 1841 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1842 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1843 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1844 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1845 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1846 | if (parcel.readInt() != 0) { |
| 1847 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1848 | } |
| 1849 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1850 | visibility = parcel.readInt(); |
| 1851 | |
| 1852 | if (parcel.readInt() != 0) { |
| 1853 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 1854 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1855 | |
| 1856 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1857 | |
| 1858 | if (parcel.readInt() != 0) { |
| 1859 | mChannelId = parcel.readString(); |
| 1860 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1861 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1862 | |
| 1863 | if (parcel.readInt() != 0) { |
| 1864 | mShortcutId = parcel.readString(); |
| 1865 | } |
| 1866 | |
| 1867 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1868 | |
| 1869 | if (parcel.readInt() != 0) { |
| 1870 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1871 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1872 | } |
| 1873 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1874 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1875 | public Notification clone() { |
| 1876 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1877 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1878 | return that; |
| 1879 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1880 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1881 | /** |
| 1882 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 1883 | * of this into that. |
| 1884 | * @hide |
| 1885 | */ |
| 1886 | public void cloneInto(Notification that, boolean heavy) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1887 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1888 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1889 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1890 | that.number = this.number; |
| 1891 | |
| 1892 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 1893 | that.contentIntent = this.contentIntent; |
| 1894 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1895 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1896 | |
| 1897 | if (this.tickerText != null) { |
| 1898 | that.tickerText = this.tickerText.toString(); |
| 1899 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1900 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1901 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1902 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1903 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1904 | that.contentView = this.contentView.clone(); |
| 1905 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1906 | if (heavy && this.mLargeIcon != null) { |
| 1907 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1908 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 1909 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1910 | that.sound = this.sound; // android.net.Uri is immutable |
| 1911 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1912 | if (this.audioAttributes != null) { |
| 1913 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 1914 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1915 | |
| 1916 | final long[] vibrate = this.vibrate; |
| 1917 | if (vibrate != null) { |
| 1918 | final int N = vibrate.length; |
| 1919 | final long[] vib = that.vibrate = new long[N]; |
| 1920 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 1921 | } |
| 1922 | |
| 1923 | that.ledARGB = this.ledARGB; |
| 1924 | that.ledOnMS = this.ledOnMS; |
| 1925 | that.ledOffMS = this.ledOffMS; |
| 1926 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1927 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1928 | that.flags = this.flags; |
| 1929 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1930 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1931 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1932 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1933 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1934 | that.mGroupKey = this.mGroupKey; |
| 1935 | |
| 1936 | that.mSortKey = this.mSortKey; |
| 1937 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1938 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1939 | try { |
| 1940 | that.extras = new Bundle(this.extras); |
| 1941 | // will unparcel |
| 1942 | that.extras.size(); |
| 1943 | } catch (BadParcelableException e) { |
| 1944 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 1945 | that.extras = null; |
| 1946 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1947 | } |
| 1948 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 1949 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 1950 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1953 | if (this.actions != null) { |
| 1954 | that.actions = new Action[this.actions.length]; |
| 1955 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 1956 | if ( this.actions[i] != null) { |
| 1957 | that.actions[i] = this.actions[i].clone(); |
| 1958 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1959 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1960 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1961 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1962 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1963 | that.bigContentView = this.bigContentView.clone(); |
| 1964 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1965 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1966 | if (heavy && this.headsUpContentView != null) { |
| 1967 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 1968 | } |
| 1969 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1970 | that.visibility = this.visibility; |
| 1971 | |
| 1972 | if (this.publicVersion != null) { |
| 1973 | that.publicVersion = new Notification(); |
| 1974 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 1975 | } |
| 1976 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1977 | that.color = this.color; |
| 1978 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1979 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1980 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1981 | that.mShortcutId = this.mShortcutId; |
| 1982 | that.mBadgeIcon = this.mBadgeIcon; |
| 1983 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1984 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1985 | if (!heavy) { |
| 1986 | that.lightenPayload(); // will clean out extras |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | /** |
| 1991 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 1992 | * listeners when the full contents are not necessary. |
| 1993 | * @hide |
| 1994 | */ |
| 1995 | public final void lightenPayload() { |
| 1996 | tickerView = null; |
| 1997 | contentView = null; |
| 1998 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1999 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2000 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2001 | if (extras != null && !extras.isEmpty()) { |
| 2002 | final Set<String> keyset = extras.keySet(); |
| 2003 | final int N = keyset.size(); |
| 2004 | final String[] keys = keyset.toArray(new String[N]); |
| 2005 | for (int i=0; i<N; i++) { |
| 2006 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2007 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2008 | continue; |
| 2009 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2010 | final Object obj = extras.get(key); |
| 2011 | if (obj != null && |
| 2012 | ( obj instanceof Parcelable |
| 2013 | || obj instanceof Parcelable[] |
| 2014 | || obj instanceof SparseArray |
| 2015 | || obj instanceof ArrayList)) { |
| 2016 | extras.remove(key); |
| 2017 | } |
| 2018 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2019 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2022 | /** |
| 2023 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2024 | * means it had better not be some custom Parcelable implementation. |
| 2025 | * @hide |
| 2026 | */ |
| 2027 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2028 | if (cs == null) return cs; |
| 2029 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2030 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2031 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2032 | if (cs instanceof Parcelable) { |
| 2033 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2034 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2035 | return cs.toString(); |
| 2036 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2037 | return removeTextSizeSpans(cs); |
| 2038 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2039 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2040 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2041 | if (charSequence instanceof Spanned) { |
| 2042 | Spanned ss = (Spanned) charSequence; |
| 2043 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2044 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2045 | for (Object span : spans) { |
| 2046 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2047 | if (resultSpan instanceof CharacterStyle) { |
| 2048 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2049 | } |
| 2050 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2051 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2052 | resultSpan = new TextAppearanceSpan( |
| 2053 | originalSpan.getFamily(), |
| 2054 | originalSpan.getTextStyle(), |
| 2055 | -1, |
| 2056 | originalSpan.getTextColor(), |
| 2057 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2058 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2059 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2060 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2061 | } else { |
| 2062 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2063 | } |
| 2064 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2065 | ss.getSpanFlags(span)); |
| 2066 | } |
| 2067 | return builder; |
| 2068 | } |
| 2069 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2070 | } |
| 2071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2072 | public int describeContents() { |
| 2073 | return 0; |
| 2074 | } |
| 2075 | |
| 2076 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2077 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2079 | public void writeToParcel(Parcel parcel, int flags) { |
| 2080 | // We need to mark all pending intents getting into the notification |
| 2081 | // system as being put there to later allow the notification ranker |
| 2082 | // to launch them and by doing so add the app to the battery saver white |
| 2083 | // list for a short period of time. The problem is that the system |
| 2084 | // cannot look into the extras as there may be parcelables there that |
| 2085 | // the platform does not know how to handle. To go around that we have |
| 2086 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2087 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2088 | if (collectPendingIntents) { |
| 2089 | PendingIntent.setOnMarshaledListener( |
| 2090 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2091 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2092 | if (allPendingIntents == null) { |
| 2093 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2094 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2095 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2096 | } |
| 2097 | }); |
| 2098 | } |
| 2099 | try { |
| 2100 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2101 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2102 | writeToParcelImpl(parcel, flags); |
| 2103 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2104 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2105 | } finally { |
| 2106 | if (collectPendingIntents) { |
| 2107 | PendingIntent.setOnMarshaledListener(null); |
| 2108 | } |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2113 | parcel.writeInt(1); |
| 2114 | |
| 2115 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2116 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2117 | if (mSmallIcon == null && icon != 0) { |
| 2118 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2119 | mSmallIcon = Icon.createWithResource("", icon); |
| 2120 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2121 | if (mSmallIcon != null) { |
| 2122 | parcel.writeInt(1); |
| 2123 | mSmallIcon.writeToParcel(parcel, 0); |
| 2124 | } else { |
| 2125 | parcel.writeInt(0); |
| 2126 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2127 | parcel.writeInt(number); |
| 2128 | if (contentIntent != null) { |
| 2129 | parcel.writeInt(1); |
| 2130 | contentIntent.writeToParcel(parcel, 0); |
| 2131 | } else { |
| 2132 | parcel.writeInt(0); |
| 2133 | } |
| 2134 | if (deleteIntent != null) { |
| 2135 | parcel.writeInt(1); |
| 2136 | deleteIntent.writeToParcel(parcel, 0); |
| 2137 | } else { |
| 2138 | parcel.writeInt(0); |
| 2139 | } |
| 2140 | if (tickerText != null) { |
| 2141 | parcel.writeInt(1); |
| 2142 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2143 | } else { |
| 2144 | parcel.writeInt(0); |
| 2145 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2146 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2147 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2148 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2149 | } else { |
| 2150 | parcel.writeInt(0); |
| 2151 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2152 | if (contentView != null) { |
| 2153 | parcel.writeInt(1); |
| 2154 | contentView.writeToParcel(parcel, 0); |
| 2155 | } else { |
| 2156 | parcel.writeInt(0); |
| 2157 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2158 | if (mLargeIcon == null && largeIcon != null) { |
| 2159 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2160 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2161 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2162 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2163 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2164 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2165 | } else { |
| 2166 | parcel.writeInt(0); |
| 2167 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2168 | |
| 2169 | parcel.writeInt(defaults); |
| 2170 | parcel.writeInt(this.flags); |
| 2171 | |
| 2172 | if (sound != null) { |
| 2173 | parcel.writeInt(1); |
| 2174 | sound.writeToParcel(parcel, 0); |
| 2175 | } else { |
| 2176 | parcel.writeInt(0); |
| 2177 | } |
| 2178 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2179 | |
| 2180 | if (audioAttributes != null) { |
| 2181 | parcel.writeInt(1); |
| 2182 | audioAttributes.writeToParcel(parcel, 0); |
| 2183 | } else { |
| 2184 | parcel.writeInt(0); |
| 2185 | } |
| 2186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2187 | parcel.writeLongArray(vibrate); |
| 2188 | parcel.writeInt(ledARGB); |
| 2189 | parcel.writeInt(ledOnMS); |
| 2190 | parcel.writeInt(ledOffMS); |
| 2191 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2192 | |
| 2193 | if (fullScreenIntent != null) { |
| 2194 | parcel.writeInt(1); |
| 2195 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2196 | } else { |
| 2197 | parcel.writeInt(0); |
| 2198 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2199 | |
| 2200 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2201 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2202 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2203 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2204 | parcel.writeString(mGroupKey); |
| 2205 | |
| 2206 | parcel.writeString(mSortKey); |
| 2207 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2208 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2209 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2210 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2211 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2212 | if (bigContentView != null) { |
| 2213 | parcel.writeInt(1); |
| 2214 | bigContentView.writeToParcel(parcel, 0); |
| 2215 | } else { |
| 2216 | parcel.writeInt(0); |
| 2217 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2218 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2219 | if (headsUpContentView != null) { |
| 2220 | parcel.writeInt(1); |
| 2221 | headsUpContentView.writeToParcel(parcel, 0); |
| 2222 | } else { |
| 2223 | parcel.writeInt(0); |
| 2224 | } |
| 2225 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2226 | parcel.writeInt(visibility); |
| 2227 | |
| 2228 | if (publicVersion != null) { |
| 2229 | parcel.writeInt(1); |
| 2230 | publicVersion.writeToParcel(parcel, 0); |
| 2231 | } else { |
| 2232 | parcel.writeInt(0); |
| 2233 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2234 | |
| 2235 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2236 | |
| 2237 | if (mChannelId != null) { |
| 2238 | parcel.writeInt(1); |
| 2239 | parcel.writeString(mChannelId); |
| 2240 | } else { |
| 2241 | parcel.writeInt(0); |
| 2242 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2243 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2244 | |
| 2245 | if (mShortcutId != null) { |
| 2246 | parcel.writeInt(1); |
| 2247 | parcel.writeString(mShortcutId); |
| 2248 | } else { |
| 2249 | parcel.writeInt(0); |
| 2250 | } |
| 2251 | |
| 2252 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2253 | |
| 2254 | if (mSettingsText != null) { |
| 2255 | parcel.writeInt(1); |
| 2256 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2257 | } else { |
| 2258 | parcel.writeInt(0); |
| 2259 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | /** |
| 2263 | * Parcelable.Creator that instantiates Notification objects |
| 2264 | */ |
| 2265 | public static final Parcelable.Creator<Notification> CREATOR |
| 2266 | = new Parcelable.Creator<Notification>() |
| 2267 | { |
| 2268 | public Notification createFromParcel(Parcel parcel) |
| 2269 | { |
| 2270 | return new Notification(parcel); |
| 2271 | } |
| 2272 | |
| 2273 | public Notification[] newArray(int size) |
| 2274 | { |
| 2275 | return new Notification[size]; |
| 2276 | } |
| 2277 | }; |
| 2278 | |
| 2279 | /** |
| 2280 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2281 | * layout. |
| 2282 | * |
| 2283 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2284 | * in the view.</p> |
| 2285 | * @param context The context for your application / activity. |
| 2286 | * @param contentTitle The title that goes in the expanded entry. |
| 2287 | * @param contentText The text that goes in the expanded entry. |
| 2288 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2289 | * If this is an activity, it must include the |
| 2290 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2291 | * that you take care of task management as described in the |
| 2292 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2293 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2294 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2295 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2296 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2297 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2298 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2299 | public void setLatestEventInfo(Context context, |
| 2300 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2301 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2302 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2303 | new Throwable()); |
| 2304 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2305 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2306 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2307 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2308 | } |
| 2309 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2310 | // ensure that any information already set directly is preserved |
| 2311 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2312 | |
| 2313 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2314 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2315 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | } |
| 2317 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2318 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2319 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2320 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2321 | |
| 2322 | 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] | 2323 | } |
| 2324 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2325 | /** |
| 2326 | * @hide |
| 2327 | */ |
| 2328 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2329 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | /** |
| 2333 | * @hide |
| 2334 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2335 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2336 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2337 | } |
| 2338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2339 | @Override |
| 2340 | public String toString() { |
| 2341 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame^] | 2342 | sb.append("Notification(channel="); |
| 2343 | sb.append(getChannel()); |
| 2344 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2345 | sb.append(priority); |
| 2346 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2347 | if (contentView != null) { |
| 2348 | sb.append(contentView.getPackage()); |
| 2349 | sb.append("/0x"); |
| 2350 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2351 | } else { |
| 2352 | sb.append("null"); |
| 2353 | } |
| 2354 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2355 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2356 | sb.append("default"); |
| 2357 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2358 | int N = this.vibrate.length-1; |
| 2359 | sb.append("["); |
| 2360 | for (int i=0; i<N; i++) { |
| 2361 | sb.append(this.vibrate[i]); |
| 2362 | sb.append(','); |
| 2363 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 2364 | if (N != -1) { |
| 2365 | sb.append(this.vibrate[N]); |
| 2366 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | } else { |
| 2369 | sb.append("null"); |
| 2370 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2371 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2372 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2373 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2374 | } else if (this.sound != null) { |
| 2375 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2376 | } else { |
| 2377 | sb.append("null"); |
| 2378 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 2379 | if (this.tickerText != null) { |
| 2380 | sb.append(" tick"); |
| 2381 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2382 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2383 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2384 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2385 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2386 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2387 | if (this.category != null) { |
| 2388 | sb.append(" category="); |
| 2389 | sb.append(this.category); |
| 2390 | } |
| 2391 | if (this.mGroupKey != null) { |
| 2392 | sb.append(" groupKey="); |
| 2393 | sb.append(this.mGroupKey); |
| 2394 | } |
| 2395 | if (this.mSortKey != null) { |
| 2396 | sb.append(" sortKey="); |
| 2397 | sb.append(this.mSortKey); |
| 2398 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2399 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2400 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2401 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2402 | } |
| 2403 | sb.append(" vis="); |
| 2404 | sb.append(visibilityToString(this.visibility)); |
| 2405 | if (this.publicVersion != null) { |
| 2406 | sb.append(" publicVersion="); |
| 2407 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2408 | } |
| 2409 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | return sb.toString(); |
| 2411 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2412 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2413 | /** |
| 2414 | * {@hide} |
| 2415 | */ |
| 2416 | public static String visibilityToString(int vis) { |
| 2417 | switch (vis) { |
| 2418 | case VISIBILITY_PRIVATE: |
| 2419 | return "PRIVATE"; |
| 2420 | case VISIBILITY_PUBLIC: |
| 2421 | return "PUBLIC"; |
| 2422 | case VISIBILITY_SECRET: |
| 2423 | return "SECRET"; |
| 2424 | default: |
| 2425 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 2426 | } |
| 2427 | } |
| 2428 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2429 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 2430 | * {@hide} |
| 2431 | */ |
| 2432 | public static String priorityToString(@Priority int pri) { |
| 2433 | switch (pri) { |
| 2434 | case PRIORITY_MIN: |
| 2435 | return "MIN"; |
| 2436 | case PRIORITY_LOW: |
| 2437 | return "LOW"; |
| 2438 | case PRIORITY_DEFAULT: |
| 2439 | return "DEFAULT"; |
| 2440 | case PRIORITY_HIGH: |
| 2441 | return "HIGH"; |
| 2442 | case PRIORITY_MAX: |
| 2443 | return "MAX"; |
| 2444 | default: |
| 2445 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | /** |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2450 | * Returns the id of the channel this notification posts to. |
| 2451 | */ |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 2452 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2453 | return mChannelId; |
| 2454 | } |
| 2455 | |
| 2456 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2457 | * Returns the time at which this notification should be canceled by the system, if it's not |
| 2458 | * canceled already. |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2459 | */ |
| 2460 | public long getTimeout() { |
| 2461 | return mTimeout; |
| 2462 | } |
| 2463 | |
| 2464 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2465 | * @removed |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2466 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 2467 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 2468 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 2469 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2470 | @Deprecated |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2471 | public int getBadgeIcon() { |
| 2472 | return mBadgeIcon; |
| 2473 | } |
| 2474 | |
| 2475 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2476 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 2477 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 2478 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 2479 | */ |
| 2480 | public int getBadgeIconType() { |
| 2481 | return mBadgeIcon; |
| 2482 | } |
| 2483 | |
| 2484 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2485 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
| 2486 | */ |
| 2487 | public String getShortcutId() { |
| 2488 | return mShortcutId; |
| 2489 | } |
| 2490 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2491 | |
| 2492 | /** |
| 2493 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 2494 | */ |
| 2495 | public CharSequence getSettingsText() { |
| 2496 | return mSettingsText; |
| 2497 | } |
| 2498 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2499 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2500 | * The small icon representing this notification in the status bar and content view. |
| 2501 | * |
| 2502 | * @return the small icon representing this notification. |
| 2503 | * |
| 2504 | * @see Builder#getSmallIcon() |
| 2505 | * @see Builder#setSmallIcon(Icon) |
| 2506 | */ |
| 2507 | public Icon getSmallIcon() { |
| 2508 | return mSmallIcon; |
| 2509 | } |
| 2510 | |
| 2511 | /** |
| 2512 | * Used when notifying to clean up legacy small icons. |
| 2513 | * @hide |
| 2514 | */ |
| 2515 | public void setSmallIcon(Icon icon) { |
| 2516 | mSmallIcon = icon; |
| 2517 | } |
| 2518 | |
| 2519 | /** |
| 2520 | * The large icon shown in this notification's content view. |
| 2521 | * @see Builder#getLargeIcon() |
| 2522 | * @see Builder#setLargeIcon(Icon) |
| 2523 | */ |
| 2524 | public Icon getLargeIcon() { |
| 2525 | return mLargeIcon; |
| 2526 | } |
| 2527 | |
| 2528 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2529 | * @hide |
| 2530 | */ |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 2531 | public boolean isGroupSummary() { |
| 2532 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 2533 | } |
| 2534 | |
| 2535 | /** |
| 2536 | * @hide |
| 2537 | */ |
| 2538 | public boolean isGroupChild() { |
| 2539 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 2540 | } |
| 2541 | |
| 2542 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2543 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2544 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2545 | * 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] | 2546 | * content views using the platform's notification layout template. If your app supports |
| 2547 | * versions of Android as old as API level 4, you can instead use |
| 2548 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 2549 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 2550 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2551 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2552 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2553 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2554 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2555 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2556 | * .setContentTitle("New mail from " + sender.toString()) |
| 2557 | * .setContentText(subject) |
| 2558 | * .setSmallIcon(R.drawable.new_mail) |
| 2559 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2560 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2561 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2562 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2563 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 2564 | /** |
| 2565 | * @hide |
| 2566 | */ |
| 2567 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 2568 | "android.rebuild.contentViewActionCount"; |
| 2569 | /** |
| 2570 | * @hide |
| 2571 | */ |
| 2572 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 2573 | = "android.rebuild.bigViewActionCount"; |
| 2574 | /** |
| 2575 | * @hide |
| 2576 | */ |
| 2577 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 2578 | = "android.rebuild.hudViewActionCount"; |
| 2579 | |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 2580 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2581 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 2582 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 2583 | SystemProperties.getBoolean("notifications.only_title", true); |
| 2584 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2585 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2586 | private Notification mN; |
| 2587 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2588 | private Style mStyle; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2589 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
| 2590 | private ArrayList<String> mPersonList = new ArrayList<String>(); |
| 2591 | private NotificationColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 2592 | private boolean mIsLegacy; |
| 2593 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2594 | |
| 2595 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2596 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 2597 | */ |
| 2598 | private int mCachedContrastColor = COLOR_INVALID; |
| 2599 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 2600 | /** |
| 2601 | * Caches a ambient version of {@link #mCachedContrastColorIsFor}. |
| 2602 | */ |
| 2603 | private int mCachedAmbientColor = COLOR_INVALID; |
| 2604 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2605 | |
| 2606 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 2607 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 2608 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 2609 | */ |
| 2610 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 2611 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 2612 | private int mPrimaryTextColor = COLOR_INVALID; |
| 2613 | private int mSecondaryTextColor = COLOR_INVALID; |
| 2614 | private int mActionBarColor = COLOR_INVALID; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 2615 | |
| 2616 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2617 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2618 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2619 | |
| 2620 | * <table> |
| 2621 | * <tr><th align=right>priority</th> |
| 2622 | * <td>{@link #PRIORITY_DEFAULT}</td></tr> |
| 2623 | * <tr><th align=right>when</th> |
| 2624 | * <td>now ({@link System#currentTimeMillis()})</td></tr> |
| 2625 | * <tr><th align=right>audio stream</th> |
| 2626 | * <td>{@link #STREAM_DEFAULT}</td></tr> |
| 2627 | * </table> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2628 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2629 | |
| 2630 | * @param context |
| 2631 | * A {@link Context} that will be used by the Builder to construct the |
| 2632 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 2633 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 2634 | * @param channelId |
| 2635 | * The constructed Notification will be posted on this |
| 2636 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 2637 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2638 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 2639 | public Builder(Context context, String channelId) { |
| 2640 | this(context, (Notification) null); |
| 2641 | mN.mChannelId = channelId; |
| 2642 | } |
| 2643 | |
| 2644 | /** |
| 2645 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 2646 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 2647 | */ |
| 2648 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2649 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 2650 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2651 | } |
| 2652 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2653 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2654 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2655 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2656 | public Builder(Context context, Notification toAdopt) { |
| 2657 | mContext = context; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2658 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2659 | if (toAdopt == null) { |
| 2660 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 2661 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2662 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2663 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2664 | mN.priority = PRIORITY_DEFAULT; |
| 2665 | mN.visibility = VISIBILITY_PRIVATE; |
| 2666 | } else { |
| 2667 | mN = toAdopt; |
| 2668 | if (mN.actions != null) { |
| 2669 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2670 | } |
| 2671 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2672 | if (mN.extras.containsKey(EXTRA_PEOPLE)) { |
| 2673 | Collections.addAll(mPersonList, mN.extras.getStringArray(EXTRA_PEOPLE)); |
| 2674 | } |
| 2675 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2676 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 2677 | setSmallIcon(mN.icon); |
| 2678 | } |
| 2679 | |
| 2680 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 2681 | setLargeIcon(mN.largeIcon); |
| 2682 | } |
| 2683 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2684 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 2685 | if (!TextUtils.isEmpty(templateClass)) { |
| 2686 | final Class<? extends Style> styleClass |
| 2687 | = getNotificationStyleClass(templateClass); |
| 2688 | if (styleClass == null) { |
| 2689 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 2690 | } else { |
| 2691 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 2692 | final Constructor<? extends Style> ctor = |
| 2693 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2694 | ctor.setAccessible(true); |
| 2695 | final Style style = ctor.newInstance(); |
| 2696 | style.restoreFromExtras(mN.extras); |
| 2697 | |
| 2698 | if (style != null) { |
| 2699 | setStyle(style); |
| 2700 | } |
| 2701 | } catch (Throwable t) { |
| 2702 | Log.e(TAG, "Could not create Style", t); |
| 2703 | } |
| 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | private NotificationColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 2711 | if (mColorUtil == null) { |
| 2712 | mColorUtil = NotificationColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2713 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2714 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2718 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 2719 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 2720 | * the shortcut. |
| 2721 | * |
| 2722 | * This field will be ignored by Launchers that don't support badging or |
| 2723 | * {@link android.content.pm.ShortcutManager shortcuts}. |
| 2724 | * |
| 2725 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 2726 | * supersedes |
| 2727 | */ |
| 2728 | public Builder setShortcutId(String shortcutId) { |
| 2729 | mN.mShortcutId = shortcutId; |
| 2730 | return this; |
| 2731 | } |
| 2732 | |
| 2733 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2734 | * @removed |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2735 | * Sets which icon to display as a badge for this notification. |
| 2736 | * |
| 2737 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 2738 | * {@link #BADGE_ICON_LARGE}. |
| 2739 | * |
| 2740 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 2741 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2742 | @Deprecated |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2743 | public Builder chooseBadgeIcon(int icon) { |
| 2744 | mN.mBadgeIcon = icon; |
| 2745 | return this; |
| 2746 | } |
| 2747 | |
| 2748 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2749 | * Sets which icon to display as a badge for this notification. |
| 2750 | * |
| 2751 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 2752 | * {@link #BADGE_ICON_LARGE}. |
| 2753 | * |
| 2754 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 2755 | */ |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 2756 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2757 | mN.mBadgeIcon = icon; |
| 2758 | return this; |
| 2759 | } |
| 2760 | |
| 2761 | /** |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2762 | * Specifies the channel the notification should be delivered on. |
| 2763 | */ |
| 2764 | public Builder setChannel(String channelId) { |
| 2765 | mN.mChannelId = channelId; |
| 2766 | return this; |
| 2767 | } |
| 2768 | |
| 2769 | /** |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 2770 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 2771 | * if it is not already canceled. |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2772 | */ |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 2773 | public Builder setTimeout(long durationMs) { |
| 2774 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2775 | return this; |
| 2776 | } |
| 2777 | |
| 2778 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2779 | * 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] | 2780 | * |
| 2781 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 2782 | * shown anymore by default and must be opted into by using |
| 2783 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2784 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2785 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2786 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2787 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2788 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2789 | return this; |
| 2790 | } |
| 2791 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2792 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2793 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2794 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 2795 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 2796 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2797 | */ |
| 2798 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2799 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2800 | return this; |
| 2801 | } |
| 2802 | |
| 2803 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2804 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2805 | * |
| 2806 | * 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] | 2807 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2808 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2809 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 2810 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2811 | * 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] | 2812 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2813 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2814 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2815 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 2816 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2817 | */ |
| 2818 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2819 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2820 | return this; |
| 2821 | } |
| 2822 | |
| 2823 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2824 | * Sets the Chronometer to count down instead of counting up. |
| 2825 | * |
| 2826 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 2827 | * If it isn't set the chronometer will count up. |
| 2828 | * |
| 2829 | * @see #setUsesChronometer(boolean) |
| 2830 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 2831 | public Builder setChronometerCountDown(boolean countDown) { |
| 2832 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2833 | return this; |
| 2834 | } |
| 2835 | |
| 2836 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2837 | * Set the small icon resource, which will be used to represent the notification in the |
| 2838 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2839 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2840 | |
| 2841 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 2842 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 2843 | * icon will be moved to the right-hand side. |
| 2844 | * |
| 2845 | |
| 2846 | * @param icon |
| 2847 | * A resource ID in the application's package of the drawable to use. |
| 2848 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2849 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2850 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2851 | return setSmallIcon(icon != 0 |
| 2852 | ? Icon.createWithResource(mContext, icon) |
| 2853 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2854 | } |
| 2855 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2856 | /** |
| 2857 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 2858 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 2859 | * LevelListDrawable}. |
| 2860 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2861 | * @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] | 2862 | * @param level The level to use for the icon. |
| 2863 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2864 | * @see Notification#icon |
| 2865 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2866 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2867 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2868 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2869 | return setSmallIcon(icon); |
| 2870 | } |
| 2871 | |
| 2872 | /** |
| 2873 | * Set the small icon, which will be used to represent the notification in the |
| 2874 | * status bar and content view (unless overriden there by a |
| 2875 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 2876 | * |
| 2877 | * @param icon An Icon object to use. |
| 2878 | * @see Notification#icon |
| 2879 | */ |
| 2880 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2881 | mN.setSmallIcon(icon); |
| 2882 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 2883 | mN.icon = icon.getResId(); |
| 2884 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2885 | return this; |
| 2886 | } |
| 2887 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2888 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2889 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2890 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2891 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2892 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2893 | return this; |
| 2894 | } |
| 2895 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2896 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2897 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2898 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2899 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2900 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2901 | return this; |
| 2902 | } |
| 2903 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2904 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 2905 | * This provides some additional information that is displayed in the notification. No |
| 2906 | * guarantees are given where exactly it is displayed. |
| 2907 | * |
| 2908 | * <p>This information should only be provided if it provides an essential |
| 2909 | * benefit to the understanding of the notification. The more text you provide the |
| 2910 | * less readable it becomes. For example, an email client should only provide the account |
| 2911 | * name here if more than one email account has been added.</p> |
| 2912 | * |
| 2913 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 2914 | * notification header area. |
| 2915 | * |
| 2916 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 2917 | * this will be shown in the third line of text in the platform notification template. |
| 2918 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 2919 | * same time on those versions; they occupy the same place. |
| 2920 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2921 | */ |
| 2922 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2923 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2924 | return this; |
| 2925 | } |
| 2926 | |
| 2927 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2928 | * Provides text that will appear as a link to your application's settings. |
| 2929 | * |
| 2930 | * <p>This text does not appear within notification {@link Style templates} but may |
| 2931 | * appear when the user uses an affordance to learn more about the notification. |
| 2932 | * Additionally, this text will not appear unless you provide a valid link target by |
| 2933 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 2934 | * |
| 2935 | * <p>This text is meant to be concise description about what the user can customize |
| 2936 | * when they click on this link. The recommended maximum length is 40 characters. |
| 2937 | * @param text |
| 2938 | * @return |
| 2939 | */ |
| 2940 | public Builder setSettingsText(CharSequence text) { |
| 2941 | mN.mSettingsText = safeCharSequence(text); |
| 2942 | return this; |
| 2943 | } |
| 2944 | |
| 2945 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 2946 | * Set the remote input history. |
| 2947 | * |
| 2948 | * This should be set to the most recent inputs that have been sent |
| 2949 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 2950 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 2951 | * |
| 2952 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 2953 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 2954 | * and how much of each individual input is shown. |
| 2955 | * |
| 2956 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 2957 | * with a {@code RemoteInput}.</p> |
| 2958 | */ |
| 2959 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 2960 | if (text == null) { |
| 2961 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 2962 | } else { |
| 2963 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 2964 | CharSequence[] safe = new CharSequence[N]; |
| 2965 | for (int i = 0; i < N; i++) { |
| 2966 | safe[i] = safeCharSequence(text[i]); |
| 2967 | } |
| 2968 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 2969 | } |
| 2970 | return this; |
| 2971 | } |
| 2972 | |
| 2973 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2974 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 2975 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2976 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2977 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2978 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2979 | return this; |
| 2980 | } |
| 2981 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2982 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2983 | * A small piece of additional information pertaining to this notification. |
| 2984 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2985 | * The platform template will draw this on the last line of the notification, at the far |
| 2986 | * 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] | 2987 | * |
| 2988 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 2989 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 2990 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2991 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 2992 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2993 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2994 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2995 | return this; |
| 2996 | } |
| 2997 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2998 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2999 | * Set the progress this notification represents. |
| 3000 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3001 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3002 | */ |
| 3003 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3004 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3005 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3006 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3007 | return this; |
| 3008 | } |
| 3009 | |
| 3010 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3011 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3012 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3013 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3014 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3015 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3016 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3017 | return setCustomContentView(views); |
| 3018 | } |
| 3019 | |
| 3020 | /** |
| 3021 | * Supply custom RemoteViews to use instead of the platform template. |
| 3022 | * |
| 3023 | * This will override the layout that would otherwise be constructed by this Builder |
| 3024 | * object. |
| 3025 | */ |
| 3026 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3027 | mN.contentView = contentView; |
| 3028 | return this; |
| 3029 | } |
| 3030 | |
| 3031 | /** |
| 3032 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3033 | * |
| 3034 | * This will override the expanded layout that would otherwise be constructed by this |
| 3035 | * Builder object. |
| 3036 | */ |
| 3037 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3038 | mN.bigContentView = contentView; |
| 3039 | return this; |
| 3040 | } |
| 3041 | |
| 3042 | /** |
| 3043 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3044 | * |
| 3045 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3046 | * Builder object. |
| 3047 | */ |
| 3048 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3049 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3050 | return this; |
| 3051 | } |
| 3052 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3053 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3054 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3055 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3056 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3057 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3058 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3059 | * 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] | 3060 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3061 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3062 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3063 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3064 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3065 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3066 | return this; |
| 3067 | } |
| 3068 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3069 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3070 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3071 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3072 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3073 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3074 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3075 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3076 | return this; |
| 3077 | } |
| 3078 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3079 | /** |
| 3080 | * An intent to launch instead of posting the notification to the status bar. |
| 3081 | * Only for use with extremely high-priority notifications demanding the user's |
| 3082 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3083 | * alarm clock that the user has explicitly set to a particular time. |
| 3084 | * If this facility is used for something else, please give the user an option |
| 3085 | * to turn it off and use a normal notification, as this can be extremely |
| 3086 | * disruptive. |
| 3087 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3088 | * <p> |
| 3089 | * The system UI may choose to display a heads-up notification, instead of |
| 3090 | * launching this intent, while the user is using the device. |
| 3091 | * </p> |
| 3092 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3093 | * @param intent The pending intent to launch. |
| 3094 | * @param highPriority Passing true will cause this notification to be sent |
| 3095 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3096 | * |
| 3097 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3098 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3099 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3100 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3101 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3102 | return this; |
| 3103 | } |
| 3104 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3105 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3106 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3107 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3108 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3109 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3110 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3111 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3112 | return this; |
| 3113 | } |
| 3114 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3115 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3116 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3117 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3118 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3119 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3120 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3121 | setTicker(tickerText); |
| 3122 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3123 | return this; |
| 3124 | } |
| 3125 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3126 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3127 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3128 | * |
| 3129 | * 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] | 3130 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3131 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3132 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3133 | public Builder setLargeIcon(Bitmap b) { |
| 3134 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3135 | } |
| 3136 | |
| 3137 | /** |
| 3138 | * Add a large icon to the notification content view. |
| 3139 | * |
| 3140 | * In the platform template, this image will be shown on the left of the notification view |
| 3141 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3142 | * badge atop the large icon). |
| 3143 | */ |
| 3144 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3145 | mN.mLargeIcon = icon; |
| 3146 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3147 | return this; |
| 3148 | } |
| 3149 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3150 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3151 | * Set the sound to play. |
| 3152 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3153 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 3154 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3155 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3156 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3157 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3158 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3159 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3160 | mN.sound = sound; |
| 3161 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3162 | return this; |
| 3163 | } |
| 3164 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3165 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3166 | * 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] | 3167 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3168 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 3169 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3170 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3171 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 3172 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3173 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 3174 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3175 | mN.sound = sound; |
| 3176 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3177 | return this; |
| 3178 | } |
| 3179 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3180 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3181 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 3182 | * use during playback. |
| 3183 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3184 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3185 | * @see Notification#sound |
| 3186 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3187 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3188 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3189 | mN.sound = sound; |
| 3190 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3191 | return this; |
| 3192 | } |
| 3193 | |
| 3194 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3195 | * Set the vibration pattern to use. |
| 3196 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3197 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 3198 | * <code>pattern</code> parameter. |
| 3199 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3200 | * <p> |
| 3201 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 3202 | * </p> |
| 3203 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3204 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3205 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3206 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3207 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3208 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3209 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3210 | return this; |
| 3211 | } |
| 3212 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3213 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3214 | * Set the desired color for the indicator LED on the device, as well as the |
| 3215 | * blink duty cycle (specified in milliseconds). |
| 3216 | * |
| 3217 | |
| 3218 | * Not all devices will honor all (or even any) of these values. |
| 3219 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3220 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3221 | * @see Notification#ledARGB |
| 3222 | * @see Notification#ledOnMS |
| 3223 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3224 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3225 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3226 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3227 | mN.ledARGB = argb; |
| 3228 | mN.ledOnMS = onMs; |
| 3229 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3230 | if (onMs != 0 || offMs != 0) { |
| 3231 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 3232 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3233 | return this; |
| 3234 | } |
| 3235 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3236 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3237 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3238 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3239 | |
| 3240 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 3241 | * must take care of canceling them. |
| 3242 | * |
| 3243 | |
| 3244 | * They are typically used to indicate a background task that the user is actively engaged |
| 3245 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 3246 | * (e.g., a file download, sync operation, active network connection). |
| 3247 | * |
| 3248 | |
| 3249 | * @see Notification#FLAG_ONGOING_EVENT |
| 3250 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3251 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3252 | public Builder setOngoing(boolean ongoing) { |
| 3253 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 3254 | return this; |
| 3255 | } |
| 3256 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3257 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3258 | * Set whether this notification should be colorized. When set, the color set with |
| 3259 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 3260 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3261 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 3262 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3263 | * <p> |
| 3264 | * For most styles, the coloring will only be applied if the notification is ongoing. |
| 3265 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
| 3266 | * that have a media session attached there is no requirement for it to be ongoing. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3267 | * |
| 3268 | * @see Builder#setOngoing(boolean) |
| 3269 | * @see Builder#setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3270 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3271 | */ |
| 3272 | public Builder setColorized(boolean colorize) { |
| 3273 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 3274 | return this; |
| 3275 | } |
| 3276 | |
| 3277 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3278 | * Set this flag if you would only like the sound, vibrate |
| 3279 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3280 | * |
| 3281 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3282 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3283 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 3284 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 3285 | return this; |
| 3286 | } |
| 3287 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3288 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 3289 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3290 | * |
| 3291 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3292 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3293 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 3294 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3295 | return this; |
| 3296 | } |
| 3297 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3298 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3299 | * Set whether or not this notification should not bridge to other devices. |
| 3300 | * |
| 3301 | * <p>Some notifications can be bridged to other devices for remote display. |
| 3302 | * This hint can be set to recommend this notification not be bridged. |
| 3303 | */ |
| 3304 | public Builder setLocalOnly(boolean localOnly) { |
| 3305 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 3306 | return this; |
| 3307 | } |
| 3308 | |
| 3309 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3310 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3311 | * <p> |
| 3312 | * The value should be one or more of the following fields combined with |
| 3313 | * bitwise-or: |
| 3314 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 3315 | * <p> |
| 3316 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3317 | * |
| 3318 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3319 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3320 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3321 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3322 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3323 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3324 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3325 | return this; |
| 3326 | } |
| 3327 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3328 | /** |
| 3329 | * Set the priority of this notification. |
| 3330 | * |
| 3331 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3332 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3333 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3334 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3335 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3336 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3337 | return this; |
| 3338 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3339 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3340 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3341 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3342 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3343 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3344 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3345 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3346 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3347 | return this; |
| 3348 | } |
| 3349 | |
| 3350 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3351 | * Add a person that is relevant to this notification. |
| 3352 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3353 | * <P> |
| 3354 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3355 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 3356 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 3357 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3358 | * </P> |
| 3359 | * |
| 3360 | * <P> |
| 3361 | * The person should be specified by the {@code String} representation of a |
| 3362 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 3363 | * </P> |
| 3364 | * |
| 3365 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 3366 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 3367 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 3368 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
| 3369 | * </P> |
| 3370 | * |
| 3371 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3372 | * @see Notification#EXTRA_PEOPLE |
| 3373 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3374 | public Builder addPerson(String uri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3375 | mPersonList.add(uri); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3376 | return this; |
| 3377 | } |
| 3378 | |
| 3379 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3380 | * Set this notification to be part of a group of notifications sharing the same key. |
| 3381 | * Grouped notifications may display in a cluster or stack on devices which |
| 3382 | * support such rendering. |
| 3383 | * |
| 3384 | * <p>To make this notification the summary for its group, also call |
| 3385 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 3386 | * {@link #setSortKey}. |
| 3387 | * @param groupKey The group key of the group. |
| 3388 | * @return this object for method chaining |
| 3389 | */ |
| 3390 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3391 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3392 | return this; |
| 3393 | } |
| 3394 | |
| 3395 | /** |
| 3396 | * Set this notification to be the group summary for a group of notifications. |
| 3397 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 3398 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 3399 | * 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] | 3400 | * @param isGroupSummary Whether this notification should be a group summary. |
| 3401 | * @return this object for method chaining |
| 3402 | */ |
| 3403 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 3404 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 3405 | return this; |
| 3406 | } |
| 3407 | |
| 3408 | /** |
| 3409 | * Set a sort key that orders this notification among other notifications from the |
| 3410 | * same package. This can be useful if an external sort was already applied and an app |
| 3411 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 3412 | * value, although providing different priorities in addition to providing sort key may |
| 3413 | * cause this value to be ignored. |
| 3414 | * |
| 3415 | * <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] | 3416 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3417 | * |
| 3418 | * @see String#compareTo(String) |
| 3419 | */ |
| 3420 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3421 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3422 | return this; |
| 3423 | } |
| 3424 | |
| 3425 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3426 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3427 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3428 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 3429 | * |
| 3430 | * @see Notification#extras |
| 3431 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3432 | public Builder addExtras(Bundle extras) { |
| 3433 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3434 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3435 | } |
| 3436 | return this; |
| 3437 | } |
| 3438 | |
| 3439 | /** |
| 3440 | * Set metadata for this notification. |
| 3441 | * |
| 3442 | * <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] | 3443 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3444 | * called. |
| 3445 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3446 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 3447 | * Use {@link #addExtras} to merge in metadata instead. |
| 3448 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3449 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3450 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3451 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3452 | if (extras != null) { |
| 3453 | mUserExtras = extras; |
| 3454 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3455 | return this; |
| 3456 | } |
| 3457 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3458 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3459 | * Get the current metadata Bundle used by this notification Builder. |
| 3460 | * |
| 3461 | * <p>The returned Bundle is shared with this Builder. |
| 3462 | * |
| 3463 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 3464 | * {@link #build()} is called. |
| 3465 | * |
| 3466 | * @see Notification#extras |
| 3467 | */ |
| 3468 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3469 | return mUserExtras; |
| 3470 | } |
| 3471 | |
| 3472 | private Bundle getAllExtras() { |
| 3473 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 3474 | saveExtras.putAll(mN.extras); |
| 3475 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3479 | * Add an action to this notification. Actions are typically displayed by |
| 3480 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3481 | * <p> |
| 3482 | * Every action must have an icon (32dp square and matching the |
| 3483 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 3484 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 3485 | * <p> |
| 3486 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 3487 | * the order they were added. Actions will not be displayed when the notification is |
| 3488 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 3489 | * 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] | 3490 | * |
| 3491 | * @param icon Resource ID of a drawable that represents the action. |
| 3492 | * @param title Text describing the action. |
| 3493 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 3494 | * |
| 3495 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3496 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 3497 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3498 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3499 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3500 | return this; |
| 3501 | } |
| 3502 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3503 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3504 | * Add an action to this notification. Actions are typically displayed by |
| 3505 | * the system as a button adjacent to the notification content. |
| 3506 | * <p> |
| 3507 | * Every action must have an icon (32dp square and matching the |
| 3508 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 3509 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 3510 | * <p> |
| 3511 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 3512 | * the order they were added. Actions will not be displayed when the notification is |
| 3513 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 3514 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 3515 | * |
| 3516 | * @param action The action to add. |
| 3517 | */ |
| 3518 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 3519 | if (action != null) { |
| 3520 | mActions.add(action); |
| 3521 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3522 | return this; |
| 3523 | } |
| 3524 | |
| 3525 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3526 | * Alter the complete list of actions attached to this notification. |
| 3527 | * @see #addAction(Action). |
| 3528 | * |
| 3529 | * @param actions |
| 3530 | * @return |
| 3531 | */ |
| 3532 | public Builder setActions(Action... actions) { |
| 3533 | mActions.clear(); |
| 3534 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 3535 | if (actions[i] != null) { |
| 3536 | mActions.add(actions[i]); |
| 3537 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3538 | } |
| 3539 | return this; |
| 3540 | } |
| 3541 | |
| 3542 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3543 | * Add a rich notification style to be applied at build time. |
| 3544 | * |
| 3545 | * @param style Object responsible for modifying the notification style. |
| 3546 | */ |
| 3547 | public Builder setStyle(Style style) { |
| 3548 | if (mStyle != style) { |
| 3549 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3550 | if (mStyle != null) { |
| 3551 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3552 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 3553 | } else { |
| 3554 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3555 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3556 | } |
| 3557 | return this; |
| 3558 | } |
| 3559 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3560 | /** |
| 3561 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 3562 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3563 | * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default), |
| 3564 | * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}. |
| 3565 | * |
| 3566 | * @return The same Builder. |
| 3567 | */ |
| 3568 | public Builder setVisibility(int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3569 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3570 | return this; |
| 3571 | } |
| 3572 | |
| 3573 | /** |
| 3574 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 3575 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 3576 | * @param n A replacement notification, presumably with some or all info redacted. |
| 3577 | * @return The same Builder. |
| 3578 | */ |
| 3579 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3580 | if (n != null) { |
| 3581 | mN.publicVersion = new Notification(); |
| 3582 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 3583 | } else { |
| 3584 | mN.publicVersion = null; |
| 3585 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3586 | return this; |
| 3587 | } |
| 3588 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 3589 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3590 | * Apply an extender to this notification builder. Extenders may be used to add |
| 3591 | * metadata or change options on this builder. |
| 3592 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 3593 | public Builder extend(Extender extender) { |
| 3594 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3595 | return this; |
| 3596 | } |
| 3597 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 3598 | /** |
| 3599 | * @hide |
| 3600 | */ |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 3601 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3602 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3603 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3604 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3605 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3606 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 3607 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3608 | } |
| 3609 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3610 | /** |
| 3611 | * Sets {@link Notification#color}. |
| 3612 | * |
| 3613 | * @param argb The accent color to use |
| 3614 | * |
| 3615 | * @return The same Builder. |
| 3616 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3617 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3618 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3619 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3620 | return this; |
| 3621 | } |
| 3622 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3623 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 3624 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 3625 | // This user can never be a badged profile, |
| 3626 | // and also includes USER_ALL system notifications. |
| 3627 | return null; |
| 3628 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3629 | // Note: This assumes that the current user can read the profile badge of the |
| 3630 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 3631 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 3632 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | private Bitmap getProfileBadge() { |
| 3636 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3637 | if (badge == null) { |
| 3638 | return null; |
| 3639 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3640 | final int size = mContext.getResources().getDimensionPixelSize( |
| 3641 | R.dimen.notification_badge_size); |
| 3642 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3643 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3644 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3645 | badge.draw(canvas); |
| 3646 | return bitmap; |
| 3647 | } |
| 3648 | |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3649 | private void bindProfileBadge(RemoteViews contentView) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3650 | Bitmap profileBadge = getProfileBadge(); |
| 3651 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3652 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3653 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 3654 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3655 | if (isColorized()) { |
| 3656 | contentView.setDrawableParameters(R.id.profile_badge, false, -1, |
| 3657 | getPrimaryTextColor(), PorterDuff.Mode.SRC_ATOP, -1); |
| 3658 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3659 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3660 | } |
| 3661 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3662 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3663 | resetNotificationHeader(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3664 | resetContentMargins(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3665 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3666 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3667 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3668 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3669 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3670 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3671 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3672 | } |
| 3673 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3674 | /** |
| 3675 | * Resets the notification header to its original state |
| 3676 | */ |
| 3677 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 3678 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 3679 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 3680 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3681 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 3682 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3683 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 3684 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3685 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3686 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 3687 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3688 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 3689 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | private void resetContentMargins(RemoteViews contentView) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 3693 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 3694 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3695 | } |
| 3696 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3697 | private RemoteViews applyStandardTemplate(int resId) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3698 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this)); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | /** |
| 3702 | * @param hasProgress whether the progress bar should be shown and set |
| 3703 | */ |
| 3704 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3705 | return applyStandardTemplate(resId, mParams.reset().hasProgress(hasProgress) |
| 3706 | .fillTextsFrom(this)); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3709 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3710 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 3711 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3712 | resetStandardTemplate(contentView); |
| 3713 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3714 | final Bundle ex = mN.extras; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3715 | updateBackgroundColor(contentView); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3716 | bindNotificationHeader(contentView, p.ambient); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3717 | bindLargeIcon(contentView); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3718 | boolean showProgress = handleProgressBar(p.hasProgress, contentView, ex); |
| 3719 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3720 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3721 | contentView.setTextViewText(R.id.title, p.title); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 3722 | if (!p.ambient) { |
| 3723 | setTextViewColorPrimary(contentView, R.id.title); |
| 3724 | } |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 3725 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 3726 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 3727 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3728 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3729 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3730 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 3731 | : com.android.internal.R.id.text; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3732 | contentView.setTextViewText(textId, p.text); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 3733 | if (!p.ambient) { |
| 3734 | setTextViewColorSecondary(contentView, textId); |
| 3735 | } |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3736 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3737 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3738 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 3739 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3740 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3741 | return contentView; |
| 3742 | } |
| 3743 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3744 | private void setTextViewColorPrimary(RemoteViews contentView, int id) { |
| 3745 | ensureColors(); |
| 3746 | contentView.setTextColor(id, mPrimaryTextColor); |
| 3747 | } |
| 3748 | |
| 3749 | private int getPrimaryTextColor() { |
| 3750 | ensureColors(); |
| 3751 | return mPrimaryTextColor; |
| 3752 | } |
| 3753 | |
| 3754 | private int getActionBarColor() { |
| 3755 | ensureColors(); |
| 3756 | return mActionBarColor; |
| 3757 | } |
| 3758 | |
| 3759 | private void setTextViewColorSecondary(RemoteViews contentView, int id) { |
| 3760 | ensureColors(); |
| 3761 | contentView.setTextColor(id, mSecondaryTextColor); |
| 3762 | } |
| 3763 | |
| 3764 | private void ensureColors() { |
| 3765 | int backgroundColor = getBackgroundColor(); |
| 3766 | if (mPrimaryTextColor == COLOR_INVALID |
| 3767 | || mSecondaryTextColor == COLOR_INVALID |
| 3768 | || mActionBarColor == COLOR_INVALID |
| 3769 | || mTextColorsAreForBackground != backgroundColor) { |
| 3770 | mTextColorsAreForBackground = backgroundColor; |
| 3771 | mPrimaryTextColor = NotificationColorUtil.resolvePrimaryColor( |
| 3772 | mContext, backgroundColor); |
| 3773 | mSecondaryTextColor = NotificationColorUtil.resolveSecondaryColor( |
| 3774 | mContext, backgroundColor); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 3775 | mActionBarColor = NotificationColorUtil.resolveActionBarColor(mContext, |
| 3776 | backgroundColor); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | private void updateBackgroundColor(RemoteViews contentView) { |
| 3781 | if (isColorized()) { |
| 3782 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
| 3783 | getBackgroundColor()); |
| 3784 | } else { |
| 3785 | // Clear it! |
| 3786 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 3787 | 0); |
| 3788 | } |
| 3789 | } |
| 3790 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3791 | /** |
| 3792 | * @param remoteView the remote view to update the minheight in |
| 3793 | * @param hasMinHeight does it have a mimHeight |
| 3794 | * @hide |
| 3795 | */ |
| 3796 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 3797 | int minHeight = 0; |
| 3798 | if (hasMinHeight) { |
| 3799 | // we need to set the minHeight of the notification |
| 3800 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 3801 | com.android.internal.R.dimen.notification_min_content_height); |
| 3802 | } |
| 3803 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 3804 | } |
| 3805 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3806 | private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3807 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 3808 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 3809 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 3810 | if (hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3811 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3812 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3813 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3814 | contentView.setProgressBackgroundTintList( |
| 3815 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 3816 | R.color.notification_progress_background_color))); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3817 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3818 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3819 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 3820 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3821 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3822 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3823 | } else { |
| 3824 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3825 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3826 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3827 | } |
| 3828 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3829 | private void bindLargeIcon(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 3830 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 3831 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 3832 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3833 | if (mN.mLargeIcon != null) { |
| 3834 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 3835 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
| 3836 | processLargeLegacyIcon(mN.mLargeIcon, contentView); |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 3837 | int endMargin = R.dimen.notification_content_picture_margin; |
| 3838 | contentView.setViewLayoutMarginEndDimen(R.id.line1, endMargin); |
| 3839 | contentView.setViewLayoutMarginEndDimen(R.id.text, endMargin); |
| 3840 | contentView.setViewLayoutMarginEndDimen(R.id.progress, endMargin); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3841 | } |
| 3842 | } |
| 3843 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3844 | private void bindNotificationHeader(RemoteViews contentView, boolean ambient) { |
| 3845 | bindSmallIcon(contentView, ambient); |
| 3846 | bindHeaderAppName(contentView, ambient); |
| 3847 | if (!ambient) { |
| 3848 | // Ambient view does not have these |
| 3849 | bindHeaderText(contentView); |
| 3850 | bindHeaderChronometerAndTime(contentView); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3851 | bindProfileBadge(contentView); |
| 3852 | } |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 3853 | bindExpandButton(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3854 | } |
| 3855 | |
| 3856 | private void bindExpandButton(RemoteViews contentView) { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3857 | int color = getPrimaryHighlightColor(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3858 | contentView.setDrawableParameters(R.id.expand_button, false, -1, color, |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3859 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 3860 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3861 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3862 | } |
| 3863 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3864 | /** |
| 3865 | * @return the color that is used as the first primary highlight color. This is applied |
| 3866 | * in several places like the action buttons or the app name in the header. |
| 3867 | */ |
| 3868 | private int getPrimaryHighlightColor() { |
| 3869 | return isColorized() ? getPrimaryTextColor() : resolveContrastColor(); |
| 3870 | } |
| 3871 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3872 | private void bindHeaderChronometerAndTime(RemoteViews contentView) { |
| 3873 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3874 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3875 | setTextViewColorSecondary(contentView, R.id.time_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3876 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 3877 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 3878 | contentView.setLong(R.id.chronometer, "setBase", |
| 3879 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 3880 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 3881 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 3882 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3883 | setTextViewColorSecondary(contentView, R.id.chronometer); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3884 | } else { |
| 3885 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 3886 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3887 | setTextViewColorSecondary(contentView, R.id.time); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3888 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 3889 | } else { |
| 3890 | // We still want a time to be set but gone, such that we can show and hide it |
| 3891 | // on demand in case it's a child notification without anything in the header |
| 3892 | 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] | 3893 | } |
| 3894 | } |
| 3895 | |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3896 | private void bindHeaderText(RemoteViews contentView) { |
| 3897 | CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 3898 | if (headerText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3899 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3900 | headerText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 3901 | } |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3902 | if (headerText == null |
| 3903 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 3904 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 3905 | headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 3906 | } |
| 3907 | if (headerText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3908 | // TODO: Remove the span entirely to only have the string with propper formating. |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3909 | contentView.setTextViewText(R.id.header_text, processLegacyText(headerText)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3910 | setTextViewColorSecondary(contentView, R.id.header_text); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3911 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 3912 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3913 | setTextViewColorSecondary(contentView, R.id.header_text_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3914 | } |
| 3915 | } |
| 3916 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 3917 | /** |
| 3918 | * @hide |
| 3919 | */ |
| 3920 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 3921 | CharSequence name = null; |
| 3922 | final PackageManager pm = mContext.getPackageManager(); |
| 3923 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 3924 | // only system packages which lump together a bunch of unrelated stuff |
| 3925 | // may substitute a different name to make the purpose of the |
| 3926 | // notification more clear. the correct package label should always |
| 3927 | // be accessible via SystemUI. |
| 3928 | final String pkg = mContext.getPackageName(); |
| 3929 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 3930 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 3931 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 3932 | name = subName; |
| 3933 | } else { |
| 3934 | Log.w(TAG, "warning: pkg " |
| 3935 | + pkg + " attempting to substitute app name '" + subName |
| 3936 | + "' without holding perm " |
| 3937 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 3938 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3939 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 3940 | if (TextUtils.isEmpty(name)) { |
| 3941 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 3942 | } |
| 3943 | if (TextUtils.isEmpty(name)) { |
| 3944 | // still nothing? |
| 3945 | return null; |
| 3946 | } |
| 3947 | |
| 3948 | return String.valueOf(name); |
| 3949 | } |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3950 | private void bindHeaderAppName(RemoteViews contentView, boolean ambient) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 3951 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 3952 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3953 | setTextViewColorPrimary(contentView, R.id.app_name_text); |
| 3954 | } else { |
| 3955 | contentView.setTextColor(R.id.app_name_text, |
| 3956 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
| 3957 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3958 | } |
| 3959 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3960 | private void bindSmallIcon(RemoteViews contentView, boolean ambient) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 3961 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 3962 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 3963 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3964 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Adrian Roos | 9b45a15 | 2016-06-28 13:32:29 -0700 | [diff] [blame] | 3965 | contentView.setDrawableParameters(R.id.icon, false /* targetBackground */, |
| 3966 | -1 /* alpha */, -1 /* colorFilter */, null /* mode */, mN.iconLevel); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3967 | processSmallIconColor(mN.mSmallIcon, contentView, ambient); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3968 | } |
| 3969 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3970 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3971 | * @return true if the built notification will show the time or the chronometer; false |
| 3972 | * otherwise |
| 3973 | */ |
| 3974 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 3975 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3976 | } |
| 3977 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3978 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 3979 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 3980 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3981 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3982 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3983 | |
| 3984 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 3985 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
| 3986 | |
| 3987 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 3988 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 3989 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 3990 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 3991 | |
| 3992 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3993 | } |
| 3994 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3995 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3996 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this)); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 3997 | } |
| 3998 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3999 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 4000 | StandardTemplateParams p) { |
| 4001 | RemoteViews big = applyStandardTemplate(layoutId, p); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4002 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4003 | resetStandardTemplateWithActions(big); |
| 4004 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4005 | boolean validRemoteInput = false; |
| 4006 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4007 | int N = mActions.size(); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4008 | boolean emphazisedMode = mN.fullScreenIntent != null && !p.ambient; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4009 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4010 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 4011 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4012 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4013 | if (p.ambient) { |
| 4014 | big.setInt(R.id.actions, "setBackgroundColor", Color.TRANSPARENT); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4015 | } else if (isColorized()) { |
| 4016 | big.setInt(R.id.actions, "setBackgroundColor", getActionBarColor()); |
| 4017 | } else { |
| 4018 | big.setInt(R.id.actions, "setBackgroundColor", mContext.getColor( |
| 4019 | R.color.notification_action_list)); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4020 | } |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 4021 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 4022 | R.dimen.notification_action_list_height); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4023 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4024 | for (int i=0; i<N; i++) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4025 | Action action = mActions.get(i); |
| 4026 | validRemoteInput |= hasValidRemoteInput(action); |
| 4027 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4028 | final RemoteViews button = generateActionButton(action, emphazisedMode, |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4029 | i % 2 != 0, p.ambient); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4030 | big.addView(R.id.actions, button); |
| 4031 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4032 | } else { |
| 4033 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4034 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4035 | |
| 4036 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4037 | if (!p.ambient && validRemoteInput && replyText != null |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4038 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) { |
| 4039 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
| 4040 | big.setTextViewText(R.id.notification_material_reply_text_1, replyText[0]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4041 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4042 | |
| 4043 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) { |
| 4044 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
| 4045 | big.setTextViewText(R.id.notification_material_reply_text_2, replyText[1]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4046 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4047 | |
| 4048 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) { |
| 4049 | big.setViewVisibility( |
| 4050 | R.id.notification_material_reply_text_3, View.VISIBLE); |
| 4051 | big.setTextViewText(R.id.notification_material_reply_text_3, replyText[2]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4052 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4053 | } |
| 4054 | } |
| 4055 | } |
| 4056 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4057 | return big; |
| 4058 | } |
| 4059 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4060 | private boolean hasValidRemoteInput(Action action) { |
| 4061 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 4062 | // Weird actions |
| 4063 | return false; |
| 4064 | } |
| 4065 | |
| 4066 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 4067 | if (remoteInputs == null) { |
| 4068 | return false; |
| 4069 | } |
| 4070 | |
| 4071 | for (RemoteInput r : remoteInputs) { |
| 4072 | CharSequence[] choices = r.getChoices(); |
| 4073 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 4074 | return true; |
| 4075 | } |
| 4076 | } |
| 4077 | return false; |
| 4078 | } |
| 4079 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4080 | /** |
| 4081 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 4082 | * 1. Custom contentView from the caller |
| 4083 | * 2. Style's proposed content view |
| 4084 | * 3. Standard template view |
| 4085 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4086 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4087 | return createContentView(false /* increasedheight */ ); |
| 4088 | } |
| 4089 | |
| 4090 | /** |
| 4091 | * Construct a RemoteViews for the smaller content view. |
| 4092 | * |
| 4093 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 4094 | * styles may support showing more then just that basic 1U size |
| 4095 | * and the system may decide to render important notifications |
| 4096 | * slightly bigger even when collapsed. |
| 4097 | * |
| 4098 | * @hide |
| 4099 | */ |
| 4100 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4101 | if (mN.contentView != null && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4102 | return mN.contentView; |
| 4103 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4104 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4105 | if (styleView != null) { |
| 4106 | return styleView; |
| 4107 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4108 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4109 | return applyStandardTemplate(getBaseLayoutResource()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4110 | } |
| 4111 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4112 | /** |
| 4113 | * Construct a RemoteViews for the final big notification layout. |
| 4114 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4115 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4116 | RemoteViews result = null; |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4117 | if (mN.bigContentView != null |
| 4118 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4119 | return mN.bigContentView; |
| 4120 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4121 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 4122 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4123 | } else if (mActions.size() != 0) { |
| 4124 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4125 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4126 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4127 | return result; |
| 4128 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4129 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4130 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4131 | * Construct a RemoteViews for the final notification header only. This will not be |
| 4132 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4133 | * |
| 4134 | * @hide |
| 4135 | */ |
| 4136 | public RemoteViews makeNotificationHeader() { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4137 | Boolean colorized = (Boolean) mN.extras.get(EXTRA_COLORIZED); |
| 4138 | mN.extras.putBoolean(EXTRA_COLORIZED, false); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4139 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
| 4140 | R.layout.notification_template_header); |
| 4141 | resetNotificationHeader(header); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4142 | bindNotificationHeader(header, false /* ambient */); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4143 | if (colorized != null) { |
| 4144 | mN.extras.putBoolean(EXTRA_COLORIZED, colorized); |
| 4145 | } else { |
| 4146 | mN.extras.remove(EXTRA_COLORIZED); |
| 4147 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4148 | return header; |
| 4149 | } |
| 4150 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4151 | /** |
| 4152 | * Construct a RemoteViews for the ambient version of the notification. |
| 4153 | * |
| 4154 | * @hide |
| 4155 | */ |
| 4156 | public RemoteViews makeAmbientNotification() { |
| 4157 | RemoteViews ambient = applyStandardTemplateWithActions( |
| 4158 | R.layout.notification_template_material_ambient, |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 4159 | mParams.reset().ambient(true).fillTextsFrom(this).hasProgress(false)); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4160 | return ambient; |
| 4161 | } |
| 4162 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4163 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4164 | if (result != null) { |
| 4165 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 4166 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4167 | } |
| 4168 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4169 | /** |
| 4170 | * Adapt the Notification header if this view is used as an expanded view. |
| 4171 | * |
| 4172 | * @hide |
| 4173 | */ |
| 4174 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4175 | if (result != null) { |
| 4176 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 4177 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4178 | } |
| 4179 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4180 | /** |
| 4181 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4182 | * |
| 4183 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 4184 | * styles may support showing more then just that basic 1U size |
| 4185 | * and the system may decide to render important notifications |
| 4186 | * slightly bigger even when collapsed. |
| 4187 | * |
| 4188 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4189 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4190 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 4191 | if (mN.headsUpContentView != null |
| 4192 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4193 | return mN.headsUpContentView; |
| 4194 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4195 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 4196 | if (styleView != null) { |
| 4197 | return styleView; |
| 4198 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4199 | } else if (mActions.size() == 0) { |
| 4200 | return null; |
| 4201 | } |
| 4202 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4203 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 4204 | } |
| 4205 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4206 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4207 | * Construct a RemoteViews for the final heads-up notification layout. |
| 4208 | */ |
| 4209 | public RemoteViews createHeadsUpContentView() { |
| 4210 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 4211 | } |
| 4212 | |
| 4213 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4214 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 4215 | * |
| 4216 | * @hide |
| 4217 | */ |
| 4218 | public RemoteViews makePublicContentView() { |
| 4219 | if (mN.publicVersion != null) { |
| 4220 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4221 | return builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4222 | } |
| 4223 | Bundle savedBundle = mN.extras; |
| 4224 | Style style = mStyle; |
| 4225 | mStyle = null; |
| 4226 | Icon largeIcon = mN.mLargeIcon; |
| 4227 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4228 | Bitmap largeIconLegacy = mN.largeIcon; |
| 4229 | mN.largeIcon = null; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4230 | Bundle publicExtras = new Bundle(); |
| 4231 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 4232 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 4233 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 4234 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4235 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 4236 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4237 | publicExtras.putCharSequence(EXTRA_TITLE, |
| 4238 | mContext.getString(R.string.notification_hidden_text)); |
| 4239 | mN.extras = publicExtras; |
| 4240 | final RemoteViews publicView = applyStandardTemplate(getBaseLayoutResource()); |
| 4241 | mN.extras = savedBundle; |
| 4242 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4243 | mN.largeIcon = largeIconLegacy; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4244 | mStyle = style; |
| 4245 | return publicView; |
| 4246 | } |
| 4247 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4248 | /** |
| 4249 | * Construct a content view for the display when low - priority |
| 4250 | * |
| 4251 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 4252 | * a new subtext is created consisting of the content of the |
| 4253 | * notification. |
| 4254 | * @hide |
| 4255 | */ |
| 4256 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
| 4257 | int color = mN.color; |
| 4258 | mN.color = COLOR_DEFAULT; |
| 4259 | CharSequence summary = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 4260 | if (!useRegularSubtext || TextUtils.isEmpty(summary)) { |
| 4261 | CharSequence newSummary = createSummaryText(); |
| 4262 | if (!TextUtils.isEmpty(newSummary)) { |
| 4263 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, newSummary); |
| 4264 | } |
| 4265 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 4266 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4267 | RemoteViews header = makeNotificationHeader(); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 4268 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4269 | if (summary != null) { |
| 4270 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, summary); |
| 4271 | } else { |
| 4272 | mN.extras.remove(EXTRA_SUB_TEXT); |
| 4273 | } |
| 4274 | mN.color = color; |
| 4275 | return header; |
| 4276 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4277 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4278 | private CharSequence createSummaryText() { |
| 4279 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 4280 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 4281 | return titleText; |
| 4282 | } |
| 4283 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 4284 | if (titleText == null) { |
| 4285 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 4286 | } |
| 4287 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 4288 | if (titleText != null) { |
| 4289 | summary.append(bidi.unicodeWrap(titleText)); |
| 4290 | } |
| 4291 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 4292 | if (titleText != null && contentText != null) { |
| 4293 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 4294 | R.string.notification_header_divider_symbol_with_spaces))); |
| 4295 | } |
| 4296 | if (contentText != null) { |
| 4297 | summary.append(bidi.unicodeWrap(contentText)); |
| 4298 | } |
| 4299 | return summary; |
| 4300 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 4301 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4302 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4303 | boolean oddAction, boolean ambient) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4304 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 4305 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4306 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 4307 | : tombstone ? getActionTombstoneLayoutResource() |
| 4308 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4309 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 4310 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 4311 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4312 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 4313 | if (action.mRemoteInputs != null) { |
| 4314 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 4315 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4316 | // TODO: handle emphasized mode / actions right |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4317 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4318 | // change the background bgColor |
| 4319 | int bgColor = mContext.getColor(oddAction ? R.color.notification_action_list |
| 4320 | : R.color.notification_action_list_dark); |
| 4321 | button.setDrawableParameters(R.id.button_holder, true, -1, bgColor, |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4322 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4323 | CharSequence title = action.title; |
| 4324 | ColorStateList[] outResultColor = null; |
| 4325 | if (isLegacy()) { |
| 4326 | title = clearColorSpans(title); |
| 4327 | } else { |
| 4328 | outResultColor = new ColorStateList[1]; |
| 4329 | title = ensureColorSpanContrast(title, bgColor, outResultColor); |
| 4330 | } |
| 4331 | button.setTextViewText(R.id.action0, title); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4332 | setTextViewColorPrimary(button, R.id.action0); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4333 | if (outResultColor != null && outResultColor[0] != null) { |
| 4334 | // We need to set the text color as well since changing a text to uppercase |
| 4335 | // clears its spans. |
| 4336 | button.setTextColor(R.id.action0, outResultColor[0]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4337 | } else if (mN.color != COLOR_DEFAULT && !isColorized()) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4338 | button.setTextColor(R.id.action0,resolveContrastColor()); |
| 4339 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4340 | } else { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4341 | button.setTextViewText(R.id.action0, processLegacyText(action.title)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4342 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4343 | setTextViewColorPrimary(button, R.id.action0); |
| 4344 | } else if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4345 | button.setTextColor(R.id.action0, |
| 4346 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4347 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 4348 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4349 | return button; |
| 4350 | } |
| 4351 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4352 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4353 | * Clears all color spans of a text |
| 4354 | * @param charSequence the input text |
| 4355 | * @return the same text but without color spans |
| 4356 | */ |
| 4357 | private CharSequence clearColorSpans(CharSequence charSequence) { |
| 4358 | if (charSequence instanceof Spanned) { |
| 4359 | Spanned ss = (Spanned) charSequence; |
| 4360 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 4361 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 4362 | for (Object span : spans) { |
| 4363 | Object resultSpan = span; |
| 4364 | if (resultSpan instanceof CharacterStyle) { |
| 4365 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 4366 | } |
| 4367 | if (resultSpan instanceof TextAppearanceSpan) { |
| 4368 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 4369 | if (originalSpan.getTextColor() != null) { |
| 4370 | resultSpan = new TextAppearanceSpan( |
| 4371 | originalSpan.getFamily(), |
| 4372 | originalSpan.getTextStyle(), |
| 4373 | originalSpan.getTextSize(), |
| 4374 | null, |
| 4375 | originalSpan.getLinkTextColor()); |
| 4376 | } |
| 4377 | } else if (resultSpan instanceof ForegroundColorSpan |
| 4378 | || (resultSpan instanceof BackgroundColorSpan)) { |
| 4379 | continue; |
| 4380 | } else { |
| 4381 | resultSpan = span; |
| 4382 | } |
| 4383 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 4384 | ss.getSpanFlags(span)); |
| 4385 | } |
| 4386 | return builder; |
| 4387 | } |
| 4388 | return charSequence; |
| 4389 | } |
| 4390 | |
| 4391 | /** |
| 4392 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 4393 | * text if a span was found that spans over the whole text. |
| 4394 | * |
| 4395 | * @param charSequence the charSequence on which the spans are |
| 4396 | * @param background the background color to ensure the contrast against |
| 4397 | * @param outResultColor an array in which a color will be returned as the first element if |
| 4398 | * there exists a full length color span. |
| 4399 | * @return the contrasted charSequence |
| 4400 | */ |
| 4401 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 4402 | ColorStateList[] outResultColor) { |
| 4403 | if (charSequence instanceof Spanned) { |
| 4404 | Spanned ss = (Spanned) charSequence; |
| 4405 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 4406 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 4407 | for (Object span : spans) { |
| 4408 | Object resultSpan = span; |
| 4409 | int spanStart = ss.getSpanStart(span); |
| 4410 | int spanEnd = ss.getSpanEnd(span); |
| 4411 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 4412 | if (resultSpan instanceof CharacterStyle) { |
| 4413 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 4414 | } |
| 4415 | if (resultSpan instanceof TextAppearanceSpan) { |
| 4416 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 4417 | ColorStateList textColor = originalSpan.getTextColor(); |
| 4418 | if (textColor != null) { |
| 4419 | int[] colors = textColor.getColors(); |
| 4420 | int[] newColors = new int[colors.length]; |
| 4421 | for (int i = 0; i < newColors.length; i++) { |
| 4422 | newColors[i] = NotificationColorUtil.ensureLargeTextContrast( |
| 4423 | colors[i], background); |
| 4424 | } |
| 4425 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 4426 | newColors); |
| 4427 | resultSpan = new TextAppearanceSpan( |
| 4428 | originalSpan.getFamily(), |
| 4429 | originalSpan.getTextStyle(), |
| 4430 | originalSpan.getTextSize(), |
| 4431 | textColor, |
| 4432 | originalSpan.getLinkTextColor()); |
| 4433 | if (fullLength) { |
| 4434 | outResultColor[0] = new ColorStateList( |
| 4435 | textColor.getStates().clone(), newColors); |
| 4436 | } |
| 4437 | } |
| 4438 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 4439 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 4440 | int foregroundColor = originalSpan.getForegroundColor(); |
| 4441 | foregroundColor = NotificationColorUtil.ensureLargeTextContrast( |
| 4442 | foregroundColor, background); |
| 4443 | resultSpan = new ForegroundColorSpan(foregroundColor); |
| 4444 | if (fullLength) { |
| 4445 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
| 4446 | } |
| 4447 | } else { |
| 4448 | resultSpan = span; |
| 4449 | } |
| 4450 | |
| 4451 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 4452 | } |
| 4453 | return builder; |
| 4454 | } |
| 4455 | return charSequence; |
| 4456 | } |
| 4457 | |
| 4458 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4459 | * @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] | 4460 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4461 | */ |
| 4462 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4463 | if (!mIsLegacyInitialized) { |
| 4464 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 4465 | < Build.VERSION_CODES.LOLLIPOP; |
| 4466 | mIsLegacyInitialized = true; |
| 4467 | } |
| 4468 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4469 | } |
| 4470 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4471 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 4472 | return processLegacyText(charSequence, false /* ambient */); |
| 4473 | } |
| 4474 | |
| 4475 | private CharSequence processLegacyText(CharSequence charSequence, boolean ambient) { |
| 4476 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
| 4477 | boolean wantLightText = ambient; |
| 4478 | if (isAlreadyLightText != wantLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4479 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4480 | } else { |
| 4481 | return charSequence; |
| 4482 | } |
| 4483 | } |
| 4484 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4485 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4486 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4487 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4488 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
| 4489 | boolean ambient) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4490 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4491 | int color = ambient ? resolveAmbientColor() : getPrimaryHighlightColor(); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4492 | if (colorable) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4493 | contentView.setDrawableParameters(R.id.icon, false, -1, color, |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 4494 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4495 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4496 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4497 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4498 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4499 | } |
| 4500 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4501 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4502 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4503 | * if it's grayscale). |
| 4504 | */ |
| 4505 | // TODO: also check bounds, transparency, that sort of thing. |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4506 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) { |
| 4507 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4508 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4509 | // resolve color will fall back to the default when legacy |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4510 | contentView.setDrawableParameters(R.id.icon, false, -1, resolveContrastColor(), |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 4511 | PorterDuff.Mode.SRC_ATOP, -1); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 4512 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4513 | } |
| 4514 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4515 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4516 | if (mN.color != COLOR_DEFAULT) { |
| 4517 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 4518 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 4519 | } |
| 4520 | |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4521 | int resolveContrastColor() { |
| 4522 | if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) { |
| 4523 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4524 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4525 | final int contrasted = NotificationColorUtil.resolveContrastColor(mContext, mN.color); |
| 4526 | |
| 4527 | mCachedContrastColorIsFor = mN.color; |
| 4528 | return mCachedContrastColor = contrasted; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4529 | } |
| 4530 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4531 | int resolveAmbientColor() { |
| 4532 | if (mCachedAmbientColorIsFor == mN.color && mCachedAmbientColorIsFor != COLOR_INVALID) { |
| 4533 | return mCachedAmbientColor; |
| 4534 | } |
| 4535 | final int contrasted = NotificationColorUtil.resolveAmbientColor(mContext, mN.color); |
| 4536 | |
| 4537 | mCachedAmbientColorIsFor = mN.color; |
| 4538 | return mCachedAmbientColor = contrasted; |
| 4539 | } |
| 4540 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4541 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4542 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4543 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4544 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4545 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4546 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4547 | mN.actions = new Action[mActions.size()]; |
| 4548 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4549 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4550 | if (!mPersonList.isEmpty()) { |
| 4551 | mN.extras.putStringArray(EXTRA_PEOPLE, |
| 4552 | mPersonList.toArray(new String[mPersonList.size()])); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4553 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4554 | if (mN.bigContentView != null || mN.contentView != null |
| 4555 | || mN.headsUpContentView != null) { |
| 4556 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 4557 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4558 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4559 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4560 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4561 | /** |
| 4562 | * Creates a Builder from an existing notification so further changes can be made. |
| 4563 | * @param context The context for your application / activity. |
| 4564 | * @param n The notification to create a Builder from. |
| 4565 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4566 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4567 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4568 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 4569 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4570 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4571 | if (applicationInfo != null) { |
| 4572 | try { |
| 4573 | builderContext = context.createApplicationContext(applicationInfo, |
| 4574 | Context.CONTEXT_RESTRICTED); |
| 4575 | } catch (NameNotFoundException e) { |
| 4576 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 4577 | builderContext = context; // try with our context |
| 4578 | } |
| 4579 | } else { |
| 4580 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4581 | } |
| 4582 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4583 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4584 | } |
| 4585 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4586 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4587 | * @deprecated Use {@link #build()} instead. |
| 4588 | */ |
| 4589 | @Deprecated |
| 4590 | public Notification getNotification() { |
| 4591 | return build(); |
| 4592 | } |
| 4593 | |
| 4594 | /** |
| 4595 | * Combine all of the options that have been set and return a new {@link Notification} |
| 4596 | * object. |
| 4597 | */ |
| 4598 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4599 | // first, add any extras from the calling code |
| 4600 | if (mUserExtras != null) { |
| 4601 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 4602 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4603 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4604 | mN.creationTime = System.currentTimeMillis(); |
| 4605 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4606 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4607 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 4608 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4609 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4610 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4611 | if (mStyle != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4612 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4613 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4614 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4615 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 4616 | && (mStyle == null || !mStyle.displayCustomViewInline())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4617 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4618 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4619 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 4620 | mN.contentView.getSequenceNumber()); |
| 4621 | } |
| 4622 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4623 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4624 | if (mN.bigContentView != null) { |
| 4625 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 4626 | mN.bigContentView.getSequenceNumber()); |
| 4627 | } |
| 4628 | } |
| 4629 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4630 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4631 | if (mN.headsUpContentView != null) { |
| 4632 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 4633 | mN.headsUpContentView.getSequenceNumber()); |
| 4634 | } |
| 4635 | } |
| 4636 | } |
| 4637 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 4638 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 4639 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 4640 | } |
| 4641 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4642 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4643 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 4644 | |
| 4645 | /** |
| 4646 | * Apply this Builder to an existing {@link Notification} object. |
| 4647 | * |
| 4648 | * @hide |
| 4649 | */ |
| 4650 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 4651 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 4652 | return n; |
| 4653 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4654 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4655 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4656 | * Removes RemoteViews that were created for compatibility from {@param n}, if they did not |
| 4657 | * change. |
| 4658 | * |
| 4659 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 4660 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4661 | * @hide |
| 4662 | */ |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4663 | public static Notification maybeCloneStrippedForDelivery(Notification n) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4664 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4665 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4666 | // Only strip views for known Styles because we won't know how to |
| 4667 | // re-create them otherwise. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4668 | if (!TextUtils.isEmpty(templateClass) |
| 4669 | && getNotificationStyleClass(templateClass) == null) { |
| 4670 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4671 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4672 | |
| 4673 | // Only strip unmodified BuilderRemoteViews. |
| 4674 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4675 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4676 | n.contentView.getSequenceNumber(); |
| 4677 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4678 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4679 | n.bigContentView.getSequenceNumber(); |
| 4680 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4681 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4682 | n.headsUpContentView.getSequenceNumber(); |
| 4683 | |
| 4684 | // Nothing to do here, no need to clone. |
| 4685 | if (!stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
| 4686 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4687 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4688 | |
| 4689 | Notification clone = n.clone(); |
| 4690 | if (stripContentView) { |
| 4691 | clone.contentView = null; |
| 4692 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 4693 | } |
| 4694 | if (stripBigContentView) { |
| 4695 | clone.bigContentView = null; |
| 4696 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 4697 | } |
| 4698 | if (stripHeadsUpContentView) { |
| 4699 | clone.headsUpContentView = null; |
| 4700 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 4701 | } |
| 4702 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4703 | } |
| 4704 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4705 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4706 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4710 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4714 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4718 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4722 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4723 | } |
| 4724 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 4725 | private int getMessagingLayoutResource() { |
| 4726 | return R.layout.notification_template_material_messaging; |
| 4727 | } |
| 4728 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4729 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4730 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4731 | } |
| 4732 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4733 | private int getEmphasizedActionLayoutResource() { |
| 4734 | return R.layout.notification_material_action_emphasized; |
| 4735 | } |
| 4736 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4737 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4738 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4739 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4740 | |
| 4741 | private int getBackgroundColor() { |
| 4742 | if (isColorized()) { |
| 4743 | return mN.color; |
| 4744 | } else { |
| 4745 | return COLOR_DEFAULT; |
| 4746 | } |
| 4747 | } |
| 4748 | |
| 4749 | private boolean isColorized() { |
| 4750 | return mN.isColorized(); |
| 4751 | } |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4752 | |
| 4753 | private boolean textColorsNeedInversion() { |
| 4754 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 4755 | return false; |
| 4756 | } |
| 4757 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 4758 | return targetSdkVersion > Build.VERSION_CODES.M |
| 4759 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 4760 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4761 | } |
| 4762 | |
| 4763 | /** |
| 4764 | * @return whether this notification is ongoing and can't be dismissed by the user. |
| 4765 | */ |
| 4766 | private boolean isOngoing() { |
| 4767 | final int ongoingFlags = Notification.FLAG_FOREGROUND_SERVICE |
| 4768 | | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; |
| 4769 | return (flags & ongoingFlags) != 0; |
| 4770 | } |
| 4771 | |
| 4772 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4773 | * @return whether this notification has a media session attached |
| 4774 | * @hide |
| 4775 | */ |
| 4776 | public boolean hasMediaSession() { |
| 4777 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 4778 | } |
| 4779 | |
| 4780 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4781 | * @return the style class of this notification |
| 4782 | * @hide |
| 4783 | */ |
| 4784 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 4785 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 4786 | |
| 4787 | if (!TextUtils.isEmpty(templateClass)) { |
| 4788 | return Notification.getNotificationStyleClass(templateClass); |
| 4789 | } |
| 4790 | return null; |
| 4791 | } |
| 4792 | |
| 4793 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4794 | * @return true if this notification is colorized. This also factors in whether the |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4795 | * notification is ongoing. |
| 4796 | * |
| 4797 | * @hide |
| 4798 | */ |
| 4799 | public boolean isColorized() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4800 | Class<? extends Style> style = getNotificationStyle(); |
| 4801 | if (MediaStyle.class.equals(style)) { |
| 4802 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 4803 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 4804 | return true; |
| 4805 | } |
| 4806 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 4807 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 4808 | return true; |
| 4809 | } |
| 4810 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4811 | return extras.getBoolean(EXTRA_COLORIZED) && isOngoing(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4812 | } |
| 4813 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4814 | private boolean hasLargeIcon() { |
| 4815 | return mLargeIcon != null || largeIcon != null; |
| 4816 | } |
| 4817 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4818 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 4819 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4820 | * @hide |
| 4821 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 4822 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4823 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 4824 | } |
| 4825 | |
| 4826 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 4827 | * @return true if the notification will show a chronometer; false otherwise |
| 4828 | * @hide |
| 4829 | */ |
| 4830 | public boolean showsChronometer() { |
| 4831 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 4832 | } |
| 4833 | |
| 4834 | /** |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 4835 | * @hide |
| 4836 | */ |
| 4837 | @SystemApi |
| 4838 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 4839 | Class<? extends Style>[] classes = new Class[] { |
| 4840 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 4841 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 4842 | MessagingStyle.class }; |
| 4843 | for (Class<? extends Style> innerClass : classes) { |
| 4844 | if (templateClass.equals(innerClass.getName())) { |
| 4845 | return innerClass; |
| 4846 | } |
| 4847 | } |
| 4848 | return null; |
| 4849 | } |
| 4850 | |
| 4851 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4852 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 4853 | * object. |
| 4854 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 4855 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4856 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 4857 | |
| 4858 | /** |
| 4859 | * @hide |
| 4860 | */ |
| 4861 | protected CharSequence mSummaryText = null; |
| 4862 | |
| 4863 | /** |
| 4864 | * @hide |
| 4865 | */ |
| 4866 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4867 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4868 | protected Builder mBuilder; |
| 4869 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4870 | /** |
| 4871 | * Overrides ContentTitle in the big form of the template. |
| 4872 | * This defaults to the value passed to setContentTitle(). |
| 4873 | */ |
| 4874 | protected void internalSetBigContentTitle(CharSequence title) { |
| 4875 | mBigContentTitle = title; |
| 4876 | } |
| 4877 | |
| 4878 | /** |
| 4879 | * Set the first line of text after the detail section in the big form of the template. |
| 4880 | */ |
| 4881 | protected void internalSetSummaryText(CharSequence cs) { |
| 4882 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 4883 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4884 | } |
| 4885 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4886 | public void setBuilder(Builder builder) { |
| 4887 | if (mBuilder != builder) { |
| 4888 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 4889 | if (mBuilder != null) { |
| 4890 | mBuilder.setStyle(this); |
| 4891 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4892 | } |
| 4893 | } |
| 4894 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4895 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4896 | if (mBuilder == null) { |
| 4897 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 4898 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4899 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4900 | |
| 4901 | protected RemoteViews getStandardView(int layoutId) { |
| 4902 | checkBuilder(); |
| 4903 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4904 | // Nasty. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4905 | CharSequence oldBuilderContentTitle = |
| 4906 | mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4907 | if (mBigContentTitle != null) { |
| 4908 | mBuilder.setContentTitle(mBigContentTitle); |
| 4909 | } |
| 4910 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4911 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 4912 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4913 | mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4914 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4915 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 4916 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 4917 | } else { |
| 4918 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4919 | } |
| 4920 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4921 | return contentView; |
| 4922 | } |
| 4923 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4924 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4925 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4926 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4927 | * |
| 4928 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4929 | * @hide |
| 4930 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4931 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4932 | return null; |
| 4933 | } |
| 4934 | |
| 4935 | /** |
| 4936 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 4937 | * @hide |
| 4938 | */ |
| 4939 | public RemoteViews makeBigContentView() { |
| 4940 | return null; |
| 4941 | } |
| 4942 | |
| 4943 | /** |
| 4944 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4945 | * |
| 4946 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4947 | * @hide |
| 4948 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4949 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4950 | return null; |
| 4951 | } |
| 4952 | |
| 4953 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4954 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4955 | * @hide |
| 4956 | */ |
| 4957 | public void addExtras(Bundle extras) { |
| 4958 | if (mSummaryTextSet) { |
| 4959 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 4960 | } |
| 4961 | if (mBigContentTitle != null) { |
| 4962 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 4963 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 4964 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4965 | } |
| 4966 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4967 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4968 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4969 | * @hide |
| 4970 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4971 | protected void restoreFromExtras(Bundle extras) { |
| 4972 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 4973 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 4974 | mSummaryTextSet = true; |
| 4975 | } |
| 4976 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 4977 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 4978 | } |
| 4979 | } |
| 4980 | |
| 4981 | |
| 4982 | /** |
| 4983 | * @hide |
| 4984 | */ |
| 4985 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4986 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4987 | return wip; |
| 4988 | } |
| 4989 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 4990 | /** |
| 4991 | * @hide |
| 4992 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 4993 | public void purgeResources() {} |
| 4994 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4995 | /** |
| 4996 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 4997 | * attached to. |
| 4998 | * |
| 4999 | * @return the fully constructed Notification. |
| 5000 | */ |
| 5001 | public Notification build() { |
| 5002 | checkBuilder(); |
| 5003 | return mBuilder.build(); |
| 5004 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5005 | |
| 5006 | /** |
| 5007 | * @hide |
| 5008 | * @return true if the style positions the progress bar on the second line; false if the |
| 5009 | * style hides the progress bar |
| 5010 | */ |
| 5011 | protected boolean hasProgress() { |
| 5012 | return true; |
| 5013 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5014 | |
| 5015 | /** |
| 5016 | * @hide |
| 5017 | * @return Whether we should put the summary be put into the notification header |
| 5018 | */ |
| 5019 | public boolean hasSummaryInHeader() { |
| 5020 | return true; |
| 5021 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 5022 | |
| 5023 | /** |
| 5024 | * @hide |
| 5025 | * @return Whether custom content views are displayed inline in the style |
| 5026 | */ |
| 5027 | public boolean displayCustomViewInline() { |
| 5028 | return false; |
| 5029 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5030 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5031 | |
| 5032 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5033 | * 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] | 5034 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5035 | * 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] | 5036 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5037 | * Notification notif = new Notification.Builder(mContext) |
| 5038 | * .setContentTitle("New photo from " + sender.toString()) |
| 5039 | * .setContentText(subject) |
| 5040 | * .setSmallIcon(R.drawable.new_post) |
| 5041 | * .setLargeIcon(aBitmap) |
| 5042 | * .setStyle(new Notification.BigPictureStyle() |
| 5043 | * .bigPicture(aBigBitmap)) |
| 5044 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5045 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5046 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5047 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5048 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5049 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5050 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5051 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5052 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5053 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5054 | public BigPictureStyle() { |
| 5055 | } |
| 5056 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 5057 | /** |
| 5058 | * @deprecated use {@code BigPictureStyle()}. |
| 5059 | */ |
| 5060 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5061 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5062 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5063 | } |
| 5064 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5065 | /** |
| 5066 | * Overrides ContentTitle in the big form of the template. |
| 5067 | * This defaults to the value passed to setContentTitle(). |
| 5068 | */ |
| 5069 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5070 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5071 | return this; |
| 5072 | } |
| 5073 | |
| 5074 | /** |
| 5075 | * Set the first line of text after the detail section in the big form of the template. |
| 5076 | */ |
| 5077 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5078 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5079 | return this; |
| 5080 | } |
| 5081 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 5082 | /** |
| 5083 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 5084 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5085 | public BigPictureStyle bigPicture(Bitmap b) { |
| 5086 | mPicture = b; |
| 5087 | return this; |
| 5088 | } |
| 5089 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5090 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5091 | * Override the large icon when the big notification is shown. |
| 5092 | */ |
| 5093 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5094 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 5095 | } |
| 5096 | |
| 5097 | /** |
| 5098 | * Override the large icon when the big notification is shown. |
| 5099 | */ |
| 5100 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5101 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5102 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5103 | return this; |
| 5104 | } |
| 5105 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 5106 | /** @hide */ |
| 5107 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 5108 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 5109 | /** |
| 5110 | * @hide |
| 5111 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5112 | @Override |
| 5113 | public void purgeResources() { |
| 5114 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 5115 | if (mPicture != null && |
| 5116 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 5117 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5118 | mPicture = mPicture.createAshmemBitmap(); |
| 5119 | } |
| 5120 | if (mBigLargeIcon != null) { |
| 5121 | mBigLargeIcon.convertToAshmem(); |
| 5122 | } |
| 5123 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5124 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5125 | /** |
| 5126 | * @hide |
| 5127 | */ |
| 5128 | public RemoteViews makeBigContentView() { |
| 5129 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5130 | // This covers the following cases: |
| 5131 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5132 | // mN.mLargeIcon |
| 5133 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5134 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5135 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5136 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5137 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 5138 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5139 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 5140 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 5141 | // for old listeners, this is in general non-null. |
| 5142 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 5143 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5144 | } |
| 5145 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5146 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5147 | if (mSummaryTextSet) { |
| 5148 | contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(mSummaryText)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5149 | mBuilder.setTextViewColorSecondary(contentView, R.id.text); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 5150 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5151 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5152 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 5153 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5154 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5155 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5156 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5157 | } |
| 5158 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5159 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5160 | return contentView; |
| 5161 | } |
| 5162 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5163 | /** |
| 5164 | * @hide |
| 5165 | */ |
| 5166 | public void addExtras(Bundle extras) { |
| 5167 | super.addExtras(extras); |
| 5168 | |
| 5169 | if (mBigLargeIconSet) { |
| 5170 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 5171 | } |
| 5172 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 5173 | } |
| 5174 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5175 | /** |
| 5176 | * @hide |
| 5177 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5178 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5179 | protected void restoreFromExtras(Bundle extras) { |
| 5180 | super.restoreFromExtras(extras); |
| 5181 | |
| 5182 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5183 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5184 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5185 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5186 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 5187 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5188 | |
| 5189 | /** |
| 5190 | * @hide |
| 5191 | */ |
| 5192 | @Override |
| 5193 | public boolean hasSummaryInHeader() { |
| 5194 | return false; |
| 5195 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5199 | * 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] | 5200 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5201 | * 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] | 5202 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5203 | * Notification notif = new Notification.Builder(mContext) |
| 5204 | * .setContentTitle("New mail from " + sender.toString()) |
| 5205 | * .setContentText(subject) |
| 5206 | * .setSmallIcon(R.drawable.new_mail) |
| 5207 | * .setLargeIcon(aBitmap) |
| 5208 | * .setStyle(new Notification.BigTextStyle() |
| 5209 | * .bigText(aVeryLongString)) |
| 5210 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5211 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5212 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5213 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5214 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5215 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 5216 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5217 | private CharSequence mBigText; |
| 5218 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5219 | public BigTextStyle() { |
| 5220 | } |
| 5221 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 5222 | /** |
| 5223 | * @deprecated use {@code BigTextStyle()}. |
| 5224 | */ |
| 5225 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5226 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5227 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5228 | } |
| 5229 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5230 | /** |
| 5231 | * Overrides ContentTitle in the big form of the template. |
| 5232 | * This defaults to the value passed to setContentTitle(). |
| 5233 | */ |
| 5234 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5235 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5236 | return this; |
| 5237 | } |
| 5238 | |
| 5239 | /** |
| 5240 | * Set the first line of text after the detail section in the big form of the template. |
| 5241 | */ |
| 5242 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5243 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5244 | return this; |
| 5245 | } |
| 5246 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 5247 | /** |
| 5248 | * Provide the longer text to be displayed in the big form of the |
| 5249 | * template in place of the content text. |
| 5250 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5251 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5252 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5253 | return this; |
| 5254 | } |
| 5255 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5256 | /** |
| 5257 | * @hide |
| 5258 | */ |
| 5259 | public void addExtras(Bundle extras) { |
| 5260 | super.addExtras(extras); |
| 5261 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5262 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 5263 | } |
| 5264 | |
| 5265 | /** |
| 5266 | * @hide |
| 5267 | */ |
| 5268 | @Override |
| 5269 | protected void restoreFromExtras(Bundle extras) { |
| 5270 | super.restoreFromExtras(extras); |
| 5271 | |
| 5272 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5273 | } |
| 5274 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5275 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5276 | * @param increasedHeight true if this layout be created with an increased height. |
| 5277 | * |
| 5278 | * @hide |
| 5279 | */ |
| 5280 | @Override |
| 5281 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 5282 | if (increasedHeight) { |
| 5283 | ArrayList<Action> actions = mBuilder.mActions; |
| 5284 | mBuilder.mActions = new ArrayList<>(); |
| 5285 | RemoteViews remoteViews = makeBigContentView(); |
| 5286 | mBuilder.mActions = actions; |
| 5287 | return remoteViews; |
| 5288 | } |
| 5289 | return super.makeContentView(increasedHeight); |
| 5290 | } |
| 5291 | |
| 5292 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5293 | * @hide |
| 5294 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5295 | @Override |
| 5296 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 5297 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 5298 | return makeBigContentView(); |
| 5299 | } |
| 5300 | return super.makeHeadsUpContentView(increasedHeight); |
| 5301 | } |
| 5302 | |
| 5303 | /** |
| 5304 | * @hide |
| 5305 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5306 | public RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5307 | |
| 5308 | // Nasty |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 5309 | CharSequence text = mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5310 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 5311 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5312 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5313 | |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 5314 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, text); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5315 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 5316 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 5317 | if (TextUtils.isEmpty(bigTextText)) { |
| 5318 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 5319 | // experience |
| 5320 | bigTextText = mBuilder.processLegacyText(text); |
| 5321 | } |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5322 | applyBigTextContentView(mBuilder, contentView, bigTextText); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 5323 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5324 | return contentView; |
| 5325 | } |
| 5326 | |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5327 | static void applyBigTextContentView(Builder builder, |
| 5328 | RemoteViews contentView, CharSequence bigTextText) { |
| 5329 | contentView.setTextViewText(R.id.big_text, bigTextText); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5330 | builder.setTextViewColorSecondary(contentView, R.id.big_text); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5331 | contentView.setViewVisibility(R.id.big_text, |
| 5332 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5333 | contentView.setBoolean(R.id.big_text, "setHasImage", builder.mN.hasLargeIcon()); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5334 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5335 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5336 | |
| 5337 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5338 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 5339 | * messages of varying types between any number of people. |
| 5340 | * |
| 5341 | * <br> |
| 5342 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 5343 | * user will always see the normal notification view. |
| 5344 | * <br> |
| 5345 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like |
| 5346 | * so: |
| 5347 | * <pre class="prettyprint"> |
| 5348 | * |
| 5349 | * Notification noti = new Notification.Builder() |
| 5350 | * .setContentTitle("2 new messages wtih " + sender.toString()) |
| 5351 | * .setContentText(subject) |
| 5352 | * .setSmallIcon(R.drawable.new_message) |
| 5353 | * .setLargeIcon(aBitmap) |
| 5354 | * .setStyle(new Notification.MessagingStyle(resources.getString(R.string.reply_name)) |
| 5355 | * .addMessage(messages[0].getText(), messages[0].getTime(), messages[0].getSender()) |
| 5356 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getSender())) |
| 5357 | * .build(); |
| 5358 | * </pre> |
| 5359 | */ |
| 5360 | public static class MessagingStyle extends Style { |
| 5361 | |
| 5362 | /** |
| 5363 | * The maximum number of messages that will be retained in the Notification itself (the |
| 5364 | * number displayed is up to the platform). |
| 5365 | */ |
| 5366 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 5367 | |
| 5368 | CharSequence mUserDisplayName; |
| 5369 | CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5370 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5371 | List<Message> mHistoricMessages = new ArrayList<>(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5372 | |
| 5373 | MessagingStyle() { |
| 5374 | } |
| 5375 | |
| 5376 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 5377 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 5378 | * user before the posting app reposts the notification with those messages after they've |
| 5379 | * 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] | 5380 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
| 5381 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 5382 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5383 | mUserDisplayName = userDisplayName; |
| 5384 | } |
| 5385 | |
| 5386 | /** |
| 5387 | * Returns the name to be displayed for any replies sent by the user |
| 5388 | */ |
| 5389 | public CharSequence getUserDisplayName() { |
| 5390 | return mUserDisplayName; |
| 5391 | } |
| 5392 | |
| 5393 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5394 | * Sets the title to be displayed on this conversation. This should only be used for |
| 5395 | * group messaging and left unset for one-on-one conversations. |
| 5396 | * @param conversationTitle |
| 5397 | * @return this object for method chaining. |
| 5398 | */ |
| 5399 | public MessagingStyle setConversationTitle(CharSequence conversationTitle) { |
| 5400 | mConversationTitle = conversationTitle; |
| 5401 | return this; |
| 5402 | } |
| 5403 | |
| 5404 | /** |
| 5405 | * Return the title to be displayed on this conversation. Can be <code>null</code> and |
| 5406 | * should be for one-on-one conversations |
| 5407 | */ |
| 5408 | public CharSequence getConversationTitle() { |
| 5409 | return mConversationTitle; |
| 5410 | } |
| 5411 | |
| 5412 | /** |
| 5413 | * Adds a message for display by this notification. Convenience call for a simple |
| 5414 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 5415 | * @param text A {@link CharSequence} to be displayed as the message content |
| 5416 | * @param timestamp Time at which the message arrived |
| 5417 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 5418 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 5419 | * the platform will insert {@link #getUserDisplayName()}. |
| 5420 | * Should be unique amongst all individuals in the conversation, and should be |
| 5421 | * consistent during re-posts of the notification. |
| 5422 | * |
| 5423 | * @see Message#Message(CharSequence, long, CharSequence) |
| 5424 | * |
| 5425 | * @return this object for method chaining |
| 5426 | */ |
| 5427 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5428 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | /** |
| 5432 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5433 | * |
| 5434 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 5435 | * the newest last. |
| 5436 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5437 | * @param message The {@link Message} to be displayed |
| 5438 | * @return this object for method chaining |
| 5439 | */ |
| 5440 | public MessagingStyle addMessage(Message message) { |
| 5441 | mMessages.add(message); |
| 5442 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 5443 | mMessages.remove(0); |
| 5444 | } |
| 5445 | return this; |
| 5446 | } |
| 5447 | |
| 5448 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5449 | * Adds a {@link Message} for historic context in this notification. |
| 5450 | * |
| 5451 | * <p>Messages should be added as historic if they are not the main subject of the |
| 5452 | * notification but may give context to a conversation. The system may choose to present |
| 5453 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 5454 | * |
| 5455 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 5456 | * the newest last. |
| 5457 | * |
| 5458 | * @param message The historic {@link Message} to be added |
| 5459 | * @return this object for method chaining |
| 5460 | */ |
| 5461 | public MessagingStyle addHistoricMessage(Message message) { |
| 5462 | mHistoricMessages.add(message); |
| 5463 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 5464 | mHistoricMessages.remove(0); |
| 5465 | } |
| 5466 | return this; |
| 5467 | } |
| 5468 | |
| 5469 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5470 | * Gets the list of {@code Message} objects that represent the notification |
| 5471 | */ |
| 5472 | public List<Message> getMessages() { |
| 5473 | return mMessages; |
| 5474 | } |
| 5475 | |
| 5476 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5477 | * Gets the list of historic {@code Message}s in the notification. |
| 5478 | */ |
| 5479 | public List<Message> getHistoricMessages() { |
| 5480 | return mHistoricMessages; |
| 5481 | } |
| 5482 | |
| 5483 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5484 | * @hide |
| 5485 | */ |
| 5486 | @Override |
| 5487 | public void addExtras(Bundle extras) { |
| 5488 | super.addExtras(extras); |
| 5489 | if (mUserDisplayName != null) { |
| 5490 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUserDisplayName); |
| 5491 | } |
| 5492 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5493 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5494 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5495 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 5496 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5497 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5498 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 5499 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 5500 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 5501 | |
| 5502 | fixTitleAndTextExtras(extras); |
| 5503 | } |
| 5504 | |
| 5505 | private void fixTitleAndTextExtras(Bundle extras) { |
| 5506 | Message m = findLatestIncomingMessage(); |
| 5507 | CharSequence text = (m == null) ? null : m.mText; |
| 5508 | CharSequence sender = m == null ? null |
| 5509 | : TextUtils.isEmpty(m.mSender) ? mUserDisplayName : m.mSender; |
| 5510 | CharSequence title; |
| 5511 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 5512 | if (!TextUtils.isEmpty(sender)) { |
| 5513 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5514 | title = mBuilder.mContext.getString( |
| 5515 | com.android.internal.R.string.notification_messaging_title_template, |
| 5516 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(m.mSender)); |
| 5517 | } else { |
| 5518 | title = mConversationTitle; |
| 5519 | } |
| 5520 | } else { |
| 5521 | title = sender; |
| 5522 | } |
| 5523 | |
| 5524 | if (title != null) { |
| 5525 | extras.putCharSequence(EXTRA_TITLE, title); |
| 5526 | } |
| 5527 | if (text != null) { |
| 5528 | extras.putCharSequence(EXTRA_TEXT, text); |
| 5529 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | /** |
| 5533 | * @hide |
| 5534 | */ |
| 5535 | @Override |
| 5536 | protected void restoreFromExtras(Bundle extras) { |
| 5537 | super.restoreFromExtras(extras); |
| 5538 | |
| 5539 | mMessages.clear(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5540 | mHistoricMessages.clear(); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5541 | mUserDisplayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
| 5542 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5543 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 5544 | if (messages != null && messages instanceof Parcelable[]) { |
| 5545 | mMessages = Message.getMessagesFromBundleArray(messages); |
| 5546 | } |
| 5547 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 5548 | if (histMessages != null && histMessages instanceof Parcelable[]) { |
| 5549 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5550 | } |
| 5551 | } |
| 5552 | |
| 5553 | /** |
| 5554 | * @hide |
| 5555 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5556 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5557 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 5558 | if (!increasedHeight) { |
| 5559 | Message m = findLatestIncomingMessage(); |
| 5560 | CharSequence title = mConversationTitle != null |
| 5561 | ? mConversationTitle |
| 5562 | : (m == null) ? null : m.mSender; |
| 5563 | CharSequence text = (m == null) |
| 5564 | ? null |
| 5565 | : mConversationTitle != null ? makeMessageLine(m, mBuilder) : m.mText; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5566 | |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5567 | return mBuilder.applyStandardTemplate(mBuilder.getBaseLayoutResource(), |
| 5568 | mBuilder.mParams.reset().hasProgress(false).title(title).text(text)); |
| 5569 | } else { |
| 5570 | ArrayList<Action> actions = mBuilder.mActions; |
| 5571 | mBuilder.mActions = new ArrayList<>(); |
| 5572 | RemoteViews remoteViews = makeBigContentView(); |
| 5573 | mBuilder.mActions = actions; |
| 5574 | return remoteViews; |
| 5575 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | private Message findLatestIncomingMessage() { |
| 5579 | for (int i = mMessages.size() - 1; i >= 0; i--) { |
| 5580 | Message m = mMessages.get(i); |
| 5581 | // Incoming messages have a non-empty sender. |
| 5582 | if (!TextUtils.isEmpty(m.mSender)) { |
| 5583 | return m; |
| 5584 | } |
| 5585 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 5586 | if (!mMessages.isEmpty()) { |
| 5587 | // No incoming messages, fall back to outgoing message |
| 5588 | return mMessages.get(mMessages.size() - 1); |
| 5589 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5590 | return null; |
| 5591 | } |
| 5592 | |
| 5593 | /** |
| 5594 | * @hide |
| 5595 | */ |
| 5596 | @Override |
| 5597 | public RemoteViews makeBigContentView() { |
| 5598 | CharSequence title = !TextUtils.isEmpty(super.mBigContentTitle) |
| 5599 | ? super.mBigContentTitle |
| 5600 | : mConversationTitle; |
| 5601 | boolean hasTitle = !TextUtils.isEmpty(title); |
| 5602 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 5603 | if (mMessages.size() == 1) { |
| 5604 | // Special case for a single message: Use the big text style |
| 5605 | // so the collapsed and expanded versions match nicely. |
| 5606 | CharSequence bigTitle; |
| 5607 | CharSequence text; |
| 5608 | if (hasTitle) { |
| 5609 | bigTitle = title; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5610 | text = makeMessageLine(mMessages.get(0), mBuilder); |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 5611 | } else { |
| 5612 | bigTitle = mMessages.get(0).mSender; |
| 5613 | text = mMessages.get(0).mText; |
| 5614 | } |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5615 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
| 5616 | mBuilder.getBigTextLayoutResource(), |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 5617 | mBuilder.mParams.reset().hasProgress(false).title(bigTitle).text(null)); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5618 | BigTextStyle.applyBigTextContentView(mBuilder, contentView, text); |
| 5619 | return contentView; |
| 5620 | } |
| 5621 | |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 5622 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5623 | mBuilder.getMessagingLayoutResource(), |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 5624 | mBuilder.mParams.reset().hasProgress(false).title(title).text(null)); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5625 | |
| 5626 | int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3, |
| 5627 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
| 5628 | |
| 5629 | // Make sure all rows are gone in case we reuse a view. |
| 5630 | for (int rowId : rowIds) { |
| 5631 | contentView.setViewVisibility(rowId, View.GONE); |
| 5632 | } |
| 5633 | |
| 5634 | int i=0; |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 5635 | contentView.setViewLayoutMarginBottomDimen(R.id.line1, |
| 5636 | hasTitle ? R.dimen.notification_messaging_spacing : 0); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5637 | contentView.setInt(R.id.notification_messaging, "setNumIndentLines", |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5638 | !mBuilder.mN.hasLargeIcon() ? 0 : (hasTitle ? 1 : 2)); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5639 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 5640 | int contractedChildId = View.NO_ID; |
| 5641 | Message contractedMessage = findLatestIncomingMessage(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5642 | int firstHistoricMessage = Math.max(0, mHistoricMessages.size() |
| 5643 | - (rowIds.length - mMessages.size())); |
| 5644 | while (firstHistoricMessage + i < mHistoricMessages.size() && i < rowIds.length) { |
| 5645 | Message m = mHistoricMessages.get(firstHistoricMessage + i); |
| 5646 | int rowId = rowIds[i]; |
| 5647 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5648 | contentView.setTextViewText(rowId, makeMessageLine(m, mBuilder)); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5649 | |
| 5650 | if (contractedMessage == m) { |
| 5651 | contractedChildId = rowId; |
| 5652 | } |
| 5653 | |
| 5654 | i++; |
| 5655 | } |
| 5656 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5657 | int firstMessage = Math.max(0, mMessages.size() - rowIds.length); |
| 5658 | while (firstMessage + i < mMessages.size() && i < rowIds.length) { |
| 5659 | Message m = mMessages.get(firstMessage + i); |
| 5660 | int rowId = rowIds[i]; |
| 5661 | |
| 5662 | contentView.setViewVisibility(rowId, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5663 | contentView.setTextViewText(rowId, makeMessageLine(m, mBuilder)); |
| 5664 | mBuilder.setTextViewColorSecondary(contentView, rowId); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5665 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 5666 | if (contractedMessage == m) { |
| 5667 | contractedChildId = rowId; |
| 5668 | } |
| 5669 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5670 | i++; |
| 5671 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5672 | // Clear the remaining views for reapply. Ensures that historic message views can |
| 5673 | // reliably be identified as being GONE and having non-null text. |
| 5674 | while (i < rowIds.length) { |
| 5675 | int rowId = rowIds[i]; |
| 5676 | contentView.setTextViewText(rowId, null); |
| 5677 | i++; |
| 5678 | } |
| 5679 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 5680 | // Record this here to allow transformation between the contracted and expanded views. |
| 5681 | contentView.setInt(R.id.notification_messaging, "setContractedChildId", |
| 5682 | contractedChildId); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5683 | return contentView; |
| 5684 | } |
| 5685 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5686 | private CharSequence makeMessageLine(Message m, Builder builder) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5687 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5688 | SpannableStringBuilder sb = new SpannableStringBuilder(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5689 | boolean colorize = builder.isColorized(); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5690 | if (TextUtils.isEmpty(m.mSender)) { |
| 5691 | CharSequence replyName = mUserDisplayName == null ? "" : mUserDisplayName; |
| 5692 | sb.append(bidi.unicodeWrap(replyName), |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5693 | makeFontColorSpan(colorize |
| 5694 | ? builder.getPrimaryTextColor() |
| 5695 | : mBuilder.resolveContrastColor()), |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5696 | 0 /* flags */); |
| 5697 | } else { |
| 5698 | sb.append(bidi.unicodeWrap(m.mSender), |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5699 | makeFontColorSpan(colorize |
| 5700 | ? builder.getPrimaryTextColor() |
| 5701 | : Color.BLACK), |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5702 | 0 /* flags */); |
| 5703 | } |
| 5704 | CharSequence text = m.mText == null ? "" : m.mText; |
| 5705 | sb.append(" ").append(bidi.unicodeWrap(text)); |
| 5706 | return sb; |
| 5707 | } |
| 5708 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 5709 | /** |
| 5710 | * @hide |
| 5711 | */ |
| 5712 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5713 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 5714 | if (increasedHeight) { |
| 5715 | return makeBigContentView(); |
| 5716 | } |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 5717 | Message m = findLatestIncomingMessage(); |
| 5718 | CharSequence title = mConversationTitle != null |
| 5719 | ? mConversationTitle |
| 5720 | : (m == null) ? null : m.mSender; |
| 5721 | CharSequence text = (m == null) |
| 5722 | ? null |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5723 | : mConversationTitle != null ? makeMessageLine(m, mBuilder) : m.mText; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 5724 | |
| 5725 | return mBuilder.applyStandardTemplateWithActions(mBuilder.getBigBaseLayoutResource(), |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 5726 | mBuilder.mParams.reset().hasProgress(false).title(title).text(text)); |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 5727 | } |
| 5728 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5729 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 5730 | return new TextAppearanceSpan(null, 0, 0, |
| 5731 | ColorStateList.valueOf(color), null); |
| 5732 | } |
| 5733 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5734 | public static final class Message { |
| 5735 | |
| 5736 | static final String KEY_TEXT = "text"; |
| 5737 | static final String KEY_TIMESTAMP = "time"; |
| 5738 | static final String KEY_SENDER = "sender"; |
| 5739 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 5740 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 5741 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5742 | |
| 5743 | private final CharSequence mText; |
| 5744 | private final long mTimestamp; |
| 5745 | private final CharSequence mSender; |
| 5746 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 5747 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5748 | private String mDataMimeType; |
| 5749 | private Uri mDataUri; |
| 5750 | |
| 5751 | /** |
| 5752 | * Constructor |
| 5753 | * @param text A {@link CharSequence} to be displayed as the message content |
| 5754 | * @param timestamp Time at which the message arrived |
| 5755 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 5756 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 5757 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 5758 | * Should be unique amongst all individuals in the conversation, and should be |
| 5759 | * consistent during re-posts of the notification. |
| 5760 | */ |
| 5761 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
| 5762 | mText = text; |
| 5763 | mTimestamp = timestamp; |
| 5764 | mSender = sender; |
| 5765 | } |
| 5766 | |
| 5767 | /** |
| 5768 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 5769 | * where the platform doesn't support the MIME type, the original text provided in the |
| 5770 | * constructor will be used. |
| 5771 | * @param dataMimeType The MIME type of the content. See |
| 5772 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 5773 | * types on Android and Android Wear. |
| 5774 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 5775 | * <p class="note"> |
| 5776 | * <ol> |
| 5777 | * <li>Notification Listeners including the System UI need permission to access the |
| 5778 | * data the Uri points to. The recommended ways to do this are:</li> |
| 5779 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 5780 | * the correct permission to access your provider. The preferred mechanism for |
| 5781 | * providing access is to use per-URI permissions which are temporary and only |
| 5782 | * grant access to the receiving application. An easy way to create a |
| 5783 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 5784 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 5785 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 5786 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 5787 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 5788 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 5789 | * Note that once added to the system MediaStore the content is accessible to any |
| 5790 | * app on the device.</li> |
| 5791 | * </ol> |
| 5792 | * @return this object for method chaining |
| 5793 | */ |
| 5794 | public Message setData(String dataMimeType, Uri dataUri) { |
| 5795 | mDataMimeType = dataMimeType; |
| 5796 | mDataUri = dataUri; |
| 5797 | return this; |
| 5798 | } |
| 5799 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5800 | /** |
| 5801 | * Get the text to be used for this message, or the fallback text if a type and content |
| 5802 | * Uri have been set |
| 5803 | */ |
| 5804 | public CharSequence getText() { |
| 5805 | return mText; |
| 5806 | } |
| 5807 | |
| 5808 | /** |
| 5809 | * Get the time at which this message arrived |
| 5810 | */ |
| 5811 | public long getTimestamp() { |
| 5812 | return mTimestamp; |
| 5813 | } |
| 5814 | |
| 5815 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 5816 | * Get the extras Bundle for this message. |
| 5817 | */ |
| 5818 | public Bundle getExtras() { |
| 5819 | return mExtras; |
| 5820 | } |
| 5821 | |
| 5822 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5823 | * Get the text used to display the contact's name in the messaging experience |
| 5824 | */ |
| 5825 | public CharSequence getSender() { |
| 5826 | return mSender; |
| 5827 | } |
| 5828 | |
| 5829 | /** |
| 5830 | * Get the MIME type of the data pointed to by the Uri |
| 5831 | */ |
| 5832 | public String getDataMimeType() { |
| 5833 | return mDataMimeType; |
| 5834 | } |
| 5835 | |
| 5836 | /** |
| 5837 | * Get the the Uri pointing to the content of the message. Can be null, in which case |
| 5838 | * {@see #getText()} is used. |
| 5839 | */ |
| 5840 | public Uri getDataUri() { |
| 5841 | return mDataUri; |
| 5842 | } |
| 5843 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5844 | private Bundle toBundle() { |
| 5845 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5846 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5847 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5848 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5849 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5850 | if (mSender != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5851 | bundle.putCharSequence(KEY_SENDER, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5852 | } |
| 5853 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5854 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5855 | } |
| 5856 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5857 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5858 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 5859 | if (mExtras != null) { |
| 5860 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 5861 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5862 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5863 | } |
| 5864 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5865 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 5866 | Bundle[] bundles = new Bundle[messages.size()]; |
| 5867 | final int N = messages.size(); |
| 5868 | for (int i = 0; i < N; i++) { |
| 5869 | bundles[i] = messages.get(i).toBundle(); |
| 5870 | } |
| 5871 | return bundles; |
| 5872 | } |
| 5873 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 5874 | static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5875 | List<Message> messages = new ArrayList<>(bundles.length); |
| 5876 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 5877 | if (bundles[i] instanceof Bundle) { |
| 5878 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 5879 | if (message != null) { |
| 5880 | messages.add(message); |
| 5881 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5882 | } |
| 5883 | } |
| 5884 | return messages; |
| 5885 | } |
| 5886 | |
| 5887 | static Message getMessageFromBundle(Bundle bundle) { |
| 5888 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 5889 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5890 | return null; |
| 5891 | } else { |
| 5892 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
| 5893 | bundle.getLong(KEY_TIMESTAMP), bundle.getCharSequence(KEY_SENDER)); |
| 5894 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 5895 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5896 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 5897 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5898 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 5899 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 5900 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 5901 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5902 | return message; |
| 5903 | } |
| 5904 | } catch (ClassCastException e) { |
| 5905 | return null; |
| 5906 | } |
| 5907 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5908 | } |
| 5909 | } |
| 5910 | |
| 5911 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5912 | * 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] | 5913 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5914 | * 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] | 5915 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5916 | * Notification notif = new Notification.Builder(mContext) |
| 5917 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 5918 | * .setContentText(subject) |
| 5919 | * .setSmallIcon(R.drawable.new_mail) |
| 5920 | * .setLargeIcon(aBitmap) |
| 5921 | * .setStyle(new Notification.InboxStyle() |
| 5922 | * .addLine(str1) |
| 5923 | * .addLine(str2) |
| 5924 | * .setContentTitle("") |
| 5925 | * .setSummaryText("+3 more")) |
| 5926 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5927 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5928 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5929 | * @see Notification#bigContentView |
| 5930 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5931 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5932 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 5933 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5934 | public InboxStyle() { |
| 5935 | } |
| 5936 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 5937 | /** |
| 5938 | * @deprecated use {@code InboxStyle()}. |
| 5939 | */ |
| 5940 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5941 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5942 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5943 | } |
| 5944 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5945 | /** |
| 5946 | * Overrides ContentTitle in the big form of the template. |
| 5947 | * This defaults to the value passed to setContentTitle(). |
| 5948 | */ |
| 5949 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5950 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5951 | return this; |
| 5952 | } |
| 5953 | |
| 5954 | /** |
| 5955 | * Set the first line of text after the detail section in the big form of the template. |
| 5956 | */ |
| 5957 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5958 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5959 | return this; |
| 5960 | } |
| 5961 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 5962 | /** |
| 5963 | * Append a line to the digest section of the Inbox notification. |
| 5964 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5965 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5966 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5967 | return this; |
| 5968 | } |
| 5969 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5970 | /** |
| 5971 | * @hide |
| 5972 | */ |
| 5973 | public void addExtras(Bundle extras) { |
| 5974 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5975 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5976 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 5977 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 5978 | } |
| 5979 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5980 | /** |
| 5981 | * @hide |
| 5982 | */ |
| 5983 | @Override |
| 5984 | protected void restoreFromExtras(Bundle extras) { |
| 5985 | super.restoreFromExtras(extras); |
| 5986 | |
| 5987 | mTexts.clear(); |
| 5988 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 5989 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 5990 | } |
| 5991 | } |
| 5992 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5993 | /** |
| 5994 | * @hide |
| 5995 | */ |
| 5996 | public RemoteViews makeBigContentView() { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 5997 | // Remove the content text so it disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5998 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5999 | CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT); |
| 6000 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6001 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 6002 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource()); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 6003 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6004 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6005 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6006 | 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] | 6007 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6008 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 6009 | // Make sure all rows are gone in case we reuse a view. |
| 6010 | for (int rowId : rowIds) { |
| 6011 | contentView.setViewVisibility(rowId, View.GONE); |
| 6012 | } |
| 6013 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6014 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6015 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 6016 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6017 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6018 | int onlyViewId = 0; |
| 6019 | int maxRows = rowIds.length; |
| 6020 | if (mBuilder.mActions.size() > 0) { |
| 6021 | maxRows--; |
| 6022 | } |
| 6023 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6024 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6025 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6026 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 6027 | contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6028 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i]); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6029 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6030 | handleInboxImageMargin(contentView, rowIds[i], first); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6031 | if (first) { |
| 6032 | onlyViewId = rowIds[i]; |
| 6033 | } else { |
| 6034 | onlyViewId = 0; |
| 6035 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6036 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6037 | } |
| 6038 | i++; |
| 6039 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6040 | if (onlyViewId != 0) { |
| 6041 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 6042 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 6043 | R.dimen.notification_text_margin_top); |
| 6044 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 6045 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6046 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6047 | return contentView; |
| 6048 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6049 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6050 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6051 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6052 | if (first) { |
| 6053 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 6054 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 6055 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6056 | if (mBuilder.mN.hasLargeIcon() && !hasProgress) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6057 | endMargin = R.dimen.notification_content_picture_margin; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6058 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6059 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6060 | contentView.setViewLayoutMarginEndDimen(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6061 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6062 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6063 | |
| 6064 | /** |
| 6065 | * Notification style for media playback notifications. |
| 6066 | * |
| 6067 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 6068 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 6069 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6070 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 6071 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 6072 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6073 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6074 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 6075 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 6076 | * {@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] | 6077 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6078 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 6079 | * Notifications created with MediaStyle will have their category set to |
| 6080 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 6081 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6082 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6083 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 6084 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6085 | * the System UI can identify this as a notification representing an active media session |
| 6086 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 6087 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6088 | * <p> |
| 6089 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 6090 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 6091 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 6092 | * <p> |
| 6093 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6094 | * To use this style with your Notification, feed it to |
| 6095 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 6096 | * <pre class="prettyprint"> |
| 6097 | * Notification noti = new Notification.Builder() |
| 6098 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 6099 | * .setContentTitle("Track title") |
| 6100 | * .setContentText("Artist - Album") |
| 6101 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 6102 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 6103 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6104 | * .build(); |
| 6105 | * </pre> |
| 6106 | * |
| 6107 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6108 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6109 | */ |
| 6110 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6111 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6112 | static final int MAX_MEDIA_BUTTONS = 5; |
| 6113 | |
| 6114 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6115 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6116 | |
| 6117 | public MediaStyle() { |
| 6118 | } |
| 6119 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6120 | /** |
| 6121 | * @deprecated use {@code MediaStyle()}. |
| 6122 | */ |
| 6123 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6124 | public MediaStyle(Builder builder) { |
| 6125 | setBuilder(builder); |
| 6126 | } |
| 6127 | |
| 6128 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6129 | * 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] | 6130 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6131 | * |
| 6132 | * @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] | 6133 | */ |
| 6134 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 6135 | mActionsToShowInCompact = actions; |
| 6136 | return this; |
| 6137 | } |
| 6138 | |
| 6139 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6140 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 6141 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6142 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6143 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6144 | mToken = token; |
| 6145 | return this; |
| 6146 | } |
| 6147 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6148 | /** |
| 6149 | * @hide |
| 6150 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6151 | @Override |
| 6152 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6153 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 6154 | if (wip.category == null) { |
| 6155 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 6156 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6157 | return wip; |
| 6158 | } |
| 6159 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6160 | /** |
| 6161 | * @hide |
| 6162 | */ |
| 6163 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6164 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6165 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6166 | } |
| 6167 | |
| 6168 | /** |
| 6169 | * @hide |
| 6170 | */ |
| 6171 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6172 | public RemoteViews makeBigContentView() { |
| 6173 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6174 | } |
| 6175 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6176 | /** |
| 6177 | * @hide |
| 6178 | */ |
| 6179 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6180 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6181 | RemoteViews expanded = makeMediaBigContentView(); |
| 6182 | return expanded != null ? expanded : makeMediaContentView(); |
| 6183 | } |
| 6184 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6185 | /** @hide */ |
| 6186 | @Override |
| 6187 | public void addExtras(Bundle extras) { |
| 6188 | super.addExtras(extras); |
| 6189 | |
| 6190 | if (mToken != null) { |
| 6191 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 6192 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 6193 | if (mActionsToShowInCompact != null) { |
| 6194 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 6195 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6196 | } |
| 6197 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6198 | /** |
| 6199 | * @hide |
| 6200 | */ |
| 6201 | @Override |
| 6202 | protected void restoreFromExtras(Bundle extras) { |
| 6203 | super.restoreFromExtras(extras); |
| 6204 | |
| 6205 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 6206 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 6207 | } |
| 6208 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 6209 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 6210 | } |
| 6211 | } |
| 6212 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6213 | private RemoteViews generateMediaActionButton(Action action, int color) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6214 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 6215 | RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 6216 | R.layout.notification_material_media_action); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 6217 | button.setImageViewIcon(R.id.action0, action.getIcon()); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6218 | button.setDrawableParameters(R.id.action0, false, -1, color, PorterDuff.Mode.SRC_ATOP, |
| 6219 | -1); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6220 | if (!tombstone) { |
| 6221 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 6222 | } |
| 6223 | button.setContentDescription(R.id.action0, action.title); |
| 6224 | return button; |
| 6225 | } |
| 6226 | |
| 6227 | private RemoteViews makeMediaContentView() { |
| 6228 | RemoteViews view = mBuilder.applyStandardTemplate( |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6229 | R.layout.notification_template_material_media, false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6230 | |
| 6231 | final int numActions = mBuilder.mActions.size(); |
| 6232 | final int N = mActionsToShowInCompact == null |
| 6233 | ? 0 |
| 6234 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 6235 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6236 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6237 | for (int i = 0; i < N; i++) { |
| 6238 | if (i >= numActions) { |
| 6239 | throw new IllegalArgumentException(String.format( |
| 6240 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 6241 | i, numActions - 1)); |
| 6242 | } |
| 6243 | |
| 6244 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6245 | final RemoteViews button = generateMediaActionButton(action, |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6246 | getPrimaryHighlightColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6247 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6248 | } |
| 6249 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 6250 | handleImage(view); |
| 6251 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6252 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6253 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6254 | endMargin = R.dimen.notification_content_plus_picture_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 6255 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6256 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6257 | return view; |
| 6258 | } |
| 6259 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6260 | private int getPrimaryHighlightColor() { |
| 6261 | return mBuilder.getPrimaryHighlightColor(); |
| 6262 | } |
| 6263 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6264 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6265 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6266 | // Dont add an expanded view if there is no more content to be revealed |
| 6267 | int actionsInCompact = mActionsToShowInCompact == null |
| 6268 | ? 0 |
| 6269 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6270 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6271 | return null; |
| 6272 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6273 | RemoteViews big = mBuilder.applyStandardTemplate( |
| 6274 | R.layout.notification_template_material_big_media, |
| 6275 | false); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6276 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6277 | if (actionCount > 0) { |
| 6278 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 6279 | for (int i = 0; i < actionCount; i++) { |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6280 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i), |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6281 | getPrimaryHighlightColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6282 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6283 | } |
| 6284 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6285 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6286 | return big; |
| 6287 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6288 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6289 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6290 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6291 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 6292 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6293 | } |
| 6294 | } |
| 6295 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6296 | /** |
| 6297 | * @hide |
| 6298 | */ |
| 6299 | @Override |
| 6300 | protected boolean hasProgress() { |
| 6301 | return false; |
| 6302 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6303 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6304 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6305 | /** |
| 6306 | * Notification style for custom views that are decorated by the system |
| 6307 | * |
| 6308 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 6309 | * style and still obtain system decorations like the notification header with the expand |
| 6310 | * affordance and actions. |
| 6311 | * |
| 6312 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 6313 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 6314 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 6315 | * corresponding custom views to display. |
| 6316 | * |
| 6317 | * To use this style with your Notification, feed it to |
| 6318 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 6319 | * <pre class="prettyprint"> |
| 6320 | * Notification noti = new Notification.Builder() |
| 6321 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 6322 | * .setLargeIcon(albumArtBitmap)) |
| 6323 | * .setCustomContentView(contentView); |
| 6324 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 6325 | * .build(); |
| 6326 | * </pre> |
| 6327 | */ |
| 6328 | public static class DecoratedCustomViewStyle extends Style { |
| 6329 | |
| 6330 | public DecoratedCustomViewStyle() { |
| 6331 | } |
| 6332 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6333 | /** |
| 6334 | * @hide |
| 6335 | */ |
| 6336 | public boolean displayCustomViewInline() { |
| 6337 | return true; |
| 6338 | } |
| 6339 | |
| 6340 | /** |
| 6341 | * @hide |
| 6342 | */ |
| 6343 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6344 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6345 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 6346 | } |
| 6347 | |
| 6348 | /** |
| 6349 | * @hide |
| 6350 | */ |
| 6351 | @Override |
| 6352 | public RemoteViews makeBigContentView() { |
| 6353 | return makeDecoratedBigContentView(); |
| 6354 | } |
| 6355 | |
| 6356 | /** |
| 6357 | * @hide |
| 6358 | */ |
| 6359 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6360 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6361 | return makeDecoratedHeadsUpContentView(); |
| 6362 | } |
| 6363 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6364 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 6365 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 6366 | ? mBuilder.mN.contentView |
| 6367 | : mBuilder.mN.headsUpContentView; |
| 6368 | if (mBuilder.mActions.size() == 0) { |
| 6369 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 6370 | } |
| 6371 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 6372 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6373 | buildIntoRemoteViewContent(remoteViews, headsUpContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6374 | return remoteViews; |
| 6375 | } |
| 6376 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6377 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
| 6378 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
| 6379 | mBuilder.getBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6380 | buildIntoRemoteViewContent(remoteViews, customContent); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6381 | return remoteViews; |
| 6382 | } |
| 6383 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6384 | private RemoteViews makeDecoratedBigContentView() { |
| 6385 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 6386 | ? mBuilder.mN.contentView |
| 6387 | : mBuilder.mN.bigContentView; |
| 6388 | if (mBuilder.mActions.size() == 0) { |
| 6389 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 6390 | } |
| 6391 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 6392 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6393 | buildIntoRemoteViewContent(remoteViews, bigContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6394 | return remoteViews; |
| 6395 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6396 | |
| 6397 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
| 6398 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6399 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6400 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 6401 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6402 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6403 | remoteViews.removeAllViews(R.id.notification_main_column); |
| 6404 | remoteViews.addView(R.id.notification_main_column, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6405 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6406 | // also update the end margin if there is an image |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6407 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6408 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6409 | endMargin = R.dimen.notification_content_plus_picture_margin_end; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6410 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6411 | remoteViews.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6412 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6413 | } |
| 6414 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6415 | /** |
| 6416 | * Notification style for media custom views that are decorated by the system |
| 6417 | * |
| 6418 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 6419 | * this style and still obtain system decorations like the notification header with the expand |
| 6420 | * affordance and actions. |
| 6421 | * |
| 6422 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 6423 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 6424 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 6425 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6426 | * <p> |
| 6427 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 6428 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 6429 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6430 | * To use this style with your Notification, feed it to |
| 6431 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 6432 | * <pre class="prettyprint"> |
| 6433 | * Notification noti = new Notification.Builder() |
| 6434 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 6435 | * .setLargeIcon(albumArtBitmap)) |
| 6436 | * .setCustomContentView(contentView); |
| 6437 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 6438 | * .setMediaSession(mySession)) |
| 6439 | * .build(); |
| 6440 | * </pre> |
| 6441 | * |
| 6442 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 6443 | * @see android.app.Notification.MediaStyle |
| 6444 | */ |
| 6445 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 6446 | |
| 6447 | public DecoratedMediaCustomViewStyle() { |
| 6448 | } |
| 6449 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6450 | /** |
| 6451 | * @hide |
| 6452 | */ |
| 6453 | public boolean displayCustomViewInline() { |
| 6454 | return true; |
| 6455 | } |
| 6456 | |
| 6457 | /** |
| 6458 | * @hide |
| 6459 | */ |
| 6460 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6461 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6462 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6463 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 6464 | mBuilder.mN.contentView); |
| 6465 | } |
| 6466 | |
| 6467 | /** |
| 6468 | * @hide |
| 6469 | */ |
| 6470 | @Override |
| 6471 | public RemoteViews makeBigContentView() { |
| 6472 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 6473 | ? mBuilder.mN.bigContentView |
| 6474 | : mBuilder.mN.contentView; |
| 6475 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 6476 | } |
| 6477 | |
| 6478 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 6479 | RemoteViews remoteViews = super.makeBigContentView(); |
| 6480 | if (remoteViews != null) { |
| 6481 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 6482 | customRemoteView); |
| 6483 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6484 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6485 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 6486 | customRemoteView); |
| 6487 | } else { |
| 6488 | return null; |
| 6489 | } |
| 6490 | } |
| 6491 | |
| 6492 | /** |
| 6493 | * @hide |
| 6494 | */ |
| 6495 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6496 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6497 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 6498 | ? mBuilder.mN.headsUpContentView |
| 6499 | : mBuilder.mN.contentView; |
| 6500 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 6501 | } |
| 6502 | |
| 6503 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 6504 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6505 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6506 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 6507 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6508 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6509 | remoteViews.removeAllViews(id); |
| 6510 | remoteViews.addView(id, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6511 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6512 | return remoteViews; |
| 6513 | } |
| 6514 | } |
| 6515 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6516 | // When adding a new Style subclass here, don't forget to update |
| 6517 | // Builder.getNotificationStyleClass. |
| 6518 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6519 | /** |
| 6520 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 6521 | * metadata or change options on a notification builder. |
| 6522 | */ |
| 6523 | public interface Extender { |
| 6524 | /** |
| 6525 | * Apply this extender to a notification builder. |
| 6526 | * @param builder the builder to be modified. |
| 6527 | * @return the build object for chaining. |
| 6528 | */ |
| 6529 | public Builder extend(Builder builder); |
| 6530 | } |
| 6531 | |
| 6532 | /** |
| 6533 | * Helper class to add wearable extensions to notifications. |
| 6534 | * <p class="note"> See |
| 6535 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 6536 | * for Android Wear</a> for more information on how to use this class. |
| 6537 | * <p> |
| 6538 | * To create a notification with wearable extensions: |
| 6539 | * <ol> |
| 6540 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 6541 | * properties. |
| 6542 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 6543 | * <li>Set wearable-specific properties using the |
| 6544 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 6545 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 6546 | * notification. |
| 6547 | * <li>Post the notification to the notification system with the |
| 6548 | * {@code NotificationManager.notify(...)} methods. |
| 6549 | * </ol> |
| 6550 | * |
| 6551 | * <pre class="prettyprint"> |
| 6552 | * Notification notif = new Notification.Builder(mContext) |
| 6553 | * .setContentTitle("New mail from " + sender.toString()) |
| 6554 | * .setContentText(subject) |
| 6555 | * .setSmallIcon(R.drawable.new_mail) |
| 6556 | * .extend(new Notification.WearableExtender() |
| 6557 | * .setContentIcon(R.drawable.new_mail)) |
| 6558 | * .build(); |
| 6559 | * NotificationManager notificationManger = |
| 6560 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 6561 | * notificationManger.notify(0, notif);</pre> |
| 6562 | * |
| 6563 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 6564 | * {@code WearableExtender(Notification)} constructor, |
| 6565 | * and then using the {@code get} methods to access values. |
| 6566 | * |
| 6567 | * <pre class="prettyprint"> |
| 6568 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 6569 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 6570 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6571 | */ |
| 6572 | public static final class WearableExtender implements Extender { |
| 6573 | /** |
| 6574 | * Sentinel value for an action index that is unset. |
| 6575 | */ |
| 6576 | public static final int UNSET_ACTION_INDEX = -1; |
| 6577 | |
| 6578 | /** |
| 6579 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 6580 | * default sizing. |
| 6581 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 6582 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6583 | * on their content. |
| 6584 | */ |
| 6585 | public static final int SIZE_DEFAULT = 0; |
| 6586 | |
| 6587 | /** |
| 6588 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 6589 | * with an extra small size. |
| 6590 | * <p>This value is only applicable for custom display notifications created using |
| 6591 | * {@link #setDisplayIntent}. |
| 6592 | */ |
| 6593 | public static final int SIZE_XSMALL = 1; |
| 6594 | |
| 6595 | /** |
| 6596 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 6597 | * with a small size. |
| 6598 | * <p>This value is only applicable for custom display notifications created using |
| 6599 | * {@link #setDisplayIntent}. |
| 6600 | */ |
| 6601 | public static final int SIZE_SMALL = 2; |
| 6602 | |
| 6603 | /** |
| 6604 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 6605 | * with a medium size. |
| 6606 | * <p>This value is only applicable for custom display notifications created using |
| 6607 | * {@link #setDisplayIntent}. |
| 6608 | */ |
| 6609 | public static final int SIZE_MEDIUM = 3; |
| 6610 | |
| 6611 | /** |
| 6612 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 6613 | * with a large size. |
| 6614 | * <p>This value is only applicable for custom display notifications created using |
| 6615 | * {@link #setDisplayIntent}. |
| 6616 | */ |
| 6617 | public static final int SIZE_LARGE = 4; |
| 6618 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 6619 | /** |
| 6620 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 6621 | * full screen. |
| 6622 | * <p>This value is only applicable for custom display notifications created using |
| 6623 | * {@link #setDisplayIntent}. |
| 6624 | */ |
| 6625 | public static final int SIZE_FULL_SCREEN = 5; |
| 6626 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6627 | /** |
| 6628 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 6629 | * short amount of time when this notification is displayed on the screen. This |
| 6630 | * is the default value. |
| 6631 | */ |
| 6632 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 6633 | |
| 6634 | /** |
| 6635 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 6636 | * for a longer amount of time when this notification is displayed on the screen. |
| 6637 | */ |
| 6638 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 6639 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6640 | /** Notification extra which contains wearable extensions */ |
| 6641 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 6642 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 6643 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6644 | private static final String KEY_ACTIONS = "actions"; |
| 6645 | private static final String KEY_FLAGS = "flags"; |
| 6646 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 6647 | private static final String KEY_PAGES = "pages"; |
| 6648 | private static final String KEY_BACKGROUND = "background"; |
| 6649 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 6650 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 6651 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 6652 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 6653 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 6654 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6655 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 6656 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 6657 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6658 | |
| 6659 | // Flags bitwise-ored to mFlags |
| 6660 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 6661 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 6662 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 6663 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6664 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 6665 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 6666 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6667 | |
| 6668 | // Default value for flags integer |
| 6669 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 6670 | |
| 6671 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 6672 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 6673 | |
| 6674 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 6675 | private int mFlags = DEFAULT_FLAGS; |
| 6676 | private PendingIntent mDisplayIntent; |
| 6677 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 6678 | private Bitmap mBackground; |
| 6679 | private int mContentIcon; |
| 6680 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 6681 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 6682 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 6683 | private int mCustomContentHeight; |
| 6684 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6685 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 6686 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 6687 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6688 | |
| 6689 | /** |
| 6690 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 6691 | * options. |
| 6692 | */ |
| 6693 | public WearableExtender() { |
| 6694 | } |
| 6695 | |
| 6696 | public WearableExtender(Notification notif) { |
| 6697 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 6698 | if (wearableBundle != null) { |
| 6699 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 6700 | if (actions != null) { |
| 6701 | mActions.addAll(actions); |
| 6702 | } |
| 6703 | |
| 6704 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 6705 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 6706 | |
| 6707 | Notification[] pages = getNotificationArrayFromBundle( |
| 6708 | wearableBundle, KEY_PAGES); |
| 6709 | if (pages != null) { |
| 6710 | Collections.addAll(mPages, pages); |
| 6711 | } |
| 6712 | |
| 6713 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 6714 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 6715 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 6716 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 6717 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 6718 | UNSET_ACTION_INDEX); |
| 6719 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 6720 | SIZE_DEFAULT); |
| 6721 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 6722 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6723 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 6724 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 6725 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6726 | } |
| 6727 | } |
| 6728 | |
| 6729 | /** |
| 6730 | * Apply wearable extensions to a notification that is being built. This is typically |
| 6731 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 6732 | * {@link android.app.Notification.Builder}. |
| 6733 | */ |
| 6734 | @Override |
| 6735 | public Notification.Builder extend(Notification.Builder builder) { |
| 6736 | Bundle wearableBundle = new Bundle(); |
| 6737 | |
| 6738 | if (!mActions.isEmpty()) { |
| 6739 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 6740 | } |
| 6741 | if (mFlags != DEFAULT_FLAGS) { |
| 6742 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 6743 | } |
| 6744 | if (mDisplayIntent != null) { |
| 6745 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 6746 | } |
| 6747 | if (!mPages.isEmpty()) { |
| 6748 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 6749 | new Notification[mPages.size()])); |
| 6750 | } |
| 6751 | if (mBackground != null) { |
| 6752 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 6753 | } |
| 6754 | if (mContentIcon != 0) { |
| 6755 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 6756 | } |
| 6757 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 6758 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 6759 | } |
| 6760 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 6761 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 6762 | mContentActionIndex); |
| 6763 | } |
| 6764 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 6765 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 6766 | } |
| 6767 | if (mCustomContentHeight != 0) { |
| 6768 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 6769 | } |
| 6770 | if (mGravity != DEFAULT_GRAVITY) { |
| 6771 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 6772 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6773 | if (mHintScreenTimeout != 0) { |
| 6774 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 6775 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 6776 | if (mDismissalId != null) { |
| 6777 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 6778 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 6779 | if (mBridgeTag != null) { |
| 6780 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 6781 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6782 | |
| 6783 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 6784 | return builder; |
| 6785 | } |
| 6786 | |
| 6787 | @Override |
| 6788 | public WearableExtender clone() { |
| 6789 | WearableExtender that = new WearableExtender(); |
| 6790 | that.mActions = new ArrayList<Action>(this.mActions); |
| 6791 | that.mFlags = this.mFlags; |
| 6792 | that.mDisplayIntent = this.mDisplayIntent; |
| 6793 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 6794 | that.mBackground = this.mBackground; |
| 6795 | that.mContentIcon = this.mContentIcon; |
| 6796 | that.mContentIconGravity = this.mContentIconGravity; |
| 6797 | that.mContentActionIndex = this.mContentActionIndex; |
| 6798 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 6799 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 6800 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6801 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 6802 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 6803 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6804 | return that; |
| 6805 | } |
| 6806 | |
| 6807 | /** |
| 6808 | * Add a wearable action to this notification. |
| 6809 | * |
| 6810 | * <p>When wearable actions are added using this method, the set of actions that |
| 6811 | * show on a wearable device splits from devices that only show actions added |
| 6812 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 6813 | * of which actions display on different devices. |
| 6814 | * |
| 6815 | * @param action the action to add to this notification |
| 6816 | * @return this object for method chaining |
| 6817 | * @see android.app.Notification.Action |
| 6818 | */ |
| 6819 | public WearableExtender addAction(Action action) { |
| 6820 | mActions.add(action); |
| 6821 | return this; |
| 6822 | } |
| 6823 | |
| 6824 | /** |
| 6825 | * Adds wearable actions to this notification. |
| 6826 | * |
| 6827 | * <p>When wearable actions are added using this method, the set of actions that |
| 6828 | * show on a wearable device splits from devices that only show actions added |
| 6829 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 6830 | * of which actions display on different devices. |
| 6831 | * |
| 6832 | * @param actions the actions to add to this notification |
| 6833 | * @return this object for method chaining |
| 6834 | * @see android.app.Notification.Action |
| 6835 | */ |
| 6836 | public WearableExtender addActions(List<Action> actions) { |
| 6837 | mActions.addAll(actions); |
| 6838 | return this; |
| 6839 | } |
| 6840 | |
| 6841 | /** |
| 6842 | * Clear all wearable actions present on this builder. |
| 6843 | * @return this object for method chaining. |
| 6844 | * @see #addAction |
| 6845 | */ |
| 6846 | public WearableExtender clearActions() { |
| 6847 | mActions.clear(); |
| 6848 | return this; |
| 6849 | } |
| 6850 | |
| 6851 | /** |
| 6852 | * Get the wearable actions present on this notification. |
| 6853 | */ |
| 6854 | public List<Action> getActions() { |
| 6855 | return mActions; |
| 6856 | } |
| 6857 | |
| 6858 | /** |
| 6859 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 6860 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 6861 | * |
| 6862 | * <pre class="prettyprint"> |
| 6863 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 6864 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 6865 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 6866 | * Notification notif = new Notification.Builder(context) |
| 6867 | * .extend(new Notification.WearableExtender() |
| 6868 | * .setDisplayIntent(displayPendingIntent) |
| 6869 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 6870 | * .build();</pre> |
| 6871 | * |
| 6872 | * <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] | 6873 | * should have an empty task affinity. It is also recommended to use the device |
| 6874 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 6875 | * |
| 6876 | * <p>Example AndroidManifest.xml entry: |
| 6877 | * <pre class="prettyprint"> |
| 6878 | * <activity android:name="com.example.MyDisplayActivity" |
| 6879 | * android:exported="true" |
| 6880 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 6881 | * android:taskAffinity="" |
| 6882 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6883 | * |
| 6884 | * @param intent the {@link PendingIntent} for an activity |
| 6885 | * @return this object for method chaining |
| 6886 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 6887 | */ |
| 6888 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 6889 | mDisplayIntent = intent; |
| 6890 | return this; |
| 6891 | } |
| 6892 | |
| 6893 | /** |
| 6894 | * Get the intent to launch inside of an activity view when displaying this |
| 6895 | * notification. This {@code PendingIntent} should be for an activity. |
| 6896 | */ |
| 6897 | public PendingIntent getDisplayIntent() { |
| 6898 | return mDisplayIntent; |
| 6899 | } |
| 6900 | |
| 6901 | /** |
| 6902 | * Add an additional page of content to display with this notification. The current |
| 6903 | * notification forms the first page, and pages added using this function form |
| 6904 | * subsequent pages. This field can be used to separate a notification into multiple |
| 6905 | * sections. |
| 6906 | * |
| 6907 | * @param page the notification to add as another page |
| 6908 | * @return this object for method chaining |
| 6909 | * @see android.app.Notification.WearableExtender#getPages |
| 6910 | */ |
| 6911 | public WearableExtender addPage(Notification page) { |
| 6912 | mPages.add(page); |
| 6913 | return this; |
| 6914 | } |
| 6915 | |
| 6916 | /** |
| 6917 | * Add additional pages of content to display with this notification. The current |
| 6918 | * notification forms the first page, and pages added using this function form |
| 6919 | * subsequent pages. This field can be used to separate a notification into multiple |
| 6920 | * sections. |
| 6921 | * |
| 6922 | * @param pages a list of notifications |
| 6923 | * @return this object for method chaining |
| 6924 | * @see android.app.Notification.WearableExtender#getPages |
| 6925 | */ |
| 6926 | public WearableExtender addPages(List<Notification> pages) { |
| 6927 | mPages.addAll(pages); |
| 6928 | return this; |
| 6929 | } |
| 6930 | |
| 6931 | /** |
| 6932 | * Clear all additional pages present on this builder. |
| 6933 | * @return this object for method chaining. |
| 6934 | * @see #addPage |
| 6935 | */ |
| 6936 | public WearableExtender clearPages() { |
| 6937 | mPages.clear(); |
| 6938 | return this; |
| 6939 | } |
| 6940 | |
| 6941 | /** |
| 6942 | * Get the array of additional pages of content for displaying this notification. The |
| 6943 | * current notification forms the first page, and elements within this array form |
| 6944 | * subsequent pages. This field can be used to separate a notification into multiple |
| 6945 | * sections. |
| 6946 | * @return the pages for this notification |
| 6947 | */ |
| 6948 | public List<Notification> getPages() { |
| 6949 | return mPages; |
| 6950 | } |
| 6951 | |
| 6952 | /** |
| 6953 | * Set a background image to be displayed behind the notification content. |
| 6954 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 6955 | * will work with any notification style. |
| 6956 | * |
| 6957 | * @param background the background bitmap |
| 6958 | * @return this object for method chaining |
| 6959 | * @see android.app.Notification.WearableExtender#getBackground |
| 6960 | */ |
| 6961 | public WearableExtender setBackground(Bitmap background) { |
| 6962 | mBackground = background; |
| 6963 | return this; |
| 6964 | } |
| 6965 | |
| 6966 | /** |
| 6967 | * Get a background image to be displayed behind the notification content. |
| 6968 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 6969 | * will work with any notification style. |
| 6970 | * |
| 6971 | * @return the background image |
| 6972 | * @see android.app.Notification.WearableExtender#setBackground |
| 6973 | */ |
| 6974 | public Bitmap getBackground() { |
| 6975 | return mBackground; |
| 6976 | } |
| 6977 | |
| 6978 | /** |
| 6979 | * Set an icon that goes with the content of this notification. |
| 6980 | */ |
| 6981 | public WearableExtender setContentIcon(int icon) { |
| 6982 | mContentIcon = icon; |
| 6983 | return this; |
| 6984 | } |
| 6985 | |
| 6986 | /** |
| 6987 | * Get an icon that goes with the content of this notification. |
| 6988 | */ |
| 6989 | public int getContentIcon() { |
| 6990 | return mContentIcon; |
| 6991 | } |
| 6992 | |
| 6993 | /** |
| 6994 | * Set the gravity that the content icon should have within the notification display. |
| 6995 | * Supported values include {@link android.view.Gravity#START} and |
| 6996 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 6997 | * @see #setContentIcon |
| 6998 | */ |
| 6999 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 7000 | mContentIconGravity = contentIconGravity; |
| 7001 | return this; |
| 7002 | } |
| 7003 | |
| 7004 | /** |
| 7005 | * Get the gravity that the content icon should have within the notification display. |
| 7006 | * Supported values include {@link android.view.Gravity#START} and |
| 7007 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 7008 | * @see #getContentIcon |
| 7009 | */ |
| 7010 | public int getContentIconGravity() { |
| 7011 | return mContentIconGravity; |
| 7012 | } |
| 7013 | |
| 7014 | /** |
| 7015 | * 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] | 7016 | * this notification. This action will no longer display separately from the |
| 7017 | * notification's content. |
| 7018 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 7019 | * <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] | 7020 | * set, although the list of available actions comes from the main notification and not |
| 7021 | * from the child page's notification. |
| 7022 | * |
| 7023 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 7024 | * If wearable actions were added to the main notification, this index |
| 7025 | * will apply to that list, otherwise it will apply to the regular |
| 7026 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7027 | */ |
| 7028 | public WearableExtender setContentAction(int actionIndex) { |
| 7029 | mContentActionIndex = actionIndex; |
| 7030 | return this; |
| 7031 | } |
| 7032 | |
| 7033 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 7034 | * Get the index of the notification action, if any, that was specified as being clickable |
| 7035 | * 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] | 7036 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7037 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 7038 | * <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] | 7039 | * set, although the list of available actions comes from the main notification and not |
| 7040 | * from the child page's notification. |
| 7041 | * |
| 7042 | * <p>If wearable specific actions were added to the main notification, this index will |
| 7043 | * 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] | 7044 | * |
| 7045 | * @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] | 7046 | */ |
| 7047 | public int getContentAction() { |
| 7048 | return mContentActionIndex; |
| 7049 | } |
| 7050 | |
| 7051 | /** |
| 7052 | * Set the gravity that this notification should have within the available viewport space. |
| 7053 | * Supported values include {@link android.view.Gravity#TOP}, |
| 7054 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 7055 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 7056 | */ |
| 7057 | public WearableExtender setGravity(int gravity) { |
| 7058 | mGravity = gravity; |
| 7059 | return this; |
| 7060 | } |
| 7061 | |
| 7062 | /** |
| 7063 | * Get the gravity that this notification should have within the available viewport space. |
| 7064 | * Supported values include {@link android.view.Gravity#TOP}, |
| 7065 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 7066 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 7067 | */ |
| 7068 | public int getGravity() { |
| 7069 | return mGravity; |
| 7070 | } |
| 7071 | |
| 7072 | /** |
| 7073 | * Set the custom size preset for the display of this notification out of the available |
| 7074 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 7075 | * {@link #SIZE_LARGE}. |
| 7076 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 7077 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 7078 | * documentation for the preset in question. See also |
| 7079 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 7080 | */ |
| 7081 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 7082 | mCustomSizePreset = sizePreset; |
| 7083 | return this; |
| 7084 | } |
| 7085 | |
| 7086 | /** |
| 7087 | * Get the custom size preset for the display of this notification out of the available |
| 7088 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 7089 | * {@link #SIZE_LARGE}. |
| 7090 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 7091 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 7092 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 7093 | */ |
| 7094 | public int getCustomSizePreset() { |
| 7095 | return mCustomSizePreset; |
| 7096 | } |
| 7097 | |
| 7098 | /** |
| 7099 | * Set the custom height in pixels for the display of this notification's content. |
| 7100 | * <p>This option is only available for custom display notifications created |
| 7101 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 7102 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 7103 | * {@link #getCustomContentHeight}. |
| 7104 | */ |
| 7105 | public WearableExtender setCustomContentHeight(int height) { |
| 7106 | mCustomContentHeight = height; |
| 7107 | return this; |
| 7108 | } |
| 7109 | |
| 7110 | /** |
| 7111 | * Get the custom height in pixels for the display of this notification's content. |
| 7112 | * <p>This option is only available for custom display notifications created |
| 7113 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 7114 | * {@link #setCustomContentHeight}. |
| 7115 | */ |
| 7116 | public int getCustomContentHeight() { |
| 7117 | return mCustomContentHeight; |
| 7118 | } |
| 7119 | |
| 7120 | /** |
| 7121 | * Set whether the scrolling position for the contents of this notification should start |
| 7122 | * at the bottom of the contents instead of the top when the contents are too long to |
| 7123 | * display within the screen. Default is false (start scroll at the top). |
| 7124 | */ |
| 7125 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 7126 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 7127 | return this; |
| 7128 | } |
| 7129 | |
| 7130 | /** |
| 7131 | * Get whether the scrolling position for the contents of this notification should start |
| 7132 | * at the bottom of the contents instead of the top when the contents are too long to |
| 7133 | * display within the screen. Default is false (start scroll at the top). |
| 7134 | */ |
| 7135 | public boolean getStartScrollBottom() { |
| 7136 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 7137 | } |
| 7138 | |
| 7139 | /** |
| 7140 | * Set whether the content intent is available when the wearable device is not connected |
| 7141 | * to a companion device. The user can still trigger this intent when the wearable device |
| 7142 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 7143 | * Defaults to true. |
| 7144 | */ |
| 7145 | public WearableExtender setContentIntentAvailableOffline( |
| 7146 | boolean contentIntentAvailableOffline) { |
| 7147 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 7148 | return this; |
| 7149 | } |
| 7150 | |
| 7151 | /** |
| 7152 | * Get whether the content intent is available when the wearable device is not connected |
| 7153 | * to a companion device. The user can still trigger this intent when the wearable device |
| 7154 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 7155 | * Defaults to true. |
| 7156 | */ |
| 7157 | public boolean getContentIntentAvailableOffline() { |
| 7158 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 7159 | } |
| 7160 | |
| 7161 | /** |
| 7162 | * Set a hint that this notification's icon should not be displayed. |
| 7163 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 7164 | * @return this object for method chaining |
| 7165 | */ |
| 7166 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 7167 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 7168 | return this; |
| 7169 | } |
| 7170 | |
| 7171 | /** |
| 7172 | * Get a hint that this notification's icon should not be displayed. |
| 7173 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 7174 | * The default value is {@code false} if this was never set. |
| 7175 | */ |
| 7176 | public boolean getHintHideIcon() { |
| 7177 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 7178 | } |
| 7179 | |
| 7180 | /** |
| 7181 | * Set a visual hint that only the background image of this notification should be |
| 7182 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 7183 | * to sub-pages added using {@link #addPage}. |
| 7184 | */ |
| 7185 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 7186 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 7187 | return this; |
| 7188 | } |
| 7189 | |
| 7190 | /** |
| 7191 | * Get a visual hint that only the background image of this notification should be |
| 7192 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 7193 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 7194 | */ |
| 7195 | public boolean getHintShowBackgroundOnly() { |
| 7196 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 7197 | } |
| 7198 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7199 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 7200 | * Set a hint that this notification's background should not be clipped if possible, |
| 7201 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 7202 | * 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] | 7203 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 7204 | * @return this object for method chaining |
| 7205 | */ |
| 7206 | public WearableExtender setHintAvoidBackgroundClipping( |
| 7207 | boolean hintAvoidBackgroundClipping) { |
| 7208 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 7209 | return this; |
| 7210 | } |
| 7211 | |
| 7212 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 7213 | * Get a hint that this notification's background should not be clipped if possible, |
| 7214 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 7215 | * 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] | 7216 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 7217 | * otherwise. The default value is {@code false} if this was never set. |
| 7218 | */ |
| 7219 | public boolean getHintAvoidBackgroundClipping() { |
| 7220 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 7221 | } |
| 7222 | |
| 7223 | /** |
| 7224 | * Set a hint that the screen should remain on for at least this duration when |
| 7225 | * this notification is displayed on the screen. |
| 7226 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 7227 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 7228 | * @return this object for method chaining |
| 7229 | */ |
| 7230 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 7231 | mHintScreenTimeout = timeout; |
| 7232 | return this; |
| 7233 | } |
| 7234 | |
| 7235 | /** |
| 7236 | * Get the duration, in milliseconds, that the screen should remain on for |
| 7237 | * when this notification is displayed. |
| 7238 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 7239 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 7240 | */ |
| 7241 | public int getHintScreenTimeout() { |
| 7242 | return mHintScreenTimeout; |
| 7243 | } |
| 7244 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 7245 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 7246 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 7247 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 7248 | * qr codes, as well as other simple black-and-white tickets. |
| 7249 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 7250 | * @return this object for method chaining |
| 7251 | */ |
| 7252 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 7253 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 7254 | return this; |
| 7255 | } |
| 7256 | |
| 7257 | /** |
| 7258 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 7259 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 7260 | * qr codes, as well as other simple black-and-white tickets. |
| 7261 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 7262 | * otherwise. The default value is {@code false} if this was never set. |
| 7263 | */ |
| 7264 | public boolean getHintAmbientBigPicture() { |
| 7265 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 7266 | } |
| 7267 | |
| 7268 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 7269 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 7270 | * directly, telling the platform that it can generate the appropriate transitions. |
| 7271 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 7272 | * an activity and transitions should be generated, false otherwise. |
| 7273 | * @return this object for method chaining |
| 7274 | */ |
| 7275 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 7276 | boolean hintContentIntentLaunchesActivity) { |
| 7277 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 7278 | return this; |
| 7279 | } |
| 7280 | |
| 7281 | /** |
| 7282 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 7283 | * directly, telling the platform that it can generate the appropriate transitions |
| 7284 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 7285 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 7286 | */ |
| 7287 | public boolean getHintContentIntentLaunchesActivity() { |
| 7288 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 7289 | } |
| 7290 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7291 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7292 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 7293 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 7294 | * 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] | 7295 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7296 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7297 | * @param dismissalId the dismissal id of the notification. |
| 7298 | * @return this object for method chaining |
| 7299 | */ |
| 7300 | public WearableExtender setDismissalId(String dismissalId) { |
| 7301 | mDismissalId = dismissalId; |
| 7302 | return this; |
| 7303 | } |
| 7304 | |
| 7305 | /** |
| 7306 | * Returns the dismissal id of the notification. |
| 7307 | * @return the dismissal id of the notification or null if it has not been set. |
| 7308 | */ |
| 7309 | public String getDismissalId() { |
| 7310 | return mDismissalId; |
| 7311 | } |
| 7312 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7313 | /** |
| 7314 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 7315 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 7316 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 7317 | * Features to Notifications</a> for more information. |
| 7318 | * @param bridgeTag the bridge tag of the notification. |
| 7319 | * @return this object for method chaining |
| 7320 | */ |
| 7321 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 7322 | mBridgeTag = bridgeTag; |
| 7323 | return this; |
| 7324 | } |
| 7325 | |
| 7326 | /** |
| 7327 | * Returns the bridge tag of the notification. |
| 7328 | * @return the bridge tag or null if not present. |
| 7329 | */ |
| 7330 | public String getBridgeTag() { |
| 7331 | return mBridgeTag; |
| 7332 | } |
| 7333 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7334 | private void setFlag(int mask, boolean value) { |
| 7335 | if (value) { |
| 7336 | mFlags |= mask; |
| 7337 | } else { |
| 7338 | mFlags &= ~mask; |
| 7339 | } |
| 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7344 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 7345 | * with car extensions: |
| 7346 | * |
| 7347 | * <ol> |
| 7348 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 7349 | * properties. |
| 7350 | * <li>Create a {@link CarExtender}. |
| 7351 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 7352 | * {@link CarExtender}. |
| 7353 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 7354 | * to apply the extensions to a notification. |
| 7355 | * </ol> |
| 7356 | * |
| 7357 | * <pre class="prettyprint"> |
| 7358 | * Notification notification = new Notification.Builder(context) |
| 7359 | * ... |
| 7360 | * .extend(new CarExtender() |
| 7361 | * .set*(...)) |
| 7362 | * .build(); |
| 7363 | * </pre> |
| 7364 | * |
| 7365 | * <p>Car extensions can be accessed on an existing notification by using the |
| 7366 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 7367 | * to access values. |
| 7368 | */ |
| 7369 | public static final class CarExtender implements Extender { |
| 7370 | private static final String TAG = "CarExtender"; |
| 7371 | |
| 7372 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 7373 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 7374 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 7375 | private static final String EXTRA_COLOR = "app_color"; |
| 7376 | |
| 7377 | private Bitmap mLargeIcon; |
| 7378 | private UnreadConversation mUnreadConversation; |
| 7379 | private int mColor = Notification.COLOR_DEFAULT; |
| 7380 | |
| 7381 | /** |
| 7382 | * Create a {@link CarExtender} with default options. |
| 7383 | */ |
| 7384 | public CarExtender() { |
| 7385 | } |
| 7386 | |
| 7387 | /** |
| 7388 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 7389 | * |
| 7390 | * @param notif The notification from which to copy options. |
| 7391 | */ |
| 7392 | public CarExtender(Notification notif) { |
| 7393 | Bundle carBundle = notif.extras == null ? |
| 7394 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 7395 | if (carBundle != null) { |
| 7396 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 7397 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 7398 | |
| 7399 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 7400 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 7401 | } |
| 7402 | } |
| 7403 | |
| 7404 | /** |
| 7405 | * Apply car extensions to a notification that is being built. This is typically called by |
| 7406 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 7407 | * method of {@link Notification.Builder}. |
| 7408 | */ |
| 7409 | @Override |
| 7410 | public Notification.Builder extend(Notification.Builder builder) { |
| 7411 | Bundle carExtensions = new Bundle(); |
| 7412 | |
| 7413 | if (mLargeIcon != null) { |
| 7414 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 7415 | } |
| 7416 | if (mColor != Notification.COLOR_DEFAULT) { |
| 7417 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 7418 | } |
| 7419 | |
| 7420 | if (mUnreadConversation != null) { |
| 7421 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 7422 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 7423 | } |
| 7424 | |
| 7425 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 7426 | return builder; |
| 7427 | } |
| 7428 | |
| 7429 | /** |
| 7430 | * Sets the accent color to use when Android Auto presents the notification. |
| 7431 | * |
| 7432 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 7433 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 7434 | * automotive setting. This method can be used to override the color provided in the |
| 7435 | * notification in such a situation. |
| 7436 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 7437 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7438 | mColor = color; |
| 7439 | return this; |
| 7440 | } |
| 7441 | |
| 7442 | /** |
| 7443 | * Gets the accent color. |
| 7444 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7445 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7446 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 7447 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7448 | public int getColor() { |
| 7449 | return mColor; |
| 7450 | } |
| 7451 | |
| 7452 | /** |
| 7453 | * Sets the large icon of the car notification. |
| 7454 | * |
| 7455 | * If no large icon is set in the extender, Android Auto will display the icon |
| 7456 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 7457 | * |
| 7458 | * @param largeIcon The large icon to use in the car notification. |
| 7459 | * @return This object for method chaining. |
| 7460 | */ |
| 7461 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 7462 | mLargeIcon = largeIcon; |
| 7463 | return this; |
| 7464 | } |
| 7465 | |
| 7466 | /** |
| 7467 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 7468 | * |
| 7469 | * @return The large icon for the car notification. |
| 7470 | * @see CarExtender#setLargeIcon |
| 7471 | */ |
| 7472 | public Bitmap getLargeIcon() { |
| 7473 | return mLargeIcon; |
| 7474 | } |
| 7475 | |
| 7476 | /** |
| 7477 | * Sets the unread conversation in a message notification. |
| 7478 | * |
| 7479 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 7480 | * @return This object for method chaining. |
| 7481 | */ |
| 7482 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 7483 | mUnreadConversation = unreadConversation; |
| 7484 | return this; |
| 7485 | } |
| 7486 | |
| 7487 | /** |
| 7488 | * Returns the unread conversation conveyed by this notification. |
| 7489 | * @see #setUnreadConversation(UnreadConversation) |
| 7490 | */ |
| 7491 | public UnreadConversation getUnreadConversation() { |
| 7492 | return mUnreadConversation; |
| 7493 | } |
| 7494 | |
| 7495 | /** |
| 7496 | * A class which holds the unread messages from a conversation. |
| 7497 | */ |
| 7498 | public static class UnreadConversation { |
| 7499 | private static final String KEY_AUTHOR = "author"; |
| 7500 | private static final String KEY_TEXT = "text"; |
| 7501 | private static final String KEY_MESSAGES = "messages"; |
| 7502 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 7503 | private static final String KEY_ON_REPLY = "on_reply"; |
| 7504 | private static final String KEY_ON_READ = "on_read"; |
| 7505 | private static final String KEY_PARTICIPANTS = "participants"; |
| 7506 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 7507 | |
| 7508 | private final String[] mMessages; |
| 7509 | private final RemoteInput mRemoteInput; |
| 7510 | private final PendingIntent mReplyPendingIntent; |
| 7511 | private final PendingIntent mReadPendingIntent; |
| 7512 | private final String[] mParticipants; |
| 7513 | private final long mLatestTimestamp; |
| 7514 | |
| 7515 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 7516 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 7517 | String[] participants, long latestTimestamp) { |
| 7518 | mMessages = messages; |
| 7519 | mRemoteInput = remoteInput; |
| 7520 | mReadPendingIntent = readPendingIntent; |
| 7521 | mReplyPendingIntent = replyPendingIntent; |
| 7522 | mParticipants = participants; |
| 7523 | mLatestTimestamp = latestTimestamp; |
| 7524 | } |
| 7525 | |
| 7526 | /** |
| 7527 | * Gets the list of messages conveyed by this notification. |
| 7528 | */ |
| 7529 | public String[] getMessages() { |
| 7530 | return mMessages; |
| 7531 | } |
| 7532 | |
| 7533 | /** |
| 7534 | * Gets the remote input that will be used to convey the response to a message list, or |
| 7535 | * null if no such remote input exists. |
| 7536 | */ |
| 7537 | public RemoteInput getRemoteInput() { |
| 7538 | return mRemoteInput; |
| 7539 | } |
| 7540 | |
| 7541 | /** |
| 7542 | * Gets the pending intent that will be triggered when the user replies to this |
| 7543 | * notification. |
| 7544 | */ |
| 7545 | public PendingIntent getReplyPendingIntent() { |
| 7546 | return mReplyPendingIntent; |
| 7547 | } |
| 7548 | |
| 7549 | /** |
| 7550 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 7551 | * in this object's message list. |
| 7552 | */ |
| 7553 | public PendingIntent getReadPendingIntent() { |
| 7554 | return mReadPendingIntent; |
| 7555 | } |
| 7556 | |
| 7557 | /** |
| 7558 | * Gets the participants in the conversation. |
| 7559 | */ |
| 7560 | public String[] getParticipants() { |
| 7561 | return mParticipants; |
| 7562 | } |
| 7563 | |
| 7564 | /** |
| 7565 | * Gets the firs participant in the conversation. |
| 7566 | */ |
| 7567 | public String getParticipant() { |
| 7568 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 7569 | } |
| 7570 | |
| 7571 | /** |
| 7572 | * Gets the timestamp of the conversation. |
| 7573 | */ |
| 7574 | public long getLatestTimestamp() { |
| 7575 | return mLatestTimestamp; |
| 7576 | } |
| 7577 | |
| 7578 | Bundle getBundleForUnreadConversation() { |
| 7579 | Bundle b = new Bundle(); |
| 7580 | String author = null; |
| 7581 | if (mParticipants != null && mParticipants.length > 1) { |
| 7582 | author = mParticipants[0]; |
| 7583 | } |
| 7584 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 7585 | for (int i = 0; i < messages.length; i++) { |
| 7586 | Bundle m = new Bundle(); |
| 7587 | m.putString(KEY_TEXT, mMessages[i]); |
| 7588 | m.putString(KEY_AUTHOR, author); |
| 7589 | messages[i] = m; |
| 7590 | } |
| 7591 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 7592 | if (mRemoteInput != null) { |
| 7593 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 7594 | } |
| 7595 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 7596 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 7597 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 7598 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 7599 | return b; |
| 7600 | } |
| 7601 | |
| 7602 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 7603 | if (b == null) { |
| 7604 | return null; |
| 7605 | } |
| 7606 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 7607 | String[] messages = null; |
| 7608 | if (parcelableMessages != null) { |
| 7609 | String[] tmp = new String[parcelableMessages.length]; |
| 7610 | boolean success = true; |
| 7611 | for (int i = 0; i < tmp.length; i++) { |
| 7612 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 7613 | success = false; |
| 7614 | break; |
| 7615 | } |
| 7616 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 7617 | if (tmp[i] == null) { |
| 7618 | success = false; |
| 7619 | break; |
| 7620 | } |
| 7621 | } |
| 7622 | if (success) { |
| 7623 | messages = tmp; |
| 7624 | } else { |
| 7625 | return null; |
| 7626 | } |
| 7627 | } |
| 7628 | |
| 7629 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 7630 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 7631 | |
| 7632 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 7633 | |
| 7634 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 7635 | if (participants == null || participants.length != 1) { |
| 7636 | return null; |
| 7637 | } |
| 7638 | |
| 7639 | return new UnreadConversation(messages, |
| 7640 | remoteInput, |
| 7641 | onReply, |
| 7642 | onRead, |
| 7643 | participants, b.getLong(KEY_TIMESTAMP)); |
| 7644 | } |
| 7645 | }; |
| 7646 | |
| 7647 | /** |
| 7648 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 7649 | */ |
| 7650 | public static class Builder { |
| 7651 | private final List<String> mMessages = new ArrayList<String>(); |
| 7652 | private final String mParticipant; |
| 7653 | private RemoteInput mRemoteInput; |
| 7654 | private PendingIntent mReadPendingIntent; |
| 7655 | private PendingIntent mReplyPendingIntent; |
| 7656 | private long mLatestTimestamp; |
| 7657 | |
| 7658 | /** |
| 7659 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 7660 | * |
| 7661 | * @param name The name of the other participant in the conversation. |
| 7662 | */ |
| 7663 | public Builder(String name) { |
| 7664 | mParticipant = name; |
| 7665 | } |
| 7666 | |
| 7667 | /** |
| 7668 | * Appends a new unread message to the list of messages for this conversation. |
| 7669 | * |
| 7670 | * The messages should be added from oldest to newest. |
| 7671 | * |
| 7672 | * @param message The text of the new unread message. |
| 7673 | * @return This object for method chaining. |
| 7674 | */ |
| 7675 | public Builder addMessage(String message) { |
| 7676 | mMessages.add(message); |
| 7677 | return this; |
| 7678 | } |
| 7679 | |
| 7680 | /** |
| 7681 | * Sets the pending intent and remote input which will convey the reply to this |
| 7682 | * notification. |
| 7683 | * |
| 7684 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 7685 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 7686 | * @return This object for method chaining. |
| 7687 | * |
| 7688 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 7689 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 7690 | */ |
| 7691 | public Builder setReplyAction( |
| 7692 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 7693 | mRemoteInput = remoteInput; |
| 7694 | mReplyPendingIntent = pendingIntent; |
| 7695 | |
| 7696 | return this; |
| 7697 | } |
| 7698 | |
| 7699 | /** |
| 7700 | * Sets the pending intent that will be sent once the messages in this notification |
| 7701 | * are read. |
| 7702 | * |
| 7703 | * @param pendingIntent The pending intent to use. |
| 7704 | * @return This object for method chaining. |
| 7705 | */ |
| 7706 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 7707 | mReadPendingIntent = pendingIntent; |
| 7708 | return this; |
| 7709 | } |
| 7710 | |
| 7711 | /** |
| 7712 | * Sets the timestamp of the most recent message in an unread conversation. |
| 7713 | * |
| 7714 | * If a messaging notification has been posted by your application and has not |
| 7715 | * yet been cancelled, posting a later notification with the same id and tag |
| 7716 | * but without a newer timestamp may result in Android Auto not displaying a |
| 7717 | * heads up notification for the later notification. |
| 7718 | * |
| 7719 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 7720 | * @return This object for method chaining. |
| 7721 | */ |
| 7722 | public Builder setLatestTimestamp(long timestamp) { |
| 7723 | mLatestTimestamp = timestamp; |
| 7724 | return this; |
| 7725 | } |
| 7726 | |
| 7727 | /** |
| 7728 | * Builds a new unread conversation object. |
| 7729 | * |
| 7730 | * @return The new unread conversation object. |
| 7731 | */ |
| 7732 | public UnreadConversation build() { |
| 7733 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 7734 | String[] participants = { mParticipant }; |
| 7735 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 7736 | mReadPendingIntent, participants, mLatestTimestamp); |
| 7737 | } |
| 7738 | } |
| 7739 | } |
| 7740 | |
| 7741 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 7742 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 7743 | * with a TV extension: |
| 7744 | * |
| 7745 | * <ol> |
| 7746 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 7747 | * <li>Create a {@link TvExtender}. |
| 7748 | * <li>Set TV-specific properties using the {@code set} methods of |
| 7749 | * {@link TvExtender}. |
| 7750 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 7751 | * to apply the extension to a notification. |
| 7752 | * </ol> |
| 7753 | * |
| 7754 | * <pre class="prettyprint"> |
| 7755 | * Notification notification = new Notification.Builder(context) |
| 7756 | * ... |
| 7757 | * .extend(new TvExtender() |
| 7758 | * .set*(...)) |
| 7759 | * .build(); |
| 7760 | * </pre> |
| 7761 | * |
| 7762 | * <p>TV extensions can be accessed on an existing notification by using the |
| 7763 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 7764 | * to access values. |
| 7765 | * |
| 7766 | * @hide |
| 7767 | */ |
| 7768 | @SystemApi |
| 7769 | public static final class TvExtender implements Extender { |
| 7770 | private static final String TAG = "TvExtender"; |
| 7771 | |
| 7772 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 7773 | private static final String EXTRA_FLAGS = "flags"; |
| 7774 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 7775 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 7776 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 7777 | |
| 7778 | // Flags bitwise-ored to mFlags |
| 7779 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 7780 | |
| 7781 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 7782 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 7783 | private PendingIntent mContentIntent; |
| 7784 | private PendingIntent mDeleteIntent; |
| 7785 | |
| 7786 | /** |
| 7787 | * Create a {@link TvExtender} with default options. |
| 7788 | */ |
| 7789 | public TvExtender() { |
| 7790 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 7791 | } |
| 7792 | |
| 7793 | /** |
| 7794 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 7795 | * |
| 7796 | * @param notif The notification from which to copy options. |
| 7797 | */ |
| 7798 | public TvExtender(Notification notif) { |
| 7799 | Bundle bundle = notif.extras == null ? |
| 7800 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 7801 | if (bundle != null) { |
| 7802 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 7803 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 7804 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 7805 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 7806 | } |
| 7807 | } |
| 7808 | |
| 7809 | /** |
| 7810 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 7811 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 7812 | * method of {@link Notification.Builder}. |
| 7813 | */ |
| 7814 | @Override |
| 7815 | public Notification.Builder extend(Notification.Builder builder) { |
| 7816 | Bundle bundle = new Bundle(); |
| 7817 | |
| 7818 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 7819 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 7820 | if (mContentIntent != null) { |
| 7821 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 7822 | } |
| 7823 | |
| 7824 | if (mDeleteIntent != null) { |
| 7825 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 7826 | } |
| 7827 | |
| 7828 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 7829 | return builder; |
| 7830 | } |
| 7831 | |
| 7832 | /** |
| 7833 | * Returns true if this notification should be shown on TV. This method return true |
| 7834 | * if the notification was extended with a TvExtender. |
| 7835 | */ |
| 7836 | public boolean isAvailableOnTv() { |
| 7837 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 7838 | } |
| 7839 | |
| 7840 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 7841 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 7842 | * It can be different from the channel that the notification is delivered to when |
| 7843 | * posting on a non-TV device. |
| 7844 | */ |
| 7845 | public TvExtender setChannel(String channelId) { |
| 7846 | mChannelId = channelId; |
| 7847 | return this; |
| 7848 | } |
| 7849 | |
| 7850 | /** |
| 7851 | * Returns the id of the channel this notification posts to on TV. |
| 7852 | */ |
| 7853 | public String getChannel() { |
| 7854 | return mChannelId; |
| 7855 | } |
| 7856 | |
| 7857 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 7858 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 7859 | * If provided, it is used instead of the content intent specified |
| 7860 | * at the level of Notification. |
| 7861 | */ |
| 7862 | public TvExtender setContentIntent(PendingIntent intent) { |
| 7863 | mContentIntent = intent; |
| 7864 | return this; |
| 7865 | } |
| 7866 | |
| 7867 | /** |
| 7868 | * Returns the TV-specific content intent. If this method returns null, the |
| 7869 | * main content intent on the notification should be used. |
| 7870 | * |
| 7871 | * @see {@link Notification#contentIntent} |
| 7872 | */ |
| 7873 | public PendingIntent getContentIntent() { |
| 7874 | return mContentIntent; |
| 7875 | } |
| 7876 | |
| 7877 | /** |
| 7878 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 7879 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 7880 | * at the level of Notification. |
| 7881 | */ |
| 7882 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 7883 | mDeleteIntent = intent; |
| 7884 | return this; |
| 7885 | } |
| 7886 | |
| 7887 | /** |
| 7888 | * Returns the TV-specific delete intent. If this method returns null, the |
| 7889 | * main delete intent on the notification should be used. |
| 7890 | * |
| 7891 | * @see {@link Notification#deleteIntent} |
| 7892 | */ |
| 7893 | public PendingIntent getDeleteIntent() { |
| 7894 | return mDeleteIntent; |
| 7895 | } |
| 7896 | } |
| 7897 | |
| 7898 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7899 | * Get an array of Notification objects from a parcelable array bundle field. |
| 7900 | * Update the bundle to have a typed array so fetches in the future don't need |
| 7901 | * to do an array copy. |
| 7902 | */ |
| 7903 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 7904 | Parcelable[] array = bundle.getParcelableArray(key); |
| 7905 | if (array instanceof Notification[] || array == null) { |
| 7906 | return (Notification[]) array; |
| 7907 | } |
| 7908 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 7909 | Notification[].class); |
| 7910 | bundle.putParcelableArray(key, typedArray); |
| 7911 | return typedArray; |
| 7912 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7913 | |
| 7914 | private static class BuilderRemoteViews extends RemoteViews { |
| 7915 | public BuilderRemoteViews(Parcel parcel) { |
| 7916 | super(parcel); |
| 7917 | } |
| 7918 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 7919 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 7920 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 7921 | } |
| 7922 | |
| 7923 | @Override |
| 7924 | public BuilderRemoteViews clone() { |
| 7925 | Parcel p = Parcel.obtain(); |
| 7926 | writeToParcel(p, 0); |
| 7927 | p.setDataPosition(0); |
| 7928 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 7929 | p.recycle(); |
| 7930 | return brv; |
| 7931 | } |
| 7932 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 7933 | |
| 7934 | private static class StandardTemplateParams { |
| 7935 | boolean hasProgress = true; |
| 7936 | boolean ambient = false; |
| 7937 | CharSequence title; |
| 7938 | CharSequence text; |
| 7939 | |
| 7940 | final StandardTemplateParams reset() { |
| 7941 | hasProgress = true; |
| 7942 | ambient = false; |
| 7943 | title = null; |
| 7944 | text = null; |
| 7945 | return this; |
| 7946 | } |
| 7947 | |
| 7948 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 7949 | this.hasProgress = hasProgress; |
| 7950 | return this; |
| 7951 | } |
| 7952 | |
| 7953 | final StandardTemplateParams title(CharSequence title) { |
| 7954 | this.title = title; |
| 7955 | return this; |
| 7956 | } |
| 7957 | |
| 7958 | final StandardTemplateParams text(CharSequence text) { |
| 7959 | this.text = text; |
| 7960 | return this; |
| 7961 | } |
| 7962 | |
| 7963 | final StandardTemplateParams ambient(boolean ambient) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 7964 | Preconditions.checkState(title == null && text == null, "must set ambient before text"); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 7965 | this.ambient = ambient; |
| 7966 | return this; |
| 7967 | } |
| 7968 | |
| 7969 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 7970 | Bundle extras = b.mN.extras; |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 7971 | title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE), ambient); |
| 7972 | text = b.processLegacyText(extras.getCharSequence(EXTRA_TEXT), ambient); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 7973 | return this; |
| 7974 | } |
| 7975 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7976 | } |