The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 19 | import static com.android.internal.util.NotificationColorUtil.satisfiesTextContrast; |
| 20 | |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 21 | import android.annotation.ColorInt; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 22 | import android.annotation.DrawableRes; |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 23 | import android.annotation.IntDef; |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 24 | import android.annotation.NonNull; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 25 | import android.annotation.RequiresPermission; |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 26 | import android.annotation.SdkConstant; |
| 27 | import android.annotation.SdkConstant.SdkConstantType; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 28 | import android.annotation.SystemApi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 31 | import android.content.pm.ApplicationInfo; |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 32 | import android.content.pm.PackageManager; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 33 | import android.content.pm.PackageManager.NameNotFoundException; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 34 | import android.content.pm.ShortcutInfo; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 35 | import android.content.res.ColorStateList; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 36 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 37 | import android.graphics.Canvas; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 38 | import android.graphics.Color; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 39 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 40 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 41 | import android.graphics.drawable.Icon; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 42 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 43 | import android.media.AudioManager; |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 44 | import android.media.PlayerBase; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 45 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 47 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 48 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 49 | import android.os.Bundle; |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 50 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.os.Parcel; |
| 52 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 53 | import android.os.SystemClock; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 54 | import android.os.SystemProperties; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 56 | import android.text.BidiFormatter; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 57 | import android.text.SpannableStringBuilder; |
| 58 | import android.text.Spanned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.text.TextUtils; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 60 | import android.text.style.AbsoluteSizeSpan; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 61 | import android.text.style.BackgroundColorSpan; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 62 | import android.text.style.CharacterStyle; |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 63 | import android.text.style.ForegroundColorSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 64 | import android.text.style.RelativeSizeSpan; |
| 65 | import android.text.style.TextAppearanceSpan; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 66 | import android.util.ArraySet; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 67 | import android.util.Log; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 68 | import android.util.SparseArray; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 69 | import android.view.Gravity; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 70 | import android.view.NotificationHeaderView; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 71 | import android.view.View; |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 72 | import android.view.ViewGroup; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 73 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.widget.RemoteViews; |
| 75 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 76 | import com.android.internal.R; |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 77 | import com.android.internal.annotations.VisibleForTesting; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 78 | import com.android.internal.util.ArrayUtils; |
Griff Hazen | c091ba8 | 2014-05-16 10:13:26 -0700 | [diff] [blame] | 79 | import com.android.internal.util.NotificationColorUtil; |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 80 | import com.android.internal.util.Preconditions; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 81 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 82 | import java.lang.annotation.Retention; |
| 83 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 84 | import java.lang.reflect.Constructor; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 85 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 86 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 87 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 88 | import java.util.List; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 89 | import java.util.Set; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 90 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | /** |
| 92 | * A class that represents how a persistent notification is to be presented to |
| 93 | * the user using the {@link android.app.NotificationManager}. |
| 94 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 95 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 96 | * easier to construct Notifications.</p> |
| 97 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 98 | * <div class="special reference"> |
| 99 | * <h3>Developer Guides</h3> |
| 100 | * <p>For a guide to creating notifications, read the |
| 101 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 102 | * developer guide.</p> |
| 103 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | */ |
| 105 | public class Notification implements Parcelable |
| 106 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 107 | private static final String TAG = "Notification"; |
| 108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 110 | * 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] | 111 | * containing application. |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 112 | */ |
| 113 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 114 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 115 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 116 | |
| 117 | /** |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 118 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 119 | * 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] | 120 | * what settings should be shown in the target app. |
Julia Reynolds | 2619b5e | 2017-02-09 09:58:15 -0500 | [diff] [blame] | 121 | */ |
| 122 | public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 123 | |
| 124 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 125 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 126 | * contain the tag provided to {@link NotificationManager#notify(String, int, Notification)} |
| 127 | * that can be used to narrow down what settings should be shown in the target app. |
| 128 | */ |
| 129 | public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 130 | |
| 131 | /** |
| 132 | * Optional extra for {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. If provided, will |
| 133 | * contain the id provided to {@link NotificationManager#notify(String, int, Notification)} |
| 134 | * that can be used to narrow down what settings should be shown in the target app. |
| 135 | */ |
| 136 | public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 137 | |
| 138 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | * Use all default values (where applicable). |
| 140 | */ |
| 141 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | /** |
| 144 | * Use the default notification sound. This will ignore any given |
| 145 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 146 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 147 | * <p> |
| 148 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 149 | * </p> |
| 150 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 152 | */ |
| 153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | public static final int DEFAULT_SOUND = 1; |
| 155 | |
| 156 | /** |
| 157 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 158 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 159 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 160 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 161 | * <p> |
| 162 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 163 | * </p> |
| 164 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 166 | */ |
| 167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | /** |
| 171 | * Use the default notification lights. This will ignore the |
| 172 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 173 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 174 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 176 | */ |
| 177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 181 | * Maximum length of CharSequences accepted by Builder and friends. |
| 182 | * |
| 183 | * <p> |
| 184 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 185 | */ |
| 186 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 187 | |
| 188 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 189 | * Maximum entries of reply text that are accepted by Builder and friends. |
| 190 | */ |
| 191 | private static final int MAX_REPLY_HISTORY = 5; |
| 192 | |
| 193 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 194 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 195 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 196 | * Default value: {@link System#currentTimeMillis() Now}. |
| 197 | * |
| 198 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 199 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 200 | * 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] | 201 | * timestamped according to when the activity began. |
| 202 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 203 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 204 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 205 | * <ul> |
| 206 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 207 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 208 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 209 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 210 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 211 | * <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] | 212 | * </ul> |
| 213 | * |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 214 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not shown |
| 215 | * anymore by default and must be opted into by using |
| 216 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | */ |
| 218 | public long when; |
| 219 | |
| 220 | /** |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 221 | * The creation time of the notification |
| 222 | */ |
| 223 | private long creationTime; |
| 224 | |
| 225 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | * 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] | 227 | * |
| 228 | * @deprecated Use {@link Builder#setSmallIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 230 | @Deprecated |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 231 | @DrawableRes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | public int icon; |
| 233 | |
| 234 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 235 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 236 | * leave it at its default value of 0. |
| 237 | * |
| 238 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 239 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 240 | */ |
| 241 | public int iconLevel; |
| 242 | |
| 243 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 244 | * The number of events that this notification represents. For example, in a new mail |
| 245 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 246 | * |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 247 | * 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] | 248 | * Starting with {@link android.os.Build.VERSION_CODES#O}, the number may be displayed as a |
| 249 | * badge icon in Launchers that support badging. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | */ |
Julia Reynolds | 3033198 | 2017-04-27 10:12:50 -0400 | [diff] [blame] | 251 | public int number = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | |
| 253 | /** |
| 254 | * The intent to execute when the expanded status entry is clicked. If |
| 255 | * this is an activity, it must include the |
| 256 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 257 | * that you take care of task management as described in the |
| 258 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
Dianne Hackborn | 6ceca58 | 2012-01-10 15:24:26 -0800 | [diff] [blame] | 259 | * Stack</a> document. In particular, make sure to read the notification section |
| 260 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 261 | * Notifications</a> for the correct ways to launch an application from a |
| 262 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | */ |
| 264 | public PendingIntent contentIntent; |
| 265 | |
| 266 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 267 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 268 | * the "Clear All" button or by swiping it away individually. |
| 269 | * |
| 270 | * This probably shouldn't be launching an activity since several of those will be sent |
| 271 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | */ |
| 273 | public PendingIntent deleteIntent; |
| 274 | |
| 275 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 276 | * An intent to launch instead of posting the notification to the status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 277 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 278 | * <p> |
| 279 | * The system UI may choose to display a heads-up notification, instead of |
| 280 | * launching this intent, while the user is using the device. |
| 281 | * </p> |
| 282 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 283 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 284 | */ |
| 285 | public PendingIntent fullScreenIntent; |
| 286 | |
| 287 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 288 | * Text that summarizes this notification for accessibility services. |
| 289 | * |
| 290 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 291 | * accessibility services (where it serves as an audible announcement of the notification's |
| 292 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 293 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 294 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | */ |
| 296 | public CharSequence tickerText; |
| 297 | |
| 298 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 299 | * Formerly, a view showing the {@link #tickerText}. |
| 300 | * |
| 301 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 302 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 303 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 304 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 305 | |
| 306 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 307 | * The view that will represent this notification in the notification list (which is pulled |
| 308 | * down from the status bar). |
| 309 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 310 | * As of N, this field may be null. The notification view is determined by the inputs |
| 311 | * to {@link Notification.Builder}; a custom RemoteViews can optionally be |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 312 | * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 314 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | public RemoteViews contentView; |
| 316 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 317 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 318 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 319 | * opportunity to show more detail. The system UI may choose to show this |
| 320 | * instead of the normal content view at its discretion. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 321 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 322 | * As of N, this field may be null. The expanded notification view is determined by the |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 323 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 324 | * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 325 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 326 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 327 | public RemoteViews bigContentView; |
| 328 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 329 | |
| 330 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 331 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 332 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 333 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 334 | * it without leaving their current activity. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 335 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 336 | * As of N, this field may be null. The heads-up notification view is determined by the |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 337 | * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be |
| 338 | * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 339 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 340 | @Deprecated |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 341 | public RemoteViews headsUpContentView; |
| 342 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 343 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 344 | * A large bitmap to be shown in the notification content area. |
| 345 | * |
| 346 | * @deprecated Use {@link Builder#setLargeIcon(Icon)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 348 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 349 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | |
| 351 | /** |
| 352 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 353 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 355 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 356 | * </p> |
| 357 | * |
| 358 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 359 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 361 | * @deprecated use {@link NotificationChannel#getSound()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 363 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | public Uri sound; |
| 365 | |
| 366 | /** |
| 367 | * Use this constant as the value for audioStreamType to request that |
| 368 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 369 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 370 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 371 | * @deprecated Use {@link NotificationChannel#getAudioAttributes()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 373 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | public static final int STREAM_DEFAULT = -1; |
| 375 | |
| 376 | /** |
| 377 | * The audio stream type to use when playing the sound. |
| 378 | * Should be one of the STREAM_ constants from |
| 379 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 380 | * |
| 381 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 383 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | public int audioStreamType = STREAM_DEFAULT; |
| 385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 387 | * The default value of {@link #audioAttributes}. |
| 388 | */ |
| 389 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 390 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 391 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 392 | .build(); |
| 393 | |
| 394 | /** |
| 395 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 396 | * |
| 397 | * @deprecated use {@link NotificationChannel#getAudioAttributes()} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 398 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 399 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 400 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 401 | |
| 402 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 403 | * The pattern with which to vibrate. |
| 404 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | * <p> |
| 406 | * To vibrate the default pattern, see {@link #defaults}. |
| 407 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 408 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | * @see android.os.Vibrator#vibrate(long[],int) |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 410 | * @deprecated use {@link NotificationChannel#getVibrationPattern()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 412 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | public long[] vibrate; |
| 414 | |
| 415 | /** |
| 416 | * The color of the led. The hardware will do its best approximation. |
| 417 | * |
| 418 | * @see #FLAG_SHOW_LIGHTS |
| 419 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 420 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 422 | @ColorInt |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 423 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | public int ledARGB; |
| 425 | |
| 426 | /** |
| 427 | * The number of milliseconds for the LED to be on while it's flashing. |
| 428 | * The hardware will do its best approximation. |
| 429 | * |
| 430 | * @see #FLAG_SHOW_LIGHTS |
| 431 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 432 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 434 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | public int ledOnMS; |
| 436 | |
| 437 | /** |
| 438 | * The number of milliseconds for the LED to be off while it's flashing. |
| 439 | * The hardware will do its best approximation. |
| 440 | * |
| 441 | * @see #FLAG_SHOW_LIGHTS |
| 442 | * @see #flags |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 443 | * |
| 444 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 446 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | public int ledOffMS; |
| 448 | |
| 449 | /** |
| 450 | * Specifies which values should be taken from the defaults. |
| 451 | * <p> |
| 452 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 453 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 454 | * values, use {@link #DEFAULT_ALL}. |
| 455 | * </p> |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 456 | * |
| 457 | * @deprecated use {@link NotificationChannel#getSound()} and |
| 458 | * {@link NotificationChannel#shouldShowLights()} and |
| 459 | * {@link NotificationChannel#shouldVibrate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 461 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | public int defaults; |
| 463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | /** |
| 465 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 466 | * set if you want the LED on for this notification. |
| 467 | * <ul> |
| 468 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 469 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 470 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 471 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 472 | * be on and off to ledOnMS and ledOffMS.</li> |
| 473 | * </ul> |
| 474 | * <p> |
| 475 | * Since hardware varies, you are not guaranteed that any of the values |
| 476 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 477 | * because they will be set to values that work on any given hardware. |
| 478 | * <p> |
| 479 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 480 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 481 | * @deprecated use {@link NotificationChannel#shouldShowLights()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 483 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 485 | |
| 486 | /** |
| 487 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 488 | * set if this notification is in reference to something that is ongoing, |
| 489 | * like a phone call. It should not be set if this notification is in |
| 490 | * reference to something that happened at a particular point in time, |
| 491 | * like a missed phone call. |
| 492 | */ |
| 493 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 494 | |
| 495 | /** |
| 496 | * Bit to be bitwise-ored into the {@link #flags} field that if set, |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 497 | * the audio will be repeated until the notification is |
| 498 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | */ |
| 500 | public static final int FLAG_INSISTENT = 0x00000004; |
| 501 | |
| 502 | /** |
| 503 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
Griff Hazen | 293977b | 2014-04-28 08:37:20 -0700 | [diff] [blame] | 504 | * set if you would only like the sound, vibrate and ticker to be played |
| 505 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | */ |
| 507 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 508 | |
| 509 | /** |
| 510 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 511 | * set if the notification should be canceled when it is clicked by the |
Daniel Sandler | 8aa9ae6 | 2012-12-04 23:31:47 -0500 | [diff] [blame] | 512 | * user. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | */ |
| 514 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 515 | |
| 516 | /** |
| 517 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 518 | * set if the notification should not be canceled when the user clicks |
| 519 | * the Clear all button. |
| 520 | */ |
| 521 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 522 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 523 | /** |
| 524 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 525 | * set if this notification represents a currently running service. This |
| 526 | * will normally be set for you by {@link Service#startForeground}. |
| 527 | */ |
| 528 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 529 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 530 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 531 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 532 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 533 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 534 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 535 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 536 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 537 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 538 | /** |
| 539 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 540 | * set if this notification is relevant to the current device only |
| 541 | * and it is not recommended that it bridge to other devices. |
| 542 | */ |
| 543 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 544 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 545 | /** |
| 546 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 547 | * set if this notification is the group summary for a group of notifications. |
| 548 | * Grouped notifications may display in a cluster or stack on devices which |
| 549 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 550 | */ |
| 551 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 552 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 553 | /** |
| 554 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 555 | * set if this notification is the group summary for an auto-group of notifications. |
| 556 | * |
| 557 | * @hide |
| 558 | */ |
| 559 | @SystemApi |
| 560 | public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 561 | |
Julia Reynolds | d71c5a9 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 562 | /** |
| 563 | * @hide |
| 564 | */ |
| 565 | public static final int FLAG_CAN_COLORIZE = 0x00000800; |
| 566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | public int flags; |
| 568 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 569 | /** @hide */ |
| 570 | @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX}) |
| 571 | @Retention(RetentionPolicy.SOURCE) |
| 572 | public @interface Priority {} |
| 573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 575 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 576 | * notifications, use this value for all notifications. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 577 | * |
| 578 | * @deprecated use {@link NotificationManager#IMPORTANCE_DEFAULT} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 579 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 580 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 581 | public static final int PRIORITY_DEFAULT = 0; |
| 582 | |
| 583 | /** |
| 584 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 585 | * items smaller, or at a different position in the list, compared with your app's |
| 586 | * {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 587 | * |
| 588 | * @deprecated use {@link NotificationManager#IMPORTANCE_LOW} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 589 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 590 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 591 | public static final int PRIORITY_LOW = -1; |
| 592 | |
| 593 | /** |
| 594 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 595 | * circumstances, such as detailed notification logs. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 596 | * |
| 597 | * @deprecated use {@link NotificationManager#IMPORTANCE_MIN} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 598 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 599 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 600 | public static final int PRIORITY_MIN = -2; |
| 601 | |
| 602 | /** |
| 603 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 604 | * show these items larger, or at a different position in notification lists, compared with |
| 605 | * your app's {@link #PRIORITY_DEFAULT} items. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 606 | * |
| 607 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 608 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 609 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 610 | public static final int PRIORITY_HIGH = 1; |
| 611 | |
| 612 | /** |
| 613 | * Highest {@link #priority}, for your application's most important items that require the |
| 614 | * user's prompt attention or input. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 615 | * |
| 616 | * @deprecated use {@link NotificationManager#IMPORTANCE_HIGH} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 617 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 618 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 619 | public static final int PRIORITY_MAX = 2; |
| 620 | |
| 621 | /** |
| 622 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 623 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 624 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 625 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 626 | * 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] | 627 | * system will make a determination about how to interpret this priority when presenting |
| 628 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 629 | * |
| 630 | * <p> |
| 631 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 632 | * as a heads-up notification. |
| 633 | * </p> |
| 634 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 635 | * @deprecated use {@link NotificationChannel#getImportance()} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 636 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 637 | @Priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 638 | @Deprecated |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 639 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 640 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 641 | /** |
| 642 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 643 | * to be applied by the standard Style templates when presenting this notification. |
| 644 | * |
| 645 | * The current template design constructs a colorful header image by overlaying the |
| 646 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 647 | * ignored. |
| 648 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 649 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 650 | public int color = COLOR_DEFAULT; |
| 651 | |
| 652 | /** |
| 653 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 654 | * any special color but instead use default colors when presenting this notification. |
| 655 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 656 | @ColorInt |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 657 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 658 | |
| 659 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 660 | * 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] | 661 | * @hide |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 662 | */ |
| 663 | @ColorInt |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 664 | public static final int COLOR_INVALID = 1; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 665 | |
| 666 | /** |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 667 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 668 | * 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] | 669 | * lockscreen). |
| 670 | * |
| 671 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 672 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 673 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 674 | * the appropriate user. |
| 675 | * |
| 676 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 677 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 678 | * To modify the public version of this notification—for example, to redact some portions—see |
| 679 | * {@link Builder#setPublicVersion(Notification)}. |
| 680 | * |
| 681 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 682 | * and ticker until the user has bypassed the lockscreen. |
| 683 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 684 | public @Visibility int visibility; |
| 685 | |
| 686 | /** @hide */ |
| 687 | @IntDef(prefix = { "VISIBILITY_" }, value = { |
| 688 | VISIBILITY_PUBLIC, |
| 689 | VISIBILITY_PRIVATE, |
| 690 | VISIBILITY_SECRET, |
| 691 | }) |
| 692 | @Retention(RetentionPolicy.SOURCE) |
| 693 | public @interface Visibility {} |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 694 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 695 | /** |
| 696 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 697 | * |
| 698 | * {@see #visibility} |
| 699 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 700 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 701 | |
| 702 | /** |
| 703 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 704 | * private information on secure lockscreens. |
| 705 | * |
| 706 | * {@see #visibility} |
| 707 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 708 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 709 | |
| 710 | /** |
| 711 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 712 | * |
| 713 | * {@see #visibility} |
| 714 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 715 | public static final int VISIBILITY_SECRET = -1; |
| 716 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 717 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 718 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 719 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 720 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 721 | |
| 722 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 723 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 724 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 725 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 726 | |
| 727 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 728 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 729 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 730 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 731 | |
| 732 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 733 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 734 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 735 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 736 | |
| 737 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 738 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 739 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 740 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 741 | |
| 742 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 743 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 744 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 745 | public static final String CATEGORY_ALARM = "alarm"; |
| 746 | |
| 747 | /** |
| 748 | * Notification category: progress of a long-running background operation. |
| 749 | */ |
| 750 | public static final String CATEGORY_PROGRESS = "progress"; |
| 751 | |
| 752 | /** |
| 753 | * Notification category: social network or sharing update. |
| 754 | */ |
| 755 | public static final String CATEGORY_SOCIAL = "social"; |
| 756 | |
| 757 | /** |
| 758 | * Notification category: error in background operation or authentication status. |
| 759 | */ |
| 760 | public static final String CATEGORY_ERROR = "err"; |
| 761 | |
| 762 | /** |
| 763 | * Notification category: media transport control for playback. |
| 764 | */ |
| 765 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 766 | |
| 767 | /** |
| 768 | * Notification category: system or device status update. Reserved for system use. |
| 769 | */ |
| 770 | public static final String CATEGORY_SYSTEM = "sys"; |
| 771 | |
| 772 | /** |
| 773 | * Notification category: indication of running background service. |
| 774 | */ |
| 775 | public static final String CATEGORY_SERVICE = "service"; |
| 776 | |
| 777 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 778 | * Notification category: a specific, timely recommendation for a single thing. |
| 779 | * For example, a news app might want to recommend a news story it believes the user will |
| 780 | * want to read next. |
| 781 | */ |
| 782 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 783 | |
| 784 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 785 | * Notification category: ongoing information about device or contextual status. |
| 786 | */ |
| 787 | public static final String CATEGORY_STATUS = "status"; |
| 788 | |
| 789 | /** |
John Spurlock | 24d3dad | 2015-04-02 12:24:02 -0400 | [diff] [blame] | 790 | * Notification category: user-scheduled reminder. |
| 791 | */ |
| 792 | public static final String CATEGORY_REMINDER = "reminder"; |
| 793 | |
| 794 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 795 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 796 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 797 | */ |
| 798 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 799 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 800 | private String mGroupKey; |
| 801 | |
| 802 | /** |
| 803 | * Get the key used to group this notification into a cluster or stack |
| 804 | * with other notifications on devices which support such rendering. |
| 805 | */ |
| 806 | public String getGroup() { |
| 807 | return mGroupKey; |
| 808 | } |
| 809 | |
| 810 | private String mSortKey; |
| 811 | |
| 812 | /** |
| 813 | * Get a sort key that orders this notification among other notifications from the |
| 814 | * same package. This can be useful if an external sort was already applied and an app |
| 815 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 816 | * value, although providing different priorities in addition to providing sort key may |
| 817 | * cause this value to be ignored. |
| 818 | * |
| 819 | * <p>This sort key can also be used to order members of a notification group. See |
| 820 | * {@link Builder#setGroup}. |
| 821 | * |
| 822 | * @see String#compareTo(String) |
| 823 | */ |
| 824 | public String getSortKey() { |
| 825 | return mSortKey; |
| 826 | } |
| 827 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 828 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 829 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 830 | * <p> |
| 831 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 832 | * APIs, and are intended to be used by |
| 833 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 834 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 835 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 836 | public Bundle extras = new Bundle(); |
| 837 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 838 | /** |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 839 | * All pending intents in the notification as the system needs to be able to access them but |
| 840 | * 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] | 841 | * custom parcelable objects. |
| 842 | * |
| 843 | * @hide |
| 844 | */ |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 845 | public ArraySet<PendingIntent> allPendingIntents; |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 846 | |
| 847 | /** |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 848 | * Token identifying the notification that is applying doze/bgcheck whitelisting to the |
| 849 | * pending intents inside of it, so only those will get the behavior. |
| 850 | * |
| 851 | * @hide |
| 852 | */ |
| 853 | static public IBinder whitelistToken; |
| 854 | |
| 855 | /** |
| 856 | * Must be set by a process to start associating tokens with Notification objects |
| 857 | * coming in to it. This is set by NotificationManagerService. |
| 858 | * |
| 859 | * @hide |
| 860 | */ |
| 861 | static public IBinder processWhitelistToken; |
| 862 | |
| 863 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 864 | * {@link #extras} key: this is the title of the notification, |
| 865 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 866 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 867 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 868 | |
| 869 | /** |
| 870 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 871 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 872 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 873 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 874 | |
| 875 | /** |
| 876 | * {@link #extras} key: this is the main text payload, as supplied to |
| 877 | * {@link Builder#setContentText(CharSequence)}. |
| 878 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 879 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 880 | |
| 881 | /** |
| 882 | * {@link #extras} key: this is a third line of text, as supplied to |
| 883 | * {@link Builder#setSubText(CharSequence)}. |
| 884 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 885 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 886 | |
| 887 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 888 | * {@link #extras} key: this is the remote input history, as supplied to |
| 889 | * {@link Builder#setRemoteInputHistory(CharSequence[])}. |
Adrian Roos | 005e774 | 2016-04-13 15:02:20 -0700 | [diff] [blame] | 890 | * |
| 891 | * Apps can fill this through {@link Builder#setRemoteInputHistory(CharSequence[])} |
| 892 | * with the most recent inputs that have been sent through a {@link RemoteInput} of this |
| 893 | * Notification and are expected to clear it once the it is no longer relevant (e.g. for chat |
| 894 | * notifications once the other party has responded). |
| 895 | * |
| 896 | * The extra with this key is of type CharSequence[] and contains the most recent entry at |
| 897 | * the 0 index, the second most recent at the 1 index, etc. |
| 898 | * |
| 899 | * @see Builder#setRemoteInputHistory(CharSequence[]) |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 900 | */ |
| 901 | public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 902 | |
| 903 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 904 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 905 | * {@link Builder#setContentInfo(CharSequence)}. |
| 906 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 907 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 908 | |
| 909 | /** |
| 910 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 911 | * alongside expanded notifications, as supplied to (e.g.) |
| 912 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 913 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 914 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 915 | |
| 916 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 917 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 918 | * {@link BigTextStyle} notification, as supplied to |
| 919 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 920 | */ |
| 921 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 922 | |
| 923 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 924 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 925 | * supplied to {@link Builder#setSmallIcon(int)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 926 | * |
| 927 | * @deprecated Use {@link #getSmallIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 928 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 929 | @Deprecated |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 930 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 931 | |
| 932 | /** |
| 933 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 934 | * notification payload, as |
| 935 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 936 | * |
| 937 | * @deprecated Use {@link #getLargeIcon()}, which supports a wider variety of icon sources. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 938 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 939 | @Deprecated |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 940 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 941 | |
| 942 | /** |
| 943 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 944 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 945 | * shown in its expanded form, as supplied to |
| 946 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 947 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 948 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 949 | |
| 950 | /** |
| 951 | * {@link #extras} key: this is the progress value supplied to |
| 952 | * {@link Builder#setProgress(int, int, boolean)}. |
| 953 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 954 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 955 | |
| 956 | /** |
| 957 | * {@link #extras} key: this is the maximum value supplied to |
| 958 | * {@link Builder#setProgress(int, int, boolean)}. |
| 959 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 960 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 961 | |
| 962 | /** |
| 963 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 964 | * {@link Builder#setProgress(int, int, boolean)}. |
| 965 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 966 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 967 | |
| 968 | /** |
| 969 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 970 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 971 | * {@link Builder#setUsesChronometer(boolean)}. |
| 972 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 973 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 974 | |
| 975 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 976 | * {@link #extras} key: whether the chronometer set on the notification should count down |
| 977 | * 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] | 978 | * This extra is a boolean. The default is false. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 979 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 980 | public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 981 | |
| 982 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 983 | * {@link #extras} key: whether {@link #when} should be shown, |
| 984 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 985 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 986 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 987 | |
| 988 | /** |
| 989 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 990 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 991 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 992 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 993 | |
| 994 | /** |
| 995 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 996 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 997 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 998 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 999 | |
| 1000 | /** |
| 1001 | * {@link #extras} key: A string representing the name of the specific |
| 1002 | * {@link android.app.Notification.Style} used to create this notification. |
| 1003 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 1004 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1005 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1006 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 1007 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 1008 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1009 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 1010 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1011 | |
| 1012 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1013 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 1014 | * Only available to notifications coming from the android package. |
| 1015 | * @hide |
| 1016 | */ |
Maurice Lam | 96c1003 | 2017-03-29 15:42:38 -0700 | [diff] [blame] | 1017 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1018 | @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1019 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 1020 | |
| 1021 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 1022 | * {@link #extras} key: A |
| 1023 | * {@link android.content.ContentUris content URI} pointing to an image that can be displayed |
| 1024 | * in the background when the notification is selected. The URI must point to an image stream |
| 1025 | * suitable for passing into |
| 1026 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
| 1027 | * BitmapFactory.decodeStream}; all other content types will be ignored. The content provider |
| 1028 | * URI used for this purpose must require no permissions to read the image data. |
| 1029 | */ |
| 1030 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1031 | |
| 1032 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1033 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 1034 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1035 | * {@link android.app.Notification.MediaStyle} notification. |
| 1036 | */ |
| 1037 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1038 | |
| 1039 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 1040 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 1041 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 1042 | */ |
| 1043 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1044 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 1045 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1046 | * {@link #extras} key: the username to be displayed for all messages sent by the user including |
| 1047 | * direct replies |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1048 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a |
| 1049 | * {@link CharSequence} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1050 | */ |
| 1051 | public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1052 | |
| 1053 | /** |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1054 | * {@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] | 1055 | * represented by a {@link android.app.Notification.MessagingStyle} |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1056 | */ |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 1057 | public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1058 | |
| 1059 | /** |
| 1060 | * {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message} |
| 1061 | * bundles provided by a |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 1062 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1063 | * array of bundles. |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 1064 | */ |
| 1065 | public static final String EXTRA_MESSAGES = "android.messages"; |
| 1066 | |
| 1067 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 1068 | * {@link #extras} key: an array of |
| 1069 | * {@link android.app.Notification.MessagingStyle#addHistoricMessage historic} |
| 1070 | * {@link android.app.Notification.MessagingStyle.Message} bundles provided by a |
| 1071 | * {@link android.app.Notification.MessagingStyle} notification. This extra is a parcelable |
| 1072 | * array of bundles. |
| 1073 | */ |
| 1074 | public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1075 | |
| 1076 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 1077 | * {@link #extras} key: whether the notification should be colorized as |
| 1078 | * supplied to {@link Builder#setColorized(boolean)}}. |
| 1079 | */ |
| 1080 | public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1081 | |
| 1082 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1083 | * @hide |
| 1084 | */ |
| 1085 | public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1086 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 1087 | /** |
| 1088 | * @hide |
| 1089 | */ |
| 1090 | public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1091 | |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1092 | /** |
| 1093 | * {@link #extras} key: the audio contents of this notification. |
| 1094 | * |
| 1095 | * This is for use when rendering the notification on an audio-focused interface; |
| 1096 | * the audio contents are a complete sound sample that contains the contents/body of the |
| 1097 | * notification. This may be used in substitute of a Text-to-Speech reading of the |
| 1098 | * notification. For example if the notification represents a voice message this should point |
| 1099 | * to the audio of that message. |
| 1100 | * |
| 1101 | * The data stored under this key should be a String representation of a Uri that contains the |
| 1102 | * audio contents in one of the following formats: WAV, PCM 16-bit, AMR-WB. |
| 1103 | * |
| 1104 | * This extra is unnecessary if you are using {@code MessagingStyle} since each {@code Message} |
| 1105 | * has a field for holding data URI. That field can be used for audio. |
| 1106 | * See {@code Message#setData}. |
| 1107 | * |
| 1108 | * Example usage: |
| 1109 | * <pre> |
| 1110 | * {@code |
| 1111 | * Notification.Builder myBuilder = (build your Notification as normal); |
| 1112 | * myBuilder.getExtras().putString(EXTRA_AUDIO_CONTENTS_URI, myAudioUri.toString()); |
| 1113 | * } |
| 1114 | * </pre> |
| 1115 | */ |
| 1116 | public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1117 | |
Dan Sandler | 80eaa59 | 2016-04-14 23:34:54 -0400 | [diff] [blame] | 1118 | /** @hide */ |
| 1119 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1120 | @RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME) |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1121 | public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1122 | |
Dianne Hackborn | fb5d4b5 | 2017-05-16 17:03:44 -0700 | [diff] [blame] | 1123 | /** |
| 1124 | * This is set on the notification shown by the activity manager about all apps |
| 1125 | * running in the background. It indicates that the notification should be shown |
| 1126 | * only if any of the given apps do not already have a {@link #FLAG_FOREGROUND_SERVICE} |
| 1127 | * notification currently visible to the user. This is a string array of all |
| 1128 | * package names of the apps. |
| 1129 | * @hide |
| 1130 | */ |
| 1131 | public static final String EXTRA_FOREGROUND_APPS = "android.foregroundApps"; |
| 1132 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1133 | private Icon mSmallIcon; |
| 1134 | private Icon mLargeIcon; |
| 1135 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1136 | private String mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1137 | private long mTimeout; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1138 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1139 | private String mShortcutId; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1140 | private CharSequence mSettingsText; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1141 | |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1142 | /** @hide */ |
| 1143 | @IntDef(prefix = { "GROUP_ALERT_" }, value = { |
| 1144 | GROUP_ALERT_ALL, GROUP_ALERT_CHILDREN, GROUP_ALERT_SUMMARY |
| 1145 | }) |
| 1146 | @Retention(RetentionPolicy.SOURCE) |
| 1147 | public @interface GroupAlertBehavior {} |
| 1148 | |
| 1149 | /** |
| 1150 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all notifications in a |
| 1151 | * group with sound or vibration ought to make sound or vibrate (respectively), so this |
| 1152 | * notification will not be muted when it is in a group. |
| 1153 | */ |
| 1154 | public static final int GROUP_ALERT_ALL = 0; |
| 1155 | |
| 1156 | /** |
| 1157 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that all children |
| 1158 | * notification in a group should be silenced (no sound or vibration) even if they are posted |
| 1159 | * to a {@link NotificationChannel} that has sound and/or vibration. Use this constant to |
| 1160 | * mute this notification if this notification is a group child. |
| 1161 | * |
| 1162 | * <p> For example, you might want to use this constant if you post a number of children |
| 1163 | * notifications at once (say, after a periodic sync), and only need to notify the user |
| 1164 | * audibly once. |
| 1165 | */ |
| 1166 | public static final int GROUP_ALERT_SUMMARY = 1; |
| 1167 | |
| 1168 | /** |
| 1169 | * Constant for {@link Builder#setGroupAlertBehavior(int)}, meaning that the summary |
| 1170 | * notification in a group should be silenced (no sound or vibration) even if they are |
| 1171 | * posted to a {@link NotificationChannel} that has sound and/or vibration. Use this constant |
| 1172 | * to mute this notification if this notification is a group summary. |
| 1173 | * |
| 1174 | * <p>For example, you might want to use this constant if only the children notifications |
| 1175 | * in your group have content and the summary is only used to visually group notifications. |
| 1176 | */ |
| 1177 | public static final int GROUP_ALERT_CHILDREN = 2; |
| 1178 | |
Julia Reynolds | 2f431e2 | 2017-06-07 14:12:09 +0000 | [diff] [blame] | 1179 | private int mGroupAlertBehavior = GROUP_ALERT_ALL; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1180 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1181 | /** |
| 1182 | * If this notification is being shown as a badge, always show as a number. |
| 1183 | */ |
| 1184 | public static final int BADGE_ICON_NONE = 0; |
| 1185 | |
| 1186 | /** |
| 1187 | * If this notification is being shown as a badge, use the {@link #getSmallIcon()} to |
| 1188 | * represent this notification. |
| 1189 | */ |
| 1190 | public static final int BADGE_ICON_SMALL = 1; |
| 1191 | |
| 1192 | /** |
| 1193 | * If this notification is being shown as a badge, use the {@link #getLargeIcon()} to |
| 1194 | * represent this notification. |
| 1195 | */ |
| 1196 | public static final int BADGE_ICON_LARGE = 2; |
Julia Reynolds | 7d5b4da | 2017-03-20 10:18:49 -0400 | [diff] [blame] | 1197 | private int mBadgeIcon = BADGE_ICON_NONE; |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1198 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1199 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1200 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 1201 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 1202 | * selected by the user. |
| 1203 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1204 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 1205 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 1206 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1207 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1208 | public static class Action implements Parcelable { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1209 | /** |
| 1210 | * {@link #extras} key: Keys to a {@link Parcelable} {@link ArrayList} of |
| 1211 | * {@link RemoteInput}s. |
| 1212 | * |
| 1213 | * This is intended for {@link RemoteInput}s that only accept data, meaning |
| 1214 | * {@link RemoteInput#getAllowFreeFormInput} is false, {@link RemoteInput#getChoices} |
| 1215 | * is null or empty, and {@link RemoteInput#getAllowedDataTypes is non-null and not |
| 1216 | * empty. These {@link RemoteInput}s will be ignored by devices that do not |
| 1217 | * support non-text-based {@link RemoteInput}s. See {@link Builder#build}. |
| 1218 | * |
| 1219 | * You can test if a RemoteInput matches these constraints using |
| 1220 | * {@link RemoteInput#isDataOnly}. |
| 1221 | */ |
| 1222 | private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1223 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1224 | private final Bundle mExtras; |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1225 | private Icon mIcon; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1226 | private final RemoteInput[] mRemoteInputs; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1227 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1228 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1229 | /** |
| 1230 | * Small icon representing the action. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1231 | * |
| 1232 | * @deprecated Use {@link Action#getIcon()} instead. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1233 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1234 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1235 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1236 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1237 | /** |
| 1238 | * Title of the action. |
| 1239 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1240 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1241 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1242 | /** |
| 1243 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 1244 | * may be rendered in a disabled presentation by the system UI. |
| 1245 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1246 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1247 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1248 | private Action(Parcel in) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1249 | if (in.readInt() != 0) { |
| 1250 | mIcon = Icon.CREATOR.createFromParcel(in); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1251 | if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1252 | icon = mIcon.getResId(); |
| 1253 | } |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1254 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1255 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1256 | if (in.readInt() == 1) { |
| 1257 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1258 | } |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1259 | mExtras = Bundle.setDefusable(in.readBundle(), true); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1260 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1261 | mAllowGeneratedReplies = in.readInt() == 1; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1262 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1263 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1264 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1265 | * @deprecated Use {@link android.app.Notification.Action.Builder}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1266 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1267 | @Deprecated |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1268 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1269 | this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1270 | } |
| 1271 | |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1272 | /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1273 | private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1274 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1275 | this.mIcon = icon; |
Gus Prevas | f5bff46f | 2015-08-24 10:34:28 -0400 | [diff] [blame] | 1276 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1277 | this.icon = icon.getResId(); |
| 1278 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1279 | this.title = title; |
| 1280 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1281 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1282 | this.mRemoteInputs = remoteInputs; |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1283 | this.mAllowGeneratedReplies = allowGeneratedReplies; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /** |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1287 | * Return an icon representing the action. |
| 1288 | */ |
| 1289 | public Icon getIcon() { |
| 1290 | if (mIcon == null && icon != 0) { |
| 1291 | // you snuck an icon in here without using the builder; let's try to keep it |
| 1292 | mIcon = Icon.createWithResource("", icon); |
| 1293 | } |
| 1294 | return mIcon; |
| 1295 | } |
| 1296 | |
| 1297 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1298 | * Get additional metadata carried around with this Action. |
| 1299 | */ |
| 1300 | public Bundle getExtras() { |
| 1301 | return mExtras; |
| 1302 | } |
| 1303 | |
| 1304 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1305 | * Return whether the platform should automatically generate possible replies for this |
| 1306 | * {@link Action} |
| 1307 | */ |
| 1308 | public boolean getAllowGeneratedReplies() { |
| 1309 | return mAllowGeneratedReplies; |
| 1310 | } |
| 1311 | |
| 1312 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1313 | * 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] | 1314 | * May return null if no remote inputs were added. Only returns inputs which accept |
| 1315 | * a text input. For inputs which only accept data use {@link #getDataOnlyRemoteInputs}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1316 | */ |
| 1317 | public RemoteInput[] getRemoteInputs() { |
| 1318 | return mRemoteInputs; |
| 1319 | } |
| 1320 | |
| 1321 | /** |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1322 | * Get the list of inputs to be collected from the user that ONLY accept data when this |
| 1323 | * action is sent. These remote inputs are guaranteed to return true on a call to |
| 1324 | * {@link RemoteInput#isDataOnly}. |
| 1325 | * |
Shane Brennan | f670d6c | 2017-04-25 13:05:45 -0700 | [diff] [blame] | 1326 | * Returns null if there are no data-only remote inputs. |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1327 | * |
| 1328 | * This method exists so that legacy RemoteInput collectors that pre-date the addition |
| 1329 | * of non-textual RemoteInputs do not access these remote inputs. |
| 1330 | */ |
| 1331 | public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1332 | return (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
| 1333 | } |
| 1334 | |
| 1335 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1336 | * Builder class for {@link Action} objects. |
| 1337 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1338 | public static final class Builder { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1339 | private final Icon mIcon; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1340 | private final CharSequence mTitle; |
| 1341 | private final PendingIntent mIntent; |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1342 | private boolean mAllowGeneratedReplies = true; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1343 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1344 | private ArrayList<RemoteInput> mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1345 | |
| 1346 | /** |
| 1347 | * Construct a new builder for {@link Action} object. |
| 1348 | * @param icon icon to show for this action |
| 1349 | * @param title the title of the action |
| 1350 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1351 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1352 | @Deprecated |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1353 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1354 | this(Icon.createWithResource("", icon), title, intent); |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * Construct a new builder for {@link Action} object. |
| 1359 | * @param icon icon to show for this action |
| 1360 | * @param title the title of the action |
| 1361 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 1362 | */ |
| 1363 | public Builder(Icon icon, CharSequence title, PendingIntent intent) { |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1364 | this(icon, title, intent, new Bundle(), null, true); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | /** |
| 1368 | * Construct a new builder for {@link Action} object using the fields from an |
| 1369 | * {@link Action}. |
| 1370 | * @param action the action to read fields from. |
| 1371 | */ |
| 1372 | public Builder(Action action) { |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1373 | this(action.getIcon(), action.title, action.actionIntent, |
| 1374 | new Bundle(action.mExtras), action.getRemoteInputs(), |
| 1375 | action.getAllowGeneratedReplies()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1378 | private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1379 | RemoteInput[] remoteInputs, boolean allowGeneratedReplies) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1380 | mIcon = icon; |
| 1381 | mTitle = title; |
| 1382 | mIntent = intent; |
| 1383 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1384 | if (remoteInputs != null) { |
| 1385 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 1386 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 1387 | } |
Adrian Roos | 7af5362 | 2016-10-12 13:44:05 -0700 | [diff] [blame] | 1388 | mAllowGeneratedReplies = allowGeneratedReplies; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | /** |
| 1392 | * Merge additional metadata into this builder. |
| 1393 | * |
| 1394 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1395 | * |
| 1396 | * @see Notification.Action#extras |
| 1397 | */ |
| 1398 | public Builder addExtras(Bundle extras) { |
| 1399 | if (extras != null) { |
| 1400 | mExtras.putAll(extras); |
| 1401 | } |
| 1402 | return this; |
| 1403 | } |
| 1404 | |
| 1405 | /** |
| 1406 | * Get the metadata Bundle used by this Builder. |
| 1407 | * |
| 1408 | * <p>The returned Bundle is shared with this Builder. |
| 1409 | */ |
| 1410 | public Bundle getExtras() { |
| 1411 | return mExtras; |
| 1412 | } |
| 1413 | |
| 1414 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1415 | * Add an input to be collected from the user when this action is sent. |
| 1416 | * Response values can be retrieved from the fired intent by using the |
| 1417 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1418 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1419 | * @return this object for method chaining |
| 1420 | */ |
| 1421 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1422 | if (mRemoteInputs == null) { |
| 1423 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1424 | } |
| 1425 | mRemoteInputs.add(remoteInput); |
| 1426 | return this; |
| 1427 | } |
| 1428 | |
| 1429 | /** |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1430 | * Set whether the platform should automatically generate possible replies to add to |
| 1431 | * {@link RemoteInput#getChoices()}. If the {@link Action} doesn't have a |
| 1432 | * {@link RemoteInput}, this has no effect. |
| 1433 | * @param allowGeneratedReplies {@code true} to allow generated replies, {@code false} |
| 1434 | * otherwise |
| 1435 | * @return this object for method chaining |
Alex Hills | 1f27f88 | 2017-01-12 11:24:46 -0500 | [diff] [blame] | 1436 | * The default value is {@code true} |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1437 | */ |
| 1438 | public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 1439 | mAllowGeneratedReplies = allowGeneratedReplies; |
| 1440 | return this; |
| 1441 | } |
| 1442 | |
| 1443 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1444 | * Apply an extender to this action builder. Extenders may be used to add |
| 1445 | * metadata or change options on this builder. |
| 1446 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1447 | public Builder extend(Extender extender) { |
| 1448 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1449 | return this; |
| 1450 | } |
| 1451 | |
| 1452 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1453 | * Combine all of the options that have been set and return a new {@link Action} |
| 1454 | * object. |
| 1455 | * @return the built action |
| 1456 | */ |
| 1457 | public Action build() { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1458 | ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 1459 | RemoteInput[] previousDataInputs = |
| 1460 | (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |
Felipe Leme | dfd1196 | 2017-01-18 18:38:46 -0800 | [diff] [blame] | 1461 | if (previousDataInputs != null) { |
Shane Brennan | 472a3b3 | 2016-12-12 15:28:10 -0800 | [diff] [blame] | 1462 | for (RemoteInput input : previousDataInputs) { |
| 1463 | dataOnlyInputs.add(input); |
| 1464 | } |
| 1465 | } |
| 1466 | List<RemoteInput> textInputs = new ArrayList<>(); |
| 1467 | if (mRemoteInputs != null) { |
| 1468 | for (RemoteInput input : mRemoteInputs) { |
| 1469 | if (input.isDataOnly()) { |
| 1470 | dataOnlyInputs.add(input); |
| 1471 | } else { |
| 1472 | textInputs.add(input); |
| 1473 | } |
| 1474 | } |
| 1475 | } |
| 1476 | if (!dataOnlyInputs.isEmpty()) { |
| 1477 | RemoteInput[] dataInputsArr = |
| 1478 | dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 1479 | mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 1480 | } |
| 1481 | RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 1482 | ? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 1483 | return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1484 | mAllowGeneratedReplies); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1485 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1486 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1487 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1488 | @Override |
| 1489 | public Action clone() { |
| 1490 | return new Action( |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1491 | getIcon(), |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1492 | title, |
| 1493 | actionIntent, // safe to alias |
Julia Reynolds | 53c934c | 2016-09-16 14:03:43 -0400 | [diff] [blame] | 1494 | mExtras == null ? new Bundle() : new Bundle(mExtras), |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1495 | getRemoteInputs(), |
| 1496 | getAllowGeneratedReplies()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1497 | } |
| 1498 | @Override |
| 1499 | public int describeContents() { |
| 1500 | return 0; |
| 1501 | } |
| 1502 | @Override |
| 1503 | public void writeToParcel(Parcel out, int flags) { |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 1504 | final Icon ic = getIcon(); |
| 1505 | if (ic != null) { |
| 1506 | out.writeInt(1); |
| 1507 | ic.writeToParcel(out, 0); |
| 1508 | } else { |
| 1509 | out.writeInt(0); |
| 1510 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1511 | TextUtils.writeToParcel(title, out, flags); |
| 1512 | if (actionIntent != null) { |
| 1513 | out.writeInt(1); |
| 1514 | actionIntent.writeToParcel(out, flags); |
| 1515 | } else { |
| 1516 | out.writeInt(0); |
| 1517 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1518 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1519 | out.writeTypedArray(mRemoteInputs, flags); |
Alex Hills | 42b0c4d | 2016-04-26 13:35:36 -0400 | [diff] [blame] | 1520 | out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1521 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1522 | public static final Parcelable.Creator<Action> CREATOR = |
| 1523 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1524 | public Action createFromParcel(Parcel in) { |
| 1525 | return new Action(in); |
| 1526 | } |
| 1527 | public Action[] newArray(int size) { |
| 1528 | return new Action[size]; |
| 1529 | } |
| 1530 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1531 | |
| 1532 | /** |
| 1533 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1534 | * metadata or change options on an action builder. |
| 1535 | */ |
| 1536 | public interface Extender { |
| 1537 | /** |
| 1538 | * Apply this extender to a notification action builder. |
| 1539 | * @param builder the builder to be modified. |
| 1540 | * @return the build object for chaining. |
| 1541 | */ |
| 1542 | public Builder extend(Builder builder); |
| 1543 | } |
| 1544 | |
| 1545 | /** |
| 1546 | * Wearable extender for notification actions. To add extensions to an action, |
| 1547 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1548 | * the {@code WearableExtender()} constructor and apply it to a |
| 1549 | * {@link android.app.Notification.Action.Builder} using |
| 1550 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1551 | * |
| 1552 | * <pre class="prettyprint"> |
| 1553 | * Notification.Action action = new Notification.Action.Builder( |
| 1554 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1555 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1556 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1557 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1558 | */ |
| 1559 | public static final class WearableExtender implements Extender { |
| 1560 | /** Notification action extra which contains wearable extensions */ |
| 1561 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1562 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1563 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1564 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1565 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1566 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1567 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1568 | |
| 1569 | // Flags bitwise-ored to mFlags |
| 1570 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1571 | private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1572 | private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1573 | |
| 1574 | // Default value for flags integer |
| 1575 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1576 | |
| 1577 | private int mFlags = DEFAULT_FLAGS; |
| 1578 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1579 | private CharSequence mInProgressLabel; |
| 1580 | private CharSequence mConfirmLabel; |
| 1581 | private CharSequence mCancelLabel; |
| 1582 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1583 | /** |
| 1584 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1585 | * options. |
| 1586 | */ |
| 1587 | public WearableExtender() { |
| 1588 | } |
| 1589 | |
| 1590 | /** |
| 1591 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1592 | * wearable options present in an existing notification action. |
| 1593 | * @param action the notification action to inspect. |
| 1594 | */ |
| 1595 | public WearableExtender(Action action) { |
| 1596 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1597 | if (wearableBundle != null) { |
| 1598 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1599 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1600 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1601 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | /** |
| 1606 | * Apply wearable extensions to a notification action that is being built. This is |
| 1607 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1608 | * method of {@link android.app.Notification.Action.Builder}. |
| 1609 | */ |
| 1610 | @Override |
| 1611 | public Action.Builder extend(Action.Builder builder) { |
| 1612 | Bundle wearableBundle = new Bundle(); |
| 1613 | |
| 1614 | if (mFlags != DEFAULT_FLAGS) { |
| 1615 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1616 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1617 | if (mInProgressLabel != null) { |
| 1618 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1619 | } |
| 1620 | if (mConfirmLabel != null) { |
| 1621 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1622 | } |
| 1623 | if (mCancelLabel != null) { |
| 1624 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1625 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1626 | |
| 1627 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1628 | return builder; |
| 1629 | } |
| 1630 | |
| 1631 | @Override |
| 1632 | public WearableExtender clone() { |
| 1633 | WearableExtender that = new WearableExtender(); |
| 1634 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1635 | that.mInProgressLabel = this.mInProgressLabel; |
| 1636 | that.mConfirmLabel = this.mConfirmLabel; |
| 1637 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1638 | return that; |
| 1639 | } |
| 1640 | |
| 1641 | /** |
| 1642 | * Set whether this action is available when the wearable device is not connected to |
| 1643 | * a companion device. The user can still trigger this action when the wearable device is |
| 1644 | * offline, but a visual hint will indicate that the action may not be available. |
| 1645 | * Defaults to true. |
| 1646 | */ |
| 1647 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1648 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1649 | return this; |
| 1650 | } |
| 1651 | |
| 1652 | /** |
| 1653 | * Get whether this action is available when the wearable device is not connected to |
| 1654 | * a companion device. The user can still trigger this action when the wearable device is |
| 1655 | * offline, but a visual hint will indicate that the action may not be available. |
| 1656 | * Defaults to true. |
| 1657 | */ |
| 1658 | public boolean isAvailableOffline() { |
| 1659 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1660 | } |
| 1661 | |
| 1662 | private void setFlag(int mask, boolean value) { |
| 1663 | if (value) { |
| 1664 | mFlags |= mask; |
| 1665 | } else { |
| 1666 | mFlags &= ~mask; |
| 1667 | } |
| 1668 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1669 | |
| 1670 | /** |
| 1671 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1672 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1673 | * |
| 1674 | * @param label the label to display while the action is being prepared to execute |
| 1675 | * @return this object for method chaining |
| 1676 | */ |
| 1677 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1678 | mInProgressLabel = label; |
| 1679 | return this; |
| 1680 | } |
| 1681 | |
| 1682 | /** |
| 1683 | * Get the label to display while the wearable is preparing to automatically execute |
| 1684 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1685 | * |
| 1686 | * @return the label to display while the action is being prepared to execute |
| 1687 | */ |
| 1688 | public CharSequence getInProgressLabel() { |
| 1689 | return mInProgressLabel; |
| 1690 | } |
| 1691 | |
| 1692 | /** |
| 1693 | * Set a label to display to confirm that the action should be executed. |
| 1694 | * This is usually an imperative verb like "Send". |
| 1695 | * |
| 1696 | * @param label the label to confirm the action should be executed |
| 1697 | * @return this object for method chaining |
| 1698 | */ |
| 1699 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1700 | mConfirmLabel = label; |
| 1701 | return this; |
| 1702 | } |
| 1703 | |
| 1704 | /** |
| 1705 | * Get the label to display to confirm that the action should be executed. |
| 1706 | * This is usually an imperative verb like "Send". |
| 1707 | * |
| 1708 | * @return the label to confirm the action should be executed |
| 1709 | */ |
| 1710 | public CharSequence getConfirmLabel() { |
| 1711 | return mConfirmLabel; |
| 1712 | } |
| 1713 | |
| 1714 | /** |
| 1715 | * Set a label to display to cancel the action. |
| 1716 | * This is usually an imperative verb, like "Cancel". |
| 1717 | * |
| 1718 | * @param label the label to display to cancel the action |
| 1719 | * @return this object for method chaining |
| 1720 | */ |
| 1721 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1722 | mCancelLabel = label; |
| 1723 | return this; |
| 1724 | } |
| 1725 | |
| 1726 | /** |
| 1727 | * Get the label to display to cancel the action. |
| 1728 | * This is usually an imperative verb like "Cancel". |
| 1729 | * |
| 1730 | * @return the label to display to cancel the action |
| 1731 | */ |
| 1732 | public CharSequence getCancelLabel() { |
| 1733 | return mCancelLabel; |
| 1734 | } |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1735 | |
| 1736 | /** |
| 1737 | * Set a hint that this Action will launch an {@link Activity} directly, telling the |
| 1738 | * platform that it can generate the appropriate transitions. |
| 1739 | * @param hintLaunchesActivity {@code true} if the content intent will launch |
| 1740 | * an activity and transitions should be generated, false otherwise. |
| 1741 | * @return this object for method chaining |
| 1742 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1743 | public WearableExtender setHintLaunchesActivity( |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1744 | boolean hintLaunchesActivity) { |
| 1745 | setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 1746 | return this; |
| 1747 | } |
| 1748 | |
| 1749 | /** |
| 1750 | * Get a hint that this Action will launch an {@link Activity} directly, telling the |
| 1751 | * platform that it can generate the appropriate transitions |
| 1752 | * @return {@code true} if the content intent will launch an activity and transitions |
| 1753 | * should be generated, false otherwise. The default value is {@code false} if this was |
| 1754 | * never set. |
| 1755 | */ |
Alex Hills | 4ec3ff4 | 2016-04-12 11:36:18 -0400 | [diff] [blame] | 1756 | public boolean getHintLaunchesActivity() { |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 1757 | return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 1758 | } |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1759 | |
| 1760 | /** |
| 1761 | * Set a hint that this Action should be displayed inline. |
| 1762 | * |
| 1763 | * @param hintDisplayInline {@code true} if action should be displayed inline, false |
| 1764 | * otherwise |
| 1765 | * @return this object for method chaining |
| 1766 | */ |
| 1767 | public WearableExtender setHintDisplayActionInline( |
| 1768 | boolean hintDisplayInline) { |
| 1769 | setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 1770 | return this; |
| 1771 | } |
| 1772 | |
| 1773 | /** |
| 1774 | * Get a hint that this Action should be displayed inline. |
| 1775 | * |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 1776 | * @return {@code true} if the Action should be displayed inline, {@code false} |
Alex Hills | 9f08761 | 2016-06-07 09:08:59 -0400 | [diff] [blame] | 1777 | * otherwise. The default value is {@code false} if this was never set. |
| 1778 | */ |
| 1779 | public boolean getHintDisplayActionInline() { |
| 1780 | return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 1781 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1782 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1783 | } |
| 1784 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1785 | /** |
| 1786 | * Array of all {@link Action} structures attached to this notification by |
| 1787 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 1788 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 1789 | * interface for invoking actions. |
| 1790 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1791 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1792 | |
| 1793 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1794 | * Replacement version of this notification whose content will be shown |
| 1795 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 1796 | * and {@link #VISIBILITY_PUBLIC}. |
| 1797 | */ |
| 1798 | public Notification publicVersion; |
| 1799 | |
| 1800 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1801 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1802 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1803 | */ |
| 1804 | public Notification() |
| 1805 | { |
| 1806 | this.when = System.currentTimeMillis(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1807 | this.creationTime = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1808 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1812 | * @hide |
| 1813 | */ |
| 1814 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 1815 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 1816 | { |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1817 | new Builder(context) |
| 1818 | .setWhen(when) |
| 1819 | .setSmallIcon(icon) |
| 1820 | .setTicker(tickerText) |
| 1821 | .setContentTitle(contentTitle) |
| 1822 | .setContentText(contentText) |
| 1823 | .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)) |
| 1824 | .buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | /** |
| 1828 | * Constructs a Notification object with the information needed to |
| 1829 | * have a status bar icon without the standard expanded view. |
| 1830 | * |
| 1831 | * @param icon The resource id of the icon to put in the status bar. |
| 1832 | * @param tickerText The text that flows by in the status bar when the notification first |
| 1833 | * activates. |
| 1834 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 1835 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1836 | * |
| 1837 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1839 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | public Notification(int icon, CharSequence tickerText, long when) |
| 1841 | { |
| 1842 | this.icon = icon; |
| 1843 | this.tickerText = tickerText; |
| 1844 | this.when = when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1845 | this.creationTime = System.currentTimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | /** |
| 1849 | * Unflatten the notification from a parcel. |
| 1850 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 1851 | @SuppressWarnings("unchecked") |
| 1852 | public Notification(Parcel parcel) { |
| 1853 | // IMPORTANT: Add unmarshaling code in readFromParcel as the pending |
| 1854 | // intents in extras are always written as the last entry. |
| 1855 | readFromParcelImpl(parcel); |
| 1856 | // Must be read last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 1857 | allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | private void readFromParcelImpl(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1861 | { |
| 1862 | int version = parcel.readInt(); |
| 1863 | |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 1864 | whitelistToken = parcel.readStrongBinder(); |
| 1865 | if (whitelistToken == null) { |
| 1866 | whitelistToken = processWhitelistToken; |
| 1867 | } |
| 1868 | // Propagate this token to all pending intents that are unmarshalled from the parcel. |
| 1869 | parcel.setClassCookie(PendingIntent.class, whitelistToken); |
| 1870 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1871 | when = parcel.readLong(); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1872 | creationTime = parcel.readLong(); |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1873 | if (parcel.readInt() != 0) { |
| 1874 | mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 1875 | if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1876 | icon = mSmallIcon.getResId(); |
| 1877 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 1878 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | number = parcel.readInt(); |
| 1880 | if (parcel.readInt() != 0) { |
| 1881 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1882 | } |
| 1883 | if (parcel.readInt() != 0) { |
| 1884 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1885 | } |
| 1886 | if (parcel.readInt() != 0) { |
| 1887 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1888 | } |
| 1889 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1890 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1891 | } |
| 1892 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1894 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1895 | if (parcel.readInt() != 0) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1896 | mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1897 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1898 | defaults = parcel.readInt(); |
| 1899 | flags = parcel.readInt(); |
| 1900 | if (parcel.readInt() != 0) { |
| 1901 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 1902 | } |
| 1903 | |
| 1904 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1905 | if (parcel.readInt() != 0) { |
| 1906 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 1907 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1908 | vibrate = parcel.createLongArray(); |
| 1909 | ledARGB = parcel.readInt(); |
| 1910 | ledOnMS = parcel.readInt(); |
| 1911 | ledOffMS = parcel.readInt(); |
| 1912 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1913 | |
| 1914 | if (parcel.readInt() != 0) { |
| 1915 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1916 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1917 | |
| 1918 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1919 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1920 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1921 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1922 | mGroupKey = parcel.readString(); |
| 1923 | |
| 1924 | mSortKey = parcel.readString(); |
| 1925 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 1926 | extras = Bundle.setDefusable(parcel.readBundle(), true); // may be null |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1927 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1928 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 1929 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1930 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1931 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1932 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1933 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1934 | if (parcel.readInt() != 0) { |
| 1935 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1936 | } |
| 1937 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1938 | visibility = parcel.readInt(); |
| 1939 | |
| 1940 | if (parcel.readInt() != 0) { |
| 1941 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 1942 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1943 | |
| 1944 | color = parcel.readInt(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1945 | |
| 1946 | if (parcel.readInt() != 0) { |
| 1947 | mChannelId = parcel.readString(); |
| 1948 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 1949 | mTimeout = parcel.readLong(); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 1950 | |
| 1951 | if (parcel.readInt() != 0) { |
| 1952 | mShortcutId = parcel.readString(); |
| 1953 | } |
| 1954 | |
| 1955 | mBadgeIcon = parcel.readInt(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1956 | |
| 1957 | if (parcel.readInt() != 0) { |
| 1958 | mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1959 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 1960 | |
| 1961 | mGroupAlertBehavior = parcel.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1962 | } |
| 1963 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1964 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1965 | public Notification clone() { |
| 1966 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1967 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1968 | return that; |
| 1969 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1970 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1971 | /** |
| 1972 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 1973 | * of this into that. |
| 1974 | * @hide |
| 1975 | */ |
| 1976 | public void cloneInto(Notification that, boolean heavy) { |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 1977 | that.whitelistToken = this.whitelistToken; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1978 | that.when = this.when; |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 1979 | that.creationTime = this.creationTime; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1980 | that.mSmallIcon = this.mSmallIcon; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1981 | that.number = this.number; |
| 1982 | |
| 1983 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 1984 | that.contentIntent = this.contentIntent; |
| 1985 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1986 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1987 | |
| 1988 | if (this.tickerText != null) { |
| 1989 | that.tickerText = this.tickerText.toString(); |
| 1990 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1991 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1992 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1993 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1994 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1995 | that.contentView = this.contentView.clone(); |
| 1996 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1997 | if (heavy && this.mLargeIcon != null) { |
| 1998 | that.mLargeIcon = this.mLargeIcon; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1999 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 2000 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2001 | that.sound = this.sound; // android.net.Uri is immutable |
| 2002 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2003 | if (this.audioAttributes != null) { |
| 2004 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 2005 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2006 | |
| 2007 | final long[] vibrate = this.vibrate; |
| 2008 | if (vibrate != null) { |
| 2009 | final int N = vibrate.length; |
| 2010 | final long[] vib = that.vibrate = new long[N]; |
| 2011 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 2012 | } |
| 2013 | |
| 2014 | that.ledARGB = this.ledARGB; |
| 2015 | that.ledOnMS = this.ledOnMS; |
| 2016 | that.ledOffMS = this.ledOffMS; |
| 2017 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2018 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2019 | that.flags = this.flags; |
| 2020 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2021 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2022 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2023 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2024 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2025 | that.mGroupKey = this.mGroupKey; |
| 2026 | |
| 2027 | that.mSortKey = this.mSortKey; |
| 2028 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2029 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2030 | try { |
| 2031 | that.extras = new Bundle(this.extras); |
| 2032 | // will unparcel |
| 2033 | that.extras.size(); |
| 2034 | } catch (BadParcelableException e) { |
| 2035 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2036 | that.extras = null; |
| 2037 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2038 | } |
| 2039 | |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2040 | if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2041 | that.allPendingIntents = new ArraySet<>(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2044 | if (this.actions != null) { |
| 2045 | that.actions = new Action[this.actions.length]; |
| 2046 | for(int i=0; i<this.actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 2047 | if ( this.actions[i] != null) { |
| 2048 | that.actions[i] = this.actions[i].clone(); |
| 2049 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2050 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2051 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2052 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2053 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2054 | that.bigContentView = this.bigContentView.clone(); |
| 2055 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2056 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2057 | if (heavy && this.headsUpContentView != null) { |
| 2058 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 2059 | } |
| 2060 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2061 | that.visibility = this.visibility; |
| 2062 | |
| 2063 | if (this.publicVersion != null) { |
| 2064 | that.publicVersion = new Notification(); |
| 2065 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2066 | } |
| 2067 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2068 | that.color = this.color; |
| 2069 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2070 | that.mChannelId = this.mChannelId; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2071 | that.mTimeout = this.mTimeout; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2072 | that.mShortcutId = this.mShortcutId; |
| 2073 | that.mBadgeIcon = this.mBadgeIcon; |
| 2074 | that.mSettingsText = this.mSettingsText; |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2075 | that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2076 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2077 | if (!heavy) { |
| 2078 | that.lightenPayload(); // will clean out extras |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | /** |
| 2083 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 2084 | * listeners when the full contents are not necessary. |
| 2085 | * @hide |
| 2086 | */ |
| 2087 | public final void lightenPayload() { |
| 2088 | tickerView = null; |
| 2089 | contentView = null; |
| 2090 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2091 | headsUpContentView = null; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2092 | mLargeIcon = null; |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2093 | if (extras != null && !extras.isEmpty()) { |
| 2094 | final Set<String> keyset = extras.keySet(); |
| 2095 | final int N = keyset.size(); |
| 2096 | final String[] keys = keyset.toArray(new String[N]); |
| 2097 | for (int i=0; i<N; i++) { |
| 2098 | final String key = keys[i]; |
Dmitri Plotnikov | 2228136 | 2017-01-30 11:16:21 -0800 | [diff] [blame] | 2099 | if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2100 | continue; |
| 2101 | } |
Dan Sandler | 5012853 | 2015-12-08 15:42:41 -0500 | [diff] [blame] | 2102 | final Object obj = extras.get(key); |
| 2103 | if (obj != null && |
| 2104 | ( obj instanceof Parcelable |
| 2105 | || obj instanceof Parcelable[] |
| 2106 | || obj instanceof SparseArray |
| 2107 | || obj instanceof ArrayList)) { |
| 2108 | extras.remove(key); |
| 2109 | } |
| 2110 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2111 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2114 | /** |
| 2115 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 2116 | * means it had better not be some custom Parcelable implementation. |
| 2117 | * @hide |
| 2118 | */ |
| 2119 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 2120 | if (cs == null) return cs; |
| 2121 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2122 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2123 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2124 | if (cs instanceof Parcelable) { |
| 2125 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2126 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 2127 | return cs.toString(); |
| 2128 | } |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2129 | return removeTextSizeSpans(cs); |
| 2130 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2131 | |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2132 | private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2133 | if (charSequence instanceof Spanned) { |
| 2134 | Spanned ss = (Spanned) charSequence; |
| 2135 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2136 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2137 | for (Object span : spans) { |
| 2138 | Object resultSpan = span; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2139 | if (resultSpan instanceof CharacterStyle) { |
| 2140 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2141 | } |
| 2142 | if (resultSpan instanceof TextAppearanceSpan) { |
| 2143 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2144 | resultSpan = new TextAppearanceSpan( |
| 2145 | originalSpan.getFamily(), |
| 2146 | originalSpan.getTextStyle(), |
| 2147 | -1, |
| 2148 | originalSpan.getTextColor(), |
| 2149 | originalSpan.getLinkTextColor()); |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2150 | } else if (resultSpan instanceof RelativeSizeSpan |
| 2151 | || resultSpan instanceof AbsoluteSizeSpan) { |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2152 | continue; |
Selim Cinek | 89991a2 | 2016-03-07 19:51:54 -0800 | [diff] [blame] | 2153 | } else { |
| 2154 | resultSpan = span; |
Selim Cinek | 60a5425 | 2016-02-26 17:03:25 -0800 | [diff] [blame] | 2155 | } |
| 2156 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2157 | ss.getSpanFlags(span)); |
| 2158 | } |
| 2159 | return builder; |
| 2160 | } |
| 2161 | return charSequence; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2162 | } |
| 2163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2164 | public int describeContents() { |
| 2165 | return 0; |
| 2166 | } |
| 2167 | |
| 2168 | /** |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2169 | * Flatten this notification into a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | */ |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2171 | public void writeToParcel(Parcel parcel, int flags) { |
| 2172 | // We need to mark all pending intents getting into the notification |
| 2173 | // system as being put there to later allow the notification ranker |
| 2174 | // to launch them and by doing so add the app to the battery saver white |
| 2175 | // list for a short period of time. The problem is that the system |
| 2176 | // cannot look into the extras as there may be parcelables there that |
| 2177 | // the platform does not know how to handle. To go around that we have |
| 2178 | // an explicit list of the pending intents in the extras bundle. |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2179 | final boolean collectPendingIntents = (allPendingIntents == null); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2180 | if (collectPendingIntents) { |
| 2181 | PendingIntent.setOnMarshaledListener( |
| 2182 | (PendingIntent intent, Parcel out, int outFlags) -> { |
| 2183 | if (parcel == out) { |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2184 | if (allPendingIntents == null) { |
| 2185 | allPendingIntents = new ArraySet<>(); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2186 | } |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2187 | allPendingIntents.add(intent); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2188 | } |
| 2189 | }); |
| 2190 | } |
| 2191 | try { |
| 2192 | // IMPORTANT: Add marshaling code in writeToParcelImpl as we |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2193 | // want to intercept all pending events written to the parcel. |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2194 | writeToParcelImpl(parcel, flags); |
| 2195 | // Must be written last! |
Felipe Leme | dd85da6 | 2016-06-28 11:29:54 -0700 | [diff] [blame] | 2196 | parcel.writeArraySet(allPendingIntents); |
Svet Ganov | ddb9488 | 2016-06-23 19:55:24 -0700 | [diff] [blame] | 2197 | } finally { |
| 2198 | if (collectPendingIntents) { |
| 2199 | PendingIntent.setOnMarshaledListener(null); |
| 2200 | } |
| 2201 | } |
| 2202 | } |
| 2203 | |
| 2204 | private void writeToParcelImpl(Parcel parcel, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2205 | parcel.writeInt(1); |
| 2206 | |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 2207 | parcel.writeStrongBinder(whitelistToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2208 | parcel.writeLong(when); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 2209 | parcel.writeLong(creationTime); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 2210 | if (mSmallIcon == null && icon != 0) { |
| 2211 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2212 | mSmallIcon = Icon.createWithResource("", icon); |
| 2213 | } |
Dan Sandler | 3936e7a | 2015-05-19 20:59:12 -0400 | [diff] [blame] | 2214 | if (mSmallIcon != null) { |
| 2215 | parcel.writeInt(1); |
| 2216 | mSmallIcon.writeToParcel(parcel, 0); |
| 2217 | } else { |
| 2218 | parcel.writeInt(0); |
| 2219 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | parcel.writeInt(number); |
| 2221 | if (contentIntent != null) { |
| 2222 | parcel.writeInt(1); |
| 2223 | contentIntent.writeToParcel(parcel, 0); |
| 2224 | } else { |
| 2225 | parcel.writeInt(0); |
| 2226 | } |
| 2227 | if (deleteIntent != null) { |
| 2228 | parcel.writeInt(1); |
| 2229 | deleteIntent.writeToParcel(parcel, 0); |
| 2230 | } else { |
| 2231 | parcel.writeInt(0); |
| 2232 | } |
| 2233 | if (tickerText != null) { |
| 2234 | parcel.writeInt(1); |
| 2235 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 2236 | } else { |
| 2237 | parcel.writeInt(0); |
| 2238 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2239 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2240 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2241 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 2242 | } else { |
| 2243 | parcel.writeInt(0); |
| 2244 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | if (contentView != null) { |
| 2246 | parcel.writeInt(1); |
| 2247 | contentView.writeToParcel(parcel, 0); |
| 2248 | } else { |
| 2249 | parcel.writeInt(0); |
| 2250 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 2251 | if (mLargeIcon == null && largeIcon != null) { |
| 2252 | // you snuck an icon in here without using the builder; let's try to keep it |
| 2253 | mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 2254 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2255 | if (mLargeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2256 | parcel.writeInt(1); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2257 | mLargeIcon.writeToParcel(parcel, 0); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2258 | } else { |
| 2259 | parcel.writeInt(0); |
| 2260 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2261 | |
| 2262 | parcel.writeInt(defaults); |
| 2263 | parcel.writeInt(this.flags); |
| 2264 | |
| 2265 | if (sound != null) { |
| 2266 | parcel.writeInt(1); |
| 2267 | sound.writeToParcel(parcel, 0); |
| 2268 | } else { |
| 2269 | parcel.writeInt(0); |
| 2270 | } |
| 2271 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2272 | |
| 2273 | if (audioAttributes != null) { |
| 2274 | parcel.writeInt(1); |
| 2275 | audioAttributes.writeToParcel(parcel, 0); |
| 2276 | } else { |
| 2277 | parcel.writeInt(0); |
| 2278 | } |
| 2279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | parcel.writeLongArray(vibrate); |
| 2281 | parcel.writeInt(ledARGB); |
| 2282 | parcel.writeInt(ledOnMS); |
| 2283 | parcel.writeInt(ledOffMS); |
| 2284 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2285 | |
| 2286 | if (fullScreenIntent != null) { |
| 2287 | parcel.writeInt(1); |
| 2288 | fullScreenIntent.writeToParcel(parcel, 0); |
| 2289 | } else { |
| 2290 | parcel.writeInt(0); |
| 2291 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2292 | |
| 2293 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2294 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2295 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2296 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2297 | parcel.writeString(mGroupKey); |
| 2298 | |
| 2299 | parcel.writeString(mSortKey); |
| 2300 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2301 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2302 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2303 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2304 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2305 | if (bigContentView != null) { |
| 2306 | parcel.writeInt(1); |
| 2307 | bigContentView.writeToParcel(parcel, 0); |
| 2308 | } else { |
| 2309 | parcel.writeInt(0); |
| 2310 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2311 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2312 | if (headsUpContentView != null) { |
| 2313 | parcel.writeInt(1); |
| 2314 | headsUpContentView.writeToParcel(parcel, 0); |
| 2315 | } else { |
| 2316 | parcel.writeInt(0); |
| 2317 | } |
| 2318 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2319 | parcel.writeInt(visibility); |
| 2320 | |
| 2321 | if (publicVersion != null) { |
| 2322 | parcel.writeInt(1); |
| 2323 | publicVersion.writeToParcel(parcel, 0); |
| 2324 | } else { |
| 2325 | parcel.writeInt(0); |
| 2326 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2327 | |
| 2328 | parcel.writeInt(color); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2329 | |
| 2330 | if (mChannelId != null) { |
| 2331 | parcel.writeInt(1); |
| 2332 | parcel.writeString(mChannelId); |
| 2333 | } else { |
| 2334 | parcel.writeInt(0); |
| 2335 | } |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2336 | parcel.writeLong(mTimeout); |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2337 | |
| 2338 | if (mShortcutId != null) { |
| 2339 | parcel.writeInt(1); |
| 2340 | parcel.writeString(mShortcutId); |
| 2341 | } else { |
| 2342 | parcel.writeInt(0); |
| 2343 | } |
| 2344 | |
| 2345 | parcel.writeInt(mBadgeIcon); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2346 | |
| 2347 | if (mSettingsText != null) { |
| 2348 | parcel.writeInt(1); |
| 2349 | TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 2350 | } else { |
| 2351 | parcel.writeInt(0); |
| 2352 | } |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2353 | |
| 2354 | parcel.writeInt(mGroupAlertBehavior); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | /** |
| 2358 | * Parcelable.Creator that instantiates Notification objects |
| 2359 | */ |
| 2360 | public static final Parcelable.Creator<Notification> CREATOR |
| 2361 | = new Parcelable.Creator<Notification>() |
| 2362 | { |
| 2363 | public Notification createFromParcel(Parcel parcel) |
| 2364 | { |
| 2365 | return new Notification(parcel); |
| 2366 | } |
| 2367 | |
| 2368 | public Notification[] newArray(int size) |
| 2369 | { |
| 2370 | return new Notification[size]; |
| 2371 | } |
| 2372 | }; |
| 2373 | |
| 2374 | /** |
| 2375 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 2376 | * layout. |
| 2377 | * |
| 2378 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 2379 | * in the view.</p> |
| 2380 | * @param context The context for your application / activity. |
| 2381 | * @param contentTitle The title that goes in the expanded entry. |
| 2382 | * @param contentText The text that goes in the expanded entry. |
| 2383 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 2384 | * If this is an activity, it must include the |
| 2385 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 2386 | * that you take care of task management as described in the |
| 2387 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 2388 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2389 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2390 | * @deprecated Use {@link Builder} instead. |
Chris Wren | a05db38 | 2015-06-24 15:18:34 -0400 | [diff] [blame] | 2391 | * @removed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2392 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2393 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2394 | public void setLatestEventInfo(Context context, |
| 2395 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2396 | if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 2397 | Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 2398 | new Throwable()); |
| 2399 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2400 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2401 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2402 | extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2403 | } |
| 2404 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2405 | // ensure that any information already set directly is preserved |
| 2406 | final Notification.Builder builder = new Notification.Builder(context, this); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2407 | |
| 2408 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2409 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2410 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2411 | } |
| 2412 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2413 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2414 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2415 | builder.setContentIntent(contentIntent); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2416 | |
| 2417 | 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] | 2418 | } |
| 2419 | |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2420 | /** |
| 2421 | * @hide |
| 2422 | */ |
| 2423 | public static void addFieldsFromContext(Context context, Notification notification) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2424 | addFieldsFromContext(context.getApplicationInfo(), notification); |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | /** |
| 2428 | * @hide |
| 2429 | */ |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2430 | public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
Jeff Sharkey | 012bc7b | 2016-04-11 16:30:27 -0600 | [diff] [blame] | 2431 | notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 2432 | } |
| 2433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2434 | @Override |
| 2435 | public String toString() { |
| 2436 | StringBuilder sb = new StringBuilder(); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2437 | sb.append("Notification(channel="); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2438 | sb.append(getChannelId()); |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 2439 | sb.append(" pri="); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2440 | sb.append(priority); |
| 2441 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 2442 | if (contentView != null) { |
| 2443 | sb.append(contentView.getPackage()); |
| 2444 | sb.append("/0x"); |
| 2445 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 2446 | } else { |
| 2447 | sb.append("null"); |
| 2448 | } |
| 2449 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2450 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 2451 | sb.append("default"); |
| 2452 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2453 | int N = this.vibrate.length-1; |
| 2454 | sb.append("["); |
| 2455 | for (int i=0; i<N; i++) { |
| 2456 | sb.append(this.vibrate[i]); |
| 2457 | sb.append(','); |
| 2458 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 2459 | if (N != -1) { |
| 2460 | sb.append(this.vibrate[N]); |
| 2461 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2462 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | } else { |
| 2464 | sb.append("null"); |
| 2465 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2466 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2467 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2468 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 2469 | } else if (this.sound != null) { |
| 2470 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2471 | } else { |
| 2472 | sb.append("null"); |
| 2473 | } |
Chris Wren | 365b6d3 | 2015-07-16 10:39:26 -0400 | [diff] [blame] | 2474 | if (this.tickerText != null) { |
| 2475 | sb.append(" tick"); |
| 2476 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2477 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2479 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 2480 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2481 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2482 | if (this.category != null) { |
| 2483 | sb.append(" category="); |
| 2484 | sb.append(this.category); |
| 2485 | } |
| 2486 | if (this.mGroupKey != null) { |
| 2487 | sb.append(" groupKey="); |
| 2488 | sb.append(this.mGroupKey); |
| 2489 | } |
| 2490 | if (this.mSortKey != null) { |
| 2491 | sb.append(" sortKey="); |
| 2492 | sb.append(this.mSortKey); |
| 2493 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2494 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2495 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2496 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2497 | } |
| 2498 | sb.append(" vis="); |
| 2499 | sb.append(visibilityToString(this.visibility)); |
| 2500 | if (this.publicVersion != null) { |
| 2501 | sb.append(" publicVersion="); |
| 2502 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2503 | } |
| 2504 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2505 | return sb.toString(); |
| 2506 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2507 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 2508 | /** |
| 2509 | * {@hide} |
| 2510 | */ |
| 2511 | public static String visibilityToString(int vis) { |
| 2512 | switch (vis) { |
| 2513 | case VISIBILITY_PRIVATE: |
| 2514 | return "PRIVATE"; |
| 2515 | case VISIBILITY_PUBLIC: |
| 2516 | return "PUBLIC"; |
| 2517 | case VISIBILITY_SECRET: |
| 2518 | return "SECRET"; |
| 2519 | default: |
| 2520 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 2521 | } |
| 2522 | } |
| 2523 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2524 | /** |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 2525 | * {@hide} |
| 2526 | */ |
| 2527 | public static String priorityToString(@Priority int pri) { |
| 2528 | switch (pri) { |
| 2529 | case PRIORITY_MIN: |
| 2530 | return "MIN"; |
| 2531 | case PRIORITY_LOW: |
| 2532 | return "LOW"; |
| 2533 | case PRIORITY_DEFAULT: |
| 2534 | return "DEFAULT"; |
| 2535 | case PRIORITY_HIGH: |
| 2536 | return "HIGH"; |
| 2537 | case PRIORITY_MAX: |
| 2538 | return "MAX"; |
| 2539 | default: |
| 2540 | return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 2541 | } |
| 2542 | } |
| 2543 | |
Julia Reynolds | 6ad0aec | 2017-07-05 08:47:03 -0400 | [diff] [blame] | 2544 | /** |
| 2545 | * @hide |
| 2546 | */ |
| 2547 | public boolean hasCompletedProgress() { |
| 2548 | // not a progress notification; can't be complete |
| 2549 | if (!extras.containsKey(EXTRA_PROGRESS) |
| 2550 | || !extras.containsKey(EXTRA_PROGRESS_MAX)) { |
| 2551 | return false; |
| 2552 | } |
| 2553 | // many apps use max 0 for 'indeterminate'; not complete |
| 2554 | if (extras.getInt(EXTRA_PROGRESS_MAX) == 0) { |
| 2555 | return false; |
| 2556 | } |
| 2557 | return extras.getInt(EXTRA_PROGRESS) == extras.getInt(EXTRA_PROGRESS_MAX); |
| 2558 | } |
| 2559 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2560 | /** @removed */ |
| 2561 | @Deprecated |
Julia Reynolds | 3785605 | 2016-11-11 09:20:07 -0500 | [diff] [blame] | 2562 | public String getChannel() { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2563 | return mChannelId; |
| 2564 | } |
| 2565 | |
| 2566 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2567 | * Returns the id of the channel this notification posts to. |
| 2568 | */ |
| 2569 | public String getChannelId() { |
| 2570 | return mChannelId; |
| 2571 | } |
| 2572 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2573 | /** @removed */ |
| 2574 | @Deprecated |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2575 | public long getTimeout() { |
| 2576 | return mTimeout; |
| 2577 | } |
| 2578 | |
| 2579 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2580 | * Returns the duration from posting after which this notification should be canceled by the |
| 2581 | * system, if it's not canceled already. |
| 2582 | */ |
| 2583 | public long getTimeoutAfter() { |
| 2584 | return mTimeout; |
| 2585 | } |
| 2586 | |
| 2587 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2588 | * Returns what icon should be shown for this notification if it is being displayed in a |
| 2589 | * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, |
| 2590 | * {@link #BADGE_ICON_SMALL}, or {@link #BADGE_ICON_LARGE}. |
| 2591 | */ |
| 2592 | public int getBadgeIconType() { |
| 2593 | return mBadgeIcon; |
| 2594 | } |
| 2595 | |
| 2596 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2597 | * Returns the {@link ShortcutInfo#getId() id} that this notification supersedes, if any. |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2598 | * |
| 2599 | * <p>Used by some Launchers that display notification content to hide shortcuts that duplicate |
| 2600 | * notifications. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2601 | */ |
| 2602 | public String getShortcutId() { |
| 2603 | return mShortcutId; |
| 2604 | } |
| 2605 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 2606 | |
| 2607 | /** |
| 2608 | * Returns the settings text provided to {@link Builder#setSettingsText(CharSequence)}. |
| 2609 | */ |
| 2610 | public CharSequence getSettingsText() { |
| 2611 | return mSettingsText; |
| 2612 | } |
| 2613 | |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2614 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2615 | * Returns which type of notifications in a group are responsible for audibly alerting the |
| 2616 | * user. See {@link #GROUP_ALERT_ALL}, {@link #GROUP_ALERT_CHILDREN}, |
| 2617 | * {@link #GROUP_ALERT_SUMMARY}. |
| 2618 | */ |
| 2619 | public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 2620 | return mGroupAlertBehavior; |
| 2621 | } |
| 2622 | |
| 2623 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 2624 | * The small icon representing this notification in the status bar and content view. |
| 2625 | * |
| 2626 | * @return the small icon representing this notification. |
| 2627 | * |
| 2628 | * @see Builder#getSmallIcon() |
| 2629 | * @see Builder#setSmallIcon(Icon) |
| 2630 | */ |
| 2631 | public Icon getSmallIcon() { |
| 2632 | return mSmallIcon; |
| 2633 | } |
| 2634 | |
| 2635 | /** |
| 2636 | * Used when notifying to clean up legacy small icons. |
| 2637 | * @hide |
| 2638 | */ |
| 2639 | public void setSmallIcon(Icon icon) { |
| 2640 | mSmallIcon = icon; |
| 2641 | } |
| 2642 | |
| 2643 | /** |
| 2644 | * The large icon shown in this notification's content view. |
| 2645 | * @see Builder#getLargeIcon() |
| 2646 | * @see Builder#setLargeIcon(Icon) |
| 2647 | */ |
| 2648 | public Icon getLargeIcon() { |
| 2649 | return mLargeIcon; |
| 2650 | } |
| 2651 | |
| 2652 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2653 | * @hide |
| 2654 | */ |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 2655 | public boolean isGroupSummary() { |
| 2656 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 2657 | } |
| 2658 | |
| 2659 | /** |
| 2660 | * @hide |
| 2661 | */ |
| 2662 | public boolean isGroupChild() { |
| 2663 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 2664 | } |
| 2665 | |
| 2666 | /** |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 2667 | * @hide |
| 2668 | */ |
| 2669 | public boolean suppressAlertingDueToGrouping() { |
| 2670 | if (isGroupSummary() |
| 2671 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { |
| 2672 | return true; |
| 2673 | } else if (isGroupChild() |
| 2674 | && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { |
| 2675 | return true; |
| 2676 | } |
| 2677 | return false; |
| 2678 | } |
| 2679 | |
| 2680 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2681 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2682 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2683 | * 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] | 2684 | * content views using the platform's notification layout template. If your app supports |
| 2685 | * versions of Android as old as API level 4, you can instead use |
| 2686 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 2687 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 2688 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2689 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2690 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2691 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2692 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 2693 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2694 | * .setContentTitle("New mail from " + sender.toString()) |
| 2695 | * .setContentText(subject) |
| 2696 | * .setSmallIcon(R.drawable.new_mail) |
| 2697 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2698 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2699 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2700 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2701 | public static class Builder { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 2702 | /** |
| 2703 | * @hide |
| 2704 | */ |
| 2705 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 2706 | "android.rebuild.contentViewActionCount"; |
| 2707 | /** |
| 2708 | * @hide |
| 2709 | */ |
| 2710 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 2711 | = "android.rebuild.bigViewActionCount"; |
| 2712 | /** |
| 2713 | * @hide |
| 2714 | */ |
| 2715 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 2716 | = "android.rebuild.hudViewActionCount"; |
| 2717 | |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 2718 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2719 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 2720 | private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 2721 | SystemProperties.getBoolean("notifications.only_title", true); |
| 2722 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 2723 | /** |
| 2724 | * The lightness difference that has to be added to the primary text color to obtain the |
| 2725 | * secondary text color when the background is light. |
| 2726 | */ |
| 2727 | private static final int LIGHTNESS_TEXT_DIFFERENCE_LIGHT = 20; |
| 2728 | |
| 2729 | /** |
| 2730 | * The lightness difference that has to be added to the primary text color to obtain the |
| 2731 | * secondary text color when the background is dark. |
| 2732 | * A bit less then the above value, since it looks better on dark backgrounds. |
| 2733 | */ |
| 2734 | private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10; |
| 2735 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2736 | private Context mContext; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2737 | private Notification mN; |
| 2738 | private Bundle mUserExtras = new Bundle(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2739 | private Style mStyle; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2740 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
| 2741 | private ArrayList<String> mPersonList = new ArrayList<String>(); |
| 2742 | private NotificationColorUtil mColorUtil; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 2743 | private boolean mIsLegacy; |
| 2744 | private boolean mIsLegacyInitialized; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2745 | |
| 2746 | /** |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2747 | * Caches a contrast-enhanced version of {@link #mCachedContrastColorIsFor}. |
| 2748 | */ |
| 2749 | private int mCachedContrastColor = COLOR_INVALID; |
| 2750 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 2751 | /** |
| 2752 | * Caches a ambient version of {@link #mCachedContrastColorIsFor}. |
| 2753 | */ |
| 2754 | private int mCachedAmbientColor = COLOR_INVALID; |
| 2755 | private int mCachedAmbientColorIsFor = COLOR_INVALID; |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 2756 | |
| 2757 | /** |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 2758 | * Caches an instance of StandardTemplateParams. Note that this may have been used before, |
| 2759 | * so make sure to call {@link StandardTemplateParams#reset()} before using it. |
| 2760 | */ |
| 2761 | StandardTemplateParams mParams = new StandardTemplateParams(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 2762 | private int mTextColorsAreForBackground = COLOR_INVALID; |
| 2763 | private int mPrimaryTextColor = COLOR_INVALID; |
| 2764 | private int mSecondaryTextColor = COLOR_INVALID; |
| 2765 | private int mActionBarColor = COLOR_INVALID; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 2766 | private int mBackgroundColor = COLOR_INVALID; |
| 2767 | private int mForegroundColor = COLOR_INVALID; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 2768 | private int mBackgroundColorHint = COLOR_INVALID; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 2769 | /** |
| 2770 | * A temporary location where actions are stored. If != null the view originally has action |
| 2771 | * but doesn't have any for this inflation. |
| 2772 | */ |
| 2773 | private ArrayList<Action> mOriginalActions; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 2774 | private boolean mRebuildStyledRemoteViews; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 2775 | |
| 2776 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2777 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2778 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2779 | * @param context |
| 2780 | * A {@link Context} that will be used by the Builder to construct the |
| 2781 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 2782 | * object. |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 2783 | * @param channelId |
| 2784 | * The constructed Notification will be posted on this |
| 2785 | * {@link NotificationChannel}. To use a NotificationChannel, it must first be |
| 2786 | * created using {@link NotificationManager#createNotificationChannel}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2787 | */ |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 2788 | public Builder(Context context, String channelId) { |
| 2789 | this(context, (Notification) null); |
| 2790 | mN.mChannelId = channelId; |
| 2791 | } |
| 2792 | |
| 2793 | /** |
| 2794 | * @deprecated use {@link Notification.Builder#Notification.Builder(Context, String)} |
| 2795 | * instead. All posted Notifications must specify a NotificationChannel Id. |
| 2796 | */ |
| 2797 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2798 | public Builder(Context context) { |
Geoffrey Pitsch | 5caa276 | 2017-01-12 09:35:54 -0500 | [diff] [blame] | 2799 | this(context, (Notification) null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2800 | } |
| 2801 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2802 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2803 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2804 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2805 | public Builder(Context context, Notification toAdopt) { |
| 2806 | mContext = context; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2807 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2808 | if (toAdopt == null) { |
| 2809 | mN = new Notification(); |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 2810 | if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 2811 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 2812 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2813 | mN.priority = PRIORITY_DEFAULT; |
| 2814 | mN.visibility = VISIBILITY_PRIVATE; |
| 2815 | } else { |
| 2816 | mN = toAdopt; |
| 2817 | if (mN.actions != null) { |
| 2818 | Collections.addAll(mActions, mN.actions); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2819 | } |
| 2820 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2821 | if (mN.extras.containsKey(EXTRA_PEOPLE)) { |
| 2822 | Collections.addAll(mPersonList, mN.extras.getStringArray(EXTRA_PEOPLE)); |
| 2823 | } |
| 2824 | |
Selim Cinek | 4ac6f60 | 2016-06-13 15:47:03 -0700 | [diff] [blame] | 2825 | if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 2826 | setSmallIcon(mN.icon); |
| 2827 | } |
| 2828 | |
| 2829 | if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 2830 | setLargeIcon(mN.largeIcon); |
| 2831 | } |
| 2832 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2833 | String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 2834 | if (!TextUtils.isEmpty(templateClass)) { |
| 2835 | final Class<? extends Style> styleClass |
| 2836 | = getNotificationStyleClass(templateClass); |
| 2837 | if (styleClass == null) { |
| 2838 | Log.d(TAG, "Unknown style class: " + templateClass); |
| 2839 | } else { |
| 2840 | try { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 2841 | final Constructor<? extends Style> ctor = |
| 2842 | styleClass.getDeclaredConstructor(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2843 | ctor.setAccessible(true); |
| 2844 | final Style style = ctor.newInstance(); |
| 2845 | style.restoreFromExtras(mN.extras); |
| 2846 | |
| 2847 | if (style != null) { |
| 2848 | setStyle(style); |
| 2849 | } |
| 2850 | } catch (Throwable t) { |
| 2851 | Log.e(TAG, "Could not create Style", t); |
| 2852 | } |
| 2853 | } |
| 2854 | } |
| 2855 | |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | private NotificationColorUtil getColorUtil() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 2860 | if (mColorUtil == null) { |
| 2861 | mColorUtil = NotificationColorUtil.getInstance(mContext); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2862 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2863 | return mColorUtil; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2867 | * If this notification is duplicative of a Launcher shortcut, sets the |
| 2868 | * {@link ShortcutInfo#getId() id} of the shortcut, in case the Launcher wants to hide |
| 2869 | * the shortcut. |
| 2870 | * |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2871 | * This field will be ignored by Launchers that don't support badging, don't show |
| 2872 | * notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}. |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 2873 | * |
| 2874 | * @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification |
| 2875 | * supersedes |
| 2876 | */ |
| 2877 | public Builder setShortcutId(String shortcutId) { |
| 2878 | mN.mShortcutId = shortcutId; |
| 2879 | return this; |
| 2880 | } |
| 2881 | |
| 2882 | /** |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2883 | * Sets which icon to display as a badge for this notification. |
| 2884 | * |
| 2885 | * Must be one of {@link #BADGE_ICON_NONE}, {@link #BADGE_ICON_SMALL}, |
| 2886 | * {@link #BADGE_ICON_LARGE}. |
| 2887 | * |
| 2888 | * Note: This value might be ignored, for launchers that don't support badge icons. |
| 2889 | */ |
Julia Reynolds | 612beb2 | 2017-03-30 10:48:30 -0400 | [diff] [blame] | 2890 | public Builder setBadgeIconType(int icon) { |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 2891 | mN.mBadgeIcon = icon; |
| 2892 | return this; |
| 2893 | } |
| 2894 | |
| 2895 | /** |
Julia Reynolds | a79c371 | 2017-04-21 10:29:57 -0400 | [diff] [blame] | 2896 | * Sets the group alert behavior for this notification. Use this method to mute this |
| 2897 | * notification if alerts for this notification's group should be handled by a different |
| 2898 | * notification. This is only applicable for notifications that belong to a |
| 2899 | * {@link #setGroup(String) group}. |
| 2900 | * |
| 2901 | * <p> The default value is {@link #GROUP_ALERT_ALL}.</p> |
| 2902 | */ |
| 2903 | public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 2904 | mN.mGroupAlertBehavior = groupAlertBehavior; |
| 2905 | return this; |
| 2906 | } |
| 2907 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2908 | /** @removed */ |
| 2909 | @Deprecated |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 2910 | public Builder setChannel(String channelId) { |
| 2911 | mN.mChannelId = channelId; |
| 2912 | return this; |
| 2913 | } |
| 2914 | |
| 2915 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2916 | * Specifies the channel the notification should be delivered on. |
| 2917 | */ |
| 2918 | public Builder setChannelId(String channelId) { |
| 2919 | mN.mChannelId = channelId; |
| 2920 | return this; |
| 2921 | } |
| 2922 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 2923 | /** @removed */ |
| 2924 | @Deprecated |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 2925 | public Builder setTimeout(long durationMs) { |
| 2926 | mN.mTimeout = durationMs; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 2927 | return this; |
| 2928 | } |
| 2929 | |
| 2930 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 2931 | * Specifies a duration in milliseconds after which this notification should be canceled, |
| 2932 | * if it is not already canceled. |
| 2933 | */ |
| 2934 | public Builder setTimeoutAfter(long durationMs) { |
| 2935 | mN.mTimeout = durationMs; |
| 2936 | return this; |
| 2937 | } |
| 2938 | |
| 2939 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2940 | * 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] | 2941 | * |
| 2942 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not |
| 2943 | * shown anymore by default and must be opted into by using |
| 2944 | * {@link android.app.Notification.Builder#setShowWhen(boolean)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2945 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2946 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2947 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2948 | public Builder setWhen(long when) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2949 | mN.when = when; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2950 | return this; |
| 2951 | } |
| 2952 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2953 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2954 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2955 | * in the content view. |
Selim Cinek | 0ff1ce60 | 2016-04-05 18:27:16 -0700 | [diff] [blame] | 2956 | * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to |
| 2957 | * {@code false}. For earlier apps, the default is {@code true}. |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2958 | */ |
| 2959 | public Builder setShowWhen(boolean show) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2960 | mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2961 | return this; |
| 2962 | } |
| 2963 | |
| 2964 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2965 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2966 | * |
| 2967 | * 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] | 2968 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2969 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2970 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 2971 | * |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2972 | * 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] | 2973 | * {@link #setChronometerCountDown(boolean)}. |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2974 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2975 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2976 | * @see Notification#when |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 2977 | * @see #setChronometerCountDown(boolean) |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2978 | */ |
| 2979 | public Builder setUsesChronometer(boolean b) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2980 | mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2981 | return this; |
| 2982 | } |
| 2983 | |
| 2984 | /** |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2985 | * Sets the Chronometer to count down instead of counting up. |
| 2986 | * |
| 2987 | * <p>This is only relevant if {@link #setUsesChronometer(boolean)} has been set to true. |
| 2988 | * If it isn't set the chronometer will count up. |
| 2989 | * |
| 2990 | * @see #setUsesChronometer(boolean) |
| 2991 | */ |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 2992 | public Builder setChronometerCountDown(boolean countDown) { |
| 2993 | mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
Selim Cinek | 81c23aa | 2016-02-25 16:23:13 -0800 | [diff] [blame] | 2994 | return this; |
| 2995 | } |
| 2996 | |
| 2997 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2998 | * Set the small icon resource, which will be used to represent the notification in the |
| 2999 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3000 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3001 | |
| 3002 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 3003 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 3004 | * icon will be moved to the right-hand side. |
| 3005 | * |
| 3006 | |
| 3007 | * @param icon |
| 3008 | * A resource ID in the application's package of the drawable to use. |
| 3009 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3010 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3011 | public Builder setSmallIcon(@DrawableRes int icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3012 | return setSmallIcon(icon != 0 |
| 3013 | ? Icon.createWithResource(mContext, icon) |
| 3014 | : null); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3015 | } |
| 3016 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3017 | /** |
| 3018 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 3019 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 3020 | * LevelListDrawable}. |
| 3021 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3022 | * @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] | 3023 | * @param level The level to use for the icon. |
| 3024 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3025 | * @see Notification#icon |
| 3026 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3027 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 3028 | public Builder setSmallIcon(@DrawableRes int icon, int level) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3029 | mN.iconLevel = level; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3030 | return setSmallIcon(icon); |
| 3031 | } |
| 3032 | |
| 3033 | /** |
| 3034 | * Set the small icon, which will be used to represent the notification in the |
| 3035 | * status bar and content view (unless overriden there by a |
| 3036 | * {@link #setLargeIcon(Bitmap) large icon}). |
| 3037 | * |
| 3038 | * @param icon An Icon object to use. |
| 3039 | * @see Notification#icon |
| 3040 | */ |
| 3041 | public Builder setSmallIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3042 | mN.setSmallIcon(icon); |
| 3043 | if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 3044 | mN.icon = icon.getResId(); |
| 3045 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3046 | return this; |
| 3047 | } |
| 3048 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3049 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3050 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3051 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3052 | public Builder setContentTitle(CharSequence title) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3053 | mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3054 | return this; |
| 3055 | } |
| 3056 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3057 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3058 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3059 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3060 | public Builder setContentText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3061 | mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3062 | return this; |
| 3063 | } |
| 3064 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3065 | /** |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3066 | * This provides some additional information that is displayed in the notification. No |
| 3067 | * guarantees are given where exactly it is displayed. |
| 3068 | * |
| 3069 | * <p>This information should only be provided if it provides an essential |
| 3070 | * benefit to the understanding of the notification. The more text you provide the |
| 3071 | * less readable it becomes. For example, an email client should only provide the account |
| 3072 | * name here if more than one email account has been added.</p> |
| 3073 | * |
| 3074 | * <p>As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the |
| 3075 | * notification header area. |
| 3076 | * |
| 3077 | * On Android versions before {@link android.os.Build.VERSION_CODES#N} |
| 3078 | * this will be shown in the third line of text in the platform notification template. |
| 3079 | * You should not be using {@link #setProgress(int, int, boolean)} at the |
| 3080 | * same time on those versions; they occupy the same place. |
| 3081 | * </p> |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3082 | */ |
| 3083 | public Builder setSubText(CharSequence text) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3084 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3085 | return this; |
| 3086 | } |
| 3087 | |
| 3088 | /** |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 3089 | * Provides text that will appear as a link to your application's settings. |
| 3090 | * |
| 3091 | * <p>This text does not appear within notification {@link Style templates} but may |
| 3092 | * appear when the user uses an affordance to learn more about the notification. |
| 3093 | * Additionally, this text will not appear unless you provide a valid link target by |
| 3094 | * handling {@link #INTENT_CATEGORY_NOTIFICATION_PREFERENCES}. |
| 3095 | * |
| 3096 | * <p>This text is meant to be concise description about what the user can customize |
| 3097 | * when they click on this link. The recommended maximum length is 40 characters. |
| 3098 | * @param text |
| 3099 | * @return |
| 3100 | */ |
| 3101 | public Builder setSettingsText(CharSequence text) { |
| 3102 | mN.mSettingsText = safeCharSequence(text); |
| 3103 | return this; |
| 3104 | } |
| 3105 | |
| 3106 | /** |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 3107 | * Set the remote input history. |
| 3108 | * |
| 3109 | * This should be set to the most recent inputs that have been sent |
| 3110 | * through a {@link RemoteInput} of this Notification and cleared once the it is no |
| 3111 | * longer relevant (e.g. for chat notifications once the other party has responded). |
| 3112 | * |
| 3113 | * The most recent input must be stored at the 0 index, the second most recent at the |
| 3114 | * 1 index, etc. Note that the system will limit both how far back the inputs will be shown |
| 3115 | * and how much of each individual input is shown. |
| 3116 | * |
| 3117 | * <p>Note: The reply text will only be shown on notifications that have least one action |
| 3118 | * with a {@code RemoteInput}.</p> |
| 3119 | */ |
| 3120 | public Builder setRemoteInputHistory(CharSequence[] text) { |
| 3121 | if (text == null) { |
| 3122 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 3123 | } else { |
| 3124 | final int N = Math.min(MAX_REPLY_HISTORY, text.length); |
| 3125 | CharSequence[] safe = new CharSequence[N]; |
| 3126 | for (int i = 0; i < N; i++) { |
| 3127 | safe[i] = safeCharSequence(text[i]); |
| 3128 | } |
| 3129 | mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 3130 | } |
| 3131 | return this; |
| 3132 | } |
| 3133 | |
| 3134 | /** |
Julia Reynolds | 13d898c | 2017-02-02 12:22:05 -0500 | [diff] [blame] | 3135 | * Sets the number of items this notification represents. May be displayed as a badge count |
| 3136 | * for Launchers that support badging. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3137 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3138 | public Builder setNumber(int number) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3139 | mN.number = number; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3140 | return this; |
| 3141 | } |
| 3142 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3143 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3144 | * A small piece of additional information pertaining to this notification. |
| 3145 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3146 | * The platform template will draw this on the last line of the notification, at the far |
| 3147 | * 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] | 3148 | * |
| 3149 | * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. |
| 3150 | * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this |
| 3151 | * field will still show up, but the subtext will take precedence. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3152 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3153 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3154 | public Builder setContentInfo(CharSequence info) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3155 | mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3156 | return this; |
| 3157 | } |
| 3158 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3159 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3160 | * Set the progress this notification represents. |
| 3161 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3162 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3163 | */ |
| 3164 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3165 | mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 3166 | mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 3167 | mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 3168 | return this; |
| 3169 | } |
| 3170 | |
| 3171 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3172 | * Supply a custom RemoteViews to use instead of the platform template. |
| 3173 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3174 | * Use {@link #setCustomContentView(RemoteViews)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3175 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3176 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3177 | public Builder setContent(RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3178 | return setCustomContentView(views); |
| 3179 | } |
| 3180 | |
| 3181 | /** |
| 3182 | * Supply custom RemoteViews to use instead of the platform template. |
| 3183 | * |
| 3184 | * This will override the layout that would otherwise be constructed by this Builder |
| 3185 | * object. |
| 3186 | */ |
| 3187 | public Builder setCustomContentView(RemoteViews contentView) { |
| 3188 | mN.contentView = contentView; |
| 3189 | return this; |
| 3190 | } |
| 3191 | |
| 3192 | /** |
| 3193 | * Supply custom RemoteViews to use instead of the platform template in the expanded form. |
| 3194 | * |
| 3195 | * This will override the expanded layout that would otherwise be constructed by this |
| 3196 | * Builder object. |
| 3197 | */ |
| 3198 | public Builder setCustomBigContentView(RemoteViews contentView) { |
| 3199 | mN.bigContentView = contentView; |
| 3200 | return this; |
| 3201 | } |
| 3202 | |
| 3203 | /** |
| 3204 | * Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
| 3205 | * |
| 3206 | * This will override the heads-up layout that would otherwise be constructed by this |
| 3207 | * Builder object. |
| 3208 | */ |
| 3209 | public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 3210 | mN.headsUpContentView = contentView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3211 | return this; |
| 3212 | } |
| 3213 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3214 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3215 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 3216 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3217 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 3218 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 3219 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3220 | * 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] | 3221 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3222 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3223 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3224 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3225 | public Builder setContentIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3226 | mN.contentIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3227 | return this; |
| 3228 | } |
| 3229 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3230 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3231 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 3232 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3233 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3234 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3235 | public Builder setDeleteIntent(PendingIntent intent) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3236 | mN.deleteIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3237 | return this; |
| 3238 | } |
| 3239 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3240 | /** |
| 3241 | * An intent to launch instead of posting the notification to the status bar. |
| 3242 | * Only for use with extremely high-priority notifications demanding the user's |
| 3243 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 3244 | * alarm clock that the user has explicitly set to a particular time. |
| 3245 | * If this facility is used for something else, please give the user an option |
| 3246 | * to turn it off and use a normal notification, as this can be extremely |
| 3247 | * disruptive. |
| 3248 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3249 | * <p> |
| 3250 | * The system UI may choose to display a heads-up notification, instead of |
| 3251 | * launching this intent, while the user is using the device. |
| 3252 | * </p> |
| 3253 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3254 | * @param intent The pending intent to launch. |
| 3255 | * @param highPriority Passing true will cause this notification to be sent |
| 3256 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3257 | * |
| 3258 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3259 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3260 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3261 | mN.fullScreenIntent = intent; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3262 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 3263 | return this; |
| 3264 | } |
| 3265 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3266 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3267 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3268 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3269 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3270 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3271 | public Builder setTicker(CharSequence tickerText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3272 | mN.tickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3273 | return this; |
| 3274 | } |
| 3275 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3276 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3277 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3278 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3279 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3280 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3281 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3282 | setTicker(tickerText); |
| 3283 | // views is ignored |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3284 | return this; |
| 3285 | } |
| 3286 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3287 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3288 | * Add a large icon to the notification content view. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3289 | * |
| 3290 | * 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] | 3291 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3292 | * badge atop the large icon). |
Dan Sandler | 08a04c1 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3293 | */ |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 3294 | public Builder setLargeIcon(Bitmap b) { |
| 3295 | return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 3296 | } |
| 3297 | |
| 3298 | /** |
| 3299 | * Add a large icon to the notification content view. |
| 3300 | * |
| 3301 | * In the platform template, this image will be shown on the left of the notification view |
| 3302 | * in place of the {@link #setSmallIcon(Icon) small icon} (which will be placed in a small |
| 3303 | * badge atop the large icon). |
| 3304 | */ |
| 3305 | public Builder setLargeIcon(Icon icon) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3306 | mN.mLargeIcon = icon; |
| 3307 | mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3308 | return this; |
| 3309 | } |
| 3310 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3311 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3312 | * Set the sound to play. |
| 3313 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3314 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 3315 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3316 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3317 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3318 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3319 | @Deprecated |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3320 | public Builder setSound(Uri sound) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3321 | mN.sound = sound; |
| 3322 | mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 3323 | return this; |
| 3324 | } |
| 3325 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3326 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3327 | * 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] | 3328 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3329 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 3330 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3331 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)}. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3332 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 3333 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3334 | public Builder setSound(Uri sound, int streamType) { |
Jean-Michel Trivi | 2f7511f | 2016-11-28 15:40:27 -0800 | [diff] [blame] | 3335 | PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3336 | mN.sound = sound; |
| 3337 | mN.audioStreamType = streamType; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3338 | return this; |
| 3339 | } |
| 3340 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3341 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3342 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 3343 | * use during playback. |
| 3344 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3345 | * @deprecated use {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3346 | * @see Notification#sound |
| 3347 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3348 | @Deprecated |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3349 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3350 | mN.sound = sound; |
| 3351 | mN.audioAttributes = audioAttributes; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3352 | return this; |
| 3353 | } |
| 3354 | |
| 3355 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3356 | * Set the vibration pattern to use. |
| 3357 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3358 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 3359 | * <code>pattern</code> parameter. |
| 3360 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 3361 | * <p> |
| 3362 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 3363 | * </p> |
| 3364 | * |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3365 | * @deprecated use {@link NotificationChannel#setVibrationPattern(long[])} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3366 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3367 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3368 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3369 | public Builder setVibrate(long[] pattern) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3370 | mN.vibrate = pattern; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3371 | return this; |
| 3372 | } |
| 3373 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3374 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3375 | * Set the desired color for the indicator LED on the device, as well as the |
| 3376 | * blink duty cycle (specified in milliseconds). |
| 3377 | * |
| 3378 | |
| 3379 | * Not all devices will honor all (or even any) of these values. |
| 3380 | * |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3381 | * @deprecated use {@link NotificationChannel#enableLights(boolean)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3382 | * @see Notification#ledARGB |
| 3383 | * @see Notification#ledOnMS |
| 3384 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3385 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3386 | @Deprecated |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3387 | public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3388 | mN.ledARGB = argb; |
| 3389 | mN.ledOnMS = onMs; |
| 3390 | mN.ledOffMS = offMs; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3391 | if (onMs != 0 || offMs != 0) { |
| 3392 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 3393 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3394 | return this; |
| 3395 | } |
| 3396 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3397 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3398 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3399 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3400 | |
| 3401 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 3402 | * must take care of canceling them. |
| 3403 | * |
| 3404 | |
| 3405 | * They are typically used to indicate a background task that the user is actively engaged |
| 3406 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 3407 | * (e.g., a file download, sync operation, active network connection). |
| 3408 | * |
| 3409 | |
| 3410 | * @see Notification#FLAG_ONGOING_EVENT |
| 3411 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3412 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3413 | public Builder setOngoing(boolean ongoing) { |
| 3414 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 3415 | return this; |
| 3416 | } |
| 3417 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3418 | /** |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3419 | * Set whether this notification should be colorized. When set, the color set with |
| 3420 | * {@link #setColor(int)} will be used as the background color of this notification. |
| 3421 | * <p> |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3422 | * This should only be used for high priority ongoing tasks like navigation, an ongoing |
| 3423 | * call, or other similarly high-priority events for the user. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3424 | * <p> |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3425 | * For most styles, the coloring will only be applied if the notification is for a |
| 3426 | * foreground service notification. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3427 | * However, for {@link MediaStyle} and {@link DecoratedMediaCustomViewStyle} notifications |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 3428 | * that have a media session attached there is no such requirement. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3429 | * |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3430 | * @see Builder#setColor(int) |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 3431 | * @see MediaStyle#setMediaSession(MediaSession.Token) |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3432 | */ |
| 3433 | public Builder setColorized(boolean colorize) { |
| 3434 | mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 3435 | return this; |
| 3436 | } |
| 3437 | |
| 3438 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3439 | * Set this flag if you would only like the sound, vibrate |
| 3440 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3441 | * |
| 3442 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3443 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3444 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 3445 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 3446 | return this; |
| 3447 | } |
| 3448 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3449 | /** |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 3450 | * Make this notification automatically dismissed when the user touches it. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3451 | * |
| 3452 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3453 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3454 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 3455 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3456 | return this; |
| 3457 | } |
| 3458 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3459 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3460 | * Set whether or not this notification should not bridge to other devices. |
| 3461 | * |
| 3462 | * <p>Some notifications can be bridged to other devices for remote display. |
| 3463 | * This hint can be set to recommend this notification not be bridged. |
| 3464 | */ |
| 3465 | public Builder setLocalOnly(boolean localOnly) { |
| 3466 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 3467 | return this; |
| 3468 | } |
| 3469 | |
| 3470 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3471 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3472 | * <p> |
| 3473 | * The value should be one or more of the following fields combined with |
| 3474 | * bitwise-or: |
| 3475 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 3476 | * <p> |
| 3477 | * For all default values, use {@link #DEFAULT_ALL}. |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3478 | * |
| 3479 | * @deprecated use {@link NotificationChannel#enableVibration(boolean)} and |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 3480 | * {@link NotificationChannel#enableLights(boolean)} and |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3481 | * {@link NotificationChannel#setSound(Uri, AudioAttributes)} instead. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3482 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3483 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3484 | public Builder setDefaults(int defaults) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3485 | mN.defaults = defaults; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3486 | return this; |
| 3487 | } |
| 3488 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3489 | /** |
| 3490 | * Set the priority of this notification. |
| 3491 | * |
| 3492 | * @see Notification#priority |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3493 | * @deprecated use {@link NotificationChannel#setImportance(int)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3494 | */ |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 3495 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 3496 | public Builder setPriority(@Priority int pri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3497 | mN.priority = pri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3498 | return this; |
| 3499 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3500 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3501 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3502 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3503 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3504 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3505 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3506 | public Builder setCategory(String category) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3507 | mN.category = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3508 | return this; |
| 3509 | } |
| 3510 | |
| 3511 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3512 | * Add a person that is relevant to this notification. |
| 3513 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3514 | * <P> |
| 3515 | * Depending on user preferences, this annotation may allow the notification to pass |
Julia Reynolds | e071abd | 2017-03-22 10:52:11 -0400 | [diff] [blame] | 3516 | * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} |
| 3517 | * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to |
| 3518 | * appear more prominently in the user interface. |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3519 | * </P> |
| 3520 | * |
| 3521 | * <P> |
| 3522 | * The person should be specified by the {@code String} representation of a |
| 3523 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 3524 | * </P> |
| 3525 | * |
| 3526 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 3527 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 3528 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 3529 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
| 3530 | * </P> |
| 3531 | * |
| 3532 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3533 | * @see Notification#EXTRA_PEOPLE |
| 3534 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 3535 | public Builder addPerson(String uri) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3536 | mPersonList.add(uri); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3537 | return this; |
| 3538 | } |
| 3539 | |
| 3540 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3541 | * Set this notification to be part of a group of notifications sharing the same key. |
| 3542 | * Grouped notifications may display in a cluster or stack on devices which |
| 3543 | * support such rendering. |
| 3544 | * |
| 3545 | * <p>To make this notification the summary for its group, also call |
| 3546 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 3547 | * {@link #setSortKey}. |
| 3548 | * @param groupKey The group key of the group. |
| 3549 | * @return this object for method chaining |
| 3550 | */ |
| 3551 | public Builder setGroup(String groupKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3552 | mN.mGroupKey = groupKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3553 | return this; |
| 3554 | } |
| 3555 | |
| 3556 | /** |
| 3557 | * Set this notification to be the group summary for a group of notifications. |
| 3558 | * Grouped notifications may display in a cluster or stack on devices which |
Julia Reynolds | 0449953 | 2016-09-13 14:04:53 -0400 | [diff] [blame] | 3559 | * support such rendering. If thereRequires a group key also be set using {@link #setGroup}. |
| 3560 | * 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] | 3561 | * @param isGroupSummary Whether this notification should be a group summary. |
| 3562 | * @return this object for method chaining |
| 3563 | */ |
| 3564 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 3565 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 3566 | return this; |
| 3567 | } |
| 3568 | |
| 3569 | /** |
| 3570 | * Set a sort key that orders this notification among other notifications from the |
| 3571 | * same package. This can be useful if an external sort was already applied and an app |
| 3572 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 3573 | * value, although providing different priorities in addition to providing sort key may |
| 3574 | * cause this value to be ignored. |
| 3575 | * |
| 3576 | * <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] | 3577 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3578 | * |
| 3579 | * @see String#compareTo(String) |
| 3580 | */ |
| 3581 | public Builder setSortKey(String sortKey) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3582 | mN.mSortKey = sortKey; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3583 | return this; |
| 3584 | } |
| 3585 | |
| 3586 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3587 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3588 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3589 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 3590 | * |
| 3591 | * @see Notification#extras |
| 3592 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3593 | public Builder addExtras(Bundle extras) { |
| 3594 | if (extras != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3595 | mUserExtras.putAll(extras); |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3596 | } |
| 3597 | return this; |
| 3598 | } |
| 3599 | |
| 3600 | /** |
| 3601 | * Set metadata for this notification. |
| 3602 | * |
| 3603 | * <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] | 3604 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3605 | * called. |
| 3606 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3607 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 3608 | * Use {@link #addExtras} to merge in metadata instead. |
| 3609 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3610 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3611 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3612 | public Builder setExtras(Bundle extras) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3613 | if (extras != null) { |
| 3614 | mUserExtras = extras; |
| 3615 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3616 | return this; |
| 3617 | } |
| 3618 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3619 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3620 | * Get the current metadata Bundle used by this notification Builder. |
| 3621 | * |
| 3622 | * <p>The returned Bundle is shared with this Builder. |
| 3623 | * |
| 3624 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 3625 | * {@link #build()} is called. |
| 3626 | * |
| 3627 | * @see Notification#extras |
| 3628 | */ |
| 3629 | public Bundle getExtras() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3630 | return mUserExtras; |
| 3631 | } |
| 3632 | |
| 3633 | private Bundle getAllExtras() { |
| 3634 | final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 3635 | saveExtras.putAll(mN.extras); |
| 3636 | return saveExtras; |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3640 | * Add an action to this notification. Actions are typically displayed by |
| 3641 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3642 | * <p> |
| 3643 | * Every action must have an icon (32dp square and matching the |
| 3644 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 3645 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 3646 | * <p> |
| 3647 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 3648 | * the order they were added. Actions will not be displayed when the notification is |
| 3649 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 3650 | * 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] | 3651 | * |
| 3652 | * @param icon Resource ID of a drawable that represents the action. |
| 3653 | * @param title Text describing the action. |
| 3654 | * @param intent PendingIntent to be fired when the action is invoked. |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 3655 | * |
| 3656 | * @deprecated Use {@link #addAction(Action)} instead. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3657 | */ |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 3658 | @Deprecated |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3659 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3660 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3661 | return this; |
| 3662 | } |
| 3663 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3664 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3665 | * Add an action to this notification. Actions are typically displayed by |
| 3666 | * the system as a button adjacent to the notification content. |
| 3667 | * <p> |
| 3668 | * Every action must have an icon (32dp square and matching the |
| 3669 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 3670 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 3671 | * <p> |
| 3672 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 3673 | * the order they were added. Actions will not be displayed when the notification is |
| 3674 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 3675 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 3676 | * |
| 3677 | * @param action The action to add. |
| 3678 | */ |
| 3679 | public Builder addAction(Action action) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 3680 | if (action != null) { |
| 3681 | mActions.add(action); |
| 3682 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 3683 | return this; |
| 3684 | } |
| 3685 | |
| 3686 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3687 | * Alter the complete list of actions attached to this notification. |
| 3688 | * @see #addAction(Action). |
| 3689 | * |
| 3690 | * @param actions |
| 3691 | * @return |
| 3692 | */ |
| 3693 | public Builder setActions(Action... actions) { |
| 3694 | mActions.clear(); |
| 3695 | for (int i = 0; i < actions.length; i++) { |
liangweikang | 63b03b5 | 2017-03-16 19:22:15 +0800 | [diff] [blame] | 3696 | if (actions[i] != null) { |
| 3697 | mActions.add(actions[i]); |
| 3698 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3699 | } |
| 3700 | return this; |
| 3701 | } |
| 3702 | |
| 3703 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3704 | * Add a rich notification style to be applied at build time. |
| 3705 | * |
| 3706 | * @param style Object responsible for modifying the notification style. |
| 3707 | */ |
| 3708 | public Builder setStyle(Style style) { |
| 3709 | if (mStyle != style) { |
| 3710 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3711 | if (mStyle != null) { |
| 3712 | mStyle.setBuilder(this); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3713 | mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 3714 | } else { |
| 3715 | mN.extras.remove(EXTRA_TEMPLATE); |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3716 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3717 | } |
| 3718 | return this; |
| 3719 | } |
| 3720 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3721 | /** |
| 3722 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 3723 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3724 | * @return The same Builder. |
| 3725 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 3726 | public Builder setVisibility(@Visibility int visibility) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3727 | mN.visibility = visibility; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3728 | return this; |
| 3729 | } |
| 3730 | |
| 3731 | /** |
| 3732 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 3733 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 3734 | * @param n A replacement notification, presumably with some or all info redacted. |
| 3735 | * @return The same Builder. |
| 3736 | */ |
| 3737 | public Builder setPublicVersion(Notification n) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3738 | if (n != null) { |
| 3739 | mN.publicVersion = new Notification(); |
| 3740 | n.cloneInto(mN.publicVersion, /*heavy=*/ true); |
| 3741 | } else { |
| 3742 | mN.publicVersion = null; |
| 3743 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3744 | return this; |
| 3745 | } |
| 3746 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 3747 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3748 | * Apply an extender to this notification builder. Extenders may be used to add |
| 3749 | * metadata or change options on this builder. |
| 3750 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 3751 | public Builder extend(Extender extender) { |
| 3752 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3753 | return this; |
| 3754 | } |
| 3755 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 3756 | /** |
| 3757 | * @hide |
| 3758 | */ |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 3759 | public Builder setFlag(int mask, boolean value) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3760 | if (value) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3761 | mN.flags |= mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3762 | } else { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3763 | mN.flags &= ~mask; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3764 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 3765 | return this; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3766 | } |
| 3767 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3768 | /** |
| 3769 | * Sets {@link Notification#color}. |
| 3770 | * |
| 3771 | * @param argb The accent color to use |
| 3772 | * |
| 3773 | * @return The same Builder. |
| 3774 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 3775 | public Builder setColor(@ColorInt int argb) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3776 | mN.color = argb; |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 3777 | sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3778 | return this; |
| 3779 | } |
| 3780 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3781 | private Drawable getProfileBadgeDrawable() { |
Chris Wren | 66619a2 | 2016-05-12 16:42:37 -0400 | [diff] [blame] | 3782 | if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 3783 | // This user can never be a badged profile, |
| 3784 | // and also includes USER_ALL system notifications. |
| 3785 | return null; |
| 3786 | } |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 3787 | // Note: This assumes that the current user can read the profile badge of the |
| 3788 | // originating user. |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 3789 | return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 3790 | new UserHandle(mContext.getUserId()), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | private Bitmap getProfileBadge() { |
| 3794 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3795 | if (badge == null) { |
| 3796 | return null; |
| 3797 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3798 | final int size = mContext.getResources().getDimensionPixelSize( |
| 3799 | R.dimen.notification_badge_size); |
| 3800 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3801 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3802 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 3803 | badge.draw(canvas); |
| 3804 | return bitmap; |
| 3805 | } |
| 3806 | |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3807 | private void bindProfileBadge(RemoteViews contentView) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3808 | Bitmap profileBadge = getProfileBadge(); |
| 3809 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3810 | if (profileBadge != null) { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3811 | contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 3812 | contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3813 | if (isColorized()) { |
| 3814 | contentView.setDrawableParameters(R.id.profile_badge, false, -1, |
| 3815 | getPrimaryTextColor(), PorterDuff.Mode.SRC_ATOP, -1); |
| 3816 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3817 | } |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3818 | } |
| 3819 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3820 | private void resetStandardTemplate(RemoteViews contentView) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3821 | resetNotificationHeader(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3822 | resetContentMargins(contentView); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3823 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3824 | contentView.setViewVisibility(R.id.title, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3825 | contentView.setTextViewText(R.id.title, null); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3826 | contentView.setViewVisibility(R.id.text, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3827 | contentView.setTextViewText(R.id.text, null); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3828 | contentView.setViewVisibility(R.id.text_line_1, View.GONE); |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3829 | contentView.setTextViewText(R.id.text_line_1, null); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3830 | } |
| 3831 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 3832 | /** |
| 3833 | * Resets the notification header to its original state |
| 3834 | */ |
| 3835 | private void resetNotificationHeader(RemoteViews contentView) { |
Adrian Roos | c4337a3 | 2016-08-02 18:30:34 -0700 | [diff] [blame] | 3836 | // Small icon doesn't need to be reset, as it's always set. Resetting would prevent |
| 3837 | // re-using the drawable when the notification is updated. |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 3838 | contentView.setBoolean(R.id.notification_header, "setExpanded", false); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3839 | contentView.setTextViewText(R.id.app_name_text, null); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 3840 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3841 | contentView.setViewVisibility(R.id.header_text, View.GONE); |
Adrian Roos | 9dfb78f | 2016-06-30 15:43:44 -0700 | [diff] [blame] | 3842 | contentView.setTextViewText(R.id.header_text, null); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 3843 | contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3844 | contentView.setViewVisibility(R.id.time_divider, View.GONE); |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 3845 | contentView.setViewVisibility(R.id.time, View.GONE); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3846 | contentView.setImageViewIcon(R.id.profile_badge, null); |
| 3847 | contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | private void resetContentMargins(RemoteViews contentView) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 3851 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 3852 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3853 | } |
| 3854 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3855 | private RemoteViews applyStandardTemplate(int resId) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3856 | return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this)); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3857 | } |
| 3858 | |
| 3859 | /** |
| 3860 | * @param hasProgress whether the progress bar should be shown and set |
| 3861 | */ |
| 3862 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3863 | return applyStandardTemplate(resId, mParams.reset().hasProgress(hasProgress) |
| 3864 | .fillTextsFrom(this)); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 3865 | } |
| 3866 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3867 | private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3868 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 3869 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 3870 | resetStandardTemplate(contentView); |
| 3871 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 3872 | final Bundle ex = mN.extras; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3873 | updateBackgroundColor(contentView); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 3874 | bindNotificationHeader(contentView, p.ambient); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 3875 | bindLargeIcon(contentView); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3876 | boolean showProgress = handleProgressBar(p.hasProgress, contentView, ex); |
| 3877 | if (p.title != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 3878 | contentView.setViewVisibility(R.id.title, View.VISIBLE); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3879 | contentView.setTextViewText(R.id.title, p.title); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 3880 | if (!p.ambient) { |
| 3881 | setTextViewColorPrimary(contentView, R.id.title); |
| 3882 | } |
Selim Cinek | 954cc23 | 2016-05-20 13:29:23 -0700 | [diff] [blame] | 3883 | contentView.setViewLayoutWidth(R.id.title, showProgress |
| 3884 | ? ViewGroup.LayoutParams.WRAP_CONTENT |
| 3885 | : ViewGroup.LayoutParams.MATCH_PARENT); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3886 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3887 | if (p.text != null) { |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3888 | int textId = showProgress ? com.android.internal.R.id.text_line_1 |
| 3889 | : com.android.internal.R.id.text; |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 3890 | contentView.setTextViewText(textId, p.text); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 3891 | if (!p.ambient) { |
| 3892 | setTextViewColorSecondary(contentView, textId); |
| 3893 | } |
Selim Cinek | 4159873 | 2016-01-11 16:58:37 -0800 | [diff] [blame] | 3894 | contentView.setViewVisibility(textId, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 3895 | } |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 3896 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 3897 | setContentMinHeight(contentView, showProgress || mN.hasLargeIcon()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3898 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 3899 | return contentView; |
| 3900 | } |
| 3901 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3902 | private void setTextViewColorPrimary(RemoteViews contentView, int id) { |
| 3903 | ensureColors(); |
| 3904 | contentView.setTextColor(id, mPrimaryTextColor); |
| 3905 | } |
| 3906 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3907 | /** |
| 3908 | * @return the primary text color |
| 3909 | * @hide |
| 3910 | */ |
| 3911 | @VisibleForTesting |
| 3912 | public int getPrimaryTextColor() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3913 | ensureColors(); |
| 3914 | return mPrimaryTextColor; |
| 3915 | } |
| 3916 | |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3917 | /** |
| 3918 | * @return the secondary text color |
| 3919 | * @hide |
| 3920 | */ |
| 3921 | @VisibleForTesting |
| 3922 | public int getSecondaryTextColor() { |
| 3923 | ensureColors(); |
| 3924 | return mSecondaryTextColor; |
| 3925 | } |
| 3926 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3927 | private int getActionBarColor() { |
| 3928 | ensureColors(); |
| 3929 | return mActionBarColor; |
| 3930 | } |
| 3931 | |
Selim Cinek | 622c64a | 2017-04-17 17:10:05 -0700 | [diff] [blame] | 3932 | private int getActionBarColorDeEmphasized() { |
| 3933 | int backgroundColor = getBackgroundColor(); |
| 3934 | return NotificationColorUtil.getShiftedColor(backgroundColor, 12); |
| 3935 | } |
| 3936 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 3937 | private void setTextViewColorSecondary(RemoteViews contentView, int id) { |
| 3938 | ensureColors(); |
| 3939 | contentView.setTextColor(id, mSecondaryTextColor); |
| 3940 | } |
| 3941 | |
| 3942 | private void ensureColors() { |
| 3943 | int backgroundColor = getBackgroundColor(); |
| 3944 | if (mPrimaryTextColor == COLOR_INVALID |
| 3945 | || mSecondaryTextColor == COLOR_INVALID |
| 3946 | || mActionBarColor == COLOR_INVALID |
| 3947 | || mTextColorsAreForBackground != backgroundColor) { |
| 3948 | mTextColorsAreForBackground = backgroundColor; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3949 | if (mForegroundColor == COLOR_INVALID || !isColorized()) { |
| 3950 | mPrimaryTextColor = NotificationColorUtil.resolvePrimaryColor(mContext, |
| 3951 | backgroundColor); |
| 3952 | mSecondaryTextColor = NotificationColorUtil.resolveSecondaryColor(mContext, |
| 3953 | backgroundColor); |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 3954 | if (backgroundColor != COLOR_DEFAULT |
| 3955 | && (mBackgroundColorHint != COLOR_INVALID || isColorized())) { |
| 3956 | mPrimaryTextColor = NotificationColorUtil.findAlphaToMeetContrast( |
| 3957 | mPrimaryTextColor, backgroundColor, 4.5); |
| 3958 | mSecondaryTextColor = NotificationColorUtil.findAlphaToMeetContrast( |
| 3959 | mSecondaryTextColor, backgroundColor, 4.5); |
| 3960 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3961 | } else { |
| 3962 | double backLum = NotificationColorUtil.calculateLuminance(backgroundColor); |
| 3963 | double textLum = NotificationColorUtil.calculateLuminance(mForegroundColor); |
| 3964 | double contrast = NotificationColorUtil.calculateContrast(mForegroundColor, |
| 3965 | backgroundColor); |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3966 | // We only respect the given colors if worst case Black or White still has |
| 3967 | // contrast |
| 3968 | boolean backgroundLight = backLum > textLum |
| 3969 | && satisfiesTextContrast(backgroundColor, Color.BLACK) |
| 3970 | || backLum <= textLum |
| 3971 | && !satisfiesTextContrast(backgroundColor, Color.WHITE); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3972 | if (contrast < 4.5f) { |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3973 | if (backgroundLight) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3974 | mSecondaryTextColor = NotificationColorUtil.findContrastColor( |
| 3975 | mForegroundColor, |
| 3976 | backgroundColor, |
| 3977 | true /* findFG */, |
| 3978 | 4.5f); |
| 3979 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3980 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_LIGHT); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3981 | } else { |
| 3982 | mSecondaryTextColor = |
| 3983 | NotificationColorUtil.findContrastColorAgainstDark( |
| 3984 | mForegroundColor, |
| 3985 | backgroundColor, |
| 3986 | true /* findFG */, |
| 3987 | 4.5f); |
| 3988 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3989 | mSecondaryTextColor, -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3990 | } |
| 3991 | } else { |
| 3992 | mPrimaryTextColor = mForegroundColor; |
| 3993 | mSecondaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3994 | mPrimaryTextColor, backgroundLight ? LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 3995 | : LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 3996 | if (NotificationColorUtil.calculateContrast(mSecondaryTextColor, |
| 3997 | backgroundColor) < 4.5f) { |
| 3998 | // oh well the secondary is not good enough |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 3999 | if (backgroundLight) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4000 | mSecondaryTextColor = NotificationColorUtil.findContrastColor( |
| 4001 | mSecondaryTextColor, |
| 4002 | backgroundColor, |
| 4003 | true /* findFG */, |
| 4004 | 4.5f); |
| 4005 | } else { |
| 4006 | mSecondaryTextColor |
| 4007 | = NotificationColorUtil.findContrastColorAgainstDark( |
| 4008 | mSecondaryTextColor, |
| 4009 | backgroundColor, |
| 4010 | true /* findFG */, |
| 4011 | 4.5f); |
| 4012 | } |
| 4013 | mPrimaryTextColor = NotificationColorUtil.changeColorLightness( |
Selim Cinek | 389edcd | 2017-05-11 19:16:44 -0700 | [diff] [blame] | 4014 | mSecondaryTextColor, backgroundLight |
| 4015 | ? -LIGHTNESS_TEXT_DIFFERENCE_LIGHT |
| 4016 | : -LIGHTNESS_TEXT_DIFFERENCE_DARK); |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 4017 | } |
| 4018 | } |
| 4019 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 4020 | mActionBarColor = NotificationColorUtil.resolveActionBarColor(mContext, |
| 4021 | backgroundColor); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4022 | } |
| 4023 | } |
| 4024 | |
| 4025 | private void updateBackgroundColor(RemoteViews contentView) { |
| 4026 | if (isColorized()) { |
| 4027 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
| 4028 | getBackgroundColor()); |
| 4029 | } else { |
| 4030 | // Clear it! |
| 4031 | contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 4032 | 0); |
| 4033 | } |
| 4034 | } |
| 4035 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 4036 | /** |
| 4037 | * @param remoteView the remote view to update the minheight in |
| 4038 | * @param hasMinHeight does it have a mimHeight |
| 4039 | * @hide |
| 4040 | */ |
| 4041 | void setContentMinHeight(RemoteViews remoteView, boolean hasMinHeight) { |
| 4042 | int minHeight = 0; |
| 4043 | if (hasMinHeight) { |
| 4044 | // we need to set the minHeight of the notification |
| 4045 | minHeight = mContext.getResources().getDimensionPixelSize( |
| 4046 | com.android.internal.R.dimen.notification_min_content_height); |
| 4047 | } |
| 4048 | remoteView.setInt(R.id.notification_main_column, "setMinimumHeight", minHeight); |
| 4049 | } |
| 4050 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4051 | private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4052 | final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 4053 | final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 4054 | final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 4055 | if (hasProgress && (max != 0 || ind)) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4056 | contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4057 | contentView.setProgressBar( |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4058 | R.id.progress, max, progress, ind); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4059 | contentView.setProgressBackgroundTintList( |
| 4060 | R.id.progress, ColorStateList.valueOf(mContext.getColor( |
| 4061 | R.color.notification_progress_background_color))); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4062 | if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4063 | ColorStateList colorStateList = ColorStateList.valueOf(resolveContrastColor()); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4064 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 4065 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 4066 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4067 | return true; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4068 | } else { |
| 4069 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4070 | return false; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 4071 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 4072 | } |
| 4073 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4074 | private void bindLargeIcon(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4075 | if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 4076 | mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 4077 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4078 | if (mN.mLargeIcon != null) { |
| 4079 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 4080 | contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon); |
| 4081 | processLargeLegacyIcon(mN.mLargeIcon, contentView); |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 4082 | int endMargin = R.dimen.notification_content_picture_margin; |
| 4083 | contentView.setViewLayoutMarginEndDimen(R.id.line1, endMargin); |
| 4084 | contentView.setViewLayoutMarginEndDimen(R.id.text, endMargin); |
| 4085 | contentView.setViewLayoutMarginEndDimen(R.id.progress, endMargin); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4086 | // Bind the reply action |
| 4087 | Action action = findReplyAction(); |
| 4088 | contentView.setViewVisibility(R.id.reply_icon_action, action != null |
| 4089 | ? View.VISIBLE |
| 4090 | : View.GONE); |
| 4091 | |
| 4092 | if (action != null) { |
| 4093 | int contrastColor = resolveContrastColor(); |
| 4094 | contentView.setDrawableParameters(R.id.reply_icon_action, |
| 4095 | true /* targetBackground */, |
| 4096 | -1, |
| 4097 | contrastColor, |
| 4098 | PorterDuff.Mode.SRC_ATOP, -1); |
| 4099 | int iconColor = NotificationColorUtil.isColorLight(contrastColor) |
| 4100 | ? Color.BLACK : Color.WHITE; |
| 4101 | contentView.setDrawableParameters(R.id.reply_icon_action, |
| 4102 | false /* targetBackground */, |
| 4103 | -1, |
| 4104 | iconColor, |
| 4105 | PorterDuff.Mode.SRC_ATOP, -1); |
| 4106 | contentView.setOnClickPendingIntent(R.id.right_icon, |
| 4107 | action.actionIntent); |
| 4108 | contentView.setOnClickPendingIntent(R.id.reply_icon_action, |
| 4109 | action.actionIntent); |
| 4110 | contentView.setRemoteInputs(R.id.right_icon, action.mRemoteInputs); |
| 4111 | contentView.setRemoteInputs(R.id.reply_icon_action, action.mRemoteInputs); |
| 4112 | |
| 4113 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4114 | } |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 4115 | contentView.setViewVisibility(R.id.right_icon_container, mN.mLargeIcon != null |
| 4116 | ? View.VISIBLE |
| 4117 | : View.GONE); |
| 4118 | } |
| 4119 | |
| 4120 | private Action findReplyAction() { |
| 4121 | ArrayList<Action> actions = mActions; |
| 4122 | if (mOriginalActions != null) { |
| 4123 | actions = mOriginalActions; |
| 4124 | } |
| 4125 | int numActions = actions.size(); |
| 4126 | for (int i = 0; i < numActions; i++) { |
| 4127 | Action action = actions.get(i); |
| 4128 | if (hasValidRemoteInput(action)) { |
| 4129 | return action; |
| 4130 | } |
| 4131 | } |
| 4132 | return null; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4135 | private void bindNotificationHeader(RemoteViews contentView, boolean ambient) { |
| 4136 | bindSmallIcon(contentView, ambient); |
| 4137 | bindHeaderAppName(contentView, ambient); |
| 4138 | if (!ambient) { |
| 4139 | // Ambient view does not have these |
| 4140 | bindHeaderText(contentView); |
| 4141 | bindHeaderChronometerAndTime(contentView); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4142 | bindProfileBadge(contentView); |
| 4143 | } |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 4144 | bindExpandButton(contentView); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4145 | } |
| 4146 | |
| 4147 | private void bindExpandButton(RemoteViews contentView) { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4148 | int color = getPrimaryHighlightColor(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4149 | contentView.setDrawableParameters(R.id.expand_button, false, -1, color, |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4150 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4151 | contentView.setInt(R.id.notification_header, "setOriginalNotificationColor", |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4152 | color); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4153 | } |
| 4154 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4155 | /** |
| 4156 | * @return the color that is used as the first primary highlight color. This is applied |
| 4157 | * in several places like the action buttons or the app name in the header. |
| 4158 | */ |
| 4159 | private int getPrimaryHighlightColor() { |
| 4160 | return isColorized() ? getPrimaryTextColor() : resolveContrastColor(); |
| 4161 | } |
| 4162 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4163 | private void bindHeaderChronometerAndTime(RemoteViews contentView) { |
| 4164 | if (showsTimeOrChronometer()) { |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4165 | contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4166 | setTextViewColorSecondary(contentView, R.id.time_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4167 | if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 4168 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 4169 | contentView.setLong(R.id.chronometer, "setBase", |
| 4170 | mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 4171 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4172 | boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
Selim Cinek | c3b752e | 2016-04-20 16:13:59 -0700 | [diff] [blame] | 4173 | contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4174 | setTextViewColorSecondary(contentView, R.id.chronometer); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4175 | } else { |
| 4176 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 4177 | contentView.setLong(R.id.time, "setTime", mN.when); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4178 | setTextViewColorSecondary(contentView, R.id.time); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4179 | } |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4180 | } else { |
| 4181 | // We still want a time to be set but gone, such that we can show and hide it |
| 4182 | // on demand in case it's a child notification without anything in the header |
| 4183 | 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] | 4184 | } |
| 4185 | } |
| 4186 | |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4187 | private void bindHeaderText(RemoteViews contentView) { |
| 4188 | CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 4189 | if (headerText == null && mStyle != null && mStyle.mSummaryTextSet |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4190 | && mStyle.hasSummaryInHeader()) { |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4191 | headerText = mStyle.mSummaryText; |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 4192 | } |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4193 | if (headerText == null |
| 4194 | && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 4195 | && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 4196 | headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 4197 | } |
| 4198 | if (headerText != null) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4199 | // 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] | 4200 | contentView.setTextViewText(R.id.header_text, processLegacyText(headerText)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4201 | setTextViewColorSecondary(contentView, R.id.header_text); |
Selim Cinek | 0f9dd1e | 2016-04-05 17:03:40 -0700 | [diff] [blame] | 4202 | contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 4203 | contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4204 | setTextViewColorSecondary(contentView, R.id.header_text_divider); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4205 | } |
| 4206 | } |
| 4207 | |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 4208 | /** |
| 4209 | * @hide |
| 4210 | */ |
| 4211 | public String loadHeaderAppName() { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4212 | CharSequence name = null; |
| 4213 | final PackageManager pm = mContext.getPackageManager(); |
| 4214 | if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 4215 | // only system packages which lump together a bunch of unrelated stuff |
| 4216 | // may substitute a different name to make the purpose of the |
| 4217 | // notification more clear. the correct package label should always |
| 4218 | // be accessible via SystemUI. |
| 4219 | final String pkg = mContext.getPackageName(); |
| 4220 | final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 4221 | if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 4222 | android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 4223 | name = subName; |
| 4224 | } else { |
| 4225 | Log.w(TAG, "warning: pkg " |
| 4226 | + pkg + " attempting to substitute app name '" + subName |
| 4227 | + "' without holding perm " |
| 4228 | + android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 4229 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4230 | } |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4231 | if (TextUtils.isEmpty(name)) { |
| 4232 | name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 4233 | } |
| 4234 | if (TextUtils.isEmpty(name)) { |
| 4235 | // still nothing? |
| 4236 | return null; |
| 4237 | } |
| 4238 | |
| 4239 | return String.valueOf(name); |
| 4240 | } |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4241 | private void bindHeaderAppName(RemoteViews contentView, boolean ambient) { |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 4242 | contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4243 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4244 | setTextViewColorPrimary(contentView, R.id.app_name_text); |
| 4245 | } else { |
| 4246 | contentView.setTextColor(R.id.app_name_text, |
| 4247 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
| 4248 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4249 | } |
| 4250 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4251 | private void bindSmallIcon(RemoteViews contentView, boolean ambient) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4252 | if (mN.mSmallIcon == null && mN.icon != 0) { |
| 4253 | mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 4254 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4255 | contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
Adrian Roos | 9b45a15 | 2016-06-28 13:32:29 -0700 | [diff] [blame] | 4256 | contentView.setDrawableParameters(R.id.icon, false /* targetBackground */, |
| 4257 | -1 /* alpha */, -1 /* colorFilter */, null /* mode */, mN.iconLevel); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4258 | processSmallIconColor(mN.mSmallIcon, contentView, ambient); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4259 | } |
| 4260 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4261 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4262 | * @return true if the built notification will show the time or the chronometer; false |
| 4263 | * otherwise |
| 4264 | */ |
| 4265 | private boolean showsTimeOrChronometer() { |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 4266 | return mN.showsTime() || mN.showsChronometer(); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4267 | } |
| 4268 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4269 | private void resetStandardTemplateWithActions(RemoteViews big) { |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4270 | // actions_container is only reset when there are no actions to avoid focus issues with |
| 4271 | // remote inputs. |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4272 | big.setViewVisibility(R.id.actions, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4273 | big.removeAllViews(R.id.actions); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4274 | |
| 4275 | big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 4276 | big.setTextViewText(R.id.notification_material_reply_text_1, null); |
| 4277 | |
| 4278 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 4279 | big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 4280 | big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 4281 | big.setTextViewText(R.id.notification_material_reply_text_3, null); |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 4282 | |
| 4283 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, 0); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4284 | } |
| 4285 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4286 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4287 | return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this)); |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 4288 | } |
| 4289 | |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 4290 | private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 4291 | StandardTemplateParams p) { |
| 4292 | RemoteViews big = applyStandardTemplate(layoutId, p); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4293 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 4294 | resetStandardTemplateWithActions(big); |
| 4295 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4296 | boolean validRemoteInput = false; |
| 4297 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4298 | int N = mActions.size(); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4299 | boolean emphazisedMode = mN.fullScreenIntent != null && !p.ambient; |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4300 | big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4301 | if (N > 0) { |
Adrian Roos | 7052de5 | 2016-03-03 15:53:34 -0800 | [diff] [blame] | 4302 | big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4303 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4304 | if (p.ambient) { |
| 4305 | big.setInt(R.id.actions, "setBackgroundColor", Color.TRANSPARENT); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4306 | } else if (isColorized()) { |
| 4307 | big.setInt(R.id.actions, "setBackgroundColor", getActionBarColor()); |
| 4308 | } else { |
| 4309 | big.setInt(R.id.actions, "setBackgroundColor", mContext.getColor( |
| 4310 | R.color.notification_action_list)); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4311 | } |
Adrian Roos | f852a42 | 2016-06-03 13:33:43 -0700 | [diff] [blame] | 4312 | big.setViewLayoutMarginBottomDimen(R.id.notification_action_list_margin_target, |
| 4313 | R.dimen.notification_action_list_height); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4314 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4315 | for (int i=0; i<N; i++) { |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4316 | Action action = mActions.get(i); |
| 4317 | validRemoteInput |= hasValidRemoteInput(action); |
| 4318 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4319 | final RemoteViews button = generateActionButton(action, emphazisedMode, |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4320 | i % 2 != 0, p.ambient); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4321 | big.addView(R.id.actions, button); |
| 4322 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 4323 | } else { |
| 4324 | big.setViewVisibility(R.id.actions_container, View.GONE); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4325 | } |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4326 | |
| 4327 | CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4328 | if (!p.ambient && validRemoteInput && replyText != null |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4329 | && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) { |
| 4330 | big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
| 4331 | big.setTextViewText(R.id.notification_material_reply_text_1, replyText[0]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4332 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_1); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4333 | |
| 4334 | if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) { |
| 4335 | big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
| 4336 | big.setTextViewText(R.id.notification_material_reply_text_2, replyText[1]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4337 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_2); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4338 | |
| 4339 | if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) { |
| 4340 | big.setViewVisibility( |
| 4341 | R.id.notification_material_reply_text_3, View.VISIBLE); |
| 4342 | big.setTextViewText(R.id.notification_material_reply_text_3, replyText[2]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4343 | setTextViewColorSecondary(big, R.id.notification_material_reply_text_3); |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4344 | } |
| 4345 | } |
| 4346 | } |
| 4347 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4348 | return big; |
| 4349 | } |
| 4350 | |
Adrian Roos | e458aa8 | 2015-12-08 16:17:19 -0800 | [diff] [blame] | 4351 | private boolean hasValidRemoteInput(Action action) { |
| 4352 | if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 4353 | // Weird actions |
| 4354 | return false; |
| 4355 | } |
| 4356 | |
| 4357 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 4358 | if (remoteInputs == null) { |
| 4359 | return false; |
| 4360 | } |
| 4361 | |
| 4362 | for (RemoteInput r : remoteInputs) { |
| 4363 | CharSequence[] choices = r.getChoices(); |
| 4364 | if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 4365 | return true; |
| 4366 | } |
| 4367 | } |
| 4368 | return false; |
| 4369 | } |
| 4370 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4371 | /** |
| 4372 | * Construct a RemoteViews for the final 1U notification layout. In order: |
| 4373 | * 1. Custom contentView from the caller |
| 4374 | * 2. Style's proposed content view |
| 4375 | * 3. Standard template view |
| 4376 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4377 | public RemoteViews createContentView() { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4378 | return createContentView(false /* increasedheight */ ); |
| 4379 | } |
| 4380 | |
| 4381 | /** |
| 4382 | * Construct a RemoteViews for the smaller content view. |
| 4383 | * |
| 4384 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 4385 | * styles may support showing more then just that basic 1U size |
| 4386 | * and the system may decide to render important notifications |
| 4387 | * slightly bigger even when collapsed. |
| 4388 | * |
| 4389 | * @hide |
| 4390 | */ |
| 4391 | public RemoteViews createContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4392 | if (mN.contentView != null && useExistingRemoteView()) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4393 | return mN.contentView; |
| 4394 | } else if (mStyle != null) { |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 4395 | final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4396 | if (styleView != null) { |
| 4397 | return styleView; |
| 4398 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4399 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4400 | return applyStandardTemplate(getBaseLayoutResource()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4401 | } |
| 4402 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4403 | private boolean useExistingRemoteView() { |
| 4404 | return mStyle == null || (!mStyle.displayCustomViewInline() |
| 4405 | && !mRebuildStyledRemoteViews); |
| 4406 | } |
| 4407 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4408 | /** |
| 4409 | * Construct a RemoteViews for the final big notification layout. |
| 4410 | */ |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4411 | public RemoteViews createBigContentView() { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4412 | RemoteViews result = null; |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4413 | if (mN.bigContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4414 | return mN.bigContentView; |
| 4415 | } else if (mStyle != null) { |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4416 | result = mStyle.makeBigContentView(); |
Selim Cinek | 90dcf6d | 2015-11-18 20:24:13 -0800 | [diff] [blame] | 4417 | hideLine1Text(result); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4418 | } else if (mActions.size() != 0) { |
| 4419 | result = applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4420 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4421 | makeHeaderExpanded(result); |
Selim Cinek | 850a854 | 2015-11-11 11:48:36 -0500 | [diff] [blame] | 4422 | return result; |
| 4423 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4424 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4425 | /** |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4426 | * Construct a RemoteViews for the final notification header only. This will not be |
| 4427 | * colorized. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4428 | * |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4429 | * @param ambient if true, generate the header for the ambient display layout. |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4430 | * @hide |
| 4431 | */ |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4432 | public RemoteViews makeNotificationHeader(boolean ambient) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4433 | Boolean colorized = (Boolean) mN.extras.get(EXTRA_COLORIZED); |
| 4434 | mN.extras.putBoolean(EXTRA_COLORIZED, false); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4435 | RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4436 | ambient ? R.layout.notification_template_ambient_header |
| 4437 | : R.layout.notification_template_header); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4438 | resetNotificationHeader(header); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4439 | bindNotificationHeader(header, ambient); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 4440 | if (colorized != null) { |
| 4441 | mN.extras.putBoolean(EXTRA_COLORIZED, colorized); |
| 4442 | } else { |
| 4443 | mN.extras.remove(EXTRA_COLORIZED); |
| 4444 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 4445 | return header; |
| 4446 | } |
| 4447 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4448 | /** |
| 4449 | * Construct a RemoteViews for the ambient version of the notification. |
| 4450 | * |
| 4451 | * @hide |
| 4452 | */ |
| 4453 | public RemoteViews makeAmbientNotification() { |
| 4454 | RemoteViews ambient = applyStandardTemplateWithActions( |
| 4455 | R.layout.notification_template_material_ambient, |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 4456 | mParams.reset().ambient(true).fillTextsFrom(this).hasProgress(false)); |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4457 | return ambient; |
| 4458 | } |
| 4459 | |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4460 | private void hideLine1Text(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4461 | if (result != null) { |
| 4462 | result.setViewVisibility(R.id.text_line_1, View.GONE); |
| 4463 | } |
Selim Cinek | 2960346 | 2015-11-17 19:04:39 -0800 | [diff] [blame] | 4464 | } |
| 4465 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4466 | /** |
| 4467 | * Adapt the Notification header if this view is used as an expanded view. |
| 4468 | * |
| 4469 | * @hide |
| 4470 | */ |
| 4471 | public static void makeHeaderExpanded(RemoteViews result) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 4472 | if (result != null) { |
| 4473 | result.setBoolean(R.id.notification_header, "setExpanded", true); |
| 4474 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4475 | } |
| 4476 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4477 | /** |
| 4478 | * Construct a RemoteViews for the final heads-up notification layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4479 | * |
| 4480 | * @param increasedHeight true if this layout be created with an increased height. Some |
| 4481 | * styles may support showing more then just that basic 1U size |
| 4482 | * and the system may decide to render important notifications |
| 4483 | * slightly bigger even when collapsed. |
| 4484 | * |
| 4485 | * @hide |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4486 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4487 | public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4488 | if (mN.headsUpContentView != null && useExistingRemoteView()) { |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4489 | return mN.headsUpContentView; |
| 4490 | } else if (mStyle != null) { |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4491 | final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 4492 | if (styleView != null) { |
| 4493 | return styleView; |
| 4494 | } |
Julia Reynolds | 089e3e4 | 2015-11-18 09:59:57 -0500 | [diff] [blame] | 4495 | } else if (mActions.size() == 0) { |
| 4496 | return null; |
| 4497 | } |
| 4498 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4499 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 4500 | } |
| 4501 | |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4502 | /** |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 4503 | * Construct a RemoteViews for the final heads-up notification layout. |
| 4504 | */ |
| 4505 | public RemoteViews createHeadsUpContentView() { |
| 4506 | return createHeadsUpContentView(false /* useIncreasedHeight */); |
| 4507 | } |
| 4508 | |
| 4509 | /** |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4510 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 4511 | * |
| 4512 | * @hide |
| 4513 | */ |
| 4514 | public RemoteViews makePublicContentView() { |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4515 | return makePublicView(false /* ambient */); |
| 4516 | } |
| 4517 | |
| 4518 | /** |
| 4519 | * Construct a RemoteViews for the display in public contexts like on the lockscreen. |
| 4520 | * |
| 4521 | * @hide |
| 4522 | */ |
| 4523 | public RemoteViews makePublicAmbientNotification() { |
| 4524 | return makePublicView(true /* ambient */); |
| 4525 | } |
| 4526 | |
| 4527 | private RemoteViews makePublicView(boolean ambient) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4528 | if (mN.publicVersion != null) { |
| 4529 | final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4530 | return ambient ? builder.makeAmbientNotification() : builder.createContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4531 | } |
| 4532 | Bundle savedBundle = mN.extras; |
| 4533 | Style style = mStyle; |
| 4534 | mStyle = null; |
| 4535 | Icon largeIcon = mN.mLargeIcon; |
| 4536 | mN.mLargeIcon = null; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4537 | Bitmap largeIconLegacy = mN.largeIcon; |
| 4538 | mN.largeIcon = null; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 4539 | ArrayList<Action> actions = mActions; |
| 4540 | mActions = new ArrayList<>(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4541 | Bundle publicExtras = new Bundle(); |
| 4542 | publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 4543 | savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 4544 | publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 4545 | savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 4546 | publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 4547 | savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4548 | mN.extras = publicExtras; |
Selim Cinek | 499c20f | 2017-07-20 14:06:09 -0700 | [diff] [blame^] | 4549 | RemoteViews view; |
| 4550 | if (ambient) { |
| 4551 | publicExtras.putCharSequence(EXTRA_TITLE, |
| 4552 | mContext.getString(com.android.internal.R.string.notification_hidden_text)); |
| 4553 | view = makeAmbientNotification(); |
| 4554 | } else{ |
| 4555 | view = makeNotificationHeader(false /* ambient */); |
| 4556 | view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true); |
| 4557 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4558 | mN.extras = savedBundle; |
| 4559 | mN.mLargeIcon = largeIcon; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 4560 | mN.largeIcon = largeIconLegacy; |
Adrian Roos | b19b06b | 2017-05-02 18:54:40 -0700 | [diff] [blame] | 4561 | mActions = actions; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4562 | mStyle = style; |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 4563 | return view; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4564 | } |
| 4565 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4566 | /** |
| 4567 | * Construct a content view for the display when low - priority |
| 4568 | * |
| 4569 | * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise |
| 4570 | * a new subtext is created consisting of the content of the |
| 4571 | * notification. |
| 4572 | * @hide |
| 4573 | */ |
| 4574 | public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
| 4575 | int color = mN.color; |
| 4576 | mN.color = COLOR_DEFAULT; |
| 4577 | CharSequence summary = mN.extras.getCharSequence(EXTRA_SUB_TEXT); |
| 4578 | if (!useRegularSubtext || TextUtils.isEmpty(summary)) { |
| 4579 | CharSequence newSummary = createSummaryText(); |
| 4580 | if (!TextUtils.isEmpty(newSummary)) { |
| 4581 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, newSummary); |
| 4582 | } |
| 4583 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 4584 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 4585 | RemoteViews header = makeNotificationHeader(false /* ambient */); |
Selim Cinek | 1b55439 | 2017-02-28 17:22:49 -0800 | [diff] [blame] | 4586 | header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4587 | if (summary != null) { |
| 4588 | mN.extras.putCharSequence(EXTRA_SUB_TEXT, summary); |
| 4589 | } else { |
| 4590 | mN.extras.remove(EXTRA_SUB_TEXT); |
| 4591 | } |
| 4592 | mN.color = color; |
| 4593 | return header; |
| 4594 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 4595 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 4596 | private CharSequence createSummaryText() { |
| 4597 | CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 4598 | if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 4599 | return titleText; |
| 4600 | } |
| 4601 | SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 4602 | if (titleText == null) { |
| 4603 | titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 4604 | } |
| 4605 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 4606 | if (titleText != null) { |
| 4607 | summary.append(bidi.unicodeWrap(titleText)); |
| 4608 | } |
| 4609 | CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 4610 | if (titleText != null && contentText != null) { |
| 4611 | summary.append(bidi.unicodeWrap(mContext.getText( |
| 4612 | R.string.notification_header_divider_symbol_with_spaces))); |
| 4613 | } |
| 4614 | if (contentText != null) { |
| 4615 | summary.append(bidi.unicodeWrap(contentText)); |
| 4616 | } |
| 4617 | return summary; |
| 4618 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 4619 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4620 | private RemoteViews generateActionButton(Action action, boolean emphazisedMode, |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4621 | boolean oddAction, boolean ambient) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4622 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 4623 | RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4624 | emphazisedMode ? getEmphasizedActionLayoutResource() |
| 4625 | : tombstone ? getActionTombstoneLayoutResource() |
| 4626 | : getActionLayoutResource()); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 4627 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 4628 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 4629 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4630 | button.setContentDescription(R.id.action0, action.title); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 4631 | if (action.mRemoteInputs != null) { |
| 4632 | button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 4633 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4634 | // TODO: handle emphasized mode / actions right |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4635 | if (emphazisedMode) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4636 | // change the background bgColor |
Selim Cinek | 622c64a | 2017-04-17 17:10:05 -0700 | [diff] [blame] | 4637 | int bgColor; |
| 4638 | if (isColorized()) { |
| 4639 | bgColor = oddAction ? getActionBarColor() : getActionBarColorDeEmphasized(); |
| 4640 | } else { |
| 4641 | bgColor = mContext.getColor(oddAction ? R.color.notification_action_list |
| 4642 | : R.color.notification_action_list_dark); |
| 4643 | } |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4644 | button.setDrawableParameters(R.id.button_holder, true, -1, bgColor, |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4645 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4646 | CharSequence title = action.title; |
| 4647 | ColorStateList[] outResultColor = null; |
| 4648 | if (isLegacy()) { |
| 4649 | title = clearColorSpans(title); |
| 4650 | } else { |
| 4651 | outResultColor = new ColorStateList[1]; |
| 4652 | title = ensureColorSpanContrast(title, bgColor, outResultColor); |
| 4653 | } |
| 4654 | button.setTextViewText(R.id.action0, title); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4655 | setTextViewColorPrimary(button, R.id.action0); |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4656 | if (outResultColor != null && outResultColor[0] != null) { |
| 4657 | // We need to set the text color as well since changing a text to uppercase |
| 4658 | // clears its spans. |
| 4659 | button.setTextColor(R.id.action0, outResultColor[0]); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4660 | } else if (mN.color != COLOR_DEFAULT && !isColorized()) { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4661 | button.setTextColor(R.id.action0,resolveContrastColor()); |
| 4662 | } |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4663 | } else { |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4664 | button.setTextViewText(R.id.action0, processLegacyText(action.title)); |
Adrian Roos | 7217162 | 2017-01-27 10:32:06 -0800 | [diff] [blame] | 4665 | if (isColorized() && !ambient) { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4666 | setTextViewColorPrimary(button, R.id.action0); |
| 4667 | } else if (mN.color != COLOR_DEFAULT) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4668 | button.setTextColor(R.id.action0, |
| 4669 | ambient ? resolveAmbientColor() : resolveContrastColor()); |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 4670 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 4671 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 4672 | return button; |
| 4673 | } |
| 4674 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4675 | /** |
Selim Cinek | 981962e | 2016-07-20 20:41:58 -0700 | [diff] [blame] | 4676 | * Clears all color spans of a text |
| 4677 | * @param charSequence the input text |
| 4678 | * @return the same text but without color spans |
| 4679 | */ |
| 4680 | private CharSequence clearColorSpans(CharSequence charSequence) { |
| 4681 | if (charSequence instanceof Spanned) { |
| 4682 | Spanned ss = (Spanned) charSequence; |
| 4683 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 4684 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 4685 | for (Object span : spans) { |
| 4686 | Object resultSpan = span; |
| 4687 | if (resultSpan instanceof CharacterStyle) { |
| 4688 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 4689 | } |
| 4690 | if (resultSpan instanceof TextAppearanceSpan) { |
| 4691 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 4692 | if (originalSpan.getTextColor() != null) { |
| 4693 | resultSpan = new TextAppearanceSpan( |
| 4694 | originalSpan.getFamily(), |
| 4695 | originalSpan.getTextStyle(), |
| 4696 | originalSpan.getTextSize(), |
| 4697 | null, |
| 4698 | originalSpan.getLinkTextColor()); |
| 4699 | } |
| 4700 | } else if (resultSpan instanceof ForegroundColorSpan |
| 4701 | || (resultSpan instanceof BackgroundColorSpan)) { |
| 4702 | continue; |
| 4703 | } else { |
| 4704 | resultSpan = span; |
| 4705 | } |
| 4706 | builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 4707 | ss.getSpanFlags(span)); |
| 4708 | } |
| 4709 | return builder; |
| 4710 | } |
| 4711 | return charSequence; |
| 4712 | } |
| 4713 | |
| 4714 | /** |
| 4715 | * Ensures contrast on color spans against a background color. also returns the color of the |
| 4716 | * text if a span was found that spans over the whole text. |
| 4717 | * |
| 4718 | * @param charSequence the charSequence on which the spans are |
| 4719 | * @param background the background color to ensure the contrast against |
| 4720 | * @param outResultColor an array in which a color will be returned as the first element if |
| 4721 | * there exists a full length color span. |
| 4722 | * @return the contrasted charSequence |
| 4723 | */ |
| 4724 | private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background, |
| 4725 | ColorStateList[] outResultColor) { |
| 4726 | if (charSequence instanceof Spanned) { |
| 4727 | Spanned ss = (Spanned) charSequence; |
| 4728 | Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 4729 | SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 4730 | for (Object span : spans) { |
| 4731 | Object resultSpan = span; |
| 4732 | int spanStart = ss.getSpanStart(span); |
| 4733 | int spanEnd = ss.getSpanEnd(span); |
| 4734 | boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 4735 | if (resultSpan instanceof CharacterStyle) { |
| 4736 | resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 4737 | } |
| 4738 | if (resultSpan instanceof TextAppearanceSpan) { |
| 4739 | TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 4740 | ColorStateList textColor = originalSpan.getTextColor(); |
| 4741 | if (textColor != null) { |
| 4742 | int[] colors = textColor.getColors(); |
| 4743 | int[] newColors = new int[colors.length]; |
| 4744 | for (int i = 0; i < newColors.length; i++) { |
| 4745 | newColors[i] = NotificationColorUtil.ensureLargeTextContrast( |
| 4746 | colors[i], background); |
| 4747 | } |
| 4748 | textColor = new ColorStateList(textColor.getStates().clone(), |
| 4749 | newColors); |
| 4750 | resultSpan = new TextAppearanceSpan( |
| 4751 | originalSpan.getFamily(), |
| 4752 | originalSpan.getTextStyle(), |
| 4753 | originalSpan.getTextSize(), |
| 4754 | textColor, |
| 4755 | originalSpan.getLinkTextColor()); |
| 4756 | if (fullLength) { |
| 4757 | outResultColor[0] = new ColorStateList( |
| 4758 | textColor.getStates().clone(), newColors); |
| 4759 | } |
| 4760 | } |
| 4761 | } else if (resultSpan instanceof ForegroundColorSpan) { |
| 4762 | ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 4763 | int foregroundColor = originalSpan.getForegroundColor(); |
| 4764 | foregroundColor = NotificationColorUtil.ensureLargeTextContrast( |
| 4765 | foregroundColor, background); |
| 4766 | resultSpan = new ForegroundColorSpan(foregroundColor); |
| 4767 | if (fullLength) { |
| 4768 | outResultColor[0] = ColorStateList.valueOf(foregroundColor); |
| 4769 | } |
| 4770 | } else { |
| 4771 | resultSpan = span; |
| 4772 | } |
| 4773 | |
| 4774 | builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 4775 | } |
| 4776 | return builder; |
| 4777 | } |
| 4778 | return charSequence; |
| 4779 | } |
| 4780 | |
| 4781 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4782 | * @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] | 4783 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4784 | */ |
| 4785 | private boolean isLegacy() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 4786 | if (!mIsLegacyInitialized) { |
| 4787 | mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 4788 | < Build.VERSION_CODES.LOLLIPOP; |
| 4789 | mIsLegacyInitialized = true; |
| 4790 | } |
| 4791 | return mIsLegacy; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4792 | } |
| 4793 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4794 | private CharSequence processLegacyText(CharSequence charSequence) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 4795 | return processLegacyText(charSequence, false /* ambient */); |
| 4796 | } |
| 4797 | |
| 4798 | private CharSequence processLegacyText(CharSequence charSequence, boolean ambient) { |
| 4799 | boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
| 4800 | boolean wantLightText = ambient; |
| 4801 | if (isAlreadyLightText != wantLightText) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4802 | return getColorUtil().invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4803 | } else { |
| 4804 | return charSequence; |
| 4805 | } |
| 4806 | } |
| 4807 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4808 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4809 | * Apply any necessariy colors to the small icon |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4810 | */ |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4811 | private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
| 4812 | boolean ambient) { |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4813 | boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 4814 | int color = ambient ? resolveAmbientColor() : getPrimaryHighlightColor(); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4815 | if (colorable) { |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4816 | contentView.setDrawableParameters(R.id.icon, false, -1, color, |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 4817 | PorterDuff.Mode.SRC_ATOP, -1); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4818 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4819 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 4820 | contentView.setInt(R.id.notification_header, "setOriginalIconColor", |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4821 | colorable ? color : NotificationHeaderView.NO_COLOR); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4822 | } |
| 4823 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4824 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4825 | * Make the largeIcon dark if it's a fake smallIcon (that is, |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4826 | * if it's grayscale). |
| 4827 | */ |
| 4828 | // TODO: also check bounds, transparency, that sort of thing. |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 4829 | private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView) { |
| 4830 | if (largeIcon != null && isLegacy() |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4831 | && getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 4832 | // resolve color will fall back to the default when legacy |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4833 | contentView.setDrawableParameters(R.id.icon, false, -1, resolveContrastColor(), |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 4834 | PorterDuff.Mode.SRC_ATOP, -1); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 4835 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4836 | } |
| 4837 | |
Julia Reynolds | 10ee1fc | 2015-11-09 11:04:55 -0500 | [diff] [blame] | 4838 | private void sanitizeColor() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4839 | if (mN.color != COLOR_DEFAULT) { |
| 4840 | mN.color |= 0xFF000000; // no alpha for custom colors |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 4841 | } |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 4842 | } |
| 4843 | |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4844 | int resolveContrastColor() { |
| 4845 | if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) { |
| 4846 | return mCachedContrastColor; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4847 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4848 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4849 | int color; |
| 4850 | int background = mBackgroundColorHint; |
| 4851 | if (mBackgroundColorHint == COLOR_INVALID) { |
| 4852 | background = mContext.getColor( |
| 4853 | com.android.internal.R.color.notification_material_background_color); |
| 4854 | } |
| 4855 | if (mN.color == COLOR_DEFAULT) { |
| 4856 | ensureColors(); |
| 4857 | color = mSecondaryTextColor; |
| 4858 | } else { |
| 4859 | color = NotificationColorUtil.resolveContrastColor(mContext, mN.color, |
| 4860 | background); |
| 4861 | } |
| 4862 | if (Color.alpha(color) < 255) { |
| 4863 | // alpha doesn't go well for color filters, so let's blend it manually |
| 4864 | color = NotificationColorUtil.compositeColors(color, background); |
| 4865 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 4866 | mCachedContrastColorIsFor = mN.color; |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 4867 | return mCachedContrastColor = color; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 4868 | } |
| 4869 | |
Adrian Roos | 487374f | 2017-01-11 15:48:14 -0800 | [diff] [blame] | 4870 | int resolveAmbientColor() { |
| 4871 | if (mCachedAmbientColorIsFor == mN.color && mCachedAmbientColorIsFor != COLOR_INVALID) { |
| 4872 | return mCachedAmbientColor; |
| 4873 | } |
| 4874 | final int contrasted = NotificationColorUtil.resolveAmbientColor(mContext, mN.color); |
| 4875 | |
| 4876 | mCachedAmbientColorIsFor = mN.color; |
| 4877 | return mCachedAmbientColor = contrasted; |
| 4878 | } |
| 4879 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4880 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4881 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4882 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 4883 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4884 | public Notification buildUnstyled() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4885 | if (mActions.size() > 0) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4886 | mN.actions = new Action[mActions.size()]; |
| 4887 | mActions.toArray(mN.actions); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 4888 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4889 | if (!mPersonList.isEmpty()) { |
| 4890 | mN.extras.putStringArray(EXTRA_PEOPLE, |
| 4891 | mPersonList.toArray(new String[mPersonList.size()])); |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 4892 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 4893 | if (mN.bigContentView != null || mN.contentView != null |
| 4894 | || mN.headsUpContentView != null) { |
| 4895 | mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 4896 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4897 | return mN; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 4898 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4899 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4900 | /** |
| 4901 | * Creates a Builder from an existing notification so further changes can be made. |
| 4902 | * @param context The context for your application / activity. |
| 4903 | * @param n The notification to create a Builder from. |
| 4904 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4905 | public static Notification.Builder recoverBuilder(Context context, Notification n) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4906 | // Re-create notification context so we can access app resources. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4907 | ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 4908 | EXTRA_BUILDER_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4909 | Context builderContext; |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4910 | if (applicationInfo != null) { |
| 4911 | try { |
| 4912 | builderContext = context.createApplicationContext(applicationInfo, |
| 4913 | Context.CONTEXT_RESTRICTED); |
| 4914 | } catch (NameNotFoundException e) { |
| 4915 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 4916 | builderContext = context; // try with our context |
| 4917 | } |
| 4918 | } else { |
| 4919 | builderContext = context; // try with given context |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4920 | } |
| 4921 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4922 | return new Builder(builderContext, n); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4923 | } |
| 4924 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4925 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4926 | * @deprecated Use {@link #build()} instead. |
| 4927 | */ |
| 4928 | @Deprecated |
| 4929 | public Notification getNotification() { |
| 4930 | return build(); |
| 4931 | } |
| 4932 | |
| 4933 | /** |
| 4934 | * Combine all of the options that have been set and return a new {@link Notification} |
| 4935 | * object. |
| 4936 | */ |
| 4937 | public Notification build() { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4938 | // first, add any extras from the calling code |
| 4939 | if (mUserExtras != null) { |
| 4940 | mN.extras = getAllExtras(); |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 4941 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4942 | |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 4943 | mN.creationTime = System.currentTimeMillis(); |
| 4944 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4945 | // lazy stuff from mContext; see comment in Builder(Context, Notification) |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 4946 | Notification.addFieldsFromContext(mContext, mN); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 4947 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4948 | buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4949 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4950 | if (mStyle != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4951 | mStyle.buildStyled(mN); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4952 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4953 | |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 4954 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 4955 | && (useExistingRemoteView())) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4956 | if (mN.contentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4957 | mN.contentView = createContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4958 | mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 4959 | mN.contentView.getSequenceNumber()); |
| 4960 | } |
| 4961 | if (mN.bigContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4962 | mN.bigContentView = createBigContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4963 | if (mN.bigContentView != null) { |
| 4964 | mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 4965 | mN.bigContentView.getSequenceNumber()); |
| 4966 | } |
| 4967 | } |
| 4968 | if (mN.headsUpContentView == null) { |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 4969 | mN.headsUpContentView = createHeadsUpContentView(); |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4970 | if (mN.headsUpContentView != null) { |
| 4971 | mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 4972 | mN.headsUpContentView.getSequenceNumber()); |
| 4973 | } |
| 4974 | } |
| 4975 | } |
| 4976 | |
Julia Reynolds | 4c0c202 | 2016-02-02 15:11:59 -0500 | [diff] [blame] | 4977 | if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 4978 | mN.flags |= FLAG_SHOW_LIGHTS; |
| 4979 | } |
| 4980 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 4981 | return mN; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4982 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 4983 | |
| 4984 | /** |
| 4985 | * Apply this Builder to an existing {@link Notification} object. |
| 4986 | * |
| 4987 | * @hide |
| 4988 | */ |
| 4989 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 4990 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 4991 | return n; |
| 4992 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4993 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 4994 | /** |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 4995 | * Removes RemoteViews that were created for compatibility from {@param n}, if they did not |
| 4996 | * change. |
| 4997 | * |
| 4998 | * @return {@param n}, if no stripping is needed, otherwise a stripped clone of {@param n}. |
| 4999 | * |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5000 | * @hide |
| 5001 | */ |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5002 | public static Notification maybeCloneStrippedForDelivery(Notification n) { |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5003 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5004 | |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5005 | // Only strip views for known Styles because we won't know how to |
| 5006 | // re-create them otherwise. |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5007 | if (!TextUtils.isEmpty(templateClass) |
| 5008 | && getNotificationStyleClass(templateClass) == null) { |
| 5009 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5010 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5011 | |
| 5012 | // Only strip unmodified BuilderRemoteViews. |
| 5013 | boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5014 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5015 | n.contentView.getSequenceNumber(); |
| 5016 | boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5017 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5018 | n.bigContentView.getSequenceNumber(); |
| 5019 | boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5020 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5021 | n.headsUpContentView.getSequenceNumber(); |
| 5022 | |
| 5023 | // Nothing to do here, no need to clone. |
| 5024 | if (!stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
| 5025 | return n; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5026 | } |
Adrian Roos | 184bfe02 | 2016-03-03 13:41:44 -0800 | [diff] [blame] | 5027 | |
| 5028 | Notification clone = n.clone(); |
| 5029 | if (stripContentView) { |
| 5030 | clone.contentView = null; |
| 5031 | clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 5032 | } |
| 5033 | if (stripBigContentView) { |
| 5034 | clone.bigContentView = null; |
| 5035 | clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 5036 | } |
| 5037 | if (stripHeadsUpContentView) { |
| 5038 | clone.headsUpContentView = null; |
| 5039 | clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 5040 | } |
| 5041 | return clone; |
Julia Reynolds | d4ea741 | 2016-02-17 14:00:56 -0500 | [diff] [blame] | 5042 | } |
| 5043 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5044 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5045 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5049 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5050 | } |
| 5051 | |
| 5052 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5053 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 5057 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5058 | } |
| 5059 | |
| 5060 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5061 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5062 | } |
| 5063 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5064 | private int getMessagingLayoutResource() { |
| 5065 | return R.layout.notification_template_material_messaging; |
| 5066 | } |
| 5067 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5068 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5069 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5070 | } |
| 5071 | |
Selim Cinek | 06e9e1f | 2016-07-08 17:14:16 -0700 | [diff] [blame] | 5072 | private int getEmphasizedActionLayoutResource() { |
| 5073 | return R.layout.notification_material_action_emphasized; |
| 5074 | } |
| 5075 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5076 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 5077 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5078 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5079 | |
| 5080 | private int getBackgroundColor() { |
| 5081 | if (isColorized()) { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5082 | return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : mN.color; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5083 | } else { |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5084 | return mBackgroundColorHint != COLOR_INVALID ? mBackgroundColorHint |
| 5085 | : COLOR_DEFAULT; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5086 | } |
| 5087 | } |
| 5088 | |
| 5089 | private boolean isColorized() { |
| 5090 | return mN.isColorized(); |
| 5091 | } |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5092 | |
| 5093 | private boolean textColorsNeedInversion() { |
| 5094 | if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 5095 | return false; |
| 5096 | } |
| 5097 | int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 5098 | return targetSdkVersion > Build.VERSION_CODES.M |
| 5099 | && targetSdkVersion < Build.VERSION_CODES.O; |
| 5100 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5101 | |
| 5102 | /** |
| 5103 | * Set a color palette to be used as the background and textColors |
| 5104 | * |
| 5105 | * @param backgroundColor the color to be used as the background |
| 5106 | * @param foregroundColor the color to be used as the foreground |
| 5107 | * |
| 5108 | * @hide |
| 5109 | */ |
| 5110 | public void setColorPalette(int backgroundColor, int foregroundColor) { |
| 5111 | mBackgroundColor = backgroundColor; |
| 5112 | mForegroundColor = foregroundColor; |
| 5113 | mTextColorsAreForBackground = COLOR_INVALID; |
| 5114 | ensureColors(); |
| 5115 | } |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 5116 | |
| 5117 | /** |
| 5118 | * Sets the background color for this notification to be a different one then the default. |
| 5119 | * This is mainly used to calculate contrast and won't necessarily be applied to the |
| 5120 | * background. |
| 5121 | * |
| 5122 | * @hide |
| 5123 | */ |
| 5124 | public void setBackgroundColorHint(int backgroundColor) { |
| 5125 | mBackgroundColorHint = backgroundColor; |
| 5126 | } |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 5127 | |
| 5128 | |
| 5129 | /** |
| 5130 | * Forces all styled remoteViews to be built from scratch and not use any cached |
| 5131 | * RemoteViews. |
| 5132 | * This is needed for legacy apps that are baking in their remoteviews into the |
| 5133 | * notification. |
| 5134 | * |
| 5135 | * @hide |
| 5136 | */ |
| 5137 | public void setRebuildStyledRemoteViews(boolean rebuild) { |
| 5138 | mRebuildStyledRemoteViews = rebuild; |
| 5139 | } |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5143 | * @return whether this notification is a foreground service notification |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5144 | */ |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5145 | private boolean isForegroundService() { |
| 5146 | return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5147 | } |
| 5148 | |
| 5149 | /** |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5150 | * @return whether this notification has a media session attached |
| 5151 | * @hide |
| 5152 | */ |
| 5153 | public boolean hasMediaSession() { |
| 5154 | return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; |
| 5155 | } |
| 5156 | |
| 5157 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5158 | * @return the style class of this notification |
| 5159 | * @hide |
| 5160 | */ |
| 5161 | public Class<? extends Notification.Style> getNotificationStyle() { |
| 5162 | String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 5163 | |
| 5164 | if (!TextUtils.isEmpty(templateClass)) { |
| 5165 | return Notification.getNotificationStyleClass(templateClass); |
| 5166 | } |
| 5167 | return null; |
| 5168 | } |
| 5169 | |
| 5170 | /** |
Selim Cinek | 22714f1 | 2017-04-13 16:23:53 -0700 | [diff] [blame] | 5171 | * @return true if this notification is colorized. |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5172 | * |
| 5173 | * @hide |
| 5174 | */ |
| 5175 | public boolean isColorized() { |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5176 | if (isColorizedMedia()) { |
| 5177 | return true; |
| 5178 | } |
Julia Reynolds | d71c5a9 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 5179 | return extras.getBoolean(EXTRA_COLORIZED) |
| 5180 | && (hasColorizedPermission() || isForegroundService()); |
| 5181 | } |
| 5182 | |
| 5183 | /** |
| 5184 | * Returns whether an app can colorize due to the android.permission.USE_COLORIZED_NOTIFICATIONS |
| 5185 | * permission. The permission is checked when a notification is enqueued. |
| 5186 | */ |
| 5187 | private boolean hasColorizedPermission() { |
| 5188 | return (flags & Notification.FLAG_CAN_COLORIZE) != 0; |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | /** |
| 5192 | * @return true if this notification is colorized and it is a media notification |
| 5193 | * |
| 5194 | * @hide |
| 5195 | */ |
| 5196 | public boolean isColorizedMedia() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 5197 | Class<? extends Style> style = getNotificationStyle(); |
| 5198 | if (MediaStyle.class.equals(style)) { |
| 5199 | Boolean colorized = (Boolean) extras.get(EXTRA_COLORIZED); |
| 5200 | if ((colorized == null || colorized) && hasMediaSession()) { |
| 5201 | return true; |
| 5202 | } |
| 5203 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 5204 | if (extras.getBoolean(EXTRA_COLORIZED) && hasMediaSession()) { |
| 5205 | return true; |
| 5206 | } |
| 5207 | } |
Selim Cinek | 5fb73f8 | 2017-04-20 16:55:38 -0700 | [diff] [blame] | 5208 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5209 | } |
| 5210 | |
Selim Cinek | 0847acd | 2017-04-24 19:48:29 -0700 | [diff] [blame] | 5211 | |
| 5212 | /** |
| 5213 | * @return true if this is a media notification |
| 5214 | * |
| 5215 | * @hide |
| 5216 | */ |
| 5217 | public boolean isMediaNotification() { |
| 5218 | Class<? extends Style> style = getNotificationStyle(); |
| 5219 | if (MediaStyle.class.equals(style)) { |
| 5220 | return true; |
| 5221 | } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { |
| 5222 | return true; |
| 5223 | } |
| 5224 | return false; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5225 | } |
| 5226 | |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5227 | private boolean hasLargeIcon() { |
| 5228 | return mLargeIcon != null || largeIcon != null; |
| 5229 | } |
| 5230 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5231 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5232 | * @return true if the notification will show the time; false otherwise |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5233 | * @hide |
| 5234 | */ |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5235 | public boolean showsTime() { |
Selim Cinek | b85f36fd | 2016-04-20 18:46:36 -0700 | [diff] [blame] | 5236 | return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 5237 | } |
| 5238 | |
| 5239 | /** |
Selim Cinek | c2c0b04 | 2016-05-18 17:13:46 -0700 | [diff] [blame] | 5240 | * @return true if the notification will show a chronometer; false otherwise |
| 5241 | * @hide |
| 5242 | */ |
| 5243 | public boolean showsChronometer() { |
| 5244 | return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 5245 | } |
| 5246 | |
| 5247 | /** |
Julia Reynolds | 4a02afb | 2016-12-13 13:39:52 -0500 | [diff] [blame] | 5248 | * @hide |
| 5249 | */ |
| 5250 | @SystemApi |
| 5251 | public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 5252 | Class<? extends Style>[] classes = new Class[] { |
| 5253 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 5254 | DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 5255 | MessagingStyle.class }; |
| 5256 | for (Class<? extends Style> innerClass : classes) { |
| 5257 | if (templateClass.equals(innerClass.getName())) { |
| 5258 | return innerClass; |
| 5259 | } |
| 5260 | } |
| 5261 | return null; |
| 5262 | } |
| 5263 | |
| 5264 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5265 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 5266 | * object. |
| 5267 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 5268 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5269 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 5270 | |
| 5271 | /** |
| 5272 | * @hide |
| 5273 | */ |
| 5274 | protected CharSequence mSummaryText = null; |
| 5275 | |
| 5276 | /** |
| 5277 | * @hide |
| 5278 | */ |
| 5279 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5280 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5281 | protected Builder mBuilder; |
| 5282 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5283 | /** |
| 5284 | * Overrides ContentTitle in the big form of the template. |
| 5285 | * This defaults to the value passed to setContentTitle(). |
| 5286 | */ |
| 5287 | protected void internalSetBigContentTitle(CharSequence title) { |
| 5288 | mBigContentTitle = title; |
| 5289 | } |
| 5290 | |
| 5291 | /** |
| 5292 | * Set the first line of text after the detail section in the big form of the template. |
| 5293 | */ |
| 5294 | protected void internalSetSummaryText(CharSequence cs) { |
| 5295 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 5296 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5297 | } |
| 5298 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5299 | public void setBuilder(Builder builder) { |
| 5300 | if (mBuilder != builder) { |
| 5301 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 5302 | if (mBuilder != null) { |
| 5303 | mBuilder.setStyle(this); |
| 5304 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5305 | } |
| 5306 | } |
| 5307 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5308 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5309 | if (mBuilder == null) { |
| 5310 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 5311 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5312 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5313 | |
| 5314 | protected RemoteViews getStandardView(int layoutId) { |
| 5315 | checkBuilder(); |
| 5316 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5317 | // Nasty. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5318 | CharSequence oldBuilderContentTitle = |
| 5319 | mBuilder.getAllExtras().getCharSequence(EXTRA_TITLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5320 | if (mBigContentTitle != null) { |
| 5321 | mBuilder.setContentTitle(mBigContentTitle); |
| 5322 | } |
| 5323 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5324 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 5325 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5326 | mBuilder.getAllExtras().putCharSequence(EXTRA_TITLE, oldBuilderContentTitle); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5327 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5328 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 5329 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 5330 | } else { |
| 5331 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5332 | } |
| 5333 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5334 | return contentView; |
| 5335 | } |
| 5336 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5337 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5338 | * Construct a Style-specific RemoteViews for the collapsed notification layout. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5339 | * The default implementation has nothing additional to add. |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5340 | * |
| 5341 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5342 | * @hide |
| 5343 | */ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5344 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5345 | return null; |
| 5346 | } |
| 5347 | |
| 5348 | /** |
| 5349 | * Construct a Style-specific RemoteViews for the final big notification layout. |
| 5350 | * @hide |
| 5351 | */ |
| 5352 | public RemoteViews makeBigContentView() { |
| 5353 | return null; |
| 5354 | } |
| 5355 | |
| 5356 | /** |
| 5357 | * Construct a Style-specific RemoteViews for the final HUN layout. |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5358 | * |
| 5359 | * @param increasedHeight true if this layout be created with an increased height. |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5360 | * @hide |
| 5361 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5362 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5363 | return null; |
| 5364 | } |
| 5365 | |
| 5366 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5367 | * Apply any style-specific extras to this notification before shipping it out. |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5368 | * @hide |
| 5369 | */ |
| 5370 | public void addExtras(Bundle extras) { |
| 5371 | if (mSummaryTextSet) { |
| 5372 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 5373 | } |
| 5374 | if (mBigContentTitle != null) { |
| 5375 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 5376 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 5377 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5378 | } |
| 5379 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5380 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5381 | * Reconstruct the internal state of this Style object from extras. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5382 | * @hide |
| 5383 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5384 | protected void restoreFromExtras(Bundle extras) { |
| 5385 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 5386 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 5387 | mSummaryTextSet = true; |
| 5388 | } |
| 5389 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 5390 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 5391 | } |
| 5392 | } |
| 5393 | |
| 5394 | |
| 5395 | /** |
| 5396 | * @hide |
| 5397 | */ |
| 5398 | public Notification buildStyled(Notification wip) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5399 | addExtras(wip.extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5400 | return wip; |
| 5401 | } |
| 5402 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 5403 | /** |
| 5404 | * @hide |
| 5405 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5406 | public void purgeResources() {} |
| 5407 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5408 | /** |
| 5409 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 5410 | * attached to. |
| 5411 | * |
| 5412 | * @return the fully constructed Notification. |
| 5413 | */ |
| 5414 | public Notification build() { |
| 5415 | checkBuilder(); |
| 5416 | return mBuilder.build(); |
| 5417 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 5418 | |
| 5419 | /** |
| 5420 | * @hide |
| 5421 | * @return true if the style positions the progress bar on the second line; false if the |
| 5422 | * style hides the progress bar |
| 5423 | */ |
| 5424 | protected boolean hasProgress() { |
| 5425 | return true; |
| 5426 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5427 | |
| 5428 | /** |
| 5429 | * @hide |
| 5430 | * @return Whether we should put the summary be put into the notification header |
| 5431 | */ |
| 5432 | public boolean hasSummaryInHeader() { |
| 5433 | return true; |
| 5434 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 5435 | |
| 5436 | /** |
| 5437 | * @hide |
| 5438 | * @return Whether custom content views are displayed inline in the style |
| 5439 | */ |
| 5440 | public boolean displayCustomViewInline() { |
| 5441 | return false; |
| 5442 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 5443 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5444 | |
| 5445 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5446 | * 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] | 5447 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5448 | * 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] | 5449 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5450 | * Notification notif = new Notification.Builder(mContext) |
| 5451 | * .setContentTitle("New photo from " + sender.toString()) |
| 5452 | * .setContentText(subject) |
| 5453 | * .setSmallIcon(R.drawable.new_post) |
| 5454 | * .setLargeIcon(aBitmap) |
| 5455 | * .setStyle(new Notification.BigPictureStyle() |
| 5456 | * .bigPicture(aBigBitmap)) |
| 5457 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5458 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5459 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5460 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5461 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5462 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5463 | private Bitmap mPicture; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5464 | private Icon mBigLargeIcon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5465 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5466 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5467 | public BigPictureStyle() { |
| 5468 | } |
| 5469 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 5470 | /** |
| 5471 | * @deprecated use {@code BigPictureStyle()}. |
| 5472 | */ |
| 5473 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5474 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5475 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5476 | } |
| 5477 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5478 | /** |
| 5479 | * Overrides ContentTitle in the big form of the template. |
| 5480 | * This defaults to the value passed to setContentTitle(). |
| 5481 | */ |
| 5482 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5483 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5484 | return this; |
| 5485 | } |
| 5486 | |
| 5487 | /** |
| 5488 | * Set the first line of text after the detail section in the big form of the template. |
| 5489 | */ |
| 5490 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5491 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5492 | return this; |
| 5493 | } |
| 5494 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 5495 | /** |
| 5496 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 5497 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5498 | public BigPictureStyle bigPicture(Bitmap b) { |
| 5499 | mPicture = b; |
| 5500 | return this; |
| 5501 | } |
| 5502 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5503 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5504 | * Override the large icon when the big notification is shown. |
| 5505 | */ |
| 5506 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5507 | return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 5508 | } |
| 5509 | |
| 5510 | /** |
| 5511 | * Override the large icon when the big notification is shown. |
| 5512 | */ |
| 5513 | public BigPictureStyle bigLargeIcon(Icon icon) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5514 | mBigLargeIconSet = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5515 | mBigLargeIcon = icon; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5516 | return this; |
| 5517 | } |
| 5518 | |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 5519 | /** @hide */ |
| 5520 | public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 5521 | |
Daniel Sandler | 0ec4620 | 2015-06-24 01:27:05 -0400 | [diff] [blame] | 5522 | /** |
| 5523 | * @hide |
| 5524 | */ |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5525 | @Override |
| 5526 | public void purgeResources() { |
| 5527 | super.purgeResources(); |
Riley Andrews | 8cee7c1 | 2015-11-01 23:36:04 -0800 | [diff] [blame] | 5528 | if (mPicture != null && |
| 5529 | mPicture.isMutable() && |
Riley Andrews | 0394a0c | 2015-11-03 23:36:52 -0800 | [diff] [blame] | 5530 | mPicture.getAllocationByteCount() >= MIN_ASHMEM_BITMAP_SIZE) { |
Jorim Jaggi | a0d58ae | 2015-06-03 11:48:13 -0700 | [diff] [blame] | 5531 | mPicture = mPicture.createAshmemBitmap(); |
| 5532 | } |
| 5533 | if (mBigLargeIcon != null) { |
| 5534 | mBigLargeIcon.convertToAshmem(); |
| 5535 | } |
| 5536 | } |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5537 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5538 | /** |
| 5539 | * @hide |
| 5540 | */ |
| 5541 | public RemoteViews makeBigContentView() { |
| 5542 | // Replace mN.mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5543 | // This covers the following cases: |
| 5544 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5545 | // mN.mLargeIcon |
| 5546 | // 2. !mBigLargeIconSet -> mN.mLargeIcon applies |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 5547 | Icon oldLargeIcon = null; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5548 | Bitmap largeIconLegacy = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5549 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5550 | oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 5551 | mBuilder.mN.mLargeIcon = mBigLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5552 | // The legacy largeIcon might not allow us to clear the image, as it's taken in |
| 5553 | // replacement if the other one is null. Because we're restoring these legacy icons |
| 5554 | // for old listeners, this is in general non-null. |
| 5555 | largeIconLegacy = mBuilder.mN.largeIcon; |
| 5556 | mBuilder.mN.largeIcon = null; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5557 | } |
| 5558 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5559 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5560 | if (mSummaryTextSet) { |
| 5561 | contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(mSummaryText)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5562 | mBuilder.setTextViewColorSecondary(contentView, R.id.text); |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 5563 | contentView.setViewVisibility(R.id.text, View.VISIBLE); |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5564 | } |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5565 | mBuilder.setContentMinHeight(contentView, mBuilder.mN.hasLargeIcon()); |
Selim Cinek | 53e64a4 | 2015-11-16 10:40:56 -0800 | [diff] [blame] | 5566 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5567 | if (mBigLargeIconSet) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5568 | mBuilder.mN.mLargeIcon = oldLargeIcon; |
Selim Cinek | e99acb2 | 2016-08-04 12:55:48 -0700 | [diff] [blame] | 5569 | mBuilder.mN.largeIcon = largeIconLegacy; |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5570 | } |
| 5571 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5572 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5573 | return contentView; |
| 5574 | } |
| 5575 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5576 | /** |
| 5577 | * @hide |
| 5578 | */ |
| 5579 | public void addExtras(Bundle extras) { |
| 5580 | super.addExtras(extras); |
| 5581 | |
| 5582 | if (mBigLargeIconSet) { |
| 5583 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 5584 | } |
| 5585 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 5586 | } |
| 5587 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 5588 | /** |
| 5589 | * @hide |
| 5590 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5591 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5592 | protected void restoreFromExtras(Bundle extras) { |
| 5593 | super.restoreFromExtras(extras); |
| 5594 | |
| 5595 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 5596 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5597 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 5598 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5599 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 5600 | } |
Selim Cinek | 03d0d65 | 2015-11-13 13:18:09 -0500 | [diff] [blame] | 5601 | |
| 5602 | /** |
| 5603 | * @hide |
| 5604 | */ |
| 5605 | @Override |
| 5606 | public boolean hasSummaryInHeader() { |
| 5607 | return false; |
| 5608 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5612 | * 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] | 5613 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5614 | * 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] | 5615 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 5616 | * Notification notif = new Notification.Builder(mContext) |
| 5617 | * .setContentTitle("New mail from " + sender.toString()) |
| 5618 | * .setContentText(subject) |
| 5619 | * .setSmallIcon(R.drawable.new_mail) |
| 5620 | * .setLargeIcon(aBitmap) |
| 5621 | * .setStyle(new Notification.BigTextStyle() |
| 5622 | * .bigText(aVeryLongString)) |
| 5623 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5624 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5625 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 5626 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5627 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5628 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 5629 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5630 | private CharSequence mBigText; |
| 5631 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5632 | public BigTextStyle() { |
| 5633 | } |
| 5634 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 5635 | /** |
| 5636 | * @deprecated use {@code BigTextStyle()}. |
| 5637 | */ |
| 5638 | @Deprecated |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5639 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 5640 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5641 | } |
| 5642 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5643 | /** |
| 5644 | * Overrides ContentTitle in the big form of the template. |
| 5645 | * This defaults to the value passed to setContentTitle(). |
| 5646 | */ |
| 5647 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5648 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5649 | return this; |
| 5650 | } |
| 5651 | |
| 5652 | /** |
| 5653 | * Set the first line of text after the detail section in the big form of the template. |
| 5654 | */ |
| 5655 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5656 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 5657 | return this; |
| 5658 | } |
| 5659 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 5660 | /** |
| 5661 | * Provide the longer text to be displayed in the big form of the |
| 5662 | * template in place of the content text. |
| 5663 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5664 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 5665 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5666 | return this; |
| 5667 | } |
| 5668 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5669 | /** |
| 5670 | * @hide |
| 5671 | */ |
| 5672 | public void addExtras(Bundle extras) { |
| 5673 | super.addExtras(extras); |
| 5674 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5675 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 5676 | } |
| 5677 | |
| 5678 | /** |
| 5679 | * @hide |
| 5680 | */ |
| 5681 | @Override |
| 5682 | protected void restoreFromExtras(Bundle extras) { |
| 5683 | super.restoreFromExtras(extras); |
| 5684 | |
| 5685 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 5686 | } |
| 5687 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5688 | /** |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5689 | * @param increasedHeight true if this layout be created with an increased height. |
| 5690 | * |
| 5691 | * @hide |
| 5692 | */ |
| 5693 | @Override |
| 5694 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 5695 | if (increasedHeight) { |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 5696 | mBuilder.mOriginalActions = mBuilder.mActions; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5697 | mBuilder.mActions = new ArrayList<>(); |
| 5698 | RemoteViews remoteViews = makeBigContentView(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 5699 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 5700 | mBuilder.mOriginalActions = null; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5701 | return remoteViews; |
| 5702 | } |
| 5703 | return super.makeContentView(increasedHeight); |
| 5704 | } |
| 5705 | |
| 5706 | /** |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5707 | * @hide |
| 5708 | */ |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 5709 | @Override |
| 5710 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 5711 | if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 5712 | return makeBigContentView(); |
| 5713 | } |
| 5714 | return super.makeHeadsUpContentView(increasedHeight); |
| 5715 | } |
| 5716 | |
| 5717 | /** |
| 5718 | * @hide |
| 5719 | */ |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5720 | public RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5721 | |
| 5722 | // Nasty |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 5723 | CharSequence text = mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 5724 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 5725 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 5726 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 5727 | |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 5728 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, text); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5729 | |
Selim Cinek | 3a2c4b9 | 2015-12-17 17:01:17 -0800 | [diff] [blame] | 5730 | CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
Selim Cinek | 7599878 | 2016-04-26 10:39:17 -0700 | [diff] [blame] | 5731 | if (TextUtils.isEmpty(bigTextText)) { |
| 5732 | // In case the bigtext is null / empty fall back to the normal text to avoid a weird |
| 5733 | // experience |
| 5734 | bigTextText = mBuilder.processLegacyText(text); |
| 5735 | } |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5736 | applyBigTextContentView(mBuilder, contentView, bigTextText); |
Selim Cinek | 4fb12d3 | 2015-11-19 18:10:48 -0800 | [diff] [blame] | 5737 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5738 | return contentView; |
| 5739 | } |
| 5740 | |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5741 | static void applyBigTextContentView(Builder builder, |
| 5742 | RemoteViews contentView, CharSequence bigTextText) { |
| 5743 | contentView.setTextViewText(R.id.big_text, bigTextText); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 5744 | builder.setTextViewColorSecondary(contentView, R.id.big_text); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5745 | contentView.setViewVisibility(R.id.big_text, |
| 5746 | TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 5747 | contentView.setBoolean(R.id.big_text, "setHasImage", builder.mN.hasLargeIcon()); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 5748 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 5749 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 5750 | |
| 5751 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5752 | * Helper class for generating large-format notifications that include multiple back-and-forth |
| 5753 | * messages of varying types between any number of people. |
| 5754 | * |
| 5755 | * <br> |
| 5756 | * If the platform does not provide large-format notifications, this method has no effect. The |
| 5757 | * user will always see the normal notification view. |
| 5758 | * <br> |
| 5759 | * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like |
| 5760 | * so: |
| 5761 | * <pre class="prettyprint"> |
| 5762 | * |
| 5763 | * Notification noti = new Notification.Builder() |
| 5764 | * .setContentTitle("2 new messages wtih " + sender.toString()) |
| 5765 | * .setContentText(subject) |
| 5766 | * .setSmallIcon(R.drawable.new_message) |
| 5767 | * .setLargeIcon(aBitmap) |
| 5768 | * .setStyle(new Notification.MessagingStyle(resources.getString(R.string.reply_name)) |
| 5769 | * .addMessage(messages[0].getText(), messages[0].getTime(), messages[0].getSender()) |
| 5770 | * .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getSender())) |
| 5771 | * .build(); |
| 5772 | * </pre> |
| 5773 | */ |
| 5774 | public static class MessagingStyle extends Style { |
| 5775 | |
| 5776 | /** |
| 5777 | * The maximum number of messages that will be retained in the Notification itself (the |
| 5778 | * number displayed is up to the platform). |
| 5779 | */ |
| 5780 | public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 5781 | |
| 5782 | CharSequence mUserDisplayName; |
| 5783 | CharSequence mConversationTitle; |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5784 | List<Message> mMessages = new ArrayList<>(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5785 | List<Message> mHistoricMessages = new ArrayList<>(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5786 | |
| 5787 | MessagingStyle() { |
| 5788 | } |
| 5789 | |
| 5790 | /** |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 5791 | * @param userDisplayName Required - the name to be displayed for any replies sent by the |
| 5792 | * user before the posting app reposts the notification with those messages after they've |
| 5793 | * 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] | 5794 | * {@link #addMessage(Notification.MessagingStyle.Message)} |
| 5795 | */ |
Alex Hills | fd59044 | 2016-10-07 09:52:44 -0400 | [diff] [blame] | 5796 | public MessagingStyle(@NonNull CharSequence userDisplayName) { |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5797 | mUserDisplayName = userDisplayName; |
| 5798 | } |
| 5799 | |
| 5800 | /** |
| 5801 | * Returns the name to be displayed for any replies sent by the user |
| 5802 | */ |
| 5803 | public CharSequence getUserDisplayName() { |
| 5804 | return mUserDisplayName; |
| 5805 | } |
| 5806 | |
| 5807 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5808 | * Sets the title to be displayed on this conversation. This should only be used for |
| 5809 | * group messaging and left unset for one-on-one conversations. |
| 5810 | * @param conversationTitle |
| 5811 | * @return this object for method chaining. |
| 5812 | */ |
| 5813 | public MessagingStyle setConversationTitle(CharSequence conversationTitle) { |
| 5814 | mConversationTitle = conversationTitle; |
| 5815 | return this; |
| 5816 | } |
| 5817 | |
| 5818 | /** |
| 5819 | * Return the title to be displayed on this conversation. Can be <code>null</code> and |
| 5820 | * should be for one-on-one conversations |
| 5821 | */ |
| 5822 | public CharSequence getConversationTitle() { |
| 5823 | return mConversationTitle; |
| 5824 | } |
| 5825 | |
| 5826 | /** |
| 5827 | * Adds a message for display by this notification. Convenience call for a simple |
| 5828 | * {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}. |
| 5829 | * @param text A {@link CharSequence} to be displayed as the message content |
| 5830 | * @param timestamp Time at which the message arrived |
| 5831 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 5832 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 5833 | * the platform will insert {@link #getUserDisplayName()}. |
| 5834 | * Should be unique amongst all individuals in the conversation, and should be |
| 5835 | * consistent during re-posts of the notification. |
| 5836 | * |
| 5837 | * @see Message#Message(CharSequence, long, CharSequence) |
| 5838 | * |
| 5839 | * @return this object for method chaining |
| 5840 | */ |
| 5841 | public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5842 | return addMessage(new Message(text, timestamp, sender)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | /** |
| 5846 | * Adds a {@link Message} for display in this notification. |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5847 | * |
| 5848 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 5849 | * the newest last. |
| 5850 | * |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5851 | * @param message The {@link Message} to be displayed |
| 5852 | * @return this object for method chaining |
| 5853 | */ |
| 5854 | public MessagingStyle addMessage(Message message) { |
| 5855 | mMessages.add(message); |
| 5856 | if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 5857 | mMessages.remove(0); |
| 5858 | } |
| 5859 | return this; |
| 5860 | } |
| 5861 | |
| 5862 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5863 | * Adds a {@link Message} for historic context in this notification. |
| 5864 | * |
| 5865 | * <p>Messages should be added as historic if they are not the main subject of the |
| 5866 | * notification but may give context to a conversation. The system may choose to present |
| 5867 | * them only when relevant, e.g. when replying to a message through a {@link RemoteInput}. |
| 5868 | * |
| 5869 | * <p>The messages should be added in chronologic order, i.e. the oldest first, |
| 5870 | * the newest last. |
| 5871 | * |
| 5872 | * @param message The historic {@link Message} to be added |
| 5873 | * @return this object for method chaining |
| 5874 | */ |
| 5875 | public MessagingStyle addHistoricMessage(Message message) { |
| 5876 | mHistoricMessages.add(message); |
| 5877 | if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 5878 | mHistoricMessages.remove(0); |
| 5879 | } |
| 5880 | return this; |
| 5881 | } |
| 5882 | |
| 5883 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5884 | * Gets the list of {@code Message} objects that represent the notification |
| 5885 | */ |
| 5886 | public List<Message> getMessages() { |
| 5887 | return mMessages; |
| 5888 | } |
| 5889 | |
| 5890 | /** |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5891 | * Gets the list of historic {@code Message}s in the notification. |
| 5892 | */ |
| 5893 | public List<Message> getHistoricMessages() { |
| 5894 | return mHistoricMessages; |
| 5895 | } |
| 5896 | |
| 5897 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5898 | * @hide |
| 5899 | */ |
| 5900 | @Override |
| 5901 | public void addExtras(Bundle extras) { |
| 5902 | super.addExtras(extras); |
| 5903 | if (mUserDisplayName != null) { |
| 5904 | extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUserDisplayName); |
| 5905 | } |
| 5906 | if (mConversationTitle != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5907 | extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5908 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 5909 | if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 5910 | Message.getBundleArrayForMessages(mMessages)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5911 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5912 | if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 5913 | Message.getBundleArrayForMessages(mHistoricMessages)); |
| 5914 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 5915 | |
| 5916 | fixTitleAndTextExtras(extras); |
| 5917 | } |
| 5918 | |
| 5919 | private void fixTitleAndTextExtras(Bundle extras) { |
| 5920 | Message m = findLatestIncomingMessage(); |
| 5921 | CharSequence text = (m == null) ? null : m.mText; |
| 5922 | CharSequence sender = m == null ? null |
| 5923 | : TextUtils.isEmpty(m.mSender) ? mUserDisplayName : m.mSender; |
| 5924 | CharSequence title; |
| 5925 | if (!TextUtils.isEmpty(mConversationTitle)) { |
| 5926 | if (!TextUtils.isEmpty(sender)) { |
| 5927 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 5928 | title = mBuilder.mContext.getString( |
| 5929 | com.android.internal.R.string.notification_messaging_title_template, |
| 5930 | bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(m.mSender)); |
| 5931 | } else { |
| 5932 | title = mConversationTitle; |
| 5933 | } |
| 5934 | } else { |
| 5935 | title = sender; |
| 5936 | } |
| 5937 | |
| 5938 | if (title != null) { |
| 5939 | extras.putCharSequence(EXTRA_TITLE, title); |
| 5940 | } |
| 5941 | if (text != null) { |
| 5942 | extras.putCharSequence(EXTRA_TEXT, text); |
| 5943 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5944 | } |
| 5945 | |
| 5946 | /** |
| 5947 | * @hide |
| 5948 | */ |
| 5949 | @Override |
| 5950 | protected void restoreFromExtras(Bundle extras) { |
| 5951 | super.restoreFromExtras(extras); |
| 5952 | |
| 5953 | mMessages.clear(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5954 | mHistoricMessages.clear(); |
Adrian Roos | 96b7e20 | 2016-05-17 13:50:38 -0700 | [diff] [blame] | 5955 | mUserDisplayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
| 5956 | mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 5957 | Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 5958 | if (messages != null && messages instanceof Parcelable[]) { |
| 5959 | mMessages = Message.getMessagesFromBundleArray(messages); |
| 5960 | } |
| 5961 | Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 5962 | if (histMessages != null && histMessages instanceof Parcelable[]) { |
| 5963 | mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5964 | } |
| 5965 | } |
| 5966 | |
| 5967 | /** |
| 5968 | * @hide |
| 5969 | */ |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5970 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5971 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 5972 | if (!increasedHeight) { |
| 5973 | Message m = findLatestIncomingMessage(); |
| 5974 | CharSequence title = mConversationTitle != null |
| 5975 | ? mConversationTitle |
| 5976 | : (m == null) ? null : m.mSender; |
| 5977 | CharSequence text = (m == null) |
| 5978 | ? null |
| 5979 | : mConversationTitle != null ? makeMessageLine(m, mBuilder) : m.mText; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 5980 | |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5981 | return mBuilder.applyStandardTemplate(mBuilder.getBaseLayoutResource(), |
| 5982 | mBuilder.mParams.reset().hasProgress(false).title(title).text(text)); |
| 5983 | } else { |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 5984 | mBuilder.mOriginalActions = mBuilder.mActions; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5985 | mBuilder.mActions = new ArrayList<>(); |
| 5986 | RemoteViews remoteViews = makeBigContentView(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 5987 | mBuilder.mActions = mBuilder.mOriginalActions; |
| 5988 | mBuilder.mOriginalActions = null; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 5989 | return remoteViews; |
| 5990 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 5991 | } |
| 5992 | |
| 5993 | private Message findLatestIncomingMessage() { |
| 5994 | for (int i = mMessages.size() - 1; i >= 0; i--) { |
| 5995 | Message m = mMessages.get(i); |
| 5996 | // Incoming messages have a non-empty sender. |
| 5997 | if (!TextUtils.isEmpty(m.mSender)) { |
| 5998 | return m; |
| 5999 | } |
| 6000 | } |
Adrian Roos | 33fbd2c | 2016-05-27 15:35:28 -0700 | [diff] [blame] | 6001 | if (!mMessages.isEmpty()) { |
| 6002 | // No incoming messages, fall back to outgoing message |
| 6003 | return mMessages.get(mMessages.size() - 1); |
| 6004 | } |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6005 | return null; |
| 6006 | } |
| 6007 | |
| 6008 | /** |
| 6009 | * @hide |
| 6010 | */ |
| 6011 | @Override |
| 6012 | public RemoteViews makeBigContentView() { |
| 6013 | CharSequence title = !TextUtils.isEmpty(super.mBigContentTitle) |
| 6014 | ? super.mBigContentTitle |
| 6015 | : mConversationTitle; |
| 6016 | boolean hasTitle = !TextUtils.isEmpty(title); |
| 6017 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 6018 | if (mMessages.size() == 1) { |
| 6019 | // Special case for a single message: Use the big text style |
| 6020 | // so the collapsed and expanded versions match nicely. |
| 6021 | CharSequence bigTitle; |
| 6022 | CharSequence text; |
| 6023 | if (hasTitle) { |
| 6024 | bigTitle = title; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6025 | text = makeMessageLine(mMessages.get(0), mBuilder); |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 6026 | } else { |
| 6027 | bigTitle = mMessages.get(0).mSender; |
| 6028 | text = mMessages.get(0).mText; |
| 6029 | } |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6030 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
| 6031 | mBuilder.getBigTextLayoutResource(), |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 6032 | mBuilder.mParams.reset().hasProgress(false).title(bigTitle).text(null)); |
Adrian Roos | b1f427c | 2016-05-26 12:27:15 -0700 | [diff] [blame] | 6033 | BigTextStyle.applyBigTextContentView(mBuilder, contentView, text); |
| 6034 | return contentView; |
| 6035 | } |
| 6036 | |
Adrian Roos | 48d746a | 2016-04-12 14:57:28 -0700 | [diff] [blame] | 6037 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6038 | mBuilder.getMessagingLayoutResource(), |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 6039 | mBuilder.mParams.reset().hasProgress(false).title(title).text(null)); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6040 | |
| 6041 | int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3, |
| 6042 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
| 6043 | |
| 6044 | // Make sure all rows are gone in case we reuse a view. |
| 6045 | for (int rowId : rowIds) { |
| 6046 | contentView.setViewVisibility(rowId, View.GONE); |
| 6047 | } |
| 6048 | |
| 6049 | int i=0; |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6050 | contentView.setViewLayoutMarginBottomDimen(R.id.line1, |
| 6051 | hasTitle ? R.dimen.notification_messaging_spacing : 0); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6052 | contentView.setInt(R.id.notification_messaging, "setNumIndentLines", |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6053 | !mBuilder.mN.hasLargeIcon() ? 0 : (hasTitle ? 1 : 2)); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6054 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 6055 | int contractedChildId = View.NO_ID; |
| 6056 | Message contractedMessage = findLatestIncomingMessage(); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6057 | int firstHistoricMessage = Math.max(0, mHistoricMessages.size() |
| 6058 | - (rowIds.length - mMessages.size())); |
| 6059 | while (firstHistoricMessage + i < mHistoricMessages.size() && i < rowIds.length) { |
| 6060 | Message m = mHistoricMessages.get(firstHistoricMessage + i); |
| 6061 | int rowId = rowIds[i]; |
| 6062 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6063 | contentView.setTextViewText(rowId, makeMessageLine(m, mBuilder)); |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6064 | |
| 6065 | if (contractedMessage == m) { |
| 6066 | contractedChildId = rowId; |
| 6067 | } |
| 6068 | |
| 6069 | i++; |
| 6070 | } |
| 6071 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6072 | int firstMessage = Math.max(0, mMessages.size() - rowIds.length); |
| 6073 | while (firstMessage + i < mMessages.size() && i < rowIds.length) { |
| 6074 | Message m = mMessages.get(firstMessage + i); |
| 6075 | int rowId = rowIds[i]; |
| 6076 | |
| 6077 | contentView.setViewVisibility(rowId, View.VISIBLE); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6078 | contentView.setTextViewText(rowId, makeMessageLine(m, mBuilder)); |
| 6079 | mBuilder.setTextViewColorSecondary(contentView, rowId); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6080 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 6081 | if (contractedMessage == m) { |
| 6082 | contractedChildId = rowId; |
| 6083 | } |
| 6084 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6085 | i++; |
| 6086 | } |
Adrian Roos | 437cd56 | 2017-01-18 15:47:03 -0800 | [diff] [blame] | 6087 | // Clear the remaining views for reapply. Ensures that historic message views can |
| 6088 | // reliably be identified as being GONE and having non-null text. |
| 6089 | while (i < rowIds.length) { |
| 6090 | int rowId = rowIds[i]; |
| 6091 | contentView.setTextViewText(rowId, null); |
| 6092 | i++; |
| 6093 | } |
| 6094 | |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 6095 | // Record this here to allow transformation between the contracted and expanded views. |
| 6096 | contentView.setInt(R.id.notification_messaging, "setContractedChildId", |
| 6097 | contractedChildId); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6098 | return contentView; |
| 6099 | } |
| 6100 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6101 | private CharSequence makeMessageLine(Message m, Builder builder) { |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6102 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 6103 | SpannableStringBuilder sb = new SpannableStringBuilder(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6104 | boolean colorize = builder.isColorized(); |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6105 | if (TextUtils.isEmpty(m.mSender)) { |
| 6106 | CharSequence replyName = mUserDisplayName == null ? "" : mUserDisplayName; |
| 6107 | sb.append(bidi.unicodeWrap(replyName), |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6108 | makeFontColorSpan(colorize |
| 6109 | ? builder.getPrimaryTextColor() |
| 6110 | : mBuilder.resolveContrastColor()), |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6111 | 0 /* flags */); |
| 6112 | } else { |
| 6113 | sb.append(bidi.unicodeWrap(m.mSender), |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6114 | makeFontColorSpan(colorize |
| 6115 | ? builder.getPrimaryTextColor() |
| 6116 | : Color.BLACK), |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6117 | 0 /* flags */); |
| 6118 | } |
| 6119 | CharSequence text = m.mText == null ? "" : m.mText; |
| 6120 | sb.append(" ").append(bidi.unicodeWrap(text)); |
| 6121 | return sb; |
| 6122 | } |
| 6123 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6124 | /** |
| 6125 | * @hide |
| 6126 | */ |
| 6127 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6128 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 6129 | if (increasedHeight) { |
| 6130 | return makeBigContentView(); |
| 6131 | } |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6132 | Message m = findLatestIncomingMessage(); |
| 6133 | CharSequence title = mConversationTitle != null |
| 6134 | ? mConversationTitle |
| 6135 | : (m == null) ? null : m.mSender; |
| 6136 | CharSequence text = (m == null) |
| 6137 | ? null |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6138 | : mConversationTitle != null ? makeMessageLine(m, mBuilder) : m.mText; |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6139 | |
| 6140 | return mBuilder.applyStandardTemplateWithActions(mBuilder.getBigBaseLayoutResource(), |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 6141 | mBuilder.mParams.reset().hasProgress(false).title(title).text(text)); |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6142 | } |
| 6143 | |
Adrian Roos | c1a80b0 | 2016-04-05 14:54:55 -0700 | [diff] [blame] | 6144 | private static TextAppearanceSpan makeFontColorSpan(int color) { |
| 6145 | return new TextAppearanceSpan(null, 0, 0, |
| 6146 | ColorStateList.valueOf(color), null); |
| 6147 | } |
| 6148 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6149 | public static final class Message { |
| 6150 | |
| 6151 | static final String KEY_TEXT = "text"; |
| 6152 | static final String KEY_TIMESTAMP = "time"; |
| 6153 | static final String KEY_SENDER = "sender"; |
| 6154 | static final String KEY_DATA_MIME_TYPE = "type"; |
| 6155 | static final String KEY_DATA_URI= "uri"; |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6156 | static final String KEY_EXTRAS_BUNDLE = "extras"; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6157 | |
| 6158 | private final CharSequence mText; |
| 6159 | private final long mTimestamp; |
| 6160 | private final CharSequence mSender; |
| 6161 | |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6162 | private Bundle mExtras = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6163 | private String mDataMimeType; |
| 6164 | private Uri mDataUri; |
| 6165 | |
| 6166 | /** |
| 6167 | * Constructor |
| 6168 | * @param text A {@link CharSequence} to be displayed as the message content |
| 6169 | * @param timestamp Time at which the message arrived |
| 6170 | * @param sender A {@link CharSequence} to be used for displaying the name of the |
| 6171 | * sender. Should be <code>null</code> for messages by the current user, in which case |
| 6172 | * the platform will insert {@link MessagingStyle#getUserDisplayName()}. |
| 6173 | * Should be unique amongst all individuals in the conversation, and should be |
| 6174 | * consistent during re-posts of the notification. |
| 6175 | */ |
| 6176 | public Message(CharSequence text, long timestamp, CharSequence sender){ |
| 6177 | mText = text; |
| 6178 | mTimestamp = timestamp; |
| 6179 | mSender = sender; |
| 6180 | } |
| 6181 | |
| 6182 | /** |
| 6183 | * Sets a binary blob of data and an associated MIME type for a message. In the case |
| 6184 | * where the platform doesn't support the MIME type, the original text provided in the |
| 6185 | * constructor will be used. |
| 6186 | * @param dataMimeType The MIME type of the content. See |
| 6187 | * <a href="{@docRoot}notifications/messaging.html"> for the list of supported MIME |
| 6188 | * types on Android and Android Wear. |
| 6189 | * @param dataUri The uri containing the content whose type is given by the MIME type. |
| 6190 | * <p class="note"> |
| 6191 | * <ol> |
| 6192 | * <li>Notification Listeners including the System UI need permission to access the |
| 6193 | * data the Uri points to. The recommended ways to do this are:</li> |
| 6194 | * <li>Store the data in your own ContentProvider, making sure that other apps have |
| 6195 | * the correct permission to access your provider. The preferred mechanism for |
| 6196 | * providing access is to use per-URI permissions which are temporary and only |
| 6197 | * grant access to the receiving application. An easy way to create a |
| 6198 | * ContentProvider like this is to use the FileProvider helper class.</li> |
| 6199 | * <li>Use the system MediaStore. The MediaStore is primarily aimed at video, audio |
| 6200 | * and image MIME types, however beginning with Android 3.0 (API level 11) it can |
| 6201 | * also store non-media types (see MediaStore.Files for more info). Files can be |
| 6202 | * inserted into the MediaStore using scanFile() after which a content:// style |
| 6203 | * Uri suitable for sharing is passed to the provided onScanCompleted() callback. |
| 6204 | * Note that once added to the system MediaStore the content is accessible to any |
| 6205 | * app on the device.</li> |
| 6206 | * </ol> |
| 6207 | * @return this object for method chaining |
| 6208 | */ |
| 6209 | public Message setData(String dataMimeType, Uri dataUri) { |
| 6210 | mDataMimeType = dataMimeType; |
| 6211 | mDataUri = dataUri; |
| 6212 | return this; |
| 6213 | } |
| 6214 | |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6215 | /** |
| 6216 | * Get the text to be used for this message, or the fallback text if a type and content |
| 6217 | * Uri have been set |
| 6218 | */ |
| 6219 | public CharSequence getText() { |
| 6220 | return mText; |
| 6221 | } |
| 6222 | |
| 6223 | /** |
| 6224 | * Get the time at which this message arrived |
| 6225 | */ |
| 6226 | public long getTimestamp() { |
| 6227 | return mTimestamp; |
| 6228 | } |
| 6229 | |
| 6230 | /** |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6231 | * Get the extras Bundle for this message. |
| 6232 | */ |
| 6233 | public Bundle getExtras() { |
| 6234 | return mExtras; |
| 6235 | } |
| 6236 | |
| 6237 | /** |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6238 | * Get the text used to display the contact's name in the messaging experience |
| 6239 | */ |
| 6240 | public CharSequence getSender() { |
| 6241 | return mSender; |
| 6242 | } |
| 6243 | |
| 6244 | /** |
| 6245 | * Get the MIME type of the data pointed to by the Uri |
| 6246 | */ |
| 6247 | public String getDataMimeType() { |
| 6248 | return mDataMimeType; |
| 6249 | } |
| 6250 | |
| 6251 | /** |
| 6252 | * Get the the Uri pointing to the content of the message. Can be null, in which case |
| 6253 | * {@see #getText()} is used. |
| 6254 | */ |
| 6255 | public Uri getDataUri() { |
| 6256 | return mDataUri; |
| 6257 | } |
| 6258 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6259 | private Bundle toBundle() { |
| 6260 | Bundle bundle = new Bundle(); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6261 | if (mText != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6262 | bundle.putCharSequence(KEY_TEXT, mText); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6263 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6264 | bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6265 | if (mSender != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6266 | bundle.putCharSequence(KEY_SENDER, mSender); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6267 | } |
| 6268 | if (mDataMimeType != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6269 | bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6270 | } |
| 6271 | if (mDataUri != null) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6272 | bundle.putParcelable(KEY_DATA_URI, mDataUri); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6273 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6274 | if (mExtras != null) { |
| 6275 | bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 6276 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6277 | return bundle; |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6278 | } |
| 6279 | |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6280 | static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 6281 | Bundle[] bundles = new Bundle[messages.size()]; |
| 6282 | final int N = messages.size(); |
| 6283 | for (int i = 0; i < N; i++) { |
| 6284 | bundles[i] = messages.get(i).toBundle(); |
| 6285 | } |
| 6286 | return bundles; |
| 6287 | } |
| 6288 | |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6289 | static List<Message> getMessagesFromBundleArray(Parcelable[] bundles) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6290 | List<Message> messages = new ArrayList<>(bundles.length); |
| 6291 | for (int i = 0; i < bundles.length; i++) { |
Adrian Roos | dedd1df | 2016-04-26 16:38:47 -0700 | [diff] [blame] | 6292 | if (bundles[i] instanceof Bundle) { |
| 6293 | Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 6294 | if (message != null) { |
| 6295 | messages.add(message); |
| 6296 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6297 | } |
| 6298 | } |
| 6299 | return messages; |
| 6300 | } |
| 6301 | |
| 6302 | static Message getMessageFromBundle(Bundle bundle) { |
| 6303 | try { |
Adrian Roos | fbddd2c | 2016-05-13 12:57:20 -0700 | [diff] [blame] | 6304 | if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6305 | return null; |
| 6306 | } else { |
| 6307 | Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
| 6308 | bundle.getLong(KEY_TIMESTAMP), bundle.getCharSequence(KEY_SENDER)); |
| 6309 | if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 6310 | bundle.containsKey(KEY_DATA_URI)) { |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6311 | message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 6312 | (Uri) bundle.getParcelable(KEY_DATA_URI)); |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6313 | } |
Shane Brennan | 5a87186 | 2017-03-11 13:14:17 -0800 | [diff] [blame] | 6314 | if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 6315 | message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 6316 | } |
Alex Hills | d9b04d9 | 2016-04-11 16:38:16 -0400 | [diff] [blame] | 6317 | return message; |
| 6318 | } |
| 6319 | } catch (ClassCastException e) { |
| 6320 | return null; |
| 6321 | } |
| 6322 | } |
Alex Hills | fc737de | 2016-03-23 17:33:02 -0400 | [diff] [blame] | 6323 | } |
| 6324 | } |
| 6325 | |
| 6326 | /** |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6327 | * 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] | 6328 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6329 | * 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] | 6330 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 6331 | * Notification notif = new Notification.Builder(mContext) |
| 6332 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 6333 | * .setContentText(subject) |
| 6334 | * .setSmallIcon(R.drawable.new_mail) |
| 6335 | * .setLargeIcon(aBitmap) |
| 6336 | * .setStyle(new Notification.InboxStyle() |
| 6337 | * .addLine(str1) |
| 6338 | * .addLine(str2) |
| 6339 | * .setContentTitle("") |
| 6340 | * .setSummaryText("+3 more")) |
| 6341 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6342 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 6343 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6344 | * @see Notification#bigContentView |
| 6345 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6346 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6347 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 6348 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6349 | public InboxStyle() { |
| 6350 | } |
| 6351 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6352 | /** |
| 6353 | * @deprecated use {@code InboxStyle()}. |
| 6354 | */ |
| 6355 | @Deprecated |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6356 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 6357 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6358 | } |
| 6359 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6360 | /** |
| 6361 | * Overrides ContentTitle in the big form of the template. |
| 6362 | * This defaults to the value passed to setContentTitle(). |
| 6363 | */ |
| 6364 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6365 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6366 | return this; |
| 6367 | } |
| 6368 | |
| 6369 | /** |
| 6370 | * Set the first line of text after the detail section in the big form of the template. |
| 6371 | */ |
| 6372 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6373 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6374 | return this; |
| 6375 | } |
| 6376 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 6377 | /** |
| 6378 | * Append a line to the digest section of the Inbox notification. |
| 6379 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6380 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 6381 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6382 | return this; |
| 6383 | } |
| 6384 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6385 | /** |
| 6386 | * @hide |
| 6387 | */ |
| 6388 | public void addExtras(Bundle extras) { |
| 6389 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6390 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 6391 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 6392 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 6393 | } |
| 6394 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6395 | /** |
| 6396 | * @hide |
| 6397 | */ |
| 6398 | @Override |
| 6399 | protected void restoreFromExtras(Bundle extras) { |
| 6400 | super.restoreFromExtras(extras); |
| 6401 | |
| 6402 | mTexts.clear(); |
| 6403 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 6404 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 6405 | } |
| 6406 | } |
| 6407 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6408 | /** |
| 6409 | * @hide |
| 6410 | */ |
| 6411 | public RemoteViews makeBigContentView() { |
Selim Cinek | c848c3a | 2016-01-13 15:27:30 -0800 | [diff] [blame] | 6412 | // Remove the content text so it disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6413 | // Nasty |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6414 | CharSequence oldBuilderContentText = mBuilder.mN.extras.getCharSequence(EXTRA_TEXT); |
| 6415 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, null); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6416 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 6417 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource()); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 6418 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6419 | mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6420 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6421 | 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] | 6422 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 6423 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 6424 | // Make sure all rows are gone in case we reuse a view. |
| 6425 | for (int rowId : rowIds) { |
| 6426 | contentView.setViewVisibility(rowId, View.GONE); |
| 6427 | } |
| 6428 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6429 | int i=0; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6430 | int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 6431 | R.dimen.notification_inbox_item_top_padding); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6432 | boolean first = true; |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6433 | int onlyViewId = 0; |
| 6434 | int maxRows = rowIds.length; |
| 6435 | if (mBuilder.mActions.size() > 0) { |
| 6436 | maxRows--; |
| 6437 | } |
| 6438 | while (i < mTexts.size() && i < maxRows) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6439 | CharSequence str = mTexts.get(i); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6440 | if (!TextUtils.isEmpty(str)) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6441 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 6442 | contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 6443 | mBuilder.setTextViewColorSecondary(contentView, rowIds[i]); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6444 | contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6445 | handleInboxImageMargin(contentView, rowIds[i], first); |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6446 | if (first) { |
| 6447 | onlyViewId = rowIds[i]; |
| 6448 | } else { |
| 6449 | onlyViewId = 0; |
| 6450 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6451 | first = false; |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6452 | } |
| 6453 | i++; |
| 6454 | } |
Selim Cinek | 07c8017 | 2016-04-21 16:40:47 -0700 | [diff] [blame] | 6455 | if (onlyViewId != 0) { |
| 6456 | // We only have 1 entry, lets make it look like the normal Text of a Bigtext |
| 6457 | topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 6458 | R.dimen.notification_text_margin_top); |
| 6459 | contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 6460 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6461 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6462 | return contentView; |
| 6463 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6464 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6465 | private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first) { |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6466 | int endMargin = 0; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6467 | if (first) { |
| 6468 | final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0); |
| 6469 | final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 6470 | boolean hasProgress = max != 0 || ind; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6471 | if (mBuilder.mN.hasLargeIcon() && !hasProgress) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6472 | endMargin = R.dimen.notification_content_picture_margin; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6473 | } |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6474 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6475 | contentView.setViewLayoutMarginEndDimen(id, endMargin); |
Selim Cinek | 1e0bf61 | 2015-11-20 15:57:26 -0800 | [diff] [blame] | 6476 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 6477 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6478 | |
| 6479 | /** |
| 6480 | * Notification style for media playback notifications. |
| 6481 | * |
| 6482 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 6483 | * {@link Notification.Action}s specified with |
Dan Sandler | 8664798 | 2015-05-13 23:41:13 -0400 | [diff] [blame] | 6484 | * {@link Notification.Builder#addAction(Action) addAction} will be |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6485 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 6486 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 6487 | * treated as album artwork. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6488 | * <p> |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6489 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 6490 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 6491 | * {@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] | 6492 | * in the standard view alongside the usual content. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6493 | * <p> |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 6494 | * Notifications created with MediaStyle will have their category set to |
| 6495 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 6496 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6497 | * <p> |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6498 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 6499 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6500 | * the System UI can identify this as a notification representing an active media session |
| 6501 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 6502 | * |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6503 | * <p> |
| 6504 | * Starting at {@link android.os.Build.VERSION_CODES#O Android O} any notification that has a |
| 6505 | * media session attached with {@link #setMediaSession(MediaSession.Token)} will be colorized. |
| 6506 | * You can opt-out of this behavior by using {@link Notification.Builder#setColorized(boolean)}. |
| 6507 | * <p> |
| 6508 | * |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6509 | * To use this style with your Notification, feed it to |
| 6510 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 6511 | * <pre class="prettyprint"> |
| 6512 | * Notification noti = new Notification.Builder() |
| 6513 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 6514 | * .setContentTitle("Track title") |
| 6515 | * .setContentText("Artist - Album") |
| 6516 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 6517 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 6518 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6519 | * .build(); |
| 6520 | * </pre> |
| 6521 | * |
| 6522 | * @see Notification#bigContentView |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6523 | * @see Notification.Builder#setColorized(boolean) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6524 | */ |
| 6525 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6526 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6527 | static final int MAX_MEDIA_BUTTONS = 5; |
| 6528 | |
| 6529 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6530 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6531 | |
| 6532 | public MediaStyle() { |
| 6533 | } |
| 6534 | |
Adrian Roos | f5faf9d | 2016-05-23 13:56:15 -0700 | [diff] [blame] | 6535 | /** |
| 6536 | * @deprecated use {@code MediaStyle()}. |
| 6537 | */ |
| 6538 | @Deprecated |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6539 | public MediaStyle(Builder builder) { |
| 6540 | setBuilder(builder); |
| 6541 | } |
| 6542 | |
| 6543 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6544 | * 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] | 6545 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6546 | * |
| 6547 | * @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] | 6548 | */ |
| 6549 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 6550 | mActionsToShowInCompact = actions; |
| 6551 | return this; |
| 6552 | } |
| 6553 | |
| 6554 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6555 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 6556 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6557 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 6558 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6559 | mToken = token; |
| 6560 | return this; |
| 6561 | } |
| 6562 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6563 | /** |
| 6564 | * @hide |
| 6565 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6566 | @Override |
| 6567 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6568 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 6569 | if (wip.category == null) { |
| 6570 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 6571 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6572 | return wip; |
| 6573 | } |
| 6574 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6575 | /** |
| 6576 | * @hide |
| 6577 | */ |
| 6578 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6579 | public RemoteViews makeContentView(boolean increasedHeight) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6580 | return makeMediaContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6581 | } |
| 6582 | |
| 6583 | /** |
| 6584 | * @hide |
| 6585 | */ |
| 6586 | @Override |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 6587 | public RemoteViews makeBigContentView() { |
| 6588 | return makeMediaBigContentView(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6589 | } |
| 6590 | |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6591 | /** |
| 6592 | * @hide |
| 6593 | */ |
| 6594 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6595 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6596 | RemoteViews expanded = makeMediaBigContentView(); |
| 6597 | return expanded != null ? expanded : makeMediaContentView(); |
| 6598 | } |
| 6599 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6600 | /** @hide */ |
| 6601 | @Override |
| 6602 | public void addExtras(Bundle extras) { |
| 6603 | super.addExtras(extras); |
| 6604 | |
| 6605 | if (mToken != null) { |
| 6606 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 6607 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 6608 | if (mActionsToShowInCompact != null) { |
| 6609 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 6610 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6611 | } |
| 6612 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6613 | /** |
| 6614 | * @hide |
| 6615 | */ |
| 6616 | @Override |
| 6617 | protected void restoreFromExtras(Bundle extras) { |
| 6618 | super.restoreFromExtras(extras); |
| 6619 | |
| 6620 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 6621 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 6622 | } |
| 6623 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 6624 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 6625 | } |
| 6626 | } |
| 6627 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6628 | private RemoteViews generateMediaActionButton(Action action, int color) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6629 | final boolean tombstone = (action.actionIntent == null); |
Selim Cinek | f33b111 | 2015-07-15 17:45:11 -0700 | [diff] [blame] | 6630 | RemoteViews button = new BuilderRemoteViews(mBuilder.mContext.getApplicationInfo(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 6631 | R.layout.notification_material_media_action); |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 6632 | button.setImageViewIcon(R.id.action0, action.getIcon()); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6633 | button.setDrawableParameters(R.id.action0, false, -1, color, PorterDuff.Mode.SRC_ATOP, |
| 6634 | -1); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6635 | if (!tombstone) { |
| 6636 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 6637 | } |
| 6638 | button.setContentDescription(R.id.action0, action.title); |
| 6639 | return button; |
| 6640 | } |
| 6641 | |
| 6642 | private RemoteViews makeMediaContentView() { |
| 6643 | RemoteViews view = mBuilder.applyStandardTemplate( |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6644 | R.layout.notification_template_material_media, false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6645 | |
| 6646 | final int numActions = mBuilder.mActions.size(); |
| 6647 | final int N = mActionsToShowInCompact == null |
| 6648 | ? 0 |
| 6649 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 6650 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6651 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6652 | for (int i = 0; i < N; i++) { |
| 6653 | if (i >= numActions) { |
| 6654 | throw new IllegalArgumentException(String.format( |
| 6655 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 6656 | i, numActions - 1)); |
| 6657 | } |
| 6658 | |
| 6659 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6660 | final RemoteViews button = generateMediaActionButton(action, |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6661 | getPrimaryHighlightColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6662 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6663 | } |
| 6664 | } |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 6665 | handleImage(view); |
| 6666 | // handle the content margin |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6667 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6668 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6669 | endMargin = R.dimen.notification_content_plus_picture_margin_end; |
Selim Cinek | fdc738f | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 6670 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6671 | view.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6672 | return view; |
| 6673 | } |
| 6674 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6675 | private int getPrimaryHighlightColor() { |
| 6676 | return mBuilder.getPrimaryHighlightColor(); |
| 6677 | } |
| 6678 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6679 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6680 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6681 | // Dont add an expanded view if there is no more content to be revealed |
| 6682 | int actionsInCompact = mActionsToShowInCompact == null |
| 6683 | ? 0 |
| 6684 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6685 | if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) { |
Selim Cinek | cc10bfb | 2016-02-10 16:24:21 -0800 | [diff] [blame] | 6686 | return null; |
| 6687 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6688 | RemoteViews big = mBuilder.applyStandardTemplate( |
| 6689 | R.layout.notification_template_material_big_media, |
| 6690 | false); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6691 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6692 | if (actionCount > 0) { |
| 6693 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 6694 | for (int i = 0; i < actionCount; i++) { |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6695 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i), |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6696 | getPrimaryHighlightColor()); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6697 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6698 | } |
| 6699 | } |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6700 | handleImage(big); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6701 | return big; |
| 6702 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6703 | |
Selim Cinek | 5bf069a | 2015-11-10 19:14:27 -0500 | [diff] [blame] | 6704 | private void handleImage(RemoteViews contentView) { |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6705 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6706 | contentView.setViewLayoutMarginEndDimen(R.id.line1, 0); |
| 6707 | contentView.setViewLayoutMarginEndDimen(R.id.text, 0); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6708 | } |
| 6709 | } |
| 6710 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 6711 | /** |
| 6712 | * @hide |
| 6713 | */ |
| 6714 | @Override |
| 6715 | protected boolean hasProgress() { |
| 6716 | return false; |
| 6717 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 6718 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6719 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6720 | /** |
| 6721 | * Notification style for custom views that are decorated by the system |
| 6722 | * |
| 6723 | * <p>Instead of providing a notification that is completely custom, a developer can set this |
| 6724 | * style and still obtain system decorations like the notification header with the expand |
| 6725 | * affordance and actions. |
| 6726 | * |
| 6727 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 6728 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 6729 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 6730 | * corresponding custom views to display. |
| 6731 | * |
| 6732 | * To use this style with your Notification, feed it to |
| 6733 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 6734 | * <pre class="prettyprint"> |
| 6735 | * Notification noti = new Notification.Builder() |
| 6736 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 6737 | * .setLargeIcon(albumArtBitmap)) |
| 6738 | * .setCustomContentView(contentView); |
| 6739 | * .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>) |
| 6740 | * .build(); |
| 6741 | * </pre> |
| 6742 | */ |
| 6743 | public static class DecoratedCustomViewStyle extends Style { |
| 6744 | |
| 6745 | public DecoratedCustomViewStyle() { |
| 6746 | } |
| 6747 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6748 | /** |
| 6749 | * @hide |
| 6750 | */ |
| 6751 | public boolean displayCustomViewInline() { |
| 6752 | return true; |
| 6753 | } |
| 6754 | |
| 6755 | /** |
| 6756 | * @hide |
| 6757 | */ |
| 6758 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6759 | public RemoteViews makeContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6760 | return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 6761 | } |
| 6762 | |
| 6763 | /** |
| 6764 | * @hide |
| 6765 | */ |
| 6766 | @Override |
| 6767 | public RemoteViews makeBigContentView() { |
| 6768 | return makeDecoratedBigContentView(); |
| 6769 | } |
| 6770 | |
| 6771 | /** |
| 6772 | * @hide |
| 6773 | */ |
| 6774 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6775 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6776 | return makeDecoratedHeadsUpContentView(); |
| 6777 | } |
| 6778 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6779 | private RemoteViews makeDecoratedHeadsUpContentView() { |
| 6780 | RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 6781 | ? mBuilder.mN.contentView |
| 6782 | : mBuilder.mN.headsUpContentView; |
| 6783 | if (mBuilder.mActions.size() == 0) { |
| 6784 | return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 6785 | } |
| 6786 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 6787 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6788 | buildIntoRemoteViewContent(remoteViews, headsUpContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6789 | return remoteViews; |
| 6790 | } |
| 6791 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6792 | private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
| 6793 | RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
| 6794 | mBuilder.getBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6795 | buildIntoRemoteViewContent(remoteViews, customContent); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6796 | return remoteViews; |
| 6797 | } |
| 6798 | |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6799 | private RemoteViews makeDecoratedBigContentView() { |
| 6800 | RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 6801 | ? mBuilder.mN.contentView |
| 6802 | : mBuilder.mN.bigContentView; |
| 6803 | if (mBuilder.mActions.size() == 0) { |
| 6804 | return makeStandardTemplateWithCustomContent(bigContentView); |
| 6805 | } |
| 6806 | RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 6807 | mBuilder.getBigBaseLayoutResource()); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6808 | buildIntoRemoteViewContent(remoteViews, bigContentView); |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6809 | return remoteViews; |
| 6810 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6811 | |
| 6812 | private void buildIntoRemoteViewContent(RemoteViews remoteViews, |
| 6813 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6814 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6815 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 6816 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6817 | customContent = customContent.clone(); |
Anthony Chen | 8f5f358 | 2017-04-11 11:18:37 -0700 | [diff] [blame] | 6818 | remoteViews.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress); |
| 6819 | remoteViews.addView(R.id.notification_main_column, customContent, 0 /* index */); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6820 | } |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6821 | // also update the end margin if there is an image |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6822 | int endMargin = R.dimen.notification_content_margin_end; |
Selim Cinek | 279fa86 | 2016-06-14 10:57:25 -0700 | [diff] [blame] | 6823 | if (mBuilder.mN.hasLargeIcon()) { |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6824 | endMargin = R.dimen.notification_content_plus_picture_margin_end; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6825 | } |
Adrian Roos | 2d5dbba | 2016-06-08 17:11:53 -0700 | [diff] [blame] | 6826 | remoteViews.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 6827 | } |
Selim Cinek | 593610c | 2016-02-16 18:42:57 -0800 | [diff] [blame] | 6828 | } |
| 6829 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6830 | /** |
| 6831 | * Notification style for media custom views that are decorated by the system |
| 6832 | * |
| 6833 | * <p>Instead of providing a media notification that is completely custom, a developer can set |
| 6834 | * this style and still obtain system decorations like the notification header with the expand |
| 6835 | * affordance and actions. |
| 6836 | * |
| 6837 | * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)}, |
| 6838 | * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and |
| 6839 | * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the |
| 6840 | * corresponding custom views to display. |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 6841 | * <p> |
| 6842 | * Contrary to {@link MediaStyle} a developer has to opt-in to the colorizing of the |
| 6843 | * notification by using {@link Notification.Builder#setColorized(boolean)}. |
| 6844 | * <p> |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6845 | * To use this style with your Notification, feed it to |
| 6846 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 6847 | * <pre class="prettyprint"> |
| 6848 | * Notification noti = new Notification.Builder() |
| 6849 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 6850 | * .setLargeIcon(albumArtBitmap)) |
| 6851 | * .setCustomContentView(contentView); |
| 6852 | * .setStyle(<b>new Notification.DecoratedMediaCustomViewStyle()</b> |
| 6853 | * .setMediaSession(mySession)) |
| 6854 | * .build(); |
| 6855 | * </pre> |
| 6856 | * |
| 6857 | * @see android.app.Notification.DecoratedCustomViewStyle |
| 6858 | * @see android.app.Notification.MediaStyle |
| 6859 | */ |
| 6860 | public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 6861 | |
| 6862 | public DecoratedMediaCustomViewStyle() { |
| 6863 | } |
| 6864 | |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6865 | /** |
| 6866 | * @hide |
| 6867 | */ |
| 6868 | public boolean displayCustomViewInline() { |
| 6869 | return true; |
| 6870 | } |
| 6871 | |
| 6872 | /** |
| 6873 | * @hide |
| 6874 | */ |
| 6875 | @Override |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6876 | public RemoteViews makeContentView(boolean increasedHeight) { |
| 6877 | RemoteViews remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6878 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 6879 | mBuilder.mN.contentView); |
| 6880 | } |
| 6881 | |
| 6882 | /** |
| 6883 | * @hide |
| 6884 | */ |
| 6885 | @Override |
| 6886 | public RemoteViews makeBigContentView() { |
| 6887 | RemoteViews customRemoteView = mBuilder.mN.bigContentView != null |
| 6888 | ? mBuilder.mN.bigContentView |
| 6889 | : mBuilder.mN.contentView; |
| 6890 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 6891 | } |
| 6892 | |
| 6893 | private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { |
| 6894 | RemoteViews remoteViews = super.makeBigContentView(); |
| 6895 | if (remoteViews != null) { |
| 6896 | return buildIntoRemoteView(remoteViews, R.id.notification_main_column, |
| 6897 | customRemoteView); |
| 6898 | } else if (customRemoteView != mBuilder.mN.contentView){ |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 6899 | remoteViews = super.makeContentView(false /* increasedHeight */); |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6900 | return buildIntoRemoteView(remoteViews, R.id.notification_content_container, |
| 6901 | customRemoteView); |
| 6902 | } else { |
| 6903 | return null; |
| 6904 | } |
| 6905 | } |
| 6906 | |
| 6907 | /** |
| 6908 | * @hide |
| 6909 | */ |
| 6910 | @Override |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 6911 | public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6912 | RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null |
| 6913 | ? mBuilder.mN.headsUpContentView |
| 6914 | : mBuilder.mN.contentView; |
| 6915 | return makeBigContentViewWithCustomContent(customRemoteView); |
| 6916 | } |
| 6917 | |
| 6918 | private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, |
| 6919 | RemoteViews customContent) { |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6920 | if (customContent != null) { |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6921 | // Need to clone customContent before adding, because otherwise it can no longer be |
| 6922 | // parceled independently of remoteViews. |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6923 | customContent = customContent.clone(); |
Selim Cinek | f91017e | 2016-03-14 12:25:09 -0700 | [diff] [blame] | 6924 | remoteViews.removeAllViews(id); |
| 6925 | remoteViews.addView(id, customContent); |
Adrian Roos | 5081c0d | 2016-02-26 16:04:19 -0800 | [diff] [blame] | 6926 | } |
Selim Cinek | 03eb3b7 | 2016-02-18 10:39:45 -0800 | [diff] [blame] | 6927 | return remoteViews; |
| 6928 | } |
| 6929 | } |
| 6930 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 6931 | // When adding a new Style subclass here, don't forget to update |
| 6932 | // Builder.getNotificationStyleClass. |
| 6933 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6934 | /** |
| 6935 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 6936 | * metadata or change options on a notification builder. |
| 6937 | */ |
| 6938 | public interface Extender { |
| 6939 | /** |
| 6940 | * Apply this extender to a notification builder. |
| 6941 | * @param builder the builder to be modified. |
| 6942 | * @return the build object for chaining. |
| 6943 | */ |
| 6944 | public Builder extend(Builder builder); |
| 6945 | } |
| 6946 | |
| 6947 | /** |
| 6948 | * Helper class to add wearable extensions to notifications. |
| 6949 | * <p class="note"> See |
| 6950 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 6951 | * for Android Wear</a> for more information on how to use this class. |
| 6952 | * <p> |
| 6953 | * To create a notification with wearable extensions: |
| 6954 | * <ol> |
| 6955 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 6956 | * properties. |
| 6957 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 6958 | * <li>Set wearable-specific properties using the |
| 6959 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 6960 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 6961 | * notification. |
| 6962 | * <li>Post the notification to the notification system with the |
| 6963 | * {@code NotificationManager.notify(...)} methods. |
| 6964 | * </ol> |
| 6965 | * |
| 6966 | * <pre class="prettyprint"> |
| 6967 | * Notification notif = new Notification.Builder(mContext) |
| 6968 | * .setContentTitle("New mail from " + sender.toString()) |
| 6969 | * .setContentText(subject) |
| 6970 | * .setSmallIcon(R.drawable.new_mail) |
| 6971 | * .extend(new Notification.WearableExtender() |
| 6972 | * .setContentIcon(R.drawable.new_mail)) |
| 6973 | * .build(); |
| 6974 | * NotificationManager notificationManger = |
| 6975 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 6976 | * notificationManger.notify(0, notif);</pre> |
| 6977 | * |
| 6978 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 6979 | * {@code WearableExtender(Notification)} constructor, |
| 6980 | * and then using the {@code get} methods to access values. |
| 6981 | * |
| 6982 | * <pre class="prettyprint"> |
| 6983 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 6984 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 6985 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6986 | */ |
| 6987 | public static final class WearableExtender implements Extender { |
| 6988 | /** |
| 6989 | * Sentinel value for an action index that is unset. |
| 6990 | */ |
| 6991 | public static final int UNSET_ACTION_INDEX = -1; |
| 6992 | |
| 6993 | /** |
| 6994 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 6995 | * default sizing. |
| 6996 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
Paul Soulos | aa4f4bf | 2015-08-04 11:59:45 -0700 | [diff] [blame] | 6997 | * the default is {@link #SIZE_MEDIUM}. All other notifications size automatically based |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 6998 | * on their content. |
| 6999 | */ |
| 7000 | public static final int SIZE_DEFAULT = 0; |
| 7001 | |
| 7002 | /** |
| 7003 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 7004 | * with an extra small size. |
| 7005 | * <p>This value is only applicable for custom display notifications created using |
| 7006 | * {@link #setDisplayIntent}. |
| 7007 | */ |
| 7008 | public static final int SIZE_XSMALL = 1; |
| 7009 | |
| 7010 | /** |
| 7011 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 7012 | * with a small size. |
| 7013 | * <p>This value is only applicable for custom display notifications created using |
| 7014 | * {@link #setDisplayIntent}. |
| 7015 | */ |
| 7016 | public static final int SIZE_SMALL = 2; |
| 7017 | |
| 7018 | /** |
| 7019 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 7020 | * with a medium size. |
| 7021 | * <p>This value is only applicable for custom display notifications created using |
| 7022 | * {@link #setDisplayIntent}. |
| 7023 | */ |
| 7024 | public static final int SIZE_MEDIUM = 3; |
| 7025 | |
| 7026 | /** |
| 7027 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 7028 | * with a large size. |
| 7029 | * <p>This value is only applicable for custom display notifications created using |
| 7030 | * {@link #setDisplayIntent}. |
| 7031 | */ |
| 7032 | public static final int SIZE_LARGE = 4; |
| 7033 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 7034 | /** |
| 7035 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 7036 | * full screen. |
| 7037 | * <p>This value is only applicable for custom display notifications created using |
| 7038 | * {@link #setDisplayIntent}. |
| 7039 | */ |
| 7040 | public static final int SIZE_FULL_SCREEN = 5; |
| 7041 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7042 | /** |
| 7043 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 7044 | * short amount of time when this notification is displayed on the screen. This |
| 7045 | * is the default value. |
| 7046 | */ |
| 7047 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 7048 | |
| 7049 | /** |
| 7050 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 7051 | * for a longer amount of time when this notification is displayed on the screen. |
| 7052 | */ |
| 7053 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 7054 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7055 | /** Notification extra which contains wearable extensions */ |
| 7056 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 7057 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 7058 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7059 | private static final String KEY_ACTIONS = "actions"; |
| 7060 | private static final String KEY_FLAGS = "flags"; |
| 7061 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 7062 | private static final String KEY_PAGES = "pages"; |
| 7063 | private static final String KEY_BACKGROUND = "background"; |
| 7064 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 7065 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 7066 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 7067 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 7068 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 7069 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7070 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7071 | private static final String KEY_DISMISSAL_ID = "dismissalId"; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7072 | private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7073 | |
| 7074 | // Flags bitwise-ored to mFlags |
| 7075 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 7076 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 7077 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 7078 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7079 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 7080 | private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 7081 | private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7082 | |
| 7083 | // Default value for flags integer |
| 7084 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 7085 | |
| 7086 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 7087 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 7088 | |
| 7089 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 7090 | private int mFlags = DEFAULT_FLAGS; |
| 7091 | private PendingIntent mDisplayIntent; |
| 7092 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 7093 | private Bitmap mBackground; |
| 7094 | private int mContentIcon; |
| 7095 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 7096 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 7097 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 7098 | private int mCustomContentHeight; |
| 7099 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7100 | private int mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7101 | private String mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7102 | private String mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7103 | |
| 7104 | /** |
| 7105 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 7106 | * options. |
| 7107 | */ |
| 7108 | public WearableExtender() { |
| 7109 | } |
| 7110 | |
| 7111 | public WearableExtender(Notification notif) { |
| 7112 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 7113 | if (wearableBundle != null) { |
| 7114 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 7115 | if (actions != null) { |
| 7116 | mActions.addAll(actions); |
| 7117 | } |
| 7118 | |
| 7119 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 7120 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 7121 | |
| 7122 | Notification[] pages = getNotificationArrayFromBundle( |
| 7123 | wearableBundle, KEY_PAGES); |
| 7124 | if (pages != null) { |
| 7125 | Collections.addAll(mPages, pages); |
| 7126 | } |
| 7127 | |
| 7128 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 7129 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 7130 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 7131 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 7132 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 7133 | UNSET_ACTION_INDEX); |
| 7134 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 7135 | SIZE_DEFAULT); |
| 7136 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 7137 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7138 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7139 | mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7140 | mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7141 | } |
| 7142 | } |
| 7143 | |
| 7144 | /** |
| 7145 | * Apply wearable extensions to a notification that is being built. This is typically |
| 7146 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 7147 | * {@link android.app.Notification.Builder}. |
| 7148 | */ |
| 7149 | @Override |
| 7150 | public Notification.Builder extend(Notification.Builder builder) { |
| 7151 | Bundle wearableBundle = new Bundle(); |
| 7152 | |
| 7153 | if (!mActions.isEmpty()) { |
| 7154 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 7155 | } |
| 7156 | if (mFlags != DEFAULT_FLAGS) { |
| 7157 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 7158 | } |
| 7159 | if (mDisplayIntent != null) { |
| 7160 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 7161 | } |
| 7162 | if (!mPages.isEmpty()) { |
| 7163 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 7164 | new Notification[mPages.size()])); |
| 7165 | } |
| 7166 | if (mBackground != null) { |
| 7167 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 7168 | } |
| 7169 | if (mContentIcon != 0) { |
| 7170 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 7171 | } |
| 7172 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 7173 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 7174 | } |
| 7175 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 7176 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 7177 | mContentActionIndex); |
| 7178 | } |
| 7179 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 7180 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 7181 | } |
| 7182 | if (mCustomContentHeight != 0) { |
| 7183 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 7184 | } |
| 7185 | if (mGravity != DEFAULT_GRAVITY) { |
| 7186 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 7187 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7188 | if (mHintScreenTimeout != 0) { |
| 7189 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 7190 | } |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7191 | if (mDismissalId != null) { |
| 7192 | wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 7193 | } |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7194 | if (mBridgeTag != null) { |
| 7195 | wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 7196 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7197 | |
| 7198 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 7199 | return builder; |
| 7200 | } |
| 7201 | |
| 7202 | @Override |
| 7203 | public WearableExtender clone() { |
| 7204 | WearableExtender that = new WearableExtender(); |
| 7205 | that.mActions = new ArrayList<Action>(this.mActions); |
| 7206 | that.mFlags = this.mFlags; |
| 7207 | that.mDisplayIntent = this.mDisplayIntent; |
| 7208 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 7209 | that.mBackground = this.mBackground; |
| 7210 | that.mContentIcon = this.mContentIcon; |
| 7211 | that.mContentIconGravity = this.mContentIconGravity; |
| 7212 | that.mContentActionIndex = this.mContentActionIndex; |
| 7213 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 7214 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 7215 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7216 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7217 | that.mDismissalId = this.mDismissalId; |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7218 | that.mBridgeTag = this.mBridgeTag; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7219 | return that; |
| 7220 | } |
| 7221 | |
| 7222 | /** |
| 7223 | * Add a wearable action to this notification. |
| 7224 | * |
| 7225 | * <p>When wearable actions are added using this method, the set of actions that |
| 7226 | * show on a wearable device splits from devices that only show actions added |
| 7227 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 7228 | * of which actions display on different devices. |
| 7229 | * |
| 7230 | * @param action the action to add to this notification |
| 7231 | * @return this object for method chaining |
| 7232 | * @see android.app.Notification.Action |
| 7233 | */ |
| 7234 | public WearableExtender addAction(Action action) { |
| 7235 | mActions.add(action); |
| 7236 | return this; |
| 7237 | } |
| 7238 | |
| 7239 | /** |
| 7240 | * Adds wearable actions to this notification. |
| 7241 | * |
| 7242 | * <p>When wearable actions are added using this method, the set of actions that |
| 7243 | * show on a wearable device splits from devices that only show actions added |
| 7244 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 7245 | * of which actions display on different devices. |
| 7246 | * |
| 7247 | * @param actions the actions to add to this notification |
| 7248 | * @return this object for method chaining |
| 7249 | * @see android.app.Notification.Action |
| 7250 | */ |
| 7251 | public WearableExtender addActions(List<Action> actions) { |
| 7252 | mActions.addAll(actions); |
| 7253 | return this; |
| 7254 | } |
| 7255 | |
| 7256 | /** |
| 7257 | * Clear all wearable actions present on this builder. |
| 7258 | * @return this object for method chaining. |
| 7259 | * @see #addAction |
| 7260 | */ |
| 7261 | public WearableExtender clearActions() { |
| 7262 | mActions.clear(); |
| 7263 | return this; |
| 7264 | } |
| 7265 | |
| 7266 | /** |
| 7267 | * Get the wearable actions present on this notification. |
| 7268 | */ |
| 7269 | public List<Action> getActions() { |
| 7270 | return mActions; |
| 7271 | } |
| 7272 | |
| 7273 | /** |
| 7274 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 7275 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 7276 | * |
| 7277 | * <pre class="prettyprint"> |
| 7278 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 7279 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 7280 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 7281 | * Notification notif = new Notification.Builder(context) |
| 7282 | * .extend(new Notification.WearableExtender() |
| 7283 | * .setDisplayIntent(displayPendingIntent) |
| 7284 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 7285 | * .build();</pre> |
| 7286 | * |
| 7287 | * <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] | 7288 | * should have an empty task affinity. It is also recommended to use the device |
| 7289 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 7290 | * |
| 7291 | * <p>Example AndroidManifest.xml entry: |
| 7292 | * <pre class="prettyprint"> |
| 7293 | * <activity android:name="com.example.MyDisplayActivity" |
| 7294 | * android:exported="true" |
| 7295 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 7296 | * android:taskAffinity="" |
| 7297 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7298 | * |
| 7299 | * @param intent the {@link PendingIntent} for an activity |
| 7300 | * @return this object for method chaining |
| 7301 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 7302 | */ |
| 7303 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 7304 | mDisplayIntent = intent; |
| 7305 | return this; |
| 7306 | } |
| 7307 | |
| 7308 | /** |
| 7309 | * Get the intent to launch inside of an activity view when displaying this |
| 7310 | * notification. This {@code PendingIntent} should be for an activity. |
| 7311 | */ |
| 7312 | public PendingIntent getDisplayIntent() { |
| 7313 | return mDisplayIntent; |
| 7314 | } |
| 7315 | |
| 7316 | /** |
| 7317 | * Add an additional page of content to display with this notification. The current |
| 7318 | * notification forms the first page, and pages added using this function form |
| 7319 | * subsequent pages. This field can be used to separate a notification into multiple |
| 7320 | * sections. |
| 7321 | * |
| 7322 | * @param page the notification to add as another page |
| 7323 | * @return this object for method chaining |
| 7324 | * @see android.app.Notification.WearableExtender#getPages |
| 7325 | */ |
| 7326 | public WearableExtender addPage(Notification page) { |
| 7327 | mPages.add(page); |
| 7328 | return this; |
| 7329 | } |
| 7330 | |
| 7331 | /** |
| 7332 | * Add additional pages of content to display with this notification. The current |
| 7333 | * notification forms the first page, and pages added using this function form |
| 7334 | * subsequent pages. This field can be used to separate a notification into multiple |
| 7335 | * sections. |
| 7336 | * |
| 7337 | * @param pages a list of notifications |
| 7338 | * @return this object for method chaining |
| 7339 | * @see android.app.Notification.WearableExtender#getPages |
| 7340 | */ |
| 7341 | public WearableExtender addPages(List<Notification> pages) { |
| 7342 | mPages.addAll(pages); |
| 7343 | return this; |
| 7344 | } |
| 7345 | |
| 7346 | /** |
| 7347 | * Clear all additional pages present on this builder. |
| 7348 | * @return this object for method chaining. |
| 7349 | * @see #addPage |
| 7350 | */ |
| 7351 | public WearableExtender clearPages() { |
| 7352 | mPages.clear(); |
| 7353 | return this; |
| 7354 | } |
| 7355 | |
| 7356 | /** |
| 7357 | * Get the array of additional pages of content for displaying this notification. The |
| 7358 | * current notification forms the first page, and elements within this array form |
| 7359 | * subsequent pages. This field can be used to separate a notification into multiple |
| 7360 | * sections. |
| 7361 | * @return the pages for this notification |
| 7362 | */ |
| 7363 | public List<Notification> getPages() { |
| 7364 | return mPages; |
| 7365 | } |
| 7366 | |
| 7367 | /** |
| 7368 | * Set a background image to be displayed behind the notification content. |
| 7369 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 7370 | * will work with any notification style. |
| 7371 | * |
| 7372 | * @param background the background bitmap |
| 7373 | * @return this object for method chaining |
| 7374 | * @see android.app.Notification.WearableExtender#getBackground |
| 7375 | */ |
| 7376 | public WearableExtender setBackground(Bitmap background) { |
| 7377 | mBackground = background; |
| 7378 | return this; |
| 7379 | } |
| 7380 | |
| 7381 | /** |
| 7382 | * Get a background image to be displayed behind the notification content. |
| 7383 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 7384 | * will work with any notification style. |
| 7385 | * |
| 7386 | * @return the background image |
| 7387 | * @see android.app.Notification.WearableExtender#setBackground |
| 7388 | */ |
| 7389 | public Bitmap getBackground() { |
| 7390 | return mBackground; |
| 7391 | } |
| 7392 | |
| 7393 | /** |
| 7394 | * Set an icon that goes with the content of this notification. |
| 7395 | */ |
| 7396 | public WearableExtender setContentIcon(int icon) { |
| 7397 | mContentIcon = icon; |
| 7398 | return this; |
| 7399 | } |
| 7400 | |
| 7401 | /** |
| 7402 | * Get an icon that goes with the content of this notification. |
| 7403 | */ |
| 7404 | public int getContentIcon() { |
| 7405 | return mContentIcon; |
| 7406 | } |
| 7407 | |
| 7408 | /** |
| 7409 | * Set the gravity that the content icon should have within the notification display. |
| 7410 | * Supported values include {@link android.view.Gravity#START} and |
| 7411 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 7412 | * @see #setContentIcon |
| 7413 | */ |
| 7414 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 7415 | mContentIconGravity = contentIconGravity; |
| 7416 | return this; |
| 7417 | } |
| 7418 | |
| 7419 | /** |
| 7420 | * Get the gravity that the content icon should have within the notification display. |
| 7421 | * Supported values include {@link android.view.Gravity#START} and |
| 7422 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 7423 | * @see #getContentIcon |
| 7424 | */ |
| 7425 | public int getContentIconGravity() { |
| 7426 | return mContentIconGravity; |
| 7427 | } |
| 7428 | |
| 7429 | /** |
| 7430 | * 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] | 7431 | * this notification. This action will no longer display separately from the |
| 7432 | * notification's content. |
| 7433 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 7434 | * <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] | 7435 | * set, although the list of available actions comes from the main notification and not |
| 7436 | * from the child page's notification. |
| 7437 | * |
| 7438 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 7439 | * If wearable actions were added to the main notification, this index |
| 7440 | * will apply to that list, otherwise it will apply to the regular |
| 7441 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7442 | */ |
| 7443 | public WearableExtender setContentAction(int actionIndex) { |
| 7444 | mContentActionIndex = actionIndex; |
| 7445 | return this; |
| 7446 | } |
| 7447 | |
| 7448 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 7449 | * Get the index of the notification action, if any, that was specified as being clickable |
| 7450 | * 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] | 7451 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7452 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 7453 | * <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] | 7454 | * set, although the list of available actions comes from the main notification and not |
| 7455 | * from the child page's notification. |
| 7456 | * |
| 7457 | * <p>If wearable specific actions were added to the main notification, this index will |
| 7458 | * 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] | 7459 | * |
| 7460 | * @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] | 7461 | */ |
| 7462 | public int getContentAction() { |
| 7463 | return mContentActionIndex; |
| 7464 | } |
| 7465 | |
| 7466 | /** |
| 7467 | * Set the gravity that this notification should have within the available viewport space. |
| 7468 | * Supported values include {@link android.view.Gravity#TOP}, |
| 7469 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 7470 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 7471 | */ |
| 7472 | public WearableExtender setGravity(int gravity) { |
| 7473 | mGravity = gravity; |
| 7474 | return this; |
| 7475 | } |
| 7476 | |
| 7477 | /** |
| 7478 | * Get the gravity that this notification should have within the available viewport space. |
| 7479 | * Supported values include {@link android.view.Gravity#TOP}, |
| 7480 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 7481 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 7482 | */ |
| 7483 | public int getGravity() { |
| 7484 | return mGravity; |
| 7485 | } |
| 7486 | |
| 7487 | /** |
| 7488 | * Set the custom size preset for the display of this notification out of the available |
| 7489 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 7490 | * {@link #SIZE_LARGE}. |
| 7491 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 7492 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 7493 | * documentation for the preset in question. See also |
| 7494 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 7495 | */ |
| 7496 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 7497 | mCustomSizePreset = sizePreset; |
| 7498 | return this; |
| 7499 | } |
| 7500 | |
| 7501 | /** |
| 7502 | * Get the custom size preset for the display of this notification out of the available |
| 7503 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 7504 | * {@link #SIZE_LARGE}. |
| 7505 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 7506 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 7507 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 7508 | */ |
| 7509 | public int getCustomSizePreset() { |
| 7510 | return mCustomSizePreset; |
| 7511 | } |
| 7512 | |
| 7513 | /** |
| 7514 | * Set the custom height in pixels for the display of this notification's content. |
| 7515 | * <p>This option is only available for custom display notifications created |
| 7516 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 7517 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 7518 | * {@link #getCustomContentHeight}. |
| 7519 | */ |
| 7520 | public WearableExtender setCustomContentHeight(int height) { |
| 7521 | mCustomContentHeight = height; |
| 7522 | return this; |
| 7523 | } |
| 7524 | |
| 7525 | /** |
| 7526 | * Get the custom height in pixels for the display of this notification's content. |
| 7527 | * <p>This option is only available for custom display notifications created |
| 7528 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 7529 | * {@link #setCustomContentHeight}. |
| 7530 | */ |
| 7531 | public int getCustomContentHeight() { |
| 7532 | return mCustomContentHeight; |
| 7533 | } |
| 7534 | |
| 7535 | /** |
| 7536 | * Set whether the scrolling position for the contents of this notification should start |
| 7537 | * at the bottom of the contents instead of the top when the contents are too long to |
| 7538 | * display within the screen. Default is false (start scroll at the top). |
| 7539 | */ |
| 7540 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 7541 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 7542 | return this; |
| 7543 | } |
| 7544 | |
| 7545 | /** |
| 7546 | * Get whether the scrolling position for the contents of this notification should start |
| 7547 | * at the bottom of the contents instead of the top when the contents are too long to |
| 7548 | * display within the screen. Default is false (start scroll at the top). |
| 7549 | */ |
| 7550 | public boolean getStartScrollBottom() { |
| 7551 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 7552 | } |
| 7553 | |
| 7554 | /** |
| 7555 | * Set whether the content intent is available when the wearable device is not connected |
| 7556 | * to a companion device. The user can still trigger this intent when the wearable device |
| 7557 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 7558 | * Defaults to true. |
| 7559 | */ |
| 7560 | public WearableExtender setContentIntentAvailableOffline( |
| 7561 | boolean contentIntentAvailableOffline) { |
| 7562 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 7563 | return this; |
| 7564 | } |
| 7565 | |
| 7566 | /** |
| 7567 | * Get whether the content intent is available when the wearable device is not connected |
| 7568 | * to a companion device. The user can still trigger this intent when the wearable device |
| 7569 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 7570 | * Defaults to true. |
| 7571 | */ |
| 7572 | public boolean getContentIntentAvailableOffline() { |
| 7573 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 7574 | } |
| 7575 | |
| 7576 | /** |
| 7577 | * Set a hint that this notification's icon should not be displayed. |
| 7578 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 7579 | * @return this object for method chaining |
| 7580 | */ |
| 7581 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 7582 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 7583 | return this; |
| 7584 | } |
| 7585 | |
| 7586 | /** |
| 7587 | * Get a hint that this notification's icon should not be displayed. |
| 7588 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 7589 | * The default value is {@code false} if this was never set. |
| 7590 | */ |
| 7591 | public boolean getHintHideIcon() { |
| 7592 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 7593 | } |
| 7594 | |
| 7595 | /** |
| 7596 | * Set a visual hint that only the background image of this notification should be |
| 7597 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 7598 | * to sub-pages added using {@link #addPage}. |
| 7599 | */ |
| 7600 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 7601 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 7602 | return this; |
| 7603 | } |
| 7604 | |
| 7605 | /** |
| 7606 | * Get a visual hint that only the background image of this notification should be |
| 7607 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 7608 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 7609 | */ |
| 7610 | public boolean getHintShowBackgroundOnly() { |
| 7611 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 7612 | } |
| 7613 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 7614 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 7615 | * Set a hint that this notification's background should not be clipped if possible, |
| 7616 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 7617 | * 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] | 7618 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 7619 | * @return this object for method chaining |
| 7620 | */ |
| 7621 | public WearableExtender setHintAvoidBackgroundClipping( |
| 7622 | boolean hintAvoidBackgroundClipping) { |
| 7623 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 7624 | return this; |
| 7625 | } |
| 7626 | |
| 7627 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 7628 | * Get a hint that this notification's background should not be clipped if possible, |
| 7629 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 7630 | * 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] | 7631 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 7632 | * otherwise. The default value is {@code false} if this was never set. |
| 7633 | */ |
| 7634 | public boolean getHintAvoidBackgroundClipping() { |
| 7635 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 7636 | } |
| 7637 | |
| 7638 | /** |
| 7639 | * Set a hint that the screen should remain on for at least this duration when |
| 7640 | * this notification is displayed on the screen. |
| 7641 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 7642 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 7643 | * @return this object for method chaining |
| 7644 | */ |
| 7645 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 7646 | mHintScreenTimeout = timeout; |
| 7647 | return this; |
| 7648 | } |
| 7649 | |
| 7650 | /** |
| 7651 | * Get the duration, in milliseconds, that the screen should remain on for |
| 7652 | * when this notification is displayed. |
| 7653 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 7654 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 7655 | */ |
| 7656 | public int getHintScreenTimeout() { |
| 7657 | return mHintScreenTimeout; |
| 7658 | } |
| 7659 | |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 7660 | /** |
Alex Hills | 4bcb06b | 2016-04-05 14:26:25 -0400 | [diff] [blame] | 7661 | * Set a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 7662 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 7663 | * qr codes, as well as other simple black-and-white tickets. |
| 7664 | * @param hintAmbientBigPicture {@code true} to enable converstion and ambient. |
| 7665 | * @return this object for method chaining |
| 7666 | */ |
| 7667 | public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 7668 | setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 7669 | return this; |
| 7670 | } |
| 7671 | |
| 7672 | /** |
| 7673 | * Get a hint that this notification's {@link BigPictureStyle} (if present) should be |
| 7674 | * converted to low-bit and displayed in ambient mode, especially useful for barcodes and |
| 7675 | * qr codes, as well as other simple black-and-white tickets. |
| 7676 | * @return {@code true} if it should be displayed in ambient, false otherwise |
| 7677 | * otherwise. The default value is {@code false} if this was never set. |
| 7678 | */ |
| 7679 | public boolean getHintAmbientBigPicture() { |
| 7680 | return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 7681 | } |
| 7682 | |
| 7683 | /** |
Alex Hills | 9ab3a23 | 2016-04-05 14:54:56 -0400 | [diff] [blame] | 7684 | * Set a hint that this notification's content intent will launch an {@link Activity} |
| 7685 | * directly, telling the platform that it can generate the appropriate transitions. |
| 7686 | * @param hintContentIntentLaunchesActivity {@code true} if the content intent will launch |
| 7687 | * an activity and transitions should be generated, false otherwise. |
| 7688 | * @return this object for method chaining |
| 7689 | */ |
| 7690 | public WearableExtender setHintContentIntentLaunchesActivity( |
| 7691 | boolean hintContentIntentLaunchesActivity) { |
| 7692 | setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 7693 | return this; |
| 7694 | } |
| 7695 | |
| 7696 | /** |
| 7697 | * Get a hint that this notification's content intent will launch an {@link Activity} |
| 7698 | * directly, telling the platform that it can generate the appropriate transitions |
| 7699 | * @return {@code true} if the content intent will launch an activity and transitions should |
| 7700 | * be generated, false otherwise. The default value is {@code false} if this was never set. |
| 7701 | */ |
| 7702 | public boolean getHintContentIntentLaunchesActivity() { |
| 7703 | return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 7704 | } |
| 7705 | |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7706 | /** |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7707 | * Sets the dismissal id for this notification. If a notification is posted with a |
| 7708 | * dismissal id, then when that notification is canceled, notifications on other wearables |
| 7709 | * 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] | 7710 | * <a href="{@docRoot}wear/notifications/index.html">Adding Wearable Features to |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7711 | * Notifications</a> for more information. |
Nadia Benbernou | 948627e | 2016-04-14 14:41:08 -0400 | [diff] [blame] | 7712 | * @param dismissalId the dismissal id of the notification. |
| 7713 | * @return this object for method chaining |
| 7714 | */ |
| 7715 | public WearableExtender setDismissalId(String dismissalId) { |
| 7716 | mDismissalId = dismissalId; |
| 7717 | return this; |
| 7718 | } |
| 7719 | |
| 7720 | /** |
| 7721 | * Returns the dismissal id of the notification. |
| 7722 | * @return the dismissal id of the notification or null if it has not been set. |
| 7723 | */ |
| 7724 | public String getDismissalId() { |
| 7725 | return mDismissalId; |
| 7726 | } |
| 7727 | |
Ariel Gertzenstein | 95ab522 | 2016-09-02 17:00:16 -0400 | [diff] [blame] | 7728 | /** |
| 7729 | * Sets a bridge tag for this notification. A bridge tag can be set for notifications |
| 7730 | * posted from a phone to provide finer-grained control on what notifications are bridged |
| 7731 | * to wearables. See <a href="{@docRoot}wear/notifications/index.html">Adding Wearable |
| 7732 | * Features to Notifications</a> for more information. |
| 7733 | * @param bridgeTag the bridge tag of the notification. |
| 7734 | * @return this object for method chaining |
| 7735 | */ |
| 7736 | public WearableExtender setBridgeTag(String bridgeTag) { |
| 7737 | mBridgeTag = bridgeTag; |
| 7738 | return this; |
| 7739 | } |
| 7740 | |
| 7741 | /** |
| 7742 | * Returns the bridge tag of the notification. |
| 7743 | * @return the bridge tag or null if not present. |
| 7744 | */ |
| 7745 | public String getBridgeTag() { |
| 7746 | return mBridgeTag; |
| 7747 | } |
| 7748 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 7749 | private void setFlag(int mask, boolean value) { |
| 7750 | if (value) { |
| 7751 | mFlags |= mask; |
| 7752 | } else { |
| 7753 | mFlags &= ~mask; |
| 7754 | } |
| 7755 | } |
| 7756 | } |
| 7757 | |
| 7758 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7759 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 7760 | * with car extensions: |
| 7761 | * |
| 7762 | * <ol> |
| 7763 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 7764 | * properties. |
| 7765 | * <li>Create a {@link CarExtender}. |
| 7766 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 7767 | * {@link CarExtender}. |
| 7768 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 7769 | * to apply the extensions to a notification. |
| 7770 | * </ol> |
| 7771 | * |
| 7772 | * <pre class="prettyprint"> |
| 7773 | * Notification notification = new Notification.Builder(context) |
| 7774 | * ... |
| 7775 | * .extend(new CarExtender() |
| 7776 | * .set*(...)) |
| 7777 | * .build(); |
| 7778 | * </pre> |
| 7779 | * |
| 7780 | * <p>Car extensions can be accessed on an existing notification by using the |
| 7781 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 7782 | * to access values. |
| 7783 | */ |
| 7784 | public static final class CarExtender implements Extender { |
| 7785 | private static final String TAG = "CarExtender"; |
| 7786 | |
| 7787 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 7788 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 7789 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 7790 | private static final String EXTRA_COLOR = "app_color"; |
| 7791 | |
| 7792 | private Bitmap mLargeIcon; |
| 7793 | private UnreadConversation mUnreadConversation; |
| 7794 | private int mColor = Notification.COLOR_DEFAULT; |
| 7795 | |
| 7796 | /** |
| 7797 | * Create a {@link CarExtender} with default options. |
| 7798 | */ |
| 7799 | public CarExtender() { |
| 7800 | } |
| 7801 | |
| 7802 | /** |
| 7803 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 7804 | * |
| 7805 | * @param notif The notification from which to copy options. |
| 7806 | */ |
| 7807 | public CarExtender(Notification notif) { |
| 7808 | Bundle carBundle = notif.extras == null ? |
| 7809 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 7810 | if (carBundle != null) { |
| 7811 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 7812 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 7813 | |
| 7814 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 7815 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 7816 | } |
| 7817 | } |
| 7818 | |
| 7819 | /** |
| 7820 | * Apply car extensions to a notification that is being built. This is typically called by |
| 7821 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 7822 | * method of {@link Notification.Builder}. |
| 7823 | */ |
| 7824 | @Override |
| 7825 | public Notification.Builder extend(Notification.Builder builder) { |
| 7826 | Bundle carExtensions = new Bundle(); |
| 7827 | |
| 7828 | if (mLargeIcon != null) { |
| 7829 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 7830 | } |
| 7831 | if (mColor != Notification.COLOR_DEFAULT) { |
| 7832 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 7833 | } |
| 7834 | |
| 7835 | if (mUnreadConversation != null) { |
| 7836 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 7837 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 7838 | } |
| 7839 | |
| 7840 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 7841 | return builder; |
| 7842 | } |
| 7843 | |
| 7844 | /** |
| 7845 | * Sets the accent color to use when Android Auto presents the notification. |
| 7846 | * |
| 7847 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 7848 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 7849 | * automotive setting. This method can be used to override the color provided in the |
| 7850 | * notification in such a situation. |
| 7851 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 7852 | public CarExtender setColor(@ColorInt int color) { |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7853 | mColor = color; |
| 7854 | return this; |
| 7855 | } |
| 7856 | |
| 7857 | /** |
| 7858 | * Gets the accent color. |
| 7859 | * |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 7860 | * @see #setColor |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7861 | */ |
Tor Norbye | 80756e3 | 2015-03-02 09:39:27 -0800 | [diff] [blame] | 7862 | @ColorInt |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame] | 7863 | public int getColor() { |
| 7864 | return mColor; |
| 7865 | } |
| 7866 | |
| 7867 | /** |
| 7868 | * Sets the large icon of the car notification. |
| 7869 | * |
| 7870 | * If no large icon is set in the extender, Android Auto will display the icon |
| 7871 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 7872 | * |
| 7873 | * @param largeIcon The large icon to use in the car notification. |
| 7874 | * @return This object for method chaining. |
| 7875 | */ |
| 7876 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 7877 | mLargeIcon = largeIcon; |
| 7878 | return this; |
| 7879 | } |
| 7880 | |
| 7881 | /** |
| 7882 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 7883 | * |
| 7884 | * @return The large icon for the car notification. |
| 7885 | * @see CarExtender#setLargeIcon |
| 7886 | */ |
| 7887 | public Bitmap getLargeIcon() { |
| 7888 | return mLargeIcon; |
| 7889 | } |
| 7890 | |
| 7891 | /** |
| 7892 | * Sets the unread conversation in a message notification. |
| 7893 | * |
| 7894 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 7895 | * @return This object for method chaining. |
| 7896 | */ |
| 7897 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 7898 | mUnreadConversation = unreadConversation; |
| 7899 | return this; |
| 7900 | } |
| 7901 | |
| 7902 | /** |
| 7903 | * Returns the unread conversation conveyed by this notification. |
| 7904 | * @see #setUnreadConversation(UnreadConversation) |
| 7905 | */ |
| 7906 | public UnreadConversation getUnreadConversation() { |
| 7907 | return mUnreadConversation; |
| 7908 | } |
| 7909 | |
| 7910 | /** |
| 7911 | * A class which holds the unread messages from a conversation. |
| 7912 | */ |
| 7913 | public static class UnreadConversation { |
| 7914 | private static final String KEY_AUTHOR = "author"; |
| 7915 | private static final String KEY_TEXT = "text"; |
| 7916 | private static final String KEY_MESSAGES = "messages"; |
| 7917 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 7918 | private static final String KEY_ON_REPLY = "on_reply"; |
| 7919 | private static final String KEY_ON_READ = "on_read"; |
| 7920 | private static final String KEY_PARTICIPANTS = "participants"; |
| 7921 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 7922 | |
| 7923 | private final String[] mMessages; |
| 7924 | private final RemoteInput mRemoteInput; |
| 7925 | private final PendingIntent mReplyPendingIntent; |
| 7926 | private final PendingIntent mReadPendingIntent; |
| 7927 | private final String[] mParticipants; |
| 7928 | private final long mLatestTimestamp; |
| 7929 | |
| 7930 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 7931 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 7932 | String[] participants, long latestTimestamp) { |
| 7933 | mMessages = messages; |
| 7934 | mRemoteInput = remoteInput; |
| 7935 | mReadPendingIntent = readPendingIntent; |
| 7936 | mReplyPendingIntent = replyPendingIntent; |
| 7937 | mParticipants = participants; |
| 7938 | mLatestTimestamp = latestTimestamp; |
| 7939 | } |
| 7940 | |
| 7941 | /** |
| 7942 | * Gets the list of messages conveyed by this notification. |
| 7943 | */ |
| 7944 | public String[] getMessages() { |
| 7945 | return mMessages; |
| 7946 | } |
| 7947 | |
| 7948 | /** |
| 7949 | * Gets the remote input that will be used to convey the response to a message list, or |
| 7950 | * null if no such remote input exists. |
| 7951 | */ |
| 7952 | public RemoteInput getRemoteInput() { |
| 7953 | return mRemoteInput; |
| 7954 | } |
| 7955 | |
| 7956 | /** |
| 7957 | * Gets the pending intent that will be triggered when the user replies to this |
| 7958 | * notification. |
| 7959 | */ |
| 7960 | public PendingIntent getReplyPendingIntent() { |
| 7961 | return mReplyPendingIntent; |
| 7962 | } |
| 7963 | |
| 7964 | /** |
| 7965 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 7966 | * in this object's message list. |
| 7967 | */ |
| 7968 | public PendingIntent getReadPendingIntent() { |
| 7969 | return mReadPendingIntent; |
| 7970 | } |
| 7971 | |
| 7972 | /** |
| 7973 | * Gets the participants in the conversation. |
| 7974 | */ |
| 7975 | public String[] getParticipants() { |
| 7976 | return mParticipants; |
| 7977 | } |
| 7978 | |
| 7979 | /** |
| 7980 | * Gets the firs participant in the conversation. |
| 7981 | */ |
| 7982 | public String getParticipant() { |
| 7983 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 7984 | } |
| 7985 | |
| 7986 | /** |
| 7987 | * Gets the timestamp of the conversation. |
| 7988 | */ |
| 7989 | public long getLatestTimestamp() { |
| 7990 | return mLatestTimestamp; |
| 7991 | } |
| 7992 | |
| 7993 | Bundle getBundleForUnreadConversation() { |
| 7994 | Bundle b = new Bundle(); |
| 7995 | String author = null; |
| 7996 | if (mParticipants != null && mParticipants.length > 1) { |
| 7997 | author = mParticipants[0]; |
| 7998 | } |
| 7999 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 8000 | for (int i = 0; i < messages.length; i++) { |
| 8001 | Bundle m = new Bundle(); |
| 8002 | m.putString(KEY_TEXT, mMessages[i]); |
| 8003 | m.putString(KEY_AUTHOR, author); |
| 8004 | messages[i] = m; |
| 8005 | } |
| 8006 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 8007 | if (mRemoteInput != null) { |
| 8008 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 8009 | } |
| 8010 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 8011 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 8012 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 8013 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 8014 | return b; |
| 8015 | } |
| 8016 | |
| 8017 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 8018 | if (b == null) { |
| 8019 | return null; |
| 8020 | } |
| 8021 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 8022 | String[] messages = null; |
| 8023 | if (parcelableMessages != null) { |
| 8024 | String[] tmp = new String[parcelableMessages.length]; |
| 8025 | boolean success = true; |
| 8026 | for (int i = 0; i < tmp.length; i++) { |
| 8027 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 8028 | success = false; |
| 8029 | break; |
| 8030 | } |
| 8031 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 8032 | if (tmp[i] == null) { |
| 8033 | success = false; |
| 8034 | break; |
| 8035 | } |
| 8036 | } |
| 8037 | if (success) { |
| 8038 | messages = tmp; |
| 8039 | } else { |
| 8040 | return null; |
| 8041 | } |
| 8042 | } |
| 8043 | |
| 8044 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 8045 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 8046 | |
| 8047 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 8048 | |
| 8049 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 8050 | if (participants == null || participants.length != 1) { |
| 8051 | return null; |
| 8052 | } |
| 8053 | |
| 8054 | return new UnreadConversation(messages, |
| 8055 | remoteInput, |
| 8056 | onReply, |
| 8057 | onRead, |
| 8058 | participants, b.getLong(KEY_TIMESTAMP)); |
| 8059 | } |
| 8060 | }; |
| 8061 | |
| 8062 | /** |
| 8063 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 8064 | */ |
| 8065 | public static class Builder { |
| 8066 | private final List<String> mMessages = new ArrayList<String>(); |
| 8067 | private final String mParticipant; |
| 8068 | private RemoteInput mRemoteInput; |
| 8069 | private PendingIntent mReadPendingIntent; |
| 8070 | private PendingIntent mReplyPendingIntent; |
| 8071 | private long mLatestTimestamp; |
| 8072 | |
| 8073 | /** |
| 8074 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 8075 | * |
| 8076 | * @param name The name of the other participant in the conversation. |
| 8077 | */ |
| 8078 | public Builder(String name) { |
| 8079 | mParticipant = name; |
| 8080 | } |
| 8081 | |
| 8082 | /** |
| 8083 | * Appends a new unread message to the list of messages for this conversation. |
| 8084 | * |
| 8085 | * The messages should be added from oldest to newest. |
| 8086 | * |
| 8087 | * @param message The text of the new unread message. |
| 8088 | * @return This object for method chaining. |
| 8089 | */ |
| 8090 | public Builder addMessage(String message) { |
| 8091 | mMessages.add(message); |
| 8092 | return this; |
| 8093 | } |
| 8094 | |
| 8095 | /** |
| 8096 | * Sets the pending intent and remote input which will convey the reply to this |
| 8097 | * notification. |
| 8098 | * |
| 8099 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 8100 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 8101 | * @return This object for method chaining. |
| 8102 | * |
| 8103 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 8104 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 8105 | */ |
| 8106 | public Builder setReplyAction( |
| 8107 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 8108 | mRemoteInput = remoteInput; |
| 8109 | mReplyPendingIntent = pendingIntent; |
| 8110 | |
| 8111 | return this; |
| 8112 | } |
| 8113 | |
| 8114 | /** |
| 8115 | * Sets the pending intent that will be sent once the messages in this notification |
| 8116 | * are read. |
| 8117 | * |
| 8118 | * @param pendingIntent The pending intent to use. |
| 8119 | * @return This object for method chaining. |
| 8120 | */ |
| 8121 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 8122 | mReadPendingIntent = pendingIntent; |
| 8123 | return this; |
| 8124 | } |
| 8125 | |
| 8126 | /** |
| 8127 | * Sets the timestamp of the most recent message in an unread conversation. |
| 8128 | * |
| 8129 | * If a messaging notification has been posted by your application and has not |
| 8130 | * yet been cancelled, posting a later notification with the same id and tag |
| 8131 | * but without a newer timestamp may result in Android Auto not displaying a |
| 8132 | * heads up notification for the later notification. |
| 8133 | * |
| 8134 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 8135 | * @return This object for method chaining. |
| 8136 | */ |
| 8137 | public Builder setLatestTimestamp(long timestamp) { |
| 8138 | mLatestTimestamp = timestamp; |
| 8139 | return this; |
| 8140 | } |
| 8141 | |
| 8142 | /** |
| 8143 | * Builds a new unread conversation object. |
| 8144 | * |
| 8145 | * @return The new unread conversation object. |
| 8146 | */ |
| 8147 | public UnreadConversation build() { |
| 8148 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 8149 | String[] participants = { mParticipant }; |
| 8150 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 8151 | mReadPendingIntent, participants, mLatestTimestamp); |
| 8152 | } |
| 8153 | } |
| 8154 | } |
| 8155 | |
| 8156 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8157 | * <p>Helper class to add Android TV extensions to notifications. To create a notification |
| 8158 | * with a TV extension: |
| 8159 | * |
| 8160 | * <ol> |
| 8161 | * <li>Create an {@link Notification.Builder}, setting any desired properties. |
| 8162 | * <li>Create a {@link TvExtender}. |
| 8163 | * <li>Set TV-specific properties using the {@code set} methods of |
| 8164 | * {@link TvExtender}. |
| 8165 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 8166 | * to apply the extension to a notification. |
| 8167 | * </ol> |
| 8168 | * |
| 8169 | * <pre class="prettyprint"> |
| 8170 | * Notification notification = new Notification.Builder(context) |
| 8171 | * ... |
| 8172 | * .extend(new TvExtender() |
| 8173 | * .set*(...)) |
| 8174 | * .build(); |
| 8175 | * </pre> |
| 8176 | * |
| 8177 | * <p>TV extensions can be accessed on an existing notification by using the |
| 8178 | * {@code TvExtender(Notification)} constructor, and then using the {@code get} methods |
| 8179 | * to access values. |
| 8180 | * |
| 8181 | * @hide |
| 8182 | */ |
| 8183 | @SystemApi |
| 8184 | public static final class TvExtender implements Extender { |
| 8185 | private static final String TAG = "TvExtender"; |
| 8186 | |
| 8187 | private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 8188 | private static final String EXTRA_FLAGS = "flags"; |
| 8189 | private static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 8190 | private static final String EXTRA_DELETE_INTENT = "delete_intent"; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8191 | private static final String EXTRA_CHANNEL_ID = "channel_id"; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8192 | |
| 8193 | // Flags bitwise-ored to mFlags |
| 8194 | private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 8195 | |
| 8196 | private int mFlags; |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8197 | private String mChannelId; |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8198 | private PendingIntent mContentIntent; |
| 8199 | private PendingIntent mDeleteIntent; |
| 8200 | |
| 8201 | /** |
| 8202 | * Create a {@link TvExtender} with default options. |
| 8203 | */ |
| 8204 | public TvExtender() { |
| 8205 | mFlags = FLAG_AVAILABLE_ON_TV; |
| 8206 | } |
| 8207 | |
| 8208 | /** |
| 8209 | * Create a {@link TvExtender} from the TvExtender options of an existing Notification. |
| 8210 | * |
| 8211 | * @param notif The notification from which to copy options. |
| 8212 | */ |
| 8213 | public TvExtender(Notification notif) { |
| 8214 | Bundle bundle = notif.extras == null ? |
| 8215 | null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 8216 | if (bundle != null) { |
| 8217 | mFlags = bundle.getInt(EXTRA_FLAGS); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8218 | mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8219 | mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT); |
| 8220 | mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT); |
| 8221 | } |
| 8222 | } |
| 8223 | |
| 8224 | /** |
| 8225 | * Apply a TV extension to a notification that is being built. This is typically called by |
| 8226 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 8227 | * method of {@link Notification.Builder}. |
| 8228 | */ |
| 8229 | @Override |
| 8230 | public Notification.Builder extend(Notification.Builder builder) { |
| 8231 | Bundle bundle = new Bundle(); |
| 8232 | |
| 8233 | bundle.putInt(EXTRA_FLAGS, mFlags); |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8234 | bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8235 | if (mContentIntent != null) { |
| 8236 | bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 8237 | } |
| 8238 | |
| 8239 | if (mDeleteIntent != null) { |
| 8240 | bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 8241 | } |
| 8242 | |
| 8243 | builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 8244 | return builder; |
| 8245 | } |
| 8246 | |
| 8247 | /** |
| 8248 | * Returns true if this notification should be shown on TV. This method return true |
| 8249 | * if the notification was extended with a TvExtender. |
| 8250 | */ |
| 8251 | public boolean isAvailableOnTv() { |
| 8252 | return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 8253 | } |
| 8254 | |
| 8255 | /** |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8256 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 8257 | * It can be different from the channel that the notification is delivered to when |
| 8258 | * posting on a non-TV device. |
| 8259 | */ |
| 8260 | public TvExtender setChannel(String channelId) { |
| 8261 | mChannelId = channelId; |
| 8262 | return this; |
| 8263 | } |
| 8264 | |
| 8265 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 8266 | * Specifies the channel the notification should be delivered on when shown on TV. |
| 8267 | * It can be different from the channel that the notification is delivered to when |
| 8268 | * posting on a non-TV device. |
| 8269 | */ |
| 8270 | public TvExtender setChannelId(String channelId) { |
| 8271 | mChannelId = channelId; |
| 8272 | return this; |
| 8273 | } |
| 8274 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 8275 | /** @removed */ |
| 8276 | @Deprecated |
Dmitri Plotnikov | b8a04ee | 2017-01-20 10:39:22 -0800 | [diff] [blame] | 8277 | public String getChannel() { |
| 8278 | return mChannelId; |
| 8279 | } |
| 8280 | |
| 8281 | /** |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 8282 | * Returns the id of the channel this notification posts to on TV. |
| 8283 | */ |
| 8284 | public String getChannelId() { |
| 8285 | return mChannelId; |
| 8286 | } |
| 8287 | |
| 8288 | /** |
Dmitri Plotnikov | 9e9cfd9 | 2016-12-21 10:52:26 -0800 | [diff] [blame] | 8289 | * Supplies a {@link PendingIntent} to be sent when the notification is selected on TV. |
| 8290 | * If provided, it is used instead of the content intent specified |
| 8291 | * at the level of Notification. |
| 8292 | */ |
| 8293 | public TvExtender setContentIntent(PendingIntent intent) { |
| 8294 | mContentIntent = intent; |
| 8295 | return this; |
| 8296 | } |
| 8297 | |
| 8298 | /** |
| 8299 | * Returns the TV-specific content intent. If this method returns null, the |
| 8300 | * main content intent on the notification should be used. |
| 8301 | * |
| 8302 | * @see {@link Notification#contentIntent} |
| 8303 | */ |
| 8304 | public PendingIntent getContentIntent() { |
| 8305 | return mContentIntent; |
| 8306 | } |
| 8307 | |
| 8308 | /** |
| 8309 | * Supplies a {@link PendingIntent} to send when the notification is cleared explicitly |
| 8310 | * by the user on TV. If provided, it is used instead of the delete intent specified |
| 8311 | * at the level of Notification. |
| 8312 | */ |
| 8313 | public TvExtender setDeleteIntent(PendingIntent intent) { |
| 8314 | mDeleteIntent = intent; |
| 8315 | return this; |
| 8316 | } |
| 8317 | |
| 8318 | /** |
| 8319 | * Returns the TV-specific delete intent. If this method returns null, the |
| 8320 | * main delete intent on the notification should be used. |
| 8321 | * |
| 8322 | * @see {@link Notification#deleteIntent} |
| 8323 | */ |
| 8324 | public PendingIntent getDeleteIntent() { |
| 8325 | return mDeleteIntent; |
| 8326 | } |
| 8327 | } |
| 8328 | |
| 8329 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 8330 | * Get an array of Notification objects from a parcelable array bundle field. |
| 8331 | * Update the bundle to have a typed array so fetches in the future don't need |
| 8332 | * to do an array copy. |
| 8333 | */ |
| 8334 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 8335 | Parcelable[] array = bundle.getParcelableArray(key); |
| 8336 | if (array instanceof Notification[] || array == null) { |
| 8337 | return (Notification[]) array; |
| 8338 | } |
| 8339 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 8340 | Notification[].class); |
| 8341 | bundle.putParcelableArray(key, typedArray); |
| 8342 | return typedArray; |
| 8343 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8344 | |
| 8345 | private static class BuilderRemoteViews extends RemoteViews { |
| 8346 | public BuilderRemoteViews(Parcel parcel) { |
| 8347 | super(parcel); |
| 8348 | } |
| 8349 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 8350 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 8351 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 8352 | } |
| 8353 | |
| 8354 | @Override |
| 8355 | public BuilderRemoteViews clone() { |
| 8356 | Parcel p = Parcel.obtain(); |
| 8357 | writeToParcel(p, 0); |
| 8358 | p.setDataPosition(0); |
| 8359 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 8360 | p.recycle(); |
| 8361 | return brv; |
| 8362 | } |
| 8363 | } |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 8364 | |
| 8365 | private static class StandardTemplateParams { |
| 8366 | boolean hasProgress = true; |
| 8367 | boolean ambient = false; |
| 8368 | CharSequence title; |
| 8369 | CharSequence text; |
| 8370 | |
| 8371 | final StandardTemplateParams reset() { |
| 8372 | hasProgress = true; |
| 8373 | ambient = false; |
| 8374 | title = null; |
| 8375 | text = null; |
| 8376 | return this; |
| 8377 | } |
| 8378 | |
| 8379 | final StandardTemplateParams hasProgress(boolean hasProgress) { |
| 8380 | this.hasProgress = hasProgress; |
| 8381 | return this; |
| 8382 | } |
| 8383 | |
| 8384 | final StandardTemplateParams title(CharSequence title) { |
| 8385 | this.title = title; |
| 8386 | return this; |
| 8387 | } |
| 8388 | |
| 8389 | final StandardTemplateParams text(CharSequence text) { |
| 8390 | this.text = text; |
| 8391 | return this; |
| 8392 | } |
| 8393 | |
| 8394 | final StandardTemplateParams ambient(boolean ambient) { |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 8395 | Preconditions.checkState(title == null && text == null, "must set ambient before text"); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 8396 | this.ambient = ambient; |
| 8397 | return this; |
| 8398 | } |
| 8399 | |
| 8400 | final StandardTemplateParams fillTextsFrom(Builder b) { |
| 8401 | Bundle extras = b.mN.extras; |
Adrian Roos | 0bc3f6a | 2017-03-06 11:54:05 -0800 | [diff] [blame] | 8402 | title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE), ambient); |
| 8403 | text = b.processLegacyText(extras.getCharSequence(EXTRA_TEXT), ambient); |
Adrian Roos | 70d7aa3 | 2017-01-11 15:39:06 -0800 | [diff] [blame] | 8404 | return this; |
| 8405 | } |
| 8406 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8407 | } |