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; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 45 | import android.os.Binder; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 46 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 47 | import android.os.Bundle; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 48 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.os.Parcel; |
| 50 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 51 | import android.os.SystemClock; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 52 | import android.os.SystemProperties; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 53 | import android.os.UserHandle; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 54 | import android.text.BidiFormatter; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 55 | import android.text.SpannableStringBuilder; |
| 56 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 58 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 59 | import android.text.style.BackgroundColorSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 60 | import android.text.style.CharacterStyle; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 61 | import android.text.style.ForegroundColorSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 62 | import android.text.style.RelativeSizeSpan; |
| 63 | import android.text.style.TextAppearanceSpan; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 64 | import android.util.ArraySet; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 65 | import android.util.Log; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 66 | import android.util.SparseArray; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 67 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 68 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 69 | import android.view.View; |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 70 | import android.view.ViewGroup; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 71 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.widget.RemoteViews; |
| 73 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 74 | import com.android.internal.R; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 75 | import com.android.internal.util.ArrayUtils; |
Griff Hazen | c091ba8 | 2014-05-16 10:13:26 -0700 | [diff] [blame] | 76 | import com.android.internal.util.NotificationColorUtil; |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 77 | import com.android.internal.util.Preconditions; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 78 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 79 | import java.lang.annotation.Retention; |
| 80 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 81 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 82 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 83 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 84 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 85 | import java.util.List; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 86 | import java.util.Set; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 87 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | /** |
| 89 | * A class that represents how a persistent notification is to be presented to |
| 90 | * the user using the {@link android.app.NotificationManager}. |
| 91 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 92 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 93 | * easier to construct Notifications.</p> |
| 94 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 95 | * <div class="special reference"> |
| 96 | * <h3>Developer Guides</h3> |
| 97 | * <p>For a guide to creating notifications, read the |
| 98 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 99 | * developer guide.</p> |
| 100 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | */ |
| 102 | public class Notification implements Parcelable |
| 103 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 104 | private static final String TAG = "Notification"; |
| 105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 107 | * 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] | 108 | * containing application. |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 109 | */ |
| 110 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 111 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 112 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 113 | |
| 114 | /** |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 115 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 116 | * 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] | 117 | * what settings should be shown in the target app. |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 118 | */ |
| 119 | public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 120 | |
| 121 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 122 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 123 | * contain the tag provided to {@link NotificationManager#notify(String, int, Notification)} |
| 124 | * that can be used to narrow down what settings should be shown in the target app. |
| 125 | */ |
| 126 | public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 127 | |
| 128 | /** |
| 129 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 130 | * contain the id provided to {@link NotificationManager#notify(String, int, Notification)} |
| 131 | * that can be used to narrow down what settings should be shown in the target app. |
| 132 | */ |
| 133 | public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 134 | |
| 135 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | * Use all default values (where applicable). |
| 137 | */ |
| 138 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | /** |
| 141 | * Use the default notification sound. This will ignore any given |
| 142 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 143 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 144 | * <p> |
| 145 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 146 | * </p> |
| 147 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 149 | */ |
| 150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | public static final int DEFAULT_SOUND = 1; |
| 152 | |
| 153 | /** |
| 154 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 155 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 156 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 157 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 158 | * <p> |
| 159 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 160 | * </p> |
| 161 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 163 | */ |
| 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | /** |
| 168 | * Use the default notification lights. This will ignore the |
| 169 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 170 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 171 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 173 | */ |
| 174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 178 | * Maximum length of CharSequences accepted by Builder and friends. |
| 179 | * |
| 180 | * <p> |
| 181 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 182 | */ |
| 183 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 184 | |
| 185 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 186 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 187 | */ |
| 188 | private static final int MAX_REPLY_HISTORY = 5; |
| 189 | |
| 190 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 191 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 192 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 193 | * Default value: {@link System#currentTimeMillis() Now}. |
| 194 | * |
| 195 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 196 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 197 | * 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] | 198 | * timestamped according to when the activity began. |
| 199 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 200 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 201 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 202 | * <ul> |
| 203 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 204 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 205 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 206 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 207 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 208 | * <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] | 209 | * </ul> |
| 210 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 211 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 212 | * anymore by default and must be opted into by using |
| 213 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | */ |
| 215 | public long when; |
| 216 | |
| 217 | /** |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 218 | * The creation time of the notification |
| 219 | */ |
| 220 | private long creationTime; |
| 221 | |
| 222 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | * 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] | 224 | * |
| 225 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 227 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 228 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | public int icon; |
| 230 | |
| 231 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 232 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 233 | * leave it at its default value of 0. |
| 234 | * |
| 235 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 236 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 237 | */ |
| 238 | public int iconLevel; |
| 239 | |
| 240 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 241 | * The number of events that this notification represents. For example, in a new mail |
| 242 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 243 | * |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 244 | * The system may or may not use this field to modify the appearance of the notification. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 245 | * Starting with {@link android.os.Build.VERSION_CODES#O}, the number may be displayed as a |
| 246 | * badge icon in Launchers that support badging. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | */ |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 248 | public int number = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | |
| 250 | /** |
| 251 | * The intent to execute when the expanded status entry is clicked. If |
| 252 | * this is an activity, it must include the |
| 253 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 254 | * that you take care of task management as described in the |
| 255 | * <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] | 256 | * Stack</a> document. In particular, make sure to read the notification section |
| 257 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 258 | * Notifications</a> for the correct ways to launch an application from a |
| 259 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | */ |
| 261 | public PendingIntent contentIntent; |
| 262 | |
| 263 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 264 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 265 | * the "Clear All" button or by swiping it away individually. |
| 266 | * |
| 267 | * This probably shouldn't be launching an activity since several of those will be sent |
| 268 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | */ |
| 270 | public PendingIntent deleteIntent; |
| 271 | |
| 272 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 273 | * 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] | 274 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 275 | * <p> |
| 276 | * The system UI may choose to display a heads-up notification, instead of |
| 277 | * launching this intent, while the user is using the device. |
| 278 | * </p> |
| 279 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 280 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 281 | */ |
| 282 | public PendingIntent fullScreenIntent; |
| 283 | |
| 284 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 285 | * Text that summarizes this notification for accessibility services. |
| 286 | * |
| 287 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 288 | * accessibility services (where it serves as an audible announcement of the notification's |
| 289 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 290 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 291 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | */ |
| 293 | public CharSequence tickerText; |
| 294 | |
| 295 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 296 | * Formerly, a view showing the {@link #tickerText}. |
| 297 | * |
| 298 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 299 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 300 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 301 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 302 | |
| 303 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 304 | * The view that will represent this notification in the notification list (which is pulled |
| 305 | * down from the status bar). |
| 306 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 307 | * As of N, this field may be null. The notification view is determined by the inputs |
| 308 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 309 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 311 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | public RemoteViews contentView; |
| 313 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 314 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 315 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 316 | * opportunity to show more detail. The system UI may choose to show this |
| 317 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 318 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 319 | * 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] | 320 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 321 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 322 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 323 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 324 | public RemoteViews bigContentView; |
| 325 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 326 | |
| 327 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 328 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 329 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 330 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 331 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 332 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 333 | * 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] | 334 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 335 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 336 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 337 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 338 | public RemoteViews headsUpContentView; |
| 339 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 340 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 341 | * A large bitmap to be shown in the notification content area. |
| 342 | * |
| 343 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 345 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 346 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | |
| 348 | /** |
| 349 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 350 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 352 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 353 | * </p> |
| 354 | * |
| 355 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 356 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 358 | * @deprecated use {@link NotificationChannel#getSound()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 360 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | public Uri sound; |
| 362 | |
| 363 | /** |
| 364 | * Use this constant as the value for audioStreamType to request that |
| 365 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 366 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 367 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 368 | * @deprecated Use {@link NotificationChannel#getAudioAttributes()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 370 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | public static final int STREAM_DEFAULT = -1; |
| 372 | |
| 373 | /** |
| 374 | * The audio stream type to use when playing the sound. |
| 375 | * Should be one of the STREAM_ constants from |
| 376 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 377 | * |
| 378 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 380 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | public int audioStreamType = STREAM_DEFAULT; |
| 382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 384 | * The default value of {@link #audioAttributes}. |
| 385 | */ |
| 386 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 387 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 388 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 389 | .build(); |
| 390 | |
| 391 | /** |
| 392 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 393 | * |
| 394 | * @deprecated use {@link NotificationChannel#getAudioAttributes()} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 395 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 396 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 397 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 398 | |
| 399 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 400 | * The pattern with which to vibrate. |
| 401 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | * <p> |
| 403 | * To vibrate the default pattern, see {@link #defaults}. |
| 404 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 405 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | * @see android.os.Vibrator#vibrate(long[],int) |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 407 | * @deprecated use {@link NotificationChannel#getVibrationPattern()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 409 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | public long[] vibrate; |
| 411 | |
| 412 | /** |
| 413 | * The color of the led. The hardware will do its best approximation. |
| 414 | * |
| 415 | * @see #FLAG_SHOW_LIGHTS |
| 416 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 417 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 419 | @ColorInt |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 420 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | public int ledARGB; |
| 422 | |
| 423 | /** |
| 424 | * The number of milliseconds for the LED to be on while it's flashing. |
| 425 | * The hardware will do its best approximation. |
| 426 | * |
| 427 | * @see #FLAG_SHOW_LIGHTS |
| 428 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 429 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 431 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | public int ledOnMS; |
| 433 | |
| 434 | /** |
| 435 | * The number of milliseconds for the LED to be off while it's flashing. |
| 436 | * The hardware will do its best approximation. |
| 437 | * |
| 438 | * @see #FLAG_SHOW_LIGHTS |
| 439 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 440 | * |
| 441 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 443 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | public int ledOffMS; |
| 445 | |
| 446 | /** |
| 447 | * Specifies which values should be taken from the defaults. |
| 448 | * <p> |
| 449 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 450 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 451 | * values, use {@link #DEFAULT_ALL}. |
| 452 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 453 | * |
| 454 | * @deprecated use {@link NotificationChannel#getSound()} and |
| 455 | * {@link NotificationChannel#shouldShowLights()} and |
| 456 | * {@link NotificationChannel#shouldVibrate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 458 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | public int defaults; |
| 460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | /** |
| 462 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 463 | * set if you want the LED on for this notification. |
| 464 | * <ul> |
| 465 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 466 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 467 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 468 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 469 | * be on and off to ledOnMS and ledOffMS.</li> |
| 470 | * </ul> |
| 471 | * <p> |
| 472 | * Since hardware varies, you are not guaranteed that any of the values |
| 473 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 474 | * because they will be set to values that work on any given hardware. |
| 475 | * <p> |
| 476 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 477 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 478 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 480 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 482 | |
| 483 | /** |
| 484 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 485 | * set if this notification is in reference to something that is ongoing, |
| 486 | * like a phone call. It should not be set if this notification is in |
| 487 | * reference to something that happened at a particular point in time, |
| 488 | * like a missed phone call. |
| 489 | */ |
| 490 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 491 | |
| 492 | /** |
| 493 | * 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] | 494 | * the audio will be repeated until the notification is |
| 495 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | */ |
| 497 | public static final int FLAG_INSISTENT = 0x00000004; |
| 498 | |
| 499 | /** |
| 500 | * 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] | 501 | * set if you would only like the sound, vibrate and ticker to be played |
| 502 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | */ |
| 504 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 505 | |
| 506 | /** |
| 507 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 508 | * 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] | 509 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | */ |
| 511 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 512 | |
| 513 | /** |
| 514 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 515 | * set if the notification should not be canceled when the user clicks |
| 516 | * the Clear all button. |
| 517 | */ |
| 518 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 519 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 520 | /** |
| 521 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 522 | * set if this notification represents a currently running service. This |
| 523 | * will normally be set for you by {@link Service#startForeground}. |
| 524 | */ |
| 525 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 526 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 527 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 528 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 529 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 530 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 531 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 532 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 533 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 534 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 535 | /** |
| 536 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 537 | * set if this notification is relevant to the current device only |
| 538 | * and it is not recommended that it bridge to other devices. |
| 539 | */ |
| 540 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 541 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 542 | /** |
| 543 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 544 | * set if this notification is the group summary for a group of notifications. |
| 545 | * Grouped notifications may display in a cluster or stack on devices which |
| 546 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 547 | */ |
| 548 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 549 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 550 | /** |
| 551 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 552 | * set if this notification is the group summary for an auto-group of notifications. |
| 553 | * |
| 554 | * @hide |
| 555 | */ |
| 556 | @SystemApi |
| 557 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | public int flags; |
| 560 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 561 | /** @hide */ |
| 562 | @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX}) |
| 563 | @Retention(RetentionPolicy.SOURCE) |
| 564 | public @interface Priority {} |
| 565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 567 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 568 | * notifications, use this value for all notifications. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 569 | * |
| 570 | * @deprecated use {@link NotificationManager#IMPORTANCE_DEFAULT} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 571 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 572 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 573 | public static final int PRIORITY_DEFAULT = 0; |
| 574 | |
| 575 | /** |
| 576 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 577 | * items smaller, or at a different position in the list, compared with your app's |
| 578 | * {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 579 | * |
| 580 | * @deprecated use {@link NotificationManager#IMPORTANCE_LOW} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 581 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 582 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 583 | public static final int PRIORITY_LOW = -1; |
| 584 | |
| 585 | /** |
| 586 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 587 | * circumstances, such as detailed notification logs. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 588 | * |
| 589 | * @deprecated use {@link NotificationManager#IMPORTANCE_MIN} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 590 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 591 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 592 | public static final int PRIORITY_MIN = -2; |
| 593 | |
| 594 | /** |
| 595 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 596 | * show these items larger, or at a different position in notification lists, compared with |
| 597 | * your app's {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 598 | * |
| 599 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 600 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 601 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 602 | public static final int PRIORITY_HIGH = 1; |
| 603 | |
| 604 | /** |
| 605 | * Highest {@link #priority}, for your application's most important items that require the |
| 606 | * user's prompt attention or input. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 607 | * |
| 608 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 609 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 610 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 611 | public static final int PRIORITY_MAX = 2; |
| 612 | |
| 613 | /** |
| 614 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 615 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 616 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 617 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 618 | * 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] | 619 | * system will make a determination about how to interpret this priority when presenting |
| 620 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 621 | * |
| 622 | * <p> |
| 623 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 624 | * as a heads-up notification. |
| 625 | * </p> |
| 626 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 627 | * @deprecated use {@link NotificationChannel#getImportance()} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 628 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 629 | @Priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 630 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 631 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 632 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 633 | /** |
| 634 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 635 | * to be applied by the standard Style templates when presenting this notification. |
| 636 | * |
| 637 | * The current template design constructs a colorful header image by overlaying the |
| 638 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 639 | * ignored. |
| 640 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 641 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 642 | public int color = COLOR_DEFAULT; |
| 643 | |
| 644 | /** |
| 645 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 646 | * any special color but instead use default colors when presenting this notification. |
| 647 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 648 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 649 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 650 | |
| 651 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 652 | * 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] | 653 | * @hide |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 654 | */ |
| 655 | @ColorInt |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 656 | public static final int COLOR_INVALID = 1; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 657 | |
| 658 | /** |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 659 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 660 | * 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] | 661 | * lockscreen). |
| 662 | * |
| 663 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 664 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 665 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 666 | * the appropriate user. |
| 667 | * |
| 668 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 669 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 670 | * To modify the public version of this notification—for example, to redact some portions—see |
| 671 | * {@link Builder#setPublicVersion(Notification)}. |
| 672 | * |
| 673 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 674 | * and ticker until the user has bypassed the lockscreen. |
| 675 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 676 | public @Visibility int visibility; |
| 677 | |
| 678 | /** @hide */ |
| 679 | @IntDef(prefix = { "VISIBILITY_" }, value = { |
| 680 | VISIBILITY_PUBLIC, |
| 681 | VISIBILITY_PRIVATE, |
| 682 | VISIBILITY_SECRET, |
| 683 | }) |
| 684 | @Retention(RetentionPolicy.SOURCE) |
| 685 | public @interface Visibility {} |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 686 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 687 | /** |
| 688 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 689 | * |
| 690 | * {@see #visibility} |
| 691 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 692 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 693 | |
| 694 | /** |
| 695 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 696 | * private information on secure lockscreens. |
| 697 | * |
| 698 | * {@see #visibility} |
| 699 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 700 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 701 | |
| 702 | /** |
| 703 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 704 | * |
| 705 | * {@see #visibility} |
| 706 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 707 | public static final int VISIBILITY_SECRET = -1; |
| 708 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 709 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 710 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 711 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 712 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 713 | |
| 714 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 715 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 716 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 717 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 718 | |
| 719 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 720 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 721 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 722 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 723 | |
| 724 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 725 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 726 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 727 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 728 | |
| 729 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 730 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 731 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 732 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 733 | |
| 734 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 735 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 736 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 737 | public static final String CATEGORY_ALARM = "alarm"; |
| 738 | |
| 739 | /** |
| 740 | * Notification category: progress of a long-running background operation. |
| 741 | */ |
| 742 | public static final String CATEGORY_PROGRESS = "progress"; |
| 743 | |
| 744 | /** |
| 745 | * Notification category: social network or sharing update. |
| 746 | */ |
| 747 | public static final String CATEGORY_SOCIAL = "social"; |
| 748 | |
| 749 | /** |
| 750 | * Notification category: error in background operation or authentication status. |
| 751 | */ |
| 752 | public static final String CATEGORY_ERROR = "err"; |
| 753 | |
| 754 | /** |
| 755 | * Notification category: media transport control for playback. |
| 756 | */ |
| 757 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 758 | |
| 759 | /** |
| 760 | * Notification category: system or device status update. Reserved for system use. |
| 761 | */ |
| 762 | public static final String CATEGORY_SYSTEM = "sys"; |
| 763 | |
| 764 | /** |
| 765 | * Notification category: indication of running background service. |
| 766 | */ |
| 767 | public static final String CATEGORY_SERVICE = "service"; |
| 768 | |
| 769 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 770 | * Notification category: a specific, timely recommendation for a single thing. |
| 771 | * For example, a news app might want to recommend a news story it believes the user will |
| 772 | * want to read next. |
| 773 | */ |
| 774 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 775 | |
| 776 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 777 | * Notification category: ongoing information about device or contextual status. |
| 778 | */ |
| 779 | public static final String CATEGORY_STATUS = "status"; |
| 780 | |
| 781 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 782 | * Notification category: user-scheduled reminder. |
| 783 | */ |
| 784 | public static final String CATEGORY_REMINDER = "reminder"; |
| 785 | |
| 786 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 787 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 788 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 789 | */ |
| 790 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 791 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 792 | private String mGroupKey; |
| 793 | |
| 794 | /** |
| 795 | * Get the key used to group this notification into a cluster or stack |
| 796 | * with other notifications on devices which support such rendering. |
| 797 | */ |
| 798 | public String getGroup() { |
| 799 | return mGroupKey; |
| 800 | } |
| 801 | |
| 802 | private String mSortKey; |
| 803 | |
| 804 | /** |
| 805 | * Get a sort key that orders this notification among other notifications from the |
| 806 | * same package. This can be useful if an external sort was already applied and an app |
| 807 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 808 | * value, although providing different priorities in addition to providing sort key may |
| 809 | * cause this value to be ignored. |
| 810 | * |
| 811 | * <p>This sort key can also be used to order members of a notification group. See |
| 812 | * {@link Builder#setGroup}. |
| 813 | * |
| 814 | * @see String#compareTo(String) |
| 815 | */ |
| 816 | public String getSortKey() { |
| 817 | return mSortKey; |
| 818 | } |
| 819 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 820 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 821 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 822 | * <p> |
| 823 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 824 | * APIs, and are intended to be used by |
| 825 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 826 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 827 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 828 | public Bundle extras = new Bundle(); |
| 829 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 830 | /** |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 831 | * All pending intents in the notification as the system needs to be able to access them but |
| 832 | * 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] | 833 | * custom parcelable objects. |
| 834 | * |
| 835 | * @hide |
| 836 | */ |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 837 | public ArraySet<PendingIntent> allPendingIntents; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 838 | |
| 839 | /** |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 840 | * Token identifying the notification that is applying doze/bgcheck whitelisting to the |
| 841 | * pending intents inside of it, so only those will get the behavior. |
| 842 | * |
| 843 | * @hide |
| 844 | */ |
| 845 | static public IBinder whitelistToken; |
| 846 | |
| 847 | /** |
| 848 | * Must be set by a process to start associating tokens with Notification objects |
| 849 | * coming in to it. This is set by NotificationManagerService. |
| 850 | * |
| 851 | * @hide |
| 852 | */ |
| 853 | static public IBinder processWhitelistToken; |
| 854 | |
| 855 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 856 | * {@link #extras} key: this is the title of the notification, |
| 857 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 858 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 859 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 860 | |
| 861 | /** |
| 862 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 863 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 864 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 865 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 866 | |
| 867 | /** |
| 868 | * {@link #extras} key: this is the main text payload, as supplied to |
| 869 | * {@link Builder#setContentText(CharSequence)}. |
| 870 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 871 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 872 | |
| 873 | /** |
| 874 | * {@link #extras} key: this is a third line of text, as supplied to |
| 875 | * {@link Builder#setSubText(CharSequence)}. |
| 876 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 877 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 878 | |
| 879 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 880 | * {@link #extras} key: this is the remote input history, as supplied to |
| 881 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
Adrian Roos | 005e774 | 2016-04-13 15:02:20 -0700 | [diff] [blame] | 882 | * |
| 883 | * Apps can fill this through {@link Builder#setRemoteInputHistory(CharSequence[])} |
| 884 | * with the most recent inputs that have been sent through a {@link RemoteInput} of this |
| 885 | * Notification and are expected to clear it once the it is no longer relevant (e.g. for chat |
| 886 | * notifications once the other party has responded). |
| 887 | * |
| 888 | * The extra with this key is of type CharSequence[] and contains the most recent entry at |
| 889 | * the 0 index, the second most recent at the 1 index, etc. |
| 890 | * |
| 891 | * @see Builder#setRemoteInputHistory(CharSequence[]) |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 892 | */ |
| 893 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 894 | |
| 895 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 896 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 897 | * {@link Builder#setContentInfo(CharSequence)}. |
| 898 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 899 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 900 | |
| 901 | /** |
| 902 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 903 | * alongside expanded notifications, as supplied to (e.g.) |
| 904 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 905 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 906 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 907 | |
| 908 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 909 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 910 | * {@link BigTextStyle} notification, as supplied to |
| 911 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 912 | */ |
| 913 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 914 | |
| 915 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 916 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 917 | * supplied to {@link Builder#setSmallIcon(int)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 918 | * |
| 919 | * @deprecated Use {@link #getSmallIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 920 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 921 | @Deprecated |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 922 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 923 | |
| 924 | /** |
| 925 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 926 | * notification payload, as |
| 927 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 928 | * |
| 929 | * @deprecated Use {@link #getLargeIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 930 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 931 | @Deprecated |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 932 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 933 | |
| 934 | /** |
| 935 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 936 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 937 | * shown in its expanded form, as supplied to |
| 938 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 939 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 940 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 941 | |
| 942 | /** |
| 943 | * {@link #extras} key: this is the progress value supplied to |
| 944 | * {@link Builder#setProgress(int, int, boolean)}. |
| 945 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 946 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 947 | |
| 948 | /** |
| 949 | * {@link #extras} key: this is the maximum value supplied to |
| 950 | * {@link Builder#setProgress(int, int, boolean)}. |
| 951 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 952 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 953 | |
| 954 | /** |
| 955 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 956 | * {@link Builder#setProgress(int, int, boolean)}. |
| 957 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 958 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 959 | |
| 960 | /** |
| 961 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 962 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 963 | * {@link Builder#setUsesChronometer(boolean)}. |
| 964 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 965 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 966 | |
| 967 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 968 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 969 | * 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] | 970 | * This extra is a boolean. The default is false. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 971 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 972 | public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 973 | |
| 974 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 975 | * {@link #extras} key: whether {@link #when} should be shown, |
| 976 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 977 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 978 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 979 | |
| 980 | /** |
| 981 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 982 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 983 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 984 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 985 | |
| 986 | /** |
| 987 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 988 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 989 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 990 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 991 | |
| 992 | /** |
| 993 | * {@link #extras} key: A string representing the name of the specific |
| 994 | * {@link android.app.Notification.Style} used to create this notification. |
| 995 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 996 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 997 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 998 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 999 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 1000 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1001 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1002 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1003 | |
| 1004 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1005 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 1006 | * Only available to notifications coming from the android package. |
| 1007 | * @hide |
| 1008 | */ |
Maurice Lam | 96c1003 | 2017-03-29 15:42:38 -0700 | [diff] [blame] | 1009 | @SystemApi |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1010 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 1011 | |
| 1012 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1013 | * {@link #extras} key: A |
| 1014 | * {@link android.content.ContentUris content URI} pointing to an image that can be displayed |
| 1015 | * in the background when the notification is selected. The URI must point to an image stream |
| 1016 | * suitable for passing into |
| 1017 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
| 1018 | * BitmapFactory.decodeStream}; all other content types will be ignored. The content provider |
| 1019 | * URI used for this purpose must require no permissions to read the image data. |
| 1020 | */ |
| 1021 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1022 | |
| 1023 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1024 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 1025 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1026 | * {@link android.app.Notification.MediaStyle} notification. |
| 1027 | */ |
| 1028 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1029 | |
| 1030 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 1031 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 1032 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 1033 | */ |
| 1034 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1035 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 1036 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1037 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 1038 | * direct replies |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1039 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1040 | * {@link CharSequence} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1041 | */ |
| 1042 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1043 | |
| 1044 | /** |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1045 | * {@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] | 1046 | * represented by a {@link android.app.Notification.MessagingStyle} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1047 | */ |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1048 | public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1049 | |
| 1050 | /** |
| 1051 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 1052 | * bundles provided by a |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1053 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1054 | * array of bundles. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1055 | */ |
| 1056 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 1057 | |
| 1058 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 1059 | * {@link #extras} key: an array of |
| 1060 | * {@link android.app.Notification.MessagingStyle#addHistoricMessage historic} |
| 1061 | * {@link android.app.Notification.MessagingStyle.Message} bundles provided by a |
| 1062 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1063 | * array of bundles. |
| 1064 | */ |
| 1065 | public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1066 | |
| 1067 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1068 | * {@link #extras} key: whether the notification should be colorized as |
| 1069 | * supplied to {@link Builder#setColorized(boolean)}}. |
| 1070 | */ |
| 1071 | public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1072 | |
| 1073 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1074 | * @hide |
| 1075 | */ |
| 1076 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1077 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 1078 | /** |
| 1079 | * @hide |
| 1080 | */ |
| 1081 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1082 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1083 | /** |
| 1084 | * {@link #extras} key: the audio contents of this notification. |
| 1085 | * |
| 1086 | * This is for use when rendering the notification on an audio-focused interface; |
| 1087 | * the audio contents are a complete sound sample that contains the contents/body of the |
| 1088 | * notification. This may be used in substitute of a Text-to-Speech reading of the |
| 1089 | * notification. For example if the notification represents a voice message this should point |
| 1090 | * to the audio of that message. |
| 1091 | * |
| 1092 | * The data stored under this key should be a String representation of a Uri that contains the |
| 1093 | * audio contents in one of the following formats: WAV, PCM 16-bit, AMR-WB. |
| 1094 | * |
| 1095 | * This extra is unnecessary if you are using {@code MessagingStyle} since each {@code Message} |
| 1096 | * has a field for holding data URI. That field can be used for audio. |
| 1097 | * See {@code Message#setData}. |
| 1098 | * |
| 1099 | * Example usage: |
| 1100 | * <pre> |
| 1101 | * {@code |
| 1102 | * Notification.Builder myBuilder = (build your Notification as normal); |
| 1103 | * myBuilder.getExtras().putString(EXTRA_AUDIO_CONTENTS_URI, myAudioUri.toString()); |
| 1104 | * } |
| 1105 | * </pre> |
| 1106 | */ |
| 1107 | public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1108 | |
Dan Sandler | 80eaa59 | 2016-04-14 23:34:54 -0400 | [diff] [blame] | 1109 | /** @hide */ |
| 1110 | @SystemApi |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1111 | public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1112 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1113 | private Icon mSmallIcon; |
| 1114 | private Icon mLargeIcon; |
| 1115 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1116 | private String mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1117 | private long mTimeout; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1118 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1119 | private String mShortcutId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1120 | private CharSequence mSettingsText; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1121 | |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1122 | /** @hide */ |
| 1123 | @IntDef(prefix = { "GROUP_ALERT_" }, value = { |
| 1124 | GROUP_ALERT_ALL, GROUP_ALERT_CHILDREN, GROUP_ALERT_SUMMARY |
| 1125 | }) |
| 1126 | @Retention(RetentionPolicy.SOURCE) |
| 1127 | public @interface GroupAlertBehavior {} |
| 1128 | |
| 1129 | /** |
| 1130 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all notifications in a |
| 1131 | * group with sound or vibration ought to make sound or vibrate (respectively), so this |
| 1132 | * notification will not be muted when it is in a group. |
| 1133 | */ |
| 1134 | public static final int GROUP_ALERT_ALL = 0; |
| 1135 | |
| 1136 | /** |
| 1137 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all children |
| 1138 | * notification in a group should be silenced (no sound or vibration) even if they are posted |
| 1139 | * to a {@link NotificationChannel} that has sound and/or vibration. Use this constant to |
| 1140 | * mute this notification if this notification is a group child. |
| 1141 | * |
| 1142 | * <p> For example, you might want to use this constant if you post a number of children |
| 1143 | * notifications at once (say, after a periodic sync), and only need to notify the user |
| 1144 | * audibly once. |
| 1145 | */ |
| 1146 | public static final int GROUP_ALERT_SUMMARY = 1; |
| 1147 | |
| 1148 | /** |
| 1149 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that the summary |
| 1150 | * notification in a group should be silenced (no sound or vibration) even if they are |
| 1151 | * posted to a {@link NotificationChannel} that has sound and/or vibration. Use this constant |
| 1152 | * to mute this notification if this notification is a group summary. |
| 1153 | * |
| 1154 | * <p>For example, you might want to use this constant if only the children notifications |
| 1155 | * in your group have content and the summary is only used to visually group notifications. |
| 1156 | */ |
| 1157 | public static final int GROUP_ALERT_CHILDREN = 2; |
| 1158 | |
| 1159 | private int mGroupAlertBehavior = GROUP_ALERT_ALL; |
| 1160 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1161 | /** |
| 1162 | * If this notification is being shown as a badge, always show as a number. |
| 1163 | */ |
| 1164 | public static final int BADGE_ICON_NONE = 0; |
| 1165 | |
| 1166 | /** |
| 1167 | * If this notification is being shown as a badge, use the {@link #getSmallIcon()} to |
| 1168 | * represent this notification. |
| 1169 | */ |
| 1170 | public static final int BADGE_ICON_SMALL = 1; |
| 1171 | |
| 1172 | /** |
| 1173 | * If this notification is being shown as a badge, use the {@link #getLargeIcon()} to |
| 1174 | * represent this notification. |
| 1175 | */ |
| 1176 | public static final int BADGE_ICON_LARGE = 2; |
Julia Reynolds | 7d5b4da | 2017-03-20 10:18:49 -0400 | [diff] [blame] | 1177 | private int mBadgeIcon = BADGE_ICON_NONE; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1178 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1179 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1180 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 1181 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 1182 | * selected by the user. |
| 1183 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1184 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 1185 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 1186 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1187 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1188 | public static class Action implements Parcelable { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1189 | /** |
| 1190 | * {@link #extras} key: Keys to a {@link Parcelable} {@link ArrayList} of |
| 1191 | * {@link RemoteInput}s. |
| 1192 | * |
| 1193 | * This is intended for {@link RemoteInput}s that only accept data, meaning |
| 1194 | * {@link RemoteInput#getAllowFreeFormInput} is false, {@link RemoteInput#getChoices} |
| 1195 | * is null or empty, and {@link RemoteInput#getAllowedDataTypes is non-null and not |
| 1196 | * empty. These {@link RemoteInput}s will be ignored by devices that do not |
| 1197 | * support non-text-based {@link RemoteInput}s. See {@link Builder#build}. |
| 1198 | * |
| 1199 | * You can test if a RemoteInput matches these constraints using |
| 1200 | * {@link RemoteInput#isDataOnly}. |
| 1201 | */ |
| 1202 | private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1203 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1204 | private final Bundle mExtras; |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1205 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1206 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1207 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1208 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1209 | /** |
| 1210 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1211 | * |
| 1212 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1213 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1214 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1215 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1216 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1217 | /** |
| 1218 | * Title of the action. |
| 1219 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1220 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1221 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1222 | /** |
| 1223 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1224 | * may be rendered in a disabled presentation by the system UI. |
| 1225 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1226 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1227 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1228 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1229 | if (in.readInt() != 0) { |
| 1230 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1231 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1232 | icon = mIcon.getResId(); |
| 1233 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1234 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1235 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1236 | if (in.readInt() == 1) { |
| 1237 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1238 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1239 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1240 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1241 | mAllowGeneratedReplies = in.readInt() == 1; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1242 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1243 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1244 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1245 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1246 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1247 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1248 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1249 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1252 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1253 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1254 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1255 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1256 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1257 | this.icon = icon.getResId(); |
| 1258 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1259 | this.title = title; |
| 1260 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1261 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1262 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1263 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1267 | * Return an icon representing the action. |
| 1268 | */ |
| 1269 | public Icon getIcon() { |
| 1270 | if (mIcon == null && icon != 0) { |
| 1271 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1272 | mIcon = Icon.createWithResource("", icon); |
| 1273 | } |
| 1274 | return mIcon; |
| 1275 | } |
| 1276 | |
| 1277 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1278 | * Get additional metadata carried around with this Action. |
| 1279 | */ |
| 1280 | public Bundle getExtras() { |
| 1281 | return mExtras; |
| 1282 | } |
| 1283 | |
| 1284 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1285 | * Return whether the platform should automatically generate possible replies for this |
| 1286 | * {@link Action} |
| 1287 | */ |
| 1288 | public boolean getAllowGeneratedReplies() { |
| 1289 | return mAllowGeneratedReplies; |
| 1290 | } |
| 1291 | |
| 1292 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1293 | * 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] | 1294 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1295 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1296 | */ |
| 1297 | public RemoteInput[] getRemoteInputs() { |
| 1298 | return mRemoteInputs; |
| 1299 | } |
| 1300 | |
| 1301 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1302 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1303 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1304 | * {@link RemoteInput#isDataOnly}. |
| 1305 | * |
Shane Brennan | f670d6c | 2017-04-25 13:05:45 -0700 | [diff] [blame] | 1306 | * Returns null if there are no data-only remote inputs. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1307 | * |
| 1308 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1309 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1310 | */ |
| 1311 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1312 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1313 | } |
| 1314 | |
| 1315 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1316 | * Builder class for {@link Action} objects. |
| 1317 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1318 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1319 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1320 | private final CharSequence mTitle; |
| 1321 | private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1322 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1323 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1324 | private ArrayList<RemoteInput> mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1325 | |
| 1326 | /** |
| 1327 | * Construct a new builder for {@link Action} object. |
| 1328 | * @param icon icon to show for this action |
| 1329 | * @param title the title of the action |
| 1330 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1331 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1332 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1333 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1334 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | /** |
| 1338 | * Construct a new builder for {@link Action} object. |
| 1339 | * @param icon icon to show for this action |
| 1340 | * @param title the title of the action |
| 1341 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1342 | */ |
| 1343 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1344 | this(icon, title, intent, new Bundle(), null, true); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | /** |
| 1348 | * Construct a new builder for {@link Action} object using the fields from an |
| 1349 | * {@link Action}. |
| 1350 | * @param action the action to read fields from. |
| 1351 | */ |
| 1352 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1353 | this(action.getIcon(), action.title, action.actionIntent, |
| 1354 | new Bundle(action.mExtras), action.getRemoteInputs(), |
| 1355 | action.getAllowGeneratedReplies()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1356 | } |
| 1357 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1358 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1359 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1360 | mIcon = icon; |
| 1361 | mTitle = title; |
| 1362 | mIntent = intent; |
| 1363 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1364 | if (remoteInputs != null) { |
| 1365 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1366 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1367 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1368 | mAllowGeneratedReplies = allowGeneratedReplies; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | /** |
| 1372 | * Merge additional metadata into this builder. |
| 1373 | * |
| 1374 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1375 | * |
| 1376 | * @see Notification.Action#extras |
| 1377 | */ |
| 1378 | public Builder addExtras(Bundle extras) { |
| 1379 | if (extras != null) { |
| 1380 | mExtras.putAll(extras); |
| 1381 | } |
| 1382 | return this; |
| 1383 | } |
| 1384 | |
| 1385 | /** |
| 1386 | * Get the metadata Bundle used by this Builder. |
| 1387 | * |
| 1388 | * <p>The returned Bundle is shared with this Builder. |
| 1389 | */ |
| 1390 | public Bundle getExtras() { |
| 1391 | return mExtras; |
| 1392 | } |
| 1393 | |
| 1394 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1395 | * Add an input to be collected from the user when this action is sent. |
| 1396 | * Response values can be retrieved from the fired intent by using the |
| 1397 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1398 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1399 | * @return this object for method chaining |
| 1400 | */ |
| 1401 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1402 | if (mRemoteInputs == null) { |
| 1403 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1404 | } |
| 1405 | mRemoteInputs.add(remoteInput); |
| 1406 | return this; |
| 1407 | } |
| 1408 | |
| 1409 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1410 | * Set whether the platform should automatically generate possible replies to add to |
| 1411 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1412 | * {@link RemoteInput}, this has no effect. |
| 1413 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1414 | * otherwise |
| 1415 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1416 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1417 | */ |
| 1418 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1419 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1420 | return this; |
| 1421 | } |
| 1422 | |
| 1423 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1424 | * Apply an extender to this action builder. Extenders may be used to add |
| 1425 | * metadata or change options on this builder. |
| 1426 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1427 | public Builder extend(Extender extender) { |
| 1428 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1429 | return this; |
| 1430 | } |
| 1431 | |
| 1432 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1433 | * Combine all of the options that have been set and return a new {@link Action} |
| 1434 | * object. |
| 1435 | * @return the built action |
| 1436 | */ |
| 1437 | public Action build() { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1438 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1439 | RemoteInput[] previousDataInputs = |
| 1440 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1441 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1442 | for (RemoteInput input : previousDataInputs) { |
| 1443 | dataOnlyInputs.add(input); |
| 1444 | } |
| 1445 | } |
| 1446 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1447 | if (mRemoteInputs != null) { |
| 1448 | for (RemoteInput input : mRemoteInputs) { |
| 1449 | if (input.isDataOnly()) { |
| 1450 | dataOnlyInputs.add(input); |
| 1451 | } else { |
| 1452 | textInputs.add(input); |
| 1453 | } |
| 1454 | } |
| 1455 | } |
| 1456 | if (!dataOnlyInputs.isEmpty()) { |
| 1457 | RemoteInput[] dataInputsArr = |
| 1458 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1459 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1460 | } |
| 1461 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1462 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1463 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1464 | mAllowGeneratedReplies); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1465 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1466 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1467 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1468 | @Override |
| 1469 | public Action clone() { |
| 1470 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1471 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1472 | title, |
| 1473 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1474 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1475 | getRemoteInputs(), |
| 1476 | getAllowGeneratedReplies()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1477 | } |
| 1478 | @Override |
| 1479 | public int describeContents() { |
| 1480 | return 0; |
| 1481 | } |
| 1482 | @Override |
| 1483 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1484 | final Icon ic = getIcon(); |
| 1485 | if (ic != null) { |
| 1486 | out.writeInt(1); |
| 1487 | ic.writeToParcel(out, 0); |
| 1488 | } else { |
| 1489 | out.writeInt(0); |
| 1490 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1491 | TextUtils.writeToParcel(title, out, flags); |
| 1492 | if (actionIntent != null) { |
| 1493 | out.writeInt(1); |
| 1494 | actionIntent.writeToParcel(out, flags); |
| 1495 | } else { |
| 1496 | out.writeInt(0); |
| 1497 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1498 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1499 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1500 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1501 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1502 | public static final Parcelable.Creator<Action> CREATOR = |
| 1503 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1504 | public Action createFromParcel(Parcel in) { |
| 1505 | return new Action(in); |
| 1506 | } |
| 1507 | public Action[] newArray(int size) { |
| 1508 | return new Action[size]; |
| 1509 | } |
| 1510 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1511 | |
| 1512 | /** |
| 1513 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1514 | * metadata or change options on an action builder. |
| 1515 | */ |
| 1516 | public interface Extender { |
| 1517 | /** |
| 1518 | * Apply this extender to a notification action builder. |
| 1519 | * @param builder the builder to be modified. |
| 1520 | * @return the build object for chaining. |
| 1521 | */ |
| 1522 | public Builder extend(Builder builder); |
| 1523 | } |
| 1524 | |
| 1525 | /** |
| 1526 | * Wearable extender for notification actions. To add extensions to an action, |
| 1527 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1528 | * the {@code WearableExtender()} constructor and apply it to a |
| 1529 | * {@link android.app.Notification.Action.Builder} using |
| 1530 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1531 | * |
| 1532 | * <pre class="prettyprint"> |
| 1533 | * Notification.Action action = new Notification.Action.Builder( |
| 1534 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1535 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1536 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1537 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1538 | */ |
| 1539 | public static final class WearableExtender implements Extender { |
| 1540 | /** Notification action extra which contains wearable extensions */ |
| 1541 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1542 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1543 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1544 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1545 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1546 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1547 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1548 | |
| 1549 | // Flags bitwise-ored to mFlags |
| 1550 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1551 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1552 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1553 | |
| 1554 | // Default value for flags integer |
| 1555 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1556 | |
| 1557 | private int mFlags = DEFAULT_FLAGS; |
| 1558 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1559 | private CharSequence mInProgressLabel; |
| 1560 | private CharSequence mConfirmLabel; |
| 1561 | private CharSequence mCancelLabel; |
| 1562 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1563 | /** |
| 1564 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1565 | * options. |
| 1566 | */ |
| 1567 | public WearableExtender() { |
| 1568 | } |
| 1569 | |
| 1570 | /** |
| 1571 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1572 | * wearable options present in an existing notification action. |
| 1573 | * @param action the notification action to inspect. |
| 1574 | */ |
| 1575 | public WearableExtender(Action action) { |
| 1576 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1577 | if (wearableBundle != null) { |
| 1578 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1579 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1580 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1581 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | /** |
| 1586 | * Apply wearable extensions to a notification action that is being built. This is |
| 1587 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1588 | * method of {@link android.app.Notification.Action.Builder}. |
| 1589 | */ |
| 1590 | @Override |
| 1591 | public Action.Builder extend(Action.Builder builder) { |
| 1592 | Bundle wearableBundle = new Bundle(); |
| 1593 | |
| 1594 | if (mFlags != DEFAULT_FLAGS) { |
| 1595 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1596 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1597 | if (mInProgressLabel != null) { |
| 1598 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1599 | } |
| 1600 | if (mConfirmLabel != null) { |
| 1601 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1602 | } |
| 1603 | if (mCancelLabel != null) { |
| 1604 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1605 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1606 | |
| 1607 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1608 | return builder; |
| 1609 | } |
| 1610 | |
| 1611 | @Override |
| 1612 | public WearableExtender clone() { |
| 1613 | WearableExtender that = new WearableExtender(); |
| 1614 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1615 | that.mInProgressLabel = this.mInProgressLabel; |
| 1616 | that.mConfirmLabel = this.mConfirmLabel; |
| 1617 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1618 | return that; |
| 1619 | } |
| 1620 | |
| 1621 | /** |
| 1622 | * Set whether this action is available when the wearable device is not connected to |
| 1623 | * a companion device. The user can still trigger this action when the wearable device is |
| 1624 | * offline, but a visual hint will indicate that the action may not be available. |
| 1625 | * Defaults to true. |
| 1626 | */ |
| 1627 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1628 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1629 | return this; |
| 1630 | } |
| 1631 | |
| 1632 | /** |
| 1633 | * Get whether this action is available when the wearable device is not connected to |
| 1634 | * a companion device. The user can still trigger this action when the wearable device is |
| 1635 | * offline, but a visual hint will indicate that the action may not be available. |
| 1636 | * Defaults to true. |
| 1637 | */ |
| 1638 | public boolean isAvailableOffline() { |
| 1639 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1640 | } |
| 1641 | |
| 1642 | private void setFlag(int mask, boolean value) { |
| 1643 | if (value) { |
| 1644 | mFlags |= mask; |
| 1645 | } else { |
| 1646 | mFlags &= ~mask; |
| 1647 | } |
| 1648 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1649 | |
| 1650 | /** |
| 1651 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1652 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1653 | * |
| 1654 | * @param label the label to display while the action is being prepared to execute |
| 1655 | * @return this object for method chaining |
| 1656 | */ |
| 1657 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1658 | mInProgressLabel = label; |
| 1659 | return this; |
| 1660 | } |
| 1661 | |
| 1662 | /** |
| 1663 | * Get the label to display while the wearable is preparing to automatically execute |
| 1664 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1665 | * |
| 1666 | * @return the label to display while the action is being prepared to execute |
| 1667 | */ |
| 1668 | public CharSequence getInProgressLabel() { |
| 1669 | return mInProgressLabel; |
| 1670 | } |
| 1671 | |
| 1672 | /** |
| 1673 | * Set a label to display to confirm that the action should be executed. |
| 1674 | * This is usually an imperative verb like "Send". |
| 1675 | * |
| 1676 | * @param label the label to confirm the action should be executed |
| 1677 | * @return this object for method chaining |
| 1678 | */ |
| 1679 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1680 | mConfirmLabel = label; |
| 1681 | return this; |
| 1682 | } |
| 1683 | |
| 1684 | /** |
| 1685 | * Get the label to display to confirm that the action should be executed. |
| 1686 | * This is usually an imperative verb like "Send". |
| 1687 | * |
| 1688 | * @return the label to confirm the action should be executed |
| 1689 | */ |
| 1690 | public CharSequence getConfirmLabel() { |
| 1691 | return mConfirmLabel; |
| 1692 | } |
| 1693 | |
| 1694 | /** |
| 1695 | * Set a label to display to cancel the action. |
| 1696 | * This is usually an imperative verb, like "Cancel". |
| 1697 | * |
| 1698 | * @param label the label to display to cancel the action |
| 1699 | * @return this object for method chaining |
| 1700 | */ |
| 1701 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1702 | mCancelLabel = label; |
| 1703 | return this; |
| 1704 | } |
| 1705 | |
| 1706 | /** |
| 1707 | * Get the label to display to cancel the action. |
| 1708 | * This is usually an imperative verb like "Cancel". |
| 1709 | * |
| 1710 | * @return the label to display to cancel the action |
| 1711 | */ |
| 1712 | public CharSequence getCancelLabel() { |
| 1713 | return mCancelLabel; |
| 1714 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1715 | |
| 1716 | /** |
| 1717 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 1718 | * platform that it can generate the appropriate transitions. |
| 1719 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 1720 | * an activity and transitions should be generated, false otherwise. |
| 1721 | * @return this object for method chaining |
| 1722 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1723 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1724 | boolean hintLaunchesActivity) { |
| 1725 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 1726 | return this; |
| 1727 | } |
| 1728 | |
| 1729 | /** |
| 1730 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 1731 | * platform that it can generate the appropriate transitions |
| 1732 | * @return {@code true} if the content intent will launch an activity and transitions |
| 1733 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 1734 | * never set. |
| 1735 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1736 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1737 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 1738 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1739 | |
| 1740 | /** |
| 1741 | * Set a hint that this Action should be displayed inline. |
| 1742 | * |
| 1743 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 1744 | * otherwise |
| 1745 | * @return this object for method chaining |
| 1746 | */ |
| 1747 | public WearableExtender setHintDisplayActionInline( |
| 1748 | boolean hintDisplayInline) { |
| 1749 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 1750 | return this; |
| 1751 | } |
| 1752 | |
| 1753 | /** |
| 1754 | * Get a hint that this Action should be displayed inline. |
| 1755 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 1756 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1757 | * otherwise. The default value is {@code false} if this was never set. |
| 1758 | */ |
| 1759 | public boolean getHintDisplayActionInline() { |
| 1760 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 1761 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1762 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1763 | } |
| 1764 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1765 | /** |
| 1766 | * Array of all {@link Action} structures attached to this notification by |
| 1767 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 1768 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 1769 | * interface for invoking actions. |
| 1770 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1771 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1772 | |
| 1773 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1774 | * Replacement version of this notification whose content will be shown |
| 1775 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 1776 | * and {@link #VISIBILITY_PUBLIC}. |
| 1777 | */ |
| 1778 | public Notification publicVersion; |
| 1779 | |
| 1780 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1781 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1782 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1783 | */ |
| 1784 | public Notification() |
| 1785 | { |
| 1786 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1787 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1788 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1792 | * @hide |
| 1793 | */ |
| 1794 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 1795 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 1796 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1797 | new Builder(context) |
| 1798 | .setWhen(when) |
| 1799 | .setSmallIcon(icon) |
| 1800 | .setTicker(tickerText) |
| 1801 | .setContentTitle(contentTitle) |
| 1802 | .setContentText(contentText) |
| 1803 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 1804 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | /** |
| 1808 | * Constructs a Notification object with the information needed to |
| 1809 | * have a status bar icon without the standard expanded view. |
| 1810 | * |
| 1811 | * @param icon The resource id of the icon to put in the status bar. |
| 1812 | * @param tickerText The text that flows by in the status bar when the notification first |
| 1813 | * activates. |
| 1814 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 1815 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1816 | * |
| 1817 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1818 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1819 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1820 | public Notification(int icon, CharSequence tickerText, long when) |
| 1821 | { |
| 1822 | this.icon = icon; |
| 1823 | this.tickerText = tickerText; |
| 1824 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1825 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | /** |
| 1829 | * Unflatten the notification from a parcel. |
| 1830 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 1831 | @SuppressWarnings("unchecked") |
| 1832 | public Notification(Parcel parcel) { |
| 1833 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 1834 | // intents in extras are always written as the last entry. |
| 1835 | readFromParcelImpl(parcel); |
| 1836 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 1837 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1841 | { |
| 1842 | int version = parcel.readInt(); |
| 1843 | |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 1844 | whitelistToken = parcel.readStrongBinder(); |
| 1845 | if (whitelistToken == null) { |
| 1846 | whitelistToken = processWhitelistToken; |
| 1847 | } |
| 1848 | // Propagate this token to all pending intents that are unmarshalled from the parcel. |
| 1849 | parcel.setClassCookie(PendingIntent.class, whitelistToken); |
| 1850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1851 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1852 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1853 | if (parcel.readInt() != 0) { |
| 1854 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1855 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1856 | icon = mSmallIcon.getResId(); |
| 1857 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1858 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1859 | number = parcel.readInt(); |
| 1860 | if (parcel.readInt() != 0) { |
| 1861 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1862 | } |
| 1863 | if (parcel.readInt() != 0) { |
| 1864 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1865 | } |
| 1866 | if (parcel.readInt() != 0) { |
| 1867 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1868 | } |
| 1869 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1870 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1871 | } |
| 1872 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1873 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1874 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1875 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1876 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1877 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1878 | defaults = parcel.readInt(); |
| 1879 | flags = parcel.readInt(); |
| 1880 | if (parcel.readInt() != 0) { |
| 1881 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 1882 | } |
| 1883 | |
| 1884 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1885 | if (parcel.readInt() != 0) { |
| 1886 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 1887 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1888 | vibrate = parcel.createLongArray(); |
| 1889 | ledARGB = parcel.readInt(); |
| 1890 | ledOnMS = parcel.readInt(); |
| 1891 | ledOffMS = parcel.readInt(); |
| 1892 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1893 | |
| 1894 | if (parcel.readInt() != 0) { |
| 1895 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1896 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1897 | |
| 1898 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1899 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1900 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1901 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1902 | mGroupKey = parcel.readString(); |
| 1903 | |
| 1904 | mSortKey = parcel.readString(); |
| 1905 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1906 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1907 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1908 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 1909 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1910 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1911 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1912 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1913 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1914 | if (parcel.readInt() != 0) { |
| 1915 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1916 | } |
| 1917 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1918 | visibility = parcel.readInt(); |
| 1919 | |
| 1920 | if (parcel.readInt() != 0) { |
| 1921 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 1922 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1923 | |
| 1924 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1925 | |
| 1926 | if (parcel.readInt() != 0) { |
| 1927 | mChannelId = parcel.readString(); |
| 1928 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1929 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1930 | |
| 1931 | if (parcel.readInt() != 0) { |
| 1932 | mShortcutId = parcel.readString(); |
| 1933 | } |
| 1934 | |
| 1935 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1936 | |
| 1937 | if (parcel.readInt() != 0) { |
| 1938 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1939 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1940 | |
| 1941 | mGroupAlertBehavior = parcel.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1942 | } |
| 1943 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1944 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1945 | public Notification clone() { |
| 1946 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1947 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1948 | return that; |
| 1949 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1950 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1951 | /** |
| 1952 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 1953 | * of this into that. |
| 1954 | * @hide |
| 1955 | */ |
| 1956 | public void cloneInto(Notification that, boolean heavy) { |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 1957 | that.whitelistToken = this.whitelistToken; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1958 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1959 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1960 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1961 | that.number = this.number; |
| 1962 | |
| 1963 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 1964 | that.contentIntent = this.contentIntent; |
| 1965 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1966 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1967 | |
| 1968 | if (this.tickerText != null) { |
| 1969 | that.tickerText = this.tickerText.toString(); |
| 1970 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1971 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1972 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1973 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1974 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1975 | that.contentView = this.contentView.clone(); |
| 1976 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1977 | if (heavy && this.mLargeIcon != null) { |
| 1978 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1979 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 1980 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1981 | that.sound = this.sound; // android.net.Uri is immutable |
| 1982 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1983 | if (this.audioAttributes != null) { |
| 1984 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 1985 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1986 | |
| 1987 | final long[] vibrate = this.vibrate; |
| 1988 | if (vibrate != null) { |
| 1989 | final int N = vibrate.length; |
| 1990 | final long[] vib = that.vibrate = new long[N]; |
| 1991 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 1992 | } |
| 1993 | |
| 1994 | that.ledARGB = this.ledARGB; |
| 1995 | that.ledOnMS = this.ledOnMS; |
| 1996 | that.ledOffMS = this.ledOffMS; |
| 1997 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1998 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1999 | that.flags = this.flags; |
| 2000 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2001 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2002 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2003 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2004 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2005 | that.mGroupKey = this.mGroupKey; |
| 2006 | |
| 2007 | that.mSortKey = this.mSortKey; |
| 2008 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2009 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2010 | try { |
| 2011 | that.extras = new Bundle(this.extras); |
| 2012 | // will unparcel |
| 2013 | that.extras.size(); |
| 2014 | } catch (BadParcelableException e) { |
| 2015 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2016 | that.extras = null; |
| 2017 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2018 | } |
| 2019 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2020 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2021 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2024 | if (this.actions != null) { |
| 2025 | that.actions = new Action[this.actions.length]; |
| 2026 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 2027 | if ( this.actions[i] != null) { |
| 2028 | that.actions[i] = this.actions[i].clone(); |
| 2029 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2030 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2031 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2032 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2033 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2034 | that.bigContentView = this.bigContentView.clone(); |
| 2035 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2036 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2037 | if (heavy && this.headsUpContentView != null) { |
| 2038 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 2039 | } |
| 2040 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2041 | that.visibility = this.visibility; |
| 2042 | |
| 2043 | if (this.publicVersion != null) { |
| 2044 | that.publicVersion = new Notification(); |
| 2045 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2046 | } |
| 2047 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2048 | that.color = this.color; |
| 2049 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2050 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2051 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2052 | that.mShortcutId = this.mShortcutId; |
| 2053 | that.mBadgeIcon = this.mBadgeIcon; |
| 2054 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2055 | that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2056 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2057 | if (!heavy) { |
| 2058 | that.lightenPayload(); // will clean out extras |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | /** |
| 2063 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 2064 | * listeners when the full contents are not necessary. |
| 2065 | * @hide |
| 2066 | */ |
| 2067 | public final void lightenPayload() { |
| 2068 | tickerView = null; |
| 2069 | contentView = null; |
| 2070 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2071 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2072 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2073 | if (extras != null && !extras.isEmpty()) { |
| 2074 | final Set<String> keyset = extras.keySet(); |
| 2075 | final int N = keyset.size(); |
| 2076 | final String[] keys = keyset.toArray(new String[N]); |
| 2077 | for (int i=0; i<N; i++) { |
| 2078 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2079 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2080 | continue; |
| 2081 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2082 | final Object obj = extras.get(key); |
| 2083 | if (obj != null && |
| 2084 | ( obj instanceof Parcelable |
| 2085 | || obj instanceof Parcelable[] |
| 2086 | || obj instanceof SparseArray |
| 2087 | || obj instanceof ArrayList)) { |
| 2088 | extras.remove(key); |
| 2089 | } |
| 2090 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2091 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2094 | /** |
| 2095 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2096 | * means it had better not be some custom Parcelable implementation. |
| 2097 | * @hide |
| 2098 | */ |
| 2099 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2100 | if (cs == null) return cs; |
| 2101 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2102 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2103 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2104 | if (cs instanceof Parcelable) { |
| 2105 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2106 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2107 | return cs.toString(); |
| 2108 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2109 | return removeTextSizeSpans(cs); |
| 2110 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2111 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2112 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2113 | if (charSequence instanceof Spanned) { |
| 2114 | Spanned ss = (Spanned) charSequence; |
| 2115 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2116 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2117 | for (Object span : spans) { |
| 2118 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2119 | if (resultSpan instanceof CharacterStyle) { |
| 2120 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2121 | } |
| 2122 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2123 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2124 | resultSpan = new TextAppearanceSpan( |
| 2125 | originalSpan.getFamily(), |
| 2126 | originalSpan.getTextStyle(), |
| 2127 | -1, |
| 2128 | originalSpan.getTextColor(), |
| 2129 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2130 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2131 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2132 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2133 | } else { |
| 2134 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2135 | } |
| 2136 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2137 | ss.getSpanFlags(span)); |
| 2138 | } |
| 2139 | return builder; |
| 2140 | } |
| 2141 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2142 | } |
| 2143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2144 | public int describeContents() { |
| 2145 | return 0; |
| 2146 | } |
| 2147 | |
| 2148 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2149 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2151 | public void writeToParcel(Parcel parcel, int flags) { |
| 2152 | // We need to mark all pending intents getting into the notification |
| 2153 | // system as being put there to later allow the notification ranker |
| 2154 | // to launch them and by doing so add the app to the battery saver white |
| 2155 | // list for a short period of time. The problem is that the system |
| 2156 | // cannot look into the extras as there may be parcelables there that |
| 2157 | // the platform does not know how to handle. To go around that we have |
| 2158 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2159 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2160 | if (collectPendingIntents) { |
| 2161 | PendingIntent.setOnMarshaledListener( |
| 2162 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2163 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2164 | if (allPendingIntents == null) { |
| 2165 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2166 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2167 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2168 | } |
| 2169 | }); |
| 2170 | } |
| 2171 | try { |
| 2172 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2173 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2174 | writeToParcelImpl(parcel, flags); |
| 2175 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2176 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2177 | } finally { |
| 2178 | if (collectPendingIntents) { |
| 2179 | PendingIntent.setOnMarshaledListener(null); |
| 2180 | } |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | parcel.writeInt(1); |
| 2186 | |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2187 | parcel.writeStrongBinder(whitelistToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2189 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2190 | if (mSmallIcon == null && icon != 0) { |
| 2191 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2192 | mSmallIcon = Icon.createWithResource("", icon); |
| 2193 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2194 | if (mSmallIcon != null) { |
| 2195 | parcel.writeInt(1); |
| 2196 | mSmallIcon.writeToParcel(parcel, 0); |
| 2197 | } else { |
| 2198 | parcel.writeInt(0); |
| 2199 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2200 | parcel.writeInt(number); |
| 2201 | if (contentIntent != null) { |
| 2202 | parcel.writeInt(1); |
| 2203 | contentIntent.writeToParcel(parcel, 0); |
| 2204 | } else { |
| 2205 | parcel.writeInt(0); |
| 2206 | } |
| 2207 | if (deleteIntent != null) { |
| 2208 | parcel.writeInt(1); |
| 2209 | deleteIntent.writeToParcel(parcel, 0); |
| 2210 | } else { |
| 2211 | parcel.writeInt(0); |
| 2212 | } |
| 2213 | if (tickerText != null) { |
| 2214 | parcel.writeInt(1); |
| 2215 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2216 | } else { |
| 2217 | parcel.writeInt(0); |
| 2218 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2219 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2220 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2221 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2222 | } else { |
| 2223 | parcel.writeInt(0); |
| 2224 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2225 | if (contentView != null) { |
| 2226 | parcel.writeInt(1); |
| 2227 | contentView.writeToParcel(parcel, 0); |
| 2228 | } else { |
| 2229 | parcel.writeInt(0); |
| 2230 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2231 | if (mLargeIcon == null && largeIcon != null) { |
| 2232 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2233 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2234 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2235 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2236 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2237 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2238 | } else { |
| 2239 | parcel.writeInt(0); |
| 2240 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2241 | |
| 2242 | parcel.writeInt(defaults); |
| 2243 | parcel.writeInt(this.flags); |
| 2244 | |
| 2245 | if (sound != null) { |
| 2246 | parcel.writeInt(1); |
| 2247 | sound.writeToParcel(parcel, 0); |
| 2248 | } else { |
| 2249 | parcel.writeInt(0); |
| 2250 | } |
| 2251 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2252 | |
| 2253 | if (audioAttributes != null) { |
| 2254 | parcel.writeInt(1); |
| 2255 | audioAttributes.writeToParcel(parcel, 0); |
| 2256 | } else { |
| 2257 | parcel.writeInt(0); |
| 2258 | } |
| 2259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | parcel.writeLongArray(vibrate); |
| 2261 | parcel.writeInt(ledARGB); |
| 2262 | parcel.writeInt(ledOnMS); |
| 2263 | parcel.writeInt(ledOffMS); |
| 2264 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2265 | |
| 2266 | if (fullScreenIntent != null) { |
| 2267 | parcel.writeInt(1); |
| 2268 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2269 | } else { |
| 2270 | parcel.writeInt(0); |
| 2271 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2272 | |
| 2273 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2274 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2275 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2276 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2277 | parcel.writeString(mGroupKey); |
| 2278 | |
| 2279 | parcel.writeString(mSortKey); |
| 2280 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2281 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2282 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2283 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2284 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2285 | if (bigContentView != null) { |
| 2286 | parcel.writeInt(1); |
| 2287 | bigContentView.writeToParcel(parcel, 0); |
| 2288 | } else { |
| 2289 | parcel.writeInt(0); |
| 2290 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2291 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2292 | if (headsUpContentView != null) { |
| 2293 | parcel.writeInt(1); |
| 2294 | headsUpContentView.writeToParcel(parcel, 0); |
| 2295 | } else { |
| 2296 | parcel.writeInt(0); |
| 2297 | } |
| 2298 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2299 | parcel.writeInt(visibility); |
| 2300 | |
| 2301 | if (publicVersion != null) { |
| 2302 | parcel.writeInt(1); |
| 2303 | publicVersion.writeToParcel(parcel, 0); |
| 2304 | } else { |
| 2305 | parcel.writeInt(0); |
| 2306 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2307 | |
| 2308 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2309 | |
| 2310 | if (mChannelId != null) { |
| 2311 | parcel.writeInt(1); |
| 2312 | parcel.writeString(mChannelId); |
| 2313 | } else { |
| 2314 | parcel.writeInt(0); |
| 2315 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2316 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2317 | |
| 2318 | if (mShortcutId != null) { |
| 2319 | parcel.writeInt(1); |
| 2320 | parcel.writeString(mShortcutId); |
| 2321 | } else { |
| 2322 | parcel.writeInt(0); |
| 2323 | } |
| 2324 | |
| 2325 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2326 | |
| 2327 | if (mSettingsText != null) { |
| 2328 | parcel.writeInt(1); |
| 2329 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2330 | } else { |
| 2331 | parcel.writeInt(0); |
| 2332 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2333 | |
| 2334 | parcel.writeInt(mGroupAlertBehavior); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | /** |
| 2338 | * Parcelable.Creator that instantiates Notification objects |
| 2339 | */ |
| 2340 | public static final Parcelable.Creator<Notification> CREATOR |
| 2341 | = new Parcelable.Creator<Notification>() |
| 2342 | { |
| 2343 | public Notification createFromParcel(Parcel parcel) |
| 2344 | { |
| 2345 | return new Notification(parcel); |
| 2346 | } |
| 2347 | |
| 2348 | public Notification[] newArray(int size) |
| 2349 | { |
| 2350 | return new Notification[size]; |
| 2351 | } |
| 2352 | }; |
| 2353 | |
| 2354 | /** |
| 2355 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2356 | * layout. |
| 2357 | * |
| 2358 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2359 | * in the view.</p> |
| 2360 | * @param context The context for your application / activity. |
| 2361 | * @param contentTitle The title that goes in the expanded entry. |
| 2362 | * @param contentText The text that goes in the expanded entry. |
| 2363 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2364 | * If this is an activity, it must include the |
| 2365 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2366 | * that you take care of task management as described in the |
| 2367 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2368 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2369 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2370 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2371 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2372 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2373 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | public void setLatestEventInfo(Context context, |
| 2375 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2376 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2377 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2378 | new Throwable()); |
| 2379 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2380 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2381 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2382 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2383 | } |
| 2384 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2385 | // ensure that any information already set directly is preserved |
| 2386 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2387 | |
| 2388 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2389 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2390 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | } |
| 2392 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2393 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2394 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2395 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2396 | |
| 2397 | 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] | 2398 | } |
| 2399 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2400 | /** |
| 2401 | * @hide |
| 2402 | */ |
| 2403 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2404 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | /** |
| 2408 | * @hide |
| 2409 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2410 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2411 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2412 | } |
| 2413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2414 | @Override |
| 2415 | public String toString() { |
| 2416 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2417 | sb.append("Notification(channel="); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2418 | sb.append(getChannelId()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2419 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2420 | sb.append(priority); |
| 2421 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2422 | if (contentView != null) { |
| 2423 | sb.append(contentView.getPackage()); |
| 2424 | sb.append("/0x"); |
| 2425 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2426 | } else { |
| 2427 | sb.append("null"); |
| 2428 | } |
| 2429 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2430 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2431 | sb.append("default"); |
| 2432 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | int N = this.vibrate.length-1; |
| 2434 | sb.append("["); |
| 2435 | for (int i=0; i<N; i++) { |
| 2436 | sb.append(this.vibrate[i]); |
| 2437 | sb.append(','); |
| 2438 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 2439 | if (N != -1) { |
| 2440 | sb.append(this.vibrate[N]); |
| 2441 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2442 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2443 | } else { |
| 2444 | sb.append("null"); |
| 2445 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2446 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2447 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2449 | } else if (this.sound != null) { |
| 2450 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | } else { |
| 2452 | sb.append("null"); |
| 2453 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 2454 | if (this.tickerText != null) { |
| 2455 | sb.append(" tick"); |
| 2456 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2457 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2459 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2460 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2461 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2462 | if (this.category != null) { |
| 2463 | sb.append(" category="); |
| 2464 | sb.append(this.category); |
| 2465 | } |
| 2466 | if (this.mGroupKey != null) { |
| 2467 | sb.append(" groupKey="); |
| 2468 | sb.append(this.mGroupKey); |
| 2469 | } |
| 2470 | if (this.mSortKey != null) { |
| 2471 | sb.append(" sortKey="); |
| 2472 | sb.append(this.mSortKey); |
| 2473 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2474 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2475 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2476 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2477 | } |
| 2478 | sb.append(" vis="); |
| 2479 | sb.append(visibilityToString(this.visibility)); |
| 2480 | if (this.publicVersion != null) { |
| 2481 | sb.append(" publicVersion="); |
| 2482 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2483 | } |
| 2484 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2485 | return sb.toString(); |
| 2486 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2487 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2488 | /** |
| 2489 | * {@hide} |
| 2490 | */ |
| 2491 | public static String visibilityToString(int vis) { |
| 2492 | switch (vis) { |
| 2493 | case VISIBILITY_PRIVATE: |
| 2494 | return "PRIVATE"; |
| 2495 | case VISIBILITY_PUBLIC: |
| 2496 | return "PUBLIC"; |
| 2497 | case VISIBILITY_SECRET: |
| 2498 | return "SECRET"; |
| 2499 | default: |
| 2500 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 2501 | } |
| 2502 | } |
| 2503 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2504 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 2505 | * {@hide} |
| 2506 | */ |
| 2507 | public static String priorityToString(@Priority int pri) { |
| 2508 | switch (pri) { |
| 2509 | case PRIORITY_MIN: |
| 2510 | return "MIN"; |
| 2511 | case PRIORITY_LOW: |
| 2512 | return "LOW"; |
| 2513 | case PRIORITY_DEFAULT: |
| 2514 | return "DEFAULT"; |
| 2515 | case PRIORITY_HIGH: |
| 2516 | return "HIGH"; |
| 2517 | case PRIORITY_MAX: |
| 2518 | return "MAX"; |
| 2519 | default: |
| 2520 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 2521 | } |
| 2522 | } |
| 2523 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2524 | /** @removed */ |
| 2525 | @Deprecated |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 2526 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2527 | return mChannelId; |
| 2528 | } |
| 2529 | |
| 2530 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2531 | * Returns the id of the channel this notification posts to. |
| 2532 | */ |
| 2533 | public String getChannelId() { |
| 2534 | return mChannelId; |
| 2535 | } |
| 2536 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2537 | /** @removed */ |
| 2538 | @Deprecated |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2539 | public long getTimeout() { |
| 2540 | return mTimeout; |
| 2541 | } |
| 2542 | |
| 2543 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2544 | * Returns the duration from posting after which this notification should be canceled by the |
| 2545 | * system, if it's not canceled already. |
| 2546 | */ |
| 2547 | public long getTimeoutAfter() { |
| 2548 | return mTimeout; |
| 2549 | } |
| 2550 | |
| 2551 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2552 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 2553 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 2554 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 2555 | */ |
| 2556 | public int getBadgeIconType() { |
| 2557 | return mBadgeIcon; |
| 2558 | } |
| 2559 | |
| 2560 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2561 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2562 | * |
| 2563 | * <p>Used by some Launchers that display notification content to hide shortcuts that duplicate |
| 2564 | * notifications. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2565 | */ |
| 2566 | public String getShortcutId() { |
| 2567 | return mShortcutId; |
| 2568 | } |
| 2569 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2570 | |
| 2571 | /** |
| 2572 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 2573 | */ |
| 2574 | public CharSequence getSettingsText() { |
| 2575 | return mSettingsText; |
| 2576 | } |
| 2577 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2578 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2579 | * Returns which type of notifications in a group are responsible for audibly alerting the |
| 2580 | * user. See {@link #GROUP_ALERT_ALL}, {@link #GROUP_ALERT_CHILDREN}, |
| 2581 | * {@link #GROUP_ALERT_SUMMARY}. |
| 2582 | */ |
| 2583 | public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 2584 | return mGroupAlertBehavior; |
| 2585 | } |
| 2586 | |
| 2587 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2588 | * The small icon representing this notification in the status bar and content view. |
| 2589 | * |
| 2590 | * @return the small icon representing this notification. |
| 2591 | * |
| 2592 | * @see Builder#getSmallIcon() |
| 2593 | * @see Builder#setSmallIcon(Icon) |
| 2594 | */ |
| 2595 | public Icon getSmallIcon() { |
| 2596 | return mSmallIcon; |
| 2597 | } |
| 2598 | |
| 2599 | /** |
| 2600 | * Used when notifying to clean up legacy small icons. |
| 2601 | * @hide |
| 2602 | */ |
| 2603 | public void setSmallIcon(Icon icon) { |
| 2604 | mSmallIcon = icon; |
| 2605 | } |
| 2606 | |
| 2607 | /** |
| 2608 | * The large icon shown in this notification's content view. |
| 2609 | * @see Builder#getLargeIcon() |
| 2610 | * @see Builder#setLargeIcon(Icon) |
| 2611 | */ |
| 2612 | public Icon getLargeIcon() { |
| 2613 | return mLargeIcon; |
| 2614 | } |
| 2615 | |
| 2616 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2617 | * @hide |
| 2618 | */ |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 2619 | public boolean isGroupSummary() { |
| 2620 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 2621 | } |
| 2622 | |
| 2623 | /** |
| 2624 | * @hide |
| 2625 | */ |
| 2626 | public boolean isGroupChild() { |
| 2627 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 2628 | } |
| 2629 | |
| 2630 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2631 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2632 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2633 | * 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] | 2634 | * content views using the platform's notification layout template. If your app supports |
| 2635 | * versions of Android as old as API level 4, you can instead use |
| 2636 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 2637 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 2638 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2639 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2640 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2641 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2642 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2643 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2644 | * .setContentTitle("New mail from " + sender.toString()) |
| 2645 | * .setContentText(subject) |
| 2646 | * .setSmallIcon(R.drawable.new_mail) |
| 2647 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2648 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2649 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2650 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2651 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 2652 | /** |
| 2653 | * @hide |
| 2654 | */ |
| 2655 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 2656 | "android.rebuild.contentViewActionCount"; |
| 2657 | /** |
| 2658 | * @hide |
| 2659 | */ |
| 2660 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 2661 | = "android.rebuild.bigViewActionCount"; |
| 2662 | /** |
| 2663 | * @hide |
| 2664 | */ |
| 2665 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 2666 | = "android.rebuild.hudViewActionCount"; |
| 2667 | |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 2668 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2669 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 2670 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 2671 | SystemProperties.getBoolean("notifications.only_title", true); |
| 2672 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2673 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2674 | private Notification mN; |
| 2675 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2676 | private Style mStyle; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2677 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
| 2678 | private ArrayList<String> mPersonList = new ArrayList<String>(); |
| 2679 | private NotificationColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 2680 | private boolean mIsLegacy; |
| 2681 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2682 | |
| 2683 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2684 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 2685 | */ |
| 2686 | private int mCachedContrastColor = COLOR_INVALID; |
| 2687 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 2688 | /** |
| 2689 | * Caches a ambient version of {@link #mCachedContrastColorIsFor}. |
| 2690 | */ |
| 2691 | private int mCachedAmbientColor = COLOR_INVALID; |
| 2692 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2693 | |
| 2694 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 2695 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 2696 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 2697 | */ |
| 2698 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 2699 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 2700 | private int mPrimaryTextColor = COLOR_INVALID; |
| 2701 | private int mSecondaryTextColor = COLOR_INVALID; |
| 2702 | private int mActionBarColor = COLOR_INVALID; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 2703 | private int mBackgroundColor = COLOR_INVALID; |
| 2704 | private int mForegroundColor = COLOR_INVALID; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 2705 | private int mBackgroundColorHint = COLOR_INVALID; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame^] | 2706 | private boolean mRebuildStyledRemoteViews; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 2707 | |
| 2708 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2709 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2710 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2711 | * @param context |
| 2712 | * A {@link Context} that will be used by the Builder to construct the |
| 2713 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 2714 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 2715 | * @param channelId |
| 2716 | * The constructed Notification will be posted on this |
| 2717 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 2718 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2719 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 2720 | public Builder(Context context, String channelId) { |
| 2721 | this(context, (Notification) null); |
| 2722 | mN.mChannelId = channelId; |
| 2723 | } |
| 2724 | |
| 2725 | /** |
| 2726 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 2727 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 2728 | */ |
| 2729 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2730 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 2731 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2732 | } |
| 2733 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2734 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2735 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2736 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2737 | public Builder(Context context, Notification toAdopt) { |
| 2738 | mContext = context; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2739 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2740 | if (toAdopt == null) { |
| 2741 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 2742 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2743 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2744 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2745 | mN.priority = PRIORITY_DEFAULT; |
| 2746 | mN.visibility = VISIBILITY_PRIVATE; |
| 2747 | } else { |
| 2748 | mN = toAdopt; |
| 2749 | if (mN.actions != null) { |
| 2750 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2751 | } |
| 2752 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2753 | if (mN.extras.containsKey(EXTRA_PEOPLE)) { |
| 2754 | Collections.addAll(mPersonList, mN.extras.getStringArray(EXTRA_PEOPLE)); |
| 2755 | } |
| 2756 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2757 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 2758 | setSmallIcon(mN.icon); |
| 2759 | } |
| 2760 | |
| 2761 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 2762 | setLargeIcon(mN.largeIcon); |
| 2763 | } |
| 2764 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2765 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 2766 | if (!TextUtils.isEmpty(templateClass)) { |
| 2767 | final Class<? extends Style> styleClass |
| 2768 | = getNotificationStyleClass(templateClass); |
| 2769 | if (styleClass == null) { |
| 2770 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 2771 | } else { |
| 2772 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 2773 | final Constructor<? extends Style> ctor = |
| 2774 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2775 | ctor.setAccessible(true); |
| 2776 | final Style style = ctor.newInstance(); |
| 2777 | style.restoreFromExtras(mN.extras); |
| 2778 | |
| 2779 | if (style != null) { |
| 2780 | setStyle(style); |
| 2781 | } |
| 2782 | } catch (Throwable t) { |
| 2783 | Log.e(TAG, "Could not create Style", t); |
| 2784 | } |
| 2785 | } |
| 2786 | } |
| 2787 | |
| 2788 | } |
| 2789 | } |
| 2790 | |
| 2791 | private NotificationColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 2792 | if (mColorUtil == null) { |
| 2793 | mColorUtil = NotificationColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2794 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2795 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2799 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 2800 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 2801 | * the shortcut. |
| 2802 | * |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2803 | * This field will be ignored by Launchers that don't support badging, don't show |
| 2804 | * notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2805 | * |
| 2806 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 2807 | * supersedes |
| 2808 | */ |
| 2809 | public Builder setShortcutId(String shortcutId) { |
| 2810 | mN.mShortcutId = shortcutId; |
| 2811 | return this; |
| 2812 | } |
| 2813 | |
| 2814 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2815 | * Sets which icon to display as a badge for this notification. |
| 2816 | * |
| 2817 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 2818 | * {@link #BADGE_ICON_LARGE}. |
| 2819 | * |
| 2820 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 2821 | */ |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 2822 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2823 | mN.mBadgeIcon = icon; |
| 2824 | return this; |
| 2825 | } |
| 2826 | |
| 2827 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2828 | * Sets the group alert behavior for this notification. Use this method to mute this |
| 2829 | * notification if alerts for this notification's group should be handled by a different |
| 2830 | * notification. This is only applicable for notifications that belong to a |
| 2831 | * {@link #setGroup(String) group}. |
| 2832 | * |
| 2833 | * <p> The default value is {@link #GROUP_ALERT_ALL}.</p> |
| 2834 | */ |
| 2835 | public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 2836 | mN.mGroupAlertBehavior = groupAlertBehavior; |
| 2837 | return this; |
| 2838 | } |
| 2839 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2840 | /** @removed */ |
| 2841 | @Deprecated |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2842 | public Builder setChannel(String channelId) { |
| 2843 | mN.mChannelId = channelId; |
| 2844 | return this; |
| 2845 | } |
| 2846 | |
| 2847 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2848 | * Specifies the channel the notification should be delivered on. |
| 2849 | */ |
| 2850 | public Builder setChannelId(String channelId) { |
| 2851 | mN.mChannelId = channelId; |
| 2852 | return this; |
| 2853 | } |
| 2854 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2855 | /** @removed */ |
| 2856 | @Deprecated |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 2857 | public Builder setTimeout(long durationMs) { |
| 2858 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2859 | return this; |
| 2860 | } |
| 2861 | |
| 2862 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2863 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 2864 | * if it is not already canceled. |
| 2865 | */ |
| 2866 | public Builder setTimeoutAfter(long durationMs) { |
| 2867 | mN.mTimeout = durationMs; |
| 2868 | return this; |
| 2869 | } |
| 2870 | |
| 2871 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2872 | * 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] | 2873 | * |
| 2874 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 2875 | * shown anymore by default and must be opted into by using |
| 2876 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2877 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2878 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2879 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2880 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2881 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2882 | return this; |
| 2883 | } |
| 2884 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2885 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2886 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2887 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 2888 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 2889 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2890 | */ |
| 2891 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2892 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2893 | return this; |
| 2894 | } |
| 2895 | |
| 2896 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2897 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2898 | * |
| 2899 | * 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] | 2900 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2901 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2902 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 2903 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2904 | * 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] | 2905 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2906 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2907 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2908 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 2909 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2910 | */ |
| 2911 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2912 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2913 | return this; |
| 2914 | } |
| 2915 | |
| 2916 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2917 | * Sets the Chronometer to count down instead of counting up. |
| 2918 | * |
| 2919 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 2920 | * If it isn't set the chronometer will count up. |
| 2921 | * |
| 2922 | * @see #setUsesChronometer(boolean) |
| 2923 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 2924 | public Builder setChronometerCountDown(boolean countDown) { |
| 2925 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2926 | return this; |
| 2927 | } |
| 2928 | |
| 2929 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2930 | * Set the small icon resource, which will be used to represent the notification in the |
| 2931 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2932 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2933 | |
| 2934 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 2935 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 2936 | * icon will be moved to the right-hand side. |
| 2937 | * |
| 2938 | |
| 2939 | * @param icon |
| 2940 | * A resource ID in the application's package of the drawable to use. |
| 2941 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2942 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2943 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2944 | return setSmallIcon(icon != 0 |
| 2945 | ? Icon.createWithResource(mContext, icon) |
| 2946 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2947 | } |
| 2948 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2949 | /** |
| 2950 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 2951 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 2952 | * LevelListDrawable}. |
| 2953 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2954 | * @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] | 2955 | * @param level The level to use for the icon. |
| 2956 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2957 | * @see Notification#icon |
| 2958 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2959 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 2960 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2961 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2962 | return setSmallIcon(icon); |
| 2963 | } |
| 2964 | |
| 2965 | /** |
| 2966 | * Set the small icon, which will be used to represent the notification in the |
| 2967 | * status bar and content view (unless overriden there by a |
| 2968 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 2969 | * |
| 2970 | * @param icon An Icon object to use. |
| 2971 | * @see Notification#icon |
| 2972 | */ |
| 2973 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2974 | mN.setSmallIcon(icon); |
| 2975 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 2976 | mN.icon = icon.getResId(); |
| 2977 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2978 | return this; |
| 2979 | } |
| 2980 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2981 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2982 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2983 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2984 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2985 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2986 | return this; |
| 2987 | } |
| 2988 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2989 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2990 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2991 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2992 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2993 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2994 | return this; |
| 2995 | } |
| 2996 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2997 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 2998 | * This provides some additional information that is displayed in the notification. No |
| 2999 | * guarantees are given where exactly it is displayed. |
| 3000 | * |
| 3001 | * <p>This information should only be provided if it provides an essential |
| 3002 | * benefit to the understanding of the notification. The more text you provide the |
| 3003 | * less readable it becomes. For example, an email client should only provide the account |
| 3004 | * name here if more than one email account has been added.</p> |
| 3005 | * |
| 3006 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 3007 | * notification header area. |
| 3008 | * |
| 3009 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 3010 | * this will be shown in the third line of text in the platform notification template. |
| 3011 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 3012 | * same time on those versions; they occupy the same place. |
| 3013 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3014 | */ |
| 3015 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3016 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3017 | return this; |
| 3018 | } |
| 3019 | |
| 3020 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3021 | * Provides text that will appear as a link to your application's settings. |
| 3022 | * |
| 3023 | * <p>This text does not appear within notification {@link Style templates} but may |
| 3024 | * appear when the user uses an affordance to learn more about the notification. |
| 3025 | * Additionally, this text will not appear unless you provide a valid link target by |
| 3026 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 3027 | * |
| 3028 | * <p>This text is meant to be concise description about what the user can customize |
| 3029 | * when they click on this link. The recommended maximum length is 40 characters. |
| 3030 | * @param text |
| 3031 | * @return |
| 3032 | */ |
| 3033 | public Builder setSettingsText(CharSequence text) { |
| 3034 | mN.mSettingsText = safeCharSequence(text); |
| 3035 | return this; |
| 3036 | } |
| 3037 | |
| 3038 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3039 | * Set the remote input history. |
| 3040 | * |
| 3041 | * This should be set to the most recent inputs that have been sent |
| 3042 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 3043 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 3044 | * |
| 3045 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 3046 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 3047 | * and how much of each individual input is shown. |
| 3048 | * |
| 3049 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 3050 | * with a {@code RemoteInput}.</p> |
| 3051 | */ |
| 3052 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 3053 | if (text == null) { |
| 3054 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 3055 | } else { |
| 3056 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 3057 | CharSequence[] safe = new CharSequence[N]; |
| 3058 | for (int i = 0; i < N; i++) { |
| 3059 | safe[i] = safeCharSequence(text[i]); |
| 3060 | } |
| 3061 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 3062 | } |
| 3063 | return this; |
| 3064 | } |
| 3065 | |
| 3066 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3067 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 3068 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3069 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3070 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3071 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3072 | return this; |
| 3073 | } |
| 3074 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3075 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3076 | * A small piece of additional information pertaining to this notification. |
| 3077 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3078 | * The platform template will draw this on the last line of the notification, at the far |
| 3079 | * 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] | 3080 | * |
| 3081 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 3082 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 3083 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3084 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3085 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3086 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3087 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3088 | return this; |
| 3089 | } |
| 3090 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3091 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3092 | * Set the progress this notification represents. |
| 3093 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3094 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3095 | */ |
| 3096 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3097 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3098 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3099 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3100 | return this; |
| 3101 | } |
| 3102 | |
| 3103 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3104 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3105 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3106 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3107 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3108 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3109 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3110 | return setCustomContentView(views); |
| 3111 | } |
| 3112 | |
| 3113 | /** |
| 3114 | * Supply custom RemoteViews to use instead of the platform template. |
| 3115 | * |
| 3116 | * This will override the layout that would otherwise be constructed by this Builder |
| 3117 | * object. |
| 3118 | */ |
| 3119 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3120 | mN.contentView = contentView; |
| 3121 | return this; |
| 3122 | } |
| 3123 | |
| 3124 | /** |
| 3125 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3126 | * |
| 3127 | * This will override the expanded layout that would otherwise be constructed by this |
| 3128 | * Builder object. |
| 3129 | */ |
| 3130 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3131 | mN.bigContentView = contentView; |
| 3132 | return this; |
| 3133 | } |
| 3134 | |
| 3135 | /** |
| 3136 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3137 | * |
| 3138 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3139 | * Builder object. |
| 3140 | */ |
| 3141 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3142 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3143 | return this; |
| 3144 | } |
| 3145 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3146 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3147 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3148 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3149 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3150 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3151 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3152 | * 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] | 3153 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3154 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3155 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3156 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3157 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3158 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3159 | return this; |
| 3160 | } |
| 3161 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3162 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3163 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3164 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3165 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3166 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3167 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3168 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3169 | return this; |
| 3170 | } |
| 3171 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3172 | /** |
| 3173 | * An intent to launch instead of posting the notification to the status bar. |
| 3174 | * Only for use with extremely high-priority notifications demanding the user's |
| 3175 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3176 | * alarm clock that the user has explicitly set to a particular time. |
| 3177 | * If this facility is used for something else, please give the user an option |
| 3178 | * to turn it off and use a normal notification, as this can be extremely |
| 3179 | * disruptive. |
| 3180 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3181 | * <p> |
| 3182 | * The system UI may choose to display a heads-up notification, instead of |
| 3183 | * launching this intent, while the user is using the device. |
| 3184 | * </p> |
| 3185 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3186 | * @param intent The pending intent to launch. |
| 3187 | * @param highPriority Passing true will cause this notification to be sent |
| 3188 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3189 | * |
| 3190 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3191 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3192 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3193 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3194 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3195 | return this; |
| 3196 | } |
| 3197 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3198 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3199 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3200 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3201 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3202 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3203 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3204 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3205 | return this; |
| 3206 | } |
| 3207 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3208 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3209 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3210 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3211 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3212 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3213 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3214 | setTicker(tickerText); |
| 3215 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3216 | return this; |
| 3217 | } |
| 3218 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3219 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3220 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3221 | * |
| 3222 | * 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] | 3223 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3224 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3225 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3226 | public Builder setLargeIcon(Bitmap b) { |
| 3227 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3228 | } |
| 3229 | |
| 3230 | /** |
| 3231 | * Add a large icon to the notification content view. |
| 3232 | * |
| 3233 | * In the platform template, this image will be shown on the left of the notification view |
| 3234 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3235 | * badge atop the large icon). |
| 3236 | */ |
| 3237 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3238 | mN.mLargeIcon = icon; |
| 3239 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3240 | return this; |
| 3241 | } |
| 3242 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3243 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3244 | * Set the sound to play. |
| 3245 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3246 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 3247 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3248 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3249 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3250 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3251 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3252 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3253 | mN.sound = sound; |
| 3254 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3255 | return this; |
| 3256 | } |
| 3257 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3258 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3259 | * 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] | 3260 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3261 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 3262 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3263 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3264 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 3265 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3266 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 3267 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3268 | mN.sound = sound; |
| 3269 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3270 | return this; |
| 3271 | } |
| 3272 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3273 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3274 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 3275 | * use during playback. |
| 3276 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3277 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3278 | * @see Notification#sound |
| 3279 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3280 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3281 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3282 | mN.sound = sound; |
| 3283 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3284 | return this; |
| 3285 | } |
| 3286 | |
| 3287 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3288 | * Set the vibration pattern to use. |
| 3289 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3290 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 3291 | * <code>pattern</code> parameter. |
| 3292 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3293 | * <p> |
| 3294 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 3295 | * </p> |
| 3296 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3297 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3298 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3299 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3300 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3301 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3302 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3303 | return this; |
| 3304 | } |
| 3305 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3306 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3307 | * Set the desired color for the indicator LED on the device, as well as the |
| 3308 | * blink duty cycle (specified in milliseconds). |
| 3309 | * |
| 3310 | |
| 3311 | * Not all devices will honor all (or even any) of these values. |
| 3312 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3313 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3314 | * @see Notification#ledARGB |
| 3315 | * @see Notification#ledOnMS |
| 3316 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3317 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3318 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3319 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3320 | mN.ledARGB = argb; |
| 3321 | mN.ledOnMS = onMs; |
| 3322 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3323 | if (onMs != 0 || offMs != 0) { |
| 3324 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 3325 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3326 | return this; |
| 3327 | } |
| 3328 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3329 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3330 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3331 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3332 | |
| 3333 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 3334 | * must take care of canceling them. |
| 3335 | * |
| 3336 | |
| 3337 | * They are typically used to indicate a background task that the user is actively engaged |
| 3338 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 3339 | * (e.g., a file download, sync operation, active network connection). |
| 3340 | * |
| 3341 | |
| 3342 | * @see Notification#FLAG_ONGOING_EVENT |
| 3343 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3344 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3345 | public Builder setOngoing(boolean ongoing) { |
| 3346 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 3347 | return this; |
| 3348 | } |
| 3349 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3350 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3351 | * Set whether this notification should be colorized. When set, the color set with |
| 3352 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 3353 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3354 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 3355 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3356 | * <p> |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3357 | * For most styles, the coloring will only be applied if the notification is for a |
| 3358 | * foreground service notification. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3359 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3360 | * that have a media session attached there is no such requirement. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3361 | * |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3362 | * @see Builder#setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3363 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3364 | */ |
| 3365 | public Builder setColorized(boolean colorize) { |
| 3366 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 3367 | return this; |
| 3368 | } |
| 3369 | |
| 3370 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3371 | * Set this flag if you would only like the sound, vibrate |
| 3372 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3373 | * |
| 3374 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3375 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3376 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 3377 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 3378 | return this; |
| 3379 | } |
| 3380 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3381 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 3382 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3383 | * |
| 3384 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3385 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3386 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 3387 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3388 | return this; |
| 3389 | } |
| 3390 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3391 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3392 | * Set whether or not this notification should not bridge to other devices. |
| 3393 | * |
| 3394 | * <p>Some notifications can be bridged to other devices for remote display. |
| 3395 | * This hint can be set to recommend this notification not be bridged. |
| 3396 | */ |
| 3397 | public Builder setLocalOnly(boolean localOnly) { |
| 3398 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 3399 | return this; |
| 3400 | } |
| 3401 | |
| 3402 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3403 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3404 | * <p> |
| 3405 | * The value should be one or more of the following fields combined with |
| 3406 | * bitwise-or: |
| 3407 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 3408 | * <p> |
| 3409 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3410 | * |
| 3411 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3412 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3413 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3414 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3415 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3416 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3417 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3418 | return this; |
| 3419 | } |
| 3420 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3421 | /** |
| 3422 | * Set the priority of this notification. |
| 3423 | * |
| 3424 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3425 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3426 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3427 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3428 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3429 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3430 | return this; |
| 3431 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3432 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3433 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3434 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3435 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3436 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3437 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3438 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3439 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3440 | return this; |
| 3441 | } |
| 3442 | |
| 3443 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3444 | * Add a person that is relevant to this notification. |
| 3445 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3446 | * <P> |
| 3447 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3448 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 3449 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 3450 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3451 | * </P> |
| 3452 | * |
| 3453 | * <P> |
| 3454 | * The person should be specified by the {@code String} representation of a |
| 3455 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 3456 | * </P> |
| 3457 | * |
| 3458 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 3459 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 3460 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 3461 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
| 3462 | * </P> |
| 3463 | * |
| 3464 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3465 | * @see Notification#EXTRA_PEOPLE |
| 3466 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3467 | public Builder addPerson(String uri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3468 | mPersonList.add(uri); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3469 | return this; |
| 3470 | } |
| 3471 | |
| 3472 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3473 | * Set this notification to be part of a group of notifications sharing the same key. |
| 3474 | * Grouped notifications may display in a cluster or stack on devices which |
| 3475 | * support such rendering. |
| 3476 | * |
| 3477 | * <p>To make this notification the summary for its group, also call |
| 3478 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 3479 | * {@link #setSortKey}. |
| 3480 | * @param groupKey The group key of the group. |
| 3481 | * @return this object for method chaining |
| 3482 | */ |
| 3483 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3484 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3485 | return this; |
| 3486 | } |
| 3487 | |
| 3488 | /** |
| 3489 | * Set this notification to be the group summary for a group of notifications. |
| 3490 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 3491 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 3492 | * 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] | 3493 | * @param isGroupSummary Whether this notification should be a group summary. |
| 3494 | * @return this object for method chaining |
| 3495 | */ |
| 3496 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 3497 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 3498 | return this; |
| 3499 | } |
| 3500 | |
| 3501 | /** |
| 3502 | * Set a sort key that orders this notification among other notifications from the |
| 3503 | * same package. This can be useful if an external sort was already applied and an app |
| 3504 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 3505 | * value, although providing different priorities in addition to providing sort key may |
| 3506 | * cause this value to be ignored. |
| 3507 | * |
| 3508 | * <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] | 3509 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3510 | * |
| 3511 | * @see String#compareTo(String) |
| 3512 | */ |
| 3513 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3514 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3515 | return this; |
| 3516 | } |
| 3517 | |
| 3518 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3519 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3520 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3521 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 3522 | * |
| 3523 | * @see Notification#extras |
| 3524 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3525 | public Builder addExtras(Bundle extras) { |
| 3526 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3527 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3528 | } |
| 3529 | return this; |
| 3530 | } |
| 3531 | |
| 3532 | /** |
| 3533 | * Set metadata for this notification. |
| 3534 | * |
| 3535 | * <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] | 3536 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3537 | * called. |
| 3538 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3539 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 3540 | * Use {@link #addExtras} to merge in metadata instead. |
| 3541 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3542 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3543 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3544 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3545 | if (extras != null) { |
| 3546 | mUserExtras = extras; |
| 3547 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3548 | return this; |
| 3549 | } |
| 3550 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3551 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3552 | * Get the current metadata Bundle used by this notification Builder. |
| 3553 | * |
| 3554 | * <p>The returned Bundle is shared with this Builder. |
| 3555 | * |
| 3556 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 3557 | * {@link #build()} is called. |
| 3558 | * |
| 3559 | * @see Notification#extras |
| 3560 | */ |
| 3561 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3562 | return mUserExtras; |
| 3563 | } |
| 3564 | |
| 3565 | private Bundle getAllExtras() { |
| 3566 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 3567 | saveExtras.putAll(mN.extras); |
| 3568 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3569 | } |
| 3570 | |
| 3571 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3572 | * Add an action to this notification. Actions are typically displayed by |
| 3573 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3574 | * <p> |
| 3575 | * Every action must have an icon (32dp square and matching the |
| 3576 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 3577 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 3578 | * <p> |
| 3579 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 3580 | * the order they were added. Actions will not be displayed when the notification is |
| 3581 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 3582 | * 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] | 3583 | * |
| 3584 | * @param icon Resource ID of a drawable that represents the action. |
| 3585 | * @param title Text describing the action. |
| 3586 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 3587 | * |
| 3588 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3589 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 3590 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3591 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3592 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3593 | return this; |
| 3594 | } |
| 3595 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3596 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3597 | * Add an action to this notification. Actions are typically displayed by |
| 3598 | * the system as a button adjacent to the notification content. |
| 3599 | * <p> |
| 3600 | * Every action must have an icon (32dp square and matching the |
| 3601 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 3602 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 3603 | * <p> |
| 3604 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 3605 | * the order they were added. Actions will not be displayed when the notification is |
| 3606 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 3607 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 3608 | * |
| 3609 | * @param action The action to add. |
| 3610 | */ |
| 3611 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 3612 | if (action != null) { |
| 3613 | mActions.add(action); |
| 3614 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3615 | return this; |
| 3616 | } |
| 3617 | |
| 3618 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3619 | * Alter the complete list of actions attached to this notification. |
| 3620 | * @see #addAction(Action). |
| 3621 | * |
| 3622 | * @param actions |
| 3623 | * @return |
| 3624 | */ |
| 3625 | public Builder setActions(Action... actions) { |
| 3626 | mActions.clear(); |
| 3627 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 3628 | if (actions[i] != null) { |
| 3629 | mActions.add(actions[i]); |
| 3630 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3631 | } |
| 3632 | return this; |
| 3633 | } |
| 3634 | |
| 3635 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3636 | * Add a rich notification style to be applied at build time. |
| 3637 | * |
| 3638 | * @param style Object responsible for modifying the notification style. |
| 3639 | */ |
| 3640 | public Builder setStyle(Style style) { |
| 3641 | if (mStyle != style) { |
| 3642 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3643 | if (mStyle != null) { |
| 3644 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3645 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 3646 | } else { |
| 3647 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3648 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3649 | } |
| 3650 | return this; |
| 3651 | } |
| 3652 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3653 | /** |
| 3654 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 3655 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3656 | * @return The same Builder. |
| 3657 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 3658 | public Builder setVisibility(@Visibility int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3659 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3660 | return this; |
| 3661 | } |
| 3662 | |
| 3663 | /** |
| 3664 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 3665 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 3666 | * @param n A replacement notification, presumably with some or all info redacted. |
| 3667 | * @return The same Builder. |
| 3668 | */ |
| 3669 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3670 | if (n != null) { |
| 3671 | mN.publicVersion = new Notification(); |
| 3672 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 3673 | } else { |
| 3674 | mN.publicVersion = null; |
| 3675 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3676 | return this; |
| 3677 | } |
| 3678 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 3679 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3680 | * Apply an extender to this notification builder. Extenders may be used to add |
| 3681 | * metadata or change options on this builder. |
| 3682 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 3683 | public Builder extend(Extender extender) { |
| 3684 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3685 | return this; |
| 3686 | } |
| 3687 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 3688 | /** |
| 3689 | * @hide |
| 3690 | */ |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 3691 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3692 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3693 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3694 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3695 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3696 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 3697 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3698 | } |
| 3699 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3700 | /** |
| 3701 | * Sets {@link Notification#color}. |
| 3702 | * |
| 3703 | * @param argb The accent color to use |
| 3704 | * |
| 3705 | * @return The same Builder. |
| 3706 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3707 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3708 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3709 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3710 | return this; |
| 3711 | } |
| 3712 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3713 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 3714 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 3715 | // This user can never be a badged profile, |
| 3716 | // and also includes USER_ALL system notifications. |
| 3717 | return null; |
| 3718 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3719 | // Note: This assumes that the current user can read the profile badge of the |
| 3720 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 3721 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 3722 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3723 | } |
| 3724 | |
| 3725 | private Bitmap getProfileBadge() { |
| 3726 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3727 | if (badge == null) { |
| 3728 | return null; |
| 3729 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3730 | final int size = mContext.getResources().getDimensionPixelSize( |
| 3731 | R.dimen.notification_badge_size); |
| 3732 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3733 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3734 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3735 | badge.draw(canvas); |
| 3736 | return bitmap; |
| 3737 | } |
| 3738 | |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3739 | private void bindProfileBadge(RemoteViews contentView) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3740 | Bitmap profileBadge = getProfileBadge(); |
| 3741 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3742 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3743 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 3744 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3745 | if (isColorized()) { |
| 3746 | contentView.setDrawableParameters(R.id.profile_badge, false, -1, |
| 3747 | getPrimaryTextColor(), PorterDuff.Mode.SRC_ATOP, -1); |
| 3748 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3749 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3750 | } |
| 3751 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3752 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3753 | resetNotificationHeader(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3754 | resetContentMargins(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3755 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3756 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3757 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3758 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3759 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3760 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3761 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3762 | } |
| 3763 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3764 | /** |
| 3765 | * Resets the notification header to its original state |
| 3766 | */ |
| 3767 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 3768 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 3769 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 3770 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3771 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 3772 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3773 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 3774 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3775 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3776 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 3777 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3778 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 3779 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | private void resetContentMargins(RemoteViews contentView) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 3783 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 3784 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3785 | } |
| 3786 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3787 | private RemoteViews applyStandardTemplate(int resId) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3788 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this)); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | /** |
| 3792 | * @param hasProgress whether the progress bar should be shown and set |
| 3793 | */ |
| 3794 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3795 | return applyStandardTemplate(resId, mParams.reset().hasProgress(hasProgress) |
| 3796 | .fillTextsFrom(this)); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3797 | } |
| 3798 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3799 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3800 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 3801 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3802 | resetStandardTemplate(contentView); |
| 3803 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3804 | final Bundle ex = mN.extras; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3805 | updateBackgroundColor(contentView); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3806 | bindNotificationHeader(contentView, p.ambient); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3807 | bindLargeIcon(contentView); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3808 | boolean showProgress = handleProgressBar(p.hasProgress, contentView, ex); |
| 3809 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3810 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3811 | contentView.setTextViewText(R.id.title, p.title); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 3812 | if (!p.ambient) { |
| 3813 | setTextViewColorPrimary(contentView, R.id.title); |
| 3814 | } |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 3815 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 3816 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 3817 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3818 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3819 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3820 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 3821 | : com.android.internal.R.id.text; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3822 | contentView.setTextViewText(textId, p.text); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 3823 | if (!p.ambient) { |
| 3824 | setTextViewColorSecondary(contentView, textId); |
| 3825 | } |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3826 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3827 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3828 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 3829 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3830 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3831 | return contentView; |
| 3832 | } |
| 3833 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3834 | private void setTextViewColorPrimary(RemoteViews contentView, int id) { |
| 3835 | ensureColors(); |
| 3836 | contentView.setTextColor(id, mPrimaryTextColor); |
| 3837 | } |
| 3838 | |
| 3839 | private int getPrimaryTextColor() { |
| 3840 | ensureColors(); |
| 3841 | return mPrimaryTextColor; |
| 3842 | } |
| 3843 | |
| 3844 | private int getActionBarColor() { |
| 3845 | ensureColors(); |
| 3846 | return mActionBarColor; |
| 3847 | } |
| 3848 | |
Selim Cinek | 622c64a | 2017-04-17 17:10:05 -0700 | [diff] [blame] | 3849 | private int getActionBarColorDeEmphasized() { |
| 3850 | int backgroundColor = getBackgroundColor(); |
| 3851 | return NotificationColorUtil.getShiftedColor(backgroundColor, 12); |
| 3852 | } |
| 3853 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3854 | private void setTextViewColorSecondary(RemoteViews contentView, int id) { |
| 3855 | ensureColors(); |
| 3856 | contentView.setTextColor(id, mSecondaryTextColor); |
| 3857 | } |
| 3858 | |
| 3859 | private void ensureColors() { |
| 3860 | int backgroundColor = getBackgroundColor(); |
| 3861 | if (mPrimaryTextColor == COLOR_INVALID |
| 3862 | || mSecondaryTextColor == COLOR_INVALID |
| 3863 | || mActionBarColor == COLOR_INVALID |
| 3864 | || mTextColorsAreForBackground != backgroundColor) { |
| 3865 | mTextColorsAreForBackground = backgroundColor; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3866 | if (mForegroundColor == COLOR_INVALID || !isColorized()) { |
| 3867 | mPrimaryTextColor = NotificationColorUtil.resolvePrimaryColor(mContext, |
| 3868 | backgroundColor); |
| 3869 | mSecondaryTextColor = NotificationColorUtil.resolveSecondaryColor(mContext, |
| 3870 | backgroundColor); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 3871 | if (backgroundColor != COLOR_DEFAULT |
| 3872 | && (mBackgroundColorHint != COLOR_INVALID || isColorized())) { |
| 3873 | mPrimaryTextColor = NotificationColorUtil.findAlphaToMeetContrast( |
| 3874 | mPrimaryTextColor, backgroundColor, 4.5); |
| 3875 | mSecondaryTextColor = NotificationColorUtil.findAlphaToMeetContrast( |
| 3876 | mSecondaryTextColor, backgroundColor, 4.5); |
| 3877 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3878 | } else { |
| 3879 | double backLum = NotificationColorUtil.calculateLuminance(backgroundColor); |
| 3880 | double textLum = NotificationColorUtil.calculateLuminance(mForegroundColor); |
| 3881 | double contrast = NotificationColorUtil.calculateContrast(mForegroundColor, |
| 3882 | backgroundColor); |
| 3883 | boolean textDark = backLum > textLum; |
| 3884 | if (contrast < 4.5f) { |
| 3885 | if (textDark) { |
| 3886 | mSecondaryTextColor = NotificationColorUtil.findContrastColor( |
| 3887 | mForegroundColor, |
| 3888 | backgroundColor, |
| 3889 | true /* findFG */, |
| 3890 | 4.5f); |
| 3891 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
| 3892 | mSecondaryTextColor, -20); |
| 3893 | } else { |
| 3894 | mSecondaryTextColor = |
| 3895 | NotificationColorUtil.findContrastColorAgainstDark( |
| 3896 | mForegroundColor, |
| 3897 | backgroundColor, |
| 3898 | true /* findFG */, |
| 3899 | 4.5f); |
| 3900 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
| 3901 | mSecondaryTextColor, 10); |
| 3902 | } |
| 3903 | } else { |
| 3904 | mPrimaryTextColor = mForegroundColor; |
| 3905 | mSecondaryTextColor = NotificationColorUtil.changeColorLightness( |
| 3906 | mPrimaryTextColor, textDark ? 10 : -20); |
| 3907 | if (NotificationColorUtil.calculateContrast(mSecondaryTextColor, |
| 3908 | backgroundColor) < 4.5f) { |
| 3909 | // oh well the secondary is not good enough |
| 3910 | if (textDark) { |
| 3911 | mSecondaryTextColor = NotificationColorUtil.findContrastColor( |
| 3912 | mSecondaryTextColor, |
| 3913 | backgroundColor, |
| 3914 | true /* findFG */, |
| 3915 | 4.5f); |
| 3916 | } else { |
| 3917 | mSecondaryTextColor |
| 3918 | = NotificationColorUtil.findContrastColorAgainstDark( |
| 3919 | mSecondaryTextColor, |
| 3920 | backgroundColor, |
| 3921 | true /* findFG */, |
| 3922 | 4.5f); |
| 3923 | } |
| 3924 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
| 3925 | mSecondaryTextColor, textDark ? -20 : 10); |
| 3926 | } |
| 3927 | } |
| 3928 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 3929 | mActionBarColor = NotificationColorUtil.resolveActionBarColor(mContext, |
| 3930 | backgroundColor); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | private void updateBackgroundColor(RemoteViews contentView) { |
| 3935 | if (isColorized()) { |
| 3936 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
| 3937 | getBackgroundColor()); |
| 3938 | } else { |
| 3939 | // Clear it! |
| 3940 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 3941 | 0); |
| 3942 | } |
| 3943 | } |
| 3944 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3945 | /** |
| 3946 | * @param remoteView the remote view to update the minheight in |
| 3947 | * @param hasMinHeight does it have a mimHeight |
| 3948 | * @hide |
| 3949 | */ |
| 3950 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 3951 | int minHeight = 0; |
| 3952 | if (hasMinHeight) { |
| 3953 | // we need to set the minHeight of the notification |
| 3954 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 3955 | com.android.internal.R.dimen.notification_min_content_height); |
| 3956 | } |
| 3957 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 3958 | } |
| 3959 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3960 | private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3961 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 3962 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 3963 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 3964 | if (hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3965 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3966 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3967 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3968 | contentView.setProgressBackgroundTintList( |
| 3969 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 3970 | R.color.notification_progress_background_color))); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3971 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 3972 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3973 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 3974 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3975 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3976 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3977 | } else { |
| 3978 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3979 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3980 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3981 | } |
| 3982 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3983 | private void bindLargeIcon(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 3984 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 3985 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 3986 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3987 | if (mN.mLargeIcon != null) { |
| 3988 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 3989 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
| 3990 | processLargeLegacyIcon(mN.mLargeIcon, contentView); |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 3991 | int endMargin = R.dimen.notification_content_picture_margin; |
| 3992 | contentView.setViewLayoutMarginEndDimen(R.id.line1, endMargin); |
| 3993 | contentView.setViewLayoutMarginEndDimen(R.id.text, endMargin); |
| 3994 | contentView.setViewLayoutMarginEndDimen(R.id.progress, endMargin); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3995 | } |
| 3996 | } |
| 3997 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3998 | private void bindNotificationHeader(RemoteViews contentView, boolean ambient) { |
| 3999 | bindSmallIcon(contentView, ambient); |
| 4000 | bindHeaderAppName(contentView, ambient); |
| 4001 | if (!ambient) { |
| 4002 | // Ambient view does not have these |
| 4003 | bindHeaderText(contentView); |
| 4004 | bindHeaderChronometerAndTime(contentView); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4005 | bindProfileBadge(contentView); |
| 4006 | } |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 4007 | bindExpandButton(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | private void bindExpandButton(RemoteViews contentView) { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4011 | int color = getPrimaryHighlightColor(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4012 | contentView.setDrawableParameters(R.id.expand_button, false, -1, color, |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4013 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4014 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4015 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4016 | } |
| 4017 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4018 | /** |
| 4019 | * @return the color that is used as the first primary highlight color. This is applied |
| 4020 | * in several places like the action buttons or the app name in the header. |
| 4021 | */ |
| 4022 | private int getPrimaryHighlightColor() { |
| 4023 | return isColorized() ? getPrimaryTextColor() : resolveContrastColor(); |
| 4024 | } |
| 4025 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4026 | private void bindHeaderChronometerAndTime(RemoteViews contentView) { |
| 4027 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4028 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4029 | setTextViewColorSecondary(contentView, R.id.time_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4030 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 4031 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 4032 | contentView.setLong(R.id.chronometer, "setBase", |
| 4033 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 4034 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4035 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 4036 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4037 | setTextViewColorSecondary(contentView, R.id.chronometer); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4038 | } else { |
| 4039 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 4040 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4041 | setTextViewColorSecondary(contentView, R.id.time); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4042 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4043 | } else { |
| 4044 | // We still want a time to be set but gone, such that we can show and hide it |
| 4045 | // on demand in case it's a child notification without anything in the header |
| 4046 | 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] | 4047 | } |
| 4048 | } |
| 4049 | |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4050 | private void bindHeaderText(RemoteViews contentView) { |
| 4051 | CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 4052 | if (headerText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4053 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4054 | headerText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4055 | } |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4056 | if (headerText == null |
| 4057 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 4058 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 4059 | headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 4060 | } |
| 4061 | if (headerText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4062 | // 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] | 4063 | contentView.setTextViewText(R.id.header_text, processLegacyText(headerText)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4064 | setTextViewColorSecondary(contentView, R.id.header_text); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4065 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 4066 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4067 | setTextViewColorSecondary(contentView, R.id.header_text_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4068 | } |
| 4069 | } |
| 4070 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4071 | /** |
| 4072 | * @hide |
| 4073 | */ |
| 4074 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4075 | CharSequence name = null; |
| 4076 | final PackageManager pm = mContext.getPackageManager(); |
| 4077 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 4078 | // only system packages which lump together a bunch of unrelated stuff |
| 4079 | // may substitute a different name to make the purpose of the |
| 4080 | // notification more clear. the correct package label should always |
| 4081 | // be accessible via SystemUI. |
| 4082 | final String pkg = mContext.getPackageName(); |
| 4083 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 4084 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 4085 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 4086 | name = subName; |
| 4087 | } else { |
| 4088 | Log.w(TAG, "warning: pkg " |
| 4089 | + pkg + " attempting to substitute app name '" + subName |
| 4090 | + "' without holding perm " |
| 4091 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 4092 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4093 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4094 | if (TextUtils.isEmpty(name)) { |
| 4095 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 4096 | } |
| 4097 | if (TextUtils.isEmpty(name)) { |
| 4098 | // still nothing? |
| 4099 | return null; |
| 4100 | } |
| 4101 | |
| 4102 | return String.valueOf(name); |
| 4103 | } |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4104 | private void bindHeaderAppName(RemoteViews contentView, boolean ambient) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4105 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4106 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4107 | setTextViewColorPrimary(contentView, R.id.app_name_text); |
| 4108 | } else { |
| 4109 | contentView.setTextColor(R.id.app_name_text, |
| 4110 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
| 4111 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4112 | } |
| 4113 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4114 | private void bindSmallIcon(RemoteViews contentView, boolean ambient) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4115 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 4116 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 4117 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4118 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Adrian Roos | 9b45a15 | 2016-06-28 13:32:29 -0700 | [diff] [blame] | 4119 | contentView.setDrawableParameters(R.id.icon, false /* targetBackground */, |
| 4120 | -1 /* alpha */, -1 /* colorFilter */, null /* mode */, mN.iconLevel); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4121 | processSmallIconColor(mN.mSmallIcon, contentView, ambient); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4122 | } |
| 4123 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4124 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4125 | * @return true if the built notification will show the time or the chronometer; false |
| 4126 | * otherwise |
| 4127 | */ |
| 4128 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 4129 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4130 | } |
| 4131 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4132 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4133 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 4134 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4135 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4136 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4137 | |
| 4138 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 4139 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
| 4140 | |
| 4141 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 4142 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 4143 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 4144 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 4145 | |
| 4146 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4147 | } |
| 4148 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4149 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4150 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this)); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4153 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 4154 | StandardTemplateParams p) { |
| 4155 | RemoteViews big = applyStandardTemplate(layoutId, p); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4156 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4157 | resetStandardTemplateWithActions(big); |
| 4158 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4159 | boolean validRemoteInput = false; |
| 4160 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4161 | int N = mActions.size(); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4162 | boolean emphazisedMode = mN.fullScreenIntent != null && !p.ambient; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4163 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4164 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 4165 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4166 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4167 | if (p.ambient) { |
| 4168 | big.setInt(R.id.actions, "setBackgroundColor", Color.TRANSPARENT); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4169 | } else if (isColorized()) { |
| 4170 | big.setInt(R.id.actions, "setBackgroundColor", getActionBarColor()); |
| 4171 | } else { |
| 4172 | big.setInt(R.id.actions, "setBackgroundColor", mContext.getColor( |
| 4173 | R.color.notification_action_list)); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4174 | } |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 4175 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 4176 | R.dimen.notification_action_list_height); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4177 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4178 | for (int i=0; i<N; i++) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4179 | Action action = mActions.get(i); |
| 4180 | validRemoteInput |= hasValidRemoteInput(action); |
| 4181 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4182 | final RemoteViews button = generateActionButton(action, emphazisedMode, |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4183 | i % 2 != 0, p.ambient); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4184 | big.addView(R.id.actions, button); |
| 4185 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4186 | } else { |
| 4187 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4188 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4189 | |
| 4190 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4191 | if (!p.ambient && validRemoteInput && replyText != null |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4192 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) { |
| 4193 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
| 4194 | big.setTextViewText(R.id.notification_material_reply_text_1, replyText[0]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4195 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4196 | |
| 4197 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) { |
| 4198 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
| 4199 | big.setTextViewText(R.id.notification_material_reply_text_2, replyText[1]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4200 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4201 | |
| 4202 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) { |
| 4203 | big.setViewVisibility( |
| 4204 | R.id.notification_material_reply_text_3, View.VISIBLE); |
| 4205 | big.setTextViewText(R.id.notification_material_reply_text_3, replyText[2]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4206 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4207 | } |
| 4208 | } |
| 4209 | } |
| 4210 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4211 | return big; |
| 4212 | } |
| 4213 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4214 | private boolean hasValidRemoteInput(Action action) { |
| 4215 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 4216 | // Weird actions |
| 4217 | return false; |
| 4218 | } |
| 4219 | |
| 4220 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 4221 | if (remoteInputs == null) { |
| 4222 | return false; |
| 4223 | } |
| 4224 | |
| 4225 | for (RemoteInput r : remoteInputs) { |
| 4226 | CharSequence[] choices = r.getChoices(); |
| 4227 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 4228 | return true; |
| 4229 | } |
| 4230 | } |
| 4231 | return false; |
| 4232 | } |
| 4233 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4234 | /** |
| 4235 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 4236 | * 1. Custom contentView from the caller |
| 4237 | * 2. Style's proposed content view |
| 4238 | * 3. Standard template view |
| 4239 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4240 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4241 | return createContentView(false /* increasedheight */ ); |
| 4242 | } |
| 4243 | |
| 4244 | /** |
| 4245 | * Construct a RemoteViews for the smaller content view. |
| 4246 | * |
| 4247 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 4248 | * styles may support showing more then just that basic 1U size |
| 4249 | * and the system may decide to render important notifications |
| 4250 | * slightly bigger even when collapsed. |
| 4251 | * |
| 4252 | * @hide |
| 4253 | */ |
| 4254 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame^] | 4255 | if (mN.contentView != null && useExistingRemoteView()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4256 | return mN.contentView; |
| 4257 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4258 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4259 | if (styleView != null) { |
| 4260 | return styleView; |
| 4261 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4262 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4263 | return applyStandardTemplate(getBaseLayoutResource()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4264 | } |
| 4265 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame^] | 4266 | private boolean useExistingRemoteView() { |
| 4267 | return mStyle == null || (!mStyle.displayCustomViewInline() |
| 4268 | && !mRebuildStyledRemoteViews); |
| 4269 | } |
| 4270 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4271 | /** |
| 4272 | * Construct a RemoteViews for the final big notification layout. |
| 4273 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4274 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4275 | RemoteViews result = null; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame^] | 4276 | if (mN.bigContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4277 | return mN.bigContentView; |
| 4278 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4279 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 4280 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4281 | } else if (mActions.size() != 0) { |
| 4282 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4283 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4284 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4285 | return result; |
| 4286 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4287 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4288 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4289 | * Construct a RemoteViews for the final notification header only. This will not be |
| 4290 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4291 | * |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4292 | * @param ambient if true, generate the header for the ambient display layout. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4293 | * @hide |
| 4294 | */ |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4295 | public RemoteViews makeNotificationHeader(boolean ambient) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4296 | Boolean colorized = (Boolean) mN.extras.get(EXTRA_COLORIZED); |
| 4297 | mN.extras.putBoolean(EXTRA_COLORIZED, false); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4298 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4299 | ambient ? R.layout.notification_template_ambient_header |
| 4300 | : R.layout.notification_template_header); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4301 | resetNotificationHeader(header); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4302 | bindNotificationHeader(header, ambient); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4303 | if (colorized != null) { |
| 4304 | mN.extras.putBoolean(EXTRA_COLORIZED, colorized); |
| 4305 | } else { |
| 4306 | mN.extras.remove(EXTRA_COLORIZED); |
| 4307 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4308 | return header; |
| 4309 | } |
| 4310 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4311 | /** |
| 4312 | * Construct a RemoteViews for the ambient version of the notification. |
| 4313 | * |
| 4314 | * @hide |
| 4315 | */ |
| 4316 | public RemoteViews makeAmbientNotification() { |
| 4317 | RemoteViews ambient = applyStandardTemplateWithActions( |
| 4318 | R.layout.notification_template_material_ambient, |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 4319 | mParams.reset().ambient(true).fillTextsFrom(this).hasProgress(false)); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4320 | return ambient; |
| 4321 | } |
| 4322 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4323 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4324 | if (result != null) { |
| 4325 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 4326 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4327 | } |
| 4328 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4329 | /** |
| 4330 | * Adapt the Notification header if this view is used as an expanded view. |
| 4331 | * |
| 4332 | * @hide |
| 4333 | */ |
| 4334 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4335 | if (result != null) { |
| 4336 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 4337 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4338 | } |
| 4339 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4340 | /** |
| 4341 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4342 | * |
| 4343 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 4344 | * styles may support showing more then just that basic 1U size |
| 4345 | * and the system may decide to render important notifications |
| 4346 | * slightly bigger even when collapsed. |
| 4347 | * |
| 4348 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4349 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4350 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame^] | 4351 | if (mN.headsUpContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4352 | return mN.headsUpContentView; |
| 4353 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4354 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 4355 | if (styleView != null) { |
| 4356 | return styleView; |
| 4357 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4358 | } else if (mActions.size() == 0) { |
| 4359 | return null; |
| 4360 | } |
| 4361 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4362 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 4363 | } |
| 4364 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4365 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4366 | * Construct a RemoteViews for the final heads-up notification layout. |
| 4367 | */ |
| 4368 | public RemoteViews createHeadsUpContentView() { |
| 4369 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 4370 | } |
| 4371 | |
| 4372 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4373 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 4374 | * |
| 4375 | * @hide |
| 4376 | */ |
| 4377 | public RemoteViews makePublicContentView() { |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4378 | return makePublicView(false /* ambient */); |
| 4379 | } |
| 4380 | |
| 4381 | /** |
| 4382 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 4383 | * |
| 4384 | * @hide |
| 4385 | */ |
| 4386 | public RemoteViews makePublicAmbientNotification() { |
| 4387 | return makePublicView(true /* ambient */); |
| 4388 | } |
| 4389 | |
| 4390 | private RemoteViews makePublicView(boolean ambient) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4391 | if (mN.publicVersion != null) { |
| 4392 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4393 | return ambient ? builder.makeAmbientNotification() : builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4394 | } |
| 4395 | Bundle savedBundle = mN.extras; |
| 4396 | Style style = mStyle; |
| 4397 | mStyle = null; |
| 4398 | Icon largeIcon = mN.mLargeIcon; |
| 4399 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4400 | Bitmap largeIconLegacy = mN.largeIcon; |
| 4401 | mN.largeIcon = null; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 4402 | ArrayList<Action> actions = mActions; |
| 4403 | mActions = new ArrayList<>(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4404 | Bundle publicExtras = new Bundle(); |
| 4405 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 4406 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 4407 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 4408 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4409 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 4410 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4411 | publicExtras.putCharSequence(EXTRA_TITLE, |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4412 | mContext.getString(com.android.internal.R.string.notification_hidden_text)); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4413 | mN.extras = publicExtras; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4414 | final RemoteViews view = ambient ? makeAmbientNotification() |
| 4415 | : applyStandardTemplate(getBaseLayoutResource()); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4416 | mN.extras = savedBundle; |
| 4417 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4418 | mN.largeIcon = largeIconLegacy; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 4419 | mActions = actions; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4420 | mStyle = style; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4421 | return view; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4422 | } |
| 4423 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4424 | /** |
| 4425 | * Construct a content view for the display when low - priority |
| 4426 | * |
| 4427 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 4428 | * a new subtext is created consisting of the content of the |
| 4429 | * notification. |
| 4430 | * @hide |
| 4431 | */ |
| 4432 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
| 4433 | int color = mN.color; |
| 4434 | mN.color = COLOR_DEFAULT; |
| 4435 | CharSequence summary = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 4436 | if (!useRegularSubtext || TextUtils.isEmpty(summary)) { |
| 4437 | CharSequence newSummary = createSummaryText(); |
| 4438 | if (!TextUtils.isEmpty(newSummary)) { |
| 4439 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, newSummary); |
| 4440 | } |
| 4441 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 4442 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4443 | RemoteViews header = makeNotificationHeader(false /* ambient */); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 4444 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4445 | if (summary != null) { |
| 4446 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, summary); |
| 4447 | } else { |
| 4448 | mN.extras.remove(EXTRA_SUB_TEXT); |
| 4449 | } |
| 4450 | mN.color = color; |
| 4451 | return header; |
| 4452 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4453 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4454 | private CharSequence createSummaryText() { |
| 4455 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 4456 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 4457 | return titleText; |
| 4458 | } |
| 4459 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 4460 | if (titleText == null) { |
| 4461 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 4462 | } |
| 4463 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 4464 | if (titleText != null) { |
| 4465 | summary.append(bidi.unicodeWrap(titleText)); |
| 4466 | } |
| 4467 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 4468 | if (titleText != null && contentText != null) { |
| 4469 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 4470 | R.string.notification_header_divider_symbol_with_spaces))); |
| 4471 | } |
| 4472 | if (contentText != null) { |
| 4473 | summary.append(bidi.unicodeWrap(contentText)); |
| 4474 | } |
| 4475 | return summary; |
| 4476 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 4477 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4478 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4479 | boolean oddAction, boolean ambient) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4480 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 4481 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4482 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 4483 | : tombstone ? getActionTombstoneLayoutResource() |
| 4484 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4485 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 4486 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 4487 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4488 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 4489 | if (action.mRemoteInputs != null) { |
| 4490 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 4491 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4492 | // TODO: handle emphasized mode / actions right |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4493 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4494 | // change the background bgColor |
Selim Cinek | 622c64a | 2017-04-17 17:10:05 -0700 | [diff] [blame] | 4495 | int bgColor; |
| 4496 | if (isColorized()) { |
| 4497 | bgColor = oddAction ? getActionBarColor() : getActionBarColorDeEmphasized(); |
| 4498 | } else { |
| 4499 | bgColor = mContext.getColor(oddAction ? R.color.notification_action_list |
| 4500 | : R.color.notification_action_list_dark); |
| 4501 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4502 | button.setDrawableParameters(R.id.button_holder, true, -1, bgColor, |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4503 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4504 | CharSequence title = action.title; |
| 4505 | ColorStateList[] outResultColor = null; |
| 4506 | if (isLegacy()) { |
| 4507 | title = clearColorSpans(title); |
| 4508 | } else { |
| 4509 | outResultColor = new ColorStateList[1]; |
| 4510 | title = ensureColorSpanContrast(title, bgColor, outResultColor); |
| 4511 | } |
| 4512 | button.setTextViewText(R.id.action0, title); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4513 | setTextViewColorPrimary(button, R.id.action0); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4514 | if (outResultColor != null && outResultColor[0] != null) { |
| 4515 | // We need to set the text color as well since changing a text to uppercase |
| 4516 | // clears its spans. |
| 4517 | button.setTextColor(R.id.action0, outResultColor[0]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4518 | } else if (mN.color != COLOR_DEFAULT && !isColorized()) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4519 | button.setTextColor(R.id.action0,resolveContrastColor()); |
| 4520 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4521 | } else { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4522 | button.setTextViewText(R.id.action0, processLegacyText(action.title)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4523 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4524 | setTextViewColorPrimary(button, R.id.action0); |
| 4525 | } else if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4526 | button.setTextColor(R.id.action0, |
| 4527 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4528 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 4529 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4530 | return button; |
| 4531 | } |
| 4532 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4533 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4534 | * Clears all color spans of a text |
| 4535 | * @param charSequence the input text |
| 4536 | * @return the same text but without color spans |
| 4537 | */ |
| 4538 | private CharSequence clearColorSpans(CharSequence charSequence) { |
| 4539 | if (charSequence instanceof Spanned) { |
| 4540 | Spanned ss = (Spanned) charSequence; |
| 4541 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 4542 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 4543 | for (Object span : spans) { |
| 4544 | Object resultSpan = span; |
| 4545 | if (resultSpan instanceof CharacterStyle) { |
| 4546 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 4547 | } |
| 4548 | if (resultSpan instanceof TextAppearanceSpan) { |
| 4549 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 4550 | if (originalSpan.getTextColor() != null) { |
| 4551 | resultSpan = new TextAppearanceSpan( |
| 4552 | originalSpan.getFamily(), |
| 4553 | originalSpan.getTextStyle(), |
| 4554 | originalSpan.getTextSize(), |
| 4555 | null, |
| 4556 | originalSpan.getLinkTextColor()); |
| 4557 | } |
| 4558 | } else if (resultSpan instanceof ForegroundColorSpan |
| 4559 | || (resultSpan instanceof BackgroundColorSpan)) { |
| 4560 | continue; |
| 4561 | } else { |
| 4562 | resultSpan = span; |
| 4563 | } |
| 4564 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 4565 | ss.getSpanFlags(span)); |
| 4566 | } |
| 4567 | return builder; |
| 4568 | } |
| 4569 | return charSequence; |
| 4570 | } |
| 4571 | |
| 4572 | /** |
| 4573 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 4574 | * text if a span was found that spans over the whole text. |
| 4575 | * |
| 4576 | * @param charSequence the charSequence on which the spans are |
| 4577 | * @param background the background color to ensure the contrast against |
| 4578 | * @param outResultColor an array in which a color will be returned as the first element if |
| 4579 | * there exists a full length color span. |
| 4580 | * @return the contrasted charSequence |
| 4581 | */ |
| 4582 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 4583 | ColorStateList[] outResultColor) { |
| 4584 | if (charSequence instanceof Spanned) { |
| 4585 | Spanned ss = (Spanned) charSequence; |
| 4586 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 4587 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 4588 | for (Object span : spans) { |
| 4589 | Object resultSpan = span; |
| 4590 | int spanStart = ss.getSpanStart(span); |
| 4591 | int spanEnd = ss.getSpanEnd(span); |
| 4592 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 4593 | if (resultSpan instanceof CharacterStyle) { |
| 4594 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 4595 | } |
| 4596 | if (resultSpan instanceof TextAppearanceSpan) { |
| 4597 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 4598 | ColorStateList textColor = originalSpan.getTextColor(); |
| 4599 | if (textColor != null) { |
| 4600 | int[] colors = textColor.getColors(); |
| 4601 | int[] newColors = new int[colors.length]; |
| 4602 | for (int i = 0; i < newColors.length; i++) { |
| 4603 | newColors[i] = NotificationColorUtil.ensureLargeTextContrast( |
| 4604 | colors[i], background); |
| 4605 | } |
| 4606 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 4607 | newColors); |
| 4608 | resultSpan = new TextAppearanceSpan( |
| 4609 | originalSpan.getFamily(), |
| 4610 | originalSpan.getTextStyle(), |
| 4611 | originalSpan.getTextSize(), |
| 4612 | textColor, |
| 4613 | originalSpan.getLinkTextColor()); |
| 4614 | if (fullLength) { |
| 4615 | outResultColor[0] = new ColorStateList( |
| 4616 | textColor.getStates().clone(), newColors); |
| 4617 | } |
| 4618 | } |
| 4619 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 4620 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 4621 | int foregroundColor = originalSpan.getForegroundColor(); |
| 4622 | foregroundColor = NotificationColorUtil.ensureLargeTextContrast( |
| 4623 | foregroundColor, background); |
| 4624 | resultSpan = new ForegroundColorSpan(foregroundColor); |
| 4625 | if (fullLength) { |
| 4626 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
| 4627 | } |
| 4628 | } else { |
| 4629 | resultSpan = span; |
| 4630 | } |
| 4631 | |
| 4632 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 4633 | } |
| 4634 | return builder; |
| 4635 | } |
| 4636 | return charSequence; |
| 4637 | } |
| 4638 | |
| 4639 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4640 | * @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] | 4641 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4642 | */ |
| 4643 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4644 | if (!mIsLegacyInitialized) { |
| 4645 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 4646 | < Build.VERSION_CODES.LOLLIPOP; |
| 4647 | mIsLegacyInitialized = true; |
| 4648 | } |
| 4649 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4650 | } |
| 4651 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4652 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 4653 | return processLegacyText(charSequence, false /* ambient */); |
| 4654 | } |
| 4655 | |
| 4656 | private CharSequence processLegacyText(CharSequence charSequence, boolean ambient) { |
| 4657 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
| 4658 | boolean wantLightText = ambient; |
| 4659 | if (isAlreadyLightText != wantLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4660 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4661 | } else { |
| 4662 | return charSequence; |
| 4663 | } |
| 4664 | } |
| 4665 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4666 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4667 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4668 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4669 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
| 4670 | boolean ambient) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4671 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4672 | int color = ambient ? resolveAmbientColor() : getPrimaryHighlightColor(); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4673 | if (colorable) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4674 | contentView.setDrawableParameters(R.id.icon, false, -1, color, |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 4675 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4676 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4677 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4678 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4679 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4680 | } |
| 4681 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4682 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4683 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4684 | * if it's grayscale). |
| 4685 | */ |
| 4686 | // TODO: also check bounds, transparency, that sort of thing. |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4687 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) { |
| 4688 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4689 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4690 | // resolve color will fall back to the default when legacy |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4691 | contentView.setDrawableParameters(R.id.icon, false, -1, resolveContrastColor(), |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 4692 | PorterDuff.Mode.SRC_ATOP, -1); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 4693 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4694 | } |
| 4695 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4696 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4697 | if (mN.color != COLOR_DEFAULT) { |
| 4698 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 4699 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 4700 | } |
| 4701 | |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4702 | int resolveContrastColor() { |
| 4703 | if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) { |
| 4704 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4705 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4706 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4707 | int color; |
| 4708 | int background = mBackgroundColorHint; |
| 4709 | if (mBackgroundColorHint == COLOR_INVALID) { |
| 4710 | background = mContext.getColor( |
| 4711 | com.android.internal.R.color.notification_material_background_color); |
| 4712 | } |
| 4713 | if (mN.color == COLOR_DEFAULT) { |
| 4714 | ensureColors(); |
| 4715 | color = mSecondaryTextColor; |
| 4716 | } else { |
| 4717 | color = NotificationColorUtil.resolveContrastColor(mContext, mN.color, |
| 4718 | background); |
| 4719 | } |
| 4720 | if (Color.alpha(color) < 255) { |
| 4721 | // alpha doesn't go well for color filters, so let's blend it manually |
| 4722 | color = NotificationColorUtil.compositeColors(color, background); |
| 4723 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4724 | mCachedContrastColorIsFor = mN.color; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4725 | return mCachedContrastColor = color; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4726 | } |
| 4727 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4728 | int resolveAmbientColor() { |
| 4729 | if (mCachedAmbientColorIsFor == mN.color && mCachedAmbientColorIsFor != COLOR_INVALID) { |
| 4730 | return mCachedAmbientColor; |
| 4731 | } |
| 4732 | final int contrasted = NotificationColorUtil.resolveAmbientColor(mContext, mN.color); |
| 4733 | |
| 4734 | mCachedAmbientColorIsFor = mN.color; |
| 4735 | return mCachedAmbientColor = contrasted; |
| 4736 | } |
| 4737 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4738 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4739 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4740 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4741 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4742 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4743 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4744 | mN.actions = new Action[mActions.size()]; |
| 4745 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4746 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4747 | if (!mPersonList.isEmpty()) { |
| 4748 | mN.extras.putStringArray(EXTRA_PEOPLE, |
| 4749 | mPersonList.toArray(new String[mPersonList.size()])); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4750 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4751 | if (mN.bigContentView != null || mN.contentView != null |
| 4752 | || mN.headsUpContentView != null) { |
| 4753 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 4754 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4755 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4756 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4757 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4758 | /** |
| 4759 | * Creates a Builder from an existing notification so further changes can be made. |
| 4760 | * @param context The context for your application / activity. |
| 4761 | * @param n The notification to create a Builder from. |
| 4762 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4763 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4764 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4765 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 4766 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4767 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4768 | if (applicationInfo != null) { |
| 4769 | try { |
| 4770 | builderContext = context.createApplicationContext(applicationInfo, |
| 4771 | Context.CONTEXT_RESTRICTED); |
| 4772 | } catch (NameNotFoundException e) { |
| 4773 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 4774 | builderContext = context; // try with our context |
| 4775 | } |
| 4776 | } else { |
| 4777 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4778 | } |
| 4779 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4780 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4781 | } |
| 4782 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4783 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4784 | * @deprecated Use {@link #build()} instead. |
| 4785 | */ |
| 4786 | @Deprecated |
| 4787 | public Notification getNotification() { |
| 4788 | return build(); |
| 4789 | } |
| 4790 | |
| 4791 | /** |
| 4792 | * Combine all of the options that have been set and return a new {@link Notification} |
| 4793 | * object. |
| 4794 | */ |
| 4795 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4796 | // first, add any extras from the calling code |
| 4797 | if (mUserExtras != null) { |
| 4798 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 4799 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4800 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4801 | mN.creationTime = System.currentTimeMillis(); |
| 4802 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4803 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4804 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 4805 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4806 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4807 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4808 | if (mStyle != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4809 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4810 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4811 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4812 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame^] | 4813 | && (useExistingRemoteView())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4814 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4815 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4816 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 4817 | mN.contentView.getSequenceNumber()); |
| 4818 | } |
| 4819 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4820 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4821 | if (mN.bigContentView != null) { |
| 4822 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 4823 | mN.bigContentView.getSequenceNumber()); |
| 4824 | } |
| 4825 | } |
| 4826 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4827 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4828 | if (mN.headsUpContentView != null) { |
| 4829 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 4830 | mN.headsUpContentView.getSequenceNumber()); |
| 4831 | } |
| 4832 | } |
| 4833 | } |
| 4834 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 4835 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 4836 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 4837 | } |
| 4838 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4839 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4840 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 4841 | |
| 4842 | /** |
| 4843 | * Apply this Builder to an existing {@link Notification} object. |
| 4844 | * |
| 4845 | * @hide |
| 4846 | */ |
| 4847 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 4848 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 4849 | return n; |
| 4850 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4851 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4852 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4853 | * Removes RemoteViews that were created for compatibility from {@param n}, if they did not |
| 4854 | * change. |
| 4855 | * |
| 4856 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 4857 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4858 | * @hide |
| 4859 | */ |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4860 | public static Notification maybeCloneStrippedForDelivery(Notification n) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4861 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4862 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4863 | // Only strip views for known Styles because we won't know how to |
| 4864 | // re-create them otherwise. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4865 | if (!TextUtils.isEmpty(templateClass) |
| 4866 | && getNotificationStyleClass(templateClass) == null) { |
| 4867 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4868 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4869 | |
| 4870 | // Only strip unmodified BuilderRemoteViews. |
| 4871 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4872 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4873 | n.contentView.getSequenceNumber(); |
| 4874 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4875 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4876 | n.bigContentView.getSequenceNumber(); |
| 4877 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4878 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4879 | n.headsUpContentView.getSequenceNumber(); |
| 4880 | |
| 4881 | // Nothing to do here, no need to clone. |
| 4882 | if (!stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
| 4883 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4884 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4885 | |
| 4886 | Notification clone = n.clone(); |
| 4887 | if (stripContentView) { |
| 4888 | clone.contentView = null; |
| 4889 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 4890 | } |
| 4891 | if (stripBigContentView) { |
| 4892 | clone.bigContentView = null; |
| 4893 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 4894 | } |
| 4895 | if (stripHeadsUpContentView) { |
| 4896 | clone.headsUpContentView = null; |
| 4897 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 4898 | } |
| 4899 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4900 | } |
| 4901 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4902 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4903 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4907 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4908 | } |
| 4909 | |
| 4910 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4911 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4915 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4916 | } |
| 4917 | |
| 4918 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4919 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4920 | } |
| 4921 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 4922 | private int getMessagingLayoutResource() { |
| 4923 | return R.layout.notification_template_material_messaging; |
| 4924 | } |
| 4925 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4926 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4927 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4928 | } |
| 4929 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4930 | private int getEmphasizedActionLayoutResource() { |
| 4931 | return R.layout.notification_material_action_emphasized; |
| 4932 | } |
| 4933 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4934 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4935 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4936 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4937 | |
| 4938 | private int getBackgroundColor() { |
| 4939 | if (isColorized()) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4940 | return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : mN.color; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4941 | } else { |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4942 | return mBackgroundColorHint != COLOR_INVALID ? mBackgroundColorHint |
| 4943 | : COLOR_DEFAULT; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4944 | } |
| 4945 | } |
| 4946 | |
| 4947 | private boolean isColorized() { |
| 4948 | return mN.isColorized(); |
| 4949 | } |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4950 | |
| 4951 | private boolean textColorsNeedInversion() { |
| 4952 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 4953 | return false; |
| 4954 | } |
| 4955 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 4956 | return targetSdkVersion > Build.VERSION_CODES.M |
| 4957 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 4958 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4959 | |
| 4960 | /** |
| 4961 | * Set a color palette to be used as the background and textColors |
| 4962 | * |
| 4963 | * @param backgroundColor the color to be used as the background |
| 4964 | * @param foregroundColor the color to be used as the foreground |
| 4965 | * |
| 4966 | * @hide |
| 4967 | */ |
| 4968 | public void setColorPalette(int backgroundColor, int foregroundColor) { |
| 4969 | mBackgroundColor = backgroundColor; |
| 4970 | mForegroundColor = foregroundColor; |
| 4971 | mTextColorsAreForBackground = COLOR_INVALID; |
| 4972 | ensureColors(); |
| 4973 | } |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4974 | |
| 4975 | /** |
| 4976 | * Sets the background color for this notification to be a different one then the default. |
| 4977 | * This is mainly used to calculate contrast and won't necessarily be applied to the |
| 4978 | * background. |
| 4979 | * |
| 4980 | * @hide |
| 4981 | */ |
| 4982 | public void setBackgroundColorHint(int backgroundColor) { |
| 4983 | mBackgroundColorHint = backgroundColor; |
| 4984 | } |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame^] | 4985 | |
| 4986 | |
| 4987 | /** |
| 4988 | * Forces all styled remoteViews to be built from scratch and not use any cached |
| 4989 | * RemoteViews. |
| 4990 | * This is needed for legacy apps that are baking in their remoteviews into the |
| 4991 | * notification. |
| 4992 | * |
| 4993 | * @hide |
| 4994 | */ |
| 4995 | public void setRebuildStyledRemoteViews(boolean rebuild) { |
| 4996 | mRebuildStyledRemoteViews = rebuild; |
| 4997 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5001 | * @return whether this notification is a foreground service notification |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5002 | */ |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5003 | private boolean isForegroundService() { |
| 5004 | return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5008 | * @return whether this notification has a media session attached |
| 5009 | * @hide |
| 5010 | */ |
| 5011 | public boolean hasMediaSession() { |
| 5012 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 5013 | } |
| 5014 | |
| 5015 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5016 | * @return the style class of this notification |
| 5017 | * @hide |
| 5018 | */ |
| 5019 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 5020 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 5021 | |
| 5022 | if (!TextUtils.isEmpty(templateClass)) { |
| 5023 | return Notification.getNotificationStyleClass(templateClass); |
| 5024 | } |
| 5025 | return null; |
| 5026 | } |
| 5027 | |
| 5028 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5029 | * @return true if this notification is colorized. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5030 | * |
| 5031 | * @hide |
| 5032 | */ |
| 5033 | public boolean isColorized() { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5034 | if (isColorizedMedia()) { |
| 5035 | return true; |
| 5036 | } |
| 5037 | return extras.getBoolean(EXTRA_COLORIZED) && isForegroundService(); |
| 5038 | } |
| 5039 | |
| 5040 | /** |
| 5041 | * @return true if this notification is colorized and it is a media notification |
| 5042 | * |
| 5043 | * @hide |
| 5044 | */ |
| 5045 | public boolean isColorizedMedia() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5046 | Class<? extends Style> style = getNotificationStyle(); |
| 5047 | if (MediaStyle.class.equals(style)) { |
| 5048 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 5049 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 5050 | return true; |
| 5051 | } |
| 5052 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 5053 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 5054 | return true; |
| 5055 | } |
| 5056 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5057 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5058 | } |
| 5059 | |
Selim Cinek | 0847acd | 2017-04-24 19:48:29 -0700 | [diff] [blame] | 5060 | |
| 5061 | /** |
| 5062 | * @return true if this is a media notification |
| 5063 | * |
| 5064 | * @hide |
| 5065 | */ |
| 5066 | public boolean isMediaNotification() { |
| 5067 | Class<? extends Style> style = getNotificationStyle(); |
| 5068 | if (MediaStyle.class.equals(style)) { |
| 5069 | return true; |
| 5070 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 5071 | return true; |
| 5072 | } |
| 5073 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5074 | } |
| 5075 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5076 | private boolean hasLargeIcon() { |
| 5077 | return mLargeIcon != null || largeIcon != null; |
| 5078 | } |
| 5079 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5080 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5081 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5082 | * @hide |
| 5083 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5084 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5085 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 5086 | } |
| 5087 | |
| 5088 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5089 | * @return true if the notification will show a chronometer; false otherwise |
| 5090 | * @hide |
| 5091 | */ |
| 5092 | public boolean showsChronometer() { |
| 5093 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 5094 | } |
| 5095 | |
| 5096 | /** |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 5097 | * @hide |
| 5098 | */ |
| 5099 | @SystemApi |
| 5100 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 5101 | Class<? extends Style>[] classes = new Class[] { |
| 5102 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 5103 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 5104 | MessagingStyle.class }; |
| 5105 | for (Class<? extends Style> innerClass : classes) { |
| 5106 | if (templateClass.equals(innerClass.getName())) { |
| 5107 | return innerClass; |
| 5108 | } |
| 5109 | } |
| 5110 | return null; |
| 5111 | } |
| 5112 | |
| 5113 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5114 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 5115 | * object. |
| 5116 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 5117 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5118 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 5119 | |
| 5120 | /** |
| 5121 | * @hide |
| 5122 | */ |
| 5123 | protected CharSequence mSummaryText = null; |
| 5124 | |
| 5125 | /** |
| 5126 | * @hide |
| 5127 | */ |
| 5128 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5129 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5130 | protected Builder mBuilder; |
| 5131 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5132 | /** |
| 5133 | * Overrides ContentTitle in the big form of the template. |
| 5134 | * This defaults to the value passed to setContentTitle(). |
| 5135 | */ |
| 5136 | protected void internalSetBigContentTitle(CharSequence title) { |
| 5137 | mBigContentTitle = title; |
| 5138 | } |
| 5139 | |
| 5140 | /** |
| 5141 | * Set the first line of text after the detail section in the big form of the template. |
| 5142 | */ |
| 5143 | protected void internalSetSummaryText(CharSequence cs) { |
| 5144 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 5145 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5146 | } |
| 5147 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5148 | public void setBuilder(Builder builder) { |
| 5149 | if (mBuilder != builder) { |
| 5150 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 5151 | if (mBuilder != null) { |
| 5152 | mBuilder.setStyle(this); |
| 5153 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5154 | } |
| 5155 | } |
| 5156 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5157 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5158 | if (mBuilder == null) { |
| 5159 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 5160 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5161 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5162 | |
| 5163 | protected RemoteViews getStandardView(int layoutId) { |
| 5164 | checkBuilder(); |
| 5165 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5166 | // Nasty. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5167 | CharSequence oldBuilderContentTitle = |
| 5168 | mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5169 | if (mBigContentTitle != null) { |
| 5170 | mBuilder.setContentTitle(mBigContentTitle); |
| 5171 | } |
| 5172 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5173 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 5174 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5175 | mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5176 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5177 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 5178 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 5179 | } else { |
| 5180 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5181 | } |
| 5182 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5183 | return contentView; |
| 5184 | } |
| 5185 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5186 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5187 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5188 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5189 | * |
| 5190 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5191 | * @hide |
| 5192 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5193 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5194 | return null; |
| 5195 | } |
| 5196 | |
| 5197 | /** |
| 5198 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 5199 | * @hide |
| 5200 | */ |
| 5201 | public RemoteViews makeBigContentView() { |
| 5202 | return null; |
| 5203 | } |
| 5204 | |
| 5205 | /** |
| 5206 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5207 | * |
| 5208 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5209 | * @hide |
| 5210 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5211 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5212 | return null; |
| 5213 | } |
| 5214 | |
| 5215 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5216 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5217 | * @hide |
| 5218 | */ |
| 5219 | public void addExtras(Bundle extras) { |
| 5220 | if (mSummaryTextSet) { |
| 5221 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 5222 | } |
| 5223 | if (mBigContentTitle != null) { |
| 5224 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 5225 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 5226 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5227 | } |
| 5228 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5229 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5230 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5231 | * @hide |
| 5232 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5233 | protected void restoreFromExtras(Bundle extras) { |
| 5234 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 5235 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 5236 | mSummaryTextSet = true; |
| 5237 | } |
| 5238 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 5239 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 5240 | } |
| 5241 | } |
| 5242 | |
| 5243 | |
| 5244 | /** |
| 5245 | * @hide |
| 5246 | */ |
| 5247 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5248 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5249 | return wip; |
| 5250 | } |
| 5251 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 5252 | /** |
| 5253 | * @hide |
| 5254 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5255 | public void purgeResources() {} |
| 5256 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5257 | /** |
| 5258 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 5259 | * attached to. |
| 5260 | * |
| 5261 | * @return the fully constructed Notification. |
| 5262 | */ |
| 5263 | public Notification build() { |
| 5264 | checkBuilder(); |
| 5265 | return mBuilder.build(); |
| 5266 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5267 | |
| 5268 | /** |
| 5269 | * @hide |
| 5270 | * @return true if the style positions the progress bar on the second line; false if the |
| 5271 | * style hides the progress bar |
| 5272 | */ |
| 5273 | protected boolean hasProgress() { |
| 5274 | return true; |
| 5275 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5276 | |
| 5277 | /** |
| 5278 | * @hide |
| 5279 | * @return Whether we should put the summary be put into the notification header |
| 5280 | */ |
| 5281 | public boolean hasSummaryInHeader() { |
| 5282 | return true; |
| 5283 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 5284 | |
| 5285 | /** |
| 5286 | * @hide |
| 5287 | * @return Whether custom content views are displayed inline in the style |
| 5288 | */ |
| 5289 | public boolean displayCustomViewInline() { |
| 5290 | return false; |
| 5291 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5292 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5293 | |
| 5294 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5295 | * 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] | 5296 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5297 | * 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] | 5298 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5299 | * Notification notif = new Notification.Builder(mContext) |
| 5300 | * .setContentTitle("New photo from " + sender.toString()) |
| 5301 | * .setContentText(subject) |
| 5302 | * .setSmallIcon(R.drawable.new_post) |
| 5303 | * .setLargeIcon(aBitmap) |
| 5304 | * .setStyle(new Notification.BigPictureStyle() |
| 5305 | * .bigPicture(aBigBitmap)) |
| 5306 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5307 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5308 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5309 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5310 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5311 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5312 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5313 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5314 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5315 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5316 | public BigPictureStyle() { |
| 5317 | } |
| 5318 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 5319 | /** |
| 5320 | * @deprecated use {@code BigPictureStyle()}. |
| 5321 | */ |
| 5322 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5323 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5324 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5325 | } |
| 5326 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5327 | /** |
| 5328 | * Overrides ContentTitle in the big form of the template. |
| 5329 | * This defaults to the value passed to setContentTitle(). |
| 5330 | */ |
| 5331 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5332 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5333 | return this; |
| 5334 | } |
| 5335 | |
| 5336 | /** |
| 5337 | * Set the first line of text after the detail section in the big form of the template. |
| 5338 | */ |
| 5339 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5340 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5341 | return this; |
| 5342 | } |
| 5343 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 5344 | /** |
| 5345 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 5346 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5347 | public BigPictureStyle bigPicture(Bitmap b) { |
| 5348 | mPicture = b; |
| 5349 | return this; |
| 5350 | } |
| 5351 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5352 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5353 | * Override the large icon when the big notification is shown. |
| 5354 | */ |
| 5355 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5356 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 5357 | } |
| 5358 | |
| 5359 | /** |
| 5360 | * Override the large icon when the big notification is shown. |
| 5361 | */ |
| 5362 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5363 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5364 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5365 | return this; |
| 5366 | } |
| 5367 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 5368 | /** @hide */ |
| 5369 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 5370 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 5371 | /** |
| 5372 | * @hide |
| 5373 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5374 | @Override |
| 5375 | public void purgeResources() { |
| 5376 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 5377 | if (mPicture != null && |
| 5378 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 5379 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5380 | mPicture = mPicture.createAshmemBitmap(); |
| 5381 | } |
| 5382 | if (mBigLargeIcon != null) { |
| 5383 | mBigLargeIcon.convertToAshmem(); |
| 5384 | } |
| 5385 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5386 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5387 | /** |
| 5388 | * @hide |
| 5389 | */ |
| 5390 | public RemoteViews makeBigContentView() { |
| 5391 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5392 | // This covers the following cases: |
| 5393 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5394 | // mN.mLargeIcon |
| 5395 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5396 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5397 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5398 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5399 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 5400 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5401 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 5402 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 5403 | // for old listeners, this is in general non-null. |
| 5404 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 5405 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5406 | } |
| 5407 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5408 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5409 | if (mSummaryTextSet) { |
| 5410 | contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(mSummaryText)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5411 | mBuilder.setTextViewColorSecondary(contentView, R.id.text); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 5412 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5413 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5414 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 5415 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5416 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5417 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5418 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5419 | } |
| 5420 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5421 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5422 | return contentView; |
| 5423 | } |
| 5424 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5425 | /** |
| 5426 | * @hide |
| 5427 | */ |
| 5428 | public void addExtras(Bundle extras) { |
| 5429 | super.addExtras(extras); |
| 5430 | |
| 5431 | if (mBigLargeIconSet) { |
| 5432 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 5433 | } |
| 5434 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 5435 | } |
| 5436 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5437 | /** |
| 5438 | * @hide |
| 5439 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5440 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5441 | protected void restoreFromExtras(Bundle extras) { |
| 5442 | super.restoreFromExtras(extras); |
| 5443 | |
| 5444 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5445 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5446 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5447 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5448 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 5449 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5450 | |
| 5451 | /** |
| 5452 | * @hide |
| 5453 | */ |
| 5454 | @Override |
| 5455 | public boolean hasSummaryInHeader() { |
| 5456 | return false; |
| 5457 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5461 | * 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] | 5462 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5463 | * 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] | 5464 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5465 | * Notification notif = new Notification.Builder(mContext) |
| 5466 | * .setContentTitle("New mail from " + sender.toString()) |
| 5467 | * .setContentText(subject) |
| 5468 | * .setSmallIcon(R.drawable.new_mail) |
| 5469 | * .setLargeIcon(aBitmap) |
| 5470 | * .setStyle(new Notification.BigTextStyle() |
| 5471 | * .bigText(aVeryLongString)) |
| 5472 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5473 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5474 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5475 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5476 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5477 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 5478 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5479 | private CharSequence mBigText; |
| 5480 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5481 | public BigTextStyle() { |
| 5482 | } |
| 5483 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 5484 | /** |
| 5485 | * @deprecated use {@code BigTextStyle()}. |
| 5486 | */ |
| 5487 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5488 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5489 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5490 | } |
| 5491 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5492 | /** |
| 5493 | * Overrides ContentTitle in the big form of the template. |
| 5494 | * This defaults to the value passed to setContentTitle(). |
| 5495 | */ |
| 5496 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5497 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5498 | return this; |
| 5499 | } |
| 5500 | |
| 5501 | /** |
| 5502 | * Set the first line of text after the detail section in the big form of the template. |
| 5503 | */ |
| 5504 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5505 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5506 | return this; |
| 5507 | } |
| 5508 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 5509 | /** |
| 5510 | * Provide the longer text to be displayed in the big form of the |
| 5511 | * template in place of the content text. |
| 5512 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5513 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5514 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5515 | return this; |
| 5516 | } |
| 5517 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5518 | /** |
| 5519 | * @hide |
| 5520 | */ |
| 5521 | public void addExtras(Bundle extras) { |
| 5522 | super.addExtras(extras); |
| 5523 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5524 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 5525 | } |
| 5526 | |
| 5527 | /** |
| 5528 | * @hide |
| 5529 | */ |
| 5530 | @Override |
| 5531 | protected void restoreFromExtras(Bundle extras) { |
| 5532 | super.restoreFromExtras(extras); |
| 5533 | |
| 5534 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5535 | } |
| 5536 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5537 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5538 | * @param increasedHeight true if this layout be created with an increased height. |
| 5539 | * |
| 5540 | * @hide |
| 5541 | */ |
| 5542 | @Override |
| 5543 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 5544 | if (increasedHeight) { |
| 5545 | ArrayList<Action> actions = mBuilder.mActions; |
| 5546 | mBuilder.mActions = new ArrayList<>(); |
| 5547 | RemoteViews remoteViews = makeBigContentView(); |
| 5548 | mBuilder.mActions = actions; |
| 5549 | return remoteViews; |
| 5550 | } |
| 5551 | return super.makeContentView(increasedHeight); |
| 5552 | } |
| 5553 | |
| 5554 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5555 | * @hide |
| 5556 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5557 | @Override |
| 5558 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 5559 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 5560 | return makeBigContentView(); |
| 5561 | } |
| 5562 | return super.makeHeadsUpContentView(increasedHeight); |
| 5563 | } |
| 5564 | |
| 5565 | /** |
| 5566 | * @hide |
| 5567 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5568 | public RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5569 | |
| 5570 | // Nasty |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 5571 | CharSequence text = mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5572 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 5573 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5574 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5575 | |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 5576 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, text); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5577 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 5578 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 5579 | if (TextUtils.isEmpty(bigTextText)) { |
| 5580 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 5581 | // experience |
| 5582 | bigTextText = mBuilder.processLegacyText(text); |
| 5583 | } |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5584 | applyBigTextContentView(mBuilder, contentView, bigTextText); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 5585 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5586 | return contentView; |
| 5587 | } |
| 5588 | |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5589 | static void applyBigTextContentView(Builder builder, |
| 5590 | RemoteViews contentView, CharSequence bigTextText) { |
| 5591 | contentView.setTextViewText(R.id.big_text, bigTextText); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5592 | builder.setTextViewColorSecondary(contentView, R.id.big_text); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5593 | contentView.setViewVisibility(R.id.big_text, |
| 5594 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5595 | contentView.setBoolean(R.id.big_text, "setHasImage", builder.mN.hasLargeIcon()); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5596 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5597 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5598 | |
| 5599 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5600 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 5601 | * messages of varying types between any number of people. |
| 5602 | * |
| 5603 | * <br> |
| 5604 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 5605 | * user will always see the normal notification view. |
| 5606 | * <br> |
| 5607 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like |
| 5608 | * so: |
| 5609 | * <pre class="prettyprint"> |
| 5610 | * |
| 5611 | * Notification noti = new Notification.Builder() |
| 5612 | * .setContentTitle("2 new messages wtih " + sender.toString()) |
| 5613 | * .setContentText(subject) |
| 5614 | * .setSmallIcon(R.drawable.new_message) |
| 5615 | * .setLargeIcon(aBitmap) |
| 5616 | * .setStyle(new Notification.MessagingStyle(resources.getString(R.string.reply_name)) |
| 5617 | * .addMessage(messages[0].getText(), messages[0].getTime(), messages[0].getSender()) |
| 5618 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getSender())) |
| 5619 | * .build(); |
| 5620 | * </pre> |
| 5621 | */ |
| 5622 | public static class MessagingStyle extends Style { |
| 5623 | |
| 5624 | /** |
| 5625 | * The maximum number of messages that will be retained in the Notification itself (the |
| 5626 | * number displayed is up to the platform). |
| 5627 | */ |
| 5628 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 5629 | |
| 5630 | CharSequence mUserDisplayName; |
| 5631 | CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5632 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5633 | List<Message> mHistoricMessages = new ArrayList<>(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5634 | |
| 5635 | MessagingStyle() { |
| 5636 | } |
| 5637 | |
| 5638 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 5639 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 5640 | * user before the posting app reposts the notification with those messages after they've |
| 5641 | * 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] | 5642 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
| 5643 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 5644 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5645 | mUserDisplayName = userDisplayName; |
| 5646 | } |
| 5647 | |
| 5648 | /** |
| 5649 | * Returns the name to be displayed for any replies sent by the user |
| 5650 | */ |
| 5651 | public CharSequence getUserDisplayName() { |
| 5652 | return mUserDisplayName; |
| 5653 | } |
| 5654 | |
| 5655 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5656 | * Sets the title to be displayed on this conversation. This should only be used for |
| 5657 | * group messaging and left unset for one-on-one conversations. |
| 5658 | * @param conversationTitle |
| 5659 | * @return this object for method chaining. |
| 5660 | */ |
| 5661 | public MessagingStyle setConversationTitle(CharSequence conversationTitle) { |
| 5662 | mConversationTitle = conversationTitle; |
| 5663 | return this; |
| 5664 | } |
| 5665 | |
| 5666 | /** |
| 5667 | * Return the title to be displayed on this conversation. Can be <code>null</code> and |
| 5668 | * should be for one-on-one conversations |
| 5669 | */ |
| 5670 | public CharSequence getConversationTitle() { |
| 5671 | return mConversationTitle; |
| 5672 | } |
| 5673 | |
| 5674 | /** |
| 5675 | * Adds a message for display by this notification. Convenience call for a simple |
| 5676 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 5677 | * @param text A {@link CharSequence} to be displayed as the message content |
| 5678 | * @param timestamp Time at which the message arrived |
| 5679 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 5680 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 5681 | * the platform will insert {@link #getUserDisplayName()}. |
| 5682 | * Should be unique amongst all individuals in the conversation, and should be |
| 5683 | * consistent during re-posts of the notification. |
| 5684 | * |
| 5685 | * @see Message#Message(CharSequence, long, CharSequence) |
| 5686 | * |
| 5687 | * @return this object for method chaining |
| 5688 | */ |
| 5689 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5690 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | /** |
| 5694 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5695 | * |
| 5696 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 5697 | * the newest last. |
| 5698 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5699 | * @param message The {@link Message} to be displayed |
| 5700 | * @return this object for method chaining |
| 5701 | */ |
| 5702 | public MessagingStyle addMessage(Message message) { |
| 5703 | mMessages.add(message); |
| 5704 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 5705 | mMessages.remove(0); |
| 5706 | } |
| 5707 | return this; |
| 5708 | } |
| 5709 | |
| 5710 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5711 | * Adds a {@link Message} for historic context in this notification. |
| 5712 | * |
| 5713 | * <p>Messages should be added as historic if they are not the main subject of the |
| 5714 | * notification but may give context to a conversation. The system may choose to present |
| 5715 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 5716 | * |
| 5717 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 5718 | * the newest last. |
| 5719 | * |
| 5720 | * @param message The historic {@link Message} to be added |
| 5721 | * @return this object for method chaining |
| 5722 | */ |
| 5723 | public MessagingStyle addHistoricMessage(Message message) { |
| 5724 | mHistoricMessages.add(message); |
| 5725 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 5726 | mHistoricMessages.remove(0); |
| 5727 | } |
| 5728 | return this; |
| 5729 | } |
| 5730 | |
| 5731 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5732 | * Gets the list of {@code Message} objects that represent the notification |
| 5733 | */ |
| 5734 | public List<Message> getMessages() { |
| 5735 | return mMessages; |
| 5736 | } |
| 5737 | |
| 5738 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5739 | * Gets the list of historic {@code Message}s in the notification. |
| 5740 | */ |
| 5741 | public List<Message> getHistoricMessages() { |
| 5742 | return mHistoricMessages; |
| 5743 | } |
| 5744 | |
| 5745 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5746 | * @hide |
| 5747 | */ |
| 5748 | @Override |
| 5749 | public void addExtras(Bundle extras) { |
| 5750 | super.addExtras(extras); |
| 5751 | if (mUserDisplayName != null) { |
| 5752 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUserDisplayName); |
| 5753 | } |
| 5754 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5755 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5756 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5757 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 5758 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5759 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5760 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 5761 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 5762 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 5763 | |
| 5764 | fixTitleAndTextExtras(extras); |
| 5765 | } |
| 5766 | |
| 5767 | private void fixTitleAndTextExtras(Bundle extras) { |
| 5768 | Message m = findLatestIncomingMessage(); |
| 5769 | CharSequence text = (m == null) ? null : m.mText; |
| 5770 | CharSequence sender = m == null ? null |
| 5771 | : TextUtils.isEmpty(m.mSender) ? mUserDisplayName : m.mSender; |
| 5772 | CharSequence title; |
| 5773 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 5774 | if (!TextUtils.isEmpty(sender)) { |
| 5775 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5776 | title = mBuilder.mContext.getString( |
| 5777 | com.android.internal.R.string.notification_messaging_title_template, |
| 5778 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(m.mSender)); |
| 5779 | } else { |
| 5780 | title = mConversationTitle; |
| 5781 | } |
| 5782 | } else { |
| 5783 | title = sender; |
| 5784 | } |
| 5785 | |
| 5786 | if (title != null) { |
| 5787 | extras.putCharSequence(EXTRA_TITLE, title); |
| 5788 | } |
| 5789 | if (text != null) { |
| 5790 | extras.putCharSequence(EXTRA_TEXT, text); |
| 5791 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5792 | } |
| 5793 | |
| 5794 | /** |
| 5795 | * @hide |
| 5796 | */ |
| 5797 | @Override |
| 5798 | protected void restoreFromExtras(Bundle extras) { |
| 5799 | super.restoreFromExtras(extras); |
| 5800 | |
| 5801 | mMessages.clear(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5802 | mHistoricMessages.clear(); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5803 | mUserDisplayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
| 5804 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5805 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 5806 | if (messages != null && messages instanceof Parcelable[]) { |
| 5807 | mMessages = Message.getMessagesFromBundleArray(messages); |
| 5808 | } |
| 5809 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 5810 | if (histMessages != null && histMessages instanceof Parcelable[]) { |
| 5811 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | /** |
| 5816 | * @hide |
| 5817 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5818 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5819 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 5820 | if (!increasedHeight) { |
| 5821 | Message m = findLatestIncomingMessage(); |
| 5822 | CharSequence title = mConversationTitle != null |
| 5823 | ? mConversationTitle |
| 5824 | : (m == null) ? null : m.mSender; |
| 5825 | CharSequence text = (m == null) |
| 5826 | ? null |
| 5827 | : mConversationTitle != null ? makeMessageLine(m, mBuilder) : m.mText; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5828 | |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5829 | return mBuilder.applyStandardTemplate(mBuilder.getBaseLayoutResource(), |
| 5830 | mBuilder.mParams.reset().hasProgress(false).title(title).text(text)); |
| 5831 | } else { |
| 5832 | ArrayList<Action> actions = mBuilder.mActions; |
| 5833 | mBuilder.mActions = new ArrayList<>(); |
| 5834 | RemoteViews remoteViews = makeBigContentView(); |
| 5835 | mBuilder.mActions = actions; |
| 5836 | return remoteViews; |
| 5837 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | private Message findLatestIncomingMessage() { |
| 5841 | for (int i = mMessages.size() - 1; i >= 0; i--) { |
| 5842 | Message m = mMessages.get(i); |
| 5843 | // Incoming messages have a non-empty sender. |
| 5844 | if (!TextUtils.isEmpty(m.mSender)) { |
| 5845 | return m; |
| 5846 | } |
| 5847 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 5848 | if (!mMessages.isEmpty()) { |
| 5849 | // No incoming messages, fall back to outgoing message |
| 5850 | return mMessages.get(mMessages.size() - 1); |
| 5851 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5852 | return null; |
| 5853 | } |
| 5854 | |
| 5855 | /** |
| 5856 | * @hide |
| 5857 | */ |
| 5858 | @Override |
| 5859 | public RemoteViews makeBigContentView() { |
| 5860 | CharSequence title = !TextUtils.isEmpty(super.mBigContentTitle) |
| 5861 | ? super.mBigContentTitle |
| 5862 | : mConversationTitle; |
| 5863 | boolean hasTitle = !TextUtils.isEmpty(title); |
| 5864 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 5865 | if (mMessages.size() == 1) { |
| 5866 | // Special case for a single message: Use the big text style |
| 5867 | // so the collapsed and expanded versions match nicely. |
| 5868 | CharSequence bigTitle; |
| 5869 | CharSequence text; |
| 5870 | if (hasTitle) { |
| 5871 | bigTitle = title; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5872 | text = makeMessageLine(mMessages.get(0), mBuilder); |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 5873 | } else { |
| 5874 | bigTitle = mMessages.get(0).mSender; |
| 5875 | text = mMessages.get(0).mText; |
| 5876 | } |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5877 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
| 5878 | mBuilder.getBigTextLayoutResource(), |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 5879 | mBuilder.mParams.reset().hasProgress(false).title(bigTitle).text(null)); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5880 | BigTextStyle.applyBigTextContentView(mBuilder, contentView, text); |
| 5881 | return contentView; |
| 5882 | } |
| 5883 | |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 5884 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5885 | mBuilder.getMessagingLayoutResource(), |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 5886 | mBuilder.mParams.reset().hasProgress(false).title(title).text(null)); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5887 | |
| 5888 | int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3, |
| 5889 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
| 5890 | |
| 5891 | // Make sure all rows are gone in case we reuse a view. |
| 5892 | for (int rowId : rowIds) { |
| 5893 | contentView.setViewVisibility(rowId, View.GONE); |
| 5894 | } |
| 5895 | |
| 5896 | int i=0; |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 5897 | contentView.setViewLayoutMarginBottomDimen(R.id.line1, |
| 5898 | hasTitle ? R.dimen.notification_messaging_spacing : 0); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5899 | contentView.setInt(R.id.notification_messaging, "setNumIndentLines", |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5900 | !mBuilder.mN.hasLargeIcon() ? 0 : (hasTitle ? 1 : 2)); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5901 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 5902 | int contractedChildId = View.NO_ID; |
| 5903 | Message contractedMessage = findLatestIncomingMessage(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5904 | int firstHistoricMessage = Math.max(0, mHistoricMessages.size() |
| 5905 | - (rowIds.length - mMessages.size())); |
| 5906 | while (firstHistoricMessage + i < mHistoricMessages.size() && i < rowIds.length) { |
| 5907 | Message m = mHistoricMessages.get(firstHistoricMessage + i); |
| 5908 | int rowId = rowIds[i]; |
| 5909 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5910 | contentView.setTextViewText(rowId, makeMessageLine(m, mBuilder)); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5911 | |
| 5912 | if (contractedMessage == m) { |
| 5913 | contractedChildId = rowId; |
| 5914 | } |
| 5915 | |
| 5916 | i++; |
| 5917 | } |
| 5918 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5919 | int firstMessage = Math.max(0, mMessages.size() - rowIds.length); |
| 5920 | while (firstMessage + i < mMessages.size() && i < rowIds.length) { |
| 5921 | Message m = mMessages.get(firstMessage + i); |
| 5922 | int rowId = rowIds[i]; |
| 5923 | |
| 5924 | contentView.setViewVisibility(rowId, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5925 | contentView.setTextViewText(rowId, makeMessageLine(m, mBuilder)); |
| 5926 | mBuilder.setTextViewColorSecondary(contentView, rowId); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5927 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 5928 | if (contractedMessage == m) { |
| 5929 | contractedChildId = rowId; |
| 5930 | } |
| 5931 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5932 | i++; |
| 5933 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5934 | // Clear the remaining views for reapply. Ensures that historic message views can |
| 5935 | // reliably be identified as being GONE and having non-null text. |
| 5936 | while (i < rowIds.length) { |
| 5937 | int rowId = rowIds[i]; |
| 5938 | contentView.setTextViewText(rowId, null); |
| 5939 | i++; |
| 5940 | } |
| 5941 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 5942 | // Record this here to allow transformation between the contracted and expanded views. |
| 5943 | contentView.setInt(R.id.notification_messaging, "setContractedChildId", |
| 5944 | contractedChildId); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5945 | return contentView; |
| 5946 | } |
| 5947 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5948 | private CharSequence makeMessageLine(Message m, Builder builder) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5949 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5950 | SpannableStringBuilder sb = new SpannableStringBuilder(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5951 | boolean colorize = builder.isColorized(); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5952 | if (TextUtils.isEmpty(m.mSender)) { |
| 5953 | CharSequence replyName = mUserDisplayName == null ? "" : mUserDisplayName; |
| 5954 | sb.append(bidi.unicodeWrap(replyName), |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5955 | makeFontColorSpan(colorize |
| 5956 | ? builder.getPrimaryTextColor() |
| 5957 | : mBuilder.resolveContrastColor()), |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5958 | 0 /* flags */); |
| 5959 | } else { |
| 5960 | sb.append(bidi.unicodeWrap(m.mSender), |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5961 | makeFontColorSpan(colorize |
| 5962 | ? builder.getPrimaryTextColor() |
| 5963 | : Color.BLACK), |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5964 | 0 /* flags */); |
| 5965 | } |
| 5966 | CharSequence text = m.mText == null ? "" : m.mText; |
| 5967 | sb.append(" ").append(bidi.unicodeWrap(text)); |
| 5968 | return sb; |
| 5969 | } |
| 5970 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 5971 | /** |
| 5972 | * @hide |
| 5973 | */ |
| 5974 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5975 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 5976 | if (increasedHeight) { |
| 5977 | return makeBigContentView(); |
| 5978 | } |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 5979 | Message m = findLatestIncomingMessage(); |
| 5980 | CharSequence title = mConversationTitle != null |
| 5981 | ? mConversationTitle |
| 5982 | : (m == null) ? null : m.mSender; |
| 5983 | CharSequence text = (m == null) |
| 5984 | ? null |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5985 | : mConversationTitle != null ? makeMessageLine(m, mBuilder) : m.mText; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 5986 | |
| 5987 | return mBuilder.applyStandardTemplateWithActions(mBuilder.getBigBaseLayoutResource(), |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 5988 | mBuilder.mParams.reset().hasProgress(false).title(title).text(text)); |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 5989 | } |
| 5990 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5991 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 5992 | return new TextAppearanceSpan(null, 0, 0, |
| 5993 | ColorStateList.valueOf(color), null); |
| 5994 | } |
| 5995 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5996 | public static final class Message { |
| 5997 | |
| 5998 | static final String KEY_TEXT = "text"; |
| 5999 | static final String KEY_TIMESTAMP = "time"; |
| 6000 | static final String KEY_SENDER = "sender"; |
| 6001 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 6002 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6003 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6004 | |
| 6005 | private final CharSequence mText; |
| 6006 | private final long mTimestamp; |
| 6007 | private final CharSequence mSender; |
| 6008 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6009 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6010 | private String mDataMimeType; |
| 6011 | private Uri mDataUri; |
| 6012 | |
| 6013 | /** |
| 6014 | * Constructor |
| 6015 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6016 | * @param timestamp Time at which the message arrived |
| 6017 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 6018 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 6019 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 6020 | * Should be unique amongst all individuals in the conversation, and should be |
| 6021 | * consistent during re-posts of the notification. |
| 6022 | */ |
| 6023 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
| 6024 | mText = text; |
| 6025 | mTimestamp = timestamp; |
| 6026 | mSender = sender; |
| 6027 | } |
| 6028 | |
| 6029 | /** |
| 6030 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 6031 | * where the platform doesn't support the MIME type, the original text provided in the |
| 6032 | * constructor will be used. |
| 6033 | * @param dataMimeType The MIME type of the content. See |
| 6034 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 6035 | * types on Android and Android Wear. |
| 6036 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 6037 | * <p class="note"> |
| 6038 | * <ol> |
| 6039 | * <li>Notification Listeners including the System UI need permission to access the |
| 6040 | * data the Uri points to. The recommended ways to do this are:</li> |
| 6041 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 6042 | * the correct permission to access your provider. The preferred mechanism for |
| 6043 | * providing access is to use per-URI permissions which are temporary and only |
| 6044 | * grant access to the receiving application. An easy way to create a |
| 6045 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 6046 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 6047 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 6048 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 6049 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 6050 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 6051 | * Note that once added to the system MediaStore the content is accessible to any |
| 6052 | * app on the device.</li> |
| 6053 | * </ol> |
| 6054 | * @return this object for method chaining |
| 6055 | */ |
| 6056 | public Message setData(String dataMimeType, Uri dataUri) { |
| 6057 | mDataMimeType = dataMimeType; |
| 6058 | mDataUri = dataUri; |
| 6059 | return this; |
| 6060 | } |
| 6061 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6062 | /** |
| 6063 | * Get the text to be used for this message, or the fallback text if a type and content |
| 6064 | * Uri have been set |
| 6065 | */ |
| 6066 | public CharSequence getText() { |
| 6067 | return mText; |
| 6068 | } |
| 6069 | |
| 6070 | /** |
| 6071 | * Get the time at which this message arrived |
| 6072 | */ |
| 6073 | public long getTimestamp() { |
| 6074 | return mTimestamp; |
| 6075 | } |
| 6076 | |
| 6077 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6078 | * Get the extras Bundle for this message. |
| 6079 | */ |
| 6080 | public Bundle getExtras() { |
| 6081 | return mExtras; |
| 6082 | } |
| 6083 | |
| 6084 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6085 | * Get the text used to display the contact's name in the messaging experience |
| 6086 | */ |
| 6087 | public CharSequence getSender() { |
| 6088 | return mSender; |
| 6089 | } |
| 6090 | |
| 6091 | /** |
| 6092 | * Get the MIME type of the data pointed to by the Uri |
| 6093 | */ |
| 6094 | public String getDataMimeType() { |
| 6095 | return mDataMimeType; |
| 6096 | } |
| 6097 | |
| 6098 | /** |
| 6099 | * Get the the Uri pointing to the content of the message. Can be null, in which case |
| 6100 | * {@see #getText()} is used. |
| 6101 | */ |
| 6102 | public Uri getDataUri() { |
| 6103 | return mDataUri; |
| 6104 | } |
| 6105 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6106 | private Bundle toBundle() { |
| 6107 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6108 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6109 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6110 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6111 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6112 | if (mSender != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6113 | bundle.putCharSequence(KEY_SENDER, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6114 | } |
| 6115 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6116 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6117 | } |
| 6118 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6119 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6120 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6121 | if (mExtras != null) { |
| 6122 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 6123 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6124 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6125 | } |
| 6126 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6127 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 6128 | Bundle[] bundles = new Bundle[messages.size()]; |
| 6129 | final int N = messages.size(); |
| 6130 | for (int i = 0; i < N; i++) { |
| 6131 | bundles[i] = messages.get(i).toBundle(); |
| 6132 | } |
| 6133 | return bundles; |
| 6134 | } |
| 6135 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6136 | static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6137 | List<Message> messages = new ArrayList<>(bundles.length); |
| 6138 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6139 | if (bundles[i] instanceof Bundle) { |
| 6140 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 6141 | if (message != null) { |
| 6142 | messages.add(message); |
| 6143 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6144 | } |
| 6145 | } |
| 6146 | return messages; |
| 6147 | } |
| 6148 | |
| 6149 | static Message getMessageFromBundle(Bundle bundle) { |
| 6150 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 6151 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6152 | return null; |
| 6153 | } else { |
| 6154 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
| 6155 | bundle.getLong(KEY_TIMESTAMP), bundle.getCharSequence(KEY_SENDER)); |
| 6156 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 6157 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6158 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 6159 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6160 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6161 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 6162 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 6163 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6164 | return message; |
| 6165 | } |
| 6166 | } catch (ClassCastException e) { |
| 6167 | return null; |
| 6168 | } |
| 6169 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6170 | } |
| 6171 | } |
| 6172 | |
| 6173 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6174 | * 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] | 6175 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6176 | * 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] | 6177 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6178 | * Notification notif = new Notification.Builder(mContext) |
| 6179 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 6180 | * .setContentText(subject) |
| 6181 | * .setSmallIcon(R.drawable.new_mail) |
| 6182 | * .setLargeIcon(aBitmap) |
| 6183 | * .setStyle(new Notification.InboxStyle() |
| 6184 | * .addLine(str1) |
| 6185 | * .addLine(str2) |
| 6186 | * .setContentTitle("") |
| 6187 | * .setSummaryText("+3 more")) |
| 6188 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6189 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6190 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6191 | * @see Notification#bigContentView |
| 6192 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6193 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6194 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 6195 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6196 | public InboxStyle() { |
| 6197 | } |
| 6198 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6199 | /** |
| 6200 | * @deprecated use {@code InboxStyle()}. |
| 6201 | */ |
| 6202 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6203 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6204 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6205 | } |
| 6206 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6207 | /** |
| 6208 | * Overrides ContentTitle in the big form of the template. |
| 6209 | * This defaults to the value passed to setContentTitle(). |
| 6210 | */ |
| 6211 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6212 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6213 | return this; |
| 6214 | } |
| 6215 | |
| 6216 | /** |
| 6217 | * Set the first line of text after the detail section in the big form of the template. |
| 6218 | */ |
| 6219 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6220 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6221 | return this; |
| 6222 | } |
| 6223 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6224 | /** |
| 6225 | * Append a line to the digest section of the Inbox notification. |
| 6226 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6227 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6228 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6229 | return this; |
| 6230 | } |
| 6231 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6232 | /** |
| 6233 | * @hide |
| 6234 | */ |
| 6235 | public void addExtras(Bundle extras) { |
| 6236 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6237 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6238 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 6239 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 6240 | } |
| 6241 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6242 | /** |
| 6243 | * @hide |
| 6244 | */ |
| 6245 | @Override |
| 6246 | protected void restoreFromExtras(Bundle extras) { |
| 6247 | super.restoreFromExtras(extras); |
| 6248 | |
| 6249 | mTexts.clear(); |
| 6250 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 6251 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 6252 | } |
| 6253 | } |
| 6254 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6255 | /** |
| 6256 | * @hide |
| 6257 | */ |
| 6258 | public RemoteViews makeBigContentView() { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 6259 | // Remove the content text so it disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6260 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6261 | CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT); |
| 6262 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6263 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 6264 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource()); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 6265 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6266 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6267 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6268 | 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] | 6269 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6270 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 6271 | // Make sure all rows are gone in case we reuse a view. |
| 6272 | for (int rowId : rowIds) { |
| 6273 | contentView.setViewVisibility(rowId, View.GONE); |
| 6274 | } |
| 6275 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6276 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6277 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 6278 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6279 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6280 | int onlyViewId = 0; |
| 6281 | int maxRows = rowIds.length; |
| 6282 | if (mBuilder.mActions.size() > 0) { |
| 6283 | maxRows--; |
| 6284 | } |
| 6285 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6286 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6287 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6288 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 6289 | contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6290 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i]); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6291 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6292 | handleInboxImageMargin(contentView, rowIds[i], first); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6293 | if (first) { |
| 6294 | onlyViewId = rowIds[i]; |
| 6295 | } else { |
| 6296 | onlyViewId = 0; |
| 6297 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6298 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6299 | } |
| 6300 | i++; |
| 6301 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6302 | if (onlyViewId != 0) { |
| 6303 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 6304 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 6305 | R.dimen.notification_text_margin_top); |
| 6306 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 6307 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6308 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6309 | return contentView; |
| 6310 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6311 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6312 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6313 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6314 | if (first) { |
| 6315 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 6316 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 6317 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6318 | if (mBuilder.mN.hasLargeIcon() && !hasProgress) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6319 | endMargin = R.dimen.notification_content_picture_margin; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6320 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6321 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6322 | contentView.setViewLayoutMarginEndDimen(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6323 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6324 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6325 | |
| 6326 | /** |
| 6327 | * Notification style for media playback notifications. |
| 6328 | * |
| 6329 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 6330 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 6331 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6332 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 6333 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 6334 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6335 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6336 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 6337 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 6338 | * {@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] | 6339 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6340 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 6341 | * Notifications created with MediaStyle will have their category set to |
| 6342 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 6343 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6344 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6345 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 6346 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6347 | * the System UI can identify this as a notification representing an active media session |
| 6348 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 6349 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6350 | * <p> |
| 6351 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 6352 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 6353 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 6354 | * <p> |
| 6355 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6356 | * To use this style with your Notification, feed it to |
| 6357 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 6358 | * <pre class="prettyprint"> |
| 6359 | * Notification noti = new Notification.Builder() |
| 6360 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 6361 | * .setContentTitle("Track title") |
| 6362 | * .setContentText("Artist - Album") |
| 6363 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 6364 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 6365 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6366 | * .build(); |
| 6367 | * </pre> |
| 6368 | * |
| 6369 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6370 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6371 | */ |
| 6372 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6373 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6374 | static final int MAX_MEDIA_BUTTONS = 5; |
| 6375 | |
| 6376 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6377 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6378 | |
| 6379 | public MediaStyle() { |
| 6380 | } |
| 6381 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6382 | /** |
| 6383 | * @deprecated use {@code MediaStyle()}. |
| 6384 | */ |
| 6385 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6386 | public MediaStyle(Builder builder) { |
| 6387 | setBuilder(builder); |
| 6388 | } |
| 6389 | |
| 6390 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6391 | * 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] | 6392 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6393 | * |
| 6394 | * @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] | 6395 | */ |
| 6396 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 6397 | mActionsToShowInCompact = actions; |
| 6398 | return this; |
| 6399 | } |
| 6400 | |
| 6401 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6402 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 6403 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6404 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6405 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6406 | mToken = token; |
| 6407 | return this; |
| 6408 | } |
| 6409 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6410 | /** |
| 6411 | * @hide |
| 6412 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6413 | @Override |
| 6414 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6415 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 6416 | if (wip.category == null) { |
| 6417 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 6418 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6419 | return wip; |
| 6420 | } |
| 6421 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6422 | /** |
| 6423 | * @hide |
| 6424 | */ |
| 6425 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6426 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6427 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | /** |
| 6431 | * @hide |
| 6432 | */ |
| 6433 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6434 | public RemoteViews makeBigContentView() { |
| 6435 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6436 | } |
| 6437 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6438 | /** |
| 6439 | * @hide |
| 6440 | */ |
| 6441 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6442 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6443 | RemoteViews expanded = makeMediaBigContentView(); |
| 6444 | return expanded != null ? expanded : makeMediaContentView(); |
| 6445 | } |
| 6446 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6447 | /** @hide */ |
| 6448 | @Override |
| 6449 | public void addExtras(Bundle extras) { |
| 6450 | super.addExtras(extras); |
| 6451 | |
| 6452 | if (mToken != null) { |
| 6453 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 6454 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 6455 | if (mActionsToShowInCompact != null) { |
| 6456 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 6457 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6458 | } |
| 6459 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6460 | /** |
| 6461 | * @hide |
| 6462 | */ |
| 6463 | @Override |
| 6464 | protected void restoreFromExtras(Bundle extras) { |
| 6465 | super.restoreFromExtras(extras); |
| 6466 | |
| 6467 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 6468 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 6469 | } |
| 6470 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 6471 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 6472 | } |
| 6473 | } |
| 6474 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6475 | private RemoteViews generateMediaActionButton(Action action, int color) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6476 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 6477 | RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 6478 | R.layout.notification_material_media_action); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 6479 | button.setImageViewIcon(R.id.action0, action.getIcon()); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6480 | button.setDrawableParameters(R.id.action0, false, -1, color, PorterDuff.Mode.SRC_ATOP, |
| 6481 | -1); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6482 | if (!tombstone) { |
| 6483 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 6484 | } |
| 6485 | button.setContentDescription(R.id.action0, action.title); |
| 6486 | return button; |
| 6487 | } |
| 6488 | |
| 6489 | private RemoteViews makeMediaContentView() { |
| 6490 | RemoteViews view = mBuilder.applyStandardTemplate( |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6491 | R.layout.notification_template_material_media, false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6492 | |
| 6493 | final int numActions = mBuilder.mActions.size(); |
| 6494 | final int N = mActionsToShowInCompact == null |
| 6495 | ? 0 |
| 6496 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 6497 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6498 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6499 | for (int i = 0; i < N; i++) { |
| 6500 | if (i >= numActions) { |
| 6501 | throw new IllegalArgumentException(String.format( |
| 6502 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 6503 | i, numActions - 1)); |
| 6504 | } |
| 6505 | |
| 6506 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6507 | final RemoteViews button = generateMediaActionButton(action, |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6508 | getPrimaryHighlightColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6509 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6510 | } |
| 6511 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 6512 | handleImage(view); |
| 6513 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6514 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6515 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6516 | endMargin = R.dimen.notification_content_plus_picture_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 6517 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6518 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6519 | return view; |
| 6520 | } |
| 6521 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6522 | private int getPrimaryHighlightColor() { |
| 6523 | return mBuilder.getPrimaryHighlightColor(); |
| 6524 | } |
| 6525 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6526 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6527 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6528 | // Dont add an expanded view if there is no more content to be revealed |
| 6529 | int actionsInCompact = mActionsToShowInCompact == null |
| 6530 | ? 0 |
| 6531 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6532 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6533 | return null; |
| 6534 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6535 | RemoteViews big = mBuilder.applyStandardTemplate( |
| 6536 | R.layout.notification_template_material_big_media, |
| 6537 | false); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6538 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6539 | if (actionCount > 0) { |
| 6540 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 6541 | for (int i = 0; i < actionCount; i++) { |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6542 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i), |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6543 | getPrimaryHighlightColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6544 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6545 | } |
| 6546 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6547 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6548 | return big; |
| 6549 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6550 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6551 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6552 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6553 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 6554 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6555 | } |
| 6556 | } |
| 6557 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6558 | /** |
| 6559 | * @hide |
| 6560 | */ |
| 6561 | @Override |
| 6562 | protected boolean hasProgress() { |
| 6563 | return false; |
| 6564 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6565 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6566 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6567 | /** |
| 6568 | * Notification style for custom views that are decorated by the system |
| 6569 | * |
| 6570 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 6571 | * style and still obtain system decorations like the notification header with the expand |
| 6572 | * affordance and actions. |
| 6573 | * |
| 6574 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 6575 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 6576 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 6577 | * corresponding custom views to display. |
| 6578 | * |
| 6579 | * To use this style with your Notification, feed it to |
| 6580 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 6581 | * <pre class="prettyprint"> |
| 6582 | * Notification noti = new Notification.Builder() |
| 6583 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 6584 | * .setLargeIcon(albumArtBitmap)) |
| 6585 | * .setCustomContentView(contentView); |
| 6586 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 6587 | * .build(); |
| 6588 | * </pre> |
| 6589 | */ |
| 6590 | public static class DecoratedCustomViewStyle extends Style { |
| 6591 | |
| 6592 | public DecoratedCustomViewStyle() { |
| 6593 | } |
| 6594 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6595 | /** |
| 6596 | * @hide |
| 6597 | */ |
| 6598 | public boolean displayCustomViewInline() { |
| 6599 | return true; |
| 6600 | } |
| 6601 | |
| 6602 | /** |
| 6603 | * @hide |
| 6604 | */ |
| 6605 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6606 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6607 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 6608 | } |
| 6609 | |
| 6610 | /** |
| 6611 | * @hide |
| 6612 | */ |
| 6613 | @Override |
| 6614 | public RemoteViews makeBigContentView() { |
| 6615 | return makeDecoratedBigContentView(); |
| 6616 | } |
| 6617 | |
| 6618 | /** |
| 6619 | * @hide |
| 6620 | */ |
| 6621 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6622 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6623 | return makeDecoratedHeadsUpContentView(); |
| 6624 | } |
| 6625 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6626 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 6627 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 6628 | ? mBuilder.mN.contentView |
| 6629 | : mBuilder.mN.headsUpContentView; |
| 6630 | if (mBuilder.mActions.size() == 0) { |
| 6631 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 6632 | } |
| 6633 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 6634 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6635 | buildIntoRemoteViewContent(remoteViews, headsUpContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6636 | return remoteViews; |
| 6637 | } |
| 6638 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6639 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
| 6640 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
| 6641 | mBuilder.getBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6642 | buildIntoRemoteViewContent(remoteViews, customContent); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6643 | return remoteViews; |
| 6644 | } |
| 6645 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6646 | private RemoteViews makeDecoratedBigContentView() { |
| 6647 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 6648 | ? mBuilder.mN.contentView |
| 6649 | : mBuilder.mN.bigContentView; |
| 6650 | if (mBuilder.mActions.size() == 0) { |
| 6651 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 6652 | } |
| 6653 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 6654 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6655 | buildIntoRemoteViewContent(remoteViews, bigContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6656 | return remoteViews; |
| 6657 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6658 | |
| 6659 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
| 6660 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6661 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6662 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 6663 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6664 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6665 | remoteViews.removeAllViews(R.id.notification_main_column); |
| 6666 | remoteViews.addView(R.id.notification_main_column, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6667 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6668 | // also update the end margin if there is an image |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6669 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6670 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6671 | endMargin = R.dimen.notification_content_plus_picture_margin_end; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6672 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6673 | remoteViews.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6674 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6675 | } |
| 6676 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6677 | /** |
| 6678 | * Notification style for media custom views that are decorated by the system |
| 6679 | * |
| 6680 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 6681 | * this style and still obtain system decorations like the notification header with the expand |
| 6682 | * affordance and actions. |
| 6683 | * |
| 6684 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 6685 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 6686 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 6687 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6688 | * <p> |
| 6689 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 6690 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 6691 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6692 | * To use this style with your Notification, feed it to |
| 6693 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 6694 | * <pre class="prettyprint"> |
| 6695 | * Notification noti = new Notification.Builder() |
| 6696 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 6697 | * .setLargeIcon(albumArtBitmap)) |
| 6698 | * .setCustomContentView(contentView); |
| 6699 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 6700 | * .setMediaSession(mySession)) |
| 6701 | * .build(); |
| 6702 | * </pre> |
| 6703 | * |
| 6704 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 6705 | * @see android.app.Notification.MediaStyle |
| 6706 | */ |
| 6707 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 6708 | |
| 6709 | public DecoratedMediaCustomViewStyle() { |
| 6710 | } |
| 6711 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6712 | /** |
| 6713 | * @hide |
| 6714 | */ |
| 6715 | public boolean displayCustomViewInline() { |
| 6716 | return true; |
| 6717 | } |
| 6718 | |
| 6719 | /** |
| 6720 | * @hide |
| 6721 | */ |
| 6722 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6723 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6724 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6725 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 6726 | mBuilder.mN.contentView); |
| 6727 | } |
| 6728 | |
| 6729 | /** |
| 6730 | * @hide |
| 6731 | */ |
| 6732 | @Override |
| 6733 | public RemoteViews makeBigContentView() { |
| 6734 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 6735 | ? mBuilder.mN.bigContentView |
| 6736 | : mBuilder.mN.contentView; |
| 6737 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 6738 | } |
| 6739 | |
| 6740 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 6741 | RemoteViews remoteViews = super.makeBigContentView(); |
| 6742 | if (remoteViews != null) { |
| 6743 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 6744 | customRemoteView); |
| 6745 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6746 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6747 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 6748 | customRemoteView); |
| 6749 | } else { |
| 6750 | return null; |
| 6751 | } |
| 6752 | } |
| 6753 | |
| 6754 | /** |
| 6755 | * @hide |
| 6756 | */ |
| 6757 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6758 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6759 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 6760 | ? mBuilder.mN.headsUpContentView |
| 6761 | : mBuilder.mN.contentView; |
| 6762 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 6763 | } |
| 6764 | |
| 6765 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 6766 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6767 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6768 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 6769 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6770 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6771 | remoteViews.removeAllViews(id); |
| 6772 | remoteViews.addView(id, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6773 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6774 | return remoteViews; |
| 6775 | } |
| 6776 | } |
| 6777 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6778 | // When adding a new Style subclass here, don't forget to update |
| 6779 | // Builder.getNotificationStyleClass. |
| 6780 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6781 | /** |
| 6782 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 6783 | * metadata or change options on a notification builder. |
| 6784 | */ |
| 6785 | public interface Extender { |
| 6786 | /** |
| 6787 | * Apply this extender to a notification builder. |
| 6788 | * @param builder the builder to be modified. |
| 6789 | * @return the build object for chaining. |
| 6790 | */ |
| 6791 | public Builder extend(Builder builder); |
| 6792 | } |
| 6793 | |
| 6794 | /** |
| 6795 | * Helper class to add wearable extensions to notifications. |
| 6796 | * <p class="note"> See |
| 6797 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 6798 | * for Android Wear</a> for more information on how to use this class. |
| 6799 | * <p> |
| 6800 | * To create a notification with wearable extensions: |
| 6801 | * <ol> |
| 6802 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 6803 | * properties. |
| 6804 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 6805 | * <li>Set wearable-specific properties using the |
| 6806 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 6807 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 6808 | * notification. |
| 6809 | * <li>Post the notification to the notification system with the |
| 6810 | * {@code NotificationManager.notify(...)} methods. |
| 6811 | * </ol> |
| 6812 | * |
| 6813 | * <pre class="prettyprint"> |
| 6814 | * Notification notif = new Notification.Builder(mContext) |
| 6815 | * .setContentTitle("New mail from " + sender.toString()) |
| 6816 | * .setContentText(subject) |
| 6817 | * .setSmallIcon(R.drawable.new_mail) |
| 6818 | * .extend(new Notification.WearableExtender() |
| 6819 | * .setContentIcon(R.drawable.new_mail)) |
| 6820 | * .build(); |
| 6821 | * NotificationManager notificationManger = |
| 6822 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 6823 | * notificationManger.notify(0, notif);</pre> |
| 6824 | * |
| 6825 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 6826 | * {@code WearableExtender(Notification)} constructor, |
| 6827 | * and then using the {@code get} methods to access values. |
| 6828 | * |
| 6829 | * <pre class="prettyprint"> |
| 6830 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 6831 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 6832 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6833 | */ |
| 6834 | public static final class WearableExtender implements Extender { |
| 6835 | /** |
| 6836 | * Sentinel value for an action index that is unset. |
| 6837 | */ |
| 6838 | public static final int UNSET_ACTION_INDEX = -1; |
| 6839 | |
| 6840 | /** |
| 6841 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 6842 | * default sizing. |
| 6843 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 6844 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6845 | * on their content. |
| 6846 | */ |
| 6847 | public static final int SIZE_DEFAULT = 0; |
| 6848 | |
| 6849 | /** |
| 6850 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 6851 | * with an extra small size. |
| 6852 | * <p>This value is only applicable for custom display notifications created using |
| 6853 | * {@link #setDisplayIntent}. |
| 6854 | */ |
| 6855 | public static final int SIZE_XSMALL = 1; |
| 6856 | |
| 6857 | /** |
| 6858 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 6859 | * with a small size. |
| 6860 | * <p>This value is only applicable for custom display notifications created using |
| 6861 | * {@link #setDisplayIntent}. |
| 6862 | */ |
| 6863 | public static final int SIZE_SMALL = 2; |
| 6864 | |
| 6865 | /** |
| 6866 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 6867 | * with a medium size. |
| 6868 | * <p>This value is only applicable for custom display notifications created using |
| 6869 | * {@link #setDisplayIntent}. |
| 6870 | */ |
| 6871 | public static final int SIZE_MEDIUM = 3; |
| 6872 | |
| 6873 | /** |
| 6874 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 6875 | * with a large size. |
| 6876 | * <p>This value is only applicable for custom display notifications created using |
| 6877 | * {@link #setDisplayIntent}. |
| 6878 | */ |
| 6879 | public static final int SIZE_LARGE = 4; |
| 6880 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 6881 | /** |
| 6882 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 6883 | * full screen. |
| 6884 | * <p>This value is only applicable for custom display notifications created using |
| 6885 | * {@link #setDisplayIntent}. |
| 6886 | */ |
| 6887 | public static final int SIZE_FULL_SCREEN = 5; |
| 6888 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6889 | /** |
| 6890 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 6891 | * short amount of time when this notification is displayed on the screen. This |
| 6892 | * is the default value. |
| 6893 | */ |
| 6894 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 6895 | |
| 6896 | /** |
| 6897 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 6898 | * for a longer amount of time when this notification is displayed on the screen. |
| 6899 | */ |
| 6900 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 6901 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6902 | /** Notification extra which contains wearable extensions */ |
| 6903 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 6904 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 6905 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6906 | private static final String KEY_ACTIONS = "actions"; |
| 6907 | private static final String KEY_FLAGS = "flags"; |
| 6908 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 6909 | private static final String KEY_PAGES = "pages"; |
| 6910 | private static final String KEY_BACKGROUND = "background"; |
| 6911 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 6912 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 6913 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 6914 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 6915 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 6916 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6917 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 6918 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 6919 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6920 | |
| 6921 | // Flags bitwise-ored to mFlags |
| 6922 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 6923 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 6924 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 6925 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6926 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 6927 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 6928 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6929 | |
| 6930 | // Default value for flags integer |
| 6931 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 6932 | |
| 6933 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 6934 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 6935 | |
| 6936 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 6937 | private int mFlags = DEFAULT_FLAGS; |
| 6938 | private PendingIntent mDisplayIntent; |
| 6939 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 6940 | private Bitmap mBackground; |
| 6941 | private int mContentIcon; |
| 6942 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 6943 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 6944 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 6945 | private int mCustomContentHeight; |
| 6946 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6947 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 6948 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 6949 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6950 | |
| 6951 | /** |
| 6952 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 6953 | * options. |
| 6954 | */ |
| 6955 | public WearableExtender() { |
| 6956 | } |
| 6957 | |
| 6958 | public WearableExtender(Notification notif) { |
| 6959 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 6960 | if (wearableBundle != null) { |
| 6961 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 6962 | if (actions != null) { |
| 6963 | mActions.addAll(actions); |
| 6964 | } |
| 6965 | |
| 6966 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 6967 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 6968 | |
| 6969 | Notification[] pages = getNotificationArrayFromBundle( |
| 6970 | wearableBundle, KEY_PAGES); |
| 6971 | if (pages != null) { |
| 6972 | Collections.addAll(mPages, pages); |
| 6973 | } |
| 6974 | |
| 6975 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 6976 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 6977 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 6978 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 6979 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 6980 | UNSET_ACTION_INDEX); |
| 6981 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 6982 | SIZE_DEFAULT); |
| 6983 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 6984 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 6985 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 6986 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 6987 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6988 | } |
| 6989 | } |
| 6990 | |
| 6991 | /** |
| 6992 | * Apply wearable extensions to a notification that is being built. This is typically |
| 6993 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 6994 | * {@link android.app.Notification.Builder}. |
| 6995 | */ |
| 6996 | @Override |
| 6997 | public Notification.Builder extend(Notification.Builder builder) { |
| 6998 | Bundle wearableBundle = new Bundle(); |
| 6999 | |
| 7000 | if (!mActions.isEmpty()) { |
| 7001 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 7002 | } |
| 7003 | if (mFlags != DEFAULT_FLAGS) { |
| 7004 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 7005 | } |
| 7006 | if (mDisplayIntent != null) { |
| 7007 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 7008 | } |
| 7009 | if (!mPages.isEmpty()) { |
| 7010 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 7011 | new Notification[mPages.size()])); |
| 7012 | } |
| 7013 | if (mBackground != null) { |
| 7014 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 7015 | } |
| 7016 | if (mContentIcon != 0) { |
| 7017 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 7018 | } |
| 7019 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 7020 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 7021 | } |
| 7022 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 7023 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 7024 | mContentActionIndex); |
| 7025 | } |
| 7026 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 7027 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 7028 | } |
| 7029 | if (mCustomContentHeight != 0) { |
| 7030 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 7031 | } |
| 7032 | if (mGravity != DEFAULT_GRAVITY) { |
| 7033 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 7034 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7035 | if (mHintScreenTimeout != 0) { |
| 7036 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 7037 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7038 | if (mDismissalId != null) { |
| 7039 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 7040 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7041 | if (mBridgeTag != null) { |
| 7042 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 7043 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7044 | |
| 7045 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 7046 | return builder; |
| 7047 | } |
| 7048 | |
| 7049 | @Override |
| 7050 | public WearableExtender clone() { |
| 7051 | WearableExtender that = new WearableExtender(); |
| 7052 | that.mActions = new ArrayList<Action>(this.mActions); |
| 7053 | that.mFlags = this.mFlags; |
| 7054 | that.mDisplayIntent = this.mDisplayIntent; |
| 7055 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 7056 | that.mBackground = this.mBackground; |
| 7057 | that.mContentIcon = this.mContentIcon; |
| 7058 | that.mContentIconGravity = this.mContentIconGravity; |
| 7059 | that.mContentActionIndex = this.mContentActionIndex; |
| 7060 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 7061 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 7062 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7063 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7064 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7065 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7066 | return that; |
| 7067 | } |
| 7068 | |
| 7069 | /** |
| 7070 | * Add a wearable action to this notification. |
| 7071 | * |
| 7072 | * <p>When wearable actions are added using this method, the set of actions that |
| 7073 | * show on a wearable device splits from devices that only show actions added |
| 7074 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 7075 | * of which actions display on different devices. |
| 7076 | * |
| 7077 | * @param action the action to add to this notification |
| 7078 | * @return this object for method chaining |
| 7079 | * @see android.app.Notification.Action |
| 7080 | */ |
| 7081 | public WearableExtender addAction(Action action) { |
| 7082 | mActions.add(action); |
| 7083 | return this; |
| 7084 | } |
| 7085 | |
| 7086 | /** |
| 7087 | * Adds wearable actions to this notification. |
| 7088 | * |
| 7089 | * <p>When wearable actions are added using this method, the set of actions that |
| 7090 | * show on a wearable device splits from devices that only show actions added |
| 7091 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 7092 | * of which actions display on different devices. |
| 7093 | * |
| 7094 | * @param actions the actions to add to this notification |
| 7095 | * @return this object for method chaining |
| 7096 | * @see android.app.Notification.Action |
| 7097 | */ |
| 7098 | public WearableExtender addActions(List<Action> actions) { |
| 7099 | mActions.addAll(actions); |
| 7100 | return this; |
| 7101 | } |
| 7102 | |
| 7103 | /** |
| 7104 | * Clear all wearable actions present on this builder. |
| 7105 | * @return this object for method chaining. |
| 7106 | * @see #addAction |
| 7107 | */ |
| 7108 | public WearableExtender clearActions() { |
| 7109 | mActions.clear(); |
| 7110 | return this; |
| 7111 | } |
| 7112 | |
| 7113 | /** |
| 7114 | * Get the wearable actions present on this notification. |
| 7115 | */ |
| 7116 | public List<Action> getActions() { |
| 7117 | return mActions; |
| 7118 | } |
| 7119 | |
| 7120 | /** |
| 7121 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 7122 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 7123 | * |
| 7124 | * <pre class="prettyprint"> |
| 7125 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 7126 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 7127 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 7128 | * Notification notif = new Notification.Builder(context) |
| 7129 | * .extend(new Notification.WearableExtender() |
| 7130 | * .setDisplayIntent(displayPendingIntent) |
| 7131 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 7132 | * .build();</pre> |
| 7133 | * |
| 7134 | * <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] | 7135 | * should have an empty task affinity. It is also recommended to use the device |
| 7136 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 7137 | * |
| 7138 | * <p>Example AndroidManifest.xml entry: |
| 7139 | * <pre class="prettyprint"> |
| 7140 | * <activity android:name="com.example.MyDisplayActivity" |
| 7141 | * android:exported="true" |
| 7142 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 7143 | * android:taskAffinity="" |
| 7144 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7145 | * |
| 7146 | * @param intent the {@link PendingIntent} for an activity |
| 7147 | * @return this object for method chaining |
| 7148 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 7149 | */ |
| 7150 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 7151 | mDisplayIntent = intent; |
| 7152 | return this; |
| 7153 | } |
| 7154 | |
| 7155 | /** |
| 7156 | * Get the intent to launch inside of an activity view when displaying this |
| 7157 | * notification. This {@code PendingIntent} should be for an activity. |
| 7158 | */ |
| 7159 | public PendingIntent getDisplayIntent() { |
| 7160 | return mDisplayIntent; |
| 7161 | } |
| 7162 | |
| 7163 | /** |
| 7164 | * Add an additional page of content to display with this notification. The current |
| 7165 | * notification forms the first page, and pages added using this function form |
| 7166 | * subsequent pages. This field can be used to separate a notification into multiple |
| 7167 | * sections. |
| 7168 | * |
| 7169 | * @param page the notification to add as another page |
| 7170 | * @return this object for method chaining |
| 7171 | * @see android.app.Notification.WearableExtender#getPages |
| 7172 | */ |
| 7173 | public WearableExtender addPage(Notification page) { |
| 7174 | mPages.add(page); |
| 7175 | return this; |
| 7176 | } |
| 7177 | |
| 7178 | /** |
| 7179 | * Add additional pages of content to display with this notification. The current |
| 7180 | * notification forms the first page, and pages added using this function form |
| 7181 | * subsequent pages. This field can be used to separate a notification into multiple |
| 7182 | * sections. |
| 7183 | * |
| 7184 | * @param pages a list of notifications |
| 7185 | * @return this object for method chaining |
| 7186 | * @see android.app.Notification.WearableExtender#getPages |
| 7187 | */ |
| 7188 | public WearableExtender addPages(List<Notification> pages) { |
| 7189 | mPages.addAll(pages); |
| 7190 | return this; |
| 7191 | } |
| 7192 | |
| 7193 | /** |
| 7194 | * Clear all additional pages present on this builder. |
| 7195 | * @return this object for method chaining. |
| 7196 | * @see #addPage |
| 7197 | */ |
| 7198 | public WearableExtender clearPages() { |
| 7199 | mPages.clear(); |
| 7200 | return this; |
| 7201 | } |
| 7202 | |
| 7203 | /** |
| 7204 | * Get the array of additional pages of content for displaying this notification. The |
| 7205 | * current notification forms the first page, and elements within this array form |
| 7206 | * subsequent pages. This field can be used to separate a notification into multiple |
| 7207 | * sections. |
| 7208 | * @return the pages for this notification |
| 7209 | */ |
| 7210 | public List<Notification> getPages() { |
| 7211 | return mPages; |
| 7212 | } |
| 7213 | |
| 7214 | /** |
| 7215 | * Set a background image to be displayed behind the notification content. |
| 7216 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 7217 | * will work with any notification style. |
| 7218 | * |
| 7219 | * @param background the background bitmap |
| 7220 | * @return this object for method chaining |
| 7221 | * @see android.app.Notification.WearableExtender#getBackground |
| 7222 | */ |
| 7223 | public WearableExtender setBackground(Bitmap background) { |
| 7224 | mBackground = background; |
| 7225 | return this; |
| 7226 | } |
| 7227 | |
| 7228 | /** |
| 7229 | * Get a background image to be displayed behind the notification content. |
| 7230 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 7231 | * will work with any notification style. |
| 7232 | * |
| 7233 | * @return the background image |
| 7234 | * @see android.app.Notification.WearableExtender#setBackground |
| 7235 | */ |
| 7236 | public Bitmap getBackground() { |
| 7237 | return mBackground; |
| 7238 | } |
| 7239 | |
| 7240 | /** |
| 7241 | * Set an icon that goes with the content of this notification. |
| 7242 | */ |
| 7243 | public WearableExtender setContentIcon(int icon) { |
| 7244 | mContentIcon = icon; |
| 7245 | return this; |
| 7246 | } |
| 7247 | |
| 7248 | /** |
| 7249 | * Get an icon that goes with the content of this notification. |
| 7250 | */ |
| 7251 | public int getContentIcon() { |
| 7252 | return mContentIcon; |
| 7253 | } |
| 7254 | |
| 7255 | /** |
| 7256 | * Set the gravity that the content icon should have within the notification display. |
| 7257 | * Supported values include {@link android.view.Gravity#START} and |
| 7258 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 7259 | * @see #setContentIcon |
| 7260 | */ |
| 7261 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 7262 | mContentIconGravity = contentIconGravity; |
| 7263 | return this; |
| 7264 | } |
| 7265 | |
| 7266 | /** |
| 7267 | * Get the gravity that the content icon should have within the notification display. |
| 7268 | * Supported values include {@link android.view.Gravity#START} and |
| 7269 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 7270 | * @see #getContentIcon |
| 7271 | */ |
| 7272 | public int getContentIconGravity() { |
| 7273 | return mContentIconGravity; |
| 7274 | } |
| 7275 | |
| 7276 | /** |
| 7277 | * 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] | 7278 | * this notification. This action will no longer display separately from the |
| 7279 | * notification's content. |
| 7280 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 7281 | * <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] | 7282 | * set, although the list of available actions comes from the main notification and not |
| 7283 | * from the child page's notification. |
| 7284 | * |
| 7285 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 7286 | * If wearable actions were added to the main notification, this index |
| 7287 | * will apply to that list, otherwise it will apply to the regular |
| 7288 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7289 | */ |
| 7290 | public WearableExtender setContentAction(int actionIndex) { |
| 7291 | mContentActionIndex = actionIndex; |
| 7292 | return this; |
| 7293 | } |
| 7294 | |
| 7295 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 7296 | * Get the index of the notification action, if any, that was specified as being clickable |
| 7297 | * 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] | 7298 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7299 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 7300 | * <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] | 7301 | * set, although the list of available actions comes from the main notification and not |
| 7302 | * from the child page's notification. |
| 7303 | * |
| 7304 | * <p>If wearable specific actions were added to the main notification, this index will |
| 7305 | * 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] | 7306 | * |
| 7307 | * @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] | 7308 | */ |
| 7309 | public int getContentAction() { |
| 7310 | return mContentActionIndex; |
| 7311 | } |
| 7312 | |
| 7313 | /** |
| 7314 | * Set the gravity that this notification should have within the available viewport space. |
| 7315 | * Supported values include {@link android.view.Gravity#TOP}, |
| 7316 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 7317 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 7318 | */ |
| 7319 | public WearableExtender setGravity(int gravity) { |
| 7320 | mGravity = gravity; |
| 7321 | return this; |
| 7322 | } |
| 7323 | |
| 7324 | /** |
| 7325 | * Get the gravity that this notification should have within the available viewport space. |
| 7326 | * Supported values include {@link android.view.Gravity#TOP}, |
| 7327 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 7328 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 7329 | */ |
| 7330 | public int getGravity() { |
| 7331 | return mGravity; |
| 7332 | } |
| 7333 | |
| 7334 | /** |
| 7335 | * Set the custom size preset for the display of this notification out of the available |
| 7336 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 7337 | * {@link #SIZE_LARGE}. |
| 7338 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 7339 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 7340 | * documentation for the preset in question. See also |
| 7341 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 7342 | */ |
| 7343 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 7344 | mCustomSizePreset = sizePreset; |
| 7345 | return this; |
| 7346 | } |
| 7347 | |
| 7348 | /** |
| 7349 | * Get the custom size preset for the display of this notification out of the available |
| 7350 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 7351 | * {@link #SIZE_LARGE}. |
| 7352 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 7353 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 7354 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 7355 | */ |
| 7356 | public int getCustomSizePreset() { |
| 7357 | return mCustomSizePreset; |
| 7358 | } |
| 7359 | |
| 7360 | /** |
| 7361 | * Set the custom height in pixels for the display of this notification's content. |
| 7362 | * <p>This option is only available for custom display notifications created |
| 7363 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 7364 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 7365 | * {@link #getCustomContentHeight}. |
| 7366 | */ |
| 7367 | public WearableExtender setCustomContentHeight(int height) { |
| 7368 | mCustomContentHeight = height; |
| 7369 | return this; |
| 7370 | } |
| 7371 | |
| 7372 | /** |
| 7373 | * Get the custom height in pixels for the display of this notification's content. |
| 7374 | * <p>This option is only available for custom display notifications created |
| 7375 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 7376 | * {@link #setCustomContentHeight}. |
| 7377 | */ |
| 7378 | public int getCustomContentHeight() { |
| 7379 | return mCustomContentHeight; |
| 7380 | } |
| 7381 | |
| 7382 | /** |
| 7383 | * Set whether the scrolling position for the contents of this notification should start |
| 7384 | * at the bottom of the contents instead of the top when the contents are too long to |
| 7385 | * display within the screen. Default is false (start scroll at the top). |
| 7386 | */ |
| 7387 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 7388 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 7389 | return this; |
| 7390 | } |
| 7391 | |
| 7392 | /** |
| 7393 | * Get whether the scrolling position for the contents of this notification should start |
| 7394 | * at the bottom of the contents instead of the top when the contents are too long to |
| 7395 | * display within the screen. Default is false (start scroll at the top). |
| 7396 | */ |
| 7397 | public boolean getStartScrollBottom() { |
| 7398 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 7399 | } |
| 7400 | |
| 7401 | /** |
| 7402 | * Set whether the content intent is available when the wearable device is not connected |
| 7403 | * to a companion device. The user can still trigger this intent when the wearable device |
| 7404 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 7405 | * Defaults to true. |
| 7406 | */ |
| 7407 | public WearableExtender setContentIntentAvailableOffline( |
| 7408 | boolean contentIntentAvailableOffline) { |
| 7409 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 7410 | return this; |
| 7411 | } |
| 7412 | |
| 7413 | /** |
| 7414 | * Get whether the content intent is available when the wearable device is not connected |
| 7415 | * to a companion device. The user can still trigger this intent when the wearable device |
| 7416 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 7417 | * Defaults to true. |
| 7418 | */ |
| 7419 | public boolean getContentIntentAvailableOffline() { |
| 7420 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 7421 | } |
| 7422 | |
| 7423 | /** |
| 7424 | * Set a hint that this notification's icon should not be displayed. |
| 7425 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 7426 | * @return this object for method chaining |
| 7427 | */ |
| 7428 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 7429 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 7430 | return this; |
| 7431 | } |
| 7432 | |
| 7433 | /** |
| 7434 | * Get a hint that this notification's icon should not be displayed. |
| 7435 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 7436 | * The default value is {@code false} if this was never set. |
| 7437 | */ |
| 7438 | public boolean getHintHideIcon() { |
| 7439 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 7440 | } |
| 7441 | |
| 7442 | /** |
| 7443 | * Set a visual hint that only the background image of this notification should be |
| 7444 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 7445 | * to sub-pages added using {@link #addPage}. |
| 7446 | */ |
| 7447 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 7448 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 7449 | return this; |
| 7450 | } |
| 7451 | |
| 7452 | /** |
| 7453 | * Get a visual hint that only the background image of this notification should be |
| 7454 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 7455 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 7456 | */ |
| 7457 | public boolean getHintShowBackgroundOnly() { |
| 7458 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 7459 | } |
| 7460 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7461 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 7462 | * Set a hint that this notification's background should not be clipped if possible, |
| 7463 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 7464 | * 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] | 7465 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 7466 | * @return this object for method chaining |
| 7467 | */ |
| 7468 | public WearableExtender setHintAvoidBackgroundClipping( |
| 7469 | boolean hintAvoidBackgroundClipping) { |
| 7470 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 7471 | return this; |
| 7472 | } |
| 7473 | |
| 7474 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 7475 | * Get a hint that this notification's background should not be clipped if possible, |
| 7476 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 7477 | * 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] | 7478 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 7479 | * otherwise. The default value is {@code false} if this was never set. |
| 7480 | */ |
| 7481 | public boolean getHintAvoidBackgroundClipping() { |
| 7482 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 7483 | } |
| 7484 | |
| 7485 | /** |
| 7486 | * Set a hint that the screen should remain on for at least this duration when |
| 7487 | * this notification is displayed on the screen. |
| 7488 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 7489 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 7490 | * @return this object for method chaining |
| 7491 | */ |
| 7492 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 7493 | mHintScreenTimeout = timeout; |
| 7494 | return this; |
| 7495 | } |
| 7496 | |
| 7497 | /** |
| 7498 | * Get the duration, in milliseconds, that the screen should remain on for |
| 7499 | * when this notification is displayed. |
| 7500 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 7501 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 7502 | */ |
| 7503 | public int getHintScreenTimeout() { |
| 7504 | return mHintScreenTimeout; |
| 7505 | } |
| 7506 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 7507 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 7508 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 7509 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 7510 | * qr codes, as well as other simple black-and-white tickets. |
| 7511 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 7512 | * @return this object for method chaining |
| 7513 | */ |
| 7514 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 7515 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 7516 | return this; |
| 7517 | } |
| 7518 | |
| 7519 | /** |
| 7520 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 7521 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 7522 | * qr codes, as well as other simple black-and-white tickets. |
| 7523 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 7524 | * otherwise. The default value is {@code false} if this was never set. |
| 7525 | */ |
| 7526 | public boolean getHintAmbientBigPicture() { |
| 7527 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 7528 | } |
| 7529 | |
| 7530 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 7531 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 7532 | * directly, telling the platform that it can generate the appropriate transitions. |
| 7533 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 7534 | * an activity and transitions should be generated, false otherwise. |
| 7535 | * @return this object for method chaining |
| 7536 | */ |
| 7537 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 7538 | boolean hintContentIntentLaunchesActivity) { |
| 7539 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 7540 | return this; |
| 7541 | } |
| 7542 | |
| 7543 | /** |
| 7544 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 7545 | * directly, telling the platform that it can generate the appropriate transitions |
| 7546 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 7547 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 7548 | */ |
| 7549 | public boolean getHintContentIntentLaunchesActivity() { |
| 7550 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 7551 | } |
| 7552 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7553 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7554 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 7555 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 7556 | * 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] | 7557 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7558 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7559 | * @param dismissalId the dismissal id of the notification. |
| 7560 | * @return this object for method chaining |
| 7561 | */ |
| 7562 | public WearableExtender setDismissalId(String dismissalId) { |
| 7563 | mDismissalId = dismissalId; |
| 7564 | return this; |
| 7565 | } |
| 7566 | |
| 7567 | /** |
| 7568 | * Returns the dismissal id of the notification. |
| 7569 | * @return the dismissal id of the notification or null if it has not been set. |
| 7570 | */ |
| 7571 | public String getDismissalId() { |
| 7572 | return mDismissalId; |
| 7573 | } |
| 7574 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7575 | /** |
| 7576 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 7577 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 7578 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 7579 | * Features to Notifications</a> for more information. |
| 7580 | * @param bridgeTag the bridge tag of the notification. |
| 7581 | * @return this object for method chaining |
| 7582 | */ |
| 7583 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 7584 | mBridgeTag = bridgeTag; |
| 7585 | return this; |
| 7586 | } |
| 7587 | |
| 7588 | /** |
| 7589 | * Returns the bridge tag of the notification. |
| 7590 | * @return the bridge tag or null if not present. |
| 7591 | */ |
| 7592 | public String getBridgeTag() { |
| 7593 | return mBridgeTag; |
| 7594 | } |
| 7595 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7596 | private void setFlag(int mask, boolean value) { |
| 7597 | if (value) { |
| 7598 | mFlags |= mask; |
| 7599 | } else { |
| 7600 | mFlags &= ~mask; |
| 7601 | } |
| 7602 | } |
| 7603 | } |
| 7604 | |
| 7605 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7606 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 7607 | * with car extensions: |
| 7608 | * |
| 7609 | * <ol> |
| 7610 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 7611 | * properties. |
| 7612 | * <li>Create a {@link CarExtender}. |
| 7613 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 7614 | * {@link CarExtender}. |
| 7615 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 7616 | * to apply the extensions to a notification. |
| 7617 | * </ol> |
| 7618 | * |
| 7619 | * <pre class="prettyprint"> |
| 7620 | * Notification notification = new Notification.Builder(context) |
| 7621 | * ... |
| 7622 | * .extend(new CarExtender() |
| 7623 | * .set*(...)) |
| 7624 | * .build(); |
| 7625 | * </pre> |
| 7626 | * |
| 7627 | * <p>Car extensions can be accessed on an existing notification by using the |
| 7628 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 7629 | * to access values. |
| 7630 | */ |
| 7631 | public static final class CarExtender implements Extender { |
| 7632 | private static final String TAG = "CarExtender"; |
| 7633 | |
| 7634 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 7635 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 7636 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 7637 | private static final String EXTRA_COLOR = "app_color"; |
| 7638 | |
| 7639 | private Bitmap mLargeIcon; |
| 7640 | private UnreadConversation mUnreadConversation; |
| 7641 | private int mColor = Notification.COLOR_DEFAULT; |
| 7642 | |
| 7643 | /** |
| 7644 | * Create a {@link CarExtender} with default options. |
| 7645 | */ |
| 7646 | public CarExtender() { |
| 7647 | } |
| 7648 | |
| 7649 | /** |
| 7650 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 7651 | * |
| 7652 | * @param notif The notification from which to copy options. |
| 7653 | */ |
| 7654 | public CarExtender(Notification notif) { |
| 7655 | Bundle carBundle = notif.extras == null ? |
| 7656 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 7657 | if (carBundle != null) { |
| 7658 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 7659 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 7660 | |
| 7661 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 7662 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 7663 | } |
| 7664 | } |
| 7665 | |
| 7666 | /** |
| 7667 | * Apply car extensions to a notification that is being built. This is typically called by |
| 7668 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 7669 | * method of {@link Notification.Builder}. |
| 7670 | */ |
| 7671 | @Override |
| 7672 | public Notification.Builder extend(Notification.Builder builder) { |
| 7673 | Bundle carExtensions = new Bundle(); |
| 7674 | |
| 7675 | if (mLargeIcon != null) { |
| 7676 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 7677 | } |
| 7678 | if (mColor != Notification.COLOR_DEFAULT) { |
| 7679 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 7680 | } |
| 7681 | |
| 7682 | if (mUnreadConversation != null) { |
| 7683 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 7684 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 7685 | } |
| 7686 | |
| 7687 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 7688 | return builder; |
| 7689 | } |
| 7690 | |
| 7691 | /** |
| 7692 | * Sets the accent color to use when Android Auto presents the notification. |
| 7693 | * |
| 7694 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 7695 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 7696 | * automotive setting. This method can be used to override the color provided in the |
| 7697 | * notification in such a situation. |
| 7698 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 7699 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7700 | mColor = color; |
| 7701 | return this; |
| 7702 | } |
| 7703 | |
| 7704 | /** |
| 7705 | * Gets the accent color. |
| 7706 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7707 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7708 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 7709 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7710 | public int getColor() { |
| 7711 | return mColor; |
| 7712 | } |
| 7713 | |
| 7714 | /** |
| 7715 | * Sets the large icon of the car notification. |
| 7716 | * |
| 7717 | * If no large icon is set in the extender, Android Auto will display the icon |
| 7718 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 7719 | * |
| 7720 | * @param largeIcon The large icon to use in the car notification. |
| 7721 | * @return This object for method chaining. |
| 7722 | */ |
| 7723 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 7724 | mLargeIcon = largeIcon; |
| 7725 | return this; |
| 7726 | } |
| 7727 | |
| 7728 | /** |
| 7729 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 7730 | * |
| 7731 | * @return The large icon for the car notification. |
| 7732 | * @see CarExtender#setLargeIcon |
| 7733 | */ |
| 7734 | public Bitmap getLargeIcon() { |
| 7735 | return mLargeIcon; |
| 7736 | } |
| 7737 | |
| 7738 | /** |
| 7739 | * Sets the unread conversation in a message notification. |
| 7740 | * |
| 7741 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 7742 | * @return This object for method chaining. |
| 7743 | */ |
| 7744 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 7745 | mUnreadConversation = unreadConversation; |
| 7746 | return this; |
| 7747 | } |
| 7748 | |
| 7749 | /** |
| 7750 | * Returns the unread conversation conveyed by this notification. |
| 7751 | * @see #setUnreadConversation(UnreadConversation) |
| 7752 | */ |
| 7753 | public UnreadConversation getUnreadConversation() { |
| 7754 | return mUnreadConversation; |
| 7755 | } |
| 7756 | |
| 7757 | /** |
| 7758 | * A class which holds the unread messages from a conversation. |
| 7759 | */ |
| 7760 | public static class UnreadConversation { |
| 7761 | private static final String KEY_AUTHOR = "author"; |
| 7762 | private static final String KEY_TEXT = "text"; |
| 7763 | private static final String KEY_MESSAGES = "messages"; |
| 7764 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 7765 | private static final String KEY_ON_REPLY = "on_reply"; |
| 7766 | private static final String KEY_ON_READ = "on_read"; |
| 7767 | private static final String KEY_PARTICIPANTS = "participants"; |
| 7768 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 7769 | |
| 7770 | private final String[] mMessages; |
| 7771 | private final RemoteInput mRemoteInput; |
| 7772 | private final PendingIntent mReplyPendingIntent; |
| 7773 | private final PendingIntent mReadPendingIntent; |
| 7774 | private final String[] mParticipants; |
| 7775 | private final long mLatestTimestamp; |
| 7776 | |
| 7777 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 7778 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 7779 | String[] participants, long latestTimestamp) { |
| 7780 | mMessages = messages; |
| 7781 | mRemoteInput = remoteInput; |
| 7782 | mReadPendingIntent = readPendingIntent; |
| 7783 | mReplyPendingIntent = replyPendingIntent; |
| 7784 | mParticipants = participants; |
| 7785 | mLatestTimestamp = latestTimestamp; |
| 7786 | } |
| 7787 | |
| 7788 | /** |
| 7789 | * Gets the list of messages conveyed by this notification. |
| 7790 | */ |
| 7791 | public String[] getMessages() { |
| 7792 | return mMessages; |
| 7793 | } |
| 7794 | |
| 7795 | /** |
| 7796 | * Gets the remote input that will be used to convey the response to a message list, or |
| 7797 | * null if no such remote input exists. |
| 7798 | */ |
| 7799 | public RemoteInput getRemoteInput() { |
| 7800 | return mRemoteInput; |
| 7801 | } |
| 7802 | |
| 7803 | /** |
| 7804 | * Gets the pending intent that will be triggered when the user replies to this |
| 7805 | * notification. |
| 7806 | */ |
| 7807 | public PendingIntent getReplyPendingIntent() { |
| 7808 | return mReplyPendingIntent; |
| 7809 | } |
| 7810 | |
| 7811 | /** |
| 7812 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 7813 | * in this object's message list. |
| 7814 | */ |
| 7815 | public PendingIntent getReadPendingIntent() { |
| 7816 | return mReadPendingIntent; |
| 7817 | } |
| 7818 | |
| 7819 | /** |
| 7820 | * Gets the participants in the conversation. |
| 7821 | */ |
| 7822 | public String[] getParticipants() { |
| 7823 | return mParticipants; |
| 7824 | } |
| 7825 | |
| 7826 | /** |
| 7827 | * Gets the firs participant in the conversation. |
| 7828 | */ |
| 7829 | public String getParticipant() { |
| 7830 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 7831 | } |
| 7832 | |
| 7833 | /** |
| 7834 | * Gets the timestamp of the conversation. |
| 7835 | */ |
| 7836 | public long getLatestTimestamp() { |
| 7837 | return mLatestTimestamp; |
| 7838 | } |
| 7839 | |
| 7840 | Bundle getBundleForUnreadConversation() { |
| 7841 | Bundle b = new Bundle(); |
| 7842 | String author = null; |
| 7843 | if (mParticipants != null && mParticipants.length > 1) { |
| 7844 | author = mParticipants[0]; |
| 7845 | } |
| 7846 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 7847 | for (int i = 0; i < messages.length; i++) { |
| 7848 | Bundle m = new Bundle(); |
| 7849 | m.putString(KEY_TEXT, mMessages[i]); |
| 7850 | m.putString(KEY_AUTHOR, author); |
| 7851 | messages[i] = m; |
| 7852 | } |
| 7853 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 7854 | if (mRemoteInput != null) { |
| 7855 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 7856 | } |
| 7857 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 7858 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 7859 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 7860 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 7861 | return b; |
| 7862 | } |
| 7863 | |
| 7864 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 7865 | if (b == null) { |
| 7866 | return null; |
| 7867 | } |
| 7868 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 7869 | String[] messages = null; |
| 7870 | if (parcelableMessages != null) { |
| 7871 | String[] tmp = new String[parcelableMessages.length]; |
| 7872 | boolean success = true; |
| 7873 | for (int i = 0; i < tmp.length; i++) { |
| 7874 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 7875 | success = false; |
| 7876 | break; |
| 7877 | } |
| 7878 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 7879 | if (tmp[i] == null) { |
| 7880 | success = false; |
| 7881 | break; |
| 7882 | } |
| 7883 | } |
| 7884 | if (success) { |
| 7885 | messages = tmp; |
| 7886 | } else { |
| 7887 | return null; |
| 7888 | } |
| 7889 | } |
| 7890 | |
| 7891 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 7892 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 7893 | |
| 7894 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 7895 | |
| 7896 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 7897 | if (participants == null || participants.length != 1) { |
| 7898 | return null; |
| 7899 | } |
| 7900 | |
| 7901 | return new UnreadConversation(messages, |
| 7902 | remoteInput, |
| 7903 | onReply, |
| 7904 | onRead, |
| 7905 | participants, b.getLong(KEY_TIMESTAMP)); |
| 7906 | } |
| 7907 | }; |
| 7908 | |
| 7909 | /** |
| 7910 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 7911 | */ |
| 7912 | public static class Builder { |
| 7913 | private final List<String> mMessages = new ArrayList<String>(); |
| 7914 | private final String mParticipant; |
| 7915 | private RemoteInput mRemoteInput; |
| 7916 | private PendingIntent mReadPendingIntent; |
| 7917 | private PendingIntent mReplyPendingIntent; |
| 7918 | private long mLatestTimestamp; |
| 7919 | |
| 7920 | /** |
| 7921 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 7922 | * |
| 7923 | * @param name The name of the other participant in the conversation. |
| 7924 | */ |
| 7925 | public Builder(String name) { |
| 7926 | mParticipant = name; |
| 7927 | } |
| 7928 | |
| 7929 | /** |
| 7930 | * Appends a new unread message to the list of messages for this conversation. |
| 7931 | * |
| 7932 | * The messages should be added from oldest to newest. |
| 7933 | * |
| 7934 | * @param message The text of the new unread message. |
| 7935 | * @return This object for method chaining. |
| 7936 | */ |
| 7937 | public Builder addMessage(String message) { |
| 7938 | mMessages.add(message); |
| 7939 | return this; |
| 7940 | } |
| 7941 | |
| 7942 | /** |
| 7943 | * Sets the pending intent and remote input which will convey the reply to this |
| 7944 | * notification. |
| 7945 | * |
| 7946 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 7947 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 7948 | * @return This object for method chaining. |
| 7949 | * |
| 7950 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 7951 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 7952 | */ |
| 7953 | public Builder setReplyAction( |
| 7954 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 7955 | mRemoteInput = remoteInput; |
| 7956 | mReplyPendingIntent = pendingIntent; |
| 7957 | |
| 7958 | return this; |
| 7959 | } |
| 7960 | |
| 7961 | /** |
| 7962 | * Sets the pending intent that will be sent once the messages in this notification |
| 7963 | * are read. |
| 7964 | * |
| 7965 | * @param pendingIntent The pending intent to use. |
| 7966 | * @return This object for method chaining. |
| 7967 | */ |
| 7968 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 7969 | mReadPendingIntent = pendingIntent; |
| 7970 | return this; |
| 7971 | } |
| 7972 | |
| 7973 | /** |
| 7974 | * Sets the timestamp of the most recent message in an unread conversation. |
| 7975 | * |
| 7976 | * If a messaging notification has been posted by your application and has not |
| 7977 | * yet been cancelled, posting a later notification with the same id and tag |
| 7978 | * but without a newer timestamp may result in Android Auto not displaying a |
| 7979 | * heads up notification for the later notification. |
| 7980 | * |
| 7981 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 7982 | * @return This object for method chaining. |
| 7983 | */ |
| 7984 | public Builder setLatestTimestamp(long timestamp) { |
| 7985 | mLatestTimestamp = timestamp; |
| 7986 | return this; |
| 7987 | } |
| 7988 | |
| 7989 | /** |
| 7990 | * Builds a new unread conversation object. |
| 7991 | * |
| 7992 | * @return The new unread conversation object. |
| 7993 | */ |
| 7994 | public UnreadConversation build() { |
| 7995 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 7996 | String[] participants = { mParticipant }; |
| 7997 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 7998 | mReadPendingIntent, participants, mLatestTimestamp); |
| 7999 | } |
| 8000 | } |
| 8001 | } |
| 8002 | |
| 8003 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8004 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 8005 | * with a TV extension: |
| 8006 | * |
| 8007 | * <ol> |
| 8008 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 8009 | * <li>Create a {@link TvExtender}. |
| 8010 | * <li>Set TV-specific properties using the {@code set} methods of |
| 8011 | * {@link TvExtender}. |
| 8012 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 8013 | * to apply the extension to a notification. |
| 8014 | * </ol> |
| 8015 | * |
| 8016 | * <pre class="prettyprint"> |
| 8017 | * Notification notification = new Notification.Builder(context) |
| 8018 | * ... |
| 8019 | * .extend(new TvExtender() |
| 8020 | * .set*(...)) |
| 8021 | * .build(); |
| 8022 | * </pre> |
| 8023 | * |
| 8024 | * <p>TV extensions can be accessed on an existing notification by using the |
| 8025 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 8026 | * to access values. |
| 8027 | * |
| 8028 | * @hide |
| 8029 | */ |
| 8030 | @SystemApi |
| 8031 | public static final class TvExtender implements Extender { |
| 8032 | private static final String TAG = "TvExtender"; |
| 8033 | |
| 8034 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 8035 | private static final String EXTRA_FLAGS = "flags"; |
| 8036 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 8037 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8038 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8039 | |
| 8040 | // Flags bitwise-ored to mFlags |
| 8041 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 8042 | |
| 8043 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8044 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8045 | private PendingIntent mContentIntent; |
| 8046 | private PendingIntent mDeleteIntent; |
| 8047 | |
| 8048 | /** |
| 8049 | * Create a {@link TvExtender} with default options. |
| 8050 | */ |
| 8051 | public TvExtender() { |
| 8052 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 8053 | } |
| 8054 | |
| 8055 | /** |
| 8056 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 8057 | * |
| 8058 | * @param notif The notification from which to copy options. |
| 8059 | */ |
| 8060 | public TvExtender(Notification notif) { |
| 8061 | Bundle bundle = notif.extras == null ? |
| 8062 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 8063 | if (bundle != null) { |
| 8064 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8065 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8066 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 8067 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 8068 | } |
| 8069 | } |
| 8070 | |
| 8071 | /** |
| 8072 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 8073 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 8074 | * method of {@link Notification.Builder}. |
| 8075 | */ |
| 8076 | @Override |
| 8077 | public Notification.Builder extend(Notification.Builder builder) { |
| 8078 | Bundle bundle = new Bundle(); |
| 8079 | |
| 8080 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8081 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8082 | if (mContentIntent != null) { |
| 8083 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 8084 | } |
| 8085 | |
| 8086 | if (mDeleteIntent != null) { |
| 8087 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 8088 | } |
| 8089 | |
| 8090 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 8091 | return builder; |
| 8092 | } |
| 8093 | |
| 8094 | /** |
| 8095 | * Returns true if this notification should be shown on TV. This method return true |
| 8096 | * if the notification was extended with a TvExtender. |
| 8097 | */ |
| 8098 | public boolean isAvailableOnTv() { |
| 8099 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 8100 | } |
| 8101 | |
| 8102 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8103 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 8104 | * It can be different from the channel that the notification is delivered to when |
| 8105 | * posting on a non-TV device. |
| 8106 | */ |
| 8107 | public TvExtender setChannel(String channelId) { |
| 8108 | mChannelId = channelId; |
| 8109 | return this; |
| 8110 | } |
| 8111 | |
| 8112 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 8113 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 8114 | * It can be different from the channel that the notification is delivered to when |
| 8115 | * posting on a non-TV device. |
| 8116 | */ |
| 8117 | public TvExtender setChannelId(String channelId) { |
| 8118 | mChannelId = channelId; |
| 8119 | return this; |
| 8120 | } |
| 8121 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 8122 | /** @removed */ |
| 8123 | @Deprecated |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8124 | public String getChannel() { |
| 8125 | return mChannelId; |
| 8126 | } |
| 8127 | |
| 8128 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 8129 | * Returns the id of the channel this notification posts to on TV. |
| 8130 | */ |
| 8131 | public String getChannelId() { |
| 8132 | return mChannelId; |
| 8133 | } |
| 8134 | |
| 8135 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8136 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 8137 | * If provided, it is used instead of the content intent specified |
| 8138 | * at the level of Notification. |
| 8139 | */ |
| 8140 | public TvExtender setContentIntent(PendingIntent intent) { |
| 8141 | mContentIntent = intent; |
| 8142 | return this; |
| 8143 | } |
| 8144 | |
| 8145 | /** |
| 8146 | * Returns the TV-specific content intent. If this method returns null, the |
| 8147 | * main content intent on the notification should be used. |
| 8148 | * |
| 8149 | * @see {@link Notification#contentIntent} |
| 8150 | */ |
| 8151 | public PendingIntent getContentIntent() { |
| 8152 | return mContentIntent; |
| 8153 | } |
| 8154 | |
| 8155 | /** |
| 8156 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 8157 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 8158 | * at the level of Notification. |
| 8159 | */ |
| 8160 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 8161 | mDeleteIntent = intent; |
| 8162 | return this; |
| 8163 | } |
| 8164 | |
| 8165 | /** |
| 8166 | * Returns the TV-specific delete intent. If this method returns null, the |
| 8167 | * main delete intent on the notification should be used. |
| 8168 | * |
| 8169 | * @see {@link Notification#deleteIntent} |
| 8170 | */ |
| 8171 | public PendingIntent getDeleteIntent() { |
| 8172 | return mDeleteIntent; |
| 8173 | } |
| 8174 | } |
| 8175 | |
| 8176 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8177 | * Get an array of Notification objects from a parcelable array bundle field. |
| 8178 | * Update the bundle to have a typed array so fetches in the future don't need |
| 8179 | * to do an array copy. |
| 8180 | */ |
| 8181 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 8182 | Parcelable[] array = bundle.getParcelableArray(key); |
| 8183 | if (array instanceof Notification[] || array == null) { |
| 8184 | return (Notification[]) array; |
| 8185 | } |
| 8186 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 8187 | Notification[].class); |
| 8188 | bundle.putParcelableArray(key, typedArray); |
| 8189 | return typedArray; |
| 8190 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8191 | |
| 8192 | private static class BuilderRemoteViews extends RemoteViews { |
| 8193 | public BuilderRemoteViews(Parcel parcel) { |
| 8194 | super(parcel); |
| 8195 | } |
| 8196 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 8197 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 8198 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8199 | } |
| 8200 | |
| 8201 | @Override |
| 8202 | public BuilderRemoteViews clone() { |
| 8203 | Parcel p = Parcel.obtain(); |
| 8204 | writeToParcel(p, 0); |
| 8205 | p.setDataPosition(0); |
| 8206 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 8207 | p.recycle(); |
| 8208 | return brv; |
| 8209 | } |
| 8210 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 8211 | |
| 8212 | private static class StandardTemplateParams { |
| 8213 | boolean hasProgress = true; |
| 8214 | boolean ambient = false; |
| 8215 | CharSequence title; |
| 8216 | CharSequence text; |
| 8217 | |
| 8218 | final StandardTemplateParams reset() { |
| 8219 | hasProgress = true; |
| 8220 | ambient = false; |
| 8221 | title = null; |
| 8222 | text = null; |
| 8223 | return this; |
| 8224 | } |
| 8225 | |
| 8226 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 8227 | this.hasProgress = hasProgress; |
| 8228 | return this; |
| 8229 | } |
| 8230 | |
| 8231 | final StandardTemplateParams title(CharSequence title) { |
| 8232 | this.title = title; |
| 8233 | return this; |
| 8234 | } |
| 8235 | |
| 8236 | final StandardTemplateParams text(CharSequence text) { |
| 8237 | this.text = text; |
| 8238 | return this; |
| 8239 | } |
| 8240 | |
| 8241 | final StandardTemplateParams ambient(boolean ambient) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 8242 | Preconditions.checkState(title == null && text == null, "must set ambient before text"); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 8243 | this.ambient = ambient; |
| 8244 | return this; |
| 8245 | } |
| 8246 | |
| 8247 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 8248 | Bundle extras = b.mN.extras; |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 8249 | title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE), ambient); |
| 8250 | text = b.processLegacyText(extras.getCharSequence(EXTRA_TEXT), ambient); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 8251 | return this; |
| 8252 | } |
| 8253 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8254 | } |